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