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
Line 
1//codecfilter.c:
2
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
25#define ROAR_REQUIRE_LIBVORBISFILE
26
27#include "roard.h"
28
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
35struct roar_codecfilter g_codecfilter[] = {
36 {-1,                     "null", "null codec filter", NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE,
37                                          NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
38
39/*
40#ifdef ROAR_HAVE_LIBSNDFILE
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},
43#else
44*/
45#ifndef ROAR_WITHOUT_CF_WAVE
46 {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, NULL,
47  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE, ROAR_SUBSYS_WAVEFORM,
48  cf_wave_open, cf_wave_close, NULL, cf_wave_write, cf_wave_read, NULL, NULL, cf_wave_ctl},
49#endif
50//#endif
51
52#ifdef ROAR_SUPPORT_ALAW
53 {ROAR_CODEC_ALAW, "alaw", "A-Law", NULL, NULL,
54#ifdef ROAR_SUPPORT_ALAW_RW
55  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
56#else
57  ROAR_CODECFILTER_READ,
58#endif
59  ROAR_SUBSYS_WAVEFORM,
60  cf_alaw_open, cf_alaw_close, NULL,
61#ifdef ROAR_SUPPORT_ALAW_RW
62  cf_alaw_write,
63#else
64  NULL,
65#endif
66  cf_alaw_read, NULL, cf_alaw_delay, NULL},
67#endif
68
69#ifdef ROAR_SUPPORT_MULAW
70 {ROAR_CODEC_MULAW, "mulaw", "mu-Law", NULL, NULL,
71#ifdef ROAR_SUPPORT_MULAW_RW
72  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
73#else
74  ROAR_CODECFILTER_READ,
75#endif
76  ROAR_SUBSYS_WAVEFORM,
77  cf_mulaw_open, cf_mulaw_close, NULL,
78#ifdef ROAR_SUPPORT_MULAW_RW
79  cf_mulaw_write,
80#else
81  NULL,
82#endif
83  cf_mulaw_read, NULL, cf_alaw_delay, NULL},
84#endif
85
86#ifndef ROAR_WITHOUT_CF_CMD
87#ifdef ROAR_HAVE_BIN_OGG123
88 {ROAR_CODEC_OGG_GENERAL, "cmd",  "ogg123",
89  ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
90  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
91#endif
92#endif
93
94#ifdef ROAR_HAVE_LIBVORBISFILE
95 {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, NULL,
96#ifdef ROAR_HAVE_LIBVORBISENC
97 ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
98#else
99 ROAR_CODECFILTER_READ,
100#endif
101 ROAR_SUBSYS_WAVEFORM,
102 cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL, codecfilter_delay_fulldyn, cf_vorbis_ctl},
103#else
104#ifndef ROAR_WITHOUT_CF_CMD
105#ifdef ROAR_HAVE_BIN_OGG123
106 {ROAR_CODEC_OGG_VORBIS, "cmd",  "ogg123",
107  ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
108  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
109#endif
110#endif
111#endif
112
113#ifdef ROAR_HAVE_LIBFISHSOUND
114 {ROAR_CODEC_OGG_SPEEX, "fishsound",  "libfishsound Xiph Codec library",
115  NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
116  cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL},
117
118 {ROAR_CODEC_OGG_FLAC, "fishsound",  "libfishsound Xiph Codec library",
119  NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
120  cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL},
121#endif
122
123#ifndef ROAR_WITHOUT_CF_CMD
124#ifdef ROAR_HAVE_BIN_TIMIDITY
125 {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth",
126  ROAR_HAVE_BIN_TIMIDITY " -Or1sl -s %R -o - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
127  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
128#endif
129#endif
130
131#ifdef ROAR_HAVE_LIBCELT
132 {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
133  ROAR_SUBSYS_WAVEFORM,
134  cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL, cf_celt_delay, NULL},
135#endif
136
137#ifdef ROAR_HAVE_LIBSPEEX
138 {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
139  ROAR_SUBSYS_WAVEFORM,
140  cf_speex_open, cf_speex_close, NULL, cf_speex_write, cf_speex_read, NULL, NULL, NULL},
141#endif
142
143#ifndef ROAR_WITHOUT_CF_CMD
144#ifdef ROAR_HAVE_BIN_FLAC
145 {ROAR_CODEC_FLAC, "cmd",  "flac",
146#if BYTE_ORDER == BIG_ENDIAN
147  ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=big -d - -o -",
148#elif BYTE_ORDER == LITTLE_ENDIAN
149  ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=little -d - -o -",
150#else
151  "false",
152#endif
153  NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
154  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
155#endif
156#endif
157
158 {-1, NULL, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE,
159  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
160};
161
162void print_codecfilterlist (void) {
163 int i;
164 int flags;
165 char mode[5];
166 char delay[6];
167 char subsys[7] = "      ";
168 uint_least32_t d;
169
170 printf("  Codec        Filtername   Mode Subsys Delay - Description\n");
171 printf("-------------------------------------------------------------\n");
172
173 for (i = 0; g_codecfilter[i].name != NULL; i++) {
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  if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_COMPLEX )
187   subsys[5] = 'X';
188
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  }
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  }
213 
214  printf("  %-12s %-12s %-4s %6s %-5s - %s\n",
215             roar_codec2str(g_codecfilter[i].codec),
216             g_codecfilter[i].name,
217             mode,
218             subsys,
219             delay,
220             g_codecfilter[i].desc
221             );
222 }
223}
224
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
233 ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id);
234
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
245 info->codecfilter = *codecfilter_id;
246
247 if (*codecfilter_id != -1) {
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  }
254  return 0;
255 }
256
257 return 0; // we found no filter -> ok
258}
259
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
296 errno = 0;
297
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
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
326int codecfilter_ctl  (CODECFILTER_USERDATA_T   inst, int codecfilter, int_least32_t cmd, void * data) {
327 ROAR_DBG("codecfilter_ctl(inst=%p, codecfilter=%i, cmd=0x%.8x, data=%p) = ?", inst, codecfilter, cmd, data);
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
338int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay) {
339 *delay = 0; // just to be sure
340 return -1;
341}
342
343//ll
Note: See TracBrowser for help on using the repository browser.