source: roaraudio/roard/driver.c @ 5044:95b04c57ae49

Last change on this file since 5044:95b04c57ae49 was 5044:95b04c57ae49, checked in by phi, 13 years ago

cdriver API supports driver=NULL

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