[0] | 1 | //streams.c: |
---|
| 2 | |
---|
[668] | 3 | /* |
---|
[3358] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[668] | 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[668] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[0] | 26 | #include "roard.h" |
---|
| 27 | |
---|
[2734] | 28 | #define _CHECK_SID_RET(id,ret) if ( (id) < 0 || (id) > ROAR_STREAMS_MAX || g_streams[(id)] == NULL ) return (ret) |
---|
| 29 | #define _CHECK_SID(id) _CHECK_SID_RET((id), -1) |
---|
| 30 | |
---|
[2417] | 31 | int streams_thru_num = 0; |
---|
| 32 | int streams_recsource_id = -1; |
---|
[2254] | 33 | |
---|
[4336] | 34 | static void _streams_change_state(struct roar_stream_server * s, const int new, const char * func) { |
---|
| 35 | register int id = ROAR_STREAM(s)->id; |
---|
| 36 | register int old = s->state; |
---|
| 37 | |
---|
| 38 | s->state = new; |
---|
| 39 | |
---|
| 40 | if ( func == NULL ) { |
---|
| 41 | func = "(unknown)"; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | ROAR_INFO("_streams_change_state[by %s](id=%i): stream state: %s->%s", ROAR_DBG_INFO_VERBOSE, |
---|
| 45 | func, |
---|
| 46 | ROAR_STREAM(s)->id, |
---|
| 47 | roar_streamstate2str(old), roar_streamstate2str(new)); |
---|
| 48 | |
---|
| 49 | roar_notify_core_emit_simple(ROAR_OE_BASICS_CHANGE_STATE, -1, id, ROAR_OT_STREAM, old, new, NULL, 0); |
---|
| 50 | } |
---|
| 51 | |
---|
[0] | 52 | int streams_init (void) { |
---|
| 53 | int i; |
---|
| 54 | |
---|
| 55 | for (i = 0; i < ROAR_STREAMS_MAX; i++) |
---|
| 56 | g_streams[i] = NULL; |
---|
| 57 | |
---|
| 58 | return 0; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | int streams_free (void) { |
---|
| 62 | int i; |
---|
| 63 | |
---|
| 64 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 65 | if ( g_streams[i] != NULL ) { |
---|
| 66 | streams_delete(i); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | return 0; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | int streams_new (void) { |
---|
[16] | 75 | int i, j; |
---|
[494] | 76 | struct roar_stream * n = NULL; |
---|
| 77 | struct roar_stream_server * s = NULL; |
---|
[0] | 78 | |
---|
[1498] | 79 | #ifdef ROAR_SUPPORT_LISTEN |
---|
[1155] | 80 | if ( g_terminate && !g_no_listen ) // don't accept new streams in case of termination state |
---|
[1148] | 81 | return -1; |
---|
[1498] | 82 | #else |
---|
| 83 | if ( g_terminate ) // don't accept new streams in case of termination state |
---|
| 84 | return -1; |
---|
| 85 | #endif |
---|
[1148] | 86 | |
---|
[0] | 87 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 88 | if ( g_streams[i] == NULL ) { |
---|
[3063] | 89 | s = ROAR_STREAM_SERVER(n = ROAR_STREAM(roar_mm_malloc(sizeof(struct roar_stream_server)))); |
---|
[0] | 90 | if ( n == NULL ) { |
---|
| 91 | ROAR_ERR("streams_new(void): can not allocate memory for new stream: %s", strerror(errno)); |
---|
| 92 | ROAR_DBG("streams_new(void) = -1"); |
---|
| 93 | return -1; |
---|
| 94 | } |
---|
| 95 | |
---|
[3671] | 96 | memset(s, 0, sizeof(struct roar_stream_server)); |
---|
| 97 | |
---|
[0] | 98 | n->id = i; |
---|
| 99 | n->fh = -1; |
---|
[2714] | 100 | n->pos_rel_id = -1; |
---|
[1804] | 101 | /* |
---|
[0] | 102 | n->database = NULL; |
---|
| 103 | n->dataoff = NULL; |
---|
| 104 | n->datalen = 0; |
---|
| 105 | n->offset = 0; |
---|
[1804] | 106 | */ |
---|
[381] | 107 | n->pos = 0; |
---|
[0] | 108 | |
---|
[1842] | 109 | s->name = NULL; |
---|
| 110 | |
---|
[2611] | 111 | s->state = ROAR_STREAMSTATE_INITING; |
---|
| 112 | |
---|
[494] | 113 | s->client = -1; |
---|
| 114 | s->socktype = ROAR_SOCKET_TYPE_UNKNOWN; |
---|
| 115 | s->buffer = NULL; |
---|
| 116 | s->need_extra = 0; |
---|
| 117 | s->output = NULL; |
---|
| 118 | s->is_new = 1; |
---|
| 119 | s->codecfilter = -1; |
---|
[538] | 120 | s->pre_underruns = 0; |
---|
| 121 | s->post_underruns = 0; |
---|
[1137] | 122 | s->delay = 0; |
---|
[538] | 123 | s->codec_orgi = -1; |
---|
[643] | 124 | s->primary = 0; |
---|
[1913] | 125 | s->ready = 0; |
---|
[2151] | 126 | s->outputbuffer = NULL; |
---|
[2816] | 127 | s->prethru = NULL; |
---|
[3213] | 128 | s->mixer_stream = -1; |
---|
[3630] | 129 | s->role = ROAR_ROLE_UNKNOWN; |
---|
[4099] | 130 | s->parent_stream = -1; |
---|
[494] | 131 | |
---|
| 132 | s->mixer.scale = 65535; |
---|
| 133 | s->mixer.rpg_mul = 1; |
---|
| 134 | s->mixer.rpg_div = 1; |
---|
[16] | 135 | for (j = 0; j < ROAR_MAX_CHANNELS; j++) |
---|
[494] | 136 | s->mixer.mixer[j] = 65535; |
---|
| 137 | |
---|
[1498] | 138 | #ifdef ROAR_SUPPORT_META |
---|
[90] | 139 | for (j = 0; j < ROAR_META_MAX_PER_STREAM; j++) { |
---|
[494] | 140 | s->meta[j].type = ROAR_META_TYPE_NONE; |
---|
| 141 | s->meta[j].key[0] = 0; |
---|
| 142 | s->meta[j].value = NULL; |
---|
[90] | 143 | } |
---|
[1498] | 144 | #endif |
---|
[0] | 145 | |
---|
[592] | 146 | roar_vio_init_calls(&(s->vio)); |
---|
[3042] | 147 | roar_vio_init_calls(&(s->jumbo)); |
---|
| 148 | s->viop = &(s->vio); |
---|
[930] | 149 | s->driver_id = -1; |
---|
[1030] | 150 | s->flags = ROAR_FLAG_NONE; |
---|
[592] | 151 | |
---|
[4361] | 152 | s->mixerstream = NULL; |
---|
| 153 | |
---|
[1857] | 154 | //roardsp_fchain_init(&(s->fc)); |
---|
[981] | 155 | |
---|
[494] | 156 | g_streams[i] = s; |
---|
[4101] | 157 | counters_inc(streams, 1); |
---|
[4237] | 158 | ROAR_INFO("streams_new(void): New stream %i created (state=initing)", ROAR_DBG_INFO_VERBOSE, i); |
---|
[491] | 159 | ROAR_DBG("streams_new(void): n->id=%i", n->id); |
---|
[4346] | 160 | roar_notify_core_emit_snoargs(ROAR_OE_BASICS_NEW, -1, i, ROAR_OT_STREAM); |
---|
[0] | 161 | ROAR_DBG("streams_new(void) = %i", i); |
---|
| 162 | return i; |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | return -1; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | int streams_delete (int id) { |
---|
[643] | 170 | struct roar_stream_server * s; |
---|
[645] | 171 | int prim; |
---|
[1245] | 172 | int no_vio_close = 0; |
---|
[1836] | 173 | int i; |
---|
[2609] | 174 | int client; |
---|
[645] | 175 | |
---|
[2734] | 176 | _CHECK_SID(id); |
---|
| 177 | |
---|
[643] | 178 | if ( (s = g_streams[id]) == NULL ) |
---|
[0] | 179 | return 0; |
---|
| 180 | |
---|
| 181 | ROAR_DBG("streams_delete(id=%i) = ?", id); |
---|
[643] | 182 | ROAR_DBG("streams_delete(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(s)->id); |
---|
[0] | 183 | |
---|
[2611] | 184 | // in case we are allready closing it... |
---|
| 185 | if ( s->state == ROAR_STREAMSTATE_CLOSING ) |
---|
| 186 | return 0; |
---|
| 187 | |
---|
[4336] | 188 | _streams_change_state(s, ROAR_STREAMSTATE_CLOSING, "streams_delete"); |
---|
[4346] | 189 | roar_notify_core_emit_snoargs(ROAR_OE_BASICS_DELETE, -1, id, ROAR_OT_STREAM); |
---|
[2611] | 190 | |
---|
[4101] | 191 | counters_inc(streams, -1); |
---|
| 192 | |
---|
[2417] | 193 | if ( streams_get_flag(id, ROAR_FLAG_RECSOURCE) == 1 ) |
---|
| 194 | streams_reset_flag(id, ROAR_FLAG_RECSOURCE); |
---|
| 195 | |
---|
[1836] | 196 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 197 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == id ) { |
---|
[2239] | 198 | switch (ROAR_STREAM(g_streams[i])->dir) { |
---|
| 199 | case ROAR_DIR_THRU: |
---|
| 200 | case ROAR_DIR_RAW_IN: |
---|
[2592] | 201 | if ( i != id ) |
---|
| 202 | streams_delete(i); |
---|
[2239] | 203 | break; |
---|
| 204 | default: |
---|
[2592] | 205 | if ( streams_get_flag(i, ROAR_FLAG_VIRTUAL) == 1 ) { |
---|
[2609] | 206 | if ( i != id ) { |
---|
| 207 | ROAR_DBG("streams_delete(id=%i): Deleting virtual child stream %i", id, i); |
---|
[2592] | 208 | streams_delete(i); |
---|
[2609] | 209 | } |
---|
[2592] | 210 | } else { |
---|
| 211 | ROAR_STREAM(g_streams[i])->pos_rel_id = -1; |
---|
| 212 | } |
---|
[1836] | 213 | } |
---|
| 214 | } |
---|
| 215 | } |
---|
| 216 | |
---|
[2255] | 217 | if ( ROAR_STREAM(s)->dir == ROAR_DIR_THRU ) |
---|
| 218 | streams_thru_num--; |
---|
| 219 | |
---|
[2603] | 220 | if ( streams_get_flag(id, ROAR_FLAG_VIRTUAL) == 1 ) { |
---|
[2605] | 221 | // we un-group the stream here to avoid a client deleting the parent deleting the client deleting ... |
---|
[2609] | 222 | i = ROAR_STREAM(s)->pos_rel_id; |
---|
| 223 | if ( i != -1 ) { |
---|
| 224 | ROAR_STREAM(s)->pos_rel_id = -1; |
---|
| 225 | client = streams_get_client(id); |
---|
| 226 | streams_set_client(id, -1); |
---|
| 227 | ROAR_DBG("streams_delete(id=%i): Stream has flag virtual, notifying parent stream %i", id, i); |
---|
[2612] | 228 | streams_ctl(i, ROAR_CODECFILTER_CTL_VIRTUAL_DELETE|ROAR_STREAM_CTL_TYPE_INT, &id); |
---|
[2609] | 229 | ROAR_DBG("streams_delete(id=%i): Notify send to stream %i", id, i); |
---|
| 230 | streams_set_client(id, client); |
---|
| 231 | ROAR_STREAM(s)->pos_rel_id = i; |
---|
| 232 | } |
---|
[2603] | 233 | } |
---|
| 234 | |
---|
[1498] | 235 | #ifdef ROAR_SUPPORT_META |
---|
[1045] | 236 | // delete meta data form other meta streams if needed |
---|
| 237 | if ( streams_get_flag(id, ROAR_FLAG_META) == 1 ) { |
---|
| 238 | ROAR_DBG("streams_delete(id=%i): deleting meta stream!", id); |
---|
| 239 | stream_meta_clear(id); |
---|
| 240 | stream_meta_finalize(id); |
---|
| 241 | } |
---|
[1498] | 242 | #endif |
---|
[1045] | 243 | |
---|
[643] | 244 | if ( s->codecfilter != -1 ) { |
---|
| 245 | codecfilter_close(s->codecfilter_inst, s->codecfilter); |
---|
| 246 | s->codecfilter_inst = NULL; |
---|
| 247 | s->codecfilter = -1; |
---|
| 248 | } |
---|
| 249 | |
---|
[936] | 250 | if ( s->driver_id != -1 ) { |
---|
[937] | 251 | driver_closevio(&(s->vio), s->driver_id); |
---|
[936] | 252 | roar_vio_init_calls(&(s->vio)); |
---|
| 253 | s->driver_id = -1; |
---|
[1245] | 254 | no_vio_close = 1; |
---|
[936] | 255 | } |
---|
| 256 | |
---|
[4361] | 257 | if ( s->mixerstream != NULL ) { |
---|
| 258 | hwmixer_close(id); |
---|
| 259 | } |
---|
| 260 | |
---|
[1857] | 261 | //roardsp_fchain_uninit(&(s->fc)); |
---|
[981] | 262 | |
---|
[643] | 263 | if ( s->client != -1 ) { |
---|
| 264 | ROAR_DBG("streams_delete(id=%i): Stream is owned by client %i", id, g_streams[id]->client); |
---|
| 265 | client_stream_delete(s->client, id); |
---|
[269] | 266 | } |
---|
| 267 | |
---|
[2151] | 268 | stream_outputbuffer_destroy(id); |
---|
[2816] | 269 | stream_prethru_destroy(id); |
---|
[2151] | 270 | |
---|
[643] | 271 | if ( s->buffer != NULL ) |
---|
| 272 | roar_buffer_free(s->buffer); |
---|
| 273 | |
---|
| 274 | if ( s->output != NULL ) |
---|
| 275 | free(s->output); |
---|
| 276 | |
---|
[1243] | 277 | /* |
---|
[643] | 278 | if ( ROAR_STREAM(s)->fh != -1 ) |
---|
| 279 | close(ROAR_STREAM(s)->fh); |
---|
[1243] | 280 | */ |
---|
| 281 | |
---|
[1245] | 282 | if ( !no_vio_close ) |
---|
[3042] | 283 | roar_vio_close(s->viop); |
---|
[643] | 284 | |
---|
[645] | 285 | prim = s->primary; |
---|
[0] | 286 | |
---|
[1842] | 287 | if ( s->name != NULL ) |
---|
| 288 | free(s->name); |
---|
| 289 | |
---|
[3063] | 290 | roar_mm_free(s); |
---|
[0] | 291 | |
---|
| 292 | g_streams[id] = NULL; |
---|
| 293 | |
---|
[4102] | 294 | if ( prim && alive ) { |
---|
[645] | 295 | alive = 0; |
---|
| 296 | clean_quit(); |
---|
| 297 | } |
---|
| 298 | |
---|
[4238] | 299 | ROAR_INFO("streams_delete(id=%i): stream deleted", ROAR_DBG_INFO_VERBOSE, id); |
---|
[0] | 300 | ROAR_DBG("streams_delete(id=%i) = 0", id); |
---|
| 301 | return 0; |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | int streams_set_client (int id, int client) { |
---|
[2734] | 305 | |
---|
| 306 | _CHECK_SID(id); |
---|
[0] | 307 | |
---|
[491] | 308 | ROAR_DBG("streams_set_client(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(g_streams[id])->id); |
---|
[0] | 309 | g_streams[id]->client = client; |
---|
| 310 | |
---|
| 311 | return 0; |
---|
| 312 | } |
---|
| 313 | |
---|
[766] | 314 | int streams_get_client (int id) { |
---|
[2734] | 315 | _CHECK_SID(id); |
---|
[766] | 316 | |
---|
| 317 | return g_streams[id]->client; |
---|
| 318 | } |
---|
| 319 | |
---|
[1609] | 320 | int streams_set_dir (int id, int dir, int defaults) { |
---|
| 321 | struct roar_stream_server * ss; |
---|
| 322 | |
---|
[2734] | 323 | _CHECK_SID(id); |
---|
| 324 | |
---|
[1609] | 325 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 326 | return -1; |
---|
| 327 | |
---|
| 328 | ROAR_STREAM(ss)->dir = dir; |
---|
| 329 | |
---|
[2255] | 330 | if ( dir == ROAR_DIR_THRU ) |
---|
| 331 | streams_thru_num++; |
---|
| 332 | |
---|
[1609] | 333 | if ( defaults ) { |
---|
| 334 | if ( dir <= 0 || dir >= ROAR_DIR_DIRIDS ) |
---|
| 335 | return -1; |
---|
| 336 | |
---|
[2387] | 337 | ROAR_DBG("streams_set_dir(*): g_config->streams[dir=%i].flags = 0x%.4x", dir, g_config->streams[dir].flags); |
---|
[1906] | 338 | |
---|
| 339 | if ( streams_set_flag(id, g_config->streams[dir].flags) == -1 ) { |
---|
| 340 | ROAR_DBG("streams_set_dir(*) = -1 // can not set stream flags"); |
---|
[1609] | 341 | return -1; |
---|
[1906] | 342 | } |
---|
[1609] | 343 | |
---|
| 344 | ss->mixer.scale = g_config->streams[dir].mixer.scale; |
---|
| 345 | ss->mixer.rpg_mul = g_config->streams[dir].mixer.rpg_mul; |
---|
| 346 | ss->mixer.rpg_div = g_config->streams[dir].mixer.rpg_div; |
---|
| 347 | } |
---|
| 348 | |
---|
[3214] | 349 | if ( dir != ROAR_DIR_MIXING ) { |
---|
| 350 | switch (streams_get_subsys(id)) { |
---|
| 351 | case ROAR_SUBSYS_WAVEFORM: |
---|
| 352 | streams_set_mixer_stream(id, g_waveform_mixer.stream); |
---|
[3539] | 353 | roardsp_chanlist_init(ss->chanmap.in, ROAR_STREAM(ss)->info.channels, ROARDSP_CHANLIST_MAP_ROARAUDIO); |
---|
[3214] | 354 | break; |
---|
| 355 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
| 356 | case ROAR_SUBSYS_MIDI: |
---|
[3544] | 357 | roardsp_chanlist_init(ss->chanmap.in, ROAR_STREAM(ss)->info.channels, ROARDSP_CHANLIST_MAP_MIDI); |
---|
[3214] | 358 | streams_set_mixer_stream(id, g_midi_mixer.stream); |
---|
| 359 | break; |
---|
| 360 | #endif |
---|
| 361 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
| 362 | case ROAR_SUBSYS_LIGHT: |
---|
| 363 | streams_set_mixer_stream(id, g_light_mixer.stream); |
---|
| 364 | break; |
---|
| 365 | #endif |
---|
| 366 | } |
---|
[3544] | 367 | |
---|
| 368 | memcpy(ss->chanmap.out, ss->chanmap.in, sizeof(ss->chanmap.out)); |
---|
[3546] | 369 | streams_set_map(id, NULL, 0); |
---|
[3214] | 370 | } else { |
---|
| 371 | streams_set_mixer_stream(id, id); |
---|
| 372 | } |
---|
| 373 | |
---|
[1906] | 374 | ROAR_DBG("streams_set_dir(*) = 0"); |
---|
[1609] | 375 | return 0; |
---|
| 376 | } |
---|
[766] | 377 | |
---|
[2251] | 378 | int streams_get_dir (int id) { |
---|
| 379 | struct roar_stream_server * ss; |
---|
| 380 | |
---|
[2734] | 381 | _CHECK_SID(id); |
---|
| 382 | |
---|
[2251] | 383 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 384 | return -1; |
---|
| 385 | |
---|
| 386 | return ROAR_STREAM(ss)->dir; |
---|
| 387 | } |
---|
| 388 | |
---|
[3213] | 389 | int streams_set_mixer_stream(int id, int mixer) { |
---|
| 390 | struct roar_stream_server * ss; |
---|
| 391 | |
---|
| 392 | _CHECK_SID(id); |
---|
| 393 | |
---|
| 394 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 395 | return -1; |
---|
| 396 | |
---|
| 397 | ss->mixer_stream = mixer; |
---|
| 398 | |
---|
| 399 | return 0; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | int streams_get_mixer_stream(int id, int mixer) { |
---|
| 403 | struct roar_stream_server * ss; |
---|
| 404 | |
---|
| 405 | _CHECK_SID(id); |
---|
| 406 | |
---|
| 407 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 408 | return -1; |
---|
| 409 | |
---|
| 410 | return ss->mixer_stream; |
---|
| 411 | } |
---|
| 412 | |
---|
[3630] | 413 | int streams_set_role (int id, int role) { |
---|
| 414 | struct roar_stream_server * ss; |
---|
| 415 | |
---|
| 416 | _CHECK_SID(id); |
---|
| 417 | |
---|
| 418 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 419 | return -1; |
---|
| 420 | |
---|
| 421 | ss->role = role; |
---|
| 422 | |
---|
| 423 | return 0; |
---|
| 424 | } |
---|
| 425 | |
---|
[2415] | 426 | int streams_get_subsys (int id) { |
---|
| 427 | struct roar_stream_server * ss; |
---|
| 428 | |
---|
[2734] | 429 | _CHECK_SID(id); |
---|
| 430 | |
---|
[2415] | 431 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 432 | return -1; |
---|
| 433 | |
---|
| 434 | switch (ROAR_STREAM(ss)->dir) { |
---|
| 435 | case ROAR_DIR_PLAY: |
---|
| 436 | case ROAR_DIR_RECORD: |
---|
| 437 | case ROAR_DIR_MONITOR: |
---|
| 438 | case ROAR_DIR_FILTER: |
---|
| 439 | case ROAR_DIR_OUTPUT: |
---|
| 440 | case ROAR_DIR_BIDIR: |
---|
| 441 | return ROAR_SUBSYS_WAVEFORM; |
---|
| 442 | break; |
---|
| 443 | case ROAR_DIR_MIDI_IN: |
---|
| 444 | case ROAR_DIR_MIDI_OUT: |
---|
| 445 | return ROAR_SUBSYS_MIDI; |
---|
| 446 | break; |
---|
| 447 | case ROAR_DIR_LIGHT_IN: |
---|
| 448 | case ROAR_DIR_LIGHT_OUT: |
---|
| 449 | return ROAR_SUBSYS_LIGHT; |
---|
| 450 | break; |
---|
| 451 | case ROAR_DIR_RAW_IN: |
---|
| 452 | case ROAR_DIR_RAW_OUT: |
---|
| 453 | return ROAR_SUBSYS_RAW; |
---|
| 454 | break; |
---|
[2681] | 455 | case ROAR_DIR_COMPLEX_IN: |
---|
| 456 | case ROAR_DIR_COMPLEX_OUT: |
---|
| 457 | return ROAR_SUBSYS_COMPLEX; |
---|
| 458 | break; |
---|
[2415] | 459 | case ROAR_DIR_THRU: |
---|
| 460 | return streams_get_subsys(ROAR_STREAM(ss)->pos_rel_id); |
---|
| 461 | break; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | return -1; |
---|
| 465 | } |
---|
| 466 | |
---|
[3542] | 467 | int streams_get_ssdir (int id) { |
---|
| 468 | struct roar_stream_server * ss; |
---|
| 469 | |
---|
| 470 | _CHECK_SID(id); |
---|
| 471 | |
---|
| 472 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 473 | return -1; |
---|
| 474 | |
---|
| 475 | switch (ROAR_STREAM(ss)->dir) { |
---|
| 476 | case ROAR_DIR_PLAY: |
---|
| 477 | case ROAR_DIR_MIDI_IN: |
---|
| 478 | case ROAR_DIR_LIGHT_IN: |
---|
| 479 | case ROAR_DIR_RAW_IN: |
---|
| 480 | case ROAR_DIR_COMPLEX_IN: |
---|
| 481 | return STREAM_DIR_IN; |
---|
| 482 | break; |
---|
| 483 | case ROAR_DIR_RECORD: |
---|
| 484 | case ROAR_DIR_MONITOR: |
---|
| 485 | case ROAR_DIR_OUTPUT: |
---|
| 486 | case ROAR_DIR_MIDI_OUT: |
---|
| 487 | case ROAR_DIR_LIGHT_OUT: |
---|
| 488 | case ROAR_DIR_RAW_OUT: |
---|
| 489 | case ROAR_DIR_COMPLEX_OUT: |
---|
| 490 | return STREAM_DIR_OUT; |
---|
| 491 | break; |
---|
| 492 | case ROAR_DIR_MIXING: |
---|
| 493 | return STREAM_DIR_NONE; |
---|
| 494 | break; |
---|
| 495 | case ROAR_DIR_FILTER: |
---|
| 496 | case ROAR_DIR_BIDIR: |
---|
| 497 | return STREAM_DIR_BIDIR; |
---|
| 498 | break; |
---|
| 499 | case ROAR_DIR_THRU: |
---|
| 500 | return streams_get_ssdir(ROAR_STREAM(ss)->pos_rel_id); |
---|
| 501 | break; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | return -1; |
---|
| 505 | } |
---|
| 506 | |
---|
[2593] | 507 | #define _err() streams_delete(id); return -1; |
---|
[2594] | 508 | int streams_new_virtual (int parent, struct roar_stream_server ** stream) { |
---|
[2593] | 509 | struct roar_stream_server * parent_ss, * ss; |
---|
| 510 | struct roar_stream * parent_s , * s; |
---|
| 511 | int id = -1; |
---|
| 512 | int client, dir; |
---|
| 513 | |
---|
| 514 | if ( streams_get(parent, &parent_ss) == -1 ) |
---|
| 515 | return -1; |
---|
| 516 | |
---|
| 517 | if ( (client = streams_get_client(parent)) == -1 ) |
---|
| 518 | return -1; |
---|
| 519 | |
---|
| 520 | if ( (dir = streams_get_dir(parent)) == -1 ) |
---|
| 521 | return -1; |
---|
| 522 | |
---|
| 523 | if ( (id = streams_new()) == -1 ) { |
---|
| 524 | return -1; |
---|
| 525 | } |
---|
| 526 | |
---|
[2597] | 527 | if ( client_stream_add(client, id) == -1 ) { |
---|
[2593] | 528 | _err(); |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | if ( streams_get(id, &ss) == -1 ) { |
---|
| 532 | _err(); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | if ( streams_set_dir(id, dir, 1) == -1 ) { |
---|
| 536 | _err(); |
---|
| 537 | } |
---|
| 538 | |
---|
| 539 | s = ROAR_STREAM( ss); |
---|
| 540 | parent_s = ROAR_STREAM(parent_ss); |
---|
| 541 | |
---|
[2596] | 542 | s->pos_rel_id = parent; |
---|
[2593] | 543 | |
---|
[2625] | 544 | if ( streams_set_rawflag(id, ROAR_FLAG_VIRTUAL) == -1 ) { |
---|
[2593] | 545 | _err(); |
---|
| 546 | } |
---|
| 547 | |
---|
[2596] | 548 | if ( stream != NULL ) |
---|
[2594] | 549 | *stream = ss; |
---|
| 550 | |
---|
[2593] | 551 | return id; |
---|
| 552 | } |
---|
| 553 | #undef _err |
---|
| 554 | |
---|
[0] | 555 | int streams_set_fh (int id, int fh) { |
---|
[1243] | 556 | struct roar_stream_server * ss; |
---|
[1913] | 557 | struct roar_stream * s; |
---|
[51] | 558 | int dir; |
---|
[2361] | 559 | int nonblock = 1; |
---|
[51] | 560 | |
---|
[2734] | 561 | _CHECK_SID(id); |
---|
| 562 | |
---|
[1913] | 563 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
[0] | 564 | return -1; |
---|
| 565 | |
---|
[4240] | 566 | if ( ss->ready ) { |
---|
| 567 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = -1 // try to set fh for stream which is already ready", id, fh); |
---|
[4229] | 568 | return -1; |
---|
[4240] | 569 | } |
---|
[4229] | 570 | |
---|
[2816] | 571 | dir = ROAR_STREAM(ss)->dir; |
---|
| 572 | |
---|
[4240] | 573 | ROAR_DBG("streams_set_fh(id=%i, fh=%i): g_streams[id]->id=%i", id, fh, s->id); |
---|
[491] | 574 | |
---|
[1913] | 575 | s->fh = fh; |
---|
[0] | 576 | |
---|
[1243] | 577 | ROAR_DBG("streams_set_fh(id=%i, fh=%i): driverID=%i", id, fh, ss->driver_id); |
---|
| 578 | |
---|
[2766] | 579 | if ( ss->driver_id == -1 && fh != -2 ) { |
---|
| 580 | #ifndef ROAR_TARGET_WIN32 |
---|
[1243] | 581 | roar_vio_set_fh(&(ss->vio), fh); |
---|
[2766] | 582 | #else |
---|
| 583 | roar_vio_open_fh_socket(&(ss->vio), fh); |
---|
| 584 | #endif |
---|
| 585 | } |
---|
[1243] | 586 | |
---|
[2816] | 587 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 588 | |
---|
[2840] | 589 | switch (dir) { |
---|
| 590 | case ROAR_DIR_THRU: |
---|
| 591 | case ROAR_DIR_RAW_IN: |
---|
| 592 | case ROAR_DIR_RAW_OUT: |
---|
| 593 | break; |
---|
| 594 | default: |
---|
| 595 | if ( codecfilter_open(&(ss->codecfilter_inst), &(ss->codecfilter), NULL, |
---|
| 596 | s->info.codec, ss) == -1 ) { |
---|
| 597 | streams_delete(id); // TODO: FIXME: is this correct? shoudn't we return -1 in any case here? |
---|
| 598 | return -1; |
---|
| 599 | } |
---|
| 600 | break; |
---|
[571] | 601 | } |
---|
[268] | 602 | |
---|
[2816] | 603 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 604 | |
---|
[1610] | 605 | if ( fh == -2 ) { |
---|
| 606 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 607 | if ( roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_GET_READ_FH, &fh) == -1 ) { |
---|
| 608 | fh = -2; |
---|
| 609 | } else { |
---|
| 610 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 611 | if ( fh < 0 ) { |
---|
| 612 | fh = -2; |
---|
| 613 | } else { |
---|
[1913] | 614 | s->fh = fh; |
---|
[1610] | 615 | } |
---|
| 616 | } |
---|
| 617 | } |
---|
| 618 | |
---|
[2816] | 619 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
| 620 | |
---|
[1610] | 621 | if ( fh == -1 || fh == -2 ) { // yes, this is valid, indecats full vio! |
---|
[1913] | 622 | ss->ready = 1; |
---|
[4336] | 623 | //ROAR_INFO("streams_set_fh(id=%i, fh=%i): stream state: %s->new", ROAR_DBG_INFO_VERBOSE, id, fh, roar_streamstate2str(ss->state)); |
---|
| 624 | _streams_change_state(ss, ROAR_STREAMSTATE_NEW, "streams_set_fh"); |
---|
[634] | 625 | return 0; |
---|
| 626 | } |
---|
| 627 | |
---|
[2816] | 628 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = ?", id, fh); |
---|
[968] | 629 | |
---|
[2816] | 630 | // roar_socket_recvbuf(fh, ROAR_OUTPUT_CALC_OUTBUFSIZE( &(ROAR_STREAM(g_streams[id])->info) )); // set recv buffer to minimum |
---|
[51] | 631 | |
---|
[1912] | 632 | switch (dir) { |
---|
| 633 | case ROAR_DIR_MONITOR: |
---|
| 634 | case ROAR_DIR_RECORD: |
---|
| 635 | case ROAR_DIR_OUTPUT: |
---|
| 636 | case ROAR_DIR_MIDI_OUT: |
---|
| 637 | case ROAR_DIR_LIGHT_OUT: |
---|
[2248] | 638 | case ROAR_DIR_RAW_OUT: |
---|
[1912] | 639 | ROAR_SHUTDOWN(fh, SHUT_RD); |
---|
| 640 | break; |
---|
[51] | 641 | } |
---|
| 642 | |
---|
[2337] | 643 | if ( dir >= ROAR_DIR_DIRIDS ) |
---|
| 644 | return -1; |
---|
| 645 | |
---|
| 646 | if ( g_config->streams[dir].flags & ROAR_FLAG_SYNC ) { |
---|
[2361] | 647 | switch (dir) { |
---|
| 648 | case ROAR_DIR_BRIDGE: |
---|
| 649 | case ROAR_DIR_MIDI_OUT: |
---|
| 650 | break; |
---|
| 651 | default: |
---|
| 652 | nonblock = 0; |
---|
| 653 | break; |
---|
| 654 | } |
---|
| 655 | } |
---|
| 656 | |
---|
| 657 | |
---|
| 658 | if ( !nonblock ) { |
---|
[1913] | 659 | ss->ready = 1; |
---|
[4336] | 660 | //ROAR_INFO("streams_set_fh(id=%i, fh=%i): stream state: %s->new", ROAR_DBG_INFO_VERBOSE, id, fh, roar_streamstate2str(ss->state)); |
---|
| 661 | _streams_change_state(ss, ROAR_STREAMSTATE_NEW, "streams_set_fh"); |
---|
[2816] | 662 | |
---|
| 663 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); |
---|
[0] | 664 | return 0; |
---|
| 665 | } else { |
---|
[2764] | 666 | #ifndef ROAR_TARGET_WIN32 |
---|
[1913] | 667 | if ( roar_socket_nonblock(fh, ROAR_SOCKET_NONBLOCK) == -1 ) |
---|
| 668 | return -1; |
---|
[2764] | 669 | #endif |
---|
[1913] | 670 | |
---|
| 671 | ss->ready = 1; |
---|
[4336] | 672 | //ROAR_INFO("streams_set_fh(id=%i, fh=%i): stream state: %s->new", ROAR_DBG_INFO_VERBOSE, id, fh, roar_streamstate2str(ss->state)); |
---|
| 673 | _streams_change_state(ss, ROAR_STREAMSTATE_NEW, "streams_set_fh"); |
---|
[2816] | 674 | |
---|
| 675 | ROAR_DBG("streams_set_fh(id=%i, fh=%i) = 0", id, fh); |
---|
[1913] | 676 | return 0; |
---|
[0] | 677 | } |
---|
| 678 | } |
---|
| 679 | |
---|
[66] | 680 | int streams_get_fh (int id) { |
---|
[2734] | 681 | _CHECK_SID(id); |
---|
[66] | 682 | |
---|
[609] | 683 | return ROAR_STREAM(g_streams[id])->fh; |
---|
[66] | 684 | } |
---|
[0] | 685 | |
---|
[2606] | 686 | int streams_set_null_io(int id) { |
---|
| 687 | struct roar_stream_server * ss; |
---|
| 688 | struct roar_stream * s; |
---|
| 689 | |
---|
[2734] | 690 | _CHECK_SID(id); |
---|
| 691 | |
---|
[2606] | 692 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
| 693 | return -1; |
---|
| 694 | |
---|
| 695 | s->fh = -1; |
---|
| 696 | |
---|
| 697 | return 0; |
---|
| 698 | } |
---|
| 699 | |
---|
[0] | 700 | int streams_get (int id, struct roar_stream_server ** stream) { |
---|
[2734] | 701 | _CHECK_SID(id); |
---|
[0] | 702 | |
---|
| 703 | *stream = g_streams[id]; |
---|
| 704 | |
---|
| 705 | return 0; |
---|
| 706 | } |
---|
| 707 | |
---|
[377] | 708 | int streams_set_socktype (int id, int socktype) { |
---|
[2734] | 709 | _CHECK_SID(id); |
---|
[377] | 710 | |
---|
| 711 | g_streams[id]->socktype = socktype; |
---|
| 712 | |
---|
| 713 | return 0; |
---|
| 714 | } |
---|
| 715 | |
---|
| 716 | int streams_get_socktype (int id) { |
---|
[2734] | 717 | _CHECK_SID(id); |
---|
[377] | 718 | |
---|
| 719 | return g_streams[id]->socktype; |
---|
| 720 | } |
---|
[0] | 721 | |
---|
[3921] | 722 | int streams_is_ready (int id) { |
---|
| 723 | _CHECK_SID(id); |
---|
| 724 | |
---|
| 725 | return g_streams[id]->ready; |
---|
| 726 | } |
---|
| 727 | |
---|
[643] | 728 | int streams_set_primary (int id, int prim) { |
---|
[2734] | 729 | _CHECK_SID(id); |
---|
[643] | 730 | |
---|
| 731 | g_streams[id]->primary = prim; |
---|
| 732 | |
---|
| 733 | return 0; |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | int streams_mark_primary (int id) { |
---|
| 737 | return streams_set_primary(id, 1); |
---|
| 738 | } |
---|
[1029] | 739 | |
---|
[1116] | 740 | int streams_set_sync (int id, int sync) { |
---|
[1117] | 741 | int fh = streams_get_fh(id); |
---|
[1116] | 742 | |
---|
[2734] | 743 | _CHECK_SID(id); |
---|
| 744 | |
---|
[1117] | 745 | if ( fh != -1 ) { |
---|
| 746 | if ( roar_socket_nonblock(fh, sync ? ROAR_SOCKET_BLOCK : ROAR_SOCKET_NONBLOCK) == -1 ) |
---|
| 747 | return -1; |
---|
[1116] | 748 | |
---|
[1498] | 749 | #ifdef ROAR_FDATASYNC |
---|
[1171] | 750 | ROAR_FDATASYNC(fh); |
---|
[1498] | 751 | #endif |
---|
[1125] | 752 | |
---|
| 753 | return 0; |
---|
[1117] | 754 | } else { |
---|
| 755 | return roar_vio_nonblock(&(g_streams[id]->vio), sync); |
---|
| 756 | } |
---|
[1116] | 757 | } |
---|
| 758 | |
---|
[1928] | 759 | int streams_set_mmap (int id, int reset) { |
---|
| 760 | int use = !reset; |
---|
| 761 | |
---|
[2734] | 762 | _CHECK_SID(id); |
---|
[1928] | 763 | |
---|
| 764 | return roar_vio_ctl(&(g_streams[id]->vio), ROAR_VIO_CTL_SET_UMMAP, &use); |
---|
| 765 | } |
---|
| 766 | |
---|
[1029] | 767 | int streams_set_flag (int id, int flag) { |
---|
[2626] | 768 | int parent; |
---|
| 769 | |
---|
[2734] | 770 | _CHECK_SID(id); |
---|
[1029] | 771 | |
---|
[2952] | 772 | if ( flag & ROAR_FLAG_IMMUTABLE ) |
---|
| 773 | flag |= ROAR_FLAG_PRIMARY; |
---|
| 774 | |
---|
[1926] | 775 | if ( flag & ROAR_FLAG_MMAP ) |
---|
[1928] | 776 | if ( streams_set_mmap(id, 0) == -1 ) |
---|
| 777 | flag -= ROAR_FLAG_MMAP; |
---|
[1926] | 778 | |
---|
[1043] | 779 | if ( flag & ROAR_FLAG_PRIMARY ) { |
---|
| 780 | streams_set_primary(id, 1); |
---|
| 781 | flag -= ROAR_FLAG_PRIMARY; |
---|
| 782 | } |
---|
| 783 | |
---|
[2626] | 784 | if ( flag & ROAR_FLAG_VIRTUAL ) { |
---|
| 785 | if ( (parent = ROAR_STREAM(g_streams[id])->pos_rel_id) == -1 ) |
---|
| 786 | return -1; |
---|
| 787 | |
---|
| 788 | if ( streams_ctl(parent, ROAR_CODECFILTER_CTL_VIRTUAL_NEW|ROAR_STREAM_CTL_TYPE_INT, &id) == -1 ) { |
---|
| 789 | // flag -= ROAR_FLAG_VIRTUAL; |
---|
| 790 | return -1; |
---|
| 791 | } |
---|
[2705] | 792 | |
---|
| 793 | if ( client_stream_move(streams_get_client(parent), id) == -1 ) { |
---|
| 794 | return -1; |
---|
| 795 | } |
---|
[2626] | 796 | } |
---|
| 797 | |
---|
[1116] | 798 | if ( flag & ROAR_FLAG_SYNC ) { |
---|
[1908] | 799 | switch (ROAR_STREAM(g_streams[id])->dir) { |
---|
| 800 | // for this stream types the flag is used in the subsystem: |
---|
| 801 | case ROAR_DIR_BRIDGE: |
---|
| 802 | case ROAR_DIR_MIDI_OUT: |
---|
| 803 | break; |
---|
| 804 | |
---|
| 805 | // normal behavor (vio blocking): |
---|
| 806 | default: |
---|
[2341] | 807 | // the fh is updated as soon as the fh get ready in case the default ask to set sync |
---|
[2342] | 808 | if ( !g_streams[id]->ready && !(g_config->streams[ROAR_STREAM(g_streams[id])->dir].flags & ROAR_FLAG_SYNC) ) { |
---|
[2341] | 809 | if ( streams_set_sync(id, 1) == -1 ) |
---|
| 810 | flag -= ROAR_FLAG_SYNC; |
---|
| 811 | } |
---|
[1908] | 812 | } |
---|
[1116] | 813 | } |
---|
| 814 | |
---|
[1585] | 815 | if ( flag & ROAR_FLAG_HWMIXER ) { // currently not supported -> ignored |
---|
[1590] | 816 | g_streams[id]->flags |= flag; |
---|
| 817 | if ( streams_set_mixer(id) == -1 ) { |
---|
| 818 | g_streams[id]->flags -= flag; |
---|
| 819 | return -1; |
---|
| 820 | } |
---|
[1585] | 821 | } |
---|
| 822 | |
---|
[2417] | 823 | if ( flag & ROAR_FLAG_RECSOURCE ) { |
---|
| 824 | if ( streams_recsource_id != -1 ) { |
---|
| 825 | if ( streams_reset_flag(streams_recsource_id, ROAR_FLAG_RECSOURCE) == -1 ) |
---|
| 826 | return -1; |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | streams_recsource_id = id; |
---|
| 830 | } |
---|
| 831 | |
---|
[1029] | 832 | g_streams[id]->flags |= flag; |
---|
| 833 | |
---|
[1498] | 834 | #ifdef ROAR_SUPPORT_META |
---|
[1043] | 835 | if ( flag & ROAR_FLAG_META ) |
---|
| 836 | stream_meta_finalize(id); |
---|
[1498] | 837 | #endif |
---|
[1043] | 838 | |
---|
[1029] | 839 | return 0; |
---|
| 840 | } |
---|
| 841 | |
---|
[2625] | 842 | int streams_set_rawflag (int id, int flag) { |
---|
[2734] | 843 | _CHECK_SID(id); |
---|
[2625] | 844 | |
---|
| 845 | g_streams[id]->flags |= flag; |
---|
| 846 | |
---|
| 847 | return 0; |
---|
| 848 | } |
---|
| 849 | |
---|
[1029] | 850 | int streams_reset_flag (int id, int flag) { |
---|
[2734] | 851 | _CHECK_SID(id); |
---|
[1029] | 852 | |
---|
[2952] | 853 | if ( g_streams[id]->flags & ROAR_FLAG_IMMUTABLE ) { |
---|
| 854 | flag |= ROAR_FLAG_PRIMARY; |
---|
| 855 | flag -= ROAR_FLAG_PRIMARY; |
---|
| 856 | } |
---|
| 857 | |
---|
[2417] | 858 | if ( flag & ROAR_FLAG_RECSOURCE ) |
---|
| 859 | if ( streams_recsource_id == id ) |
---|
| 860 | streams_recsource_id = -1; |
---|
| 861 | |
---|
[1928] | 862 | if ( flag & ROAR_FLAG_MMAP ) |
---|
| 863 | if ( streams_set_mmap(id, 1) == -1 ) |
---|
| 864 | flag -= ROAR_FLAG_MMAP; |
---|
| 865 | |
---|
[1043] | 866 | if ( flag & ROAR_FLAG_PRIMARY ) { |
---|
| 867 | streams_set_primary(id, 0); |
---|
| 868 | flag -= ROAR_FLAG_PRIMARY; |
---|
| 869 | } |
---|
| 870 | |
---|
[1116] | 871 | if ( flag & ROAR_FLAG_SYNC ) { |
---|
[2264] | 872 | // we refuse to reset the flag on FILTER streams |
---|
| 873 | if ( streams_get_dir(id) == ROAR_DIR_FILTER ) { |
---|
| 874 | // flags -= ROAR_FLAG_SYNC; |
---|
| 875 | return -1; |
---|
| 876 | } else { |
---|
| 877 | streams_set_sync(id, 0); |
---|
| 878 | } |
---|
[1116] | 879 | } |
---|
| 880 | |
---|
[1029] | 881 | g_streams[id]->flags |= flag; |
---|
| 882 | g_streams[id]->flags -= flag; |
---|
| 883 | |
---|
| 884 | return 0; |
---|
| 885 | } |
---|
| 886 | |
---|
[1042] | 887 | int streams_get_flag (int id, int flag) { |
---|
[2734] | 888 | _CHECK_SID(id); |
---|
[1042] | 889 | |
---|
| 890 | return g_streams[id]->flags & flag ? 1 : 0; |
---|
| 891 | } |
---|
| 892 | |
---|
[1842] | 893 | int streams_set_name (int id, char * name) { |
---|
| 894 | char * str; |
---|
| 895 | |
---|
[2734] | 896 | _CHECK_SID(id); |
---|
[1842] | 897 | |
---|
| 898 | if ( (str = strdup(name)) == NULL ) |
---|
| 899 | return -1; |
---|
| 900 | |
---|
| 901 | if ( g_streams[id]->name != NULL ) |
---|
| 902 | free(g_streams[id]->name); |
---|
| 903 | |
---|
| 904 | g_streams[id]->name = str; |
---|
[1845] | 905 | |
---|
| 906 | return 0; |
---|
[1842] | 907 | } |
---|
| 908 | |
---|
| 909 | char * streams_get_name (int id) { |
---|
[2734] | 910 | _CHECK_SID_RET(id, NULL); |
---|
[1842] | 911 | |
---|
| 912 | return g_streams[id]->name; |
---|
| 913 | } |
---|
| 914 | |
---|
| 915 | |
---|
[1223] | 916 | int streams_calc_delay (int id) { |
---|
[1142] | 917 | struct roar_stream_server * ss; |
---|
[1151] | 918 | struct roar_stream * s; |
---|
[1142] | 919 | register uint_least32_t d = 0; |
---|
| 920 | uint_least32_t t[1]; |
---|
[1151] | 921 | uint64_t tmp; |
---|
[1142] | 922 | |
---|
[2734] | 923 | _CHECK_SID(id); |
---|
| 924 | |
---|
[1151] | 925 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
[1142] | 926 | return -1; |
---|
| 927 | |
---|
[3212] | 928 | // mixer store there value in ss->delay directly |
---|
| 929 | if ( s->dir == ROAR_DIR_MIXING ) |
---|
| 930 | return 0; |
---|
| 931 | |
---|
[4157] | 932 | #if 0 |
---|
| 933 | // this only confuses the user... |
---|
[3216] | 934 | if ( ss->mixer_stream != id ) { |
---|
| 935 | if ( streams_calc_delay(ss->mixer_stream) != -1 ) { |
---|
| 936 | d += g_streams[ss->mixer_stream]->delay; // in case we can calc the delay |
---|
| 937 | // the stream must exist, so no check here |
---|
| 938 | } |
---|
| 939 | } |
---|
[4157] | 940 | #endif |
---|
[3216] | 941 | |
---|
[1142] | 942 | if ( ss->codecfilter != -1 ) { |
---|
| 943 | if ( codecfilter_delay(ss->codecfilter_inst, ss->codecfilter, t) != -1 ) |
---|
| 944 | d += *t; |
---|
| 945 | } |
---|
| 946 | |
---|
[1151] | 947 | if ( ss->vio.ctl != NULL ) { |
---|
| 948 | if ( roar_vio_ctl(&(ss->vio), ROAR_VIO_CTL_GET_DELAY, t) != -1 ) { // *t is in byte |
---|
[1223] | 949 | ROAR_DBG("streams_calc_delay(id=%i): VIO delay in byte: %i", id, *t); |
---|
[1151] | 950 | tmp = *t; |
---|
| 951 | tmp *= 1000000; // musec per sec |
---|
| 952 | tmp /= s->info.rate * s->info.channels * (s->info.bits/8); |
---|
[2387] | 953 | ROAR_DBG("streams_calc_delay(id=%i): VIO delay in musec: %llu", id, tmp); |
---|
[1151] | 954 | |
---|
| 955 | d += tmp; |
---|
| 956 | } |
---|
| 957 | } |
---|
| 958 | |
---|
[1223] | 959 | ROAR_DBG("streams_calc_delay(id=%i): delay in musec: %i", id, d); |
---|
[1151] | 960 | |
---|
[1142] | 961 | ss->delay = d; |
---|
| 962 | |
---|
| 963 | return 0; |
---|
| 964 | } |
---|
| 965 | |
---|
[1590] | 966 | int streams_set_mixer (int id) { |
---|
| 967 | struct roar_stream_server * ss; |
---|
[2416] | 968 | struct roar_stream_server * pmss; |
---|
| 969 | int i; |
---|
| 970 | int subsys; |
---|
[1590] | 971 | |
---|
[2734] | 972 | _CHECK_SID(id); |
---|
| 973 | |
---|
[1590] | 974 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 975 | return -1; |
---|
| 976 | |
---|
[2416] | 977 | if ( streams_get_flag(id, ROAR_FLAG_PASSMIXER) == 1 ) { |
---|
| 978 | if ( (subsys = streams_get_subsys(id)) == -1 ) |
---|
| 979 | return -1; |
---|
| 980 | |
---|
| 981 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 982 | if ( (pmss = g_streams[i]) != NULL ) { |
---|
| 983 | if ( streams_get_flag(i, ROAR_FLAG_PASSMIXER) == 1 ) { |
---|
| 984 | if ( streams_get_subsys(i) == subsys ) { |
---|
[4119] | 985 | if ( &(pmss->mixer) != &(ss->mixer) ) { |
---|
| 986 | memcpy(&(pmss->mixer), &(ss->mixer), sizeof(struct roar_mixer_settings)); |
---|
| 987 | } |
---|
[2416] | 988 | |
---|
| 989 | // update hwmixers and the like but do not set mixer value recrusivly. |
---|
| 990 | streams_reset_flag(i, ROAR_FLAG_PASSMIXER); |
---|
| 991 | streams_set_mixer(i); |
---|
| 992 | streams_set_flag(i, ROAR_FLAG_PASSMIXER); |
---|
| 993 | } |
---|
| 994 | } |
---|
| 995 | } |
---|
| 996 | } |
---|
| 997 | } |
---|
| 998 | |
---|
[1590] | 999 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) ) |
---|
| 1000 | return 0; |
---|
| 1001 | |
---|
| 1002 | if ( ss->driver_id == -1 ) |
---|
| 1003 | return 0; |
---|
| 1004 | |
---|
| 1005 | return driver_set_volume(id, &(ss->mixer)); |
---|
| 1006 | } |
---|
| 1007 | |
---|
[3542] | 1008 | int streams_set_map (int id, char * map, size_t len) { |
---|
| 1009 | struct roar_stream_server * ss; |
---|
| 1010 | int ssdir; |
---|
| 1011 | |
---|
| 1012 | _CHECK_SID(id); |
---|
| 1013 | |
---|
| 1014 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1015 | return -1; |
---|
| 1016 | |
---|
| 1017 | if ( map != NULL ) { |
---|
| 1018 | if ( ROAR_STREAM(ss)->info.channels != len ) |
---|
| 1019 | return -1; |
---|
| 1020 | } |
---|
| 1021 | |
---|
[3557] | 1022 | ssdir = streams_get_ssdir(id); |
---|
| 1023 | |
---|
[3542] | 1024 | switch (ssdir) { |
---|
| 1025 | case STREAM_DIR_IN: |
---|
[3557] | 1026 | case STREAM_DIR_NONE: |
---|
[3671] | 1027 | memset(ss->chanmap.in, 0, sizeof(ss->chanmap.in)); |
---|
| 1028 | |
---|
[3556] | 1029 | if ( map != NULL ) |
---|
| 1030 | memcpy(ss->chanmap.in, map, len); |
---|
| 1031 | |
---|
[3542] | 1032 | roardsp_chanmap_calc(&(ss->chanmap), ROARDSP_CHANMAP_MAP, 0); |
---|
| 1033 | break; |
---|
| 1034 | case STREAM_DIR_OUT: |
---|
[3671] | 1035 | memset(ss->chanmap.out, 0, sizeof(ss->chanmap.out)); |
---|
| 1036 | |
---|
[3556] | 1037 | if ( map != NULL ) |
---|
| 1038 | memcpy(ss->chanmap.out, map, len); |
---|
| 1039 | |
---|
| 1040 | roardsp_chanmap_calc(&(ss->chanmap), ROARDSP_CHANMAP_MAP, 0); |
---|
[3542] | 1041 | break; |
---|
[3557] | 1042 | default: |
---|
| 1043 | return -1; |
---|
[3542] | 1044 | } |
---|
| 1045 | |
---|
| 1046 | return 0; |
---|
| 1047 | } |
---|
| 1048 | |
---|
[4272] | 1049 | int streams_ltm_ctl (int id, int mt, int window, int cmd) { |
---|
| 1050 | struct roar_stream_server * ss; |
---|
| 1051 | struct roar_stream_ltm * ltm; |
---|
| 1052 | int i; |
---|
| 1053 | |
---|
| 1054 | _CHECK_SID(id); |
---|
| 1055 | |
---|
| 1056 | // currently we only support the WORKBLOCK window |
---|
| 1057 | if ( window != ROAR_LTM_WIN_WORKBLOCK ) |
---|
| 1058 | return -1; |
---|
| 1059 | |
---|
| 1060 | // currently we only support ROAR_LTM_MT_RMS |
---|
| 1061 | if ( (mt | ROAR_LTM_MT_RMS) - ROAR_LTM_MT_RMS ) |
---|
| 1062 | return -1; |
---|
| 1063 | |
---|
| 1064 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1065 | return -1; |
---|
| 1066 | |
---|
| 1067 | switch (cmd) { |
---|
| 1068 | case ROAR_LTM_SST_NOOP: |
---|
| 1069 | return 0; |
---|
| 1070 | break; |
---|
| 1071 | case ROAR_LTM_SST_REGISTER: |
---|
| 1072 | // test if the window is already registered: |
---|
| 1073 | for (i = 0; i < MAX_LTM_WINDOWS_PER_STREAM; i++) { |
---|
| 1074 | ltm = &(ss->ltm[i]); |
---|
| 1075 | if ( ltm->refc && ltm->window == window ) { |
---|
| 1076 | ltm->refc++; |
---|
| 1077 | ltm->mt |= mt; |
---|
| 1078 | return 0; |
---|
| 1079 | } |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | // register |
---|
| 1083 | for (i = 0; i < MAX_LTM_WINDOWS_PER_STREAM; i++) { |
---|
| 1084 | ltm = &(ss->ltm[i]); |
---|
| 1085 | if ( ltm->refc == 0 ) { |
---|
| 1086 | memset(ltm, 0, sizeof(struct roar_stream_ltm)); |
---|
| 1087 | ltm->refc = 1; |
---|
| 1088 | ltm->window = window; |
---|
| 1089 | ltm->parent_window = -1; |
---|
| 1090 | ltm->mt = mt; |
---|
| 1091 | ltm->channels = ROAR_STREAM(ss)->info.channels; |
---|
| 1092 | if ( (ltm->cur = roar_mm_malloc(ltm->channels*sizeof(struct roar_ltm_vals))) == NULL ) { |
---|
| 1093 | ltm->refc = 0; // reset |
---|
| 1094 | return -1; |
---|
| 1095 | } |
---|
| 1096 | memset(ltm->cur, 0, ltm->channels*sizeof(struct roar_ltm_vals)); |
---|
| 1097 | return 0; |
---|
| 1098 | } |
---|
| 1099 | } |
---|
| 1100 | return -1; |
---|
| 1101 | break; |
---|
| 1102 | case ROAR_LTM_SST_UNREGISTER: |
---|
| 1103 | for (i = 0; i < MAX_LTM_WINDOWS_PER_STREAM; i++) { |
---|
| 1104 | ltm = &(ss->ltm[i]); |
---|
| 1105 | if ( ltm->refc && ltm->window == window ) { |
---|
| 1106 | ltm->refc--; |
---|
| 1107 | if ( ! ltm->refc ) { |
---|
| 1108 | roar_mm_free(ltm->cur); |
---|
| 1109 | return 0; |
---|
| 1110 | } |
---|
| 1111 | } |
---|
| 1112 | } |
---|
| 1113 | return -1; |
---|
| 1114 | break; |
---|
| 1115 | default: |
---|
| 1116 | return -1; |
---|
| 1117 | break; |
---|
| 1118 | } |
---|
| 1119 | } |
---|
| 1120 | |
---|
| 1121 | int streams_ltm_calc (int id, struct roar_audio_info * info, void * data, size_t len) { |
---|
| 1122 | struct roar_stream_server * ss; |
---|
| 1123 | struct roar_stream_ltm * ltm = NULL; |
---|
| 1124 | int64_t rmsbuf_real[8]; |
---|
| 1125 | int64_t * rmsbuf = rmsbuf_real; |
---|
| 1126 | size_t samples = 0; |
---|
| 1127 | int i; |
---|
| 1128 | |
---|
| 1129 | _CHECK_SID(id); |
---|
| 1130 | |
---|
| 1131 | if ( data == NULL || info == NULL ) |
---|
| 1132 | return -1; |
---|
| 1133 | |
---|
| 1134 | if ( info->codec != ROAR_CODEC_DEFAULT ) |
---|
| 1135 | return -1; |
---|
| 1136 | |
---|
| 1137 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1138 | return -1; |
---|
| 1139 | |
---|
| 1140 | for (i = 0; i < MAX_LTM_WINDOWS_PER_STREAM; i++) { |
---|
| 1141 | if ( ss->ltm[i].refc && ss->ltm[i].window == ROAR_LTM_WIN_WORKBLOCK ) { |
---|
| 1142 | ltm = &(ss->ltm[i]); |
---|
| 1143 | break; |
---|
| 1144 | } |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | if ( ltm == NULL ) |
---|
| 1148 | return -1; |
---|
| 1149 | |
---|
| 1150 | // TODO: support change of number of channels |
---|
| 1151 | if ( ltm->channels != info->channels ) |
---|
| 1152 | return -1; |
---|
| 1153 | |
---|
| 1154 | if ( len == 0 ) { |
---|
| 1155 | memset(ltm->cur, 0, ltm->channels * sizeof(struct roar_ltm_vals)); |
---|
| 1156 | return 0; |
---|
| 1157 | } |
---|
| 1158 | |
---|
| 1159 | // TODO: support more channels then rmsbuf_real has space for |
---|
| 1160 | if ( ltm->channels > (sizeof(rmsbuf_real)/sizeof(*rmsbuf_real)) ) { |
---|
| 1161 | return -1; |
---|
| 1162 | } |
---|
| 1163 | |
---|
| 1164 | samples = len / info->bits; |
---|
| 1165 | |
---|
| 1166 | if ( ltm->mt & ROAR_LTM_MT_RMS ) { |
---|
| 1167 | if ( roar_rms2_1_b_n(data, samples, rmsbuf, ltm->channels, info->bits) == -1 ) |
---|
| 1168 | return -1; |
---|
| 1169 | |
---|
| 1170 | for (i = 0; i < ltm->channels; i++) { |
---|
[4286] | 1171 | ltm->cur[i].rms = rmsbuf[i] << (64 - info->bits*2); |
---|
[4272] | 1172 | } |
---|
| 1173 | |
---|
| 1174 | ROAR_DBG("streams_ltm_calc(id=%i,...): rmsbuf[0]=%lli", id, (long long int)rmsbuf[0]); |
---|
| 1175 | } |
---|
| 1176 | |
---|
| 1177 | return 0; |
---|
| 1178 | } |
---|
| 1179 | |
---|
[4289] | 1180 | struct roar_stream_ltm * streams_ltm_get(int id, int mt, int window) { |
---|
[4278] | 1181 | struct roar_stream_server * ss; |
---|
| 1182 | struct roar_stream_ltm * ltm = NULL; |
---|
| 1183 | int i; |
---|
| 1184 | |
---|
[4290] | 1185 | _CHECK_SID_RET(id, NULL); |
---|
[4278] | 1186 | |
---|
| 1187 | if ( (ss = g_streams[id]) == NULL ) |
---|
[4290] | 1188 | return NULL; |
---|
[4278] | 1189 | |
---|
| 1190 | for (i = 0; i < MAX_LTM_WINDOWS_PER_STREAM; i++) { |
---|
| 1191 | if ( ss->ltm[i].refc && ss->ltm[i].window == window ) { |
---|
| 1192 | ltm = &(ss->ltm[i]); |
---|
| 1193 | break; |
---|
| 1194 | } |
---|
| 1195 | } |
---|
| 1196 | |
---|
| 1197 | if ( ltm == NULL ) |
---|
| 1198 | return NULL; |
---|
| 1199 | |
---|
| 1200 | if ( (ltm->mt & mt) != mt ) |
---|
| 1201 | return NULL; |
---|
| 1202 | |
---|
| 1203 | return ltm; |
---|
| 1204 | } |
---|
[4272] | 1205 | |
---|
[4361] | 1206 | struct hwmixer_stream * streams_get_mixerstream(int id) { |
---|
| 1207 | _CHECK_SID_RET(id, NULL); |
---|
| 1208 | |
---|
| 1209 | return g_streams[id]->mixerstream; |
---|
| 1210 | } |
---|
| 1211 | |
---|
| 1212 | int streams_set_mixerstream(int id, struct hwmixer_stream * mstream) { |
---|
| 1213 | _CHECK_SID(id); |
---|
| 1214 | |
---|
| 1215 | g_streams[id]->mixerstream = mstream; |
---|
| 1216 | |
---|
| 1217 | return 0; |
---|
| 1218 | } |
---|
| 1219 | |
---|
[4272] | 1220 | |
---|
[1224] | 1221 | int streams_ctl (int id, int_least32_t cmd, void * data) { |
---|
| 1222 | struct roar_stream_server * ss; |
---|
| 1223 | int_least32_t comp; |
---|
| 1224 | |
---|
[2734] | 1225 | _CHECK_SID(id); |
---|
| 1226 | |
---|
[1224] | 1227 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1228 | return -1; |
---|
| 1229 | |
---|
| 1230 | comp = cmd & ROAR_STREAM_CTL_COMPMASK; |
---|
| 1231 | |
---|
| 1232 | cmd &= ~comp; |
---|
| 1233 | |
---|
[1239] | 1234 | ROAR_DBG("streams_ctl(id=%i, cmd=?, data=%p): comp=0x%.8x, cmd=0x%.4x", id, data, comp, cmd); |
---|
[1238] | 1235 | |
---|
[1224] | 1236 | switch (comp) { |
---|
| 1237 | case ROAR_STREAM_CTL_COMP_BASE: |
---|
| 1238 | break; |
---|
| 1239 | case ROAR_STREAM_CTL_COMP_CF: |
---|
| 1240 | return codecfilter_ctl(ss->codecfilter_inst, ss->codecfilter, cmd, data); |
---|
| 1241 | break; |
---|
| 1242 | case ROAR_STREAM_CTL_COMP_DRV: |
---|
| 1243 | break; |
---|
| 1244 | default: |
---|
| 1245 | return -1; |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | return -1; |
---|
| 1249 | } |
---|
| 1250 | |
---|
[0] | 1251 | int streams_get_outputbuffer (int id, void ** buffer, size_t size) { |
---|
[2734] | 1252 | _CHECK_SID(id); |
---|
[0] | 1253 | |
---|
| 1254 | // output buffer size does never change. |
---|
| 1255 | if ( g_streams[id]->output != NULL ) { |
---|
| 1256 | *buffer = g_streams[id]->output; |
---|
| 1257 | return 0; |
---|
| 1258 | } |
---|
| 1259 | |
---|
| 1260 | if ( (g_streams[id]->output = malloc(size)) == NULL ) { |
---|
| 1261 | ROAR_ERR("streams_get_outputbuffer(*): Can not alloc: %s", strerror(errno)); |
---|
| 1262 | return -1; |
---|
| 1263 | } |
---|
| 1264 | |
---|
| 1265 | *buffer = g_streams[id]->output; |
---|
| 1266 | |
---|
| 1267 | return 0; |
---|
| 1268 | } |
---|
| 1269 | |
---|
[2061] | 1270 | int streams_fill_mixbuffer2 (int id, struct roar_audio_info * info) { |
---|
| 1271 | size_t outlen = ROAR_OUTPUT_CALC_OUTBUFSIZE(info); |
---|
| 1272 | void * outdata; |
---|
| 1273 | size_t inlen; |
---|
| 1274 | size_t inlen_got; |
---|
| 1275 | void * indata = NULL; |
---|
[2091] | 1276 | size_t buflen; |
---|
| 1277 | void * bufdata = NULL; |
---|
| 1278 | struct roar_buffer * bufbuf = NULL; |
---|
[2061] | 1279 | int is_the_same = 0; |
---|
| 1280 | struct roar_audio_info * stream_info; |
---|
| 1281 | struct roar_stream * s; |
---|
| 1282 | struct roar_stream_server * ss; |
---|
| 1283 | |
---|
[2734] | 1284 | _CHECK_SID(id); |
---|
| 1285 | |
---|
[2061] | 1286 | if ( (s = ROAR_STREAM(ss = g_streams[id])) == NULL ) |
---|
| 1287 | return -1; |
---|
| 1288 | |
---|
| 1289 | // set up stream_info |
---|
| 1290 | stream_info = &(s->info); |
---|
| 1291 | |
---|
| 1292 | // calc todo_in |
---|
| 1293 | inlen = ROAR_OUTPUT_CALC_OUTBUFSIZE(stream_info); |
---|
| 1294 | |
---|
[2091] | 1295 | buflen = ROAR_OUTPUT_CALC_OUTBUFSIZE_MAX(info, stream_info); |
---|
| 1296 | |
---|
[2747] | 1297 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=%p{...}): inlen=%lu, buflen=%lu", id, info, (unsigned long)inlen, (unsigned long)buflen); |
---|
| 1298 | |
---|
[2061] | 1299 | if ( inlen == 0 ) { |
---|
| 1300 | ROAR_WARN("streams_fill_mixbuffer2(id=%i, info=%p{...}): inlen == 0, this should not happen!", id, info); |
---|
| 1301 | return -1; |
---|
| 1302 | } |
---|
| 1303 | |
---|
| 1304 | if ( streams_get_outputbuffer(id, &outdata, outlen) == -1 ) { |
---|
| 1305 | return -1; |
---|
| 1306 | } |
---|
| 1307 | |
---|
| 1308 | if ( outdata == NULL ) { |
---|
| 1309 | return -1; |
---|
| 1310 | } |
---|
| 1311 | |
---|
| 1312 | ROAR_DBG("streams_fill_mixbuffer2(*): outdata=%p, len=%i->%i (in->out)", outdata, inlen, outlen); |
---|
| 1313 | |
---|
| 1314 | is_the_same = stream_info->rate == info->rate && stream_info->bits == info->bits && |
---|
| 1315 | stream_info->channels == info->channels && stream_info->codec == info->codec; |
---|
| 1316 | |
---|
| 1317 | ROAR_DBG("streams_fill_mixbuffer2(*): is_the_same=%i", is_the_same); |
---|
| 1318 | |
---|
[2091] | 1319 | if ( !is_the_same && buflen > outlen ) { |
---|
| 1320 | /* |
---|
[2061] | 1321 | // this is not supported at the moment |
---|
| 1322 | memset(outdata, 0, outlen); |
---|
| 1323 | return -1; |
---|
[2091] | 1324 | */ |
---|
| 1325 | |
---|
| 1326 | if ( roar_buffer_new(&bufbuf, buflen) == -1 ) |
---|
| 1327 | return -1; |
---|
| 1328 | |
---|
| 1329 | if ( roar_buffer_get_data(bufbuf, &bufdata) == -1 ) |
---|
| 1330 | return -1; |
---|
[2102] | 1331 | indata = bufdata; |
---|
[2061] | 1332 | } else { |
---|
[2091] | 1333 | indata = outdata; |
---|
| 1334 | bufdata = outdata; |
---|
[2061] | 1335 | } |
---|
| 1336 | |
---|
| 1337 | inlen_got = inlen; |
---|
| 1338 | |
---|
[2102] | 1339 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=...): inlen_got=%u", id, inlen_got); |
---|
| 1340 | |
---|
[2061] | 1341 | if ( stream_shift_out_buffer(id, indata, &inlen_got) == -1 ) { |
---|
| 1342 | if ( ss->is_new ) { |
---|
| 1343 | ss->pre_underruns++; |
---|
| 1344 | } else { |
---|
[2088] | 1345 | ROAR_WARN("streams_fill_mixbuffer2(id=%i, info=...): underrun in stream", id); |
---|
[2061] | 1346 | ss->post_underruns++; |
---|
| 1347 | } |
---|
| 1348 | memset(outdata, 0, outlen); |
---|
| 1349 | return 0; |
---|
| 1350 | } |
---|
| 1351 | |
---|
[2387] | 1352 | ROAR_DBG("streams_fill_mixbuffer2(id=%i, info=...): inlen_got=%u", id, inlen_got); |
---|
| 1353 | |
---|
[2061] | 1354 | if ( ss->is_new ) { |
---|
[4336] | 1355 | //ROAR_INFO("streams_fill_mixbuffer2(id=%i, info=...): stream state: new->old", ROAR_DBG_INFO_VERBOSE, id); |
---|
| 1356 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_fill_mixbuffer2"); |
---|
[2061] | 1357 | } |
---|
| 1358 | |
---|
| 1359 | ss->is_new = 0; |
---|
| 1360 | |
---|
[3549] | 1361 | // check channel map: |
---|
[3555] | 1362 | #if 0 |
---|
[3554] | 1363 | if ( roardsp_chanmap_mappcm(indata, indata, inlen, stream_info->channels, &(ss->chanmap), stream_info->bits) == -1 ) { |
---|
[3549] | 1364 | if ( bufbuf != NULL ) |
---|
| 1365 | roar_buffer_free(bufbuf); |
---|
| 1366 | return -1; |
---|
| 1367 | } |
---|
[3555] | 1368 | #endif |
---|
[3549] | 1369 | |
---|
[4118] | 1370 | // TODO: this only works in case a we have a amp for the given stream parameters. |
---|
| 1371 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) && !streams_get_flag(id, ROAR_FLAG_PASSMIXER) ) { |
---|
| 1372 | ROAR_DBG("streams_fill_mixbuffer2(*): CALL roar_amp_pcm(*)..."); |
---|
[4120] | 1373 | if ( roar_amp_pcm(indata, stream_info->bits, indata, 8*inlen / stream_info->bits, stream_info->channels, &(ss->mixer)) == -1 ) |
---|
[4118] | 1374 | return -1; |
---|
| 1375 | } |
---|
| 1376 | |
---|
[3549] | 1377 | // check codec, bits, channels, rate... |
---|
[2061] | 1378 | if ( is_the_same ) { |
---|
| 1379 | if ( indata != outdata ) |
---|
| 1380 | memcpy(outdata, indata, inlen); |
---|
| 1381 | |
---|
| 1382 | if ( inlen < outlen ) |
---|
| 1383 | memset(outdata+inlen, 0, outlen-inlen); |
---|
| 1384 | } else { |
---|
[2095] | 1385 | // if ( roar_conv(outdata, indata, (8*inlen_got*info->rate)/(stream_info->rate * stream_info->bits), stream_info, info) == -1 ) { |
---|
[2387] | 1386 | ROAR_DBG("streams_fill_mixbuffer2(*): CALL roar_conv2(*)..."); |
---|
[4111] | 1387 | if ( roar_conv2(bufdata, indata, inlen, stream_info, info, outlen) == -1 ) { |
---|
[2091] | 1388 | if ( bufbuf != NULL ) |
---|
| 1389 | roar_buffer_free(bufbuf); |
---|
[2062] | 1390 | return -1; |
---|
| 1391 | } |
---|
| 1392 | |
---|
| 1393 | // memset(outdata, 0, outlen); |
---|
[2061] | 1394 | } |
---|
| 1395 | |
---|
[2091] | 1396 | if ( bufbuf != NULL ) { |
---|
| 1397 | memcpy(outdata, bufdata, outlen); |
---|
| 1398 | roar_buffer_free(bufbuf); |
---|
| 1399 | } |
---|
| 1400 | |
---|
[4272] | 1401 | streams_ltm_calc(id, stream_info, outdata, outlen); |
---|
| 1402 | |
---|
[2153] | 1403 | if ( streams_get_flag(id, ROAR_FLAG_ANTIECHO) ) { |
---|
[2747] | 1404 | ROAR_DBG("streams_fill_mixbuffer2(*): Calcing antiecho..."); |
---|
[2153] | 1405 | // we can ignore errors here: |
---|
[2389] | 1406 | if ( stream_outputbuffer_request(id, &bufbuf, buflen) == 0 ) { |
---|
[2153] | 1407 | if ( roar_buffer_get_data(bufbuf, &bufdata) != -1 ) |
---|
| 1408 | memcpy(bufdata, outdata, outlen); |
---|
| 1409 | } |
---|
| 1410 | } |
---|
| 1411 | |
---|
[3932] | 1412 | ROAR_DBG("streams_fill_mixbuffer2(*): inlen_got=%llu, stream_info={.bits=%i, .rate=%i,...}", (long long unsigned int)inlen_got, stream_info->bits, stream_info->rate); |
---|
| 1413 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, (inlen_got*8)/stream_info->bits); |
---|
[2153] | 1414 | |
---|
[2747] | 1415 | ROAR_DBG("streams_fill_mixbuffer2(*) = 0"); |
---|
[2062] | 1416 | return 0; |
---|
[2061] | 1417 | } |
---|
| 1418 | |
---|
[491] | 1419 | |
---|
[0] | 1420 | int streams_get_mixbuffers (void *** bufferlist, struct roar_audio_info * info, unsigned int pos) { |
---|
[84] | 1421 | static void * bufs[ROAR_STREAMS_MAX+1]; |
---|
[0] | 1422 | int i; |
---|
| 1423 | int have = 0; |
---|
[2458] | 1424 | int dir; |
---|
[0] | 1425 | |
---|
| 1426 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 1427 | if ( g_streams[i] != NULL ) { |
---|
[2458] | 1428 | dir = streams_get_dir(i); |
---|
| 1429 | |
---|
| 1430 | switch (dir) { |
---|
| 1431 | case ROAR_DIR_PLAY: |
---|
| 1432 | case ROAR_DIR_BIDIR: |
---|
| 1433 | break; |
---|
[2459] | 1434 | case ROAR_DIR_BRIDGE: |
---|
| 1435 | if ( g_streams[i]->buffer == NULL ) |
---|
| 1436 | continue; |
---|
| 1437 | break; |
---|
[2458] | 1438 | default: |
---|
| 1439 | continue; |
---|
| 1440 | } |
---|
[0] | 1441 | |
---|
[2730] | 1442 | if ( streams_get_flag(i, ROAR_FLAG_PAUSE) ) |
---|
| 1443 | continue; |
---|
| 1444 | |
---|
[0] | 1445 | if ( streams_get_outputbuffer(i, &bufs[have], ROAR_OUTPUT_CALC_OUTBUFSIZE(info)) == -1 ) { |
---|
| 1446 | ROAR_ERR("streams_get_mixbuffer(*): Can not alloc output buffer for stream %i, BAD!", i); |
---|
| 1447 | ROAR_ERR("streams_get_mixbuffer(*): Ignoring stream for this round."); |
---|
| 1448 | continue; |
---|
| 1449 | } |
---|
[2061] | 1450 | if ( streams_fill_mixbuffer2(i, info) == -1 ) { |
---|
[0] | 1451 | ROAR_ERR("streams_get_mixbuffer(*): Can not fill output buffer for stream %i, this should not happen", i); |
---|
| 1452 | continue; |
---|
| 1453 | } |
---|
| 1454 | |
---|
[139] | 1455 | // printf("D: bufs[have=%i] = %p\n", have, bufs[have]); |
---|
| 1456 | |
---|
[0] | 1457 | ROAR_DBG("streams_get_mixbuffers(*): bufs[have] = %p", bufs[have]); |
---|
| 1458 | ROAR_DBG("streams_get_mixbuffers(*): *bufs[have] = 0x%08x...", *(uint32_t*)bufs[have]); |
---|
| 1459 | |
---|
[1887] | 1460 | if ( !streams_get_flag(i, ROAR_FLAG_MUTE) ) |
---|
| 1461 | have++; // we have a new stream! |
---|
[0] | 1462 | } |
---|
| 1463 | } |
---|
| 1464 | |
---|
| 1465 | bufs[have] = NULL; |
---|
[139] | 1466 | //printf("D: bufs[have=%i] = %p\n", have, bufs[have]); |
---|
[0] | 1467 | |
---|
| 1468 | ROAR_DBG("streams_get_mixbuffers(*): have = %i", have); |
---|
| 1469 | |
---|
| 1470 | *bufferlist = bufs; |
---|
[547] | 1471 | return have; |
---|
[0] | 1472 | } |
---|
| 1473 | |
---|
| 1474 | |
---|
| 1475 | int stream_add_buffer (int id, struct roar_buffer * buf) { |
---|
| 1476 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf); |
---|
| 1477 | |
---|
[2734] | 1478 | _CHECK_SID(id); |
---|
[0] | 1479 | |
---|
| 1480 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1481 | g_streams[id]->buffer = buf; |
---|
| 1482 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = 0", id, buf); |
---|
| 1483 | return 0; |
---|
| 1484 | } |
---|
| 1485 | |
---|
| 1486 | ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf); |
---|
| 1487 | return roar_buffer_add(g_streams[id]->buffer, buf); |
---|
| 1488 | } |
---|
| 1489 | |
---|
[2061] | 1490 | int stream_shift_out_buffer (int id, void * data, size_t * len) { |
---|
[2734] | 1491 | _CHECK_SID(id); |
---|
[2061] | 1492 | |
---|
| 1493 | if ( g_streams[id]->buffer == NULL ) |
---|
| 1494 | return -1; |
---|
| 1495 | |
---|
| 1496 | return roar_buffer_shift_out(&(g_streams[id]->buffer), data, len); |
---|
| 1497 | } |
---|
| 1498 | |
---|
[0] | 1499 | int stream_shift_buffer (int id, struct roar_buffer ** buf) { |
---|
| 1500 | struct roar_buffer * next; |
---|
| 1501 | |
---|
[2734] | 1502 | _CHECK_SID(id); |
---|
[0] | 1503 | |
---|
| 1504 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1505 | *buf = NULL; |
---|
| 1506 | return 0; |
---|
| 1507 | } |
---|
| 1508 | |
---|
| 1509 | roar_buffer_get_next(g_streams[id]->buffer, &next); |
---|
| 1510 | |
---|
| 1511 | *buf = g_streams[id]->buffer; |
---|
| 1512 | g_streams[id]->buffer = next; |
---|
| 1513 | |
---|
| 1514 | return 0; |
---|
| 1515 | } |
---|
| 1516 | int stream_unshift_buffer (int id, struct roar_buffer * buf) { |
---|
[2734] | 1517 | _CHECK_SID(id); |
---|
[0] | 1518 | |
---|
| 1519 | if ( g_streams[id]->buffer == NULL ) { |
---|
| 1520 | g_streams[id]->buffer = buf; |
---|
| 1521 | return 0; |
---|
| 1522 | } |
---|
| 1523 | |
---|
[271] | 1524 | buf->next = NULL; |
---|
| 1525 | |
---|
[0] | 1526 | roar_buffer_add(buf, g_streams[id]->buffer); |
---|
| 1527 | |
---|
| 1528 | g_streams[id]->buffer = buf; |
---|
| 1529 | |
---|
| 1530 | return 0; |
---|
| 1531 | } |
---|
| 1532 | |
---|
[2151] | 1533 | int stream_outputbuffer_request(int id, struct roar_buffer ** buf, size_t len) { |
---|
| 1534 | register struct roar_stream_server * ss; |
---|
| 1535 | size_t buflen; |
---|
[2159] | 1536 | void * bufdata; |
---|
[2151] | 1537 | int ret; |
---|
| 1538 | |
---|
[2734] | 1539 | _CHECK_SID(id); |
---|
| 1540 | |
---|
[2151] | 1541 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1542 | return -1; |
---|
| 1543 | |
---|
| 1544 | if ( buf != NULL ) /* just be be sure */ |
---|
| 1545 | *buf = NULL; |
---|
| 1546 | |
---|
| 1547 | if ( ss->outputbuffer != NULL ) { |
---|
| 1548 | if ( roar_buffer_get_len(ss->outputbuffer, &buflen) == 0 ) { |
---|
| 1549 | if ( buflen == len ) { |
---|
| 1550 | if ( buf != NULL ) |
---|
| 1551 | *buf = ss->outputbuffer; |
---|
| 1552 | return 0; |
---|
| 1553 | } else if ( buflen > len ) { |
---|
| 1554 | if ( roar_buffer_set_len(ss->outputbuffer, len) == 0 ) { |
---|
| 1555 | if ( buf != NULL ) |
---|
| 1556 | *buf = ss->outputbuffer; |
---|
| 1557 | return 0; |
---|
| 1558 | } |
---|
| 1559 | } |
---|
| 1560 | } |
---|
| 1561 | |
---|
| 1562 | // if the buffer is not suitable: |
---|
| 1563 | |
---|
| 1564 | ret = roar_buffer_free(ss->outputbuffer); |
---|
| 1565 | ss->outputbuffer = NULL; |
---|
| 1566 | if ( ret == -1 ) |
---|
| 1567 | return ret; |
---|
| 1568 | } |
---|
| 1569 | |
---|
| 1570 | if ( roar_buffer_new(&(ss->outputbuffer), len) == -1 ) |
---|
| 1571 | return -1; |
---|
| 1572 | |
---|
[2159] | 1573 | if ( roar_buffer_get_data(ss->outputbuffer, &bufdata) == -1 ) { |
---|
| 1574 | roar_buffer_free(ss->outputbuffer); |
---|
| 1575 | ss->outputbuffer = NULL; |
---|
| 1576 | return -1; |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | memset(bufdata, 0, len); |
---|
| 1580 | |
---|
[2151] | 1581 | if ( buf != NULL ) |
---|
| 1582 | *buf = ss->outputbuffer; |
---|
| 1583 | |
---|
| 1584 | return 0; |
---|
| 1585 | } |
---|
| 1586 | |
---|
| 1587 | int stream_outputbuffer_destroy(int id) { |
---|
| 1588 | int ret; |
---|
| 1589 | register struct roar_stream_server * ss; |
---|
| 1590 | |
---|
[2734] | 1591 | _CHECK_SID(id); |
---|
| 1592 | |
---|
[2151] | 1593 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1594 | return -1; |
---|
| 1595 | |
---|
| 1596 | if ( ss->outputbuffer != NULL ) { |
---|
| 1597 | ret = roar_buffer_free(ss->outputbuffer); |
---|
| 1598 | ss->outputbuffer = NULL; |
---|
| 1599 | return ret; |
---|
| 1600 | } |
---|
| 1601 | |
---|
| 1602 | return 0; |
---|
| 1603 | } |
---|
| 1604 | |
---|
[2816] | 1605 | int stream_prethru_add(int id, struct roar_buffer * buf) { |
---|
| 1606 | register struct roar_stream_server * ss; |
---|
| 1607 | |
---|
| 1608 | _CHECK_SID(id); |
---|
| 1609 | |
---|
| 1610 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1611 | return -1; |
---|
| 1612 | |
---|
| 1613 | if ( ss->prethru == NULL ) { |
---|
| 1614 | ss->prethru = buf; |
---|
| 1615 | return 0; |
---|
| 1616 | } |
---|
| 1617 | |
---|
| 1618 | if ( roar_buffer_add(ss->prethru, buf) == -1 ) { |
---|
| 1619 | return -1; |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | return 0; |
---|
| 1623 | } |
---|
| 1624 | |
---|
| 1625 | int stream_prethru_add_data(int id, void ** buf, size_t len) { |
---|
| 1626 | struct roar_buffer * buffer; |
---|
| 1627 | |
---|
| 1628 | _CHECK_SID(id); |
---|
| 1629 | |
---|
| 1630 | if ( roar_buffer_new(&buffer, len) == -1 ) |
---|
| 1631 | return -1; |
---|
| 1632 | |
---|
| 1633 | if ( roar_buffer_get_data(buffer, buf) == -1 ) { |
---|
| 1634 | roar_buffer_free(buffer); |
---|
| 1635 | return -1; |
---|
| 1636 | } |
---|
| 1637 | |
---|
| 1638 | if ( stream_prethru_add(id, buffer) == -1 ) { |
---|
| 1639 | roar_buffer_free(buffer); |
---|
| 1640 | return -1; |
---|
| 1641 | } |
---|
| 1642 | |
---|
| 1643 | return 0; |
---|
| 1644 | } |
---|
| 1645 | |
---|
| 1646 | int stream_prethru_destroy(int id) { |
---|
| 1647 | int ret; |
---|
| 1648 | register struct roar_stream_server * ss; |
---|
| 1649 | |
---|
| 1650 | _CHECK_SID(id); |
---|
| 1651 | |
---|
| 1652 | if ( (ss = g_streams[id]) == NULL ) |
---|
| 1653 | return -1; |
---|
| 1654 | |
---|
| 1655 | if ( ss->prethru != NULL ) { |
---|
| 1656 | ret = roar_buffer_free(ss->prethru); |
---|
| 1657 | ss->prethru = NULL; |
---|
| 1658 | return ret; |
---|
| 1659 | } |
---|
| 1660 | |
---|
| 1661 | return 0; |
---|
| 1662 | } |
---|
| 1663 | |
---|
| 1664 | int stream_prethru_send(int dst, int src) { |
---|
| 1665 | struct roar_stream_server * dst_ss, * src_ss; |
---|
| 1666 | struct roar_buffer * bufbuf; |
---|
| 1667 | void * bufdata; |
---|
| 1668 | size_t buflen; |
---|
| 1669 | |
---|
| 1670 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = ?", dst, src); |
---|
| 1671 | |
---|
| 1672 | _CHECK_SID(dst); |
---|
| 1673 | _CHECK_SID(src); |
---|
| 1674 | |
---|
| 1675 | if ( (dst_ss = g_streams[dst]) == NULL ) |
---|
| 1676 | return -1; |
---|
| 1677 | |
---|
| 1678 | if ( (src_ss = g_streams[src]) == NULL ) |
---|
| 1679 | return -1; |
---|
| 1680 | |
---|
| 1681 | bufbuf = src_ss->prethru; |
---|
| 1682 | |
---|
| 1683 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i): prethru buffer at %p", dst, src, bufbuf); |
---|
| 1684 | |
---|
| 1685 | while (bufbuf != NULL) { |
---|
| 1686 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i): looping with buffer at %p", dst, src, bufbuf); |
---|
| 1687 | |
---|
| 1688 | if ( roar_buffer_get_data(bufbuf, &bufdata) == -1 ) |
---|
| 1689 | return -1; |
---|
| 1690 | |
---|
| 1691 | if ( roar_buffer_get_len(bufbuf, &buflen) == -1 ) |
---|
| 1692 | return -1; |
---|
| 1693 | |
---|
| 1694 | if ( stream_vio_s_write(dst_ss, bufdata, buflen) != buflen ) |
---|
| 1695 | return -1; |
---|
| 1696 | |
---|
| 1697 | if ( roar_buffer_get_next(bufbuf, &bufbuf) == -1 ) |
---|
| 1698 | return -1; |
---|
| 1699 | } |
---|
| 1700 | |
---|
| 1701 | ROAR_DBG("stream_prethru_send(dst=%i, src=%i) = 0", dst, src); |
---|
| 1702 | return 0; |
---|
| 1703 | } |
---|
| 1704 | |
---|
[0] | 1705 | int streams_check (int id) { |
---|
| 1706 | int fh; |
---|
[508] | 1707 | ssize_t req, realreq, done; |
---|
[0] | 1708 | struct roar_stream * s; |
---|
| 1709 | struct roar_stream_server * ss; |
---|
| 1710 | struct roar_buffer * b; |
---|
| 1711 | char * buf; |
---|
[2248] | 1712 | // char tmp; |
---|
[0] | 1713 | |
---|
[2734] | 1714 | _CHECK_SID(id); |
---|
[0] | 1715 | |
---|
| 1716 | ROAR_DBG("streams_check(id=%i) = ?", id); |
---|
| 1717 | |
---|
[609] | 1718 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
[0] | 1719 | |
---|
| 1720 | if ( (fh = s->fh) == -1 ) |
---|
| 1721 | return 0; |
---|
| 1722 | |
---|
[1821] | 1723 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
[0] | 1724 | return 0; |
---|
| 1725 | |
---|
[1821] | 1726 | switch (s->dir) { |
---|
| 1727 | case ROAR_DIR_LIGHT_IN: |
---|
[2493] | 1728 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1821] | 1729 | return light_check_stream(id); |
---|
[2493] | 1730 | #else |
---|
| 1731 | streams_delete(id); |
---|
| 1732 | return -1; |
---|
| 1733 | #endif |
---|
[1821] | 1734 | break; |
---|
[1845] | 1735 | case ROAR_DIR_MIDI_IN: |
---|
[2493] | 1736 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1845] | 1737 | return midi_check_stream(id); |
---|
[2493] | 1738 | #else |
---|
| 1739 | streams_delete(id); |
---|
| 1740 | return -1; |
---|
| 1741 | #endif |
---|
[1845] | 1742 | break; |
---|
[2237] | 1743 | case ROAR_DIR_RAW_IN: |
---|
[2493] | 1744 | #ifndef ROAR_WITHOUT_DCOMP_RAW |
---|
[2237] | 1745 | return raw_check_stream(id); |
---|
[2493] | 1746 | #else |
---|
| 1747 | streams_delete(id); |
---|
| 1748 | return -1; |
---|
| 1749 | #endif |
---|
[2237] | 1750 | break; |
---|
[2721] | 1751 | case ROAR_DIR_RDTCS_IN: |
---|
| 1752 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1753 | return rdtcs_check_stream(id); |
---|
| 1754 | #else |
---|
| 1755 | streams_delete(id); |
---|
| 1756 | return -1; |
---|
| 1757 | #endif |
---|
| 1758 | break; |
---|
[1821] | 1759 | case ROAR_DIR_PLAY: |
---|
| 1760 | case ROAR_DIR_BIDIR: |
---|
| 1761 | break; |
---|
| 1762 | default: |
---|
[2248] | 1763 | /* |
---|
| 1764 | ROAR_WARN("streams_check(id=%i): Read event on non input stream of type/dir %s", id, roar_dir2str(s->dir)); |
---|
| 1765 | errno = 0; |
---|
| 1766 | req = stream_vio_s_read(ss, &tmp, 1); |
---|
| 1767 | ROAR_DBG("streams_check(id=%i): stream_vio_s_read(ss, &tmp, 1) = %li // errno=%s(%i)", id, req, strerror(errno), errno); |
---|
| 1768 | if ( req == 1 ) { |
---|
| 1769 | ROAR_ERR("streams_check(id=%i): Client violates protocol, got one byte of data on output stream, kicking stream"); |
---|
| 1770 | streams_delete(id); |
---|
| 1771 | return -1; |
---|
| 1772 | } |
---|
| 1773 | */ |
---|
[1821] | 1774 | return 0; |
---|
| 1775 | break; |
---|
| 1776 | } |
---|
[1585] | 1777 | |
---|
[0] | 1778 | ROAR_DBG("streams_check(id=%i): fh = %i", id, fh); |
---|
| 1779 | |
---|
[2387] | 1780 | /* |
---|
| 1781 | 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); |
---|
| 1782 | */ |
---|
| 1783 | |
---|
| 1784 | req = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); // optimal size |
---|
| 1785 | // req = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * (s->info.bits / 8) * ((float)s->info.rate/g_sa->rate); |
---|
[0] | 1786 | req += ss->need_extra; // bytes left we sould get.... |
---|
| 1787 | |
---|
[2387] | 1788 | ROAR_DBG("streams_check(id=%i): asking for %i bytes", id, req); |
---|
| 1789 | |
---|
[0] | 1790 | if ( roar_buffer_new(&b, req) == -1 ) { |
---|
| 1791 | ROAR_ERR("streams_check(*): Can not alloc buffer space!"); |
---|
| 1792 | ROAR_DBG("streams_check(*) = -1"); |
---|
| 1793 | return -1; |
---|
| 1794 | } |
---|
| 1795 | |
---|
| 1796 | roar_buffer_get_data(b, (void **)&buf); |
---|
| 1797 | |
---|
| 1798 | ROAR_DBG("streams_check(id=%i): buffer is up and ready ;)", id); |
---|
[2387] | 1799 | ROAR_DBG("streams_check(id=%i): asking for %i bytes", id, req); |
---|
[0] | 1800 | |
---|
[270] | 1801 | if ( ss->codecfilter == -1 ) { |
---|
[508] | 1802 | realreq = req; |
---|
| 1803 | /* |
---|
[270] | 1804 | req = read(fh, buf, req); |
---|
[508] | 1805 | if ( req < realreq ) { // we can do this as the stream is in nonblocking mode! |
---|
| 1806 | if ( (realreq = read(fh, buf+req, realreq-req)) > 0 ) |
---|
| 1807 | req += realreq; |
---|
| 1808 | } |
---|
| 1809 | */ |
---|
| 1810 | done = 0; |
---|
| 1811 | while (req > 0 && done != realreq) { |
---|
[881] | 1812 | if ( (req = stream_vio_s_read(ss, buf+done, realreq-done)) > 0 ) |
---|
[508] | 1813 | done += req; |
---|
| 1814 | } |
---|
| 1815 | req = done; |
---|
[1837] | 1816 | |
---|
| 1817 | roar_buffer_get_data(b, (void **)&buf); |
---|
[270] | 1818 | } else { |
---|
| 1819 | req = codecfilter_read(ss->codecfilter_inst, ss->codecfilter, buf, req); |
---|
| 1820 | } |
---|
| 1821 | |
---|
| 1822 | if ( req > 0 ) { |
---|
[0] | 1823 | ROAR_DBG("streams_check(id=%i): got %i bytes", id, req); |
---|
| 1824 | |
---|
| 1825 | roar_buffer_set_len(b, req); |
---|
| 1826 | |
---|
| 1827 | if ( stream_add_buffer(id, b) != -1 ) |
---|
| 1828 | return 0; |
---|
| 1829 | |
---|
| 1830 | ROAR_ERR("streams_check(id=%i): something is wrong, could not add buffer to stream!", id); |
---|
| 1831 | roar_buffer_free(b); |
---|
| 1832 | } else { |
---|
[272] | 1833 | ROAR_DBG("streams_check(id=%i): read() = %i // errno: %s", id, req, strerror(errno)); |
---|
| 1834 | #ifdef ROAR_HAVE_LIBVORBISFILE |
---|
| 1835 | if ( errno != EAGAIN && errno != ESPIPE ) { // libvorbis file trys to seek a bit ofen :) |
---|
| 1836 | #else |
---|
| 1837 | if ( errno != EAGAIN ) { |
---|
| 1838 | #endif |
---|
| 1839 | ROAR_DBG("streams_check(id=%i): EOF!", id); |
---|
| 1840 | streams_delete(id); |
---|
| 1841 | ROAR_DBG("streams_check(id=%i) = 0", id); |
---|
| 1842 | } |
---|
[334] | 1843 | roar_buffer_free(b); |
---|
[0] | 1844 | return 0; |
---|
| 1845 | } |
---|
| 1846 | |
---|
| 1847 | |
---|
| 1848 | ROAR_DBG("streams_check(id=%i) = -1", id); |
---|
| 1849 | return -1; |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | |
---|
[2152] | 1853 | #define _return(x) return (x) |
---|
[0] | 1854 | int streams_send_mon (int id) { |
---|
[936] | 1855 | // int fh; |
---|
[0] | 1856 | struct roar_stream * s; |
---|
| 1857 | struct roar_stream_server * ss; |
---|
[2146] | 1858 | struct roar_buffer * bufbuf = NULL; |
---|
[2155] | 1859 | struct roar_remove_state removalstate; |
---|
[2148] | 1860 | void * ip; |
---|
[1157] | 1861 | void * obuf; |
---|
| 1862 | int olen; |
---|
[2150] | 1863 | int is_the_same = 1; |
---|
| 1864 | int is_vol_eq = 1; |
---|
[2155] | 1865 | int antiecho = 0; |
---|
[1157] | 1866 | ssize_t ret; |
---|
[0] | 1867 | |
---|
[2734] | 1868 | _CHECK_SID(id); |
---|
[0] | 1869 | |
---|
| 1870 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 1871 | |
---|
[585] | 1872 | s = ROAR_STREAM((ss = g_streams[id])); |
---|
[0] | 1873 | |
---|
[934] | 1874 | /* |
---|
[0] | 1875 | if ( (fh = s->fh) == -1 ) |
---|
| 1876 | return 0; |
---|
[934] | 1877 | */ |
---|
[0] | 1878 | |
---|
[1914] | 1879 | if ( !ss->ready ) |
---|
| 1880 | return 0; |
---|
[930] | 1881 | |
---|
[3042] | 1882 | if ( g_config->jumbo_mtu ) |
---|
| 1883 | roar_vio_sync(ss->viop); |
---|
| 1884 | |
---|
[1585] | 1885 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
| 1886 | return 0; |
---|
| 1887 | |
---|
[1821] | 1888 | switch (s->dir) { |
---|
| 1889 | case ROAR_DIR_LIGHT_OUT: |
---|
[2493] | 1890 | #ifndef ROAR_WITHOUT_DCOMP_LIGHT |
---|
[1821] | 1891 | return light_send_stream(id); |
---|
[2493] | 1892 | #else |
---|
| 1893 | streams_delete(id); |
---|
| 1894 | return -1; |
---|
| 1895 | #endif |
---|
[1821] | 1896 | break; |
---|
[1845] | 1897 | case ROAR_DIR_MIDI_OUT: |
---|
[2493] | 1898 | #ifndef ROAR_WITHOUT_DCOMP_MIDI |
---|
[1845] | 1899 | return midi_send_stream(id); |
---|
[2493] | 1900 | #else |
---|
| 1901 | streams_delete(id); |
---|
| 1902 | return -1; |
---|
| 1903 | #endif |
---|
[1845] | 1904 | break; |
---|
[2721] | 1905 | case ROAR_DIR_RDTCS_OUT: |
---|
| 1906 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 1907 | return rdtcs_send_stream(id); |
---|
| 1908 | #else |
---|
| 1909 | streams_delete(id); |
---|
| 1910 | return -1; |
---|
| 1911 | #endif |
---|
| 1912 | break; |
---|
[2694] | 1913 | |
---|
| 1914 | case ROAR_DIR_COMPLEX_OUT: |
---|
| 1915 | // send a tick: |
---|
| 1916 | if ( ss->codecfilter != -1 ) { |
---|
| 1917 | if ( codecfilter_write(ss->codecfilter_inst, ss->codecfilter, NULL, 0) == 0 ) |
---|
[4237] | 1918 | if ( ss->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 1919 | //ROAR_INFO("streams_send_mon(id=%i): stream state: %s->old", ROAR_DBG_INFO_VERBOSE, id, roar_streamstate2str(ss->state)); |
---|
| 1920 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_send_mon"); |
---|
[4237] | 1921 | } |
---|
[2694] | 1922 | } |
---|
| 1923 | return 0; |
---|
| 1924 | break; |
---|
| 1925 | |
---|
[1821] | 1926 | case ROAR_DIR_OUTPUT: |
---|
| 1927 | if ( g_standby ) |
---|
| 1928 | return 0; |
---|
| 1929 | case ROAR_DIR_MONITOR: |
---|
| 1930 | case ROAR_DIR_BIDIR: |
---|
| 1931 | break; |
---|
| 1932 | |
---|
| 1933 | default: |
---|
| 1934 | return 0; |
---|
| 1935 | break; |
---|
| 1936 | } |
---|
| 1937 | |
---|
| 1938 | |
---|
[1042] | 1939 | ROAR_DBG("streams_send_mon(id=%i): fh = %i", id, s->fh); |
---|
[0] | 1940 | |
---|
[625] | 1941 | if ( s->info.channels != g_sa->channels || s->info.bits != g_sa->bits || |
---|
[2147] | 1942 | s->info.rate != g_sa->rate || s->info.codec != g_sa->codec ) |
---|
| 1943 | is_the_same = 0; |
---|
| 1944 | |
---|
[2150] | 1945 | if ( !streams_get_flag(id, ROAR_FLAG_HWMIXER) ) { |
---|
| 1946 | is_vol_eq = need_vol_change(g_sa->channels, &(ss->mixer)) ? 0 : 1; |
---|
| 1947 | } |
---|
| 1948 | |
---|
[2155] | 1949 | if ( streams_get_flag(id, ROAR_FLAG_ANTIECHO) ) |
---|
| 1950 | antiecho = 1; |
---|
| 1951 | |
---|
| 1952 | if ( !is_the_same || !is_vol_eq || antiecho ) { |
---|
[625] | 1953 | olen = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); // we hope g_output_buffer_len |
---|
| 1954 | // is ROAR_OUTPUT_CALC_OUTBUFSIZE(g_sa) here |
---|
[2390] | 1955 | if ( stream_outputbuffer_request(id, &bufbuf, ROAR_OUTPUT_CALC_OUTBUFSIZE_MAX(&(s->info), g_sa)) == -1 ) |
---|
[625] | 1956 | return -1; |
---|
| 1957 | |
---|
[2146] | 1958 | if ( roar_buffer_get_data(bufbuf, &obuf) == -1 ) { |
---|
| 1959 | _return(-1); |
---|
| 1960 | } |
---|
| 1961 | |
---|
[625] | 1962 | ROAR_DBG("streams_send_mon(id=%i): obuf=%p, olen=%i", id, obuf, olen); |
---|
[2147] | 1963 | } else { |
---|
| 1964 | obuf = g_output_buffer; |
---|
| 1965 | olen = g_output_buffer_len; |
---|
| 1966 | } |
---|
[625] | 1967 | |
---|
[2148] | 1968 | ip = g_output_buffer; |
---|
| 1969 | |
---|
[2155] | 1970 | if ( antiecho ) { |
---|
[2397] | 1971 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2158] | 1972 | if ( roar_remove_init(&removalstate) == -1 ) { |
---|
[2155] | 1973 | _return(-1); |
---|
[2158] | 1974 | } |
---|
| 1975 | |
---|
[2397] | 1976 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2158] | 1977 | if ( roar_remove_so(obuf, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa->bits, &removalstate) == -1 ) { |
---|
[2397] | 1978 | ROAR_DBG("streams_send_mon(id=%i): anti echo failed", id); |
---|
[2158] | 1979 | _return(-1); |
---|
| 1980 | } |
---|
[2397] | 1981 | ROAR_DBG("streams_send_mon(id=%i): antiecho=%i", id, antiecho); |
---|
[2155] | 1982 | } |
---|
| 1983 | |
---|
[2150] | 1984 | if ( !is_vol_eq ) { |
---|
[2938] | 1985 | if ( roar_amp_pcm(obuf, g_sa->bits, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa->channels, &(ss->mixer)) == -1 ) { |
---|
[2150] | 1986 | _return(-1); |
---|
| 1987 | } |
---|
| 1988 | |
---|
| 1989 | ip = obuf; |
---|
| 1990 | } |
---|
| 1991 | |
---|
[4288] | 1992 | streams_ltm_calc(id, &(s->info), ip, (ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels*g_sa->bits)/8); |
---|
| 1993 | |
---|
[2147] | 1994 | if ( !is_the_same ) { |
---|
[2148] | 1995 | if ( roar_conv(obuf, ip, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa, &(s->info)) == -1 ) { |
---|
[2146] | 1996 | _return(-1); |
---|
[625] | 1997 | } |
---|
| 1998 | } |
---|
| 1999 | |
---|
[585] | 2000 | errno = 0; |
---|
| 2001 | |
---|
| 2002 | if ( ss->codecfilter == -1 ) { |
---|
[1042] | 2003 | ROAR_DBG("streams_send_mon(id=%i): not a CF stream", id); |
---|
[2146] | 2004 | if ( s->fh == -1 && roar_vio_get_fh(&(ss->vio)) == -1 ) { |
---|
[2705] | 2005 | ROAR_DBG("streams_send_mon(id=%i) = 0", id); |
---|
[2146] | 2006 | _return(0); |
---|
| 2007 | } |
---|
[1014] | 2008 | |
---|
[2705] | 2009 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 2010 | |
---|
[1157] | 2011 | if ( (ret = stream_vio_s_write(ss, obuf, olen)) == olen ) { |
---|
[981] | 2012 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[4237] | 2013 | if ( ss->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2014 | //ROAR_INFO("streams_send_mon(id=%i): stream state: %s->old", ROAR_DBG_INFO_VERBOSE, id, roar_streamstate2str(ss->state)); |
---|
| 2015 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_send_mon"); |
---|
[4237] | 2016 | } |
---|
[2705] | 2017 | ROAR_DBG("streams_send_mon(id=%i) = 0", id); |
---|
[2146] | 2018 | _return(0); |
---|
[625] | 2019 | } |
---|
[1157] | 2020 | |
---|
[2705] | 2021 | ROAR_DBG("streams_send_mon(id=%i) = ?", id); |
---|
| 2022 | |
---|
[1157] | 2023 | if ( ret > 0 && errno == 0 ) { |
---|
[1231] | 2024 | 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] | 2025 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), ret)*s->info.channels); |
---|
[4237] | 2026 | if ( ss->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2027 | //ROAR_INFO("streams_send_mon(id=%i): stream state: %s->old", ROAR_DBG_INFO_VERBOSE, id, roar_streamstate2str(ss->state)); |
---|
| 2028 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_send_mon"); |
---|
[4237] | 2029 | } |
---|
[2146] | 2030 | _return(0); |
---|
[1157] | 2031 | } |
---|
[585] | 2032 | } else { |
---|
[1012] | 2033 | errno = 0; |
---|
[625] | 2034 | if ( codecfilter_write(ss->codecfilter_inst, ss->codecfilter, obuf, olen) |
---|
| 2035 | == olen ) { |
---|
[981] | 2036 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[4237] | 2037 | if ( ss->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2038 | //ROAR_INFO("streams_send_mon(id=%i): stream state: %s->old", ROAR_DBG_INFO_VERBOSE, id, roar_streamstate2str(ss->state)); |
---|
| 2039 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_send_mon"); |
---|
[4237] | 2040 | } |
---|
[2146] | 2041 | _return(0); |
---|
[585] | 2042 | } else { // we cann't retry on codec filetered streams |
---|
[1012] | 2043 | if ( errno != EAGAIN ) { |
---|
| 2044 | streams_delete(id); |
---|
[2146] | 2045 | _return(-1); |
---|
[1012] | 2046 | } |
---|
[585] | 2047 | } |
---|
| 2048 | } |
---|
[0] | 2049 | |
---|
[129] | 2050 | if ( errno == EAGAIN ) { |
---|
| 2051 | // ok, the client blocks for a moment, we try to sleep a bit an retry in the hope not to |
---|
| 2052 | // make any gapes in any output because of this |
---|
| 2053 | |
---|
[1750] | 2054 | #ifdef ROAR_HAVE_USLEEP |
---|
[129] | 2055 | usleep(100); // 0.1ms |
---|
[1750] | 2056 | #endif |
---|
[129] | 2057 | |
---|
[881] | 2058 | if ( stream_vio_s_write(ss, obuf, olen) == olen ) { |
---|
[981] | 2059 | s->pos = ROAR_MATH_OVERFLOW_ADD(s->pos, ROAR_OUTPUT_CALC_OUTBUFSAMP(&(s->info), olen)*s->info.channels); |
---|
[4237] | 2060 | if ( ss->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2061 | //ROAR_INFO("streams_send_mon(id=%i): stream state: %s->old", ROAR_DBG_INFO_VERBOSE, id, roar_streamstate2str(ss->state)); |
---|
| 2062 | _streams_change_state(ss, ROAR_STREAMSTATE_OLD, "streams_send_mon"); |
---|
[4237] | 2063 | } |
---|
[2146] | 2064 | _return(0); |
---|
[1015] | 2065 | } else if ( errno == EAGAIN ) { |
---|
| 2066 | ROAR_WARN("streams_send_mon(id=%i): Can not send data to client: %s", id, strerror(errno)); |
---|
[2146] | 2067 | _return(0); |
---|
[625] | 2068 | } |
---|
[129] | 2069 | } |
---|
| 2070 | |
---|
[0] | 2071 | // ug... error... delete stream! |
---|
| 2072 | |
---|
| 2073 | streams_delete(id); |
---|
| 2074 | |
---|
[2146] | 2075 | _return(-1); |
---|
[0] | 2076 | } |
---|
[2146] | 2077 | #undef _return |
---|
[0] | 2078 | |
---|
| 2079 | int streams_send_filter(int id) { |
---|
| 2080 | int fh; |
---|
[127] | 2081 | int have = 0; |
---|
| 2082 | int len; |
---|
[0] | 2083 | struct roar_stream * s; |
---|
| 2084 | struct roar_stream_server * ss; |
---|
| 2085 | |
---|
[2734] | 2086 | _CHECK_SID(id); |
---|
[0] | 2087 | |
---|
| 2088 | ROAR_DBG("streams_send_filter(id=%i) = ?", id); |
---|
| 2089 | |
---|
[609] | 2090 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
[0] | 2091 | |
---|
| 2092 | if ( (fh = s->fh) == -1 ) |
---|
| 2093 | return 0; |
---|
| 2094 | |
---|
| 2095 | if ( s->dir != ROAR_DIR_FILTER ) |
---|
| 2096 | return 0; |
---|
| 2097 | |
---|
[1585] | 2098 | if ( streams_get_flag(id, ROAR_FLAG_PAUSE) ) |
---|
| 2099 | return 0; |
---|
| 2100 | |
---|
| 2101 | |
---|
[0] | 2102 | ROAR_DBG("streams_send_filter(id=%i): fh = %i", id, fh); |
---|
| 2103 | |
---|
[881] | 2104 | if ( stream_vio_s_write(ss, g_output_buffer, g_output_buffer_len) == g_output_buffer_len ) { |
---|
[127] | 2105 | while ( have < g_output_buffer_len ) { |
---|
[881] | 2106 | if ( (len = stream_vio_s_read(ss, g_output_buffer+have, g_output_buffer_len-have)) < 1 ) { |
---|
[127] | 2107 | streams_delete(id); |
---|
| 2108 | return -1; |
---|
| 2109 | } |
---|
| 2110 | have += len; |
---|
[0] | 2111 | } |
---|
[127] | 2112 | return 0; |
---|
[0] | 2113 | } |
---|
| 2114 | |
---|
| 2115 | // ug... error... delete stream! |
---|
| 2116 | |
---|
| 2117 | streams_delete(id); |
---|
| 2118 | |
---|
| 2119 | return -1; |
---|
| 2120 | } |
---|
| 2121 | |
---|
[596] | 2122 | |
---|
| 2123 | // VIO: |
---|
| 2124 | |
---|
| 2125 | ssize_t stream_vio_read (int stream, void *buf, size_t count) { |
---|
[2734] | 2126 | _CHECK_SID(stream); |
---|
[596] | 2127 | |
---|
[2734] | 2128 | return stream_vio_s_read(g_streams[stream], buf, count); |
---|
[596] | 2129 | } |
---|
| 2130 | |
---|
| 2131 | ssize_t stream_vio_write(int stream, void *buf, size_t count) { |
---|
[2734] | 2132 | _CHECK_SID(stream); |
---|
[596] | 2133 | |
---|
[2734] | 2134 | return stream_vio_s_write(g_streams[stream], buf, count); |
---|
[596] | 2135 | } |
---|
| 2136 | |
---|
| 2137 | |
---|
| 2138 | ssize_t stream_vio_s_read (struct roar_stream_server * stream, void *buf, size_t count) { |
---|
[2253] | 2139 | void * orig_buf = buf; |
---|
| 2140 | size_t len = 0; |
---|
| 2141 | ssize_t r = -1; |
---|
| 2142 | int i; |
---|
[739] | 2143 | |
---|
[596] | 2144 | errno = 0; |
---|
| 2145 | |
---|
| 2146 | if ( !stream ) |
---|
| 2147 | return -1; |
---|
| 2148 | |
---|
[1613] | 2149 | //roar_vio_set_fh(&(stream->vio), ROAR_STREAM(stream)->fh); |
---|
[881] | 2150 | |
---|
[596] | 2151 | if ( ! stream->vio.read ) |
---|
| 2152 | return -1; |
---|
| 2153 | |
---|
[881] | 2154 | while ( (r = roar_vio_read(&(stream->vio), buf, count)) > 0 ) { |
---|
[739] | 2155 | len += r; |
---|
| 2156 | buf += r; |
---|
| 2157 | count -= r; |
---|
| 2158 | if ( count == 0 ) |
---|
| 2159 | break; |
---|
| 2160 | } |
---|
| 2161 | |
---|
[740] | 2162 | if ( len == 0 && r == -1 ) |
---|
| 2163 | return -1; |
---|
| 2164 | |
---|
[2816] | 2165 | if ( streams_thru_num ) { |
---|
| 2166 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 2167 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { |
---|
| 2168 | if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { |
---|
| 2169 | if ( g_streams[i]->ready ) { |
---|
[2258] | 2170 | if ( stream_vio_write(i, orig_buf, len) != len ) |
---|
| 2171 | streams_delete(i); |
---|
[2252] | 2172 | |
---|
[4237] | 2173 | if ( g_streams[i] != NULL ) { |
---|
| 2174 | if ( g_streams[i]->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2175 | //ROAR_INFO("stream_vio_s_read(*): (stream: %i) stream state: %s->old", ROAR_DBG_INFO_VERBOSE, i, roar_streamstate2str(g_streams[i]->state)); |
---|
| 2176 | _streams_change_state(g_streams[i], ROAR_STREAMSTATE_OLD, "stream_vio_s_read"); |
---|
[4237] | 2177 | } |
---|
| 2178 | } |
---|
[2816] | 2179 | } |
---|
| 2180 | } |
---|
| 2181 | } |
---|
| 2182 | } |
---|
| 2183 | } |
---|
| 2184 | |
---|
[739] | 2185 | return len; |
---|
[596] | 2186 | } |
---|
| 2187 | |
---|
| 2188 | ssize_t stream_vio_s_write(struct roar_stream_server * stream, void *buf, size_t count) { |
---|
[2259] | 2189 | int i; |
---|
| 2190 | |
---|
[596] | 2191 | errno = 0; |
---|
| 2192 | |
---|
| 2193 | if ( !stream ) |
---|
| 2194 | return -1; |
---|
| 2195 | |
---|
[1613] | 2196 | /* |
---|
[934] | 2197 | if ( roar_vio_get_fh(&(stream->vio)) == -1 && ROAR_STREAM(stream)->fh != -1 ) |
---|
| 2198 | roar_vio_set_fh(&(stream->vio), ROAR_STREAM(stream)->fh); |
---|
[1613] | 2199 | */ |
---|
[934] | 2200 | |
---|
| 2201 | // ROAR_WARN("stream_vio_s_write(*): writing..."); |
---|
[596] | 2202 | |
---|
[2816] | 2203 | if ( streams_thru_num ) { |
---|
| 2204 | for (i = 0; i < ROAR_STREAMS_MAX; i++) { |
---|
| 2205 | if ( g_streams[i] != NULL && ROAR_STREAM(g_streams[i])->pos_rel_id == ROAR_STREAM(stream)->id ) { |
---|
| 2206 | if ( ROAR_STREAM(g_streams[i])->dir == ROAR_DIR_THRU ) { |
---|
| 2207 | if ( g_streams[i]->ready ) { |
---|
| 2208 | if ( g_streams[i]->state == ROAR_STREAMSTATE_NEW ) { |
---|
| 2209 | if ( streams_get_flag(i, ROAR_FLAG_PRETHRU) == 1 ) { |
---|
[3042] | 2210 | if ( stream_prethru_send(i, ROAR_STREAM(stream)->id) == -1 ) { |
---|
[2816] | 2211 | streams_delete(i); |
---|
| 2212 | } |
---|
| 2213 | } |
---|
| 2214 | } |
---|
| 2215 | |
---|
| 2216 | if ( stream_vio_write(i, buf, count) != count ) { |
---|
[2259] | 2217 | streams_delete(i); |
---|
[2816] | 2218 | } |
---|
| 2219 | |
---|
[4237] | 2220 | if ( g_streams[i] != NULL ) { |
---|
| 2221 | if ( g_streams[i]->state != ROAR_STREAMSTATE_OLD ) { |
---|
[4336] | 2222 | //ROAR_INFO("stream_vio_s_write(*): (stream: %i) stream state: %s->old", ROAR_DBG_INFO_VERBOSE, i, roar_streamstate2str(g_streams[i]->state)); |
---|
| 2223 | _streams_change_state(g_streams[i], ROAR_STREAMSTATE_OLD, "stream_vio_s_write"); |
---|
[4237] | 2224 | } |
---|
| 2225 | } |
---|
[2816] | 2226 | } |
---|
| 2227 | } |
---|
| 2228 | } |
---|
| 2229 | } |
---|
| 2230 | } |
---|
[2259] | 2231 | |
---|
[3042] | 2232 | if ( g_config->jumbo_mtu ) { |
---|
| 2233 | if ( stream->viop != &(stream->jumbo) ) { |
---|
| 2234 | if ( roar_vio_open_jumbo(&(stream->jumbo), &(stream->vio), g_config->jumbo_mtu) != -1 ) { |
---|
| 2235 | // if that works we continue using the jumbo vio, |
---|
| 2236 | // in case it didn't we dont, just use normal VIO. |
---|
| 2237 | stream->viop = &(stream->jumbo); |
---|
| 2238 | } |
---|
| 2239 | } |
---|
| 2240 | } |
---|
| 2241 | |
---|
| 2242 | return roar_vio_write(stream->viop, buf, count); |
---|
[596] | 2243 | } |
---|
| 2244 | |
---|
[0] | 2245 | //ll |
---|