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