source: roaraudio/roard/driver.c @ 2681:359a85bcf5e9

Last change on this file since 2681:359a85bcf5e9 was 2681:359a85bcf5e9, checked in by phi, 15 years ago

added new subsystem complex

File size: 8.8 KB
Line 
1//driver.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27struct roar_driver g_driver[] = {
28 { "null", "null audio driver", "/dev/null", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
29   NULL, NULL, NULL},
30#ifdef ROAR_HAVE_ESD
31 { "esd", "EsounD audio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
32   NULL, driver_esd_close, driver_esd_open_vio},
33#endif
34 { "roar", "RoarAudio driver", "localhost, remote.host.dom", DRV_FLAG_NONE,
35   ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_COMPLEX,
36   NULL, driver_roar_close, driver_roar_open_vio},
37#ifdef ROAR_HAVE_IO_POSIX
38 { "raw",  "RAW PCM driver", "/some/file", DRV_FLAG_FHSEC,
39   ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX,
40   NULL, NULL, driver_raw_open_vio},
41#endif
42#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
43#ifndef ROAR_DEFAULT_OSS_DEV
44#define ROAR_DEFAULT_OSS_DEV "no default device"
45#endif
46 { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
47   NULL, NULL, driver_oss_open},
48#endif
49#ifdef ROAR_HAVE_LIBAO
50 { "ao", "libao audio driver", "DRIVER", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
51   NULL, driver_ao_close, driver_ao_open_vio},
52#endif
53#ifdef ROAR_HAVE_LIBSHOUT
54 {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
55  NULL, driver_shout_close, driver_shout_open_vio},
56#endif
57#ifdef ROAR_HAVE_LIBSNDIO
58 {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI,
59  NULL, NULL, driver_sndio_open},
60#endif
61#ifndef ROAR_WITHOUT_DCOMP_DMX
62 {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
63  NULL, NULL, driver_dmx_open_vio},
64#endif
65#ifndef ROAR_WITHOUT_DCOMP_PWMLED
66 {"pwmled", "PWM LED driver", "/dev/ttyS0", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT,
67  NULL, NULL, driver_pwmled_open_vio},
68#endif
69#ifdef ROAR_HAVE_DRIVER_SYSCLOCK
70 {"sysclock", "System Clock Clock Source", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
71  NULL, NULL, driver_sysclock_open_vio},
72#endif
73#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
74 {"cdriver", "RoarAudio Client driver", "driver#device", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM,
75  NULL, NULL, driver_cdriver_open},
76#endif
77 {NULL, NULL, NULL, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list
78                                };
79
80void print_driverlist (void) {
81 int i;
82 char subsys[7] = "      ";
83
84 printf("  Driver   Flag Subsys - Description (devices)\n");
85 printf("------------------------------------------------------\n");
86
87 for (i = 0; g_driver[i].name != NULL; i++) {
88  strncpy(subsys, "      ", 6);
89
90  if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM )
91   subsys[0] = 'W';
92  if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI )
93   subsys[1] = 'M';
94  if ( g_driver[i].subsystems & ROAR_SUBSYS_CB )
95   subsys[2] = 'C';
96  if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT )
97   subsys[3] = 'L';
98  if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW )
99   subsys[4] = 'R';
100  if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX )
101   subsys[5] = 'X';
102
103  printf("  %-9s %c%c%c %6s - %s (devices: %s)\n", g_driver[i].name,
104                g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? 's' : ' ',
105                g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
106                g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
107                subsys,
108                g_driver[i].desc, g_driver[i].devices);
109 }
110}
111
112int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) {
113 int i;
114
115 if ( driver == NULL )
116  driver = ROAR_DRIVER_DEFAULT;
117
118 for (i = 0; g_driver[i].name != NULL; i++) {
119  if ( strcmp(g_driver[i].name, driver) == 0 ) {
120   ROAR_DBG("driver_open(*): found driver: id = %i", i);
121
122   *driver_id = i;
123
124   if ( g_driver[i].vio_init != NULL ) {
125    if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL )
126     return -1;
127
128    memset(*inst, 0, sizeof(struct roar_vio_calls));
129
130    if ( (i = g_driver[i].vio_init(*inst, device, info, -1, NULL)) == -1 ) {
131     free(*inst);
132     return -1;
133    }
134    return i;
135   }
136
137   if ( g_driver[i].open ) {
138    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
139    return g_driver[i].open(inst, device, info);
140   }
141
142   return 0;
143  }
144 }
145
146 return -1;
147}
148
149int driver_openvio(struct roar_vio_calls * calls,
150                 int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */,
151                 char * device, struct roar_audio_info * info, int fh,
152                 struct roar_stream_server * sstream) {
153 int i;
154
155 if ( driver == NULL )
156  driver = ROAR_DRIVER_DEFAULT;
157
158 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
159
160 for (i = 0; g_driver[i].name != NULL; i++) {
161  if ( strcmp(g_driver[i].name, driver) == 0 ) {
162   ROAR_DBG("driver_open(*): found driver: id = %i", i);
163
164   *driver_id = i;
165
166   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
167
168   if ( g_driver[i].vio_init == NULL ) {
169    if ( g_driver[i].open == NULL ) { // this is the null driver
170     memset(calls, 0, sizeof(struct roar_vio_calls));
171     calls->read  = roar_vio_null_rw;
172     calls->write = roar_vio_null_rw;
173     return 0;
174    }
175
176    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
177    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
178        calls, i, driver, device, info, fh);
179    return -1;
180   }
181
182   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
183   return g_driver[i].vio_init(calls, device, info, fh, sstream);
184  }
185 }
186 return -1;
187}
188
189int driver_close(DRIVER_USERDATA_T   inst, int driver) {
190 int ret = 0;
191 ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver);
192
193 if ( driver == -1 )
194  return -1;
195
196 if ( g_driver[driver].close )
197  ret = g_driver[driver].close(inst);
198
199 if ( g_driver[driver].vio_init != NULL )
200  free(inst);
201
202 return ret;
203}
204
205int driver_closevio(struct roar_vio_calls * calls, int driver) {
206 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
207
208 if ( driver == -1 )
209  return -1;
210
211 if ( g_driver[driver].close )
212  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
213
214 if ( calls->close != NULL )
215  roar_vio_close(calls);
216
217 return 0;
218}
219
220int driver_write(DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
221 if ( driver == -1 )
222  return -1;
223
224 if ( g_driver[driver].vio_init != NULL )
225  return roar_vio_write((struct roar_vio_calls *) inst, buf, len);
226
227 return 0;
228}
229
230int driver_read (DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
231 if ( driver == -1 )
232  return -1;
233
234 if ( g_driver[driver].vio_init != NULL )
235  return roar_vio_read((struct roar_vio_calls *) inst, buf, len);
236
237 return 0;
238}
239
240int driver_set_volume(int stream, struct roar_mixer_settings * mixer) {
241 struct roar_stream_server * ss;
242
243 if ( (ss = g_streams[stream]) == NULL )
244  return -1;
245
246 if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) )
247  return 0;
248
249 if ( ss->driver_id == -1 )
250  return -1;
251
252 return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer);
253}
254
255
256#ifndef ROAR_WITHOUT_DCOMP_CDRIVER
257int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
258 char * driver;
259 char * delm;
260 int ret;
261
262 ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh);
263
264 if (device == NULL) {
265  driver = NULL;
266  return -1;
267 } else {
268  driver = strdup(device);
269
270  if ( (delm = strstr(driver, "#")) == NULL ) {
271   device = NULL;
272  } else {
273   *delm  = 0;
274   device = strstr(device, "#") + 1;
275  }
276 }
277
278 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);
279 ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY);
280 ROAR_DBG("driver_cdriver_open(*): RET %i", ret);
281
282 if ( driver != NULL )
283  free(driver);
284
285 return ret;
286}
287#endif
288
289//ll
Note: See TracBrowser for help on using the repository browser.