source: roaraudio/roard/driver.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 3358:7f9d211148e0, checked in by phi, 14 years ago

updated (C) statements

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