[169] | 1 | //codecfilter.c: |
---|
| 2 | |
---|
| 3 | #include "roard.h" |
---|
| 4 | |
---|
[173] | 5 | struct roar_codecfilter g_codecfilter[] = { |
---|
[179] | 6 | {-1, "null", "null codec filter", NULL, NULL, NULL, NULL, NULL, NULL, NULL}, |
---|
[201] | 7 | |
---|
[561] | 8 | {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, |
---|
| 9 | cf_wave_open, cf_wave_close, NULL, NULL, cf_wave_read, NULL}, |
---|
| 10 | |
---|
[201] | 11 | {ROAR_CODEC_OGG_GENERAL, "cmd", "ogg123", |
---|
| 12 | "ogg123 -q -d raw -f - -", |
---|
| 13 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, |
---|
| 14 | |
---|
[362] | 15 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
[205] | 16 | {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, |
---|
[582] | 17 | cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL}, |
---|
[362] | 18 | #endif |
---|
[205] | 19 | |
---|
[221] | 20 | {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth", |
---|
| 21 | "timidity -Or1sl -s %R -o - -", |
---|
| 22 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, |
---|
| 23 | |
---|
[361] | 24 | #ifdef ROAR_HAVE_LIBCELT |
---|
[330] | 25 | {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, |
---|
| 26 | cf_celt_open, cf_celt_close, NULL, NULL, cf_celt_read, NULL}, |
---|
[361] | 27 | #endif |
---|
[330] | 28 | |
---|
[373] | 29 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
[432] | 30 | {ROAR_CODEC_ROAR_SPEEX, "RoarSPEEX", "RoarAudio SPEEX", NULL, |
---|
[373] | 31 | cf_speex_open, cf_speex_close, NULL, NULL, cf_speex_read, NULL}, |
---|
| 32 | #endif |
---|
| 33 | |
---|
[201] | 34 | {ROAR_CODEC_FLAC, "cmd", "ogg123", |
---|
| 35 | #if BYTE_ORDER == BIG_ENDIAN |
---|
| 36 | "flac --silent --force-raw-format --sign=signed --endian=big -d - -o -", |
---|
| 37 | #elif BYTE_ORDER == LITTLE_ENDIAN |
---|
| 38 | "flac --silent --force-raw-format --sign=signed --endian=little -d - -o -", |
---|
| 39 | #else |
---|
| 40 | "false", |
---|
| 41 | #endif |
---|
| 42 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, |
---|
[179] | 43 | |
---|
| 44 | {-1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list |
---|
[173] | 45 | }; |
---|
| 46 | |
---|
[175] | 47 | void print_codecfilterlist (void) { |
---|
| 48 | int i; |
---|
| 49 | |
---|
| 50 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
[552] | 51 | printf(" %-12s %-12s - %s\n", |
---|
[178] | 52 | roar_codec2str(g_codecfilter[i].codec), |
---|
| 53 | g_codecfilter[i].name, |
---|
[552] | 54 | g_codecfilter[i].desc |
---|
| 55 | ); |
---|
[175] | 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
[194] | 59 | int codecfilter_open (CODECFILTER_USERDATA_T * inst, |
---|
| 60 | int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */, |
---|
| 61 | int codec, struct roar_stream_server * info) { |
---|
| 62 | int i; |
---|
| 63 | struct roar_codecfilter * filter = NULL; |
---|
| 64 | |
---|
| 65 | *codecfilter_id = -1; |
---|
| 66 | |
---|
[486] | 67 | ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id); |
---|
| 68 | |
---|
[194] | 69 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
| 70 | if ( g_codecfilter[i].codec == codec ) { |
---|
| 71 | if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) { |
---|
| 72 | *codecfilter_id = i; |
---|
| 73 | filter = &g_codecfilter[i]; |
---|
| 74 | break; |
---|
| 75 | } |
---|
| 76 | } |
---|
| 77 | } |
---|
| 78 | |
---|
[196] | 79 | info->codecfilter = *codecfilter_id; |
---|
[194] | 80 | |
---|
| 81 | if (*codecfilter_id != -1) { |
---|
[571] | 82 | if ( filter->open ) { |
---|
| 83 | if ( (i = filter->open(inst, codec, info, filter)) == -1 ) { |
---|
| 84 | info->codecfilter = *codecfilter_id = -1; |
---|
| 85 | } |
---|
| 86 | return i; |
---|
| 87 | } |
---|
[194] | 88 | return 0; |
---|
| 89 | } |
---|
| 90 | |
---|
[571] | 91 | return 0; // we found no filter -> ok |
---|
[194] | 92 | } |
---|
| 93 | |
---|
[180] | 94 | int codecfilter_close(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 95 | ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter); |
---|
| 96 | |
---|
| 97 | if ( codecfilter == -1 ) |
---|
| 98 | return -1; |
---|
| 99 | |
---|
| 100 | if ( g_codecfilter[codecfilter].close ) |
---|
| 101 | return g_codecfilter[codecfilter].close(inst); |
---|
| 102 | |
---|
| 103 | return 0; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | int codecfilter_pause(CODECFILTER_USERDATA_T inst, int codecfilter, int newstate) { |
---|
| 107 | if ( codecfilter == -1 ) |
---|
| 108 | return -1; |
---|
| 109 | |
---|
| 110 | if ( g_codecfilter[codecfilter].pause ) |
---|
| 111 | return g_codecfilter[codecfilter].pause(inst, newstate); |
---|
| 112 | |
---|
| 113 | return 0; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | int codecfilter_write(CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 117 | if ( codecfilter == -1 ) |
---|
| 118 | return -1; |
---|
| 119 | |
---|
| 120 | if ( g_codecfilter[codecfilter].write ) |
---|
| 121 | return g_codecfilter[codecfilter].write(inst, buf, len); |
---|
| 122 | |
---|
| 123 | return 0; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | int codecfilter_read (CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 127 | if ( codecfilter == -1 ) |
---|
| 128 | return -1; |
---|
| 129 | |
---|
[541] | 130 | errno = 0; |
---|
| 131 | |
---|
[180] | 132 | if ( g_codecfilter[codecfilter].read ) |
---|
| 133 | return g_codecfilter[codecfilter].read(inst, buf, len); |
---|
| 134 | |
---|
| 135 | return 0; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | int codecfilter_flush(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 139 | if ( codecfilter == -1 ) |
---|
| 140 | return -1; |
---|
| 141 | |
---|
| 142 | if ( g_codecfilter[codecfilter].flush ) |
---|
| 143 | return g_codecfilter[codecfilter].flush(inst); |
---|
| 144 | |
---|
| 145 | return 0; |
---|
| 146 | } |
---|
| 147 | |
---|
[169] | 148 | //ll |
---|