source: roaraudio/roard/driver.c @ 1827:4bdb185f92a3

Last change on this file since 1827:4bdb185f92a3 was 1827:4bdb185f92a3, checked in by phi, 15 years ago

added basic DMX512 driver, still need to set stream direction

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