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
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
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  }
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  }
211 
212  printf("  %-12s %-12s %-4s %6s %-5s - %s\n",
213             roar_codec2str(g_codecfilter[i].codec),
214             g_codecfilter[i].name,
215             mode,
216             subsys,
217             delay,
218             g_codecfilter[i].desc
219             );
220 }
221}
222
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
231 ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id);
232
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
243 info->codecfilter = *codecfilter_id;
244
245 if (*codecfilter_id != -1) {
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  }
252  return 0;
253 }
254
255 return 0; // we found no filter -> ok
256}
257
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
294 errno = 0;
295
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
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
324int codecfilter_ctl  (CODECFILTER_USERDATA_T   inst, int codecfilter, int_least32_t cmd, void * data) {
325 ROAR_DBG("codecfilter_ctl(inst=%p, codecfilter=%i, cmd=0x%.8x, data=%p) = ?", inst, codecfilter, cmd, data);
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
336int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay) {
337 *delay = 0; // just to be sure
338 return -1;
339}
340
341//ll
Note: See TracBrowser for help on using the repository browser.