1 | //driver.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 |
---|
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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "roard.h" |
---|
27 | |
---|
28 | struct roar_driver g_driver[] = { |
---|
29 | { "null", "null audio driver", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
30 | NULL, NULL, NULL}, |
---|
31 | #ifdef ROAR_HAVE_ESD |
---|
32 | { "esd", "EsounD audio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
33 | NULL, NULL, driver_esd_open_vio}, |
---|
34 | #endif |
---|
35 | { "roar", "RoarAudio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, DRV_FLAG_NONE, |
---|
36 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_COMPLEX, |
---|
37 | NULL, NULL, driver_roar_open_vio}, |
---|
38 | #ifndef ROAR_WITHOUT_VIO_DSTR |
---|
39 | { "dstr", "VIO DSTR driver", "/some/file", STREAM_DIR_OUT, DRV_FLAG_FHSEC, |
---|
40 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX, |
---|
41 | NULL, NULL, driver_dstr_open_vio}, |
---|
42 | #endif |
---|
43 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
44 | #ifndef ROAR_DEFAULT_OSS_DEV |
---|
45 | #define ROAR_DEFAULT_OSS_DEV "no default device" |
---|
46 | #endif |
---|
47 | { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, STREAM_DIR_BIDIR, DRV_FLAG_FHSEC, ROAR_SUBSYS_WAVEFORM, |
---|
48 | NULL, NULL, driver_oss_open}, |
---|
49 | #endif |
---|
50 | #ifdef ROAR_HAVE_LIBAO |
---|
51 | { "ao", "libao audio driver", "DRIVER", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
52 | NULL, NULL, driver_ao_open_vio}, |
---|
53 | #endif |
---|
54 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
55 | {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
56 | NULL, NULL, driver_shout_open_vio}, |
---|
57 | #endif |
---|
58 | #ifdef ROAR_HAVE_LIBSNDIO |
---|
59 | {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI, |
---|
60 | NULL, NULL, driver_sndio_open}, |
---|
61 | #endif |
---|
62 | #ifdef ROAR_HAVE_LIBRSOUND |
---|
63 | {"rsound", "RSound", "servername", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
64 | NULL, NULL, driver_rsound_open}, |
---|
65 | #endif |
---|
66 | #ifdef _DRIVER_PORTAUDIO_CAN_OPERATE |
---|
67 | {"portaudio", "PortAudio", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
68 | NULL, NULL, driver_portaudio_open}, |
---|
69 | #endif |
---|
70 | #ifdef ROAR_HAVE_LIBASOUND |
---|
71 | {"alsa", "ALSA", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio}, |
---|
72 | #endif |
---|
73 | #ifdef ROAR_HAVE_LIBWINMM |
---|
74 | {"wmm", "Win32 MM", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio}, |
---|
75 | #endif |
---|
76 | #ifndef ROAR_WITHOUT_DCOMP_DMX |
---|
77 | {"dmx", "DMX512 driver", "/dev/dmx", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
78 | NULL, NULL, driver_dmx_open_vio}, |
---|
79 | #endif |
---|
80 | #if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR) |
---|
81 | {"pwmled", "PWM LED driver", "/dev/ttyS0", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
82 | NULL, NULL, driver_pwmled_open_vio}, |
---|
83 | #endif |
---|
84 | #ifdef ROAR_HAVE_DRIVER_SYSCLOCK |
---|
85 | {"sysclock", "System Clock Clock Source", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
86 | NULL, NULL, driver_sysclock_open_vio}, |
---|
87 | #endif |
---|
88 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
89 | {"cdriver", "RoarAudio Client driver", "driver#device", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
90 | NULL, NULL, driver_cdriver_open}, |
---|
91 | #endif |
---|
92 | #ifdef ROAR_HAVE_LIBPULSE |
---|
93 | {"pulsesimple", "PulseAudio Simple", "server", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
94 | NULL, NULL, driver_pulsesimple_open}, |
---|
95 | #endif |
---|
96 | #ifdef ROAR_HAVE_LIBJACK |
---|
97 | #if 0 |
---|
98 | // this is currently just a driver stub. |
---|
99 | {"jack", "JACK", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
100 | NULL, NULL, driver_jack_open_vio}, |
---|
101 | #endif |
---|
102 | #endif |
---|
103 | #ifdef ROAR_HAVE_LIBARTSC |
---|
104 | {"artsc", "aRts plain C API", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
105 | NULL, NULL, driver_artsc_open_vio}, |
---|
106 | #endif |
---|
107 | {NULL, NULL, NULL, STREAM_DIR_NONE, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list |
---|
108 | }; |
---|
109 | |
---|
110 | void print_driverlist (enum output_format format) { |
---|
111 | int i; |
---|
112 | char subsys[7] = " "; |
---|
113 | char mode[5] = " "; |
---|
114 | |
---|
115 | switch (format) { |
---|
116 | case FORMAT_NATIVE: |
---|
117 | printf(" Driver Mode Flag Subsys - Description (devices)\n"); |
---|
118 | printf("---------------------------------------------------------------\n"); |
---|
119 | break; |
---|
120 | case FORMAT_WIKI: |
---|
121 | printf("||=Driver =||=Mode =||=Flag =||=Subsys =||=Description =||=Devices =||\n"); |
---|
122 | break; |
---|
123 | case FORMAT_CSV: |
---|
124 | printf("Driver,Mode,Flag,Subsys,Description,Devices\n"); |
---|
125 | break; |
---|
126 | default: |
---|
127 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
128 | return; |
---|
129 | } |
---|
130 | |
---|
131 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
132 | strncpy(subsys, " ", 6); |
---|
133 | strncpy(mode, " ", 4); |
---|
134 | |
---|
135 | if ( g_driver[i].mode & STREAM_DIR_IN ) |
---|
136 | mode[0] = 'r'; |
---|
137 | if ( g_driver[i].mode & STREAM_DIR_OUT ) |
---|
138 | mode[1] = 'w'; |
---|
139 | |
---|
140 | if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
141 | subsys[0] = 'W'; |
---|
142 | if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
143 | subsys[1] = 'M'; |
---|
144 | if ( g_driver[i].subsystems & ROAR_SUBSYS_CB ) |
---|
145 | subsys[2] = 'C'; |
---|
146 | if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
147 | subsys[3] = 'L'; |
---|
148 | if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
149 | subsys[4] = 'R'; |
---|
150 | if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
151 | subsys[5] = 'X'; |
---|
152 | |
---|
153 | switch (format) { |
---|
154 | case FORMAT_NATIVE: |
---|
155 | if ( g_driver[i].devices != NULL ) { |
---|
156 | printf(" %-12s %4s %c%c%c%c %6s - %s (devices: %s)\n", g_driver[i].name, |
---|
157 | mode, |
---|
158 | ' ', /* unused Flag */ |
---|
159 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
160 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
161 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
162 | subsys, |
---|
163 | g_driver[i].desc, g_driver[i].devices); |
---|
164 | } else { |
---|
165 | printf(" %-12s %4s %c%c%c%c %6s - %s\n", g_driver[i].name, |
---|
166 | mode, |
---|
167 | ' ', /* unused Flag */ |
---|
168 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
169 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
170 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
171 | subsys, |
---|
172 | g_driver[i].desc); |
---|
173 | } |
---|
174 | break; |
---|
175 | case FORMAT_WIKI: |
---|
176 | printf("||=%-12s =|| %s || %s%s%s ||%s ||%s ||%s ||\n", g_driver[i].name, mode[0] == ' ' ? mode+1 : mode, |
---|
177 | g_driver[i].flags & DRV_FLAG_FHSEC ? "s" : " ", |
---|
178 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ", |
---|
179 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ", |
---|
180 | subsys, |
---|
181 | g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices); |
---|
182 | break; |
---|
183 | case FORMAT_CSV: |
---|
184 | printf("%s,%s,%s%s%s,%s,%s,%s\n", g_driver[i].name, mode, |
---|
185 | g_driver[i].flags & DRV_FLAG_FHSEC ? "s" : " ", |
---|
186 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ", |
---|
187 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ", |
---|
188 | subsys, |
---|
189 | g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices); |
---|
190 | break; |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | int driver_openvio(struct roar_vio_calls * calls, |
---|
196 | int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */, |
---|
197 | char * device, struct roar_audio_info * info, int fh, |
---|
198 | struct roar_stream_server * sstream) { |
---|
199 | int i; |
---|
200 | |
---|
201 | #ifdef ROAR_DRIVER_DEFAULT |
---|
202 | if ( driver == NULL ) |
---|
203 | driver = ROAR_DRIVER_DEFAULT; |
---|
204 | #else |
---|
205 | if ( driver == NULL ) |
---|
206 | return -1; |
---|
207 | #endif |
---|
208 | |
---|
209 | ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver); |
---|
210 | |
---|
211 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
212 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
213 | ROAR_DBG("driver_openvio(*): found driver: id = %i", i); |
---|
214 | |
---|
215 | *driver_id = i; |
---|
216 | |
---|
217 | ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i); |
---|
218 | |
---|
219 | if ( g_driver[i].vio_init == NULL ) { |
---|
220 | if ( g_driver[i].open == NULL ) { // this is the null driver |
---|
221 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
222 | calls->flags = ROAR_VIO_FLAGS_NONE; |
---|
223 | calls->refc = 1; |
---|
224 | calls->read = roar_vio_null_rw; |
---|
225 | calls->write = roar_vio_null_rw; |
---|
226 | return 0; |
---|
227 | } |
---|
228 | |
---|
229 | ROAR_WARN("driver_openvio(*): driver(%s) uses old non-vio interface!", driver); |
---|
230 | ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!", |
---|
231 | calls, i, driver, device, info, fh); |
---|
232 | return -1; |
---|
233 | } |
---|
234 | |
---|
235 | // if this driver does not support input we need to check if it is used in input mode. |
---|
236 | if ( !(g_driver[i].mode & STREAM_DIR_IN) ) { |
---|
237 | if ( sstream == NULL ) |
---|
238 | return -1; |
---|
239 | |
---|
240 | if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) ) { |
---|
241 | if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) == 1 ) { |
---|
242 | if ( streams_reset_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) == -1 ) |
---|
243 | return -1; |
---|
244 | } else { |
---|
245 | ROAR_WARN("driver_openvio(*): driver(%s) is not abled to record data and autoconf flag is not set.", driver); |
---|
246 | return -1; |
---|
247 | } |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i); |
---|
252 | return g_driver[i].vio_init(calls, device, info, fh, sstream); |
---|
253 | } |
---|
254 | } |
---|
255 | return -1; |
---|
256 | } |
---|
257 | |
---|
258 | int driver_closevio(struct roar_vio_calls * calls, int driver) { |
---|
259 | ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver); |
---|
260 | |
---|
261 | if ( driver == -1 ) |
---|
262 | return -1; |
---|
263 | |
---|
264 | if ( g_driver[driver].close ) |
---|
265 | return g_driver[driver].close((DRIVER_USERDATA_T)calls); |
---|
266 | |
---|
267 | if ( calls->close != NULL ) |
---|
268 | roar_vio_close(calls); |
---|
269 | |
---|
270 | return 0; |
---|
271 | } |
---|
272 | |
---|
273 | int driver_set_volume(int stream, struct roar_mixer_settings * mixer) { |
---|
274 | struct roar_stream_server * ss; |
---|
275 | |
---|
276 | if ( (ss = g_streams[stream]) == NULL ) |
---|
277 | return -1; |
---|
278 | |
---|
279 | if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) ) |
---|
280 | return 0; |
---|
281 | |
---|
282 | if ( ss->driver_id == -1 ) |
---|
283 | return -1; |
---|
284 | |
---|
285 | return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer); |
---|
286 | } |
---|
287 | |
---|
288 | |
---|
289 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
290 | int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
291 | char * driver; |
---|
292 | char * delm; |
---|
293 | int ret; |
---|
294 | |
---|
295 | ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh); |
---|
296 | |
---|
297 | if (device == NULL) { |
---|
298 | driver = NULL; |
---|
299 | } else { |
---|
300 | driver = roar_mm_strdup(device); |
---|
301 | |
---|
302 | if ( (delm = strstr(driver, "#")) == NULL ) { |
---|
303 | device = NULL; |
---|
304 | } else { |
---|
305 | *delm = 0; |
---|
306 | device = strstr(device, "#") + 1; |
---|
307 | } |
---|
308 | } |
---|
309 | |
---|
310 | ROAR_DBG("driver_cdriver_open(*): CALL roar_cdriver_open(inst=%p, driver='%s', device='%s', info=%p, dir=ROAR_DIR_PLAY)", inst, driver, device, info); |
---|
311 | ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY); |
---|
312 | ROAR_DBG("driver_cdriver_open(*): RET %i", ret); |
---|
313 | |
---|
314 | if ( driver != NULL ) |
---|
315 | roar_mm_free(driver); |
---|
316 | |
---|
317 | return ret; |
---|
318 | } |
---|
319 | #endif |
---|
320 | |
---|
321 | int driver_dummy_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) { |
---|
322 | switch (cmd) { |
---|
323 | case ROAR_VIO_CTL_NONBLOCK: |
---|
324 | if ( *(const int*)data == ROAR_SOCKET_BLOCK ) |
---|
325 | return 0; |
---|
326 | |
---|
327 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
328 | return -1; |
---|
329 | break; |
---|
330 | default: |
---|
331 | roar_err_set(ROAR_ERROR_BADRQC); |
---|
332 | return -1; |
---|
333 | break; |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | //ll |
---|