[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 |
---|
[1918] | 52 | { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, DRV_FLAG_NONE, 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 |
---|
[3693] | 67 | #ifdef ROAR_HAVE_LIBASOUND |
---|
| 68 | {"alsa", "ALSA", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio}, |
---|
| 69 | #endif |
---|
[2779] | 70 | #ifdef ROAR_HAVE_LIBWINMM |
---|
| 71 | {"wmm", "Win32 MM", "???", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio}, |
---|
| 72 | #endif |
---|
[2503] | 73 | #ifndef ROAR_WITHOUT_DCOMP_DMX |
---|
[1918] | 74 | {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 75 | NULL, NULL, driver_dmx_open_vio}, |
---|
[2503] | 76 | #endif |
---|
[3602] | 77 | #if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR) |
---|
[1974] | 78 | {"pwmled", "PWM LED driver", "/dev/ttyS0", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 79 | NULL, NULL, driver_pwmled_open_vio}, |
---|
[2502] | 80 | #endif |
---|
[2209] | 81 | #ifdef ROAR_HAVE_DRIVER_SYSCLOCK |
---|
[2207] | 82 | {"sysclock", "System Clock Clock Source", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 83 | NULL, NULL, driver_sysclock_open_vio}, |
---|
[2209] | 84 | #endif |
---|
[2507] | 85 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[2363] | 86 | {"cdriver", "RoarAudio Client driver", "driver#device", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 87 | NULL, NULL, driver_cdriver_open}, |
---|
[2507] | 88 | #endif |
---|
[2365] | 89 | {NULL, NULL, NULL, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list |
---|
[0] | 90 | }; |
---|
| 91 | |
---|
| 92 | void print_driverlist (void) { |
---|
| 93 | int i; |
---|
[1918] | 94 | char subsys[7] = " "; |
---|
[0] | 95 | |
---|
[2207] | 96 | printf(" Driver Flag Subsys - Description (devices)\n"); |
---|
[975] | 97 | printf("------------------------------------------------------\n"); |
---|
| 98 | |
---|
[0] | 99 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
[1918] | 100 | strncpy(subsys, " ", 6); |
---|
| 101 | |
---|
| 102 | if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 103 | subsys[0] = 'W'; |
---|
| 104 | if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 105 | subsys[1] = 'M'; |
---|
| 106 | if ( g_driver[i].subsystems & ROAR_SUBSYS_CB ) |
---|
| 107 | subsys[2] = 'C'; |
---|
| 108 | if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 109 | subsys[3] = 'L'; |
---|
[2233] | 110 | if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
| 111 | subsys[4] = 'R'; |
---|
[2681] | 112 | if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
| 113 | subsys[5] = 'X'; |
---|
[1918] | 114 | |
---|
[2207] | 115 | printf(" %-9s %c%c%c %6s - %s (devices: %s)\n", g_driver[i].name, |
---|
[1915] | 116 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
[947] | 117 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
| 118 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
[1918] | 119 | subsys, |
---|
[947] | 120 | g_driver[i].desc, g_driver[i].devices); |
---|
[0] | 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) { |
---|
| 125 | int i; |
---|
| 126 | |
---|
| 127 | if ( driver == NULL ) |
---|
| 128 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 129 | |
---|
| 130 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 131 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 132 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 133 | |
---|
| 134 | *driver_id = i; |
---|
| 135 | |
---|
[911] | 136 | if ( g_driver[i].vio_init != NULL ) { |
---|
| 137 | if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL ) |
---|
| 138 | return -1; |
---|
| 139 | |
---|
[912] | 140 | memset(*inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 141 | |
---|
[2367] | 142 | if ( (i = g_driver[i].vio_init(*inst, device, info, -1, NULL)) == -1 ) { |
---|
[911] | 143 | free(*inst); |
---|
| 144 | return -1; |
---|
| 145 | } |
---|
| 146 | return i; |
---|
| 147 | } |
---|
| 148 | |
---|
[944] | 149 | if ( g_driver[i].open ) { |
---|
| 150 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 151 | return g_driver[i].open(inst, device, info); |
---|
| 152 | } |
---|
[912] | 153 | |
---|
[0] | 154 | return 0; |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | return -1; |
---|
| 159 | } |
---|
| 160 | |
---|
[931] | 161 | int driver_openvio(struct roar_vio_calls * calls, |
---|
| 162 | int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */, |
---|
[2364] | 163 | char * device, struct roar_audio_info * info, int fh, |
---|
| 164 | struct roar_stream_server * sstream) { |
---|
[931] | 165 | int i; |
---|
| 166 | |
---|
| 167 | if ( driver == NULL ) |
---|
| 168 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 169 | |
---|
[1243] | 170 | ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver); |
---|
| 171 | |
---|
[931] | 172 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 173 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 174 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 175 | |
---|
| 176 | *driver_id = i; |
---|
| 177 | |
---|
[1243] | 178 | ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i); |
---|
| 179 | |
---|
[931] | 180 | if ( g_driver[i].vio_init == NULL ) { |
---|
[944] | 181 | if ( g_driver[i].open == NULL ) { // this is the null driver |
---|
| 182 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 183 | calls->read = roar_vio_null_rw; |
---|
| 184 | calls->write = roar_vio_null_rw; |
---|
| 185 | return 0; |
---|
| 186 | } |
---|
| 187 | |
---|
[931] | 188 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 189 | ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!", |
---|
| 190 | calls, i, driver, device, info, fh); |
---|
| 191 | return -1; |
---|
| 192 | } |
---|
| 193 | |
---|
[1243] | 194 | ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i); |
---|
[2367] | 195 | return g_driver[i].vio_init(calls, device, info, fh, sstream); |
---|
[931] | 196 | } |
---|
| 197 | } |
---|
| 198 | return -1; |
---|
| 199 | } |
---|
| 200 | |
---|
[0] | 201 | int driver_close(DRIVER_USERDATA_T inst, int driver) { |
---|
[912] | 202 | int ret = 0; |
---|
[0] | 203 | ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver); |
---|
| 204 | |
---|
| 205 | if ( driver == -1 ) |
---|
| 206 | return -1; |
---|
| 207 | |
---|
| 208 | if ( g_driver[driver].close ) |
---|
[912] | 209 | ret = g_driver[driver].close(inst); |
---|
[0] | 210 | |
---|
[912] | 211 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 212 | free(inst); |
---|
| 213 | |
---|
| 214 | return ret; |
---|
[0] | 215 | } |
---|
| 216 | |
---|
[937] | 217 | int driver_closevio(struct roar_vio_calls * calls, int driver) { |
---|
| 218 | ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver); |
---|
| 219 | |
---|
| 220 | if ( driver == -1 ) |
---|
| 221 | return -1; |
---|
| 222 | |
---|
| 223 | if ( g_driver[driver].close ) |
---|
| 224 | return g_driver[driver].close((DRIVER_USERDATA_T)calls); |
---|
| 225 | |
---|
[1244] | 226 | if ( calls->close != NULL ) |
---|
| 227 | roar_vio_close(calls); |
---|
| 228 | |
---|
[937] | 229 | return 0; |
---|
| 230 | } |
---|
| 231 | |
---|
[0] | 232 | int driver_write(DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 233 | if ( driver == -1 ) |
---|
| 234 | return -1; |
---|
| 235 | |
---|
[911] | 236 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 237 | return roar_vio_write((struct roar_vio_calls *) inst, buf, len); |
---|
| 238 | |
---|
[0] | 239 | return 0; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | int driver_read (DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 243 | if ( driver == -1 ) |
---|
| 244 | return -1; |
---|
| 245 | |
---|
[911] | 246 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 247 | return roar_vio_read((struct roar_vio_calls *) inst, buf, len); |
---|
| 248 | |
---|
[0] | 249 | return 0; |
---|
| 250 | } |
---|
| 251 | |
---|
[1590] | 252 | int driver_set_volume(int stream, struct roar_mixer_settings * mixer) { |
---|
| 253 | struct roar_stream_server * ss; |
---|
| 254 | |
---|
| 255 | if ( (ss = g_streams[stream]) == NULL ) |
---|
| 256 | return -1; |
---|
| 257 | |
---|
| 258 | if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) ) |
---|
| 259 | return 0; |
---|
| 260 | |
---|
| 261 | if ( ss->driver_id == -1 ) |
---|
| 262 | return -1; |
---|
| 263 | |
---|
| 264 | return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer); |
---|
| 265 | } |
---|
| 266 | |
---|
[2345] | 267 | |
---|
[2507] | 268 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[2367] | 269 | int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[2345] | 270 | char * driver; |
---|
| 271 | char * delm; |
---|
| 272 | int ret; |
---|
| 273 | |
---|
| 274 | ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh); |
---|
| 275 | |
---|
| 276 | if (device == NULL) { |
---|
| 277 | driver = NULL; |
---|
| 278 | return -1; |
---|
| 279 | } else { |
---|
| 280 | driver = strdup(device); |
---|
| 281 | |
---|
| 282 | if ( (delm = strstr(driver, "#")) == NULL ) { |
---|
| 283 | device = NULL; |
---|
| 284 | } else { |
---|
| 285 | *delm = 0; |
---|
| 286 | device = strstr(device, "#") + 1; |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | 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); |
---|
| 291 | ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY); |
---|
| 292 | ROAR_DBG("driver_cdriver_open(*): RET %i", ret); |
---|
| 293 | |
---|
| 294 | if ( driver != NULL ) |
---|
| 295 | free(driver); |
---|
| 296 | |
---|
| 297 | return ret; |
---|
| 298 | } |
---|
[2507] | 299 | #endif |
---|
[2345] | 300 | |
---|
[0] | 301 | //ll |
---|