source: roaraudio/roard/driver.c @ 4815:df2ef6edb97f

Last change on this file since 4815:df2ef6edb97f was 4815:df2ef6edb97f, checked in by phi, 13 years ago

added support to roard for record streams.

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