[2519] | 1 | //emul_esd.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5961] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 |
---|
[2519] | 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. |
---|
[2519] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[5740] | 26 | #include <roard/include/roard.h> |
---|
[2519] | 27 | |
---|
| 28 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD |
---|
[2791] | 29 | #ifdef ROAR_HAVE_H_ESD |
---|
[5739] | 30 | #include <esd.h> |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | struct emul_esd_command { |
---|
| 34 | int cmd; |
---|
| 35 | size_t datalen; |
---|
| 36 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL) |
---|
| 37 | char name[COMMAND_MAX_NAMELEN]; |
---|
| 38 | #else |
---|
| 39 | char * name; |
---|
| 40 | #endif |
---|
| 41 | int (*handler)(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | static int emul_esd_exec_command (int client, int cmd, struct roar_vio_calls * vio); |
---|
| 45 | static int emul_esd_check_client (int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
| 46 | |
---|
| 47 | static int emul_esd_int_read_buf (int client, int * data, void * buf); |
---|
| 48 | static int emul_esd_int_write (int client, int data, struct roar_vio_calls * vio); |
---|
| 49 | static int emul_esd_test_auth (int client, void * data, struct roar_vio_calls * vio); |
---|
| 50 | static int emul_esd_test_byteorder(int client, void * data); |
---|
| 51 | |
---|
| 52 | static int emul_esd_on_connect (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 53 | static int emul_esd_on_stream (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 54 | static int emul_esd_on_latency (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 55 | static int emul_esd_on_standby (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 56 | static int emul_esd_on_standbymode(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 57 | |
---|
| 58 | static int emul_esd_on_stream_pan (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 59 | |
---|
| 60 | static int emul_esd_on_server_info(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 61 | |
---|
| 62 | static int emul_esd_on_all_info (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio); |
---|
| 63 | |
---|
| 64 | |
---|
[2519] | 65 | |
---|
[2521] | 66 | #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL) |
---|
| 67 | #define _NAME(x) (x) |
---|
| 68 | #else |
---|
| 69 | #define _NAME(x) ((char*)NULL) |
---|
| 70 | #endif |
---|
| 71 | |
---|
[2522] | 72 | #define _cmd_t int |
---|
| 73 | #define _INTSIZE sizeof(_cmd_t) |
---|
| 74 | |
---|
[2537] | 75 | #define _NOT_TO_IMPLEMENT NULL |
---|
| 76 | #define _UNIMPLEMNTED_IN_ESD NULL |
---|
| 77 | #define _NEED_SAMPLE_SUPPORT NULL |
---|
| 78 | |
---|
[2538] | 79 | #define _ROAR2ESD(x) ((x)+1) |
---|
| 80 | #define _ESD2ROAR(x) ((x)-1) |
---|
| 81 | |
---|
[5739] | 82 | static struct emul_esd_command g_emul_esd_commands[] = { |
---|
[2525] | 83 | {ESD_PROTO_CONNECT, ESD_KEY_LEN + _INTSIZE, _NAME("CONNECT"), emul_esd_on_connect}, |
---|
[2522] | 84 | {ESD_PROTO_LOCK, ESD_KEY_LEN + _INTSIZE, _NAME("LOCK"), NULL}, |
---|
| 85 | {ESD_PROTO_UNLOCK, ESD_KEY_LEN + _INTSIZE, _NAME("UNLOCK"), NULL}, |
---|
[2527] | 86 | {ESD_PROTO_STREAM_PLAY, ESD_NAME_MAX + 2 * _INTSIZE, _NAME("STREAM_PLAY"), emul_esd_on_stream}, |
---|
| 87 | {ESD_PROTO_STREAM_REC, ESD_NAME_MAX + 2 * _INTSIZE, _NAME("STREAM_REC"), emul_esd_on_stream}, |
---|
| 88 | {ESD_PROTO_STREAM_MON, ESD_NAME_MAX + 2 * _INTSIZE, _NAME("STREAM_MON"), emul_esd_on_stream}, |
---|
[2537] | 89 | {ESD_PROTO_SAMPLE_CACHE, ESD_NAME_MAX + 3 * _INTSIZE, _NAME("SAMPLE_CACHE"), _NEED_SAMPLE_SUPPORT}, |
---|
| 90 | {ESD_PROTO_SAMPLE_FREE, _INTSIZE, _NAME("SAMPLE_FREE"), _NEED_SAMPLE_SUPPORT}, |
---|
| 91 | {ESD_PROTO_SAMPLE_PLAY, _INTSIZE, _NAME("SAMPLE_PLAY"), _NEED_SAMPLE_SUPPORT}, |
---|
| 92 | {ESD_PROTO_SAMPLE_LOOP, _INTSIZE, _NAME("SAMPLE_LOOP"), _NEED_SAMPLE_SUPPORT}, |
---|
| 93 | {ESD_PROTO_SAMPLE_STOP, _INTSIZE, _NAME("SAMPLE_STOP"), _NEED_SAMPLE_SUPPORT}, |
---|
| 94 | {ESD_PROTO_SAMPLE_KILL, 0 , _NAME("SAMPLE_KILL"), _NEED_SAMPLE_SUPPORT}, |
---|
[2535] | 95 | {ESD_PROTO_STANDBY, ESD_KEY_LEN + _INTSIZE, _NAME("STANDBY"), emul_esd_on_standby}, |
---|
| 96 | {ESD_PROTO_RESUME, ESD_KEY_LEN + _INTSIZE, _NAME("RESUME"), emul_esd_on_standby}, |
---|
[2537] | 97 | {ESD_PROTO_SAMPLE_GETID, ESD_NAME_MAX , _NAME("SAMPLE_GETID"), _NEED_SAMPLE_SUPPORT}, |
---|
[2527] | 98 | {ESD_PROTO_STREAM_FILT, ESD_NAME_MAX + 2 * _INTSIZE, _NAME("STREAM_FILT"), emul_esd_on_stream}, |
---|
[2539] | 99 | {ESD_PROTO_SERVER_INFO, _INTSIZE, _NAME("SERVER_INFO"), emul_esd_on_server_info}, |
---|
[2541] | 100 | {ESD_PROTO_ALL_INFO, _INTSIZE, _NAME("ALL_INFO"), emul_esd_on_all_info}, |
---|
[2537] | 101 | {ESD_PROTO_SUBSCRIBE, 0 , _NAME("SUBSCRIBE"), _UNIMPLEMNTED_IN_ESD}, |
---|
| 102 | {ESD_PROTO_UNSUBSCRIBE, 0 , _NAME("UNSUBSCRIBE"), _UNIMPLEMNTED_IN_ESD}, |
---|
[2538] | 103 | {ESD_PROTO_STREAM_PAN, 3 * _INTSIZE, _NAME("STREAM_PAN"), emul_esd_on_stream_pan}, |
---|
[2537] | 104 | {ESD_PROTO_SAMPLE_PAN, 3 * _INTSIZE, _NAME("SAMPLE_PAN"), _NEED_SAMPLE_SUPPORT}, |
---|
[2536] | 105 | {ESD_PROTO_STANDBY_MODE, _INTSIZE, _NAME("STANDBY_MODE"), emul_esd_on_standbymode}, |
---|
[2533] | 106 | {ESD_PROTO_LATENCY, 0 , _NAME("LATENCY"), emul_esd_on_latency}, |
---|
[2537] | 107 | {ESD_PROTO_MAX, 0 , _NAME("MAX"), _NOT_TO_IMPLEMENT}, |
---|
| 108 | {-1, 0, _NAME("END OF LIST"), _NOT_TO_IMPLEMENT} |
---|
[2521] | 109 | }; |
---|
| 110 | |
---|
[2524] | 111 | // command handling: |
---|
[5739] | 112 | static int emul_esd_exec_command(int client, int cmd, struct roar_vio_calls * vio) { |
---|
[2522] | 113 | struct emul_esd_command * cur; |
---|
| 114 | void * data = NULL; |
---|
[2534] | 115 | ssize_t ret; |
---|
| 116 | size_t done = 0; |
---|
[2522] | 117 | int r; |
---|
| 118 | int i; |
---|
| 119 | |
---|
[2530] | 120 | ROAR_DBG("emul_esd_exec_command(*) = ?"); |
---|
| 121 | |
---|
[2522] | 122 | if ( client == -1 || cmd < ESD_PROTO_CONNECT || cmd > ESD_PROTO_MAX || vio == NULL ) |
---|
| 123 | return -1; |
---|
| 124 | |
---|
[2530] | 125 | ROAR_DBG("emul_esd_exec_command(*) = ?"); |
---|
| 126 | |
---|
[2522] | 127 | for (i = 0; (cur = &(g_emul_esd_commands[i]))->cmd != -1; i++) { |
---|
| 128 | if ( cur->cmd == cmd ) { |
---|
| 129 | if ( cur->datalen > 0 ) { |
---|
[4957] | 130 | if ( (data = roar_mm_malloc(cur->datalen)) == NULL ) { |
---|
[2522] | 131 | // we will do a protocol error in case we do not drop the client |
---|
| 132 | return -1; |
---|
| 133 | } |
---|
| 134 | |
---|
[2534] | 135 | while ( done < cur->datalen ) { |
---|
| 136 | ret = roar_vio_read(vio, data+done, cur->datalen-done); |
---|
| 137 | |
---|
| 138 | if ( ret < 1 ) { |
---|
[4957] | 139 | roar_mm_free(data); |
---|
[2534] | 140 | return -1; |
---|
| 141 | } else { |
---|
| 142 | done += ret; |
---|
| 143 | } |
---|
[2522] | 144 | } |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if ( cur->handler == NULL ) { |
---|
| 148 | ROAR_WARN("emul_esd_exec_command(client=%i, cmd=%s(%i), vio=%p): client uses unimplemted command", |
---|
| 149 | client, cur->name, cmd, vio |
---|
| 150 | ); |
---|
| 151 | r = -1; |
---|
| 152 | } else { |
---|
| 153 | r = cur->handler(client, cur, data, vio); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | if ( data != NULL ) |
---|
[4957] | 157 | roar_mm_free(data); |
---|
[2522] | 158 | |
---|
| 159 | return r; |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | return -1; |
---|
| 164 | } |
---|
| 165 | |
---|
[5739] | 166 | static int emul_esd_set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) { |
---|
[5740] | 167 | |
---|
| 168 | (void)obuffer, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara; |
---|
| 169 | |
---|
[5739] | 170 | if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, vio) == -1 ) |
---|
| 171 | return -1; |
---|
| 172 | |
---|
| 173 | return 0; |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | static int emul_esd_check_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) { |
---|
[2522] | 177 | _cmd_t cmd; |
---|
| 178 | |
---|
[5740] | 179 | (void)obuffer, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara; |
---|
| 180 | |
---|
[2522] | 181 | if ( client == -1 ) |
---|
| 182 | return -1; |
---|
| 183 | |
---|
| 184 | if ( roar_vio_read(vio, &cmd, _INTSIZE) != _INTSIZE ) { |
---|
| 185 | // really bad protocol error |
---|
| 186 | return -1; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | return emul_esd_exec_command(client, cmd, vio); |
---|
| 190 | } |
---|
| 191 | |
---|
[2524] | 192 | // porto lib: |
---|
[2528] | 193 | int emul_esd_int_read_buf (int client, int * data, void * buf) { |
---|
| 194 | _cmd_t d; |
---|
| 195 | |
---|
[5740] | 196 | (void)client; |
---|
| 197 | |
---|
[2528] | 198 | if ( data == NULL || buf == NULL ) |
---|
| 199 | return -1; |
---|
| 200 | |
---|
| 201 | d = *(_cmd_t*)buf; |
---|
| 202 | |
---|
| 203 | *data = d; |
---|
| 204 | |
---|
| 205 | return 0; |
---|
| 206 | } |
---|
[2524] | 207 | |
---|
[5739] | 208 | static int emul_esd_int_write (int client, int data, struct roar_vio_calls * vio) { |
---|
[2524] | 209 | _cmd_t d = data; |
---|
| 210 | |
---|
[5740] | 211 | (void)client; |
---|
| 212 | |
---|
[2524] | 213 | return roar_vio_write(vio, &d, _INTSIZE) == _INTSIZE ? 0 : -1; |
---|
| 214 | } |
---|
| 215 | |
---|
[5739] | 216 | static int emul_esd_test_auth (int client, void * data, struct roar_vio_calls * vio) { |
---|
[2524] | 217 | // accept all clients for the moment. |
---|
[5740] | 218 | |
---|
| 219 | (void)data; |
---|
| 220 | |
---|
[2524] | 221 | return emul_esd_int_write(client, 1, vio); |
---|
| 222 | } |
---|
| 223 | |
---|
[5739] | 224 | static int emul_esd_test_byteorder(int client, void * data) { |
---|
[2828] | 225 | struct roar_client * c; |
---|
| 226 | |
---|
| 227 | if ( clients_get(client, &c) == -1 ) |
---|
| 228 | return -1; |
---|
| 229 | |
---|
| 230 | // "NDNE"; |
---|
| 231 | |
---|
| 232 | if ( !memcmp(data, "NDNE", 4) ) { |
---|
| 233 | c->byteorder = ROAR_BYTEORDER_LE; |
---|
| 234 | } else if ( !memcmp(data, "ENDE", 4) ) { |
---|
| 235 | c->byteorder = ROAR_BYTEORDER_BE; |
---|
| 236 | } else if ( !memcmp(data, "NEED", 4) ) { |
---|
| 237 | c->byteorder = ROAR_BYTEORDER_PDP; |
---|
| 238 | } else { |
---|
| 239 | return -1; |
---|
| 240 | } |
---|
| 241 | |
---|
[2524] | 242 | return 0; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | // handler: |
---|
[5739] | 246 | static int emul_esd_on_connect (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2529] | 247 | |
---|
[5740] | 248 | (void)cmd; |
---|
| 249 | |
---|
[2529] | 250 | ROAR_DBG("emul_esd_on_connect(client=%i, cmd=%p, data=%p, vio=%p) = ?", client, cmd, data, vio); |
---|
| 251 | |
---|
[2526] | 252 | if ( client == -1 || data == NULL || vio == NULL ) |
---|
| 253 | return -1; |
---|
| 254 | |
---|
[2529] | 255 | ROAR_DBG("emul_esd_on_connect(client=%i, cmd=%p, data=%p, vio=%p) = ?", client, cmd, data, vio); |
---|
| 256 | |
---|
[2526] | 257 | if ( emul_esd_test_auth(client, data, vio) == -1 ) |
---|
| 258 | return -1; |
---|
| 259 | |
---|
[2529] | 260 | ROAR_DBG("emul_esd_on_connect(client=%i, cmd=%p, data=%p, vio=%p) = ?", client, cmd, data, vio); |
---|
| 261 | |
---|
[2526] | 262 | if ( emul_esd_test_byteorder(client, data+ESD_KEY_LEN) == -1 ) |
---|
| 263 | return -1; |
---|
| 264 | |
---|
[2529] | 265 | ROAR_DBG("emul_esd_on_connect(client=%i, cmd=%p, data=%p, vio=%p) = ?", client, cmd, data, vio); |
---|
| 266 | |
---|
[2526] | 267 | return 0; |
---|
[2524] | 268 | } |
---|
| 269 | |
---|
[5739] | 270 | static int emul_esd_on_stream (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2527] | 271 | struct roar_stream_server * ss; |
---|
| 272 | struct roar_stream * s; |
---|
[2531] | 273 | struct roar_client * c; |
---|
[2527] | 274 | int stream; |
---|
| 275 | int dir = -1; |
---|
[2528] | 276 | int esdformat; |
---|
[3194] | 277 | int rate = 0; |
---|
[2527] | 278 | |
---|
| 279 | if ( client == -1 || cmd == NULL || data == NULL || vio == NULL ) |
---|
| 280 | return -1; |
---|
| 281 | |
---|
| 282 | switch (cmd->cmd) { |
---|
| 283 | case ESD_PROTO_STREAM_PLAY: dir = ROAR_DIR_PLAY; break; |
---|
| 284 | case ESD_PROTO_STREAM_REC: dir = ROAR_DIR_RECORD; break; |
---|
| 285 | case ESD_PROTO_STREAM_MON: dir = ROAR_DIR_MONITOR; break; |
---|
| 286 | case ESD_PROTO_STREAM_FILT: dir = ROAR_DIR_FILTER; break; |
---|
| 287 | default: |
---|
| 288 | return -1; |
---|
| 289 | } |
---|
| 290 | |
---|
[2531] | 291 | if ( clients_get(client, &c) == -1 ) { |
---|
| 292 | return -1; |
---|
| 293 | } |
---|
| 294 | |
---|
[2527] | 295 | ROAR_DBG("emul_esd_on_stream(client=%i, ...): creating stream...", client); |
---|
| 296 | if ((stream = streams_new()) == -1 ) { |
---|
| 297 | return -1; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | ROAR_DBG("emul_esd_on_stream(client=%i, ...): getting stream...", client); |
---|
| 301 | if ( streams_get(stream, &ss) == -1 ) { |
---|
| 302 | streams_delete(stream); |
---|
| 303 | return -1; |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | s = ROAR_STREAM(ss); |
---|
| 307 | |
---|
| 308 | ROAR_DBG("emul_esd_on_stream(client=%i, ...): set client of stream...", client); |
---|
| 309 | if ( client_stream_add(client, stream) == -1 ) { |
---|
| 310 | streams_delete(stream); |
---|
| 311 | return -1; |
---|
| 312 | } |
---|
| 313 | |
---|
[2528] | 314 | emul_esd_int_read_buf(client, &esdformat, data); |
---|
| 315 | emul_esd_int_read_buf(client, &rate, data+_INTSIZE); |
---|
| 316 | |
---|
[2531] | 317 | strncpy(c->name, data + 2*_INTSIZE, ROAR_BUFFER_NAME > ESD_NAME_MAX ? ESD_NAME_MAX : ROAR_BUFFER_NAME); |
---|
| 318 | c->name[ROAR_BUFFER_NAME-1] = 0; |
---|
| 319 | |
---|
[2529] | 320 | ROAR_DBG("emul_esd_on_stream(*): esdformat=0x%.8X, rate=%i", esdformat, rate); |
---|
| 321 | |
---|
[2528] | 322 | s->info.rate = rate; |
---|
| 323 | |
---|
| 324 | switch (esdformat & ESD_MASK_BITS) { |
---|
[2529] | 325 | case ESD_BITS8: s->info.bits = 8; s->info.codec = ROAR_CODEC_PCM_U_LE; break; |
---|
| 326 | case ESD_BITS16: s->info.bits = 16; s->info.codec = ROAR_CODEC_DEFAULT; break; |
---|
[2528] | 327 | default: |
---|
| 328 | streams_delete(stream); |
---|
| 329 | return -1; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | switch (esdformat & ESD_MASK_CHAN) { |
---|
| 333 | case ESD_MONO: s->info.channels = 1; break; |
---|
| 334 | case ESD_STEREO: s->info.channels = 2; break; |
---|
| 335 | default: |
---|
| 336 | streams_delete(stream); |
---|
| 337 | return -1; |
---|
| 338 | } |
---|
| 339 | |
---|
[2527] | 340 | ss->codec_orgi = s->info.codec; |
---|
| 341 | |
---|
[2529] | 342 | ROAR_DBG("emul_esd_on_stream(*): s->info = {.rate=%i, .bits=%i, .channels=%i, .codec=%i}", s->info.rate, s->info.bits, s->info.channels, s->info.codec); |
---|
| 343 | |
---|
[2527] | 344 | if ( streams_set_dir(stream, dir, 1) == -1 ) { |
---|
| 345 | return -1; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | if ( client_stream_exec(client, stream) == -1 ) { |
---|
| 349 | return -1; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | return 0; |
---|
| 353 | } |
---|
[2524] | 354 | |
---|
[5739] | 355 | static int emul_esd_on_latency (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2533] | 356 | int lag = ROAR_OUTPUT_CFREQ; |
---|
| 357 | |
---|
[5740] | 358 | (void)cmd, (void)data; |
---|
| 359 | |
---|
[2533] | 360 | lag *= 2.0 * 44100.0 / (float)g_sa->rate; |
---|
| 361 | |
---|
| 362 | return emul_esd_int_write(client, lag, vio); |
---|
| 363 | } |
---|
| 364 | |
---|
[5739] | 365 | static int emul_esd_on_standby (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2535] | 366 | int ok = 0; |
---|
| 367 | |
---|
| 368 | if ( emul_esd_test_auth(client, data, vio) == -1 ) { |
---|
| 369 | return emul_esd_int_write(client, ok, vio); |
---|
| 370 | } |
---|
| 371 | |
---|
| 372 | ok = 1; |
---|
| 373 | |
---|
| 374 | if (cmd->cmd == ESD_PROTO_STANDBY) { |
---|
| 375 | g_standby = 1; |
---|
| 376 | } else { |
---|
| 377 | g_standby = 0; |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | |
---|
| 381 | return emul_esd_int_write(client, ok, vio); |
---|
| 382 | } |
---|
| 383 | |
---|
[5739] | 384 | static int emul_esd_on_standbymode(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2536] | 385 | int mode = ESM_ERROR; |
---|
| 386 | |
---|
[5740] | 387 | (void)cmd, (void)data; |
---|
| 388 | |
---|
[2536] | 389 | if ( g_standby ) { |
---|
| 390 | if ( g_autostandby ) { |
---|
| 391 | mode = ESM_ON_AUTOSTANDBY; |
---|
| 392 | } else { |
---|
| 393 | mode = ESM_ON_STANDBY; |
---|
| 394 | } |
---|
| 395 | } else { |
---|
| 396 | mode = ESM_RUNNING; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | return emul_esd_int_write(client, mode, vio); |
---|
| 400 | } |
---|
| 401 | |
---|
[5739] | 402 | static int emul_esd_on_stream_pan (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2538] | 403 | struct roar_stream_server * ss; |
---|
[3194] | 404 | int stream = -1; |
---|
| 405 | int left = 256, right = 256; |
---|
[2538] | 406 | int ok = 0; |
---|
| 407 | |
---|
[5740] | 408 | (void)cmd; |
---|
| 409 | |
---|
[2538] | 410 | emul_esd_int_read_buf(client, &stream, data + 0*_INTSIZE); |
---|
| 411 | emul_esd_int_read_buf(client, &left, data + 1*_INTSIZE); |
---|
| 412 | emul_esd_int_read_buf(client, &right, data + 2*_INTSIZE); |
---|
| 413 | |
---|
| 414 | stream = _ESD2ROAR(stream); |
---|
| 415 | |
---|
| 416 | if ( streams_get(stream, &ss) != -1 ) { |
---|
[3562] | 417 | ss->mixer.scale = 256; |
---|
| 418 | ss->mixer.mixer[0] = left; |
---|
| 419 | ss->mixer.mixer[1] = right; |
---|
[2538] | 420 | if ( streams_set_mixer(stream) != -1 ) |
---|
| 421 | ok = 1; |
---|
| 422 | } |
---|
| 423 | |
---|
| 424 | return emul_esd_int_write(client, ok, vio); |
---|
| 425 | } |
---|
| 426 | |
---|
[5739] | 427 | static int emul_esd_on_server_info(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2539] | 428 | int version = 0; |
---|
| 429 | int rate = g_sa->rate; |
---|
| 430 | int format = 0; |
---|
| 431 | |
---|
[5740] | 432 | (void)cmd, (void)data; |
---|
| 433 | |
---|
[2539] | 434 | switch (g_sa->bits) { |
---|
| 435 | case 8: format |= ESD_BITS8; break; |
---|
| 436 | case 16: format |= ESD_BITS16; break; |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | switch (g_sa->channels) { |
---|
| 440 | case 1: format |= ESD_MONO; break; |
---|
| 441 | case 2: format |= ESD_STEREO; break; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | if ( emul_esd_int_write(client, version, vio) == -1 ) |
---|
| 445 | return -1; |
---|
| 446 | |
---|
| 447 | if ( emul_esd_int_write(client, rate, vio) == -1 ) |
---|
| 448 | return -1; |
---|
| 449 | |
---|
| 450 | if ( emul_esd_int_write(client, format, vio) == -1 ) |
---|
| 451 | return -1; |
---|
| 452 | |
---|
| 453 | return 0; |
---|
| 454 | } |
---|
| 455 | |
---|
[5739] | 456 | static int emul_esd_on_all_info (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) { |
---|
[2541] | 457 | struct roar_stream_server * ss; |
---|
| 458 | struct roar_audio_info * info; |
---|
| 459 | struct roar_client * c; |
---|
| 460 | char name[ESD_NAME_MAX]; |
---|
| 461 | char * sname; |
---|
| 462 | int id, rate, left, right, format; |
---|
| 463 | int i; |
---|
| 464 | |
---|
| 465 | if ( emul_esd_on_server_info(client, cmd, data, vio) == -1 ) |
---|
| 466 | return -1; |
---|
| 467 | |
---|
| 468 | for (i = 0; i < (ROAR_STREAMS_MAX+2); i++) { |
---|
| 469 | memset(name, 0, sizeof(name)); |
---|
| 470 | |
---|
| 471 | id = rate = format = 0; |
---|
| 472 | left = right = 0; |
---|
| 473 | |
---|
| 474 | if ( i >= ROAR_STREAMS_MAX ) { |
---|
| 475 | id = -1; |
---|
| 476 | } else { |
---|
| 477 | if ( streams_get(i, &ss) == -1 ) |
---|
| 478 | continue; |
---|
| 479 | |
---|
[2542] | 480 | switch (streams_get_dir(i)) { |
---|
| 481 | case ROAR_DIR_PLAY: format |= ESD_PLAY; break; |
---|
| 482 | case ROAR_DIR_MONITOR: format |= ESD_MONITOR; break; |
---|
| 483 | case ROAR_DIR_RECORD: format |= ESD_RECORD; break; |
---|
| 484 | default: continue; break; |
---|
| 485 | } |
---|
[2541] | 486 | |
---|
| 487 | info = &(ROAR_STREAM(ss)->info); |
---|
| 488 | |
---|
| 489 | id = i; |
---|
| 490 | rate = info->rate; |
---|
| 491 | |
---|
| 492 | switch (info->bits) { |
---|
| 493 | case 8: format |= ESD_BITS8; break; |
---|
| 494 | case 16: format |= ESD_BITS16; break; |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | switch (info->channels) { |
---|
| 498 | case 1: |
---|
| 499 | if ( ss->mixer.mixer[0] == ss->mixer.scale ) { |
---|
| 500 | left = right = 256; |
---|
| 501 | } else { |
---|
[3562] | 502 | left = right = ss->mixer.mixer[0] * 256 / ss->mixer.scale; |
---|
[2541] | 503 | } |
---|
| 504 | format |= ESD_MONO; |
---|
| 505 | break; |
---|
| 506 | case 2: |
---|
| 507 | if ( ss->mixer.mixer[0] == ss->mixer.scale ) { |
---|
| 508 | left = 256; |
---|
| 509 | } else { |
---|
[3562] | 510 | left = ss->mixer.mixer[0] * 256 / ss->mixer.scale; |
---|
[2541] | 511 | } |
---|
| 512 | |
---|
| 513 | if ( ss->mixer.mixer[1] == ss->mixer.scale ) { |
---|
| 514 | right = 256; |
---|
| 515 | } else { |
---|
[3562] | 516 | right = ss->mixer.mixer[1] * 256 / ss->mixer.scale; |
---|
[2541] | 517 | } |
---|
| 518 | |
---|
| 519 | format |= ESD_STEREO; |
---|
| 520 | break; |
---|
| 521 | default: |
---|
| 522 | left = right = 0; |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | sname = streams_get_name(id); |
---|
| 526 | |
---|
| 527 | if ( sname == NULL || sname[0] == 0 ) { |
---|
| 528 | if ( clients_get(streams_get_client(id), &c) != -1 ) { |
---|
| 529 | sname = c->name; |
---|
| 530 | } |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | if ( sname == NULL || sname[0] == 0 ) |
---|
| 534 | sname = "(unknown)"; |
---|
| 535 | |
---|
| 536 | strncpy(name, sname, sizeof(name) > ROAR_BUFFER_NAME ? ROAR_BUFFER_NAME : sizeof(name)); |
---|
| 537 | name[sizeof(name)-1] = 0; |
---|
| 538 | |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | id = _ROAR2ESD(id); |
---|
| 542 | |
---|
| 543 | if ( emul_esd_int_write(client, id, vio) == -1 ) |
---|
| 544 | return -1; |
---|
| 545 | if ( roar_vio_write(vio, name, sizeof(name)) != sizeof(name) ) |
---|
| 546 | return -1; |
---|
| 547 | if ( emul_esd_int_write(client, rate, vio) == -1 ) |
---|
| 548 | return -1; |
---|
| 549 | if ( emul_esd_int_write(client, left, vio) == -1 ) |
---|
| 550 | return -1; |
---|
| 551 | if ( emul_esd_int_write(client, right, vio) == -1 ) |
---|
| 552 | return -1; |
---|
| 553 | if ( emul_esd_int_write(client, format, vio) == -1 ) |
---|
| 554 | return -1; |
---|
| 555 | |
---|
| 556 | if ( i == ROAR_STREAMS_MAX+1) { |
---|
| 557 | // write 'length'... |
---|
| 558 | if ( emul_esd_int_write(client, id, vio) == -1 ) |
---|
| 559 | return -1; |
---|
| 560 | } |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | return 0; |
---|
| 564 | } |
---|
| 565 | |
---|
[5740] | 566 | static struct roar_dl_proto __proto_common_esd = { |
---|
[5739] | 567 | .proto = ROAR_PROTO_ESOUND, |
---|
| 568 | .description = "EsounD emulation", |
---|
| 569 | .flags = ROAR_DL_PROTO_FLAGS_NONE, |
---|
| 570 | .set_proto = emul_esd_set_proto, |
---|
| 571 | .handle = emul_esd_check_client |
---|
| 572 | }; |
---|
| 573 | |
---|
[5740] | 574 | static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { |
---|
| 575 | (void)para, (void)lib; |
---|
| 576 | ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, __proto_common_esd, ROAR_DL_PROTO_VERSION); |
---|
| 577 | return 0; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | ROAR_DL_PLUGIN_START(protocol_esd) { |
---|
| 581 | ROARD_DL_CHECK_VERSIONS(); |
---|
| 582 | |
---|
| 583 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-esd", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
| 584 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
| 585 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
| 586 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
| 587 | ROAR_DL_PLUGIN_META_DESC("Implementation of the Enlightened Sound Daemon's protocol"); |
---|
| 588 | |
---|
| 589 | ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); |
---|
| 590 | } ROAR_DL_PLUGIN_END |
---|
| 591 | |
---|
[2521] | 592 | #endif |
---|
[2519] | 593 | #endif |
---|
| 594 | |
---|
| 595 | //ll |
---|