source: roaraudio/roard/driver.c @ 2507:946700cef0b8

Last change on this file since 2507:946700cef0b8 was 2507:946700cef0b8, checked in by phi, 15 years ago

make cdriver support in roard optional, disable it on --minimal

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