source: roaraudio/roard/driver.c @ 6056:8d4468a24909

Last change on this file since 6056:8d4468a24909 was 6052:d48765b2475e, checked in by phi, 9 years ago

updated copyright headers

File size: 12.5 KB
RevLine 
[668]1//driver.c:
[0]2
[668]3/*
[6052]4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015
[668]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
[3517]21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
[668]23 *
24 */
[0]25
26#include "roard.h"
27
28struct roar_driver g_driver[] = {
[4812]29 { "null", "null audio driver", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[2365]30   NULL, NULL, NULL},
[0]31#ifdef ROAR_HAVE_ESD
[4812]32 { "esd", "EsounD audio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3591]33   NULL, NULL, driver_esd_open_vio},
[0]34#endif
[4812]35 { "roar", "RoarAudio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, DRV_FLAG_NONE,
[2681]36   ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_COMPLEX,
[3593]37   NULL, NULL, driver_roar_open_vio},
[3601]38#ifndef ROAR_WITHOUT_VIO_DSTR
[4812]39 { "dstr", "VIO DSTR driver", "/some/file", STREAM_DIR_OUT, DRV_FLAG_FHSEC,
[3262]40   ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX,
41   NULL, NULL, driver_dstr_open_vio},
[1478]42#endif
[919]43#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
[924]44#ifndef ROAR_DEFAULT_OSS_DEV
45#define ROAR_DEFAULT_OSS_DEV "no default device"
46#endif
[4815]47 { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, STREAM_DIR_BIDIR, DRV_FLAG_FHSEC, ROAR_SUBSYS_WAVEFORM,
[2365]48   NULL, NULL, driver_oss_open},
[919]49#endif
[0]50#ifdef ROAR_HAVE_LIBAO
[4812]51 { "ao", "libao audio driver", "DRIVER", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3588]52   NULL, NULL, driver_ao_open_vio},
[0]53#endif
[951]54#ifdef ROAR_HAVE_LIBSHOUT
[4812]55 {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3589]56  NULL, NULL, driver_shout_open_vio},
[951]57#endif
[1543]58#ifdef ROAR_HAVE_LIBSNDIO
[4812]59 {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI,
[2365]60  NULL, NULL, driver_sndio_open},
[1543]61#endif
[3725]62#ifdef ROAR_HAVE_LIBRSOUND
[4812]63 {"rsound", "RSound", "servername", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3725]64  NULL, NULL, driver_rsound_open},
65#endif
[3751]66#ifdef _DRIVER_PORTAUDIO_CAN_OPERATE
[4812]67 {"portaudio", "PortAudio", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3751]68  NULL, NULL, driver_portaudio_open},
69#endif
[3693]70#ifdef ROAR_HAVE_LIBASOUND
[4812]71 {"alsa", "ALSA", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio},
[3693]72#endif
[2779]73#ifdef ROAR_HAVE_LIBWINMM
[4812]74 {"wmm", "Win32 MM", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio},
[2779]75#endif
[2503]76#ifndef ROAR_WITHOUT_DCOMP_DMX
[4812]77 {"dmx", "DMX512 driver", "/dev/dmx", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
[2365]78  NULL, NULL, driver_dmx_open_vio},
[2503]79#endif
[3602]80#if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR)
[4812]81 {"pwmled", "PWM LED driver", "/dev/ttyS0", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
[2365]82  NULL, NULL, driver_pwmled_open_vio},
[2502]83#endif
[5908]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
[2209]88#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
[4812]89 {"sysclock", "System Clock Clock Source", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[2365]90  NULL, NULL, driver_sysclock_open_vio},
[2209]91#endif
[2507]92#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
[4812]93 {"cdriver", "RoarAudio Client driver", "driver#device", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[2365]94  NULL, NULL, driver_cdriver_open},
[2507]95#endif
[3839]96#ifdef ROAR_HAVE_LIBPULSE
[4812]97 {"pulsesimple", "PulseAudio Simple", "server", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[3839]98  NULL, NULL, driver_pulsesimple_open},
99#endif
[4490]100#ifdef ROAR_HAVE_LIBJACK
[4572]101#if 0
102 // this is currently just a driver stub.
[4812]103 {"jack", "JACK", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[4490]104  NULL, NULL, driver_jack_open_vio},
105#endif
[4572]106#endif
[4809]107#ifdef ROAR_HAVE_LIBARTSC
[4812]108 {"artsc", "aRts plain C API", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
[4809]109  NULL, NULL, driver_artsc_open_vio},
110#endif
[4812]111 {NULL, NULL, NULL, STREAM_DIR_NONE, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list
[0]112                                };
113
[4955]114void print_driverlist (enum output_format format) {
[0]115 int i;
[1918]116 char subsys[7] = "      ";
[4812]117 char mode[5]   = "    ";
[0]118
[4955]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:
[5274]125    printf("||=Driver =||=Mode =||=Flag =||=Subsys =||=Description =||=Devices =||\n");
[4955]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 }
[975]134
[0]135 for (i = 0; g_driver[i].name != NULL; i++) {
[1918]136  strncpy(subsys, "      ", 6);
[4812]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';
[1918]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';
[2233]152  if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW )
153   subsys[4] = 'R';
[2681]154  if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX )
155   subsys[5] = 'X';
[1918]156
[4955]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;
[4812]195  }
[0]196 }
197}
198
[931]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! */,
[2364]201                 char * device, struct roar_audio_info * info, int fh,
202                 struct roar_stream_server * sstream) {
[931]203 int i;
204
[4148]205#ifdef ROAR_DRIVER_DEFAULT
[931]206 if ( driver == NULL )
207  driver = ROAR_DRIVER_DEFAULT;
[4148]208#else
209 if ( driver == NULL )
210  return -1;
211#endif
[931]212
[5957]213#ifdef ROAR_DRIVER_DEVICE
214 if ( device == NULL )
215  device = ROAR_DRIVER_DEVICE;
216#endif
217
[1243]218 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
219
[931]220 for (i = 0; g_driver[i].name != NULL; i++) {
221  if ( strcmp(g_driver[i].name, driver) == 0 ) {
[4811]222   ROAR_DBG("driver_openvio(*): found driver: id = %i", i);
[931]223
224   *driver_id = i;
225
[1243]226   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
227
[931]228   if ( g_driver[i].vio_init == NULL ) {
[944]229    if ( g_driver[i].open == NULL ) { // this is the null driver
230     memset(calls, 0, sizeof(struct roar_vio_calls));
[5388]231     calls->flags = ROAR_VIO_FLAGS_NONE;
232     calls->refc  = 1;
[944]233     calls->read  = roar_vio_null_rw;
234     calls->write = roar_vio_null_rw;
235     return 0;
236    }
237
[4811]238    ROAR_WARN("driver_openvio(*): driver(%s) uses old non-vio interface!", driver);
[931]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
[4815]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
[1243]260   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
[2367]261   return g_driver[i].vio_init(calls, device, info, fh, sstream);
[931]262  }
263 }
264 return -1;
265}
266
[937]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
[1244]276 if ( calls->close != NULL )
277  roar_vio_close(calls);
278
[937]279 return 0;
280}
281
[1590]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
[2345]297
[2507]298#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
[2367]299int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
[2345]300 char * driver;
301 char * delm;
302 int ret;
303
[5586]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 }
[2345]312
313 if (device == NULL) {
314  driver = NULL;
315 } else {
[4975]316  driver = roar_mm_strdup(device);
[2345]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 )
[4975]331  roar_mm_free(driver);
[2345]332
333 return ret;
334}
[2507]335#endif
[2345]336
[5278]337int  driver_dummy_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) {
[5586]338 (void)vio;
339
[5276]340 switch (cmd) {
341  case ROAR_VIO_CTL_NONBLOCK:
342    if ( *(const int*)data == ROAR_SOCKET_BLOCK )
343     return 0;
[5012]344
[5276]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 }
[5012]353}
354
[0]355//ll
Note: See TracBrowser for help on using the repository browser.