source: roaraudio/roard/driver.c @ 1243:741d7d9f165a

Last change on this file since 1243:741d7d9f165a was 1243:741d7d9f165a, checked in by phi, 15 years ago

use vio close for normal streams (non-driver)

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