source: roaraudio/roard/codecfilter.c @ 1481:30246a17e3d5

Last change on this file since 1481:30246a17e3d5 was 1481:30246a17e3d5, checked in by phi, 15 years ago

update list of CFs

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