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