[0] | 1 | //streams.c: |
---|
| 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 | */ |
---|
| 24 | |
---|
[0] | 25 | #include "roard.h" |
---|
| 26 | |
---|
[2734] | 27 | #define _CHECK_SID_RET(id,ret) if ( (id) < 0 || (id) > ROAR_STREAMS_MAX || g_streams[(id)] == NULL ) return (ret) |
---|
| 28 | #define _CHECK_SID(id) _CHECK_SID_RET((id), -1) |
---|
| 29 | |
---|
[2417] | 30 | int streams_thru_num = 0; |
---|
| 31 | int streams_recsource_id = -1; |
---|
[2254] | 32 | |
---|
[0] | 33 | int streams_init (void) { |
---|
| 34 | int i; |
---|
| 35 | |
---|
| 36 | for (i = 0; i < ROAR_STREAMS_MAX; i++) |
---|
| 37 | g_streams[i] = NULL; |
---|
| 38 | |
---|
| 39 | return 0; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | int streams_free (void) { |
---|
| 43 | int i; |
---|
| 44 | |
---|
| 45 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 46 | if ( g_streams[i] != NULL ) { |
---|
| 47 | streams_delete(i); |
---|
| 48 | } |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | return 0; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | int streams_new (void) { |
---|
[16] | 56 | int i, j; |
---|
[494] | 57 | struct roar_stream * n = NULL; |
---|
| 58 | struct roar_stream_server * s = NULL; |
---|
[0] | 59 | |
---|
[1498] | 60 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 61 | if ( g_terminate && !g_no_listen ) // don't accept new streams in case of termination state |
---|
[1148] | 62 | return -1; |
---|
[1498] | 63 | #else |
---|
| 64 | if ( g_terminate ) // don't accept new streams in case of termination state |
---|
| 65 | return -1; |
---|
| 66 | #endif |
---|
[1148] | 67 | |
---|
[0] | 68 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 69 | if ( g_streams[i] == NULL ) { |
---|
[494] | 70 | s = ROAR_STREAM_SERVER(n = ROAR_STREAM(malloc(sizeof(struct roar_stream_server)))); |
---|
[0] | 71 | if ( n == NULL ) { |
---|
| 72 | ROAR_ERR("streams_new(void): can not allocate memory for new stream: %s", strerror(errno)); |
---|
| 73 | ROAR_DBG("streams_new(void) = -1"); |
---|
| 74 | return -1; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | n->id = i; |
---|
| 78 | n->fh = -1; |
---|
[2714] | 79 | n->pos_rel_id = -1; |
---|
[1804] | 80 | /* |
---|
[0] | 81 | n->database = NULL; |
---|
| 82 | n->dataoff = NULL; |
---|
| 83 | n->datalen = 0; |
---|
| 84 | n->offset = 0; |
---|
[1804] | 85 | */ |
---|
[381] | 86 | n->pos = 0; |
---|
[0] | 87 | |
---|
[1842] | 88 | s->name = NULL; |
---|
| 89 | |
---|
[2611] | 90 | s->state = ROAR_STREAMSTATE_INITING; |
---|
| 91 | |
---|
[494] | 92 | s->client = -1; |
---|
| 93 | s->socktype = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
| 94 | s->buffer = NULL; |
---|
| 95 | s->need_extra = 0; |
---|
| 96 | s->output = NULL; |
---|
| 97 | s->is_new = 1; |
---|
| 98 | s->codecfilter = -1; |
---|
[538] | 99 | s->pre_underruns = 0; |
---|
| 100 | s->post_underruns = 0; |
---|
[1137] | 101 | s->delay = 0; |
---|
[538] | 102 | s->codec_orgi = -1; |
---|
[643] | 103 | s->primary = 0; |
---|
[1913] | 104 | s->ready = 0; |
---|
[2151] | 105 | s->outputbuffer = NULL; |
---|
[2816] | 106 | s->prethru = NULL; |
---|
[494] | 107 | |
---|
| 108 | s->mixer.scale = 65535; |
---|
| 109 | s->mixer.rpg_mul = 1; |
---|
| 110 | s->mixer.rpg_div = 1; |
---|
[16] | 111 | for (j = 0; j < ROAR_MAX_CHANNELS; j++) |
---|
[494] | 112 | s->mixer.mixer[j] = 65535; |
---|
| 113 | |
---|
[1498] | 114 | #ifdef ROAR_SUPPORT_META |
---|
[90] | 115 | for (j = 0; j < ROAR_META_MAX_PER_STREAM; j++) { |
---|
[494] | 116 | s->meta[j].type = ROAR_META_TYPE_NONE; |
---|
| 117 | s->meta[j].key[0] = 0; |
---|
| 118 | s->meta[j].value = NULL; |
---|
[90] | 119 | } |
---|
[1498] | 120 | #endif |
---|
[0] | 121 | |
---|
[592] | 122 | roar_vio_init_calls(&(s->vio)); |
---|
[930] | 123 | s->driver_id = -1; |
---|
[1030] | 124 | s->flags = ROAR_FLAG_NONE; |
---|
[592] | 125 | |
---|
[1857] | 126 | //roardsp_fchain_init(&(s->fc)); |
---|
[981] | 127 | |
---|
[494] | 128 | g_streams[i] = s; |
---|
[491] | 129 | ROAR_DBG("streams_new(void): n->id=%i", n->id); |
---|
[0] | 130 | ROAR_DBG("streams_new(void) = %i", i); |
---|
| 131 | return i; |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | return -1; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | int streams_delete (int id) { |
---|
[643] | 139 | struct roar_stream_server * s; |
---|
[645] | 140 | int prim; |
---|
[1245] | 141 | int no_vio_close = 0; |
---|
[1836] | 142 | int i; |
---|
[2609] | 143 | int client; |
---|
[645] | 144 | |
---|
[2734] | 145 | _CHECK_SID(id); |
---|
| 146 | |
---|
[643] | 147 | if ( (s = g_streams[id]) == NULL ) |
---|
[0] | 148 | return 0; |
---|
| 149 | |
---|
| 150 | ROAR_DBG("streams_delete(id=%i) = ?", id); |
---|
[643] | 151 | ROAR_DBG("streams_delete(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(s)->id); |
---|
[0] | 152 | |
---|
[2611] | 153 | // in case we are allready closing it... |
---|
| 154 | if ( s->state == ROAR_STREAMSTATE_CLOSING ) |
---|
| 155 | return 0; |
---|
| 156 | |
---|
| 157 | s->state = ROAR_STREAMSTATE_CLOSING; |
---|
| 158 | |
---|
[2417] | 159 | if ( streams_get_flag(id, ROAR_FLAG_RECSOURCE) == 1 ) |
---|
| 160 | streams_reset_flag(id, ROAR_FLAG_RECSOURCE); |
---|
| 161 | |
---|
[1836] | 162 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 163 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == id ) { |
---|
[2239] | 164 | switch (ROAR_STREAM(g_streams[i])->dir) { |
---|
| 165 | case ROAR_DIR_THRU: |
---|
| 166 | case ROAR_DIR_RAW_IN: |
---|
[2592] | 167 | if ( i != id ) |
---|
| 168 | streams_delete(i); |
---|
[2239] | 169 | break; |
---|
| 170 | default: |
---|
[2592] | 171 | if ( streams_get_flag(i, ROAR_FLAG_VIRTUAL) == 1 ) { |
---|
[2609] | 172 | if ( i != id ) { |
---|
| 173 | ROAR_DBG("streams_delete(id=%i): Deleting virtual child stream %i", id, i); |
---|
[2592] | 174 | streams_delete(i); |
---|
[2609] | 175 | } |
---|
[2592] | 176 | } else { |
---|
| 177 | ROAR_STREAM(g_streams[i])->pos_rel_id = -1; |
---|
| 178 | } |
---|
[1836] | 179 | } |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
[2255] | 183 | if ( ROAR_STREAM(s)->dir == ROAR_DIR_THRU ) |
---|
| 184 | streams_thru_num--; |
---|
| 185 | |
---|
[2603] | 186 | if ( streams_get_flag(id, ROAR_FLAG_VIRTUAL) == 1 ) { |
---|
[2605] | 187 | // we un-group the stream here to avoid a client deleting the parent deleting the client deleting ... |
---|
[2609] | 188 | i = ROAR_STREAM(s)->pos_rel_id; |
---|
| 189 | if ( i != -1 ) { |
---|
| 190 | ROAR_STREAM(s)->pos_rel_id = -1; |
---|
| 191 | client = streams_get_client(id); |
---|
| 192 | streams_set_client(id, -1); |
---|
| 193 | ROAR_DBG("streams_delete(id=%i): Stream has flag virtual, notifying parent stream %i", id, i); |
---|
[2612] | 194 | streams_ctl(i, ROAR_CODECFILTER_CTL_VIRTUAL_DELETE|ROAR_STREAM_CTL_TYPE_INT, &id); |
---|
[2609] | 195 | ROAR_DBG("streams_delete(id=%i): Notify send to stream %i", id, i); |
---|
| 196 | streams_set_client(id, client); |
---|
| 197 | ROAR_STREAM(s)->pos_rel_id = i; |
---|
| 198 | } |
---|
[2603] | 199 | } |
---|
| 200 | |
---|
[1498] | 201 | #ifdef ROAR_SUPPORT_META |
---|
[1045] | 202 | // delete meta data form other meta streams if needed |
---|
| 203 | if ( streams_get_flag(id, ROAR_FLAG_META) == 1 ) { |
---|
| 204 | ROAR_DBG("streams_delete(id=%i): deleting meta stream!", id); |
---|
| 205 | stream_meta_clear(id); |
---|
| 206 | stream_meta_finalize(id); |
---|
| 207 | } |
---|
[1498] | 208 | #endif |
---|
[1045] | 209 | |
---|
[643] | 210 | if ( s->codecfilter != -1 ) { |
---|
| 211 | codecfilter_close(s->codecfilter_inst, s->codecfilter); |
---|
| 212 | s->codecfilter_inst = NULL; |
---|
| 213 | s->codecfilter = -1; |
---|
| 214 | } |
---|
| 215 | |
---|
[936] | 216 | if ( s->driver_id != -1 ) { |
---|
[937] | 217 | driver_closevio(&(s->vio), s->driver_id); |
---|
[936] | 218 | roar_vio_init_calls(&(s->vio)); |
---|
| 219 | s->driver_id = -1; |
---|
[1245] | 220 | no_vio_close = 1; |
---|
[936] | 221 | } |
---|
| 222 | |
---|
[1857] | 223 | //roardsp_fchain_uninit(&(s->fc)); |
---|
[981] | 224 | |
---|
[643] | 225 | if ( s->client != -1 ) { |
---|
| 226 | ROAR_DBG("streams_delete(id=%i): Stream is owned by client %i", id, g_streams[id]->client); |
---|
| 227 | client_stream_delete(s->client, id); |
---|
[269] | 228 | } |
---|
| 229 | |
---|
[2151] | 230 | stream_outputbuffer_destroy(id); |
---|
[2816] | 231 | stream_prethru_destroy(id); |
---|
[2151] | 232 | |
---|
[643] | 233 | if ( s->buffer != NULL ) |
---|
| 234 | roar_buffer_free(s->buffer); |
---|
| 235 | |
---|
| 236 | if ( s->output != NULL ) |
---|
| 237 | free(s->output); |
---|
| 238 | |
---|
[1243] | 239 | /* |
---|
[643] | 240 | if ( ROAR_STREAM(s)->fh != -1 ) |
---|
| 241 | close(ROAR_STREAM(s)->fh); |
---|
[1243] | 242 | */ |
---|
| 243 | |
---|
[1245] | 244 | if ( !no_vio_close ) |
---|
| 245 | roar_vio_close(&(s->vio)); |
---|
[643] | 246 | |
---|
[645] | 247 | prim = s->primary; |
---|
[0] | 248 | |
---|
[1842] | 249 | if ( s->name != NULL ) |
---|
| 250 | free(s->name); |
---|
| 251 | |
---|
[643] | 252 | free(s); |
---|
[0] | 253 | |
---|
| 254 | g_streams[id] = NULL; |
---|
| 255 | |
---|
[645] | 256 | if ( prim ) { |
---|
| 257 | alive = 0; |
---|
| 258 | clean_quit(); |
---|
| 259 | } |
---|
| 260 | |
---|
[0] | 261 | ROAR_DBG("streams_delete(id=%i) = 0", id); |
---|
| 262 | return 0; |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | int streams_set_client (int id, int client) { |
---|
[2734] | 266 | |
---|
| 267 | _CHECK_SID(id); |
---|
[0] | 268 | |
---|
[491] | 269 | ROAR_DBG("streams_set_client(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(g_streams[id])->id); |
---|
[0] | 270 | g_streams[id]->client = client; |
---|
| 271 | |
---|
| 272 | return 0; |
---|
| 273 | } |
---|
| 274 | |
---|
[766] | 275 | int streams_get_client (int id) { |
---|
[2734] | 276 | _CHECK_SID(id); |
---|
[766] | 277 | |
---|
| 278 | return g_streams[id]->client; |
---|
| 279 | } |
---|
| 280 | |
---|
[1609] | 281 | int streams_set_dir (int id, int dir, int defaults) { |
---|
| 282 | struct roar_stream_server * ss; |
---|
| 283 | |
---|
[2734] | 284 | _CHECK_SID(id); |
---|
| 285 | |
---|
[1609] | 286 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 287 | return -1; |
---|
| 288 | |
---|
| 289 | ROAR_STREAM(ss)->dir = dir; |
---|
| 290 | |
---|
[2255] | 291 | if ( dir == ROAR_DIR_THRU ) |
---|
| 292 | streams_thru_num++; |
---|
| 293 | |
---|
[1609] | 294 | if ( defaults ) { |
---|
| 295 | if ( dir <= 0 || dir >= ROAR_DIR_DIRIDS ) |
---|
| 296 | return -1; |
---|
| 297 | |
---|
[2387] | 298 | ROAR_DBG("streams_set_dir(*): g_config->streams[dir=%i].flags = 0x%.4x", dir, g_config->streams[dir].flags); |
---|
[1906] | 299 | |
---|
| 300 | if ( streams_set_flag(id, g_config->streams[dir].flags) == -1 ) { |
---|
| 301 | ROAR_DBG("streams_set_dir(*) = -1 // can not set stream flags"); |
---|
[1609] | 302 | return -1; |
---|
[1906] | 303 | } |
---|
[1609] | 304 | |
---|
| 305 | ss->mixer.scale = g_config->streams[dir].mixer.scale; |
---|
| 306 | ss->mixer.rpg_mul = g_config->streams[dir].mixer.rpg_mul; |
---|
| 307 | ss->mixer.rpg_div = g_config->streams[dir].mixer.rpg_div; |
---|
| 308 | } |
---|
| 309 | |
---|
[1906] | 310 | ROAR_DBG("streams_set_dir(*) = 0"); |
---|
[1609] | 311 | return 0; |
---|
| 312 | } |
---|
[766] | 313 | |
---|
[2251] | 314 | int streams_get_dir (int id) { |
---|
| 315 | struct roar_stream_server * ss; |
---|
| 316 | |
---|
[2734] | 317 | _CHECK_SID(id); |
---|
| 318 | |
---|
[2251] | 319 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 320 | return -1; |
---|
| 321 | |
---|
| 322 | return ROAR_STREAM(ss)->dir; |
---|
| 323 | } |
---|
| 324 | |
---|
[2415] | 325 | int streams_get_subsys (int id) { |
---|
| 326 | struct roar_stream_server * ss; |
---|
| 327 | |
---|
[2734] | 328 | _CHECK_SID(id); |
---|
| 329 | |
---|
[2415] | 330 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 331 | return -1; |
---|
| 332 | |
---|
| 333 | switch (ROAR_STREAM(ss)->dir) { |
---|
| 334 | case ROAR_DIR_PLAY: |
---|
| 335 | case ROAR_DIR_RECORD: |
---|
| 336 | case ROAR_DIR_MONITOR: |
---|
| 337 | case ROAR_DIR_FILTER: |
---|
| 338 | case ROAR_DIR_OUTPUT: |
---|
| 339 | case ROAR_DIR_BIDIR: |
---|
| 340 | return ROAR_SUBSYS_WAVEFORM; |
---|
| 341 | break; |
---|
| 342 | case ROAR_DIR_MIDI_IN: |
---|
| 343 | case ROAR_DIR_MIDI_OUT: |
---|
| 344 | return ROAR_SUBSYS_MIDI; |
---|
| 345 | break; |
---|
| 346 | case ROAR_DIR_LIGHT_IN: |
---|
| 347 | case ROAR_DIR_LIGHT_OUT: |
---|
| 348 | return ROAR_SUBSYS_LIGHT; |
---|
| 349 | break; |
---|
| 350 | case ROAR_DIR_RAW_IN: |
---|
| 351 | case ROAR_DIR_RAW_OUT: |
---|
| 352 | return ROAR_SUBSYS_RAW; |
---|
| 353 | break; |
---|
[2681] | 354 | case ROAR_DIR_COMPLEX_IN: |
---|
| 355 | case ROAR_DIR_COMPLEX_OUT: |
---|
| 356 | return ROAR_SUBSYS_COMPLEX; |
---|
| 357 | break; |
---|
[2415] | 358 | case ROAR_DIR_THRU: |
---|
| 359 | return streams_get_subsys(ROAR_STREAM(ss)->pos_rel_id); |
---|
| 360 | break; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | return -1; |
---|
| 364 | } |
---|
| 365 | |
---|
[2593] | 366 | #define _err() streams_delete(id); return -1; |
---|
[2594] | 367 | int streams_new_virtual (int parent, struct roar_stream_server ** stream) { |
---|
[2593] | 368 | struct roar_stream_server * parent_ss, * ss; |
---|
| 369 | struct roar_stream * parent_s , * s; |
---|
| 370 | int id = -1; |
---|
| 371 | int client, dir; |
---|
| 372 | |
---|
| 373 | if ( streams_get(parent, &parent_ss) == -1 ) |
---|
| 374 | return -1; |
---|
| 375 | |
---|
| 376 | if ( (client = streams_get_client(parent)) == -1 ) |
---|
| 377 | return -1; |
---|
| 378 | |
---|
| 379 | if ( (dir = streams_get_dir(parent)) == -1 ) |
---|
| 380 | return -1; |
---|
| 381 | |
---|
| 382 | if ( (id = streams_new()) == -1 ) { |
---|
| 383 | return -1; |
---|
| 384 | } |
---|
| 385 | |
---|
[2597] | 386 | if ( client_stream_add(client, id) == -1 ) { |
---|
[2593] | 387 | _err(); |
---|
| 388 | } |
---|
| 389 | |
---|
| 390 | if ( streams_get(id, &ss) == -1 ) { |
---|
| 391 | _err(); |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | if ( streams_set_dir(id, dir, 1) == -1 ) { |
---|
| 395 | _err(); |
---|
| 396 | } |
---|
| 397 | |
---|
| 398 | s = ROAR_STREAM( ss); |
---|
| 399 | parent_s = ROAR_STREAM(parent_ss); |
---|
| 400 | |
---|
[2596] | 401 | s->pos_rel_id = parent; |
---|
[2593] | 402 | |
---|
[2625] | 403 | if ( streams_set_rawflag(id, ROAR_FLAG_VIRTUAL) == -1 ) { |
---|
[2593] | 404 | _err(); |
---|
| 405 | } |
---|
| 406 | |
---|
[2596] | 407 | if ( stream != NULL ) |
---|
[2594] | 408 | *stream = ss; |
---|
| 409 | |
---|
[2593] | 410 | return id; |
---|
| 411 | } |
---|
| 412 | #undef _err |
---|
| 413 | |
---|
[0] | 414 | int streams_set_fh (int id, int fh) { |
---|
[1243] | 415 | struct roar_stream_server * ss; |
---|
[1913] | 416 | struct roar_stream * s; |
---|
[51] | 417 | int dir; |
---|
[2361] | 418 | int nonblock = 1; |
---|
[51] | 419 | |
---|
[2734] | 420 | _CHECK_SID(id); |
---|
| 421 | |
---|
[1913] | 422 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
[0] | 423 | return -1; |
---|
| 424 | |
---|
[2816] | 425 | dir = ROAR_STREAM(ss)->dir; |
---|
| 426 | |
---|
[1913] | 427 | ROAR_DBG("streams_set_fh(id=%i): g_streams[id]->id=%i", id, s->id); |
---|
[491] | 428 | |
---|
[1913] | 429 | s->fh = fh; |
---|
[0] | 430 | |
---|
[1243] | 431 | ROAR_DBG("streams_set_fh(id=%i, fh=%i): driverID=%i", id, fh, ss->driver_id); |
---|
| 432 | |
---|
[2766] | 433 | if ( ss->driver_id == -1 && fh != -2 ) { |
---|
| 434 | #ifndef ROAR_TARGET_WIN32 |
---|
[1243] | 435 | roar_vio_set_fh(&(ss->vio), fh); |
---|
[2766] | 436 | #else |
---|
| 437 | roar_vio_open_fh_socket(&(ss->vio), fh); |
---|
| 438 | #endif |
---|
| 439 | } |
---|
[1243] | 440 | |
---|
[2816] | 441 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 442 | |
---|
| 443 | if ( dir != ROAR_DIR_THRU ) { |
---|
| 444 | if ( codecfilter_open(&(ss->codecfilter_inst), &(ss->codecfilter), NULL, |
---|
| 445 | s->info.codec, ss) == -1 ) { |
---|
| 446 | return streams_delete(id); // TODO: FIXME: is this correct? shoudn't we return -1 in any case here? |
---|
| 447 | } |
---|
[571] | 448 | } |
---|
[268] | 449 | |
---|
[2816] | 450 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 451 | |
---|
[1610] | 452 | if ( fh == -2 ) { |
---|
| 453 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 454 | if ( roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_GET_READ_FH, &fh) == -1 ) { |
---|
| 455 | fh = -2; |
---|
| 456 | } else { |
---|
| 457 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 458 | if ( fh < 0 ) { |
---|
| 459 | fh = -2; |
---|
| 460 | } else { |
---|
[1913] | 461 | s->fh = fh; |
---|
[1610] | 462 | } |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
[2816] | 466 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 467 | |
---|
[1610] | 468 | if ( fh == -1 || fh == -2 ) { // yes, this is valid, indecats full vio! |
---|
[1913] | 469 | ss->ready = 1; |
---|
[2613] | 470 | ss->state = ROAR_STREAMSTATE_NEW; |
---|
[634] | 471 | return 0; |
---|
| 472 | } |
---|
| 473 | |
---|
[2816] | 474 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
[968] | 475 | |
---|
[2816] | 476 | // roar_socket_recvbuf(fh, ROAR_OUTPUT_CALC_OUTBUFSIZE( &(ROAR_STREAM(g_streams[id])->info) )); // set recv buffer to minimum |
---|
[51] | 477 | |
---|
[1912] | 478 | switch (dir) { |
---|
| 479 | case ROAR_DIR_MONITOR: |
---|
| 480 | case ROAR_DIR_RECORD: |
---|
| 481 | case ROAR_DIR_OUTPUT: |
---|
| 482 | case ROAR_DIR_MIDI_OUT: |
---|
| 483 | case ROAR_DIR_LIGHT_OUT: |
---|
[2248] | 484 | case ROAR_DIR_RAW_OUT: |
---|
[1912] | 485 | ROAR_SHUTDOWN(fh, SHUT_RD); |
---|
| 486 | break; |
---|
[51] | 487 | } |
---|
| 488 | |
---|
[2337] | 489 | if ( dir >= ROAR_DIR_DIRIDS ) |
---|
| 490 | return -1; |
---|
| 491 | |
---|
| 492 | if ( g_config->streams[dir].flags & ROAR_FLAG_SYNC ) { |
---|
[2361] | 493 | switch (dir) { |
---|
| 494 | case ROAR_DIR_BRIDGE: |
---|
| 495 | case ROAR_DIR_MIDI_OUT: |
---|
| 496 | break; |
---|
| 497 | default: |
---|
| 498 | nonblock = 0; |
---|
| 499 | break; |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | |
---|
| 504 | if ( !nonblock ) { |
---|
[1913] | 505 | ss->ready = 1; |
---|
[2613] | 506 | ss->state = ROAR_STREAMSTATE_NEW; |
---|
[2816] | 507 | |
---|
| 508 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); |
---|
[0] | 509 | return 0; |
---|
| 510 | } else { |
---|
[2764] | 511 | #ifndef ROAR_TARGET_WIN32 |
---|
[1913] | 512 | if ( roar_socket_nonblock(fh, ROAR_SOCKET_NONBLOCK) == -1 ) |
---|
| 513 | return -1; |
---|
[2764] | 514 | #endif |
---|
[1913] | 515 | |
---|
| 516 | ss->ready = 1; |
---|
[2613] | 517 | ss->state = ROAR_STREAMSTATE_NEW; |
---|
[2816] | 518 | |
---|
| 519 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); |
---|
[1913] | 520 | return 0; |
---|
[0] | 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
[66] | 524 | int streams_get_fh (int id) { |
---|
[2734] | 525 | _CHECK_SID(id); |
---|
[66] | 526 | |
---|
[609] | 527 | return ROAR_STREAM(g_streams[id])->fh; |
---|
[66] | 528 | } |
---|
[0] | 529 | |
---|
[2606] | 530 | int streams_set_null_io(int id) { |
---|
| 531 | struct roar_stream_server * ss; |
---|
| 532 | struct roar_stream * s; |
---|
| 533 | |
---|
[2734] | 534 | _CHECK_SID(id); |
---|
| 535 | |
---|
[2606] | 536 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
| 537 | return -1; |
---|
| 538 | |
---|
| 539 | s->fh = -1; |
---|
| 540 | |
---|
| 541 | return 0; |
---|
| 542 | } |
---|
| 543 | |
---|
[0] | 544 | int streams_get (int id, struct roar_stream_server ** stream) { |
---|
[2734] | 545 | _CHECK_SID(id); |
---|
[0] | 546 | |
---|
| 547 | *stream = g_streams[id]; |
---|
| 548 | |
---|
| 549 | return 0; |
---|
| 550 | } |
---|
| 551 | |
---|
[377] | 552 | int streams_set_socktype (int id, int socktype) { |
---|
[2734] | 553 | _CHECK_SID(id); |
---|
[377] | 554 | |
---|
| 555 | g_streams[id]->socktype = socktype; |
---|
| 556 | |
---|
| 557 | return 0; |
---|
| 558 | } |
---|
| 559 | |
---|
| 560 | int streams_get_socktype (int id) { |
---|
[2734] | 561 | _CHECK_SID(id); |
---|
[377] | 562 | |
---|
| 563 | return g_streams[id]->socktype; |
---|
| 564 | } |
---|
[0] | 565 | |
---|
[643] | 566 | int streams_set_primary (int id, int prim) { |
---|
[2734] | 567 | _CHECK_SID(id); |
---|
[643] | 568 | |
---|
| 569 | g_streams[id]->primary = prim; |
---|
| 570 | |
---|
| 571 | return 0; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | int streams_mark_primary (int id) { |
---|
| 575 | return streams_set_primary(id, 1); |
---|
| 576 | } |
---|
[1029] | 577 | |
---|
[1116] | 578 | int streams_set_sync (int id, int sync) { |
---|
[1117] | 579 | int fh = streams_get_fh(id); |
---|
[1116] | 580 | |
---|
[2734] | 581 | _CHECK_SID(id); |
---|
| 582 | |
---|
[1117] | 583 | if ( fh != -1 ) { |
---|
| 584 | if ( roar_socket_nonblock(fh, sync ? ROAR_SOCKET_BLOCK : ROAR_SOCKET_NONBLOCK) == -1 ) |
---|
| 585 | return -1; |
---|
[1116] | 586 | |
---|
[1498] | 587 | #ifdef ROAR_FDATASYNC |
---|
[1171] | 588 | ROAR_FDATASYNC(fh); |
---|
[1498] | 589 | #endif |
---|
[1125] | 590 | |
---|
| 591 | return 0; |
---|
[1117] | 592 | } else { |
---|
| 593 | return roar_vio_nonblock(&(g_streams[id]->vio), sync); |
---|
| 594 | } |
---|
[1116] | 595 | } |
---|
| 596 | |
---|
[1928] | 597 | int streams_set_mmap (int id, int reset) { |
---|
| 598 | int use = !reset; |
---|
| 599 | |
---|
[2734] | 600 | _CHECK_SID(id); |
---|
[1928] | 601 | |
---|
| 602 | return roar_vio_ctl(&(g_streams[id]->vio), ROAR_VIO_CTL_SET_UMMAP, &use); |
---|
| 603 | } |
---|
| 604 | |
---|
[1029] | 605 | int streams_set_flag (int id, int flag) { |
---|
[2626] | 606 | int parent; |
---|
| 607 | |
---|
[2734] | 608 | _CHECK_SID(id); |
---|
[1029] | 609 | |
---|
[1926] | 610 | if ( flag & ROAR_FLAG_MMAP ) |
---|
[1928] | 611 | if ( streams_set_mmap(id, 0) == -1 ) |
---|
| 612 | flag -= ROAR_FLAG_MMAP; |
---|
[1926] | 613 | |
---|
[1043] | 614 | if ( flag & ROAR_FLAG_PRIMARY ) { |
---|
| 615 | streams_set_primary(id, 1); |
---|
| 616 | flag -= ROAR_FLAG_PRIMARY; |
---|
| 617 | } |
---|
| 618 | |
---|
[2626] | 619 | if ( flag & ROAR_FLAG_VIRTUAL ) { |
---|
| 620 | if ( (parent = ROAR_STREAM(g_streams[id])->pos_rel_id) == -1 ) |
---|
| 621 | return -1; |
---|
| 622 | |
---|
| 623 | if ( streams_ctl(parent, ROAR_CODECFILTER_CTL_VIRTUAL_NEW|ROAR_STREAM_CTL_TYPE_INT, &id) == -1 ) { |
---|
| 624 | // flag -= ROAR_FLAG_VIRTUAL; |
---|
| 625 | return -1; |
---|
| 626 | } |
---|
[2705] | 627 | |
---|
| 628 | if ( client_stream_move(streams_get_client(parent), id) == -1 ) { |
---|
| 629 | return -1; |
---|
| 630 | } |
---|
[2626] | 631 | } |
---|
| 632 | |
---|
[1116] | 633 | if ( flag & ROAR_FLAG_SYNC ) { |
---|
[1908] | 634 | switch (ROAR_STREAM(g_streams[id])->dir) { |
---|
| 635 | // for this stream types the flag is used in the subsystem: |
---|
| 636 | case ROAR_DIR_BRIDGE: |
---|
| 637 | case ROAR_DIR_MIDI_OUT: |
---|
| 638 | break; |
---|
| 639 | |
---|
| 640 | // normal behavor (vio blocking): |
---|
| 641 | default: |
---|
[2341] | 642 | // the fh is updated as soon as the fh get ready in case the default ask to set sync |
---|
[2342] | 643 | if ( !g_streams[id]->ready && !(g_config->streams[ROAR_STREAM(g_streams[id])->dir].flags & ROAR_FLAG_SYNC) ) { |
---|
[2341] | 644 | if ( streams_set_sync(id, 1) == -1 ) |
---|
| 645 | flag -= ROAR_FLAG_SYNC; |
---|
| 646 | } |
---|
[1908] | 647 | } |
---|
[1116] | 648 | } |
---|
| 649 | |
---|
[1585] | 650 | if ( flag & ROAR_FLAG_HWMIXER ) { // currently not supported -> ignored |
---|
[1590] | 651 | g_streams[id]->flags |= flag; |
---|
| 652 | if ( streams_set_mixer(id) == -1 ) { |
---|
| 653 | g_streams[id]->flags -= flag; |
---|
| 654 | return -1; |
---|
| 655 | } |
---|
[1585] | 656 | } |
---|
| 657 | |
---|
[2417] | 658 | if ( flag & ROAR_FLAG_RECSOURCE ) { |
---|
| 659 | if ( streams_recsource_id != -1 ) { |
---|
| 660 | if ( streams_reset_flag(streams_recsource_id, ROAR_FLAG_RECSOURCE) == -1 ) |
---|
| 661 | return -1; |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | streams_recsource_id = id; |
---|
| 665 | } |
---|
| 666 | |
---|
[1029] | 667 | g_streams[id]->flags |= flag; |
---|
| 668 | |
---|
[1498] | 669 | #ifdef ROAR_SUPPORT_META |
---|
[1043] | 670 | if ( flag & ROAR_FLAG_META ) |
---|
| 671 | stream_meta_finalize(id); |
---|
[1498] | 672 | #endif |
---|
[1043] | 673 | |
---|
[1029] | 674 | return 0; |
---|
| 675 | } |
---|
| 676 | |
---|
[2625] | 677 | int streams_set_rawflag (int id, int flag) { |
---|
[2734] | 678 | _CHECK_SID(id); |
---|
[2625] | 679 | |
---|
| 680 | g_streams[id]->flags |= flag; |
---|
| 681 | |
---|
| 682 | return 0; |
---|
| 683 | } |
---|
| 684 | |
---|
[1029] | 685 | int streams_reset_flag (int id, int flag) { |
---|
[2734] | 686 | _CHECK_SID(id); |
---|
[1029] | 687 | |
---|
[2417] | 688 | if ( flag & ROAR_FLAG_RECSOURCE ) |
---|
| 689 | if ( streams_recsource_id == id ) |
---|
| 690 | streams_recsource_id = -1; |
---|
| 691 | |
---|
[1928] | 692 | if ( flag & ROAR_FLAG_MMAP ) |
---|
| 693 | if ( streams_set_mmap(id, 1) == -1 ) |
---|
| 694 | flag -= ROAR_FLAG_MMAP; |
---|
| 695 | |
---|
[1043] | 696 | if ( flag & ROAR_FLAG_PRIMARY ) { |
---|
| 697 | streams_set_primary(id, 0); |
---|
| 698 | flag -= ROAR_FLAG_PRIMARY; |
---|
| 699 | } |
---|
| 700 | |
---|
[1116] | 701 | if ( flag & ROAR_FLAG_SYNC ) { |
---|
[2264] | 702 | // we refuse to reset the flag on FILTER streams |
---|
| 703 | if ( streams_get_dir(id) == ROAR_DIR_FILTER ) { |
---|
| 704 | // flags -= ROAR_FLAG_SYNC; |
---|
| 705 | return -1; |
---|
| 706 | } else { |
---|
| 707 | streams_set_sync(id, 0); |
---|
| 708 | } |
---|
[1116] | 709 | } |
---|
| 710 | |
---|
[1029] | 711 | g_streams[id]->flags |= flag; |
---|
| 712 | g_streams[id]->flags -= flag; |
---|
| 713 | |
---|
| 714 | return 0; |
---|
| 715 | } |
---|
| 716 | |
---|
[1042] | 717 | int streams_get_flag (int id, int flag) { |
---|
[2734] | 718 | _CHECK_SID(id); |
---|
[1042] | 719 | |
---|
| 720 | return g_streams[id]->flags & flag ? 1 : 0; |
---|
| 721 | } |
---|
| 722 | |
---|
[1842] | 723 | int streams_set_name (int id, char * name) { |
---|
| 724 | char * str; |
---|
| 725 | |
---|
[2734] | 726 | _CHECK_SID(id); |
---|
[1842] | 727 | |
---|
| 728 | if ( (str = strdup(name)) == NULL ) |
---|
| 729 | return -1; |
---|
| 730 | |
---|
| 731 | if ( g_streams[id]->name != NULL ) |
---|
| 732 | free(g_streams[id]->name); |
---|
| 733 | |
---|
| 734 | g_streams[id]->name = str; |
---|
[1845] | 735 | |
---|
| 736 | return 0; |
---|
[1842] | 737 | } |
---|
| 738 | |
---|
| 739 | char * streams_get_name (int id) { |
---|
[2734] | 740 | _CHECK_SID_RET(id, NULL); |
---|
[1842] | 741 | |
---|
| 742 | return g_streams[id]->name; |
---|
| 743 | } |
---|
| 744 | |
---|
| 745 | |
---|
[1223] | 746 | int streams_calc_delay (int id) { |
---|
[1142] | 747 | struct roar_stream_server * ss; |
---|
[1151] | 748 | struct roar_stream * s; |
---|
[1142] | 749 | register uint_least32_t d = 0; |
---|
| 750 | uint_least32_t t[1]; |
---|
[1151] | 751 | uint64_t tmp; |
---|
[1142] | 752 | |
---|
[2734] | 753 | _CHECK_SID(id); |
---|
| 754 | |
---|
[1151] | 755 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
[1142] | 756 | return -1; |
---|
| 757 | |
---|
| 758 | if ( ss->codecfilter != -1 ) { |
---|
| 759 | if ( codecfilter_delay(ss->codecfilter_inst, ss->codecfilter, t) != -1 ) |
---|
| 760 | d += *t; |
---|
| 761 | } |
---|
| 762 | |
---|
[1151] | 763 | if ( ss->vio.ctl != NULL ) { |
---|
| 764 | if ( roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_GET_DELAY, t) != -1 ) { // *t is in byte |
---|
[1223] | 765 | ROAR_DBG("streams_calc_delay(id=%i): VIO delay in byte: %i", id, *t); |
---|
[1151] | 766 | tmp = *t; |
---|
| 767 | tmp *= 1000000; // musec per sec |
---|
| 768 | tmp /= s->info.rate * s->info.channels * (s->info.bits/8); |
---|
[2387] | 769 | ROAR_DBG("streams_calc_delay(id=%i): VIO delay in musec: %llu", id, tmp); |
---|
[1151] | 770 | |
---|
| 771 | d += tmp; |
---|
| 772 | } |
---|
| 773 | } |
---|
| 774 | |
---|
[1223] | 775 | ROAR_DBG("streams_calc_delay(id=%i): delay in musec: %i", id, d); |
---|
[1151] | 776 | |
---|
[1142] | 777 | ss->delay = d; |
---|
| 778 | |
---|
| 779 | return 0; |
---|
| 780 | } |
---|
| 781 | |
---|
[1590] | 782 | int streams_set_mixer (int id) { |
---|
| 783 | struct roar_stream_server * ss; |
---|
[2416] | 784 | struct roar_stream_server * pmss; |
---|
| 785 | int i; |
---|
| 786 | int subsys; |
---|
[1590] | 787 | |
---|
[2734] | 788 | _CHECK_SID(id); |
---|
| 789 | |
---|
[1590] | 790 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 791 | return -1; |
---|
| 792 | |
---|
[2416] | 793 | if ( streams_get_flag(id, ROAR_FLAG_PASSMIXER) == 1 ) { |
---|
| 794 | if ( (subsys = streams_get_subsys(id)) == -1 ) |
---|
| 795 | return -1; |
---|
| 796 | |
---|
| 797 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 798 | if ( (pmss = g_streams[i]) != NULL ) { |
---|
| 799 | if ( streams_get_flag(i, ROAR_FLAG_PASSMIXER) == 1 ) { |
---|
| 800 | if ( streams_get_subsys(i) == subsys ) { |
---|
| 801 | memcpy(&(pmss->mixer), &(ss->mixer), sizeof(struct roar_mixer_settings)); |
---|
| 802 | |
---|
| 803 | // update hwmixers and the like but do not set mixer value recrusivly. |
---|
| 804 | streams_reset_flag(i, ROAR_FLAG_PASSMIXER); |
---|
| 805 | streams_set_mixer(i); |
---|
| 806 | streams_set_flag(i, ROAR_FLAG_PASSMIXER); |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | } |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | |
---|
[1590] | 813 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) ) |
---|
| 814 | return 0; |
---|
| 815 | |
---|
| 816 | if ( ss->driver_id == -1 ) |
---|
| 817 | return 0; |
---|
| 818 | |
---|
| 819 | return driver_set_volume(id, &(ss->mixer)); |
---|
| 820 | } |
---|
| 821 | |
---|
[1224] | 822 | int streams_ctl (int id, int_least32_t cmd, void * data) { |
---|
| 823 | struct roar_stream_server * ss; |
---|
| 824 | int_least32_t comp; |
---|
| 825 | |
---|
[2734] | 826 | _CHECK_SID(id); |
---|
| 827 | |
---|
[1224] | 828 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 829 | return -1; |
---|
| 830 | |
---|
| 831 | comp = cmd & ROAR_STREAM_CTL_COMPMASK; |
---|
| 832 | |
---|
| 833 | cmd &= ~comp; |
---|
| 834 | |
---|
[1239] | 835 | ROAR_DBG("streams_ctl(id=%i, cmd=?, data=%p): comp=0x%.8x, cmd=0x%.4x", id, data, comp, cmd); |
---|
[1238] | 836 | |
---|
[1224] | 837 | switch (comp) { |
---|
| 838 | case ROAR_STREAM_CTL_COMP_BASE: |
---|
| 839 | break; |
---|
| 840 | case ROAR_STREAM_CTL_COMP_CF: |
---|
| 841 | return codecfilter_ctl(ss->codecfilter_inst, ss->codecfilter, cmd, data); |
---|
| 842 | break; |
---|
| 843 | case ROAR_STREAM_CTL_COMP_DRV: |
---|
| 844 | break; |
---|
| 845 | default: |
---|
| 846 | return -1; |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | return -1; |
---|
| 850 | } |
---|
| 851 | |
---|
[0] | 852 | int streams_get_outputbuffer (int id, void ** buffer, size_t size) { |
---|
[2734] | 853 | _CHECK_SID(id); |
---|
[0] | 854 | |
---|
| 855 | // output buffer size does never change. |
---|
| 856 | if ( g_streams[id]->output != NULL ) { |
---|
| 857 | *buffer = g_streams[id]->output; |
---|
| 858 | return 0; |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | if ( (g_streams[id]->output = malloc(size)) == NULL ) { |
---|
| 862 | ROAR_ERR("streams_get_outputbuffer(*): Can not alloc: %s", strerror(errno)); |
---|
| 863 | return -1; |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | *buffer = g_streams[id]->output; |
---|
| 867 | |
---|
| 868 | return 0; |
---|
| 869 | } |
---|
| 870 | |
---|
[2061] | 871 | int streams_fill_mixbuffer2 (int id, struct roar_audio_info * info) { |
---|
| 872 | size_t outlen = ROAR_OUTPUT_CALC_OUTBUFSIZE(info); |
---|
| 873 | void * outdata; |
---|
| 874 | size_t inlen; |
---|
| 875 | size_t inlen_got; |
---|
| 876 | void * indata = NULL; |
---|
[2091] | 877 | size_t buflen; |
---|
| 878 | void * bufdata = NULL; |
---|
| 879 | struct roar_buffer * bufbuf = NULL; |
---|
[2061] | 880 | int is_the_same = 0; |
---|
| 881 | struct roar_audio_info * stream_info; |
---|
| 882 | struct roar_stream * s; |
---|
| 883 | struct roar_stream_server * ss; |
---|
| 884 | |
---|
[2734] | 885 | _CHECK_SID(id); |
---|
| 886 | |
---|
[2061] | 887 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
| 888 | return -1; |
---|
| 889 | |
---|
| 890 | // set up stream_info |
---|
| 891 | stream_info = &(s->info); |
---|
| 892 | |
---|
| 893 | // calc todo_in |
---|
| 894 | inlen = ROAR_OUTPUT_CALC_OUTBUFSIZE(stream_info); |
---|
| 895 | |
---|
[2091] | 896 | buflen = ROAR_OUTPUT_CALC_OUTBUFSIZE_MAX(info, stream_info); |
---|
| 897 | |
---|
[2747] | 898 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=%p{...}): inlen=%lu, buflen=%lu", id, info, (unsigned long)inlen, (unsigned long)buflen); |
---|
| 899 | |
---|
[2061] | 900 | if ( inlen == 0 ) { |
---|
| 901 | ROAR_WARN("streams_fill_mixbuffer2(id=%i, info=%p{...}): inlen == 0, this should not happen!", id, info); |
---|
| 902 | return -1; |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | if ( streams_get_outputbuffer(id, &outdata, outlen) == -1 ) { |
---|
| 906 | return -1; |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | if ( outdata == NULL ) { |
---|
| 910 | return -1; |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | ROAR_DBG("streams_fill_mixbuffer2(*): outdata=%p, len=%i->%i (in->out)", outdata, inlen, outlen); |
---|
| 914 | |
---|
| 915 | is_the_same = stream_info->rate == info->rate && stream_info->bits == info->bits && |
---|
| 916 | stream_info->channels == info->channels && stream_info->codec == info->codec; |
---|
| 917 | |
---|
| 918 | ROAR_DBG("streams_fill_mixbuffer2(*): is_the_same=%i", is_the_same); |
---|
| 919 | |
---|
[2091] | 920 | if ( !is_the_same && buflen > outlen ) { |
---|
| 921 | /* |
---|
[2061] | 922 | // this is not supported at the moment |
---|
| 923 | memset(outdata, 0, outlen); |
---|
| 924 | return -1; |
---|
[2091] | 925 | */ |
---|
| 926 | |
---|
| 927 | if ( roar_buffer_new(&bufbuf, buflen) == -1 ) |
---|
| 928 | return -1; |
---|
| 929 | |
---|
| 930 | if ( roar_buffer_get_data(bufbuf, &bufdata) == -1 ) |
---|
| 931 | return -1; |
---|
[2102] | 932 | indata = bufdata; |
---|
[2061] | 933 | } else { |
---|
[2091] | 934 | indata = outdata; |
---|
| 935 | bufdata = outdata; |
---|
[2061] | 936 | } |
---|
| 937 | |
---|
| 938 | inlen_got = inlen; |
---|
| 939 | |
---|
[2102] | 940 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=...): inlen_got=%u", id, inlen_got); |
---|
| 941 | |
---|
[2061] | 942 | if ( stream_shift_out_buffer(id, indata, &inlen_got) == -1 ) { |
---|
| 943 | if ( ss->is_new ) { |
---|
| 944 | ss->pre_underruns++; |
---|
| 945 | } else { |
---|
[2088] | 946 | ROAR_WARN("streams_fill_mixbuffer2(id=%i, info=...): underrun in stream", id); |
---|
[2061] | 947 | ss->post_underruns++; |
---|
| 948 | } |
---|
| 949 | memset(outdata, 0, outlen); |
---|
| 950 | return 0; |
---|
| 951 | } |
---|
| 952 | |
---|
[2387] | 953 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=...): inlen_got=%u", id, inlen_got); |
---|
| 954 | |
---|
[2061] | 955 | if ( ss->is_new ) { |
---|
[2613] | 956 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
[2088] | 957 | ROAR_WARN("streams_fill_mixbuffer2(id=%i, info=...): stream state: new->old", id); |
---|
[2061] | 958 | } |
---|
| 959 | |
---|
| 960 | ss->is_new = 0; |
---|
| 961 | |
---|
| 962 | if ( is_the_same ) { |
---|
| 963 | if ( indata != outdata ) |
---|
| 964 | memcpy(outdata, indata, inlen); |
---|
| 965 | |
---|
| 966 | if ( inlen < outlen ) |
---|
| 967 | memset(outdata+inlen, 0, outlen-inlen); |
---|
| 968 | } else { |
---|
[2095] | 969 | // if ( roar_conv(outdata, indata, (8*inlen_got*info->rate)/(stream_info->rate * stream_info->bits), stream_info, info) == -1 ) { |
---|
[2387] | 970 | ROAR_DBG("streams_fill_mixbuffer2(*): CALL roar_conv2(*)..."); |
---|
[2095] | 971 | if ( roar_conv2(bufdata, indata, inlen, stream_info, info, buflen) == -1 ) { |
---|
[2091] | 972 | if ( bufbuf != NULL ) |
---|
| 973 | roar_buffer_free(bufbuf); |
---|
[2062] | 974 | return -1; |
---|
| 975 | } |
---|
| 976 | |
---|
| 977 | // memset(outdata, 0, outlen); |
---|
[2061] | 978 | } |
---|
| 979 | |
---|
[2091] | 980 | if ( bufbuf != NULL ) { |
---|
| 981 | memcpy(outdata, bufdata, outlen); |
---|
| 982 | roar_buffer_free(bufbuf); |
---|
| 983 | } |
---|
| 984 | |
---|
[2414] | 985 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) && !streams_get_flag(id, ROAR_FLAG_PASSMIXER) ) { |
---|
[2747] | 986 | ROAR_DBG("streams_fill_mixbuffer2(*): CALL change_vol(*)..."); |
---|
[2079] | 987 | if ( change_vol(outdata, info->bits, outdata, 8*outlen / info->bits, info->channels, &(ss->mixer)) == -1 ) |
---|
| 988 | return -1; |
---|
| 989 | } |
---|
| 990 | |
---|
[2153] | 991 | if ( streams_get_flag(id, ROAR_FLAG_ANTIECHO) ) { |
---|
[2747] | 992 | ROAR_DBG("streams_fill_mixbuffer2(*): Calcing antiecho..."); |
---|
[2153] | 993 | // we can ignore errors here: |
---|
[2389] | 994 | if ( stream_outputbuffer_request(id, &bufbuf, buflen) == 0 ) { |
---|
[2153] | 995 | if ( roar_buffer_get_data(bufbuf, &bufdata) != -1 ) |
---|
| 996 | memcpy(bufdata, outdata, outlen); |
---|
| 997 | } |
---|
| 998 | } |
---|
| 999 | |
---|
[2623] | 1000 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(info, outlen)*info->channels); |
---|
[2153] | 1001 | |
---|
[2747] | 1002 | ROAR_DBG("streams_fill_mixbuffer2(*) = 0"); |
---|
[2062] | 1003 | return 0; |
---|
[2061] | 1004 | } |
---|
| 1005 | |
---|
[491] | 1006 | |
---|
[0] | 1007 | int streams_get_mixbuffers (void *** bufferlist, struct roar_audio_info * info, unsigned int pos) { |
---|
[84] | 1008 | static void * bufs[ROAR_STREAMS_MAX+1]; |
---|
[0] | 1009 | int i; |
---|
| 1010 | int have = 0; |
---|
[2458] | 1011 | int dir; |
---|
[0] | 1012 | |
---|
| 1013 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 1014 | if ( g_streams[i] != NULL ) { |
---|
[2458] | 1015 | dir = streams_get_dir(i); |
---|
| 1016 | |
---|
| 1017 | switch (dir) { |
---|
| 1018 | case ROAR_DIR_PLAY: |
---|
| 1019 | case ROAR_DIR_BIDIR: |
---|
| 1020 | break; |
---|
[2459] | 1021 | case ROAR_DIR_BRIDGE: |
---|
| 1022 | if ( g_streams[i]->buffer == NULL ) |
---|
| 1023 | continue; |
---|
| 1024 | break; |
---|
[2458] | 1025 | default: |
---|
| 1026 | continue; |
---|
| 1027 | } |
---|
[0] | 1028 | |
---|
[2730] | 1029 | if ( streams_get_flag(i, ROAR_FLAG_PAUSE) ) |
---|
| 1030 | continue; |
---|
| 1031 | |
---|
[0] | 1032 | if ( streams_get_outputbuffer(i, &bufs[have], ROAR_OUTPUT_CALC_OUTBUFSIZE(info)) == -1 ) { |
---|
| 1033 | ROAR_ERR("streams_get_mixbuffer(*): Can not alloc output buffer for stream %i, BAD!", i); |
---|
| 1034 | ROAR_ERR("streams_get_mixbuffer(*): Ignoring stream for this round."); |
---|
| 1035 | continue; |
---|
| 1036 | } |
---|
[2061] | 1037 | if ( streams_fill_mixbuffer2(i, info) == -1 ) { |
---|
[0] | 1038 | ROAR_ERR("streams_get_mixbuffer(*): Can not fill output buffer for stream %i, this should not happen", i); |
---|
| 1039 | continue; |
---|
| 1040 | } |
---|
| 1041 | |
---|
[139] | 1042 | // printf("D: bufs[have=%i] = %p\n", have, bufs[have]); |
---|
| 1043 | |
---|
[0] | 1044 | ROAR_DBG("streams_get_mixbuffers(*): bufs[have] = %p", bufs[have]); |
---|
| 1045 | ROAR_DBG("streams_get_mixbuffers(*): *bufs[have] = 0x%08x...", *(uint32_t*)bufs[have]); |
---|
| 1046 | |
---|
[1887] | 1047 | if ( !streams_get_flag(i, ROAR_FLAG_MUTE) ) |
---|
| 1048 | have++; // we have a new stream! |
---|
[0] | 1049 | } |
---|
| 1050 | } |
---|
| 1051 | |
---|
| 1052 | bufs[have] = NULL; |
---|
[139] | 1053 | //printf("D: bufs[have=%i] = %p\n", have, bufs[have]); |
---|
[0] | 1054 | |
---|
| 1055 | ROAR_DBG("streams_get_mixbuffers(*): have = %i", have); |
---|
| 1056 | |
---|
| 1057 | *bufferlist = bufs; |
---|
[547] | 1058 | return have; |
---|
[0] | 1059 | } |
---|
| 1060 | |
---|
| 1061 | |
---|
| 1062 | int stream_add_buffer (int id, struct roar_buffer * buf) { |
---|
| 1063 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf); |
---|
| 1064 | |
---|
[2734] | 1065 | _CHECK_SID(id); |
---|
[0] | 1066 | |
---|
| 1067 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1068 | g_streams[id]->buffer = buf; |
---|
| 1069 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = 0", id, buf); |
---|
| 1070 | return 0; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf); |
---|
| 1074 | return roar_buffer_add(g_streams[id]->buffer, buf); |
---|
| 1075 | } |
---|
| 1076 | |
---|
[2061] | 1077 | int stream_shift_out_buffer (int id, void * data, size_t * len) { |
---|
[2734] | 1078 | _CHECK_SID(id); |
---|
[2061] | 1079 | |
---|
| 1080 | if ( g_streams[id]->buffer == NULL ) |
---|
| 1081 | return -1; |
---|
| 1082 | |
---|
| 1083 | return roar_buffer_shift_out(&(g_streams[id]->buffer), data, len); |
---|
| 1084 | } |
---|
| 1085 | |
---|
[0] | 1086 | int stream_shift_buffer (int id, struct roar_buffer ** buf) { |
---|
| 1087 | struct roar_buffer * next; |
---|
| 1088 | |
---|
[2734] | 1089 | _CHECK_SID(id); |
---|
[0] | 1090 | |
---|
| 1091 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1092 | *buf = NULL; |
---|
| 1093 | return 0; |
---|
| 1094 | } |
---|
| 1095 | |
---|
| 1096 | roar_buffer_get_next(g_streams[id]->buffer, &next); |
---|
| 1097 | |
---|
| 1098 | *buf = g_streams[id]->buffer; |
---|
| 1099 | g_streams[id]->buffer = next; |
---|
| 1100 | |
---|
| 1101 | return 0; |
---|
| 1102 | } |
---|
| 1103 | int stream_unshift_buffer (int id, struct roar_buffer * buf) { |
---|
[2734] | 1104 | _CHECK_SID(id); |
---|
[0] | 1105 | |
---|
| 1106 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1107 | g_streams[id]->buffer = buf; |
---|
| 1108 | return 0; |
---|
| 1109 | } |
---|
| 1110 | |
---|
[271] | 1111 | buf->next = NULL; |
---|
| 1112 | |
---|
[0] | 1113 | roar_buffer_add(buf, g_streams[id]->buffer); |
---|
| 1114 | |
---|
| 1115 | g_streams[id]->buffer = buf; |
---|
| 1116 | |
---|
| 1117 | return 0; |
---|
| 1118 | } |
---|
| 1119 | |
---|
[2151] | 1120 | int stream_outputbuffer_request(int id, struct roar_buffer ** buf, size_t len) { |
---|
| 1121 | register struct roar_stream_server * ss; |
---|
| 1122 | size_t buflen; |
---|
[2159] | 1123 | void * bufdata; |
---|
[2151] | 1124 | int ret; |
---|
| 1125 | |
---|
[2734] | 1126 | _CHECK_SID(id); |
---|
| 1127 | |
---|
[2151] | 1128 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1129 | return -1; |
---|
| 1130 | |
---|
| 1131 | if ( buf != NULL ) /* just be be sure */ |
---|
| 1132 | *buf = NULL; |
---|
| 1133 | |
---|
| 1134 | if ( ss->outputbuffer != NULL ) { |
---|
| 1135 | if ( roar_buffer_get_len(ss->outputbuffer, &buflen) == 0 ) { |
---|
| 1136 | if ( buflen == len ) { |
---|
| 1137 | if ( buf != NULL ) |
---|
| 1138 | *buf = ss->outputbuffer; |
---|
| 1139 | return 0; |
---|
| 1140 | } else if ( buflen > len ) { |
---|
| 1141 | if ( roar_buffer_set_len(ss->outputbuffer, len) == 0 ) { |
---|
| 1142 | if ( buf != NULL ) |
---|
| 1143 | *buf = ss->outputbuffer; |
---|
| 1144 | return 0; |
---|
| 1145 | } |
---|
| 1146 | } |
---|
| 1147 | } |
---|
| 1148 | |
---|
| 1149 | // if the buffer is not suitable: |
---|
| 1150 | |
---|
| 1151 | ret = roar_buffer_free(ss->outputbuffer); |
---|
| 1152 | ss->outputbuffer = NULL; |
---|
| 1153 | if ( ret == -1 ) |
---|
| 1154 | return ret; |
---|
| 1155 | } |
---|
| 1156 | |
---|
| 1157 | if ( roar_buffer_new(&(ss->outputbuffer), len) == -1 ) |
---|
| 1158 | return -1; |
---|
| 1159 | |
---|
[2159] | 1160 | if ( roar_buffer_get_data(ss->outputbuffer, &bufdata) == -1 ) { |
---|
| 1161 | roar_buffer_free(ss->outputbuffer); |
---|
| 1162 | ss->outputbuffer = NULL; |
---|
| 1163 | return -1; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | memset(bufdata, 0, len); |
---|
| 1167 | |
---|
[2151] | 1168 | if ( buf != NULL ) |
---|
| 1169 | *buf = ss->outputbuffer; |
---|
| 1170 | |
---|
| 1171 | return 0; |
---|
| 1172 | } |
---|
| 1173 | |
---|
| 1174 | int stream_outputbuffer_destroy(int id) { |
---|
| 1175 | int ret; |
---|
| 1176 | register struct roar_stream_server * ss; |
---|
| 1177 | |
---|
[2734] | 1178 | _CHECK_SID(id); |
---|
| 1179 | |
---|
[2151] | 1180 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1181 | return -1; |
---|
| 1182 | |
---|
| 1183 | if ( ss->outputbuffer != NULL ) { |
---|
| 1184 | ret = roar_buffer_free(ss->outputbuffer); |
---|
| 1185 | ss->outputbuffer = NULL; |
---|
| 1186 | return ret; |
---|
| 1187 | } |
---|
| 1188 | |
---|
| 1189 | return 0; |
---|
| 1190 | } |
---|
| 1191 | |
---|
[2816] | 1192 | int stream_prethru_add(int id, struct roar_buffer * buf) { |
---|
| 1193 | register struct roar_stream_server * ss; |
---|
| 1194 | |
---|
| 1195 | _CHECK_SID(id); |
---|
| 1196 | |
---|
| 1197 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1198 | return -1; |
---|
| 1199 | |
---|
| 1200 | if ( ss->prethru == NULL ) { |
---|
| 1201 | ss->prethru = buf; |
---|
| 1202 | return 0; |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | if ( roar_buffer_add(ss->prethru, buf) == -1 ) { |
---|
| 1206 | return -1; |
---|
| 1207 | } |
---|
| 1208 | |
---|
| 1209 | return 0; |
---|
| 1210 | } |
---|
| 1211 | |
---|
| 1212 | int stream_prethru_add_data(int id, void ** buf, size_t len) { |
---|
| 1213 | struct roar_buffer * buffer; |
---|
| 1214 | |
---|
| 1215 | _CHECK_SID(id); |
---|
| 1216 | |
---|
| 1217 | if ( roar_buffer_new(&buffer, len) == -1 ) |
---|
| 1218 | return -1; |
---|
| 1219 | |
---|
| 1220 | if ( roar_buffer_get_data(buffer, buf) == -1 ) { |
---|
| 1221 | roar_buffer_free(buffer); |
---|
| 1222 | return -1; |
---|
| 1223 | } |
---|
| 1224 | |
---|
| 1225 | if ( stream_prethru_add(id, buffer) == -1 ) { |
---|
| 1226 | roar_buffer_free(buffer); |
---|
| 1227 | return -1; |
---|
| 1228 | } |
---|
| 1229 | |
---|
| 1230 | return 0; |
---|
| 1231 | } |
---|
| 1232 | |
---|
| 1233 | int stream_prethru_destroy(int id) { |
---|
| 1234 | int ret; |
---|
| 1235 | register struct roar_stream_server * ss; |
---|
| 1236 | |
---|
| 1237 | _CHECK_SID(id); |
---|
| 1238 | |
---|
| 1239 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1240 | return -1; |
---|
| 1241 | |
---|
| 1242 | if ( ss->prethru != NULL ) { |
---|
| 1243 | ret = roar_buffer_free(ss->prethru); |
---|
| 1244 | ss->prethru = NULL; |
---|
| 1245 | return ret; |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | return 0; |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | int stream_prethru_send(int dst, int src) { |
---|
| 1252 | struct roar_stream_server * dst_ss, * src_ss; |
---|
| 1253 | struct roar_buffer * bufbuf; |
---|
| 1254 | void * bufdata; |
---|
| 1255 | size_t buflen; |
---|
| 1256 | |
---|
| 1257 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = ?", dst, src); |
---|
| 1258 | |
---|
| 1259 | _CHECK_SID(dst); |
---|
| 1260 | _CHECK_SID(src); |
---|
| 1261 | |
---|
| 1262 | if ( (dst_ss = g_streams[dst]) == NULL ) |
---|
| 1263 | return -1; |
---|
| 1264 | |
---|
| 1265 | if ( (src_ss = g_streams[src]) == NULL ) |
---|
| 1266 | return -1; |
---|
| 1267 | |
---|
| 1268 | bufbuf = src_ss->prethru; |
---|
| 1269 | |
---|
| 1270 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i): prethru buffer at %p", dst, src, bufbuf); |
---|
| 1271 | |
---|
| 1272 | while (bufbuf != NULL) { |
---|
| 1273 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i): looping with buffer at %p", dst, src, bufbuf); |
---|
| 1274 | |
---|
| 1275 | if ( roar_buffer_get_data(bufbuf, &bufdata) == -1 ) |
---|
| 1276 | return -1; |
---|
| 1277 | |
---|
| 1278 | if ( roar_buffer_get_len(bufbuf, &buflen) == -1 ) |
---|
| 1279 | return -1; |
---|
| 1280 | |
---|
| 1281 | if ( stream_vio_s_write(dst_ss, bufdata, buflen) != buflen ) |
---|
| 1282 | return -1; |
---|
| 1283 | |
---|
| 1284 | if ( roar_buffer_get_next(bufbuf, &bufbuf) == -1 ) |
---|
| 1285 | return -1; |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = 0", dst, src); |
---|
| 1289 | return 0; |
---|
| 1290 | } |
---|
| 1291 | |
---|
[0] | 1292 | int streams_check (int id) { |
---|
| 1293 | int fh; |
---|
[508] | 1294 | ssize_t req, realreq, done; |
---|
[0] | 1295 | struct roar_stream * s; |
---|
| 1296 | struct roar_stream_server * ss; |
---|
| 1297 | struct roar_buffer * b; |
---|
| 1298 | char * buf; |
---|
[2248] | 1299 | // char tmp; |
---|
[0] | 1300 | |
---|
[2734] | 1301 | _CHECK_SID(id); |
---|
[0] | 1302 | |
---|
| 1303 | ROAR_DBG("streams_check(id=%i) = ?", id); |
---|
| 1304 | |
---|
[609] | 1305 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
[0] | 1306 | |
---|
| 1307 | if ( (fh = s->fh) == -1 ) |
---|
| 1308 | return 0; |
---|
| 1309 | |
---|
[1821] | 1310 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
[0] | 1311 | return 0; |
---|
| 1312 | |
---|
[1821] | 1313 | switch (s->dir) { |
---|
| 1314 | case ROAR_DIR_LIGHT_IN: |
---|
[2493] | 1315 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1821] | 1316 | return light_check_stream(id); |
---|
[2493] | 1317 | #else |
---|
| 1318 | streams_delete(id); |
---|
| 1319 | return -1; |
---|
| 1320 | #endif |
---|
[1821] | 1321 | break; |
---|
[1845] | 1322 | case ROAR_DIR_MIDI_IN: |
---|
[2493] | 1323 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1845] | 1324 | return midi_check_stream(id); |
---|
[2493] | 1325 | #else |
---|
| 1326 | streams_delete(id); |
---|
| 1327 | return -1; |
---|
| 1328 | #endif |
---|
[1845] | 1329 | break; |
---|
[2237] | 1330 | case ROAR_DIR_RAW_IN: |
---|
[2493] | 1331 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
[2237] | 1332 | return raw_check_stream(id); |
---|
[2493] | 1333 | #else |
---|
| 1334 | streams_delete(id); |
---|
| 1335 | return -1; |
---|
| 1336 | #endif |
---|
[2237] | 1337 | break; |
---|
[2721] | 1338 | case ROAR_DIR_RDTCS_IN: |
---|
| 1339 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1340 | return rdtcs_check_stream(id); |
---|
| 1341 | #else |
---|
| 1342 | streams_delete(id); |
---|
| 1343 | return -1; |
---|
| 1344 | #endif |
---|
| 1345 | break; |
---|
[1821] | 1346 | case ROAR_DIR_PLAY: |
---|
| 1347 | case ROAR_DIR_BIDIR: |
---|
| 1348 | break; |
---|
| 1349 | default: |
---|
[2248] | 1350 | /* |
---|
| 1351 | ROAR_WARN("streams_check(id=%i): Read event on non input stream of type/dir %s", id, roar_dir2str(s->dir)); |
---|
| 1352 | errno = 0; |
---|
| 1353 | req = stream_vio_s_read(ss, &tmp, 1); |
---|
| 1354 | ROAR_DBG("streams_check(id=%i): stream_vio_s_read(ss, &tmp, 1) = %li // errno=%s(%i)", id, req, strerror(errno), errno); |
---|
| 1355 | if ( req == 1 ) { |
---|
| 1356 | ROAR_ERR("streams_check(id=%i): Client violates protocol, got one byte of data on output stream, kicking stream"); |
---|
| 1357 | streams_delete(id); |
---|
| 1358 | return -1; |
---|
| 1359 | } |
---|
| 1360 | */ |
---|
[1821] | 1361 | return 0; |
---|
| 1362 | break; |
---|
| 1363 | } |
---|
[1585] | 1364 | |
---|
[0] | 1365 | ROAR_DBG("streams_check(id=%i): fh = %i", id, fh); |
---|
| 1366 | |
---|
[2387] | 1367 | /* |
---|
| 1368 | ROAR_DBG("streams_check(id=%i): ROAR_OUTPUT_BUFFER_SAMPLES=%i, s->info.channels=%i, s->info.bits=%i, s->info.rat=%i, g_sa->rate=%i", id, ROAR_OUTPUT_BUFFER_SAMPLES, s->info.channels, s->info.bits, s->info.rate, g_sa->rate); |
---|
| 1369 | */ |
---|
| 1370 | |
---|
| 1371 | req = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); // optimal size |
---|
| 1372 | // req = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * (s->info.bits / 8) * ((float)s->info.rate/g_sa->rate); |
---|
[0] | 1373 | req += ss->need_extra; // bytes left we sould get.... |
---|
| 1374 | |
---|
[2387] | 1375 | ROAR_DBG("streams_check(id=%i): asking for %i bytes", id, req); |
---|
| 1376 | |
---|
[0] | 1377 | if ( roar_buffer_new(&b, req) == -1 ) { |
---|
| 1378 | ROAR_ERR("streams_check(*): Can not alloc buffer space!"); |
---|
| 1379 | ROAR_DBG("streams_check(*) = -1"); |
---|
| 1380 | return -1; |
---|
| 1381 | } |
---|
| 1382 | |
---|
| 1383 | roar_buffer_get_data(b, (void **)&buf); |
---|
| 1384 | |
---|
| 1385 | ROAR_DBG("streams_check(id=%i): buffer is up and ready ;)", id); |
---|
[2387] | 1386 | ROAR_DBG("streams_check(id=%i): asking for %i bytes", id, req); |
---|
[0] | 1387 | |
---|
[270] | 1388 | if ( ss->codecfilter == -1 ) { |
---|
[508] | 1389 | realreq = req; |
---|
| 1390 | /* |
---|
[270] | 1391 | req = read(fh, buf, req); |
---|
[508] | 1392 | if ( req < realreq ) { // we can do this as the stream is in nonblocking mode! |
---|
| 1393 | if ( (realreq = read(fh, buf+req, realreq-req)) > 0 ) |
---|
| 1394 | req += realreq; |
---|
| 1395 | } |
---|
| 1396 | */ |
---|
| 1397 | done = 0; |
---|
| 1398 | while (req > 0 && done != realreq) { |
---|
[881] | 1399 | if ( (req = stream_vio_s_read(ss, buf+done, realreq-done)) > 0 ) |
---|
[508] | 1400 | done += req; |
---|
| 1401 | } |
---|
| 1402 | req = done; |
---|
[1837] | 1403 | |
---|
| 1404 | roar_buffer_get_data(b, (void **)&buf); |
---|
[270] | 1405 | } else { |
---|
| 1406 | req = codecfilter_read(ss->codecfilter_inst, ss->codecfilter, buf, req); |
---|
| 1407 | } |
---|
| 1408 | |
---|
| 1409 | if ( req > 0 ) { |
---|
[0] | 1410 | ROAR_DBG("streams_check(id=%i): got %i bytes", id, req); |
---|
| 1411 | |
---|
| 1412 | roar_buffer_set_len(b, req); |
---|
| 1413 | |
---|
| 1414 | if ( stream_add_buffer(id, b) != -1 ) |
---|
| 1415 | return 0; |
---|
| 1416 | |
---|
| 1417 | ROAR_ERR("streams_check(id=%i): something is wrong, could not add buffer to stream!", id); |
---|
| 1418 | roar_buffer_free(b); |
---|
| 1419 | } else { |
---|
[272] | 1420 | ROAR_DBG("streams_check(id=%i): read() = %i // errno: %s", id, req, strerror(errno)); |
---|
| 1421 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
| 1422 | if ( errno != EAGAIN && errno != ESPIPE ) { // libvorbis file trys to seek a bit ofen :) |
---|
| 1423 | #else |
---|
| 1424 | if ( errno != EAGAIN ) { |
---|
| 1425 | #endif |
---|
| 1426 | ROAR_DBG("streams_check(id=%i): EOF!", id); |
---|
| 1427 | streams_delete(id); |
---|
| 1428 | ROAR_DBG("streams_check(id=%i) = 0", id); |
---|
| 1429 | } |
---|
[334] | 1430 | roar_buffer_free(b); |
---|
[0] | 1431 | return 0; |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | |
---|
| 1435 | ROAR_DBG("streams_check(id=%i) = -1", id); |
---|
| 1436 | return -1; |
---|
| 1437 | } |
---|
| 1438 | |
---|
| 1439 | |
---|
[2152] | 1440 | #define _return(x) return (x) |
---|
[0] | 1441 | int streams_send_mon (int id) { |
---|
[936] | 1442 | // int fh; |
---|
[0] | 1443 | struct roar_stream * s; |
---|
| 1444 | struct roar_stream_server * ss; |
---|
[2146] | 1445 | struct roar_buffer * bufbuf = NULL; |
---|
[2155] | 1446 | struct roar_remove_state removalstate; |
---|
[2148] | 1447 | void * ip; |
---|
[1157] | 1448 | void * obuf; |
---|
| 1449 | int olen; |
---|
[2150] | 1450 | int is_the_same = 1; |
---|
| 1451 | int is_vol_eq = 1; |
---|
[2155] | 1452 | int antiecho = 0; |
---|
[1157] | 1453 | ssize_t ret; |
---|
[0] | 1454 | |
---|
[2734] | 1455 | _CHECK_SID(id); |
---|
[0] | 1456 | |
---|
| 1457 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 1458 | |
---|
[585] | 1459 | s = ROAR_STREAM((ss = g_streams[id])); |
---|
[0] | 1460 | |
---|
[934] | 1461 | /* |
---|
[0] | 1462 | if ( (fh = s->fh) == -1 ) |
---|
| 1463 | return 0; |
---|
[934] | 1464 | */ |
---|
[0] | 1465 | |
---|
[1914] | 1466 | if ( !ss->ready ) |
---|
| 1467 | return 0; |
---|
[930] | 1468 | |
---|
[1585] | 1469 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
| 1470 | return 0; |
---|
| 1471 | |
---|
[1821] | 1472 | switch (s->dir) { |
---|
| 1473 | case ROAR_DIR_LIGHT_OUT: |
---|
[2493] | 1474 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1821] | 1475 | return light_send_stream(id); |
---|
[2493] | 1476 | #else |
---|
| 1477 | streams_delete(id); |
---|
| 1478 | return -1; |
---|
| 1479 | #endif |
---|
[1821] | 1480 | break; |
---|
[1845] | 1481 | case ROAR_DIR_MIDI_OUT: |
---|
[2493] | 1482 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1845] | 1483 | return midi_send_stream(id); |
---|
[2493] | 1484 | #else |
---|
| 1485 | streams_delete(id); |
---|
| 1486 | return -1; |
---|
| 1487 | #endif |
---|
[1845] | 1488 | break; |
---|
[2721] | 1489 | case ROAR_DIR_RDTCS_OUT: |
---|
| 1490 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1491 | return rdtcs_send_stream(id); |
---|
| 1492 | #else |
---|
| 1493 | streams_delete(id); |
---|
| 1494 | return -1; |
---|
| 1495 | #endif |
---|
| 1496 | break; |
---|
[2694] | 1497 | |
---|
| 1498 | case ROAR_DIR_COMPLEX_OUT: |
---|
| 1499 | // send a tick: |
---|
| 1500 | if ( ss->codecfilter != -1 ) { |
---|
| 1501 | if ( codecfilter_write(ss->codecfilter_inst, ss->codecfilter, NULL, 0) == 0 ) |
---|
| 1502 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
| 1503 | } |
---|
| 1504 | return 0; |
---|
| 1505 | break; |
---|
| 1506 | |
---|
[1821] | 1507 | case ROAR_DIR_OUTPUT: |
---|
| 1508 | if ( g_standby ) |
---|
| 1509 | return 0; |
---|
| 1510 | case ROAR_DIR_MONITOR: |
---|
| 1511 | case ROAR_DIR_BIDIR: |
---|
| 1512 | break; |
---|
| 1513 | |
---|
| 1514 | default: |
---|
| 1515 | return 0; |
---|
| 1516 | break; |
---|
| 1517 | } |
---|
| 1518 | |
---|
| 1519 | |
---|
[1042] | 1520 | ROAR_DBG("streams_send_mon(id=%i): fh = %i", id, s->fh); |
---|
[0] | 1521 | |
---|
[625] | 1522 | if ( s->info.channels != g_sa->channels || s->info.bits != g_sa->bits || |
---|
[2147] | 1523 | s->info.rate != g_sa->rate || s->info.codec != g_sa->codec ) |
---|
| 1524 | is_the_same = 0; |
---|
| 1525 | |
---|
[2150] | 1526 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) ) { |
---|
| 1527 | is_vol_eq = need_vol_change(g_sa->channels, &(ss->mixer)) ? 0 : 1; |
---|
| 1528 | } |
---|
| 1529 | |
---|
[2155] | 1530 | if ( streams_get_flag(id, ROAR_FLAG_ANTIECHO) ) |
---|
| 1531 | antiecho = 1; |
---|
| 1532 | |
---|
| 1533 | if ( !is_the_same || !is_vol_eq || antiecho ) { |
---|
[625] | 1534 | olen = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); // we hope g_output_buffer_len |
---|
| 1535 | // is ROAR_OUTPUT_CALC_OUTBUFSIZE(g_sa) here |
---|
[2390] | 1536 | if ( stream_outputbuffer_request(id, &bufbuf, ROAR_OUTPUT_CALC_OUTBUFSIZE_MAX(&(s->info), g_sa)) == -1 ) |
---|
[625] | 1537 | return -1; |
---|
| 1538 | |
---|
[2146] | 1539 | if ( roar_buffer_get_data(bufbuf, &obuf) == -1 ) { |
---|
| 1540 | _return(-1); |
---|
| 1541 | } |
---|
| 1542 | |
---|
[625] | 1543 | ROAR_DBG("streams_send_mon(id=%i): obuf=%p, olen=%i", id, obuf, olen); |
---|
[2147] | 1544 | } else { |
---|
| 1545 | obuf = g_output_buffer; |
---|
| 1546 | olen = g_output_buffer_len; |
---|
| 1547 | } |
---|
[625] | 1548 | |
---|
[2148] | 1549 | ip = g_output_buffer; |
---|
| 1550 | |
---|
[2155] | 1551 | if ( antiecho ) { |
---|
[2397] | 1552 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2158] | 1553 | if ( roar_remove_init(&removalstate) == -1 ) { |
---|
[2155] | 1554 | _return(-1); |
---|
[2158] | 1555 | } |
---|
| 1556 | |
---|
[2397] | 1557 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2158] | 1558 | if ( roar_remove_so(obuf, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa->bits, &removalstate) == -1 ) { |
---|
[2397] | 1559 | ROAR_DBG("streams_send_mon(id=%i): anti echo failed", id); |
---|
[2158] | 1560 | _return(-1); |
---|
| 1561 | } |
---|
[2397] | 1562 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2155] | 1563 | } |
---|
| 1564 | |
---|
[2150] | 1565 | if ( !is_vol_eq ) { |
---|
| 1566 | if ( change_vol(obuf, g_sa->bits, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa->channels, &(ss->mixer)) == -1 ) { |
---|
| 1567 | _return(-1); |
---|
| 1568 | } |
---|
| 1569 | |
---|
| 1570 | ip = obuf; |
---|
| 1571 | } |
---|
| 1572 | |
---|
[2147] | 1573 | if ( !is_the_same ) { |
---|
[2148] | 1574 | if ( roar_conv(obuf, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa, &(s->info)) == -1 ) { |
---|
[2146] | 1575 | _return(-1); |
---|
[625] | 1576 | } |
---|
| 1577 | } |
---|
| 1578 | |
---|
[585] | 1579 | errno = 0; |
---|
| 1580 | |
---|
| 1581 | if ( ss->codecfilter == -1 ) { |
---|
[1042] | 1582 | ROAR_DBG("streams_send_mon(id=%i): not a CF stream", id); |
---|
[2146] | 1583 | if ( s->fh == -1 && roar_vio_get_fh(&(ss->vio)) == -1 ) { |
---|
[2705] | 1584 | ROAR_DBG("streams_send_mon(id=%i) = 0", id); |
---|
[2146] | 1585 | _return(0); |
---|
| 1586 | } |
---|
[1014] | 1587 | |
---|
[2705] | 1588 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 1589 | |
---|
[1157] | 1590 | if ( (ret = stream_vio_s_write(ss, obuf, olen)) == olen ) { |
---|
[981] | 1591 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[2635] | 1592 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
[2705] | 1593 | ROAR_DBG("streams_send_mon(id=%i) = 0", id); |
---|
[2146] | 1594 | _return(0); |
---|
[625] | 1595 | } |
---|
[1157] | 1596 | |
---|
[2705] | 1597 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 1598 | |
---|
[1157] | 1599 | if ( ret > 0 && errno == 0 ) { |
---|
[1231] | 1600 | ROAR_WARN("streams_send_mon(id=%i): Overrun in stream: wrote %i of %i bytes, %i bytes missing", id, (int)ret, olen, olen-(int)ret); |
---|
[1157] | 1601 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), ret)*s->info.channels); |
---|
[2635] | 1602 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
[2146] | 1603 | _return(0); |
---|
[1157] | 1604 | } |
---|
[585] | 1605 | } else { |
---|
[1012] | 1606 | errno = 0; |
---|
[625] | 1607 | if ( codecfilter_write(ss->codecfilter_inst, ss->codecfilter, obuf, olen) |
---|
| 1608 | == olen ) { |
---|
[981] | 1609 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[2635] | 1610 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
[2146] | 1611 | _return(0); |
---|
[585] | 1612 | } else { // we cann't retry on codec filetered streams |
---|
[1012] | 1613 | if ( errno != EAGAIN ) { |
---|
| 1614 | streams_delete(id); |
---|
[2146] | 1615 | _return(-1); |
---|
[1012] | 1616 | } |
---|
[585] | 1617 | } |
---|
| 1618 | } |
---|
[0] | 1619 | |
---|
[129] | 1620 | if ( errno == EAGAIN ) { |
---|
| 1621 | // ok, the client blocks for a moment, we try to sleep a bit an retry in the hope not to |
---|
| 1622 | // make any gapes in any output because of this |
---|
| 1623 | |
---|
[1750] | 1624 | #ifdef ROAR_HAVE_USLEEP |
---|
[129] | 1625 | usleep(100); // 0.1ms |
---|
[1750] | 1626 | #endif |
---|
[129] | 1627 | |
---|
[881] | 1628 | if ( stream_vio_s_write(ss, obuf, olen) == olen ) { |
---|
[981] | 1629 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[2635] | 1630 | ss->state = ROAR_STREAMSTATE_OLD; |
---|
[2146] | 1631 | _return(0); |
---|
[1015] | 1632 | } else if ( errno == EAGAIN ) { |
---|
| 1633 | ROAR_WARN("streams_send_mon(id=%i): Can not send data to client: %s", id, strerror(errno)); |
---|
[2146] | 1634 | _return(0); |
---|
[625] | 1635 | } |
---|
[129] | 1636 | } |
---|
| 1637 | |
---|
[0] | 1638 | // ug... error... delete stream! |
---|
| 1639 | |
---|
| 1640 | streams_delete(id); |
---|
| 1641 | |
---|
[2146] | 1642 | _return(-1); |
---|
[0] | 1643 | } |
---|
[2146] | 1644 | #undef _return |
---|
[0] | 1645 | |
---|
| 1646 | int streams_send_filter(int id) { |
---|
| 1647 | int fh; |
---|
[127] | 1648 | int have = 0; |
---|
| 1649 | int len; |
---|
[0] | 1650 | struct roar_stream * s; |
---|
| 1651 | struct roar_stream_server * ss; |
---|
| 1652 | |
---|
[2734] | 1653 | _CHECK_SID(id); |
---|
[0] | 1654 | |
---|
| 1655 | ROAR_DBG("streams_send_filter(id=%i) = ?", id); |
---|
| 1656 | |
---|
[609] | 1657 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
[0] | 1658 | |
---|
| 1659 | if ( (fh = s->fh) == -1 ) |
---|
| 1660 | return 0; |
---|
| 1661 | |
---|
| 1662 | if ( s->dir != ROAR_DIR_FILTER ) |
---|
| 1663 | return 0; |
---|
| 1664 | |
---|
[1585] | 1665 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
| 1666 | return 0; |
---|
| 1667 | |
---|
| 1668 | |
---|
[0] | 1669 | ROAR_DBG("streams_send_filter(id=%i): fh = %i", id, fh); |
---|
| 1670 | |
---|
[881] | 1671 | if ( stream_vio_s_write(ss, g_output_buffer, g_output_buffer_len) == g_output_buffer_len ) { |
---|
[127] | 1672 | while ( have < g_output_buffer_len ) { |
---|
[881] | 1673 | if ( (len = stream_vio_s_read(ss, g_output_buffer+have, g_output_buffer_len-have)) < 1 ) { |
---|
[127] | 1674 | streams_delete(id); |
---|
| 1675 | return -1; |
---|
| 1676 | } |
---|
| 1677 | have += len; |
---|
[0] | 1678 | } |
---|
[127] | 1679 | return 0; |
---|
[0] | 1680 | } |
---|
| 1681 | |
---|
| 1682 | // ug... error... delete stream! |
---|
| 1683 | |
---|
| 1684 | streams_delete(id); |
---|
| 1685 | |
---|
| 1686 | return -1; |
---|
| 1687 | } |
---|
| 1688 | |
---|
[596] | 1689 | |
---|
| 1690 | // VIO: |
---|
| 1691 | |
---|
| 1692 | ssize_t stream_vio_read (int stream, void *buf, size_t count) { |
---|
[2734] | 1693 | _CHECK_SID(stream); |
---|
[596] | 1694 | |
---|
[2734] | 1695 | return stream_vio_s_read(g_streams[stream], buf, count); |
---|
[596] | 1696 | } |
---|
| 1697 | |
---|
| 1698 | ssize_t stream_vio_write(int stream, void *buf, size_t count) { |
---|
[2734] | 1699 | _CHECK_SID(stream); |
---|
[596] | 1700 | |
---|
[2734] | 1701 | return stream_vio_s_write(g_streams[stream], buf, count); |
---|
[596] | 1702 | } |
---|
| 1703 | |
---|
| 1704 | |
---|
| 1705 | ssize_t stream_vio_s_read (struct roar_stream_server * stream, void *buf, size_t count) { |
---|
[2253] | 1706 | void * orig_buf = buf; |
---|
| 1707 | size_t len = 0; |
---|
| 1708 | ssize_t r = -1; |
---|
| 1709 | int i; |
---|
[739] | 1710 | |
---|
[596] | 1711 | errno = 0; |
---|
| 1712 | |
---|
| 1713 | if ( !stream ) |
---|
| 1714 | return -1; |
---|
| 1715 | |
---|
[1613] | 1716 | //roar_vio_set_fh(&(stream->vio), ROAR_STREAM(stream)->fh); |
---|
[881] | 1717 | |
---|
[596] | 1718 | if ( ! stream->vio.read ) |
---|
| 1719 | return -1; |
---|
| 1720 | |
---|
[881] | 1721 | while ( (r = roar_vio_read(&(stream->vio), buf, count)) > 0 ) { |
---|
[739] | 1722 | len += r; |
---|
| 1723 | buf += r; |
---|
| 1724 | count -= r; |
---|
| 1725 | if ( count == 0 ) |
---|
| 1726 | break; |
---|
| 1727 | } |
---|
| 1728 | |
---|
[740] | 1729 | if ( len == 0 && r == -1 ) |
---|
| 1730 | return -1; |
---|
| 1731 | |
---|
[2816] | 1732 | if ( streams_thru_num ) { |
---|
| 1733 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 1734 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { |
---|
| 1735 | if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { |
---|
| 1736 | if ( g_streams[i]->ready ) { |
---|
[2258] | 1737 | if ( stream_vio_write(i, orig_buf, len) != len ) |
---|
| 1738 | streams_delete(i); |
---|
[2252] | 1739 | |
---|
[2816] | 1740 | if ( g_streams[i] != NULL ) |
---|
| 1741 | g_streams[i]->state = ROAR_STREAMSTATE_OLD; |
---|
| 1742 | } |
---|
| 1743 | } |
---|
| 1744 | } |
---|
| 1745 | } |
---|
| 1746 | } |
---|
| 1747 | |
---|
[739] | 1748 | return len; |
---|
[596] | 1749 | } |
---|
| 1750 | |
---|
| 1751 | ssize_t stream_vio_s_write(struct roar_stream_server * stream, void *buf, size_t count) { |
---|
[2259] | 1752 | int i; |
---|
| 1753 | |
---|
[596] | 1754 | errno = 0; |
---|
| 1755 | |
---|
| 1756 | if ( !stream ) |
---|
| 1757 | return -1; |
---|
| 1758 | |
---|
[1613] | 1759 | /* |
---|
[934] | 1760 | if ( roar_vio_get_fh(&(stream->vio)) == -1 && ROAR_STREAM(stream)->fh != -1 ) |
---|
| 1761 | roar_vio_set_fh(&(stream->vio), ROAR_STREAM(stream)->fh); |
---|
[1613] | 1762 | */ |
---|
[934] | 1763 | |
---|
| 1764 | // ROAR_WARN("stream_vio_s_write(*): writing..."); |
---|
[596] | 1765 | |
---|
[2816] | 1766 | if ( streams_thru_num ) { |
---|
| 1767 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 1768 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { |
---|
| 1769 | if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { |
---|
| 1770 | if ( g_streams[i]->ready ) { |
---|
| 1771 | if ( g_streams[i]->state == ROAR_STREAMSTATE_NEW ) { |
---|
| 1772 | if ( streams_get_flag(i, ROAR_FLAG_PRETHRU) == 1 ) { |
---|
| 1773 | if ( stream_prethru_send(i, ROAR_STREAM(stream)->id) == -1 ) { |
---|
| 1774 | streams_delete(i); |
---|
| 1775 | } |
---|
| 1776 | } |
---|
| 1777 | } |
---|
| 1778 | |
---|
| 1779 | if ( stream_vio_write(i, buf, count) != count ) { |
---|
[2259] | 1780 | streams_delete(i); |
---|
[2816] | 1781 | } |
---|
| 1782 | |
---|
| 1783 | if ( g_streams[i] != NULL ) |
---|
| 1784 | g_streams[i]->state = ROAR_STREAMSTATE_OLD; |
---|
| 1785 | } |
---|
| 1786 | } |
---|
| 1787 | } |
---|
| 1788 | } |
---|
| 1789 | } |
---|
[2259] | 1790 | |
---|
[881] | 1791 | return roar_vio_write(&(stream->vio), buf, count); |
---|
[596] | 1792 | } |
---|
| 1793 | |
---|
[0] | 1794 | //ll |
---|