source: roaraudio/roard/driver.c @ 3602:26da60465e66

Last change on this file since 3602:26da60465e66 was 3602:26da60465e66, checked in by phi, 14 years ago

driver pwmled requires dstr, too

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