source: roaraudio/roard/codecfilter.c @ 1481:30246a17e3d5

Last change on this file since 1481:30246a17e3d5 was 1481:30246a17e3d5, checked in by phi, 15 years ago

update list of CFs

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