[2168] | 1 | //transcode.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 5 | * |
---|
[2169] | 6 | * This file is part of libroardsp a part of RoarAudio, |
---|
[2168] | 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
[2169] | 14 | * libroardsp is distributed in the hope that it will be useful, |
---|
[2168] | 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
[2169] | 25 | #include "libroardsp.h" |
---|
[2168] | 26 | |
---|
[2174] | 27 | #define _FUNC(func) (state->entry->func) |
---|
| 28 | #define _CHECK_STATE() (!(state == NULL || state->entry == NULL)) |
---|
| 29 | #define _CHECK_FUNC(func) (_CHECK_STATE() && _FUNC(func) != NULL) |
---|
| 30 | #define _CHECK_BASIC(func) if ( !_CHECK_FUNC(func) ) return -1 |
---|
| 31 | #define _CHECK() if ( !_CHECK_STATE() ) return -1 |
---|
| 32 | |
---|
| 33 | static struct roar_xcoder_entry g_xcoders[] = { |
---|
| 34 | {ROAR_CODEC_ALAW, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_packet_size_any, |
---|
| 35 | NULL, NULL}, |
---|
| 36 | {ROAR_CODEC_MULAW, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_packet_size_any, |
---|
| 37 | NULL, NULL}, |
---|
| 38 | {-1, NULL, NULL, NULL, NULL, NULL} |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | int roar_xcoder_init(struct roar_xcoder * state, int encoder, struct roar_audio_info * info, struct roar_vio_calls * vio); |
---|
| 42 | int roar_xcoder_set_backend(struct roar_xcoder * state, struct roar_vio_calls * vio) { |
---|
| 43 | _CHECK(); |
---|
| 44 | |
---|
| 45 | if ( vio == NULL && state->backend != NULL ) |
---|
| 46 | return -1; |
---|
| 47 | |
---|
| 48 | state->backend = vio; |
---|
| 49 | |
---|
| 50 | return 0; |
---|
| 51 | } |
---|
| 52 | int roar_xcoder_packet_size(struct roar_xcoder * state, int samples) { |
---|
| 53 | _CHECK_BASIC(packet_size); |
---|
| 54 | |
---|
| 55 | state->packet_len = state->entry->packet_size(state, samples); |
---|
| 56 | |
---|
| 57 | if ( state->packet_len == 0 ) { |
---|
| 58 | if ( samples < 1 ) { |
---|
| 59 | return ROAR_RATE_DEFAULT/100; |
---|
| 60 | } else { |
---|
| 61 | return samples; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | return state->packet_len; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | int roar_xcoder_close (struct roar_xcoder * state) { |
---|
| 69 | _CHECK_BASIC(uninit); |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | if ( state->iobuffer != NULL ) { |
---|
| 73 | roar_xcoder_proc(state, NULL, 0); // try to flush |
---|
| 74 | roar_buffer_free(state->iobuffer); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | return _FUNC(uninit)(state); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | int roar_xcoder_proc_packet(struct roar_xcoder * state, void * buf, size_t len); |
---|
| 81 | int roar_xcoder_proc (struct roar_xcoder * state, void * buf, size_t len) { |
---|
| 82 | return -1; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | int roar_bixcoder_init(struct roar_bixcoder * state, struct roar_audio_info * info, struct roar_vio_calls * vio); |
---|
| 86 | int roar_bixcoder_packet_size (struct roar_bixcoder * state, int samples); |
---|
| 87 | int roar_bixcoder_close (struct roar_bixcoder * state); |
---|
| 88 | int roar_bixcoder_read_packet (struct roar_bixcoder * state, void * buf, size_t len); |
---|
| 89 | int roar_bixcoder_read (struct roar_bixcoder * state, void * buf, size_t len); |
---|
| 90 | int roar_bixcoder_write_packet(struct roar_bixcoder * state, void * buf, size_t len); |
---|
| 91 | int roar_bixcoder_write (struct roar_bixcoder * state, void * buf, size_t len); |
---|
| 92 | |
---|
| 93 | // dummy functions used by some de/encoders: |
---|
| 94 | int roar_xcoder_dummy_inituninit(struct roar_xcoder * state) { |
---|
| 95 | return 0; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | int roar_xcoder_dummy_packet_size_any(struct roar_xcoder * state, int samples) { |
---|
| 99 | // the case samples=-1/samples!=-1 based things are done in the general func |
---|
| 100 | return 0; |
---|
| 101 | } |
---|
[2168] | 102 | |
---|
| 103 | //ll |
---|