[0] | 1 | //stream.c: |
---|
| 2 | |
---|
[690] | 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
| 5 | * |
---|
| 6 | * This file is part of libroar 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 | * libroar 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. |
---|
[690] | 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
[0] | 36 | #include "libroar.h" |
---|
| 37 | |
---|
| 38 | int roar_stream_connect (struct roar_connection * con, struct roar_stream * s, int dir) { |
---|
[3136] | 39 | struct roar_libroar_config * config = roar_libroar_get_config(); |
---|
| 40 | struct roar_stream ms; |
---|
[0] | 41 | struct roar_message m; |
---|
| 42 | |
---|
| 43 | s->dir = dir; |
---|
| 44 | |
---|
[3136] | 45 | memcpy(&ms, s, sizeof(ms)); |
---|
| 46 | |
---|
[0] | 47 | m.cmd = ROAR_CMD_NEW_STREAM; |
---|
| 48 | m.stream = -1; |
---|
| 49 | m.pos = 0; |
---|
| 50 | |
---|
[3136] | 51 | if ( config != NULL ) { |
---|
| 52 | if ( config->info.rate ) |
---|
| 53 | ms.info.rate = config->info.rate; |
---|
| 54 | if ( config->info.bits ) |
---|
| 55 | ms.info.bits = config->info.bits; |
---|
| 56 | if ( config->info.channels ) |
---|
| 57 | ms.info.channels = config->info.channels; |
---|
| 58 | if ( config->info.codec ) |
---|
| 59 | ms.info.codec = config->info.codec; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | roar_stream_s2m(&ms, &m); |
---|
[0] | 63 | |
---|
| 64 | if ( roar_req(con, &m, NULL) != 0 ) |
---|
| 65 | return -1; |
---|
| 66 | |
---|
| 67 | if ( m.cmd == ROAR_CMD_OK ) { |
---|
| 68 | s->id = m.stream; |
---|
| 69 | |
---|
| 70 | ROAR_DBG("roar_stream_connect(*) = 0"); |
---|
| 71 | return 0; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | ROAR_ERR("roar_stream_connect(*): Connecting new stream faild!"); |
---|
| 75 | ROAR_DBG("roar_stream_connect(*) = -1"); |
---|
| 76 | return -1; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | int roar_stream_new (struct roar_stream * s, unsigned int rate, |
---|
| 80 | unsigned int channels, unsigned int bits, unsigned int codec) { |
---|
| 81 | |
---|
[1813] | 82 | if ( s == NULL ) |
---|
| 83 | return -1; |
---|
[0] | 84 | |
---|
| 85 | s->fh = -1; |
---|
| 86 | s->id = -1; |
---|
[1813] | 87 | s->pos = 0; |
---|
[0] | 88 | s->pos_rel_id = -1; |
---|
| 89 | |
---|
| 90 | s->dir = ROAR_DIR_DEFAULT; |
---|
| 91 | |
---|
[1804] | 92 | /* |
---|
[0] | 93 | s->datalen = 0; |
---|
| 94 | s->offset = 0; |
---|
| 95 | |
---|
| 96 | s->database = NULL; |
---|
| 97 | s->dataoff = NULL; |
---|
[1804] | 98 | */ |
---|
[0] | 99 | |
---|
| 100 | s->info.rate = rate; |
---|
| 101 | s->info.channels = channels; |
---|
| 102 | s->info.bits = bits; |
---|
| 103 | s->info.codec = codec; |
---|
| 104 | |
---|
| 105 | if ( bits > ROAR_BITS_MAX ) |
---|
| 106 | return -1; |
---|
| 107 | |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
[1813] | 111 | int roar_stream_set_rel_id(struct roar_stream * s, int id) { |
---|
| 112 | if ( s == NULL ) |
---|
| 113 | return -1; |
---|
| 114 | |
---|
| 115 | s->pos_rel_id = id; |
---|
| 116 | |
---|
| 117 | return 0; |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | int roar_stream_get_rel_id(struct roar_stream * s) { |
---|
| 121 | if ( s == NULL ) |
---|
| 122 | return -1; |
---|
| 123 | |
---|
| 124 | return s->pos_rel_id; |
---|
| 125 | } |
---|
| 126 | |
---|
[1167] | 127 | int roar_stream_new_by_id(struct roar_stream * s, int id) { |
---|
| 128 | if ( s == NULL ) |
---|
| 129 | return -1; |
---|
| 130 | |
---|
| 131 | if ( roar_stream_new_empty(s) == -1 ) |
---|
| 132 | return -1; |
---|
| 133 | |
---|
| 134 | return roar_stream_set_id(s, id); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | int roar_stream_new_empty(struct roar_stream * s) { |
---|
| 138 | if ( s == NULL ) |
---|
| 139 | return -1; |
---|
| 140 | |
---|
| 141 | return roar_stream_new(s, 0, 0, 0, 0); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | int roar_stream_set_id (struct roar_stream * s, int id) { |
---|
| 145 | if ( s == NULL ) |
---|
| 146 | return -1; |
---|
| 147 | |
---|
| 148 | s->id = id; |
---|
| 149 | |
---|
| 150 | return 0; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | int roar_stream_get_id (struct roar_stream * s) { |
---|
| 154 | if ( s == NULL ) |
---|
| 155 | return -1; |
---|
| 156 | |
---|
| 157 | return s->id; |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | int roar_stream_set_fh (struct roar_stream * s, int fh) { |
---|
| 161 | if ( s == NULL ) |
---|
| 162 | return -1; |
---|
| 163 | |
---|
| 164 | s->fh = fh; |
---|
| 165 | |
---|
| 166 | return 0; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | int roar_stream_get_fh (struct roar_stream * s) { |
---|
| 170 | if ( s == NULL ) |
---|
| 171 | return -1; |
---|
| 172 | |
---|
| 173 | return s->fh; |
---|
| 174 | } |
---|
| 175 | |
---|
[2588] | 176 | int roar_stream_set_dir (struct roar_stream * s, int dir) { |
---|
| 177 | if ( s == NULL ) |
---|
| 178 | return -1; |
---|
| 179 | |
---|
| 180 | s->dir = dir; |
---|
| 181 | |
---|
| 182 | return 0; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | int roar_stream_get_dir (struct roar_stream * s) { |
---|
| 186 | if ( s == NULL ) |
---|
| 187 | return -1; |
---|
| 188 | |
---|
| 189 | return s->dir; |
---|
| 190 | } |
---|
| 191 | |
---|
[1167] | 192 | |
---|
[0] | 193 | int roar_stream_exec (struct roar_connection * con, struct roar_stream * s) { |
---|
| 194 | struct roar_message m; |
---|
| 195 | |
---|
| 196 | m.cmd = ROAR_CMD_EXEC_STREAM; |
---|
| 197 | m.stream = s->id; |
---|
| 198 | m.datalen = 0; |
---|
| 199 | m.pos = 0; |
---|
| 200 | |
---|
| 201 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 202 | return -1; |
---|
| 203 | |
---|
| 204 | if ( m.cmd == ROAR_CMD_OK ) |
---|
| 205 | return 0; |
---|
| 206 | return -1; |
---|
| 207 | } |
---|
| 208 | |
---|
[81] | 209 | int roar_stream_connect_to (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) { |
---|
| 210 | struct roar_message m; |
---|
[82] | 211 | |
---|
| 212 | if ( roar_stream_connect_to_ask(con, s, type, host, port) == -1 ) |
---|
| 213 | return -1; |
---|
| 214 | |
---|
| 215 | if ( roar_recv_message(con, &m, NULL) == -1 ) |
---|
| 216 | return -1; |
---|
| 217 | |
---|
| 218 | if ( m.cmd == ROAR_CMD_OK ) |
---|
| 219 | return 0; |
---|
| 220 | return -1; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | int roar_stream_connect_to_ask (struct roar_connection * con, struct roar_stream * s, int type, char * host, int port) { |
---|
| 224 | struct roar_message m; |
---|
[81] | 225 | int len = 0; |
---|
| 226 | |
---|
| 227 | if ( host == NULL ) |
---|
| 228 | return -1; |
---|
| 229 | |
---|
[487] | 230 | ROAR_DBG("roar_stream_connect_to_ask(*): Ask the server to connect to: %s:%i", host, port); |
---|
| 231 | |
---|
[81] | 232 | m.cmd = ROAR_CMD_CON_STREAM; |
---|
| 233 | m.stream = s->id; |
---|
| 234 | m.pos = 0; |
---|
| 235 | |
---|
| 236 | m.data[0] = 0; |
---|
| 237 | m.data[1] = type; |
---|
| 238 | ((uint16_t*)&(m.data))[1] = ROAR_HOST2NET16(port); |
---|
| 239 | |
---|
| 240 | len = strlen(host); |
---|
| 241 | |
---|
| 242 | if ( len > 76 ) |
---|
| 243 | return -1; |
---|
| 244 | |
---|
| 245 | strncpy(&(m.data[4]), host, len); |
---|
| 246 | |
---|
| 247 | m.datalen = len + 4; |
---|
| 248 | |
---|
[82] | 249 | if ( roar_send_message(con, &m, NULL) == -1 ) |
---|
[81] | 250 | return -1; |
---|
| 251 | |
---|
[82] | 252 | return 0; |
---|
[81] | 253 | } |
---|
[0] | 254 | |
---|
[758] | 255 | int roar_stream_passfh (struct roar_connection * con, struct roar_stream * s, int fh) { |
---|
| 256 | struct roar_message m; |
---|
[1660] | 257 | int confh; |
---|
[758] | 258 | |
---|
| 259 | m.cmd = ROAR_CMD_PASSFH; |
---|
| 260 | m.stream = s->id; |
---|
| 261 | m.pos = 0; |
---|
[759] | 262 | m.datalen = 0; |
---|
[758] | 263 | |
---|
[2038] | 264 | ROAR_DBG("roar_stream_passfh(con=%p{...}, s={.id=%i,...}, fh=%i) = ?", con, s->id, fh); |
---|
[759] | 265 | |
---|
[1660] | 266 | if ( (confh = roar_get_connection_fh(con)) == -1 ) |
---|
| 267 | return -1; |
---|
| 268 | |
---|
[759] | 269 | if ( roar_send_message(con, &m, NULL) == -1 ) { |
---|
[2038] | 270 | ROAR_DBG("roar_stream_passfh(con=%p{...}, s={.id=%i,...}, fh=%i) = -1 // can not send message", con, s->id, fh); |
---|
[758] | 271 | return -1; |
---|
[759] | 272 | } |
---|
| 273 | |
---|
| 274 | ROAR_DBG("roar_stream_passfh(*): msg send"); |
---|
[758] | 275 | |
---|
[1660] | 276 | if ( roar_socket_send_fh(confh, fh, NULL, 0) == -1 ) |
---|
[758] | 277 | return -1; |
---|
| 278 | |
---|
[759] | 279 | ROAR_DBG("roar_stream_passfh(*): fh send"); |
---|
| 280 | |
---|
[758] | 281 | if ( roar_recv_message(con, &m, NULL) == -1 ) |
---|
| 282 | return -1; |
---|
| 283 | |
---|
[759] | 284 | ROAR_DBG("roar_stream_passfh(*): mes recved"); |
---|
| 285 | |
---|
[761] | 286 | if ( m.cmd == ROAR_CMD_OK ) |
---|
| 287 | return 0; |
---|
| 288 | |
---|
| 289 | return -1; |
---|
[758] | 290 | } |
---|
| 291 | |
---|
[773] | 292 | int roar_stream_attach_simple (struct roar_connection * con, struct roar_stream * s, int client) { |
---|
| 293 | struct roar_message m; |
---|
| 294 | uint16_t * info = (uint16_t *) m.data; |
---|
| 295 | int i; |
---|
| 296 | |
---|
| 297 | m.cmd = ROAR_CMD_ATTACH; |
---|
| 298 | m.stream = s->id; |
---|
| 299 | m.pos = 0; |
---|
| 300 | m.datalen = 6; |
---|
| 301 | |
---|
| 302 | info[0] = 0; |
---|
| 303 | info[1] = ROAR_ATTACH_SIMPLE; |
---|
| 304 | info[2] = client; |
---|
| 305 | |
---|
| 306 | for (i = 0; i < m.datalen/2; i++) { |
---|
| 307 | info[i] = ROAR_HOST2NET16(info[i]); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 311 | return -1; |
---|
| 312 | |
---|
| 313 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 314 | return -1; |
---|
| 315 | |
---|
| 316 | return 0; |
---|
| 317 | } |
---|
| 318 | |
---|
[0] | 319 | int roar_stream_add_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len) { |
---|
| 320 | struct roar_message m; |
---|
| 321 | |
---|
| 322 | m.cmd = ROAR_CMD_ADD_DATA; |
---|
| 323 | m.stream = s->id; |
---|
[134] | 324 | m.pos = 0; |
---|
[0] | 325 | m.datalen = len; |
---|
| 326 | |
---|
| 327 | // if ( roar_req(con, &m, (void**)&data) == -1 ) |
---|
| 328 | // return -1; |
---|
| 329 | if ( roar_send_message(con, &m, data) != 0 ) |
---|
| 330 | return -1; |
---|
| 331 | |
---|
| 332 | if ( roar_recv_message(con, &m, NULL) == -1 ) |
---|
| 333 | return -1; |
---|
| 334 | |
---|
| 335 | if ( m.cmd == ROAR_CMD_OK ) |
---|
| 336 | return 0; |
---|
| 337 | return -1; |
---|
| 338 | } |
---|
| 339 | |
---|
[506] | 340 | int roar_stream_send_data (struct roar_connection * con, struct roar_stream * s, char * data, size_t len) { |
---|
| 341 | if ( ! s ) |
---|
| 342 | return -1; |
---|
| 343 | |
---|
| 344 | if ( s->fh == -1 ) { |
---|
| 345 | if ( !con ) |
---|
| 346 | return -1; |
---|
| 347 | |
---|
| 348 | if ( roar_stream_add_data(con, s, data, len) == -1 ) |
---|
| 349 | return -1; |
---|
| 350 | |
---|
| 351 | return len; |
---|
| 352 | } |
---|
| 353 | |
---|
[1475] | 354 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[506] | 355 | return write(s->fh, data, len); |
---|
[1475] | 356 | #endif |
---|
| 357 | |
---|
| 358 | return -1; |
---|
[506] | 359 | } |
---|
| 360 | |
---|
[465] | 361 | int roar_stream_get_info (struct roar_connection * con, struct roar_stream * s, struct roar_stream_info * info) { |
---|
| 362 | struct roar_message m; |
---|
| 363 | uint16_t * data = (uint16_t *) m.data; |
---|
| 364 | int i; |
---|
| 365 | |
---|
| 366 | m.cmd = ROAR_CMD_GET_STREAM_PARA; |
---|
| 367 | m.stream = s->id; |
---|
| 368 | m.datalen = 4; |
---|
| 369 | m.pos = 0; |
---|
| 370 | |
---|
| 371 | data[0] = 0; // Version and reserved |
---|
[1842] | 372 | data[1] = ROAR_STREAM_PARA_INFO; // stream |
---|
[465] | 373 | |
---|
| 374 | for (i = 0; i < m.datalen/2; i++) { |
---|
| 375 | data[i] = ROAR_HOST2NET16(data[i]); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 379 | return -1; |
---|
| 380 | |
---|
| 381 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 382 | return -1; |
---|
| 383 | |
---|
| 384 | for (i = 0; i < m.datalen/2; i++) { |
---|
| 385 | data[i] = ROAR_NET2HOST16(data[i]); |
---|
| 386 | } |
---|
| 387 | |
---|
[1137] | 388 | if ( m.datalen < 7*2 ) |
---|
[465] | 389 | return -1; |
---|
| 390 | |
---|
| 391 | if ( data[0] != 0 || data[1] != 1 ) |
---|
| 392 | return -1; |
---|
| 393 | |
---|
[963] | 394 | memset(info, 0, sizeof(struct roar_stream_info)); |
---|
[3213] | 395 | info->mixer = -1; |
---|
[963] | 396 | |
---|
[496] | 397 | info->block_size = data[2]; |
---|
| 398 | info->pre_underruns = data[3]; |
---|
| 399 | info->post_underruns = data[4]; |
---|
[540] | 400 | info->codec = data[5]; |
---|
[963] | 401 | info->flags = data[6]; |
---|
[1137] | 402 | info->delay = data[7]*1000; |
---|
[465] | 403 | |
---|
[2951] | 404 | if ( m.datalen < 9*2 ) { |
---|
[2632] | 405 | info->state = ROAR_STREAMSTATE_UNKNOWN; |
---|
| 406 | return 0; |
---|
| 407 | } else { |
---|
| 408 | info->state = data[8]; |
---|
| 409 | } |
---|
| 410 | |
---|
[2951] | 411 | if ( m.datalen < 10*2 ) { |
---|
| 412 | return 0; |
---|
| 413 | } else { |
---|
| 414 | info->flags |= ((uint32_t)data[9]) << 16; |
---|
| 415 | } |
---|
| 416 | |
---|
[3213] | 417 | if ( m.datalen < 11*2 ) { |
---|
| 418 | return 0; |
---|
| 419 | } else { |
---|
| 420 | info->mixer = data[10]; |
---|
| 421 | } |
---|
| 422 | |
---|
[465] | 423 | return 0; |
---|
| 424 | } |
---|
[0] | 425 | |
---|
[1842] | 426 | int roar_stream_get_name (struct roar_connection * con, struct roar_stream * s, char * name, size_t len) { |
---|
| 427 | struct roar_message m; |
---|
| 428 | uint16_t * data = (uint16_t *) m.data; |
---|
| 429 | |
---|
| 430 | if ( con == NULL || s == NULL || name == NULL || len == 0 ) |
---|
| 431 | return -1; |
---|
| 432 | |
---|
| 433 | name[0] = 0; // just in case... |
---|
| 434 | |
---|
| 435 | m.cmd = ROAR_CMD_GET_STREAM_PARA; |
---|
| 436 | m.stream = s->id; |
---|
| 437 | m.datalen = 4; |
---|
| 438 | m.pos = 0; |
---|
| 439 | |
---|
| 440 | data[0] = 0; // Version and reserved |
---|
| 441 | data[1] = ROAR_STREAM_PARA_NAME; // stream |
---|
| 442 | |
---|
| 443 | data[0] = ROAR_HOST2NET16(data[0]); |
---|
| 444 | data[1] = ROAR_HOST2NET16(data[1]); |
---|
| 445 | |
---|
| 446 | ROAR_DBG("roar_stream_get_name(*) = ?"); |
---|
| 447 | |
---|
| 448 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 449 | return -1; |
---|
| 450 | |
---|
| 451 | ROAR_DBG("roar_stream_get_name(*) = ?"); |
---|
| 452 | |
---|
| 453 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 454 | return -1; |
---|
| 455 | |
---|
| 456 | ROAR_DBG("roar_stream_get_name(*) = ?"); |
---|
| 457 | |
---|
| 458 | if ( m.datalen < 4 ) |
---|
| 459 | return -1; |
---|
| 460 | |
---|
| 461 | data[0] = ROAR_NET2HOST16(data[0]); |
---|
| 462 | data[1] = ROAR_NET2HOST16(data[1]); |
---|
| 463 | |
---|
| 464 | ROAR_DBG("roar_stream_get_name(*) = ?"); |
---|
| 465 | |
---|
| 466 | if ( data[0] != 0 || data[1] != ROAR_STREAM_PARA_NAME ) |
---|
| 467 | return -1; |
---|
| 468 | |
---|
| 469 | m.datalen -= 4; |
---|
| 470 | |
---|
| 471 | len--; |
---|
| 472 | |
---|
| 473 | if ( len > m.datalen ) |
---|
| 474 | len = m.datalen; |
---|
| 475 | |
---|
| 476 | strncpy(name, ((char*)m.data)+4, len); |
---|
| 477 | name[len] = 0; |
---|
| 478 | |
---|
| 479 | ROAR_DBG("roar_stream_get_name(*) = 0"); |
---|
| 480 | |
---|
| 481 | return 0; |
---|
| 482 | } |
---|
| 483 | |
---|
[1043] | 484 | int roar_stream_set_flags (struct roar_connection * con, struct roar_stream * s, int flags, int reset) { |
---|
| 485 | struct roar_message m; |
---|
| 486 | uint16_t * data = (uint16_t *) m.data; |
---|
| 487 | int i; |
---|
| 488 | |
---|
| 489 | m.cmd = ROAR_CMD_SET_STREAM_PARA; |
---|
| 490 | m.stream = s->id; |
---|
| 491 | m.datalen = 8; |
---|
| 492 | m.pos = 0; |
---|
| 493 | |
---|
| 494 | data[0] = 0; // Version and reserved |
---|
| 495 | data[1] = 2; // flags |
---|
| 496 | data[2] = reset == ROAR_RESET_FLAG ? ROAR_RESET_FLAG : ROAR_SET_FLAG; |
---|
| 497 | data[3] = flags; |
---|
| 498 | |
---|
| 499 | for (i = 0; i < m.datalen/2; i++) { |
---|
| 500 | data[i] = ROAR_HOST2NET16(data[i]); |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | if ( roar_req(con, &m, NULL) == -1 ) |
---|
| 504 | return -1; |
---|
| 505 | |
---|
| 506 | if ( m.cmd != ROAR_CMD_OK ) |
---|
| 507 | return -1; |
---|
| 508 | |
---|
| 509 | return 0; |
---|
| 510 | } |
---|
| 511 | |
---|
[0] | 512 | #define _ROAR_STREAM_MESSAGE_LEN ((5+1)*4) |
---|
| 513 | |
---|
| 514 | int roar_stream_s2m (struct roar_stream * s, struct roar_message * m) { |
---|
| 515 | uint32_t * data; |
---|
| 516 | int i; |
---|
| 517 | |
---|
| 518 | if ( !(s && m) ) |
---|
| 519 | return -1; |
---|
| 520 | |
---|
| 521 | m->datalen = _ROAR_STREAM_MESSAGE_LEN; |
---|
| 522 | data = (uint32_t*) m->data; |
---|
| 523 | |
---|
| 524 | data[0] = s->dir; |
---|
| 525 | data[1] = s->pos_rel_id; |
---|
| 526 | data[2] = s->info.rate; |
---|
| 527 | data[3] = s->info.bits; |
---|
| 528 | data[4] = s->info.channels; |
---|
| 529 | data[5] = s->info.codec; |
---|
| 530 | |
---|
| 531 | for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++) |
---|
| 532 | data[i] = ROAR_HOST2NET32(data[i]); |
---|
| 533 | |
---|
| 534 | ROAR_DBG("roar_stream_s2m(*): s->info:"); |
---|
| 535 | roar_debug_audio_info_print(&s->info); |
---|
| 536 | |
---|
[964] | 537 | m->pos = s->pos; |
---|
| 538 | |
---|
[0] | 539 | return 0; |
---|
| 540 | } |
---|
| 541 | int roar_stream_m2s (struct roar_stream * s, struct roar_message * m) { |
---|
| 542 | uint32_t * data; |
---|
| 543 | int i; |
---|
| 544 | |
---|
| 545 | if ( !(s && m) ) |
---|
| 546 | return -1; |
---|
| 547 | |
---|
| 548 | if ( m->datalen != _ROAR_STREAM_MESSAGE_LEN ) |
---|
| 549 | return -1; |
---|
| 550 | |
---|
[964] | 551 | s->pos = m->pos; |
---|
| 552 | |
---|
[0] | 553 | data = (uint32_t*) m->data; |
---|
| 554 | |
---|
| 555 | for (i = 0; i < _ROAR_STREAM_MESSAGE_LEN/4; i++) |
---|
| 556 | data[i] = ROAR_NET2HOST32(data[i]); |
---|
| 557 | |
---|
[465] | 558 | s->id = m->stream; |
---|
[0] | 559 | s->dir = data[0]; |
---|
| 560 | s->pos_rel_id = data[1]; |
---|
| 561 | s->info.rate = data[2]; |
---|
| 562 | s->info.bits = data[3]; |
---|
| 563 | s->info.channels = data[4]; |
---|
| 564 | s->info.codec = data[5]; |
---|
| 565 | |
---|
| 566 | ROAR_DBG("roar_stream_m2s(*): s->info:"); |
---|
| 567 | roar_debug_audio_info_print(&s->info); |
---|
| 568 | |
---|
| 569 | return 0; |
---|
| 570 | } |
---|
| 571 | |
---|
[1807] | 572 | // stream direction funcs: |
---|
| 573 | /* |
---|
| 574 | #define roar_dir2str(x) ((x) == ROAR_DIR_PLAY ? "play" : (x) == ROAR_DIR_MONITOR ? "monitor" : \ |
---|
| 575 | (x) == ROAR_DIR_FILTER ? "filter" : (x) == ROAR_DIR_RECORD ? "record" : \ |
---|
| 576 | (x) == ROAR_DIR_OUTPUT ? "output" : (x) == ROAR_DIR_BIDIR ? "bidir" : \ |
---|
| 577 | (x) == ROAR_DIR_MIXING ? "mixing" : \ |
---|
| 578 | "unknown") |
---|
| 579 | */ |
---|
| 580 | |
---|
[2338] | 581 | struct { |
---|
| 582 | int dir; |
---|
| 583 | char * name; |
---|
| 584 | } _libroar_dir[] = { |
---|
[2681] | 585 | {ROAR_DIR_PLAY, "play" }, |
---|
| 586 | {ROAR_DIR_RECORD, "record" }, |
---|
| 587 | {ROAR_DIR_MONITOR, "monitor" }, |
---|
| 588 | {ROAR_DIR_FILTER, "filter" }, |
---|
| 589 | {ROAR_DIR_OUTPUT, "output" }, |
---|
| 590 | {ROAR_DIR_MIXING, "mixing" }, |
---|
| 591 | {ROAR_DIR_META, "meta" }, |
---|
| 592 | {ROAR_DIR_BIDIR, "bidir" }, |
---|
| 593 | {ROAR_DIR_THRU, "thru" }, |
---|
| 594 | {ROAR_DIR_BRIDGE, "bridge" }, |
---|
| 595 | {ROAR_DIR_MIDI_IN, "midi_in" }, |
---|
| 596 | {ROAR_DIR_MIDI_OUT, "midi_out" }, |
---|
| 597 | {ROAR_DIR_LIGHT_IN, "light_in" }, |
---|
| 598 | {ROAR_DIR_LIGHT_OUT, "light_out" }, |
---|
| 599 | {ROAR_DIR_RAW_IN, "raw_in" }, |
---|
| 600 | {ROAR_DIR_RAW_OUT, "raw_out" }, |
---|
| 601 | {ROAR_DIR_COMPLEX_IN, "complex_in" }, |
---|
| 602 | {ROAR_DIR_COMPLEX_OUT, "complex_out"}, |
---|
[2711] | 603 | {ROAR_DIR_RDTCS_IN, "rdtcs_in" }, |
---|
| 604 | {ROAR_DIR_RDTCS_OUT, "rdtcs_out" }, |
---|
[2681] | 605 | {-1, "unknown" } |
---|
[2338] | 606 | }; |
---|
| 607 | |
---|
[1807] | 608 | char * roar_dir2str (int dir) { |
---|
[2338] | 609 | int i; |
---|
| 610 | |
---|
| 611 | for (i = 0; _libroar_dir[i].dir != -1; i++) |
---|
| 612 | if ( _libroar_dir[i].dir == dir ) |
---|
| 613 | return _libroar_dir[i].name; |
---|
| 614 | |
---|
| 615 | return _libroar_dir[i].name; |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | int roar_str2dir (char * name) { |
---|
| 619 | int i; |
---|
| 620 | |
---|
| 621 | for (i = 0; _libroar_dir[i].dir != -1; i++) |
---|
| 622 | if ( !strcmp(_libroar_dir[i].name, name) ) |
---|
| 623 | return _libroar_dir[i].dir; |
---|
| 624 | |
---|
| 625 | return _libroar_dir[i].dir; |
---|
[1807] | 626 | } |
---|
[537] | 627 | |
---|
| 628 | // codec funcs: |
---|
| 629 | |
---|
| 630 | /* |
---|
| 631 | #define roar_codec2str(x) ((x) == ROAR_CODEC_PCM_S_LE ? "pcm_s_le" : (x) == ROAR_CODEC_PCM_S_BE ? "pcm_s_be" : \ |
---|
| 632 | (x) == ROAR_CODEC_PCM_S_PDP ? "pcm_s_pdp" : (x) == ROAR_CODEC_MIDI_FILE ? "midi_file" : \ |
---|
| 633 | "unknown" ) |
---|
| 634 | */ |
---|
| 635 | |
---|
| 636 | struct { |
---|
| 637 | int codec; |
---|
| 638 | char * name; |
---|
| 639 | } _libroar_codec[] = { |
---|
| 640 | // PCM: |
---|
| 641 | {ROAR_CODEC_PCM_S_LE, "pcm_s_le" }, |
---|
| 642 | {ROAR_CODEC_PCM_S_BE, "pcm_s_be" }, |
---|
| 643 | {ROAR_CODEC_PCM_S_PDP, "pcm_s_pdp" }, |
---|
| 644 | {ROAR_CODEC_PCM_U_LE, "pcm_u_le" }, |
---|
| 645 | {ROAR_CODEC_PCM_U_BE, "pcm_u_be" }, |
---|
| 646 | {ROAR_CODEC_PCM_U_PDP, "pcm_u_pdp" }, |
---|
| 647 | {ROAR_CODEC_DEFAULT, "default" }, // alias |
---|
| 648 | {ROAR_CODEC_DEFAULT, "pcm" }, // alias |
---|
[557] | 649 | {ROAR_CODEC_DEFAULT, "raw" }, // alias |
---|
[537] | 650 | |
---|
| 651 | // MIDI: |
---|
| 652 | {ROAR_CODEC_MIDI_FILE, "midi_file" }, |
---|
[1820] | 653 | {ROAR_CODEC_MIDI, "midi" }, |
---|
[537] | 654 | |
---|
| 655 | // XIPH: |
---|
| 656 | {ROAR_CODEC_OGG_VORBIS, "ogg_vorbis" }, |
---|
| 657 | {ROAR_CODEC_OGG_VORBIS, "vorbis" }, // alias |
---|
| 658 | {ROAR_CODEC_FLAC, "flac" }, |
---|
| 659 | {ROAR_CODEC_OGG_SPEEX, "ogg_speex" }, |
---|
| 660 | {ROAR_CODEC_OGG_SPEEX, "speex" }, // alias |
---|
| 661 | {ROAR_CODEC_OGG_FLAC, "ogg_flac" }, |
---|
| 662 | {ROAR_CODEC_OGG_GENERAL, "ogg_general"}, |
---|
[2681] | 663 | {ROAR_CODEC_OGG_CELT, "ogg_celt" }, |
---|
| 664 | {ROAR_CODEC_OGG, "ogg" }, |
---|
[537] | 665 | {ROAR_CODEC_ROAR_CELT, "roar_celt" }, |
---|
| 666 | {ROAR_CODEC_ROAR_SPEEX, "roar_speex" }, |
---|
[560] | 667 | |
---|
[881] | 668 | // RAUM: |
---|
| 669 | {ROAR_CODEC_RAUM, "raum" }, |
---|
| 670 | {ROAR_CODEC_RAUM_VORBIS, "raum_vorbis"}, |
---|
[2332] | 671 | {ROAR_CODEC_RAUM_FLAC, "raum_flac" }, |
---|
[881] | 672 | |
---|
[560] | 673 | // RIFF/WAVE like: |
---|
| 674 | {ROAR_CODEC_RIFF_WAVE, "riff_wave" }, |
---|
| 675 | {ROAR_CODEC_RIFF_WAVE, "wave" }, // alias |
---|
| 676 | {ROAR_CODEC_RIFF_WAVE, "wav" }, // alias |
---|
| 677 | |
---|
[733] | 678 | //Log codecs: |
---|
| 679 | {ROAR_CODEC_ALAW, "alaw" }, |
---|
| 680 | {ROAR_CODEC_MULAW, "mulaw" }, |
---|
| 681 | {ROAR_CODEC_MULAW, "ulaw" }, // alias |
---|
| 682 | |
---|
[1211] | 683 | // Meta Codecs: |
---|
| 684 | {ROAR_CODEC_META_VCLT, "meta_vclt" }, |
---|
| 685 | {ROAR_CODEC_META_RALT, "meta_ralt" }, |
---|
| 686 | {ROAR_CODEC_META_RALB, "meta_ralb" }, |
---|
| 687 | {ROAR_CODEC_META_RALB_LE, "meta_ralb_le" }, |
---|
| 688 | {ROAR_CODEC_META_RALB_BE, "meta_ralb_be" }, |
---|
| 689 | {ROAR_CODEC_META_RALB_PDP, "meta_ralb_pdp"}, |
---|
| 690 | |
---|
[1820] | 691 | // light control: |
---|
| 692 | {ROAR_CODEC_DMX512, "dmx512" }, |
---|
[1963] | 693 | {ROAR_CODEC_ROARDMX, "roardmx" }, |
---|
[1820] | 694 | |
---|
[2709] | 695 | // Radio Data and Transmitter Control System: |
---|
| 696 | {ROAR_CODEC_RDS, "rds" }, |
---|
| 697 | |
---|
| 698 | // User specific: |
---|
| 699 | {ROAR_CODEC_USER0, "user0" }, |
---|
| 700 | {ROAR_CODEC_USER1, "user1" }, |
---|
| 701 | {ROAR_CODEC_USER2, "user2" }, |
---|
| 702 | {ROAR_CODEC_USER3, "user3" }, |
---|
| 703 | {ROAR_CODEC_USER4, "user4" }, |
---|
| 704 | {ROAR_CODEC_USER5, "user5" }, |
---|
| 705 | {ROAR_CODEC_USER6, "user6" }, |
---|
| 706 | {ROAR_CODEC_USER7, "user7" }, |
---|
| 707 | {ROAR_CODEC_USER8, "user8" }, |
---|
| 708 | {ROAR_CODEC_USER9, "user9" }, |
---|
| 709 | {ROAR_CODEC_USER10, "user10" }, |
---|
| 710 | {ROAR_CODEC_USER11, "user11" }, |
---|
| 711 | {ROAR_CODEC_USER12, "user12" }, |
---|
| 712 | {ROAR_CODEC_USER13, "user13" }, |
---|
| 713 | {ROAR_CODEC_USER14, "user14" }, |
---|
| 714 | {ROAR_CODEC_USER15, "user15" }, |
---|
[537] | 715 | {-1, NULL} |
---|
| 716 | }; |
---|
| 717 | |
---|
| 718 | int roar_str2codec(char * codec) { |
---|
| 719 | int i; |
---|
[549] | 720 | int guess; |
---|
[537] | 721 | |
---|
[549] | 722 | if ( codec == NULL || *codec == 0 ) |
---|
| 723 | return ROAR_CODEC_DEFAULT; |
---|
| 724 | |
---|
| 725 | if ( (guess = atoi(codec)) > 0 ) |
---|
[537] | 726 | return guess; |
---|
| 727 | |
---|
| 728 | if ( codec == NULL || *codec == 0 ) |
---|
| 729 | return ROAR_CODEC_DEFAULT; |
---|
| 730 | |
---|
| 731 | for (i = 0; _libroar_codec[i].codec != -1; i++) |
---|
| 732 | if ( strcasecmp(_libroar_codec[i].name, codec) == 0 ) |
---|
| 733 | return _libroar_codec[i].codec; |
---|
| 734 | |
---|
| 735 | return -1; |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | |
---|
| 739 | char * roar_codec2str (int codec) { |
---|
| 740 | int i; |
---|
| 741 | |
---|
| 742 | for (i = 0; _libroar_codec[i].codec != -1; i++) |
---|
| 743 | if ( _libroar_codec[i].codec == codec ) |
---|
| 744 | return _libroar_codec[i].name; |
---|
| 745 | |
---|
| 746 | return "unknown"; |
---|
| 747 | } |
---|
| 748 | |
---|
[2633] | 749 | char * roar_streamstate2str(int streamstate) { |
---|
| 750 | switch (streamstate) { |
---|
| 751 | case ROAR_STREAMSTATE_UNUSED: return "unused"; break; |
---|
| 752 | case ROAR_STREAMSTATE_INITING: return "initing"; break; |
---|
| 753 | case ROAR_STREAMSTATE_NEW: return "new"; break; |
---|
| 754 | case ROAR_STREAMSTATE_OLD: return "old"; break; |
---|
| 755 | case ROAR_STREAMSTATE_CLOSING: return "closing"; break; |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | return "unknown"; |
---|
| 759 | } |
---|
| 760 | |
---|
[0] | 761 | //ll |
---|