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