source: roaraudio/roard/driver.c

tip
Last change on this file was 6052:d48765b2475e, checked in by phi, 8 years ago

updated copyright headers

File size: 12.5 KB
Line 
1//driver.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015
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
28struct 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_I2CDMX
85 {"i2cdmx", "I^2C DMX Interface driver", "/dev/i2c-1", STREAM_DIR_BIDIR, DRV_FLAG_NONE, ROAR_SUBSYS_LIGHT,
86  NULL, NULL, driver_i2cdmx_open_vio},
87#endif
88#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
89 {"sysclock", "System Clock Clock Source", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
90  NULL, NULL, driver_sysclock_open_vio},
91#endif
92#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
93 {"cdriver", "RoarAudio Client driver", "driver#device", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
94  NULL, NULL, driver_cdriver_open},
95#endif
96#ifdef ROAR_HAVE_LIBPULSE
97 {"pulsesimple", "PulseAudio Simple", "server", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
98  NULL, NULL, driver_pulsesimple_open},
99#endif
100#ifdef ROAR_HAVE_LIBJACK
101#if 0
102 // this is currently just a driver stub.
103 {"jack", "JACK", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
104  NULL, NULL, driver_jack_open_vio},
105#endif
106#endif
107#ifdef ROAR_HAVE_LIBARTSC
108 {"artsc", "aRts plain C API", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
109  NULL, NULL, driver_artsc_open_vio},
110#endif
111 {NULL, NULL, NULL, STREAM_DIR_NONE, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list
112                                };
113
114void print_driverlist (enum output_format format) {
115 int i;
116 char subsys[7] = "      ";
117 char mode[5]   = "    ";
118
119 switch (format) {
120  case FORMAT_NATIVE:
121    printf("  Driver       Mode Flag Subsys - Description (devices)\n");
122    printf("---------------------------------------------------------------\n");
123   break;
124  case FORMAT_WIKI:
125    printf("||=Driver =||=Mode =||=Flag =||=Subsys =||=Description =||=Devices =||\n");
126   break;
127  case FORMAT_CSV:
128    printf("Driver,Mode,Flag,Subsys,Description,Devices\n");
129   break;
130  default:
131    roar_err_set(ROAR_ERROR_NOTSUP);
132    return;
133 }
134
135 for (i = 0; g_driver[i].name != NULL; i++) {
136  strncpy(subsys, "      ", 6);
137  strncpy(mode,   "    ",   4);
138
139  if ( g_driver[i].mode & STREAM_DIR_IN )
140   mode[0] = 'r';
141  if ( g_driver[i].mode & STREAM_DIR_OUT )
142   mode[1] = 'w';
143
144  if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM )
145   subsys[0] = 'W';
146  if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI )
147   subsys[1] = 'M';
148  if ( g_driver[i].subsystems & ROAR_SUBSYS_CB )
149   subsys[2] = 'C';
150  if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT )
151   subsys[3] = 'L';
152  if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW )
153   subsys[4] = 'R';
154  if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX )
155   subsys[5] = 'X';
156
157  switch (format) {
158   case FORMAT_NATIVE:
159     if ( g_driver[i].devices != NULL ) {
160      printf("  %-12s %4s %c%c%c%c %6s - %s (devices: %s)\n", g_driver[i].name,
161                    mode,
162                    ' ', /* unused Flag */
163                    g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? 's' : ' ',
164                    g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
165                    g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
166                    subsys,
167                    g_driver[i].desc, g_driver[i].devices);
168     } else {
169      printf("  %-12s %4s %c%c%c%c %6s - %s\n", g_driver[i].name,
170                    mode,
171                    ' ', /* unused Flag */
172                    g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? 's' : ' ',
173                    g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
174                    g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
175                    subsys,
176                    g_driver[i].desc);
177     }
178    break;
179   case FORMAT_WIKI:
180     printf("||=%-12s =|| %s || %s%s%s ||%s ||%s ||%s ||\n", g_driver[i].name, mode[0] == ' ' ? mode+1 : mode,
181                    g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? "s" : " ",
182                    g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ",
183                    g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ",
184                    subsys,
185                    g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices);
186    break;
187   case FORMAT_CSV:
188     printf("%s,%s,%s%s%s,%s,%s,%s\n", g_driver[i].name, mode,
189                    g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? "s" : " ",
190                    g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ",
191                    g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ",
192                    subsys,
193                    g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices);
194    break;
195  }
196 }
197}
198
199int driver_openvio(struct roar_vio_calls * calls,
200                 int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */,
201                 char * device, struct roar_audio_info * info, int fh,
202                 struct roar_stream_server * sstream) {
203 int i;
204
205#ifdef ROAR_DRIVER_DEFAULT
206 if ( driver == NULL )
207  driver = ROAR_DRIVER_DEFAULT;
208#else
209 if ( driver == NULL )
210  return -1;
211#endif
212
213#ifdef ROAR_DRIVER_DEVICE
214 if ( device == NULL )
215  device = ROAR_DRIVER_DEVICE;
216#endif
217
218 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
219
220 for (i = 0; g_driver[i].name != NULL; i++) {
221  if ( strcmp(g_driver[i].name, driver) == 0 ) {
222   ROAR_DBG("driver_openvio(*): found driver: id = %i", i);
223
224   *driver_id = i;
225
226   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
227
228   if ( g_driver[i].vio_init == NULL ) {
229    if ( g_driver[i].open == NULL ) { // this is the null driver
230     memset(calls, 0, sizeof(struct roar_vio_calls));
231     calls->flags = ROAR_VIO_FLAGS_NONE;
232     calls->refc  = 1;
233     calls->read  = roar_vio_null_rw;
234     calls->write = roar_vio_null_rw;
235     return 0;
236    }
237
238    ROAR_WARN("driver_openvio(*): driver(%s) uses old non-vio interface!", driver);
239    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
240        calls, i, driver, device, info, fh);
241    return -1;
242   }
243
244   // if this driver does not support input we need to check if it is used in input mode.
245   if ( !(g_driver[i].mode & STREAM_DIR_IN) ) {
246    if ( sstream == NULL )
247     return -1;
248
249    if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) ) {
250     if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) == 1 ) {
251      if ( streams_reset_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) == -1 )
252       return -1;
253     } else {
254      ROAR_WARN("driver_openvio(*): driver(%s) is not abled to record data and autoconf flag is not set.", driver);
255      return -1;
256     }
257    }
258   }
259
260   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
261   return g_driver[i].vio_init(calls, device, info, fh, sstream);
262  }
263 }
264 return -1;
265}
266
267int driver_closevio(struct roar_vio_calls * calls, int driver) {
268 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
269
270 if ( driver == -1 )
271  return -1;
272
273 if ( g_driver[driver].close )
274  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
275
276 if ( calls->close != NULL )
277  roar_vio_close(calls);
278
279 return 0;
280}
281
282int driver_set_volume(int stream, struct roar_mixer_settings * mixer) {
283 struct roar_stream_server * ss;
284
285 if ( (ss = g_streams[stream]) == NULL )
286  return -1;
287
288 if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) )
289  return 0;
290
291 if ( ss->driver_id == -1 )
292  return -1;
293
294 return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer);
295}
296
297
298#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
299int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
300 char * driver;
301 char * delm;
302 int ret;
303
304 (void)sstream;
305
306 ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p) = ?", inst, device, info, fh, sstream);
307
308 if ( fh != -1 ) {
309  roar_err_set(ROAR_ERROR_NOTSUP);
310  return -1;
311 }
312
313 if (device == NULL) {
314  driver = NULL;
315 } else {
316  driver = roar_mm_strdup(device);
317
318  if ( (delm = strstr(driver, "#")) == NULL ) {
319   device = NULL;
320  } else {
321   *delm  = 0;
322   device = strstr(device, "#") + 1;
323  }
324 }
325
326 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);
327 ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY);
328 ROAR_DBG("driver_cdriver_open(*): RET %i", ret);
329
330 if ( driver != NULL )
331  roar_mm_free(driver);
332
333 return ret;
334}
335#endif
336
337int  driver_dummy_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) {
338 (void)vio;
339
340 switch (cmd) {
341  case ROAR_VIO_CTL_NONBLOCK:
342    if ( *(const int*)data == ROAR_SOCKET_BLOCK )
343     return 0;
344
345    roar_err_set(ROAR_ERROR_NOTSUP);
346    return -1;
347   break;
348  default:
349    roar_err_set(ROAR_ERROR_BADRQC);
350    return -1;
351   break;
352 }
353}
354
355//ll
Note: See TracBrowser for help on using the repository browser.