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