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