source: roaraudio/roard/driver.c @ 1478:8b72a771afd4

Last change on this file since 1478:8b72a771afd4 was 1478:8b72a771afd4, checked in by phi, 15 years ago

updated driver list

File size: 6.4 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 {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list
49                                };
50
51void print_driverlist (void) {
52 int i;
53
54 printf("  Driver Type - Description (devices)\n");
55 printf("------------------------------------------------------\n");
56
57 for (i = 0; g_driver[i].name != NULL; i++) {
58  printf("  %-8s %c%c - %s (devices: %s)\n", g_driver[i].name,
59                g_driver[i].open     != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ',
60                g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ',
61                g_driver[i].desc, g_driver[i].devices);
62 }
63}
64
65int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) {
66 int i;
67
68 if ( driver == NULL )
69  driver = ROAR_DRIVER_DEFAULT;
70
71 for (i = 0; g_driver[i].name != NULL; i++) {
72  if ( strcmp(g_driver[i].name, driver) == 0 ) {
73   ROAR_DBG("driver_open(*): found driver: id = %i", i);
74
75   *driver_id = i;
76
77   if ( g_driver[i].vio_init != NULL ) {
78    if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL )
79     return -1;
80
81    memset(*inst, 0, sizeof(struct roar_vio_calls));
82
83    if ( (i = g_driver[i].vio_init(*inst, device, info, -1)) == -1 ) {
84     free(*inst);
85     return -1;
86    }
87    return i;
88   }
89
90   if ( g_driver[i].open ) {
91    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
92    return g_driver[i].open(inst, device, info);
93   }
94
95   return 0;
96  }
97 }
98
99 return -1;
100}
101
102int driver_openvio(struct roar_vio_calls * calls,
103                 int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */,
104                 char * device, struct roar_audio_info * info, int fh) {
105 int i;
106
107 if ( driver == NULL )
108  driver = ROAR_DRIVER_DEFAULT;
109
110 ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver);
111
112 for (i = 0; g_driver[i].name != NULL; i++) {
113  if ( strcmp(g_driver[i].name, driver) == 0 ) {
114   ROAR_DBG("driver_open(*): found driver: id = %i", i);
115
116   *driver_id = i;
117
118   ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i);
119
120   if ( g_driver[i].vio_init == NULL ) {
121    if ( g_driver[i].open == NULL ) { // this is the null driver
122     memset(calls, 0, sizeof(struct roar_vio_calls));
123     calls->read  = roar_vio_null_rw;
124     calls->write = roar_vio_null_rw;
125     return 0;
126    }
127
128    ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver);
129    ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!",
130        calls, i, driver, device, info, fh);
131    return -1;
132   }
133
134   ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i);
135   return g_driver[i].vio_init(calls, device, info, fh);
136  }
137 }
138 return -1;
139}
140
141int driver_close(DRIVER_USERDATA_T   inst, int driver) {
142 int ret = 0;
143 ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver);
144
145 if ( driver == -1 )
146  return -1;
147
148 if ( g_driver[driver].close )
149  ret = g_driver[driver].close(inst);
150
151 if ( g_driver[driver].vio_init != NULL )
152  free(inst);
153
154 return ret;
155}
156
157int driver_closevio(struct roar_vio_calls * calls, int driver) {
158 ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver);
159
160 if ( driver == -1 )
161  return -1;
162
163 if ( g_driver[driver].close )
164  return g_driver[driver].close((DRIVER_USERDATA_T)calls);
165
166 if ( calls->close != NULL )
167  roar_vio_close(calls);
168
169 return 0;
170}
171
172int driver_pause(DRIVER_USERDATA_T   inst, int driver, int newstate) {
173 if ( driver == -1 )
174  return -1;
175
176 if ( g_driver[driver].pause )
177  return g_driver[driver].pause(inst, newstate);
178
179 return -1;
180}
181
182int driver_write(DRIVER_USERDATA_T   inst, int driver, char * buf, int len) {
183 if ( driver == -1 )
184  return -1;
185
186 if ( g_driver[driver].vio_init != NULL )
187  return roar_vio_write((struct roar_vio_calls *) inst, buf, len);
188
189 if ( g_driver[driver].write )
190  return g_driver[driver].write(inst, buf, len);
191
192 return 0;
193}
194
195int driver_read (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_read((struct roar_vio_calls *) inst, buf, len);
201
202 if ( g_driver[driver].read )
203  return g_driver[driver].read(inst, buf, len);
204
205 return 0;
206}
207
208int driver_flush(DRIVER_USERDATA_T   inst, int driver) {
209 if ( driver == -1 )
210  return -1;
211
212 if ( g_driver[driver].flush )
213  return g_driver[driver].flush(inst);
214
215 return 0;
216}
217
218//ll
Note: See TracBrowser for help on using the repository browser.