source: roaraudio/roard/codecfilter.c @ 2690:126cf09c7389

Last change on this file since 2690:126cf09c7389 was 2690:126cf09c7389, checked in by phi, 15 years ago

we start with write support

File size: 10.4 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_HAVE_LIBRAUM
53 {ROAR_CODEC_RAUM, "RAUM", "RAUM Container Format", NULL, cf_raum_setup, ROAR_CODECFILTER_WRITE,
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
58#ifdef ROAR_SUPPORT_ALAW
59 {ROAR_CODEC_ALAW, "alaw", "A-Law", NULL, NULL,
60#ifdef ROAR_SUPPORT_ALAW_RW
61  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
62#else
63  ROAR_CODECFILTER_READ,
64#endif
65  ROAR_SUBSYS_WAVEFORM,
66  cf_alaw_open, cf_alaw_close, NULL,
67#ifdef ROAR_SUPPORT_ALAW_RW
68  cf_alaw_write,
69#else
70  NULL,
71#endif
72  cf_alaw_read, NULL, cf_alaw_delay, NULL},
73#endif
74
75#ifdef ROAR_SUPPORT_MULAW
76 {ROAR_CODEC_MULAW, "mulaw", "mu-Law", NULL, NULL,
77#ifdef ROAR_SUPPORT_MULAW_RW
78  ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
79#else
80  ROAR_CODECFILTER_READ,
81#endif
82  ROAR_SUBSYS_WAVEFORM,
83  cf_mulaw_open, cf_mulaw_close, NULL,
84#ifdef ROAR_SUPPORT_MULAW_RW
85  cf_mulaw_write,
86#else
87  NULL,
88#endif
89  cf_mulaw_read, NULL, cf_alaw_delay, NULL},
90#endif
91
92#ifndef ROAR_WITHOUT_CF_CMD
93#ifdef ROAR_HAVE_BIN_OGG123
94 {ROAR_CODEC_OGG_GENERAL, "cmd",  "ogg123",
95  ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
96  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
97#endif
98#endif
99
100#ifdef ROAR_HAVE_LIBVORBISFILE
101 {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL, NULL,
102#ifdef ROAR_HAVE_LIBVORBISENC
103 ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
104#else
105 ROAR_CODECFILTER_READ,
106#endif
107 ROAR_SUBSYS_WAVEFORM,
108 cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL, codecfilter_delay_fulldyn, cf_vorbis_ctl},
109#else
110#ifndef ROAR_WITHOUT_CF_CMD
111#ifdef ROAR_HAVE_BIN_OGG123
112 {ROAR_CODEC_OGG_VORBIS, "cmd",  "ogg123",
113  ROAR_HAVE_BIN_OGG123 " -q -d raw -f - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
114  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
115#endif
116#endif
117#endif
118
119#ifdef ROAR_HAVE_LIBFISHSOUND
120 {ROAR_CODEC_OGG_SPEEX, "fishsound",  "libfishsound Xiph Codec library",
121  NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
122  cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL},
123
124 {ROAR_CODEC_OGG_FLAC, "fishsound",  "libfishsound Xiph Codec library",
125  NULL, NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
126  cf_fishsound_open, cf_fishsound_close, NULL, NULL, cf_fishsound_read, NULL, codecfilter_delay_fulldyn, NULL},
127#endif
128
129#ifndef ROAR_WITHOUT_CF_CMD
130#ifdef ROAR_HAVE_BIN_TIMIDITY
131 {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth",
132  ROAR_HAVE_BIN_TIMIDITY " -Or1sl -s %R -o - -", NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
133  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
134#endif
135#endif
136
137#ifdef ROAR_HAVE_LIBCELT
138 {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
139  ROAR_SUBSYS_WAVEFORM,
140  cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL, cf_celt_delay, NULL},
141#endif
142
143#ifdef ROAR_HAVE_LIBSPEEX
144 {ROAR_CODEC_ROAR_SPEEX, "RoarSpeex", "RoarAudio Speex", NULL, NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
145  ROAR_SUBSYS_WAVEFORM,
146  cf_speex_open, cf_speex_close, NULL, cf_speex_write, cf_speex_read, NULL, NULL, NULL},
147#endif
148
149#ifndef ROAR_WITHOUT_CF_CMD
150#ifdef ROAR_HAVE_BIN_FLAC
151 {ROAR_CODEC_FLAC, "cmd",  "flac",
152#if BYTE_ORDER == BIG_ENDIAN
153  ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=big -d - -o -",
154#elif BYTE_ORDER == LITTLE_ENDIAN
155  ROAR_HAVE_BIN_FLAC " --silent --force-raw-format --sign=signed --endian=little -d - -o -",
156#else
157  "false",
158#endif
159  NULL, ROAR_CODECFILTER_READ, ROAR_SUBSYS_WAVEFORM,
160  cf_cmd_open, NULL, NULL, NULL, NULL, NULL, codecfilter_delay_fulldyn, NULL},
161#endif
162#endif
163
164 {-1, NULL, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, ROAR_SUBSYS_NONE,
165  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
166};
167
168void print_codecfilterlist (void) {
169 int i;
170 int flags;
171 char mode[5];
172 char delay[6];
173 char subsys[7] = "      ";
174 uint_least32_t d;
175
176 printf("  Codec        Filtername   Mode Subsys Delay - Description\n");
177 printf("-------------------------------------------------------------\n");
178
179 for (i = 0; g_codecfilter[i].name != NULL; i++) {
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';
192  if ( g_codecfilter[i].subsystems & ROAR_SUBSYS_COMPLEX )
193   subsys[5] = 'X';
194
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  }
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  }
219 
220  printf("  %-12s %-12s %-4s %6s %-5s - %s\n",
221             roar_codec2str(g_codecfilter[i].codec),
222             g_codecfilter[i].name,
223             mode,
224             subsys,
225             delay,
226             g_codecfilter[i].desc
227             );
228 }
229}
230
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
239 ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id);
240
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
251 info->codecfilter = *codecfilter_id;
252
253 if (*codecfilter_id != -1) {
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  }
260  return 0;
261 }
262
263 return 0; // we found no filter -> ok
264}
265
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
302 errno = 0;
303
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
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
332int codecfilter_ctl  (CODECFILTER_USERDATA_T   inst, int codecfilter, int_least32_t cmd, void * data) {
333 ROAR_DBG("codecfilter_ctl(inst=%p, codecfilter=%i, cmd=0x%.8x, data=%p) = ?", inst, codecfilter, cmd, data);
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
344int codecfilter_delay_fulldyn(CODECFILTER_USERDATA_T   inst, uint_least32_t * delay) {
345 *delay = 0; // just to be sure
346 return -1;
347}
348
349//ll
Note: See TracBrowser for help on using the repository browser.