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