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