[169] | 1 | //codecfilter.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 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 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 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 | |
---|
[169] | 25 | #include "roard.h" |
---|
| 26 | |
---|
[173] | 27 | struct roar_codecfilter g_codecfilter[] = { |
---|
[1144] | 28 | {-1, "null", "null codec filter", NULL, ROAR_CODECFILTER_NONE, |
---|
| 29 | NULL, NULL, NULL, NULL, NULL, NULL, NULL}, |
---|
[201] | 30 | |
---|
[1012] | 31 | /* |
---|
[851] | 32 | #ifdef ROAR_HAVE_LIBSNDFILE |
---|
[1012] | 33 | {ROAR_CODEC_RIFF_WAVE, "sndfile", "libsndfile codec filter", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 34 | cf_sndfile_open, cf_sndfile_close, NULL, cf_sndfile_write, cf_sndfile_read, NULL}, |
---|
[851] | 35 | #else |
---|
[1012] | 36 | */ |
---|
[1021] | 37 | {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
[1144] | 38 | cf_wave_open, cf_wave_close, NULL, cf_wave_write, cf_wave_read, NULL, NULL}, |
---|
[1012] | 39 | //#endif |
---|
[561] | 40 | |
---|
[1065] | 41 | #ifdef ROAR_SUPPORT_ALAW |
---|
| 42 | {ROAR_CODEC_ALAW, "alaw", "A-Law", NULL, |
---|
| 43 | #ifdef ROAR_SUPPORT_ALAW_RW |
---|
| 44 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 45 | #else |
---|
| 46 | ROAR_CODECFILTER_READ, |
---|
| 47 | #endif |
---|
| 48 | cf_alaw_open, cf_alaw_close, NULL, |
---|
| 49 | #ifdef ROAR_SUPPORT_ALAW_RW |
---|
| 50 | cf_alaw_write, |
---|
| 51 | #else |
---|
| 52 | NULL, |
---|
| 53 | #endif |
---|
[1144] | 54 | cf_alaw_read, NULL, cf_alaw_delay}, |
---|
[1065] | 55 | #endif |
---|
[736] | 56 | |
---|
[1065] | 57 | #ifdef ROAR_SUPPORT_MULAW |
---|
| 58 | {ROAR_CODEC_MULAW, "mulaw", "mu-Law", NULL, |
---|
| 59 | #ifdef ROAR_SUPPORT_MULAW_RW |
---|
| 60 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 61 | #else |
---|
| 62 | ROAR_CODECFILTER_READ, |
---|
| 63 | #endif |
---|
| 64 | cf_mulaw_open, cf_mulaw_close, NULL, |
---|
| 65 | #ifdef ROAR_SUPPORT_MULAW_RW |
---|
| 66 | cf_mulaw_write, |
---|
| 67 | #else |
---|
| 68 | NULL, |
---|
| 69 | #endif |
---|
[1144] | 70 | cf_mulaw_read, NULL, cf_alaw_delay}, |
---|
[1065] | 71 | #endif |
---|
[922] | 72 | |
---|
[749] | 73 | #ifdef ROAR_HAVE_BIN_OGG123 |
---|
[201] | 74 | {ROAR_CODEC_OGG_GENERAL, "cmd", "ogg123", |
---|
[749] | 75 | ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", ROAR_CODECFILTER_READ, |
---|
[1144] | 76 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn}, |
---|
[749] | 77 | #endif |
---|
[201] | 78 | |
---|
[362] | 79 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
[205] | 80 | {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, |
---|
[612] | 81 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 82 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 83 | #else |
---|
| 84 | ROAR_CODECFILTER_READ, |
---|
| 85 | #endif |
---|
[1144] | 86 | cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL, codecfilter_delay_fulldyn}, |
---|
[976] | 87 | #else |
---|
| 88 | #ifdef ROAR_HAVE_BIN_OGG123 |
---|
| 89 | {ROAR_CODEC_OGG_VORBIS, "cmd", "ogg123", |
---|
| 90 | ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", ROAR_CODECFILTER_READ, |
---|
[1144] | 91 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn}, |
---|
[976] | 92 | #endif |
---|
[362] | 93 | #endif |
---|
[205] | 94 | |
---|
[994] | 95 | #ifdef ROAR_HAVE_LIBFISHSOUND |
---|
[998] | 96 | {ROAR_CODEC_OGG_SPEEX, "fishsound", "libfishsound Xiph Codec library", |
---|
[994] | 97 | NULL, ROAR_CODECFILTER_READ, |
---|
[1144] | 98 | cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn}, |
---|
[995] | 99 | |
---|
[998] | 100 | {ROAR_CODEC_OGG_FLAC, "fishsound", "libfishsound Xiph Codec library", |
---|
[995] | 101 | NULL, ROAR_CODECFILTER_READ, |
---|
[1144] | 102 | cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn}, |
---|
[994] | 103 | #endif |
---|
| 104 | |
---|
[749] | 105 | #ifdef ROAR_HAVE_BIN_TIMIDITY |
---|
[221] | 106 | {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth", |
---|
[749] | 107 | ROAR_HAVE_BIN_TIMIDITY " -Or1sl -s %R -o - -", ROAR_CODECFILTER_READ, |
---|
[1144] | 108 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn}, |
---|
[749] | 109 | #endif |
---|
[221] | 110 | |
---|
[361] | 111 | #ifdef ROAR_HAVE_LIBCELT |
---|
[612] | 112 | {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
[1144] | 113 | cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL, cf_celt_delay}, |
---|
[361] | 114 | #endif |
---|
[330] | 115 | |
---|
[373] | 116 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
[621] | 117 | {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
[1144] | 118 | cf_speex_open, cf_speex_close, NULL, cf_speex_write, cf_speex_read, NULL, NULL}, |
---|
[373] | 119 | #endif |
---|
| 120 | |
---|
[749] | 121 | #ifdef ROAR_HAVE_BIN_FLAC |
---|
[612] | 122 | {ROAR_CODEC_FLAC, "cmd", "flac", |
---|
[201] | 123 | #if BYTE_ORDER == BIG_ENDIAN |
---|
[749] | 124 | ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=big -d - -o -", |
---|
[201] | 125 | #elif BYTE_ORDER == LITTLE_ENDIAN |
---|
[749] | 126 | ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=little -d - -o -", |
---|
[201] | 127 | #else |
---|
| 128 | "false", |
---|
| 129 | #endif |
---|
[612] | 130 | ROAR_CODECFILTER_READ, |
---|
[1144] | 131 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn}, |
---|
[749] | 132 | #endif |
---|
[179] | 133 | |
---|
[1144] | 134 | {-1, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list |
---|
[173] | 135 | }; |
---|
| 136 | |
---|
[175] | 137 | void print_codecfilterlist (void) { |
---|
| 138 | int i; |
---|
[613] | 139 | int flags; |
---|
| 140 | char mode[5]; |
---|
[1144] | 141 | char delay[6]; |
---|
| 142 | uint_least32_t d; |
---|
[613] | 143 | |
---|
[1144] | 144 | printf(" Codec Filtername Mode Delay - Description\n"); |
---|
[613] | 145 | printf("------------------------------------------------------\n"); |
---|
[175] | 146 | |
---|
| 147 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
[613] | 148 | flags = g_codecfilter[i].flags; |
---|
| 149 | |
---|
| 150 | if ( flags == ROAR_CODECFILTER_NONE ) { |
---|
| 151 | strcpy(mode, "none"); |
---|
| 152 | } else { |
---|
| 153 | strcpy(mode, " "); |
---|
| 154 | if ( flags & ROAR_CODECFILTER_READ ) |
---|
| 155 | mode[0] = 'r'; |
---|
| 156 | if ( flags & ROAR_CODECFILTER_WRITE ) |
---|
| 157 | mode[1] = 'w'; |
---|
| 158 | } |
---|
[1144] | 159 | |
---|
| 160 | *delay = 0; |
---|
| 161 | if ( g_codecfilter[i].codec == -1 ) { // null codec filter |
---|
| 162 | strcpy(delay, "0ms"); |
---|
| 163 | } else if ( g_codecfilter[i].delay == NULL ) { |
---|
| 164 | strcpy(delay, "?"); |
---|
| 165 | } else { |
---|
| 166 | if ( codecfilter_delay(NULL, i, &d) == -1 ) { |
---|
| 167 | strcpy(delay, "dyn"); |
---|
| 168 | } else { |
---|
| 169 | snprintf(delay, 5, "%ims", d/1000); |
---|
| 170 | } |
---|
| 171 | } |
---|
[613] | 172 | |
---|
[1144] | 173 | printf(" %-12s %-12s %-4s %-5s - %s\n", |
---|
[178] | 174 | roar_codec2str(g_codecfilter[i].codec), |
---|
| 175 | g_codecfilter[i].name, |
---|
[613] | 176 | mode, |
---|
[1144] | 177 | delay, |
---|
[552] | 178 | g_codecfilter[i].desc |
---|
| 179 | ); |
---|
[175] | 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
[194] | 183 | int codecfilter_open (CODECFILTER_USERDATA_T * inst, |
---|
| 184 | int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */, |
---|
| 185 | int codec, struct roar_stream_server * info) { |
---|
| 186 | int i; |
---|
| 187 | struct roar_codecfilter * filter = NULL; |
---|
| 188 | |
---|
| 189 | *codecfilter_id = -1; |
---|
| 190 | |
---|
[486] | 191 | ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id); |
---|
| 192 | |
---|
[194] | 193 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
| 194 | if ( g_codecfilter[i].codec == codec ) { |
---|
| 195 | if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) { |
---|
| 196 | *codecfilter_id = i; |
---|
| 197 | filter = &g_codecfilter[i]; |
---|
| 198 | break; |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
[196] | 203 | info->codecfilter = *codecfilter_id; |
---|
[194] | 204 | |
---|
| 205 | if (*codecfilter_id != -1) { |
---|
[571] | 206 | if ( filter->open ) { |
---|
| 207 | if ( (i = filter->open(inst, codec, info, filter)) == -1 ) { |
---|
| 208 | info->codecfilter = *codecfilter_id = -1; |
---|
| 209 | } |
---|
| 210 | return i; |
---|
| 211 | } |
---|
[194] | 212 | return 0; |
---|
| 213 | } |
---|
| 214 | |
---|
[571] | 215 | return 0; // we found no filter -> ok |
---|
[194] | 216 | } |
---|
| 217 | |
---|
[180] | 218 | int codecfilter_close(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 219 | ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter); |
---|
| 220 | |
---|
| 221 | if ( codecfilter == -1 ) |
---|
| 222 | return -1; |
---|
| 223 | |
---|
| 224 | if ( g_codecfilter[codecfilter].close ) |
---|
| 225 | return g_codecfilter[codecfilter].close(inst); |
---|
| 226 | |
---|
| 227 | return 0; |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | int codecfilter_pause(CODECFILTER_USERDATA_T inst, int codecfilter, int newstate) { |
---|
| 231 | if ( codecfilter == -1 ) |
---|
| 232 | return -1; |
---|
| 233 | |
---|
| 234 | if ( g_codecfilter[codecfilter].pause ) |
---|
| 235 | return g_codecfilter[codecfilter].pause(inst, newstate); |
---|
| 236 | |
---|
| 237 | return 0; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | int codecfilter_write(CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 241 | if ( codecfilter == -1 ) |
---|
| 242 | return -1; |
---|
| 243 | |
---|
| 244 | if ( g_codecfilter[codecfilter].write ) |
---|
| 245 | return g_codecfilter[codecfilter].write(inst, buf, len); |
---|
| 246 | |
---|
| 247 | return 0; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | int codecfilter_read (CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 251 | if ( codecfilter == -1 ) |
---|
| 252 | return -1; |
---|
| 253 | |
---|
[541] | 254 | errno = 0; |
---|
| 255 | |
---|
[180] | 256 | if ( g_codecfilter[codecfilter].read ) |
---|
| 257 | return g_codecfilter[codecfilter].read(inst, buf, len); |
---|
| 258 | |
---|
| 259 | return 0; |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | int codecfilter_flush(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 263 | if ( codecfilter == -1 ) |
---|
| 264 | return -1; |
---|
| 265 | |
---|
| 266 | if ( g_codecfilter[codecfilter].flush ) |
---|
| 267 | return g_codecfilter[codecfilter].flush(inst); |
---|
| 268 | |
---|
| 269 | return 0; |
---|
| 270 | } |
---|
| 271 | |
---|
[1144] | 272 | int codecfilter_delay(CODECFILTER_USERDATA_T inst, int codecfilter, uint_least32_t * delay) { |
---|
| 273 | ROAR_DBG("codecfilter_delay(inst=%p, codecfilter=%i, *delay=?) = ?", inst, codecfilter); |
---|
| 274 | |
---|
| 275 | if ( codecfilter == -1 ) |
---|
| 276 | return -1; |
---|
| 277 | |
---|
| 278 | if ( g_codecfilter[codecfilter].delay ) |
---|
| 279 | return g_codecfilter[codecfilter].delay(inst, delay); |
---|
| 280 | |
---|
| 281 | return -1; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T inst, uint_least32_t * delay) { |
---|
| 285 | *delay = 0; // just to be sure |
---|
| 286 | return -1; |
---|
| 287 | } |
---|
| 288 | |
---|
[169] | 289 | //ll |
---|