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