source: roaraudio/roard/codecfilter.c @ 612:5ab0ccdc9e13

Last change on this file since 612:5ab0ccdc9e13 was 612:5ab0ccdc9e13, checked in by phi, 16 years ago

added flags to codecfilter list

File size: 4.2 KB
Line 
1//codecfilter.c:
2
3#include "roard.h"
4
5struct roar_codecfilter g_codecfilter[] = {
6 {-1,                     "null", "null codec filter", NULL, ROAR_CODECFILTER_NONE, NULL, NULL, NULL, NULL, NULL, NULL},
7
8 {ROAR_CODEC_RIFF_WAVE, "RIFF/WAVE", "RIFF/WAVE", NULL, ROAR_CODECFILTER_READ,
9  cf_wave_open, cf_wave_close, NULL, NULL, cf_wave_read, NULL},
10
11 {ROAR_CODEC_OGG_GENERAL, "cmd",  "ogg123",
12  "ogg123 -q -d raw -f - -", ROAR_CODECFILTER_READ,
13  cf_cmd_open, NULL, NULL, NULL, NULL, NULL},
14
15#ifdef ROAR_HAVE_LIBVORBISFILE
16 {ROAR_CODEC_OGG_VORBIS, "oggvorbis", "Ogg Vorbis decoder", NULL,
17#ifdef ROAR_HAVE_LIBVORBISENC
18 ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
19#else
20 ROAR_CODECFILTER_READ,
21#endif
22 cf_vorbis_open, cf_vorbis_close, NULL, cf_vorbis_write, cf_vorbis_read, NULL},
23#endif
24
25 {ROAR_CODEC_MIDI_FILE, "MIDIFILE", "timidity MIDI synth",
26  "timidity -Or1sl -s %R -o - -", ROAR_CODECFILTER_READ,
27  cf_cmd_open, NULL, NULL, NULL, NULL, NULL},
28
29#ifdef ROAR_HAVE_LIBCELT
30 {ROAR_CODEC_ROAR_CELT, "RoarCELT", "RoarAudio CELT", NULL, ROAR_CODECFILTER_READ|ROAR_CODECFILTER_WRITE,
31  cf_celt_open, cf_celt_close, NULL, cf_celt_write, cf_celt_read, NULL},
32#endif
33
34#ifdef ROAR_HAVE_LIBSPEEX
35 {ROAR_CODEC_ROAR_SPEEX, "RoarSPEEX", "RoarAudio SPEEX", NULL, ROAR_CODECFILTER_READ,
36  cf_speex_open, cf_speex_close, NULL, NULL, cf_speex_read, NULL},
37#endif
38
39 {ROAR_CODEC_FLAC, "cmd",  "flac",
40#if BYTE_ORDER == BIG_ENDIAN
41  "flac --silent --force-raw-format --sign=signed --endian=big -d - -o -",
42#elif BYTE_ORDER == LITTLE_ENDIAN
43  "flac --silent --force-raw-format --sign=signed --endian=little -d - -o -",
44#else
45  "false",
46#endif
47  ROAR_CODECFILTER_READ,
48  cf_cmd_open, NULL, NULL, NULL, NULL, NULL},
49
50 {-1, NULL, NULL, NULL, ROAR_CODECFILTER_NONE, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
51};
52
53void print_codecfilterlist (void) {
54 int i;
55
56 for (i = 0; g_codecfilter[i].name != NULL; i++) {
57  printf("  %-12s %-12s - %s\n",
58             roar_codec2str(g_codecfilter[i].codec),
59             g_codecfilter[i].name,
60             g_codecfilter[i].desc
61             );
62 }
63}
64
65int codecfilter_open (CODECFILTER_USERDATA_T * inst,
66                 int * codecfilter_id, char * codecfilter /* NOTE: this is not part of struct roar_codecfilter's def! */,
67                 int codec, struct roar_stream_server * info) {
68 int i;
69 struct roar_codecfilter   * filter = NULL;
70
71 *codecfilter_id = -1;
72
73 ROAR_DBG("codecfilter_open(*): codecfilter='%s', info->id=%i", codecfilter, ROAR_STREAM(info)->id);
74
75 for (i = 0; g_codecfilter[i].name != NULL; i++) {
76  if ( g_codecfilter[i].codec == codec ) {
77   if ( !codecfilter || strcmp(codecfilter, g_codecfilter[i].name) == 0 ) {
78    *codecfilter_id = i;
79    filter = &g_codecfilter[i];
80    break;
81   }
82  }
83 }
84
85 info->codecfilter = *codecfilter_id;
86
87 if (*codecfilter_id != -1) {
88  if ( filter->open ) {
89   if ( (i = filter->open(inst, codec, info, filter)) == -1 ) {
90    info->codecfilter = *codecfilter_id = -1;
91   }
92   return i;
93  }
94  return 0;
95 }
96
97 return 0; // we found no filter -> ok
98}
99
100int codecfilter_close(CODECFILTER_USERDATA_T   inst, int codecfilter) {
101 ROAR_DBG("codecfilter_close(inst=%p, codecfilter=%i) = ?", inst, codecfilter);
102
103 if ( codecfilter == -1 )
104  return -1;
105
106 if ( g_codecfilter[codecfilter].close )
107  return g_codecfilter[codecfilter].close(inst);
108
109 return 0;
110}
111
112int codecfilter_pause(CODECFILTER_USERDATA_T   inst, int codecfilter, int newstate) {
113 if ( codecfilter == -1 )
114  return -1;
115
116 if ( g_codecfilter[codecfilter].pause )
117  return g_codecfilter[codecfilter].pause(inst, newstate);
118
119 return 0;
120}
121
122int codecfilter_write(CODECFILTER_USERDATA_T   inst, int codecfilter, char * buf, int len) {
123 if ( codecfilter == -1 )
124  return -1;
125
126 if ( g_codecfilter[codecfilter].write )
127  return g_codecfilter[codecfilter].write(inst, buf, len);
128
129 return 0;
130}
131
132int codecfilter_read (CODECFILTER_USERDATA_T   inst, int codecfilter, char * buf, int len) {
133 if ( codecfilter == -1 )
134  return -1;
135
136 errno = 0;
137
138 if ( g_codecfilter[codecfilter].read )
139  return g_codecfilter[codecfilter].read(inst, buf, len);
140
141 return 0;
142}
143
144int codecfilter_flush(CODECFILTER_USERDATA_T   inst, int codecfilter) {
145 if ( codecfilter == -1 )
146  return -1;
147
148 if ( g_codecfilter[codecfilter].flush )
149  return g_codecfilter[codecfilter].flush(inst);
150
151 return 0;
152}
153
154//ll
Note: See TracBrowser for help on using the repository browser.