source: roaraudio/roard/codecfilter.c @ 2679:4b2619f63dd7

Last change on this file since 2679:4b2619f63dd7 was 2679:4b2619f63dd7, checked in by phi, 15 years ago

added cf config element void * setup, added subsystem info

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