source: roaraudio/roard/driver.c @ 2779:bbc1d711c495

Last change on this file since 2779:bbc1d711c495 was 2779:bbc1d711c495, checked in by phi, 15 years ago

seems that the WMM driver finaly works

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