source: roaraudio/roard/driver.c @ 1590:07fa8c4493e4

Last change on this file since 1590:07fa8c4493e4 was 1590:07fa8c4493e4, checked in by phi, 15 years ago

added first try of support for hwmixer flag

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