[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 | |
---|
| 27 | struct roar_driver g_driver[] = { |
---|
[1918] | 28 | { "null", "null audio driver", "/dev/null", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
| 29 | NULL, NULL, NULL, NULL, NULL, NULL, NULL}, |
---|
[0] | 30 | #ifdef ROAR_HAVE_ESD |
---|
[1918] | 31 | { "esd", "EsounD audio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 32 | NULL, driver_esd_close, driver_esd_pause, NULL, NULL, driver_esd_flush, driver_esd_open_vio}, |
---|
[0] | 33 | #endif |
---|
[1918] | 34 | { "roar", "RoarAudio driver", "localhost, remote.host.dom", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 35 | NULL, driver_roar_close, NULL, NULL, NULL, driver_roar_flush, driver_roar_open_vio}, |
---|
[1478] | 36 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[2233] | 37 | { "raw", "RAW PCM driver", "/some/file", DRV_FLAG_FHSEC, |
---|
| 38 | ROAR_SUBSYS_WAVEFORM|ROAR_SUBSYS_MIDI|ROAR_SUBSYS_LIGHT|ROAR_SUBSYS_RAW, |
---|
[1915] | 39 | NULL, NULL, NULL, NULL, NULL, driver_raw_flush, driver_raw_open_vio}, |
---|
[1478] | 40 | #endif |
---|
[919] | 41 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
[924] | 42 | #ifndef ROAR_DEFAULT_OSS_DEV |
---|
| 43 | #define ROAR_DEFAULT_OSS_DEV "no default device" |
---|
| 44 | #endif |
---|
[1918] | 45 | { "oss", "Open Sound System", ROAR_DEFAULT_OSS_DEV, DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 46 | NULL, NULL, NULL, NULL, NULL, NULL, driver_oss_open}, |
---|
[919] | 47 | #endif |
---|
[0] | 48 | #ifdef ROAR_HAVE_LIBAO |
---|
[1918] | 49 | { "ao", "libao audio driver", "DRIVER", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 50 | NULL, driver_ao_close, NULL, NULL, NULL, NULL, driver_ao_open_vio}, |
---|
[0] | 51 | #endif |
---|
[951] | 52 | #ifdef ROAR_HAVE_LIBSHOUT |
---|
[1918] | 53 | {"shout", "libshout streaming", "http://user:pw@host:port/mount.ogg", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 54 | NULL, driver_shout_close, NULL, NULL, NULL, NULL, driver_shout_open_vio}, |
---|
[951] | 55 | #endif |
---|
[1543] | 56 | #ifdef ROAR_HAVE_LIBSNDIO |
---|
[1918] | 57 | {"sndio", "OpenBSD sndio", "/dev/audio, /tmp/aucat-<uid>/default", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
[1915] | 58 | NULL, NULL, NULL, NULL, NULL, NULL, driver_sndio_open}, |
---|
[1543] | 59 | #endif |
---|
[1918] | 60 | {"dmx", "DMX512 driver", "/dev/dmx", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
[1915] | 61 | NULL, NULL, NULL, NULL, NULL, NULL, driver_dmx_open_vio}, |
---|
[1974] | 62 | {"pwmled", "PWM LED driver", "/dev/ttyS0", DRV_FLAG_FHSEC, ROAR_SUBSYS_LIGHT, |
---|
| 63 | NULL, NULL, NULL, NULL, NULL, NULL, driver_pwmled_open_vio}, |
---|
[2209] | 64 | #ifdef ROAR_HAVE_DRIVER_SYSCLOCK |
---|
[2207] | 65 | {"sysclock", "System Clock Clock Source", "(none)", DRV_FLAG_NONE, ROAR_SUBSYS_WAVEFORM, |
---|
| 66 | NULL, NULL, NULL, NULL, NULL, NULL, driver_sysclock_open_vio}, |
---|
[2209] | 67 | #endif |
---|
[1951] | 68 | {NULL, NULL, NULL, DRV_FLAG_NONE, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL} // end of list |
---|
[0] | 69 | }; |
---|
| 70 | |
---|
| 71 | void print_driverlist (void) { |
---|
| 72 | int i; |
---|
[1918] | 73 | char subsys[7] = " "; |
---|
[0] | 74 | |
---|
[2207] | 75 | printf(" Driver Flag Subsys - Description (devices)\n"); |
---|
[975] | 76 | printf("------------------------------------------------------\n"); |
---|
| 77 | |
---|
[0] | 78 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
[1918] | 79 | strncpy(subsys, " ", 6); |
---|
| 80 | |
---|
| 81 | if ( g_driver[i].subsystems & ROAR_SUBSYS_WAVEFORM ) |
---|
| 82 | subsys[0] = 'W'; |
---|
| 83 | if ( g_driver[i].subsystems & ROAR_SUBSYS_MIDI ) |
---|
| 84 | subsys[1] = 'M'; |
---|
| 85 | if ( g_driver[i].subsystems & ROAR_SUBSYS_CB ) |
---|
| 86 | subsys[2] = 'C'; |
---|
| 87 | if ( g_driver[i].subsystems & ROAR_SUBSYS_LIGHT ) |
---|
| 88 | subsys[3] = 'L'; |
---|
[2233] | 89 | if ( g_driver[i].subsystems & ROAR_SUBSYS_RAW ) |
---|
| 90 | subsys[4] = 'R'; |
---|
[1918] | 91 | |
---|
[2207] | 92 | printf(" %-9s %c%c%c %6s - %s (devices: %s)\n", g_driver[i].name, |
---|
[1915] | 93 | g_driver[i].flags & DRV_FLAG_FHSEC ? 's' : ' ', |
---|
[947] | 94 | g_driver[i].open != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'S' : ' ', |
---|
| 95 | g_driver[i].vio_init != NULL || (g_driver[i].open == NULL && g_driver[i].vio_init == NULL) ? 'V' : ' ', |
---|
[1918] | 96 | subsys, |
---|
[947] | 97 | g_driver[i].desc, g_driver[i].devices); |
---|
[0] | 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | int driver_open (DRIVER_USERDATA_T * inst, int * driver_id, char * driver, char * device, struct roar_audio_info * info) { |
---|
| 102 | int i; |
---|
| 103 | |
---|
| 104 | if ( driver == NULL ) |
---|
| 105 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 106 | |
---|
| 107 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 108 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 109 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 110 | |
---|
| 111 | *driver_id = i; |
---|
| 112 | |
---|
[911] | 113 | if ( g_driver[i].vio_init != NULL ) { |
---|
| 114 | if ( (*inst = malloc(sizeof(struct roar_vio_calls))) == NULL ) |
---|
| 115 | return -1; |
---|
| 116 | |
---|
[912] | 117 | memset(*inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 118 | |
---|
[930] | 119 | if ( (i = g_driver[i].vio_init(*inst, device, info, -1)) == -1 ) { |
---|
[911] | 120 | free(*inst); |
---|
| 121 | return -1; |
---|
| 122 | } |
---|
| 123 | return i; |
---|
| 124 | } |
---|
| 125 | |
---|
[944] | 126 | if ( g_driver[i].open ) { |
---|
| 127 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 128 | return g_driver[i].open(inst, device, info); |
---|
| 129 | } |
---|
[912] | 130 | |
---|
[0] | 131 | return 0; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return -1; |
---|
| 136 | } |
---|
| 137 | |
---|
[931] | 138 | int driver_openvio(struct roar_vio_calls * calls, |
---|
| 139 | int * driver_id, char * driver /* NOTE: this is not part of struct roar_driver's def! */, |
---|
| 140 | char * device, struct roar_audio_info * info, int fh) { |
---|
| 141 | int i; |
---|
| 142 | |
---|
| 143 | if ( driver == NULL ) |
---|
| 144 | driver = ROAR_DRIVER_DEFAULT; |
---|
| 145 | |
---|
[1243] | 146 | ROAR_DBG("driver_openvio(*): searching for driver '%s'...", driver); |
---|
| 147 | |
---|
[931] | 148 | for (i = 0; g_driver[i].name != NULL; i++) { |
---|
| 149 | if ( strcmp(g_driver[i].name, driver) == 0 ) { |
---|
| 150 | ROAR_DBG("driver_open(*): found driver: id = %i", i); |
---|
| 151 | |
---|
| 152 | *driver_id = i; |
---|
| 153 | |
---|
[1243] | 154 | ROAR_DBG("driver_openvio(*): driver found: %s -> %i", driver, i); |
---|
| 155 | |
---|
[931] | 156 | if ( g_driver[i].vio_init == NULL ) { |
---|
[944] | 157 | if ( g_driver[i].open == NULL ) { // this is the null driver |
---|
| 158 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 159 | calls->read = roar_vio_null_rw; |
---|
| 160 | calls->write = roar_vio_null_rw; |
---|
| 161 | return 0; |
---|
| 162 | } |
---|
| 163 | |
---|
[931] | 164 | ROAR_WARN("driver_open(*): driver(%s) uses old non-vio interface!", driver); |
---|
| 165 | ROAR_ERR("driver_openvio(calls=%p, driver_id={%i}, driver='%s', device='%s', info=%p, fh=%i): not a VIO driver!", |
---|
| 166 | calls, i, driver, device, info, fh); |
---|
| 167 | return -1; |
---|
| 168 | } |
---|
| 169 | |
---|
[1243] | 170 | ROAR_DBG("driver_openvio(*): Opening VIO driver %s(%i)...", driver, i); |
---|
[931] | 171 | return g_driver[i].vio_init(calls, device, info, fh); |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | return -1; |
---|
| 175 | } |
---|
| 176 | |
---|
[0] | 177 | int driver_close(DRIVER_USERDATA_T inst, int driver) { |
---|
[912] | 178 | int ret = 0; |
---|
[0] | 179 | ROAR_DBG("driver_close(inst=%p, driver=%i) = ?", inst, driver); |
---|
| 180 | |
---|
| 181 | if ( driver == -1 ) |
---|
| 182 | return -1; |
---|
| 183 | |
---|
| 184 | if ( g_driver[driver].close ) |
---|
[912] | 185 | ret = g_driver[driver].close(inst); |
---|
[0] | 186 | |
---|
[912] | 187 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 188 | free(inst); |
---|
| 189 | |
---|
| 190 | return ret; |
---|
[0] | 191 | } |
---|
| 192 | |
---|
[937] | 193 | int driver_closevio(struct roar_vio_calls * calls, int driver) { |
---|
| 194 | ROAR_DBG("driver_closevio(calls=%p, driver=%i) = ?", calls, driver); |
---|
| 195 | |
---|
| 196 | if ( driver == -1 ) |
---|
| 197 | return -1; |
---|
| 198 | |
---|
| 199 | if ( g_driver[driver].close ) |
---|
| 200 | return g_driver[driver].close((DRIVER_USERDATA_T)calls); |
---|
| 201 | |
---|
[1244] | 202 | if ( calls->close != NULL ) |
---|
| 203 | roar_vio_close(calls); |
---|
| 204 | |
---|
[937] | 205 | return 0; |
---|
| 206 | } |
---|
| 207 | |
---|
[0] | 208 | int driver_pause(DRIVER_USERDATA_T inst, int driver, int newstate) { |
---|
| 209 | if ( driver == -1 ) |
---|
| 210 | return -1; |
---|
| 211 | |
---|
| 212 | if ( g_driver[driver].pause ) |
---|
| 213 | return g_driver[driver].pause(inst, newstate); |
---|
| 214 | |
---|
[1228] | 215 | return -1; |
---|
[0] | 216 | } |
---|
| 217 | |
---|
| 218 | int driver_write(DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 219 | if ( driver == -1 ) |
---|
| 220 | return -1; |
---|
| 221 | |
---|
[911] | 222 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 223 | return roar_vio_write((struct roar_vio_calls *) inst, buf, len); |
---|
| 224 | |
---|
[0] | 225 | if ( g_driver[driver].write ) |
---|
| 226 | return g_driver[driver].write(inst, buf, len); |
---|
| 227 | |
---|
| 228 | return 0; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | int driver_read (DRIVER_USERDATA_T inst, int driver, char * buf, int len) { |
---|
| 232 | if ( driver == -1 ) |
---|
| 233 | return -1; |
---|
| 234 | |
---|
[911] | 235 | if ( g_driver[driver].vio_init != NULL ) |
---|
| 236 | return roar_vio_read((struct roar_vio_calls *) inst, buf, len); |
---|
| 237 | |
---|
[0] | 238 | if ( g_driver[driver].read ) |
---|
| 239 | return g_driver[driver].read(inst, buf, len); |
---|
| 240 | |
---|
| 241 | return 0; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | int driver_flush(DRIVER_USERDATA_T inst, int driver) { |
---|
| 245 | if ( driver == -1 ) |
---|
| 246 | return -1; |
---|
| 247 | |
---|
| 248 | if ( g_driver[driver].flush ) |
---|
| 249 | return g_driver[driver].flush(inst); |
---|
| 250 | |
---|
| 251 | return 0; |
---|
| 252 | } |
---|
| 253 | |
---|
[1590] | 254 | int driver_set_volume(int stream, struct roar_mixer_settings * mixer) { |
---|
| 255 | struct roar_stream_server * ss; |
---|
| 256 | |
---|
| 257 | if ( (ss = g_streams[stream]) == NULL ) |
---|
| 258 | return -1; |
---|
| 259 | |
---|
| 260 | if ( !streams_get_flag(stream, ROAR_FLAG_HWMIXER) ) |
---|
| 261 | return 0; |
---|
| 262 | |
---|
| 263 | if ( ss->driver_id == -1 ) |
---|
| 264 | return -1; |
---|
| 265 | |
---|
| 266 | return roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_SET_VOLUME, (void*)mixer); |
---|
| 267 | } |
---|
| 268 | |
---|
[0] | 269 | //ll |
---|