source: roaraudio/roard/codecfilter.c @ 1195:66d00542e9a7

Last change on this file since 1195:66d00542e9a7 was 1185:be5dce10bf4b, checked in by phi, 15 years ago

only include vorbisfile.h if needed, should suppress some warnings

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