[668] | 1 | //driver.c: |
---|
[0] | 2 | |
---|
[668] | 3 | /* |
---|
[3358] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
[0] | 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
| 28 | struct roar_driver g_driver[] = { |
---|
[1918] | 29 | { "null", "null audio driver", "/dev/null", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 30 | NULL, NULL, NULL}, |
---|
[0] | 31 | #ifdef ROAR_HAVE_ESD |
---|
[1918] | 32 | { "esd", "EsounD audio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3591] | 33 | NULL, NULL, driver_esd_open_vio}, |
---|
[0] | 34 | #endif |
---|
[2508] | 35 | { "roar", "RoarAudio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, |
---|
[2681] | 36 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_COMPLEX, |
---|
[3593] | 37 | NULL, NULL, driver_roar_open_vio}, |
---|
[1478] | 38 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[2682] | 39 | { "raw", "RAW driver", "/some/file", DRV_FLAG_FHSEC, |
---|
[2681] | 40 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX, |
---|
[2365] | 41 | NULL, NULL, driver_raw_open_vio}, |
---|
[3601] | 42 | #endif |
---|
| 43 | #ifndef ROAR_WITHOUT_VIO_DSTR |
---|
[3262] | 44 | { "dstr", "VIO DSTR driver", "/some/file", DRV_FLAG_FHSEC, |
---|
| 45 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX, |
---|
| 46 | NULL, NULL, driver_dstr_open_vio}, |
---|
[1478] | 47 | #endif |
---|
[919] | 48 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
[924] | 49 | #ifndef ROAR_DEFAULT_OSS_DEV |
---|
| 50 | #define ROAR_DEFAULT_OSS_DEV "no default device" |
---|
| 51 | #endif |
---|
[3838] | 52 | { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, DRV_FLAG_FHSEC, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 53 | NULL, NULL, driver_oss_open}, |
---|
[919] | 54 | #endif |
---|
[0] | 55 | #ifdef ROAR_HAVE_LIBAO |
---|
[1918] | 56 | { "ao", "libao audio driver", "DRIVER", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3588] | 57 | NULL, NULL, driver_ao_open_vio}, |
---|
[0] | 58 | #endif |
---|
[951] | 59 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
[1918] | 60 | {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3589] | 61 | NULL, NULL, driver_shout_open_vio}, |
---|
[951] | 62 | #endif |
---|
[1543] | 63 | #ifdef ROAR_HAVE_LIBSNDIO |
---|
[2370] | 64 | {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI, |
---|
[2365] | 65 | NULL, NULL, driver_sndio_open}, |
---|
[1543] | 66 | #endif |
---|
[3725] | 67 | #ifdef ROAR_HAVE_LIBRSOUND |
---|
| 68 | {"rsound", "RSound", "servername", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
| 69 | NULL, NULL, driver_rsound_open}, |
---|
| 70 | #endif |
---|
[3751] | 71 | #ifdef _DRIVER_PORTAUDIO_CAN_OPERATE |
---|
| 72 | {"portaudio", "PortAudio", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
| 73 | NULL, NULL, driver_portaudio_open}, |
---|
| 74 | #endif |
---|
[3693] | 75 | #ifdef ROAR_HAVE_LIBASOUND |
---|
| 76 | {"alsa", "ALSA", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio}, |
---|
| 77 | #endif |
---|
[2779] | 78 | #ifdef ROAR_HAVE_LIBWINMM |
---|
| 79 | {"wmm", "Win32 MM", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio}, |
---|
| 80 | #endif |
---|
[2503] | 81 | #ifndef ROAR_WITHOUT_DCOMP_DMX |
---|
[1918] | 82 | {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 83 | NULL, NULL, driver_dmx_open_vio}, |
---|
[2503] | 84 | #endif |
---|
[3602] | 85 | #if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR) |
---|
[1974] | 86 | {"pwmled", "PWM LED driver", "/dev/ttyS0", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 87 | NULL, NULL, driver_pwmled_open_vio}, |
---|
[2502] | 88 | #endif |
---|
[2209] | 89 | #ifdef ROAR_HAVE_DRIVER_SYSCLOCK |
---|
[2207] | 90 | {"sysclock", "System Clock Clock Source", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 91 | NULL, NULL, driver_sysclock_open_vio}, |
---|
[2209] | 92 | #endif |
---|
[2507] | 93 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[2363] | 94 | {"cdriver", "RoarAudio Client driver", "driver#device", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 95 | NULL, NULL, driver_cdriver_open}, |
---|
[2507] | 96 | #endif |
---|
[3839] | 97 | #ifdef ROAR_HAVE_LIBPULSE |
---|
| 98 | {"pulsesimple", "PulseAudio Simple", "server", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
| 99 | NULL, NULL, driver_pulsesimple_open}, |
---|
| 100 | #endif |
---|
[2365] | 101 | {NULL, NULL, NULL, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list |
---|
[0] | 102 | }; |
---|
| 103 | |
---|
| 104 | void print_driverlist (void) { |
---|
| 105 | int i; |
---|
[1918] | 106 | char subsys[7] = " "; |
---|
[0] | 107 | |
---|
[3840] | 108 | printf(" Driver Flag Subsys - Description (devices)\n"); |
---|
| 109 | printf("---------------------------------------------------------\n"); |
---|
[975] | 110 | |
---|
[0] | 111 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
[1918] | 112 | strncpy(subsys, " ", 6); |
---|
| 113 | |
---|
| 114 | if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 115 | subsys[0] = 'W'; |
---|
| 116 | if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 117 | subsys[1] = 'M'; |
---|
| 118 | if ( g_driver[i].subsystems & ROAR_SUBSYS_CB ) |
---|
| 119 | subsys[2] = 'C'; |
---|
| 120 | if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 121 | subsys[3] = 'L'; |
---|
[2233] | 122 | if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
| 123 | subsys[4] = 'R'; |
---|
[2681] | 124 | if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
| 125 | subsys[5] = 'X'; |
---|
[1918] | 126 | |
---|
[3840] | 127 | printf(" %-12s %c%c%c %6s - %s (devices: %s)\n", g_driver[i].name, |
---|
[1915] | 128 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
[947] | 129 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
| 130 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
[1918] | 131 | subsys, |
---|
[947] | 132 | g_driver[i].desc, g_driver[i].devices); |
---|
[0] | 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) { |
---|
| 137 | int i; |
---|
| 138 | |
---|
| 139 | if ( driver == NULL ) |
---|
| 140 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 141 | |
---|
| 142 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 143 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 144 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 145 | |
---|
| 146 | *driver_id = i; |
---|
| 147 | |
---|
[911] | 148 | if ( g_driver[i].vio_init != NULL ) { |
---|
| 149 | if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL ) |
---|
| 150 | return -1; |
---|
| 151 | |
---|
[912] | 152 | memset(*inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 153 | |
---|
[2367] | 154 | if ( (i = g_driver[i].vio_init(*inst, device, info, -1, NULL)) == -1 ) { |
---|
[911] | 155 | free(*inst); |
---|
| 156 | return -1; |
---|
| 157 | } |
---|
| 158 | return i; |
---|
| 159 | } |
---|
| 160 | |
---|
[944] | 161 | if ( g_driver[i].open ) { |
---|
| 162 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 163 | return g_driver[i].open(inst, device, info); |
---|
| 164 | } |
---|
[912] | 165 | |
---|
[0] | 166 | return 0; |
---|
| 167 | } |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | return -1; |
---|
| 171 | } |
---|
| 172 | |
---|
[931] | 173 | int driver_openvio(struct roar_vio_calls * calls, |
---|
| 174 | int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */, |
---|
[2364] | 175 | char * device, struct roar_audio_info * info, int fh, |
---|
| 176 | struct roar_stream_server * sstream) { |
---|
[931] | 177 | int i; |
---|
| 178 | |
---|
| 179 | if ( driver == NULL ) |
---|
| 180 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 181 | |
---|
[1243] | 182 | ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver); |
---|
| 183 | |
---|
[931] | 184 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 185 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 186 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 187 | |
---|
| 188 | *driver_id = i; |
---|
| 189 | |
---|
[1243] | 190 | ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i); |
---|
| 191 | |
---|
[931] | 192 | if ( g_driver[i].vio_init == NULL ) { |
---|
[944] | 193 | if ( g_driver[i].open == NULL ) { // this is the null driver |
---|
| 194 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 195 | calls->read = roar_vio_null_rw; |
---|
| 196 | calls->write = roar_vio_null_rw; |
---|
| 197 | return 0; |
---|
| 198 | } |
---|
| 199 | |
---|
[931] | 200 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 201 | ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!", |
---|
| 202 | calls, i, driver, device, info, fh); |
---|
| 203 | return -1; |
---|
| 204 | } |
---|
| 205 | |
---|
[1243] | 206 | ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i); |
---|
[2367] | 207 | return g_driver[i].vio_init(calls, device, info, fh, sstream); |
---|
[931] | 208 | } |
---|
| 209 | } |
---|
| 210 | return -1; |
---|
| 211 | } |
---|
| 212 | |
---|
[0] | 213 | int driver_close(DRIVER_USERDATA_T inst, int driver) { |
---|
[912] | 214 | int ret = 0; |
---|
[0] | 215 | ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver); |
---|
| 216 | |
---|
| 217 | if ( driver == -1 ) |
---|
| 218 | return -1; |
---|
| 219 | |
---|
| 220 | if ( g_driver[driver].close ) |
---|
[912] | 221 | ret = g_driver[driver].close(inst); |
---|
[0] | 222 | |
---|
[912] | 223 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 224 | free(inst); |
---|
| 225 | |
---|
| 226 | return ret; |
---|
[0] | 227 | } |
---|
| 228 | |
---|
[937] | 229 | int driver_closevio(struct roar_vio_calls * calls, int driver) { |
---|
| 230 | ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver); |
---|
| 231 | |
---|
| 232 | if ( driver == -1 ) |
---|
| 233 | return -1; |
---|
| 234 | |
---|
| 235 | if ( g_driver[driver].close ) |
---|
| 236 | return g_driver[driver].close((DRIVER_USERDATA_T)calls); |
---|
| 237 | |
---|
[1244] | 238 | if ( calls->close != NULL ) |
---|
| 239 | roar_vio_close(calls); |
---|
| 240 | |
---|
[937] | 241 | return 0; |
---|
| 242 | } |
---|
| 243 | |
---|
[0] | 244 | int driver_write(DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 245 | if ( driver == -1 ) |
---|
| 246 | return -1; |
---|
| 247 | |
---|
[911] | 248 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 249 | return roar_vio_write((struct roar_vio_calls *) inst, buf, len); |
---|
| 250 | |
---|
[0] | 251 | return 0; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | int driver_read (DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 255 | if ( driver == -1 ) |
---|
| 256 | return -1; |
---|
| 257 | |
---|
[911] | 258 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 259 | return roar_vio_read((struct roar_vio_calls *) inst, buf, len); |
---|
| 260 | |
---|
[0] | 261 | return 0; |
---|
| 262 | } |
---|
| 263 | |
---|
[1590] | 264 | int driver_set_volume(int stream, struct roar_mixer_settings * mixer) { |
---|
| 265 | struct roar_stream_server * ss; |
---|
| 266 | |
---|
| 267 | if ( (ss = g_streams[stream]) == NULL ) |
---|
| 268 | return -1; |
---|
| 269 | |
---|
| 270 | if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) ) |
---|
| 271 | return 0; |
---|
| 272 | |
---|
| 273 | if ( ss->driver_id == -1 ) |
---|
| 274 | return -1; |
---|
| 275 | |
---|
| 276 | return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer); |
---|
| 277 | } |
---|
| 278 | |
---|
[2345] | 279 | |
---|
[2507] | 280 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[2367] | 281 | int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[2345] | 282 | char * driver; |
---|
| 283 | char * delm; |
---|
| 284 | int ret; |
---|
| 285 | |
---|
| 286 | ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh); |
---|
| 287 | |
---|
| 288 | if (device == NULL) { |
---|
| 289 | driver = NULL; |
---|
| 290 | return -1; |
---|
| 291 | } else { |
---|
| 292 | driver = strdup(device); |
---|
| 293 | |
---|
| 294 | if ( (delm = strstr(driver, "#")) == NULL ) { |
---|
| 295 | device = NULL; |
---|
| 296 | } else { |
---|
| 297 | *delm = 0; |
---|
| 298 | device = strstr(device, "#") + 1; |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | ROAR_DBG("driver_cdriver_open(*): CALL roar_cdriver_open(inst=%p, driver='%s', device='%s', info=%p, dir=ROAR_DIR_PLAY)", inst, driver, device, info); |
---|
| 303 | ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY); |
---|
| 304 | ROAR_DBG("driver_cdriver_open(*): RET %i", ret); |
---|
| 305 | |
---|
| 306 | if ( driver != NULL ) |
---|
| 307 | free(driver); |
---|
| 308 | |
---|
| 309 | return ret; |
---|
| 310 | } |
---|
[2507] | 311 | #endif |
---|
[2345] | 312 | |
---|
[0] | 313 | //ll |
---|