source: roaraudio/roard/codecfilter.c @ 2505:890cd5d87269

Last change on this file since 2505:890cd5d87269 was 2505:890cd5d87269, checked in by phi, 15 years ago

make cf wave optional

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