source: roaraudio/roard/driver.c @ 2345:5739d31d0f74

Last change on this file since 2345:5739d31d0f74 was 2345:5739d31d0f74, checked in by phi, 15 years ago

added support to open a cdriver

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