source: roaraudio/roard/codecfilter.c @ 2680:6b94b1c1fc6b

Last change on this file since 2680:6b94b1c1fc6b was 2680:6b94b1c1fc6b, checked in by phi, 15 years ago

added info about subsystems to list

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