source: roaraudio/roard/driver.c @ 1974:3cfe906b214f

Last change on this file since 1974:3cfe906b214f was 1974:3cfe906b214f, checked in by phi, 15 years ago

added very simple PWM LED driver

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