[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 | |
---|
[1185] | 25 | #define ROAR_REQUIRE_LIBVORBISFILE |
---|
| 26 | |
---|
[169] | 27 | #include "roard.h" |
---|
| 28 | |
---|
[1481] | 29 | #ifndef ROAR_WITHOUT_CF_CMD |
---|
| 30 | #if !defined(ROAR_HAVE_UNIX) || !defined(ROAR_HAVE_BSDSOCKETS) || !defined(ROAR_HAVE_IO_POSIX) |
---|
| 31 | #define ROAR_WITHOUT_CF_CMD |
---|
| 32 | #endif |
---|
| 33 | #endif |
---|
| 34 | |
---|
[173] | 35 | struct roar_codecfilter g_codecfilter[] = { |
---|
[2679] | 36 | {-1, "null", "null codec filter", NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE, |
---|
[1223] | 37 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, |
---|
[201] | 38 | |
---|
[1012] | 39 | /* |
---|
[851] | 40 | #ifdef ROAR_HAVE_LIBSNDFILE |
---|
[1012] | 41 | {ROAR_CODEC_RIFF_WAVE, "sndfile", "libsndfile codec filter", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 42 | cf_sndfile_open, cf_sndfile_close, NULL, cf_sndfile_write, cf_sndfile_read, NULL}, |
---|
[851] | 43 | #else |
---|
[1012] | 44 | */ |
---|
[2505] | 45 | #ifndef ROAR_WITHOUT_CF_WAVE |
---|
[2679] | 46 | {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, NULL, |
---|
| 47 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, ROAR_SUBSYS_WAVEFORM, |
---|
[2604] | 48 | cf_wave_open, cf_wave_close, NULL, cf_wave_write, cf_wave_read, NULL, NULL, cf_wave_ctl}, |
---|
[2505] | 49 | #endif |
---|
[1012] | 50 | //#endif |
---|
[561] | 51 | |
---|
[2686] | 52 | #ifdef ROAR_HAVE_LIBRAUM |
---|
[2690] | 53 | {ROAR_CODEC_RAUM, "RAUM", "RAUM Container Format", NULL, cf_raum_setup, ROAR_CODECFILTER_WRITE, |
---|
[2686] | 54 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX, |
---|
[2701] | 55 | cont_fw_cf_open, cont_fw_cf_close, NULL, cont_fw_cf_write, cont_fw_cf_read, cont_fw_cf_flush, NULL, cont_fw_cf_ctl}, |
---|
[2686] | 56 | #endif |
---|
| 57 | |
---|
[1065] | 58 | #ifdef ROAR_SUPPORT_ALAW |
---|
[2679] | 59 | {ROAR_CODEC_ALAW, "alaw", "A-Law", NULL, NULL, |
---|
[1065] | 60 | #ifdef ROAR_SUPPORT_ALAW_RW |
---|
| 61 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 62 | #else |
---|
| 63 | ROAR_CODECFILTER_READ, |
---|
| 64 | #endif |
---|
[2679] | 65 | ROAR_SUBSYS_WAVEFORM, |
---|
[1065] | 66 | cf_alaw_open, cf_alaw_close, NULL, |
---|
| 67 | #ifdef ROAR_SUPPORT_ALAW_RW |
---|
| 68 | cf_alaw_write, |
---|
| 69 | #else |
---|
| 70 | NULL, |
---|
| 71 | #endif |
---|
[1223] | 72 | cf_alaw_read, NULL, cf_alaw_delay, NULL}, |
---|
[1065] | 73 | #endif |
---|
[736] | 74 | |
---|
[1065] | 75 | #ifdef ROAR_SUPPORT_MULAW |
---|
[2679] | 76 | {ROAR_CODEC_MULAW, "mulaw", "mu-Law", NULL, NULL, |
---|
[1065] | 77 | #ifdef ROAR_SUPPORT_MULAW_RW |
---|
| 78 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 79 | #else |
---|
| 80 | ROAR_CODECFILTER_READ, |
---|
| 81 | #endif |
---|
[2679] | 82 | ROAR_SUBSYS_WAVEFORM, |
---|
[1065] | 83 | cf_mulaw_open, cf_mulaw_close, NULL, |
---|
| 84 | #ifdef ROAR_SUPPORT_MULAW_RW |
---|
| 85 | cf_mulaw_write, |
---|
| 86 | #else |
---|
| 87 | NULL, |
---|
| 88 | #endif |
---|
[1223] | 89 | cf_mulaw_read, NULL, cf_alaw_delay, NULL}, |
---|
[1065] | 90 | #endif |
---|
[922] | 91 | |
---|
[1199] | 92 | #ifndef ROAR_WITHOUT_CF_CMD |
---|
[749] | 93 | #ifdef ROAR_HAVE_BIN_OGG123 |
---|
[201] | 94 | {ROAR_CODEC_OGG_GENERAL, "cmd", "ogg123", |
---|
[2679] | 95 | ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 96 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[749] | 97 | #endif |
---|
[1199] | 98 | #endif |
---|
[201] | 99 | |
---|
[362] | 100 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
[2679] | 101 | {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, NULL, |
---|
[612] | 102 | #ifdef ROAR_HAVE_LIBVORBISENC |
---|
| 103 | ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 104 | #else |
---|
| 105 | ROAR_CODECFILTER_READ, |
---|
| 106 | #endif |
---|
[2679] | 107 | ROAR_SUBSYS_WAVEFORM, |
---|
[1238] | 108 | cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL, codecfilter_delay_fulldyn, cf_vorbis_ctl}, |
---|
[976] | 109 | #else |
---|
[1199] | 110 | #ifndef ROAR_WITHOUT_CF_CMD |
---|
[976] | 111 | #ifdef ROAR_HAVE_BIN_OGG123 |
---|
| 112 | {ROAR_CODEC_OGG_VORBIS, "cmd", "ogg123", |
---|
[2679] | 113 | ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 114 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[976] | 115 | #endif |
---|
[362] | 116 | #endif |
---|
[1199] | 117 | #endif |
---|
[205] | 118 | |
---|
[994] | 119 | #ifdef ROAR_HAVE_LIBFISHSOUND |
---|
[998] | 120 | {ROAR_CODEC_OGG_SPEEX, "fishsound", "libfishsound Xiph Codec library", |
---|
[2679] | 121 | NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 122 | cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[995] | 123 | |
---|
[998] | 124 | {ROAR_CODEC_OGG_FLAC, "fishsound", "libfishsound Xiph Codec library", |
---|
[2679] | 125 | NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 126 | cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[994] | 127 | #endif |
---|
| 128 | |
---|
[1199] | 129 | #ifndef ROAR_WITHOUT_CF_CMD |
---|
[749] | 130 | #ifdef ROAR_HAVE_BIN_TIMIDITY |
---|
[221] | 131 | {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth", |
---|
[2679] | 132 | ROAR_HAVE_BIN_TIMIDITY " -Or1sl -s %R -o - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 133 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[749] | 134 | #endif |
---|
[1199] | 135 | #endif |
---|
[221] | 136 | |
---|
[361] | 137 | #ifdef ROAR_HAVE_LIBCELT |
---|
[2679] | 138 | {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 139 | ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 140 | cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL, cf_celt_delay, NULL}, |
---|
[361] | 141 | #endif |
---|
[330] | 142 | |
---|
[373] | 143 | #ifdef ROAR_HAVE_LIBSPEEX |
---|
[2679] | 144 | {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, |
---|
| 145 | ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 146 | cf_speex_open, cf_speex_close, NULL, cf_speex_write, cf_speex_read, NULL, NULL, NULL}, |
---|
[373] | 147 | #endif |
---|
| 148 | |
---|
[1199] | 149 | #ifndef ROAR_WITHOUT_CF_CMD |
---|
[749] | 150 | #ifdef ROAR_HAVE_BIN_FLAC |
---|
[612] | 151 | {ROAR_CODEC_FLAC, "cmd", "flac", |
---|
[201] | 152 | #if BYTE_ORDER == BIG_ENDIAN |
---|
[749] | 153 | ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=big -d - -o -", |
---|
[201] | 154 | #elif BYTE_ORDER == LITTLE_ENDIAN |
---|
[749] | 155 | ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=little -d - -o -", |
---|
[201] | 156 | #else |
---|
| 157 | "false", |
---|
| 158 | #endif |
---|
[2679] | 159 | NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM, |
---|
[1223] | 160 | cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL}, |
---|
[749] | 161 | #endif |
---|
[1199] | 162 | #endif |
---|
[179] | 163 | |
---|
[2679] | 164 | {-1, NULL, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE, |
---|
| 165 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list |
---|
[173] | 166 | }; |
---|
| 167 | |
---|
[175] | 168 | void print_codecfilterlist (void) { |
---|
| 169 | int i; |
---|
[613] | 170 | int flags; |
---|
| 171 | char mode[5]; |
---|
[1144] | 172 | char delay[6]; |
---|
[2680] | 173 | char subsys[7] = " "; |
---|
[1144] | 174 | uint_least32_t d; |
---|
[613] | 175 | |
---|
[2680] | 176 | printf(" Codec Filtername Mode Subsys Delay - Description\n"); |
---|
| 177 | printf("-------------------------------------------------------------\n"); |
---|
[175] | 178 | |
---|
| 179 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
[2680] | 180 | strncpy(subsys, " ", 6); |
---|
| 181 | |
---|
| 182 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 183 | subsys[0] = 'W'; |
---|
| 184 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 185 | subsys[1] = 'M'; |
---|
| 186 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_CB ) |
---|
| 187 | subsys[2] = 'C'; |
---|
| 188 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 189 | subsys[3] = 'L'; |
---|
| 190 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
| 191 | subsys[4] = 'R'; |
---|
[2681] | 192 | if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
| 193 | subsys[5] = 'X'; |
---|
[2680] | 194 | |
---|
[613] | 195 | flags = g_codecfilter[i].flags; |
---|
| 196 | |
---|
| 197 | if ( flags == ROAR_CODECFILTER_NONE ) { |
---|
| 198 | strcpy(mode, "none"); |
---|
| 199 | } else { |
---|
| 200 | strcpy(mode, " "); |
---|
| 201 | if ( flags & ROAR_CODECFILTER_READ ) |
---|
| 202 | mode[0] = 'r'; |
---|
| 203 | if ( flags & ROAR_CODECFILTER_WRITE ) |
---|
| 204 | mode[1] = 'w'; |
---|
| 205 | } |
---|
[1144] | 206 | |
---|
| 207 | *delay = 0; |
---|
| 208 | if ( g_codecfilter[i].codec == -1 ) { // null codec filter |
---|
| 209 | strcpy(delay, "0ms"); |
---|
| 210 | } else if ( g_codecfilter[i].delay == NULL ) { |
---|
| 211 | strcpy(delay, "?"); |
---|
| 212 | } else { |
---|
| 213 | if ( codecfilter_delay(NULL, i, &d) == -1 ) { |
---|
| 214 | strcpy(delay, "dyn"); |
---|
| 215 | } else { |
---|
| 216 | snprintf(delay, 5, "%ims", d/1000); |
---|
| 217 | } |
---|
| 218 | } |
---|
[613] | 219 | |
---|
[2680] | 220 | printf(" %-12s %-12s %-4s %6s %-5s - %s\n", |
---|
[178] | 221 | roar_codec2str(g_codecfilter[i].codec), |
---|
| 222 | g_codecfilter[i].name, |
---|
[613] | 223 | mode, |
---|
[2680] | 224 | subsys, |
---|
[1144] | 225 | delay, |
---|
[552] | 226 | g_codecfilter[i].desc |
---|
| 227 | ); |
---|
[175] | 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
[194] | 231 | int codecfilter_open (CODECFILTER_USERDATA_T * inst, |
---|
| 232 | int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */, |
---|
| 233 | int codec, struct roar_stream_server * info) { |
---|
| 234 | int i; |
---|
| 235 | struct roar_codecfilter * filter = NULL; |
---|
| 236 | |
---|
| 237 | *codecfilter_id = -1; |
---|
| 238 | |
---|
[486] | 239 | ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id); |
---|
| 240 | |
---|
[194] | 241 | for (i = 0; g_codecfilter[i].name != NULL; i++) { |
---|
[2693] | 242 | ROAR_DBG("codecfilter_open(*): g_codecfilter[i].codec <-> codec => %i <-> %i", g_codecfilter[i].codec, codec); |
---|
[194] | 243 | if ( g_codecfilter[i].codec == codec ) { |
---|
| 244 | if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) { |
---|
| 245 | *codecfilter_id = i; |
---|
| 246 | filter = &g_codecfilter[i]; |
---|
| 247 | break; |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | |
---|
[196] | 252 | info->codecfilter = *codecfilter_id; |
---|
[194] | 253 | |
---|
| 254 | if (*codecfilter_id != -1) { |
---|
[571] | 255 | if ( filter->open ) { |
---|
| 256 | if ( (i = filter->open(inst, codec, info, filter)) == -1 ) { |
---|
| 257 | info->codecfilter = *codecfilter_id = -1; |
---|
| 258 | } |
---|
| 259 | return i; |
---|
| 260 | } |
---|
[194] | 261 | return 0; |
---|
| 262 | } |
---|
| 263 | |
---|
[571] | 264 | return 0; // we found no filter -> ok |
---|
[194] | 265 | } |
---|
| 266 | |
---|
[180] | 267 | int codecfilter_close(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 268 | ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter); |
---|
| 269 | |
---|
| 270 | if ( codecfilter == -1 ) |
---|
| 271 | return -1; |
---|
| 272 | |
---|
| 273 | if ( g_codecfilter[codecfilter].close ) |
---|
| 274 | return g_codecfilter[codecfilter].close(inst); |
---|
| 275 | |
---|
| 276 | return 0; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | int codecfilter_pause(CODECFILTER_USERDATA_T inst, int codecfilter, int newstate) { |
---|
| 280 | if ( codecfilter == -1 ) |
---|
| 281 | return -1; |
---|
| 282 | |
---|
| 283 | if ( g_codecfilter[codecfilter].pause ) |
---|
| 284 | return g_codecfilter[codecfilter].pause(inst, newstate); |
---|
| 285 | |
---|
| 286 | return 0; |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | int codecfilter_write(CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 290 | if ( codecfilter == -1 ) |
---|
| 291 | return -1; |
---|
| 292 | |
---|
| 293 | if ( g_codecfilter[codecfilter].write ) |
---|
| 294 | return g_codecfilter[codecfilter].write(inst, buf, len); |
---|
| 295 | |
---|
| 296 | return 0; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | int codecfilter_read (CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { |
---|
| 300 | if ( codecfilter == -1 ) |
---|
| 301 | return -1; |
---|
| 302 | |
---|
[541] | 303 | errno = 0; |
---|
| 304 | |
---|
[180] | 305 | if ( g_codecfilter[codecfilter].read ) |
---|
| 306 | return g_codecfilter[codecfilter].read(inst, buf, len); |
---|
| 307 | |
---|
| 308 | return 0; |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | int codecfilter_flush(CODECFILTER_USERDATA_T inst, int codecfilter) { |
---|
| 312 | if ( codecfilter == -1 ) |
---|
| 313 | return -1; |
---|
| 314 | |
---|
| 315 | if ( g_codecfilter[codecfilter].flush ) |
---|
| 316 | return g_codecfilter[codecfilter].flush(inst); |
---|
| 317 | |
---|
| 318 | return 0; |
---|
| 319 | } |
---|
| 320 | |
---|
[1144] | 321 | int codecfilter_delay(CODECFILTER_USERDATA_T inst, int codecfilter, uint_least32_t * delay) { |
---|
| 322 | ROAR_DBG("codecfilter_delay(inst=%p, codecfilter=%i, *delay=?) = ?", inst, codecfilter); |
---|
| 323 | |
---|
| 324 | if ( codecfilter == -1 ) |
---|
| 325 | return -1; |
---|
| 326 | |
---|
| 327 | if ( g_codecfilter[codecfilter].delay ) |
---|
| 328 | return g_codecfilter[codecfilter].delay(inst, delay); |
---|
| 329 | |
---|
| 330 | return -1; |
---|
| 331 | } |
---|
| 332 | |
---|
[1224] | 333 | int codecfilter_ctl (CODECFILTER_USERDATA_T inst, int codecfilter, int_least32_t cmd, void * data) { |
---|
[2086] | 334 | ROAR_DBG("codecfilter_ctl(inst=%p, codecfilter=%i, cmd=0x%.8x, data=%p) = ?", inst, codecfilter, cmd, data); |
---|
[1224] | 335 | if ( codecfilter == -1 ) |
---|
| 336 | return -1; |
---|
| 337 | |
---|
| 338 | if ( g_codecfilter[codecfilter].ctl ) |
---|
| 339 | return g_codecfilter[codecfilter].ctl(inst, cmd, data); |
---|
| 340 | |
---|
| 341 | return -1; |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | |
---|
[1144] | 345 | int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T inst, uint_least32_t * delay) { |
---|
| 346 | *delay = 0; // just to be sure |
---|
| 347 | return -1; |
---|
| 348 | } |
---|
| 349 | |
---|
[169] | 350 | //ll |
---|