source: roaraudio/roard/codecfilter.c @ 1021:bdf6df991057

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

ha, I added write support to it yesterday...

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