source: roaraudio/roard/codecfilter.c @ 998:fdee4bd3aeec

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

updated description

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