[668] | 1 | //driver.c: |
---|
[0] | 2 | |
---|
[668] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[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[] = { |
---|
[4812] | 29 | { "null", "null audio driver", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 30 | NULL, NULL, NULL}, |
---|
[0] | 31 | #ifdef ROAR_HAVE_ESD |
---|
[4812] | 32 | { "esd", "EsounD audio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3591] | 33 | NULL, NULL, driver_esd_open_vio}, |
---|
[0] | 34 | #endif |
---|
[4812] | 35 | { "roar", "RoarAudio driver", "localhost, remote.host.dom", STREAM_DIR_OUT, 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}, |
---|
[3601] | 38 | #ifndef ROAR_WITHOUT_VIO_DSTR |
---|
[4812] | 39 | { "dstr", "VIO DSTR driver", "/some/file", STREAM_DIR_OUT, DRV_FLAG_FHSEC, |
---|
[3262] | 40 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW|ROAR_SUBSYS_COMPLEX, |
---|
| 41 | NULL, NULL, driver_dstr_open_vio}, |
---|
[1478] | 42 | #endif |
---|
[919] | 43 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
[924] | 44 | #ifndef ROAR_DEFAULT_OSS_DEV |
---|
| 45 | #define ROAR_DEFAULT_OSS_DEV "no default device" |
---|
| 46 | #endif |
---|
[4815] | 47 | { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, STREAM_DIR_BIDIR, DRV_FLAG_FHSEC, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 48 | NULL, NULL, driver_oss_open}, |
---|
[919] | 49 | #endif |
---|
[0] | 50 | #ifdef ROAR_HAVE_LIBAO |
---|
[4812] | 51 | { "ao", "libao audio driver", "DRIVER", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3588] | 52 | NULL, NULL, driver_ao_open_vio}, |
---|
[0] | 53 | #endif |
---|
[951] | 54 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
[4812] | 55 | {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3589] | 56 | NULL, NULL, driver_shout_open_vio}, |
---|
[951] | 57 | #endif |
---|
[1543] | 58 | #ifdef ROAR_HAVE_LIBSNDIO |
---|
[4812] | 59 | {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI, |
---|
[2365] | 60 | NULL, NULL, driver_sndio_open}, |
---|
[1543] | 61 | #endif |
---|
[3725] | 62 | #ifdef ROAR_HAVE_LIBRSOUND |
---|
[4812] | 63 | {"rsound", "RSound", "servername", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3725] | 64 | NULL, NULL, driver_rsound_open}, |
---|
| 65 | #endif |
---|
[3751] | 66 | #ifdef _DRIVER_PORTAUDIO_CAN_OPERATE |
---|
[4812] | 67 | {"portaudio", "PortAudio", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3751] | 68 | NULL, NULL, driver_portaudio_open}, |
---|
| 69 | #endif |
---|
[3693] | 70 | #ifdef ROAR_HAVE_LIBASOUND |
---|
[4812] | 71 | {"alsa", "ALSA", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_alsa_open_vio}, |
---|
[3693] | 72 | #endif |
---|
[2779] | 73 | #ifdef ROAR_HAVE_LIBWINMM |
---|
[4812] | 74 | {"wmm", "Win32 MM", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, NULL, NULL, driver_wmm_open_vio}, |
---|
[2779] | 75 | #endif |
---|
[2503] | 76 | #ifndef ROAR_WITHOUT_DCOMP_DMX |
---|
[4812] | 77 | {"dmx", "DMX512 driver", "/dev/dmx", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 78 | NULL, NULL, driver_dmx_open_vio}, |
---|
[2503] | 79 | #endif |
---|
[3602] | 80 | #if !defined(ROAR_WITHOUT_DCOMP_PWMLED) && !defined(ROAR_WITHOUT_VIO_DSTR) |
---|
[4812] | 81 | {"pwmled", "PWM LED driver", "/dev/ttyS0", STREAM_DIR_OUT, DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[2365] | 82 | NULL, NULL, driver_pwmled_open_vio}, |
---|
[2502] | 83 | #endif |
---|
[2209] | 84 | #ifdef ROAR_HAVE_DRIVER_SYSCLOCK |
---|
[4812] | 85 | {"sysclock", "System Clock Clock Source", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 86 | NULL, NULL, driver_sysclock_open_vio}, |
---|
[2209] | 87 | #endif |
---|
[2507] | 88 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[4812] | 89 | {"cdriver", "RoarAudio Client driver", "driver#device", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[2365] | 90 | NULL, NULL, driver_cdriver_open}, |
---|
[2507] | 91 | #endif |
---|
[3839] | 92 | #ifdef ROAR_HAVE_LIBPULSE |
---|
[4812] | 93 | {"pulsesimple", "PulseAudio Simple", "server", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[3839] | 94 | NULL, NULL, driver_pulsesimple_open}, |
---|
| 95 | #endif |
---|
[4490] | 96 | #ifdef ROAR_HAVE_LIBJACK |
---|
[4572] | 97 | #if 0 |
---|
| 98 | // this is currently just a driver stub. |
---|
[4812] | 99 | {"jack", "JACK", "???", STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[4490] | 100 | NULL, NULL, driver_jack_open_vio}, |
---|
| 101 | #endif |
---|
[4572] | 102 | #endif |
---|
[4809] | 103 | #ifdef ROAR_HAVE_LIBARTSC |
---|
[4812] | 104 | {"artsc", "aRts plain C API", NULL, STREAM_DIR_OUT, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[4809] | 105 | NULL, NULL, driver_artsc_open_vio}, |
---|
| 106 | #endif |
---|
[4812] | 107 | {NULL, NULL, NULL, STREAM_DIR_NONE, DRV_FLAG_NONE, 0, NULL, NULL, NULL} // end of list |
---|
[0] | 108 | }; |
---|
| 109 | |
---|
[4955] | 110 | void print_driverlist (enum output_format format) { |
---|
[0] | 111 | int i; |
---|
[1918] | 112 | char subsys[7] = " "; |
---|
[4812] | 113 | char mode[5] = " "; |
---|
[0] | 114 | |
---|
[4955] | 115 | switch (format) { |
---|
| 116 | case FORMAT_NATIVE: |
---|
| 117 | printf(" Driver Mode Flag Subsys - Description (devices)\n"); |
---|
| 118 | printf("---------------------------------------------------------------\n"); |
---|
| 119 | break; |
---|
| 120 | case FORMAT_WIKI: |
---|
[5274] | 121 | printf("||=Driver =||=Mode =||=Flag =||=Subsys =||=Description =||=Devices =||\n"); |
---|
[4955] | 122 | break; |
---|
| 123 | case FORMAT_CSV: |
---|
| 124 | printf("Driver,Mode,Flag,Subsys,Description,Devices\n"); |
---|
| 125 | break; |
---|
| 126 | default: |
---|
| 127 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
| 128 | return; |
---|
| 129 | } |
---|
[975] | 130 | |
---|
[0] | 131 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
[1918] | 132 | strncpy(subsys, " ", 6); |
---|
[4812] | 133 | strncpy(mode, " ", 4); |
---|
| 134 | |
---|
| 135 | if ( g_driver[i].mode & STREAM_DIR_IN ) |
---|
| 136 | mode[0] = 'r'; |
---|
| 137 | if ( g_driver[i].mode & STREAM_DIR_OUT ) |
---|
| 138 | mode[1] = 'w'; |
---|
[1918] | 139 | |
---|
| 140 | if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 141 | subsys[0] = 'W'; |
---|
| 142 | if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 143 | subsys[1] = 'M'; |
---|
| 144 | if ( g_driver[i].subsystems & ROAR_SUBSYS_CB ) |
---|
| 145 | subsys[2] = 'C'; |
---|
| 146 | if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 147 | subsys[3] = 'L'; |
---|
[2233] | 148 | if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
| 149 | subsys[4] = 'R'; |
---|
[2681] | 150 | if ( g_driver[i].subsystems & ROAR_SUBSYS_COMPLEX ) |
---|
| 151 | subsys[5] = 'X'; |
---|
[1918] | 152 | |
---|
[4955] | 153 | switch (format) { |
---|
| 154 | case FORMAT_NATIVE: |
---|
| 155 | if ( g_driver[i].devices != NULL ) { |
---|
| 156 | printf(" %-12s %4s %c%c%c%c %6s - %s (devices: %s)\n", g_driver[i].name, |
---|
| 157 | mode, |
---|
| 158 | ' ', /* unused Flag */ |
---|
| 159 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
| 160 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
| 161 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
| 162 | subsys, |
---|
| 163 | g_driver[i].desc, g_driver[i].devices); |
---|
| 164 | } else { |
---|
| 165 | printf(" %-12s %4s %c%c%c%c %6s - %s\n", g_driver[i].name, |
---|
| 166 | mode, |
---|
| 167 | ' ', /* unused Flag */ |
---|
| 168 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
| 169 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
| 170 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
| 171 | subsys, |
---|
| 172 | g_driver[i].desc); |
---|
| 173 | } |
---|
| 174 | break; |
---|
| 175 | case FORMAT_WIKI: |
---|
| 176 | printf("||=%-12s =|| %s || %s%s%s ||%s ||%s ||%s ||\n", g_driver[i].name, mode[0] == ' ' ? mode+1 : mode, |
---|
| 177 | g_driver[i].flags & DRV_FLAG_FHSEC ? "s" : " ", |
---|
| 178 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ", |
---|
| 179 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ", |
---|
| 180 | subsys, |
---|
| 181 | g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices); |
---|
| 182 | break; |
---|
| 183 | case FORMAT_CSV: |
---|
| 184 | printf("%s,%s,%s%s%s,%s,%s,%s\n", g_driver[i].name, mode, |
---|
| 185 | g_driver[i].flags & DRV_FLAG_FHSEC ? "s" : " ", |
---|
| 186 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "S" : " ", |
---|
| 187 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? "V" : " ", |
---|
| 188 | subsys, |
---|
| 189 | g_driver[i].desc, g_driver[i].devices == NULL ? "" : g_driver[i].devices); |
---|
| 190 | break; |
---|
[4812] | 191 | } |
---|
[0] | 192 | } |
---|
| 193 | } |
---|
| 194 | |
---|
[931] | 195 | int driver_openvio(struct roar_vio_calls * calls, |
---|
| 196 | int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */, |
---|
[2364] | 197 | char * device, struct roar_audio_info * info, int fh, |
---|
| 198 | struct roar_stream_server * sstream) { |
---|
[931] | 199 | int i; |
---|
| 200 | |
---|
[4148] | 201 | #ifdef ROAR_DRIVER_DEFAULT |
---|
[931] | 202 | if ( driver == NULL ) |
---|
| 203 | driver = ROAR_DRIVER_DEFAULT; |
---|
[4148] | 204 | #else |
---|
| 205 | if ( driver == NULL ) |
---|
| 206 | return -1; |
---|
| 207 | #endif |
---|
[931] | 208 | |
---|
[1243] | 209 | ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver); |
---|
| 210 | |
---|
[931] | 211 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 212 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
[4811] | 213 | ROAR_DBG("driver_openvio(*): found driver: id = %i", i); |
---|
[931] | 214 | |
---|
| 215 | *driver_id = i; |
---|
| 216 | |
---|
[1243] | 217 | ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i); |
---|
| 218 | |
---|
[931] | 219 | if ( g_driver[i].vio_init == NULL ) { |
---|
[944] | 220 | if ( g_driver[i].open == NULL ) { // this is the null driver |
---|
| 221 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 222 | calls->read = roar_vio_null_rw; |
---|
| 223 | calls->write = roar_vio_null_rw; |
---|
| 224 | return 0; |
---|
| 225 | } |
---|
| 226 | |
---|
[4811] | 227 | ROAR_WARN("driver_openvio(*): driver(%s) uses old non-vio interface!", driver); |
---|
[931] | 228 | ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!", |
---|
| 229 | calls, i, driver, device, info, fh); |
---|
| 230 | return -1; |
---|
| 231 | } |
---|
| 232 | |
---|
[4815] | 233 | // if this driver does not support input we need to check if it is used in input mode. |
---|
| 234 | if ( !(g_driver[i].mode & STREAM_DIR_IN) ) { |
---|
| 235 | if ( sstream == NULL ) |
---|
| 236 | return -1; |
---|
| 237 | |
---|
| 238 | if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) ) { |
---|
| 239 | if ( streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF) == 1 ) { |
---|
| 240 | if ( streams_reset_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE) == -1 ) |
---|
| 241 | return -1; |
---|
| 242 | } else { |
---|
| 243 | ROAR_WARN("driver_openvio(*): driver(%s) is not abled to record data and autoconf flag is not set.", driver); |
---|
| 244 | return -1; |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
[1243] | 249 | ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i); |
---|
[2367] | 250 | return g_driver[i].vio_init(calls, device, info, fh, sstream); |
---|
[931] | 251 | } |
---|
| 252 | } |
---|
| 253 | return -1; |
---|
| 254 | } |
---|
| 255 | |
---|
[937] | 256 | int driver_closevio(struct roar_vio_calls * calls, int driver) { |
---|
| 257 | ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver); |
---|
| 258 | |
---|
| 259 | if ( driver == -1 ) |
---|
| 260 | return -1; |
---|
| 261 | |
---|
| 262 | if ( g_driver[driver].close ) |
---|
| 263 | return g_driver[driver].close((DRIVER_USERDATA_T)calls); |
---|
| 264 | |
---|
[1244] | 265 | if ( calls->close != NULL ) |
---|
| 266 | roar_vio_close(calls); |
---|
| 267 | |
---|
[937] | 268 | return 0; |
---|
| 269 | } |
---|
| 270 | |
---|
[1590] | 271 | int driver_set_volume(int stream, struct roar_mixer_settings * mixer) { |
---|
| 272 | struct roar_stream_server * ss; |
---|
| 273 | |
---|
| 274 | if ( (ss = g_streams[stream]) == NULL ) |
---|
| 275 | return -1; |
---|
| 276 | |
---|
| 277 | if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) ) |
---|
| 278 | return 0; |
---|
| 279 | |
---|
| 280 | if ( ss->driver_id == -1 ) |
---|
| 281 | return -1; |
---|
| 282 | |
---|
| 283 | return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer); |
---|
| 284 | } |
---|
| 285 | |
---|
[2345] | 286 | |
---|
[2507] | 287 | #ifndef ROAR_WITHOUT_DCOMP_CDRIVER |
---|
[2367] | 288 | int driver_cdriver_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[2345] | 289 | char * driver; |
---|
| 290 | char * delm; |
---|
| 291 | int ret; |
---|
| 292 | |
---|
| 293 | ROAR_DBG("driver_cdriver_open(inst=%p, device='%s', info=%p, fh=%i) = ?", inst, device, info, fh); |
---|
| 294 | |
---|
| 295 | if (device == NULL) { |
---|
| 296 | driver = NULL; |
---|
| 297 | } else { |
---|
[4975] | 298 | driver = roar_mm_strdup(device); |
---|
[2345] | 299 | |
---|
| 300 | if ( (delm = strstr(driver, "#")) == NULL ) { |
---|
| 301 | device = NULL; |
---|
| 302 | } else { |
---|
| 303 | *delm = 0; |
---|
| 304 | device = strstr(device, "#") + 1; |
---|
| 305 | } |
---|
| 306 | } |
---|
| 307 | |
---|
| 308 | 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); |
---|
| 309 | ret = roar_cdriver_open(inst, driver, device, info, ROAR_DIR_PLAY); |
---|
| 310 | ROAR_DBG("driver_cdriver_open(*): RET %i", ret); |
---|
| 311 | |
---|
| 312 | if ( driver != NULL ) |
---|
[4975] | 313 | roar_mm_free(driver); |
---|
[2345] | 314 | |
---|
| 315 | return ret; |
---|
| 316 | } |
---|
[2507] | 317 | #endif |
---|
[2345] | 318 | |
---|
[5278] | 319 | int driver_dummy_ctl(struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) { |
---|
[5276] | 320 | switch (cmd) { |
---|
| 321 | case ROAR_VIO_CTL_NONBLOCK: |
---|
| 322 | if ( *(const int*)data == ROAR_SOCKET_BLOCK ) |
---|
| 323 | return 0; |
---|
[5012] | 324 | |
---|
[5276] | 325 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
| 326 | return -1; |
---|
| 327 | break; |
---|
| 328 | default: |
---|
| 329 | roar_err_set(ROAR_ERROR_BADRQC); |
---|
| 330 | return -1; |
---|
| 331 | break; |
---|
| 332 | } |
---|
[5012] | 333 | } |
---|
| 334 | |
---|
[0] | 335 | //ll |
---|