source: roaraudio/roard/codecfilter.c @ 362:b13b2abea6f0

Last change on this file since 362:b13b2abea6f0 was 362:b13b2abea6f0, checked in by phi, 16 years ago

only compile vorbis stuff if we have libvorbisfile

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