source: roaraudio/roard/codecfilter.c @ 2686:b20911f482f3

Last change on this file since 2686:b20911f482f3 was 2686:b20911f482f3, checked in by phi, 15 years ago

added RAUM to list of CFs

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