source: roaraudio/roard/codecfilter.c @ 668:71ac426690da

Last change on this file since 668:71ac426690da was 668:71ac426690da, checked in by phi, 16 years ago

added license statements

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