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