source: roaraudio/roard/driver.c @ 5244:e97aa5907fa2

Last change on this file since 5244:e97aa5907fa2 was 5244:e97aa5907fa2, checked in by phi, 12 years ago

fully removed driver "raw"

File size: 11.9 KB
Line 
1//driver.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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_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
110void 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
195int 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->read  = roar_vio_null_rw;
223     calls->write = roar_vio_null_rw;
224     return 0;
225    }
226
227    ROAR_WARN("driver_openvio(*): driver(%s) uses old non-vio interface!", driver);
228    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
229        calls, i, driver, device, info, fh);
230    return -1;
231   }
232
233   // if this driver does not support input we need to check if it is used in input mode.
234   if ( !(g_driver[i].mode & STREAM_DIR_IN) ) {
235    if ( sstream == NULL )
236     return -1;
237
238    if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) ) {
239     if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) == 1 ) {
240      if ( streams_reset_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) == -1 )
241       return -1;
242     } else {
243      ROAR_WARN("driver_openvio(*): driver(%s) is not abled to record data and autoconf flag is not set.", driver);
244      return -1;
245     }
246    }
247   }
248
249   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
250   return g_driver[i].vio_init(calls, device, info, fh, sstream);
251  }
252 }
253 return -1;
254}
255
256int driver_closevio(struct roar_vio_calls * calls, int driver) {
257 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
258
259 if ( driver == -1 )
260  return -1;
261
262 if ( g_driver[driver].close )
263  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
264
265 if ( calls->close != NULL )
266  roar_vio_close(calls);
267
268 return 0;
269}
270
271int driver_set_volume(int stream, struct roar_mixer_settings * mixer) {
272 struct roar_stream_server * ss;
273
274 if ( (ss = g_streams[stream]) == NULL )
275  return -1;
276
277 if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) )
278  return 0;
279
280 if ( ss->driver_id == -1 )
281  return -1;
282
283 return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer);
284}
285
286
287#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
288int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
289 char * driver;
290 char * delm;
291 int ret;
292
293 ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh);
294
295 if (device == NULL) {
296  driver = NULL;
297 } else {
298  driver = roar_mm_strdup(device);
299
300  if ( (delm = strstr(driver, "#")) == NULL ) {
301   device = NULL;
302  } else {
303   *delm  = 0;
304   device = strstr(device, "#") + 1;
305  }
306 }
307
308 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);
309 ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY);
310 ROAR_DBG("driver_cdriver_open(*): RET %i", ret);
311
312 if ( driver != NULL )
313  roar_mm_free(driver);
314
315 return ret;
316}
317#endif
318
319int  driver_dummy_nonblock(struct roar_vio_calls * vio, int state) {
320 if ( state == ROAR_SOCKET_BLOCK )
321  return 0;
322
323 roar_err_set(ROAR_ERROR_NOTSUP);
324 return -1;
325}
326
327//ll
Note: See TracBrowser for help on using the repository browser.