source: roaraudio/roard/codecfilter.c @ 2681:359a85bcf5e9

Last change on this file since 2681:359a85bcf5e9 was 2681:359a85bcf5e9, checked in by phi, 15 years ago

added new subsystem complex

File size: 10.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[] = {
[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';
[2681]186  if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_COMPLEX )
187   subsys[5] = 'X';
[2680]188
[613]189  flags = g_codecfilter[i].flags;
190
191  if ( flags == ROAR_CODECFILTER_NONE ) {
192   strcpy(mode, "none");
193  } else {
194   strcpy(mode, "    ");
195   if ( flags & ROAR_CODECFILTER_READ )
196    mode[0] = 'r';
197   if ( flags & ROAR_CODECFILTER_WRITE )
198    mode[1] = 'w';
199  }
[1144]200
201  *delay = 0;
202  if ( g_codecfilter[i].codec == -1 ) { // null codec filter
203   strcpy(delay, "0ms");
204  } else if ( g_codecfilter[i].delay == NULL ) {
205   strcpy(delay, "?");
206  } else {
207   if ( codecfilter_delay(NULL, i, &d) == -1 ) {
208    strcpy(delay, "dyn");
209   } else {
210    snprintf(delay, 5, "%ims", d/1000);
211   }
212  }
[613]213 
[2680]214  printf("  %-12s %-12s %-4s %6s %-5s - %s\n",
[178]215             roar_codec2str(g_codecfilter[i].codec),
216             g_codecfilter[i].name,
[613]217             mode,
[2680]218             subsys,
[1144]219             delay,
[552]220             g_codecfilter[i].desc
221             );
[175]222 }
223}
224
[194]225int codecfilter_open (CODECFILTER_USERDATA_T * inst,
226                 int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */,
227                 int codec, struct roar_stream_server * info) {
228 int i;
229 struct roar_codecfilter   * filter = NULL;
230
231 *codecfilter_id = -1;
232
[486]233 ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id);
234
[194]235 for (i = 0; g_codecfilter[i].name != NULL; i++) {
236  if ( g_codecfilter[i].codec == codec ) {
237   if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) {
238    *codecfilter_id = i;
239    filter = &g_codecfilter[i];
240    break;
241   }
242  }
243 }
244
[196]245 info->codecfilter = *codecfilter_id;
[194]246
247 if (*codecfilter_id != -1) {
[571]248  if ( filter->open ) {
249   if ( (i = filter->open(inst, codec, info, filter)) == -1 ) {
250    info->codecfilter = *codecfilter_id = -1;
251   }
252   return i;
253  }
[194]254  return 0;
255 }
256
[571]257 return 0; // we found no filter -> ok
[194]258}
259
[180]260int codecfilter_close(CODECFILTER_USERDATA_T   inst, int codecfilter) {
261 ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter);
262
263 if ( codecfilter == -1 )
264  return -1;
265
266 if ( g_codecfilter[codecfilter].close )
267  return g_codecfilter[codecfilter].close(inst);
268
269 return 0;
270}
271
272int codecfilter_pause(CODECFILTER_USERDATA_T   inst, int codecfilter, int newstate) {
273 if ( codecfilter == -1 )
274  return -1;
275
276 if ( g_codecfilter[codecfilter].pause )
277  return g_codecfilter[codecfilter].pause(inst, newstate);
278
279 return 0;
280}
281
282int codecfilter_write(CODECFILTER_USERDATA_T   inst, int codecfilter, char * buf, int len) {
283 if ( codecfilter == -1 )
284  return -1;
285
286 if ( g_codecfilter[codecfilter].write )
287  return g_codecfilter[codecfilter].write(inst, buf, len);
288
289 return 0;
290}
291
292int codecfilter_read (CODECFILTER_USERDATA_T   inst, int codecfilter, char * buf, int len) {
293 if ( codecfilter == -1 )
294  return -1;
295
[541]296 errno = 0;
297
[180]298 if ( g_codecfilter[codecfilter].read )
299  return g_codecfilter[codecfilter].read(inst, buf, len);
300
301 return 0;
302}
303
304int codecfilter_flush(CODECFILTER_USERDATA_T   inst, int codecfilter) {
305 if ( codecfilter == -1 )
306  return -1;
307
308 if ( g_codecfilter[codecfilter].flush )
309  return g_codecfilter[codecfilter].flush(inst);
310
311 return 0;
312}
313
[1144]314int codecfilter_delay(CODECFILTER_USERDATA_T   inst, int codecfilter, uint_least32_t * delay) {
315 ROAR_DBG("codecfilter_delay(inst=%p, codecfilter=%i, *delay=?) = ?", inst, codecfilter);
316
317 if ( codecfilter == -1 )
318  return -1;
319
320 if ( g_codecfilter[codecfilter].delay )
321  return g_codecfilter[codecfilter].delay(inst, delay);
322
323 return -1;
324}
325
[1224]326int codecfilter_ctl  (CODECFILTER_USERDATA_T   inst, int codecfilter, int_least32_t cmd, void * data) {
[2086]327 ROAR_DBG("codecfilter_ctl(inst=%p, codecfilter=%i, cmd=0x%.8x, data=%p) = ?", inst, codecfilter, cmd, data);
[1224]328 if ( codecfilter == -1 )
329  return -1;
330
331 if ( g_codecfilter[codecfilter].ctl )
332  return g_codecfilter[codecfilter].ctl(inst, cmd, data);
333
334 return -1;
335}
336
337
[1144]338int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay) {
339 *delay = 0; // just to be sure
340 return -1;
341}
342
[169]343//ll
Note: See TracBrowser for help on using the repository browser.