//codecfilter.c: #include "roard.h" struct roar_codecfilter g_codecfilter[] = { {-1, "null", "null codec filter", NULL, NULL, NULL, NULL, NULL, NULL, NULL}, {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, cf_wave_open, cf_wave_close, NULL, NULL, cf_wave_read, NULL}, {ROAR_CODEC_OGG_GENERAL, "cmd", "ogg123", "ogg123 -q -d raw -f - -", cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, #ifdef ROAR_HAVE_LIBVORBISFILE {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL}, #endif {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth", "timidity -Or1sl -s %R -o - -", cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, #ifdef ROAR_HAVE_LIBCELT {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, cf_celt_open, cf_celt_close, NULL, NULL, cf_celt_read, NULL}, #endif #ifdef ROAR_HAVE_LIBSPEEX {ROAR_CODEC_ROAR_SPEEX, "RoarSPEEX", "RoarAudio SPEEX", NULL, cf_speex_open, cf_speex_close, NULL, NULL, cf_speex_read, NULL}, #endif {ROAR_CODEC_FLAC, "cmd", "ogg123", #if BYTE_ORDER == BIG_ENDIAN "flac --silent --force-raw-format --sign=signed --endian=big -d - -o -", #elif BYTE_ORDER == LITTLE_ENDIAN "flac --silent --force-raw-format --sign=signed --endian=little -d - -o -", #else "false", #endif cf_cmd_open, NULL, NULL, NULL, NULL, NULL}, {-1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list }; void print_codecfilterlist (void) { int i; for (i = 0; g_codecfilter[i].name != NULL; i++) { printf(" %-12s %-12s - %s\n", roar_codec2str(g_codecfilter[i].codec), g_codecfilter[i].name, g_codecfilter[i].desc ); } } int codecfilter_open (CODECFILTER_USERDATA_T * inst, int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */, int codec, struct roar_stream_server * info) { int i; struct roar_codecfilter * filter = NULL; *codecfilter_id = -1; ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id); for (i = 0; g_codecfilter[i].name != NULL; i++) { if ( g_codecfilter[i].codec == codec ) { if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) { *codecfilter_id = i; filter = &g_codecfilter[i]; break; } } } info->codecfilter = *codecfilter_id; if (*codecfilter_id != -1) { if ( filter->open ) { if ( (i = filter->open(inst, codec, info, filter)) == -1 ) { info->codecfilter = *codecfilter_id = -1; } return i; } return 0; } return 0; // we found no filter -> ok } int codecfilter_close(CODECFILTER_USERDATA_T inst, int codecfilter) { ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter); if ( codecfilter == -1 ) return -1; if ( g_codecfilter[codecfilter].close ) return g_codecfilter[codecfilter].close(inst); return 0; } int codecfilter_pause(CODECFILTER_USERDATA_T inst, int codecfilter, int newstate) { if ( codecfilter == -1 ) return -1; if ( g_codecfilter[codecfilter].pause ) return g_codecfilter[codecfilter].pause(inst, newstate); return 0; } int codecfilter_write(CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { if ( codecfilter == -1 ) return -1; if ( g_codecfilter[codecfilter].write ) return g_codecfilter[codecfilter].write(inst, buf, len); return 0; } int codecfilter_read (CODECFILTER_USERDATA_T inst, int codecfilter, char * buf, int len) { if ( codecfilter == -1 ) return -1; errno = 0; if ( g_codecfilter[codecfilter].read ) return g_codecfilter[codecfilter].read(inst, buf, len); return 0; } int codecfilter_flush(CODECFILTER_USERDATA_T inst, int codecfilter) { if ( codecfilter == -1 ) return -1; if ( g_codecfilter[codecfilter].flush ) return g_codecfilter[codecfilter].flush(inst); return 0; } //ll