source: roaraudio/roard/driver.c @ 3725:35622f6adcee

Last change on this file since 3725:35622f6adcee was 3725:35622f6adcee, checked in by phi, 14 years ago

added RSound driver

File size: 9.5 KB
Line 
1//driver.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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", "/dev/null", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
30   NULL, NULL, NULL},
31#ifdef ROAR_HAVE_ESD
32 { "esd", "EsounD audio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
33   NULL, NULL, driver_esd_open_vio},
34#endif
35 { "roar", "RoarAudio driver", "localhost, remote.host.dom", 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", 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", 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, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
53   NULL, NULL, driver_oss_open},
54#endif
55#ifdef ROAR_HAVE_LIBAO
56 { "ao", "libao audio driver", "DRIVER", 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", 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", 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", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
69  NULL, NULL, driver_rsound_open},
70#endif
71#ifdef ROAR_HAVE_LIBASOUND
72 {"alsa", "ALSA", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio},
73#endif
74#ifdef ROAR_HAVE_LIBWINMM
75 {"wmm", "Win32 MM", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio},
76#endif
77#ifndef ROAR_WITHOUT_DCOMP_DMX
78 {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
79  NULL, NULL, driver_dmx_open_vio},
80#endif
81#if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR)
82 {"pwmled", "PWM LED driver", "/dev/ttyS0", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
83  NULL, NULL, driver_pwmled_open_vio},
84#endif
85#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
86 {"sysclock", "System Clock Clock Source", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
87  NULL, NULL, driver_sysclock_open_vio},
88#endif
89#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
90 {"cdriver", "RoarAudio Client driver", "driver#device", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
91  NULL, NULL, driver_cdriver_open},
92#endif
93 {NULL, NULL, NULL, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list
94                                };
95
96void print_driverlist (void) {
97 int i;
98 char subsys[7] = "      ";
99
100 printf("  Driver   Flag Subsys - Description (devices)\n");
101 printf("------------------------------------------------------\n");
102
103 for (i = 0; g_driver[i].name != NULL; i++) {
104  strncpy(subsys, "      ", 6);
105
106  if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM )
107   subsys[0] = 'W';
108  if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI )
109   subsys[1] = 'M';
110  if ( g_driver[i].subsystems & ROAR_SUBSYS_CB )
111   subsys[2] = 'C';
112  if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT )
113   subsys[3] = 'L';
114  if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW )
115   subsys[4] = 'R';
116  if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX )
117   subsys[5] = 'X';
118
119  printf("  %-9s %c%c%c %6s - %s (devices: %s)\n", g_driver[i].name,
120                g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? 's' : ' ',
121                g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
122                g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
123                subsys,
124                g_driver[i].desc, g_driver[i].devices);
125 }
126}
127
128int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) {
129 int i;
130
131 if ( driver == NULL )
132  driver = ROAR_DRIVER_DEFAULT;
133
134 for (i = 0; g_driver[i].name != NULL; i++) {
135  if ( strcmp(g_driver[i].name, driver) == 0 ) {
136   ROAR_DBG("driver_open(*): found driver: id = %i", i);
137
138   *driver_id = i;
139
140   if ( g_driver[i].vio_init != NULL ) {
141    if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL )
142     return -1;
143
144    memset(*inst, 0, sizeof(struct roar_vio_calls));
145
146    if ( (i = g_driver[i].vio_init(*inst, device, info, -1, NULL)) == -1 ) {
147     free(*inst);
148     return -1;
149    }
150    return i;
151   }
152
153   if ( g_driver[i].open ) {
154    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
155    return g_driver[i].open(inst, device, info);
156   }
157
158   return 0;
159  }
160 }
161
162 return -1;
163}
164
165int driver_openvio(struct roar_vio_calls * calls,
166                 int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */,
167                 char * device, struct roar_audio_info * info, int fh,
168                 struct roar_stream_server * sstream) {
169 int i;
170
171 if ( driver == NULL )
172  driver = ROAR_DRIVER_DEFAULT;
173
174 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
175
176 for (i = 0; g_driver[i].name != NULL; i++) {
177  if ( strcmp(g_driver[i].name, driver) == 0 ) {
178   ROAR_DBG("driver_open(*): found driver: id = %i", i);
179
180   *driver_id = i;
181
182   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
183
184   if ( g_driver[i].vio_init == NULL ) {
185    if ( g_driver[i].open == NULL ) { // this is the null driver
186     memset(calls, 0, sizeof(struct roar_vio_calls));
187     calls->read  = roar_vio_null_rw;
188     calls->write = roar_vio_null_rw;
189     return 0;
190    }
191
192    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
193    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
194        calls, i, driver, device, info, fh);
195    return -1;
196   }
197
198   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
199   return g_driver[i].vio_init(calls, device, info, fh, sstream);
200  }
201 }
202 return -1;
203}
204
205int driver_close(DRIVER_USERDATA_T   inst, int driver) {
206 int ret = 0;
207 ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver);
208
209 if ( driver == -1 )
210  return -1;
211
212 if ( g_driver[driver].close )
213  ret = g_driver[driver].close(inst);
214
215 if ( g_driver[driver].vio_init != NULL )
216  free(inst);
217
218 return ret;
219}
220
221int driver_closevio(struct roar_vio_calls * calls, int driver) {
222 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
223
224 if ( driver == -1 )
225  return -1;
226
227 if ( g_driver[driver].close )
228  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
229
230 if ( calls->close != NULL )
231  roar_vio_close(calls);
232
233 return 0;
234}
235
236int driver_write(DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
237 if ( driver == -1 )
238  return -1;
239
240 if ( g_driver[driver].vio_init != NULL )
241  return roar_vio_write((struct roar_vio_calls *) inst, buf, len);
242
243 return 0;
244}
245
246int driver_read (DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
247 if ( driver == -1 )
248  return -1;
249
250 if ( g_driver[driver].vio_init != NULL )
251  return roar_vio_read((struct roar_vio_calls *) inst, buf, len);
252
253 return 0;
254}
255
256int driver_set_volume(int stream, struct roar_mixer_settings * mixer) {
257 struct roar_stream_server * ss;
258
259 if ( (ss = g_streams[stream]) == NULL )
260  return -1;
261
262 if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) )
263  return 0;
264
265 if ( ss->driver_id == -1 )
266  return -1;
267
268 return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer);
269}
270
271
272#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
273int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
274 char * driver;
275 char * delm;
276 int ret;
277
278 ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh);
279
280 if (device == NULL) {
281  driver = NULL;
282  return -1;
283 } else {
284  driver = strdup(device);
285
286  if ( (delm = strstr(driver, "#")) == NULL ) {
287   device = NULL;
288  } else {
289   *delm  = 0;
290   device = strstr(device, "#") + 1;
291  }
292 }
293
294 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);
295 ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY);
296 ROAR_DBG("driver_cdriver_open(*): RET %i", ret);
297
298 if ( driver != NULL )
299  free(driver);
300
301 return ret;
302}
303#endif
304
305//ll
Note: See TracBrowser for help on using the repository browser.