source: roaraudio/roard/codecfilter.c @ 1185:be5dce10bf4b

Last change on this file since 1185:be5dce10bf4b was 1185:be5dce10bf4b, checked in by phi, 15 years ago

only include vorbisfile.h if needed, should suppress some warnings

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