[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, |
---|
| 17 | cf_vorbis_open, cf_vorbis_close, NULL, NULL, 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) { |
---|
| 82 | if ( filter->open ) |
---|
| 83 | return filter->open(inst, codec, info, filter); |
---|
| 84 | return 0; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | return -1; |
---|
| 88 | } |
---|
| 89 | |
---|
[180] | 90 | int codecfilter_close(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 91 | ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter); |
---|
| 92 | |
---|
| 93 | if ( codecfilter == -1 ) |
---|
| 94 | return -1; |
---|
| 95 | |
---|
| 96 | if ( g_codecfilter[codecfilter].close ) |
---|
| 97 | return g_codecfilter[codecfilter].close(inst); |
---|
| 98 | |
---|
| 99 | return 0; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | int codecfilter_pause(CODECFILTER_USERDATA_T inst, int codecfilter, int newstate) { |
---|
| 103 | if ( codecfilter == -1 ) |
---|
| 104 | return -1; |
---|
| 105 | |
---|
| 106 | if ( g_codecfilter[codecfilter].pause ) |
---|
| 107 | return g_codecfilter[codecfilter].pause(inst, newstate); |
---|
| 108 | |
---|
| 109 | return 0; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | int codecfilter_write(CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 113 | if ( codecfilter == -1 ) |
---|
| 114 | return -1; |
---|
| 115 | |
---|
| 116 | if ( g_codecfilter[codecfilter].write ) |
---|
| 117 | return g_codecfilter[codecfilter].write(inst, buf, len); |
---|
| 118 | |
---|
| 119 | return 0; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | int codecfilter_read (CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 123 | if ( codecfilter == -1 ) |
---|
| 124 | return -1; |
---|
| 125 | |
---|
[541] | 126 | errno = 0; |
---|
| 127 | |
---|
[180] | 128 | if ( g_codecfilter[codecfilter].read ) |
---|
| 129 | return g_codecfilter[codecfilter].read(inst, buf, len); |
---|
| 130 | |
---|
| 131 | return 0; |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | int codecfilter_flush(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 135 | if ( codecfilter == -1 ) |
---|
| 136 | return -1; |
---|
| 137 | |
---|
| 138 | if ( g_codecfilter[codecfilter].flush ) |
---|
| 139 | return g_codecfilter[codecfilter].flush(inst); |
---|
| 140 | |
---|
| 141 | return 0; |
---|
| 142 | } |
---|
| 143 | |
---|
[169] | 144 | //ll |
---|