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