source: roaraudio/roard/driver.c @ 3593:81af1674e14f

Last change on this file since 3593:81af1674e14f was 3593:81af1674e14f, checked in by phi, 14 years ago

done cleanup for roar driver

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