source: roaraudio/roard/driver.c @ 1915:559d6db65d5d

Last change on this file since 1915:559d6db65d5d was 1915:559d6db65d5d, checked in by phi, 15 years ago

added flags to driver array

File size: 7.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, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
29#ifdef ROAR_HAVE_ESD
30 { "esd", "EsounD audio driver", "localhost, remote.host.dom", DRV_FLAG_NONE,
31   NULL, driver_esd_close, driver_esd_pause, NULL, NULL, driver_esd_flush, driver_esd_open_vio},
32#endif
33 { "roar", "RoarAudio driver", "localhost, remote.host.dom", DRV_FLAG_NONE,
34   NULL, driver_roar_close, NULL, NULL, NULL, driver_roar_flush, driver_roar_open_vio},
35#ifdef ROAR_HAVE_IO_POSIX
36 { "raw",  "RAW PCM driver", "/some/file", DRV_FLAG_FHSEC,
37   NULL, NULL, NULL, NULL, NULL, driver_raw_flush, driver_raw_open_vio},
38#endif
39#if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS)
40#ifndef ROAR_DEFAULT_OSS_DEV
41#define ROAR_DEFAULT_OSS_DEV "no default device"
42#endif
43 { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, DRV_FLAG_NONE,
44   NULL, NULL, NULL, NULL, NULL, NULL, driver_oss_open},
45#endif
46#ifdef ROAR_HAVE_LIBAO
47 { "ao", "libao audio driver", "DRIVER", DRV_FLAG_NONE,
48   NULL, driver_ao_close, NULL, NULL, NULL, NULL, driver_ao_open_vio},
49#endif
50#ifdef ROAR_HAVE_LIBSHOUT
51 {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", DRV_FLAG_NONE,
52  NULL, driver_shout_close, NULL, NULL, NULL, NULL, driver_shout_open_vio},
53#endif
54#ifdef ROAR_HAVE_LIBSNDIO
55 {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE,
56  NULL, NULL, NULL, NULL, NULL, NULL, driver_sndio_open},
57#endif
58 {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_NONE,
59  NULL, NULL, NULL, NULL, NULL, NULL, driver_dmx_open_vio},
60 {NULL, NULL, NULL, DRV_FLAG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
61                                };
62
63void print_driverlist (void) {
64 int i;
65
66 printf("  Driver Flag - Description (devices)\n");
67 printf("------------------------------------------------------\n");
68
69 for (i = 0; g_driver[i].name != NULL; i++) {
70  printf("  %-7s %c%c%c - %s (devices: %s)\n", g_driver[i].name,
71                g_driver[i].flags & DRV_FLAG_FHSEC                                                         ? 's' : ' ',
72                g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
73                g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
74                g_driver[i].desc, g_driver[i].devices);
75 }
76}
77
78int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) {
79 int i;
80
81 if ( driver == NULL )
82  driver = ROAR_DRIVER_DEFAULT;
83
84 for (i = 0; g_driver[i].name != NULL; i++) {
85  if ( strcmp(g_driver[i].name, driver) == 0 ) {
86   ROAR_DBG("driver_open(*): found driver: id = %i", i);
87
88   *driver_id = i;
89
90   if ( g_driver[i].vio_init != NULL ) {
91    if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL )
92     return -1;
93
94    memset(*inst, 0, sizeof(struct roar_vio_calls));
95
96    if ( (i = g_driver[i].vio_init(*inst, device, info, -1)) == -1 ) {
97     free(*inst);
98     return -1;
99    }
100    return i;
101   }
102
103   if ( g_driver[i].open ) {
104    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
105    return g_driver[i].open(inst, device, info);
106   }
107
108   return 0;
109  }
110 }
111
112 return -1;
113}
114
115int driver_openvio(struct roar_vio_calls * calls,
116                 int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */,
117                 char * device, struct roar_audio_info * info, int fh) {
118 int i;
119
120 if ( driver == NULL )
121  driver = ROAR_DRIVER_DEFAULT;
122
123 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
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
131   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
132
133   if ( g_driver[i].vio_init == NULL ) {
134    if ( g_driver[i].open == NULL ) { // this is the null driver
135     memset(calls, 0, sizeof(struct roar_vio_calls));
136     calls->read  = roar_vio_null_rw;
137     calls->write = roar_vio_null_rw;
138     return 0;
139    }
140
141    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
142    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
143        calls, i, driver, device, info, fh);
144    return -1;
145   }
146
147   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
148   return g_driver[i].vio_init(calls, device, info, fh);
149  }
150 }
151 return -1;
152}
153
154int driver_close(DRIVER_USERDATA_T   inst, int driver) {
155 int ret = 0;
156 ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver);
157
158 if ( driver == -1 )
159  return -1;
160
161 if ( g_driver[driver].close )
162  ret = g_driver[driver].close(inst);
163
164 if ( g_driver[driver].vio_init != NULL )
165  free(inst);
166
167 return ret;
168}
169
170int driver_closevio(struct roar_vio_calls * calls, int driver) {
171 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
172
173 if ( driver == -1 )
174  return -1;
175
176 if ( g_driver[driver].close )
177  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
178
179 if ( calls->close != NULL )
180  roar_vio_close(calls);
181
182 return 0;
183}
184
185int driver_pause(DRIVER_USERDATA_T   inst, int driver, int newstate) {
186 if ( driver == -1 )
187  return -1;
188
189 if ( g_driver[driver].pause )
190  return g_driver[driver].pause(inst, newstate);
191
192 return -1;
193}
194
195int driver_write(DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
196 if ( driver == -1 )
197  return -1;
198
199 if ( g_driver[driver].vio_init != NULL )
200  return roar_vio_write((struct roar_vio_calls *) inst, buf, len);
201
202 if ( g_driver[driver].write )
203  return g_driver[driver].write(inst, buf, len);
204
205 return 0;
206}
207
208int driver_read (DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
209 if ( driver == -1 )
210  return -1;
211
212 if ( g_driver[driver].vio_init != NULL )
213  return roar_vio_read((struct roar_vio_calls *) inst, buf, len);
214
215 if ( g_driver[driver].read )
216  return g_driver[driver].read(inst, buf, len);
217
218 return 0;
219}
220
221int driver_flush(DRIVER_USERDATA_T   inst, int driver) {
222 if ( driver == -1 )
223  return -1;
224
225 if ( g_driver[driver].flush )
226  return g_driver[driver].flush(inst);
227
228 return 0;
229}
230
231int driver_set_volume(int stream, struct roar_mixer_settings * mixer) {
232 struct roar_stream_server * ss;
233
234 if ( (ss = g_streams[stream]) == NULL )
235  return -1;
236
237 if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) )
238  return 0;
239
240 if ( ss->driver_id == -1 )
241  return -1;
242
243 return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer);
244}
245
246//ll
Note: See TracBrowser for help on using the repository browser.