source: roaraudio/roard/streams.c @ 645:6cbe070ef8fc

Last change on this file since 645:6cbe070ef8fc was 645:6cbe070ef8fc, checked in by phi, 16 years ago

make primary streams work without double-free while quit

File size: 18.4 KB
Line 
1//streams.c:
2
3#include "roard.h"
4
5int streams_init (void) {
6 int i;
7
8 for (i = 0; i < ROAR_STREAMS_MAX; i++)
9  g_streams[i] = NULL;
10
11 return 0;
12}
13
14int streams_free (void) {
15 int i;
16
17 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
18  if ( g_streams[i] != NULL ) {
19   streams_delete(i);
20  }
21 }
22
23 return 0;
24}
25
26
27int streams_new    (void) {
28 int i, j;
29 struct roar_stream        * n = NULL;
30 struct roar_stream_server * s = NULL;
31
32 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
33  if ( g_streams[i] == NULL ) {
34   s = ROAR_STREAM_SERVER(n = ROAR_STREAM(malloc(sizeof(struct roar_stream_server))));
35   if ( n == NULL ) {
36    ROAR_ERR("streams_new(void): can not allocate memory for new stream: %s", strerror(errno));
37    ROAR_DBG("streams_new(void) = -1");
38    return -1;
39   }
40
41   n->id         = i;
42   n->fh         = -1;
43//   n->pos_rel_id = i;
44   n->database   = NULL;
45   n->dataoff    = NULL;
46   n->datalen    = 0;
47   n->offset     = 0;
48   n->pos        = 0;
49
50   s->client          = -1;
51   s->socktype        = ROAR_SOCKET_TYPE_UNKNOWN;
52   s->buffer          = NULL;
53   s->need_extra      =  0;
54   s->output          = NULL;
55   s->is_new          =  1;
56   s->codecfilter     = -1;
57   s->pre_underruns   =  0;
58   s->post_underruns  =  0;
59   s->codec_orgi      = -1;
60   s->primary         =  0;
61
62   s->mixer.scale     = 65535;
63   s->mixer.rpg_mul   = 1;
64   s->mixer.rpg_div   = 1;
65   for (j = 0; j < ROAR_MAX_CHANNELS; j++)
66    s->mixer.mixer[j] = 65535;
67
68   for (j = 0; j < ROAR_META_MAX_PER_STREAM; j++) {
69    s->meta[j].type   = ROAR_META_TYPE_NONE;
70    s->meta[j].key[0] = 0;
71    s->meta[j].value  = NULL;
72   }
73
74   roar_vio_init_calls(&(s->vio));
75
76   g_streams[i] = s;
77   ROAR_DBG("streams_new(void): n->id=%i", n->id);
78   ROAR_DBG("streams_new(void) = %i", i);
79   return i;
80  }
81 }
82
83 return -1;
84}
85
86int streams_delete (int id) {
87 struct roar_stream_server * s;
88 int prim;
89
90 if ( (s = g_streams[id]) == NULL )
91  return 0;
92
93 ROAR_DBG("streams_delete(id=%i) = ?", id);
94 ROAR_DBG("streams_delete(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(s)->id);
95
96 if ( s->codecfilter != -1 ) {
97  codecfilter_close(s->codecfilter_inst, s->codecfilter);
98  s->codecfilter_inst = NULL;
99  s->codecfilter = -1;
100 }
101
102 if ( s->client != -1 ) {
103  ROAR_DBG("streams_delete(id=%i): Stream is owned by client %i", id, g_streams[id]->client);
104  client_stream_delete(s->client, id);
105 }
106
107 if ( s->buffer != NULL )
108  roar_buffer_free(s->buffer);
109
110 if ( s->output != NULL )
111  free(s->output);
112
113 if ( ROAR_STREAM(s)->fh != -1 )
114  close(ROAR_STREAM(s)->fh);
115
116 prim = s->primary;
117
118 free(s);
119
120 g_streams[id] = NULL;
121
122 if ( prim ) {
123  alive = 0;
124  clean_quit();
125 }
126
127 ROAR_DBG("streams_delete(id=%i) = 0", id);
128 return 0;
129}
130
131int streams_set_client (int id, int client) {
132 if ( g_streams[id] == NULL )
133  return -1;
134
135 ROAR_DBG("streams_set_client(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(g_streams[id])->id);
136 g_streams[id]->client = client;
137
138 return 0;
139}
140
141int streams_set_fh     (int id, int fh) {
142 int dir;
143
144 if ( g_streams[id] == NULL )
145  return -1;
146
147 ROAR_DBG("streams_set_fh(id=%i): g_streams[id]->id=%i", id, ROAR_STREAM(g_streams[id])->id);
148
149 ROAR_STREAM(g_streams[id])->fh = fh;
150
151 if ( codecfilter_open(&(g_streams[id]->codecfilter_inst), &(g_streams[id]->codecfilter), NULL,
152                  ROAR_STREAM(g_streams[id])->info.codec, g_streams[id]) == -1 ) {
153  return streams_delete(id);
154 }
155
156 if ( fh == -1 ) { // yes, this is valid, indecats full vio!
157  return 0;
158 }
159
160 dir = ROAR_STREAM(g_streams[id])->dir;
161
162 if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD || dir == ROAR_DIR_OUTPUT ) {
163  shutdown(fh, SHUT_RD);
164 }
165
166 if ( dir == ROAR_DIR_FILTER ) {
167  return 0;
168 } else {
169  return roar_socket_nonblock(fh, ROAR_SOCKET_NONBLOCK);
170 }
171}
172
173int streams_get_fh     (int id) {
174 if ( id < 0 )
175  return -1;
176
177 if ( g_streams[id] == NULL )
178  return -1;
179
180 return ROAR_STREAM(g_streams[id])->fh;
181}
182
183int streams_get    (int id, struct roar_stream_server ** stream) {
184 if ( g_streams[id] == NULL )
185  return -1;
186
187 *stream = g_streams[id];
188
189 return 0;
190}
191
192int streams_set_socktype (int id, int socktype) {
193 if ( g_streams[id] == NULL )
194  return -1;
195
196 g_streams[id]->socktype = socktype;
197
198 return 0;
199}
200
201int streams_get_socktype (int id) {
202 if ( g_streams[id] == NULL )
203  return -1;
204
205 return g_streams[id]->socktype;
206}
207
208int streams_set_primary (int id, int prim) {
209 if ( g_streams[id] == NULL )
210  return -1;
211
212 g_streams[id]->primary = prim;
213
214 return 0;
215}
216
217int streams_mark_primary (int id) {
218 return streams_set_primary(id, 1);
219}
220int streams_get_outputbuffer  (int id, void ** buffer, size_t size) {
221 if ( g_streams[id] == NULL )
222  return -1;
223
224 // output buffer size does never change.
225 if ( g_streams[id]->output != NULL ) {
226  *buffer = g_streams[id]->output;
227  return 0;
228 }
229
230 if ( (g_streams[id]->output = malloc(size)) == NULL ) {
231  ROAR_ERR("streams_get_outputbuffer(*): Can not alloc: %s", strerror(errno));
232  return -1;
233 }
234
235 *buffer = g_streams[id]->output;
236
237 return 0;
238}
239
240int streams_fill_mixbuffer (int id, struct roar_audio_info * info) {
241 // TODO: decide: is this the most complex, hacked, un-understadable,
242 //               un-writeable and even worse: un-readable
243 //               function in the whole project?
244 size_t todo = ROAR_OUTPUT_CALC_OUTBUFSIZE(info);
245 size_t needed = todo;
246 size_t todo_in;
247 size_t len, outlen;
248 size_t mul = 1, div = 1;
249 void * rest = NULL;
250 void * in   = NULL;
251 struct roar_buffer     * buf;
252 struct roar_audio_info * stream_info;
253 struct roar_stream_server * stream = g_streams[id];
254 int is_the_same = 0;
255
256 if ( g_streams[id] == NULL )
257  return -1;
258
259 if ( streams_get_outputbuffer(id, &rest, todo) == -1 ) {
260  return -1;
261 }
262
263 if ( rest == NULL ) {
264  return -1;
265 }
266
267 // set up stream_info
268
269 stream_info = &(ROAR_STREAM(stream)->info);
270
271 // calc todo_in
272 todo_in = ROAR_OUTPUT_CALC_OUTBUFSIZE(stream_info);
273
274 // calc mul and div:
275 mul = todo    / todo_in;
276 div = todo_in / todo;
277
278 if ( mul == 0 ) {
279  mul = 1;
280 } else {
281  div = 1;
282 }
283
284 ROAR_DBG("streams_fill_mixbuffer(*): mul=%i, div=%i", mul, div);
285
286 ROAR_DBG("streams_fill_mixbuffer(*): rest=%p, todo=%i->%i (in->out)", rest, todo_in, todo);
287 // are both (input and output) of same format?
288
289
290 ROAR_DBG("streams_fill_mixbuffer(*): stream_info:");
291 roar_debug_audio_info_print(stream_info);
292 ROAR_DBG("streams_fill_mixbuffer(*): info:");
293 roar_debug_audio_info_print(info);
294
295 is_the_same = stream_info->rate     == info->rate     && stream_info->bits  == info->bits &&
296               stream_info->channels == info->channels && stream_info->codec == info->codec;
297
298 ROAR_DBG("streams_fill_mixbuffer(*): is_the_same=%i", is_the_same);
299
300/* How it works:
301 *
302 * set a counter to the number of samples we need.
303 * loop until we have all samples done or no samples are
304 * left in our input buffer.
305 * If there a no samples left in the input buffer: fill the rest
306 * of the output buffer with zeros.
307 *
308 * The loop:
309 * get a buffer from the input.
310 * if it's bigger than needed, set an offset.
311 * The rest of the data:
312 * 0) convert endianness (codec) from remote to local...
313 * 1) change bits in of the samples
314 * 2) change sample rate
315 * 3) change the nummber of channels
316 * 4) insert into output buffer
317 */
318
319/*
320 // get our first buffer:
321
322 if ( stream_shift_buffer(id, &buf) == -1 ) {
323  return -1;
324 }
325
326 // first test for some basic simple cases...
327
328 if ( buf == NULL ) { // we habe nothing in input queue
329                      // we may memset() our output buffer OR
330                      // just return with -1 so we are going to
331                      // be ignored.
332  return -1;
333 }
334*/
335
336 while (todo) { // main loop
337  ROAR_DBG("streams_fill_mixbuffer(*): looping...");
338  // exit loop if nothing is left, even if we need more data..
339  if ( stream_shift_buffer(id, &buf) == -1 )
340   break;
341  if ( buf == NULL )
342   break;
343
344  // read the data for this loop...
345  roar_buffer_get_data(buf, &in);
346  roar_buffer_get_len(buf, &len);
347
348  ROAR_DBG("streams_fill_mixbuffer(*): len = %i", len);
349
350  if ( len > todo_in ) {
351   roar_buffer_set_offset(buf, todo_in);
352   len = todo_in;
353  } else {
354   roar_buffer_set_len(buf, 0); // queue for deletation
355  }
356
357  // we now have 'len' bytes in 'in'
358
359  // calc how much outlen this has...
360  outlen = (len * mul) / div;
361
362  ROAR_DBG("streams_fill_mixbuffer(*): outlen = %i, buf = %p, len = %i", outlen, in, len);
363
364  if ( is_the_same ) {
365/*
366 * 0) convert endianness (codec) from remote to local...
367 * 1) change bits in of the samples
368 * 2) change sample rate
369 * 3) change the nummber of channels
370   \\==> skiping,...
371 */
372   // * 4) insert into output buffer
373   ROAR_DBG("streams_fill_mixbuffer(*): memcpy: in->rest: %p -> %p", in, rest);
374   if ( memcpy(rest, in, len) != rest ) {
375    ROAR_ERR("streams_fill_mixbuffer(*): memcpy returned invalid pointer.");
376   }
377
378  } else {
379
380/*
381   // * 0) convert endianness (codec) from remote to local...
382   if ( stream_info->codec != info->codec ) {
383    // we neet to convert...
384    return -1;
385   }
386
387   // * 1) change bits in of the samples
388   if ( stream_info->bits != info->bits ) {
389    return -1;
390   }
391
392   // * 2) change sample rate
393   if ( stream_info->rate != info->rate ) {
394    return -1;
395   }
396
397   // * 3) change the nummber of channels
398   if ( stream_info->channels != info->channels ) {
399    return -1;
400   }
401
402   // * 4) insert into output buffer
403*/
404  // hey! we have roar_conv() :)
405
406  if ( roar_conv(rest, in, 8*len / stream_info->bits, stream_info, info) == -1 )
407   return -1;
408  }
409
410  if ( change_vol(rest, info->bits, rest, 8*outlen / info->bits, info->channels, &(stream->mixer)) == -1 )
411   return -1;
412
413  // we habe outlen bytes more...
414  todo    -= outlen;
415  rest    += outlen;
416  todo_in -= len;
417
418  roar_buffer_get_len(buf, &len);
419  ROAR_DBG("streams_fill_mixbuffer(*): New length of buffer %p is %i", buf, len);
420  if ( len == 0 ) {
421   roar_buffer_delete(buf, NULL);
422  } else {
423   stream_unshift_buffer(id, buf);
424  }
425 }
426
427//len = 0;
428//roar_buffer_get_len(buf, &len);
429
430/*
431 if ( len > 0 ) // we still have some data in this buffer, re-inserting it to the input buffers...
432  stream_unshift_buffer(id, buf);
433 else
434  buffer_delete(buf, NULL);
435*/
436
437 ROAR_STREAM(g_streams[id])->pos =
438      ROAR_MATH_OVERFLOW_ADD(ROAR_STREAM(g_streams[id])->pos,
439          ROAR_OUTPUT_CALC_OUTBUFSAMP(info, needed-todo));
440 //ROAR_WARN("stream=%i, pos=%u", id, ((struct roar_stream*)g_streams[id])->pos);
441
442 if ( todo > 0 ) { // zeroize the rest of the buffer
443  memset(rest, 0, todo);
444
445  if ( todo != ROAR_OUTPUT_CALC_OUTBUFSIZE(info) ) {
446   if ( g_streams[id]->is_new ) {
447    stream->pre_underruns++;
448   } else {
449    ROAR_WARN("streams_fill_mixbuffer(*): Underrun in stream: %i bytes missing, filling with zeros", todo);
450    stream->post_underruns++;
451   }
452
453   stream->is_new = 0;
454  }
455 } else {
456  stream->is_new = 0;
457 }
458
459 return 0;
460}
461
462
463int streams_get_mixbuffers (void *** bufferlist, struct roar_audio_info * info, unsigned int pos) {
464 static void * bufs[ROAR_STREAMS_MAX+1];
465 int i;
466 int have = 0;
467
468 for (i = 0; i < ROAR_STREAMS_MAX; i++) {
469  if ( g_streams[i] != NULL ) {
470   if ( ROAR_STREAM(g_streams[i])->dir != ROAR_DIR_PLAY )
471    continue;
472
473   if ( streams_get_outputbuffer(i, &bufs[have], ROAR_OUTPUT_CALC_OUTBUFSIZE(info)) == -1 ) {
474    ROAR_ERR("streams_get_mixbuffer(*): Can not alloc output buffer for stream %i, BAD!", i);
475    ROAR_ERR("streams_get_mixbuffer(*): Ignoring stream for this round.");
476    continue;
477   }
478   if ( streams_fill_mixbuffer(i, info) == -1 ) {
479    ROAR_ERR("streams_get_mixbuffer(*): Can not fill output buffer for stream %i, this should not happen", i);
480    continue;
481   }
482
483//   printf("D: bufs[have=%i] = %p\n", have, bufs[have]);
484
485   ROAR_DBG("streams_get_mixbuffers(*):  bufs[have] = %p", bufs[have]);
486   ROAR_DBG("streams_get_mixbuffers(*): *bufs[have] = 0x%08x...", *(uint32_t*)bufs[have]);
487
488   have++; // we have a new stream!
489  }
490 }
491
492 bufs[have] = NULL;
493 //printf("D: bufs[have=%i] = %p\n", have, bufs[have]);
494
495 ROAR_DBG("streams_get_mixbuffers(*): have = %i", have);
496
497 *bufferlist = bufs;
498 return have;
499}
500
501
502int stream_add_buffer  (int id, struct roar_buffer * buf) {
503 ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf);
504
505 if ( g_streams[id] == NULL )
506  return -1;
507
508 if ( g_streams[id]->buffer == NULL ) {
509  g_streams[id]->buffer = buf;
510  ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = 0", id, buf);
511  return 0;
512 }
513
514 ROAR_DBG("stream_add_buffer(id=%i, buf=%p) = ?", id, buf);
515 return roar_buffer_add(g_streams[id]->buffer, buf);
516}
517
518int stream_shift_buffer   (int id, struct roar_buffer ** buf) {
519 struct roar_buffer * next;
520
521 if ( g_streams[id] == NULL )
522  return -1;
523
524 if ( g_streams[id]->buffer == NULL ) {
525  *buf = NULL;
526  return 0;
527 }
528
529 roar_buffer_get_next(g_streams[id]->buffer, &next);
530
531 *buf                  = g_streams[id]->buffer;
532 g_streams[id]->buffer = next;
533
534 return 0;
535}
536int stream_unshift_buffer (int id, struct roar_buffer *  buf) {
537 if ( g_streams[id] == NULL )
538  return -1;
539
540 if ( g_streams[id]->buffer == NULL ) {
541  g_streams[id]->buffer = buf;
542  return 0;
543 }
544
545 buf->next = NULL;
546
547 roar_buffer_add(buf, g_streams[id]->buffer);
548
549 g_streams[id]->buffer = buf;
550
551 return 0;
552}
553
554int streams_check  (int id) {
555 int fh;
556 ssize_t req, realreq, done;
557 struct roar_stream        *   s;
558 struct roar_stream_server *  ss;
559 struct roar_buffer        *   b;
560 char                      * buf;
561
562 if ( g_streams[id] == NULL )
563  return -1;
564
565 ROAR_DBG("streams_check(id=%i) = ?", id);
566
567 s = ROAR_STREAM(ss = g_streams[id]);
568
569 if ( (fh = s->fh) == -1 )
570  return 0;
571
572 if ( s->dir != ROAR_DIR_PLAY )
573  return 0;
574
575 ROAR_DBG("streams_check(id=%i): fh = %i", id, fh);
576
577 req  = ROAR_OUTPUT_BUFFER_SAMPLES * s->info.channels * s->info.bits / 8; // optimal size
578 req += ss->need_extra; // bytes left we sould get....
579
580 if ( roar_buffer_new(&b, req) == -1 ) {
581  ROAR_ERR("streams_check(*): Can not alloc buffer space!");
582  ROAR_DBG("streams_check(*) = -1");
583  return -1;
584 }
585
586 roar_buffer_get_data(b, (void **)&buf);
587
588 ROAR_DBG("streams_check(id=%i): buffer is up and ready ;)", id);
589
590 if ( ss->codecfilter == -1 ) {
591  realreq = req;
592/*
593  req = read(fh, buf, req);
594  if ( req < realreq ) { // we can do this as the stream is in nonblocking mode!
595   if ( (realreq = read(fh, buf+req, realreq-req)) > 0 )
596    req += realreq;
597  }
598*/
599  done = 0;
600  while (req > 0 && done != realreq) {
601   if ( (req = read(fh, buf+done, realreq-done)) > 0 )
602    done += req;
603  }
604  req = done;
605 } else {
606  req = codecfilter_read(ss->codecfilter_inst, ss->codecfilter, buf, req);
607 }
608
609 if ( req > 0 ) {
610  ROAR_DBG("streams_check(id=%i): got %i bytes", id, req);
611
612  roar_buffer_set_len(b, req);
613
614  if ( stream_add_buffer(id, b) != -1 )
615   return 0;
616
617  ROAR_ERR("streams_check(id=%i): something is wrong, could not add buffer to stream!", id);
618  roar_buffer_free(b);
619 } else {
620  ROAR_DBG("streams_check(id=%i): read() = %i // errno: %s", id, req, strerror(errno));
621#ifdef ROAR_HAVE_LIBVORBISFILE
622  if ( errno != EAGAIN && errno != ESPIPE ) { // libvorbis file trys to seek a bit ofen :)
623#else
624  if ( errno != EAGAIN ) {
625#endif
626   ROAR_DBG("streams_check(id=%i): EOF!", id);
627   streams_delete(id);
628   ROAR_DBG("streams_check(id=%i) = 0", id);
629  }
630  roar_buffer_free(b);
631  return 0;
632 }
633
634
635 ROAR_DBG("streams_check(id=%i) = -1", id);
636 return -1;
637}
638
639
640int streams_send_mon   (int id) {
641 int fh;
642 struct roar_stream        *   s;
643 struct roar_stream_server *  ss;
644 void * obuf;
645 int    olen;
646 int    need_to_free = 0;
647
648 if ( g_streams[id] == NULL )
649  return -1;
650
651 ROAR_DBG("streams_send_mon(id=%i) = ?", id);
652
653 s = ROAR_STREAM((ss = g_streams[id]));
654
655 if ( (fh = s->fh) == -1 )
656  return 0;
657
658 if ( s->dir != ROAR_DIR_MONITOR && s->dir != ROAR_DIR_OUTPUT )
659  return 0;
660
661 ROAR_DBG("streams_send_mon(id=%i): fh = %i", id, fh);
662
663 if ( s->info.channels != g_sa->channels || s->info.bits  != g_sa->bits ||
664      s->info.rate     != g_sa->rate     || s->info.codec != g_sa->codec  ) {
665  olen = ROAR_OUTPUT_CALC_OUTBUFSIZE(&(s->info)); // we hope g_output_buffer_len
666                                                  // is ROAR_OUTPUT_CALC_OUTBUFSIZE(g_sa) here
667  if ( (obuf = malloc(olen)) == NULL )
668   return -1;
669
670  need_to_free = 1;
671
672  ROAR_DBG("streams_send_mon(id=%i): obuf=%p, olen=%i", id, obuf, olen);
673
674  if ( roar_conv(obuf, g_output_buffer, ROAR_OUTPUT_BUFFER_SAMPLES*g_sa->channels, g_sa, &(s->info)) == -1 ) {
675   free(obuf);
676   return -1;
677  }
678 } else {
679  obuf = g_output_buffer;
680  olen = g_output_buffer_len;
681 }
682
683 errno = 0;
684
685 if ( ss->codecfilter == -1 ) {
686  if ( write(fh, obuf, olen) == olen ) {
687   if ( need_to_free ) free(obuf);
688   return 0;
689  }
690 } else {
691  if ( codecfilter_write(ss->codecfilter_inst, ss->codecfilter, obuf, olen)
692            == olen ) {
693   if ( need_to_free ) free(obuf);
694   return 0;
695  } else { // we cann't retry on codec filetered streams
696   if ( need_to_free ) free(obuf);
697   streams_delete(id);
698   return -1;
699  }
700 }
701
702 if ( errno == EAGAIN ) {
703  // ok, the client blocks for a moment, we try to sleep a bit an retry in the hope not to
704  // make any gapes in any output because of this
705
706  usleep(100); // 0.1ms
707
708  if ( write(fh, obuf, olen) == olen ) {
709   if ( need_to_free ) free(obuf);
710   return 0;
711  }
712 }
713
714 // ug... error... delete stream!
715
716 if ( need_to_free ) free(obuf);
717 streams_delete(id);
718
719 return -1;
720}
721
722int streams_send_filter(int id) {
723 int fh;
724 int have = 0;
725 int len;
726 struct roar_stream        *   s;
727 struct roar_stream_server *  ss;
728
729 if ( g_streams[id] == NULL )
730  return -1;
731
732 ROAR_DBG("streams_send_filter(id=%i) = ?", id);
733
734 s = ROAR_STREAM(ss = g_streams[id]);
735
736 if ( (fh = s->fh) == -1 )
737  return 0;
738
739 if ( s->dir != ROAR_DIR_FILTER )
740  return 0;
741
742 ROAR_DBG("streams_send_filter(id=%i): fh = %i", id, fh);
743
744 if ( write(fh, g_output_buffer, g_output_buffer_len) == g_output_buffer_len ) {
745  while ( have < g_output_buffer_len ) {
746   if ( (len = read(fh, g_output_buffer+have, g_output_buffer_len-have)) < 1 ) {
747    streams_delete(id);
748    return -1;
749   }
750   have += len;
751  }
752  return 0;
753 }
754
755 // ug... error... delete stream!
756
757 streams_delete(id);
758
759 return -1;
760}
761
762
763// VIO:
764
765ssize_t stream_vio_read (int stream, void *buf, size_t count) {
766 struct roar_stream_server * s = g_streams[stream];
767
768 if ( !s )
769  return -1;
770
771 return stream_vio_s_read(s, buf, count);
772}
773
774ssize_t stream_vio_write(int stream, void *buf, size_t count) {
775 struct roar_stream_server * s = g_streams[stream];
776
777 if ( !s )
778  return -1;
779
780 return stream_vio_s_write(s, buf, count);
781}
782
783
784ssize_t stream_vio_s_read (struct roar_stream_server * stream, void *buf, size_t count) {
785 errno = 0;
786
787 if ( !stream )
788  return -1;
789
790 if ( ! stream->vio.read )
791  return -1;
792
793 return stream->vio.read(ROAR_STREAM(stream)->fh, buf, count, stream->vio.inst);
794}
795
796ssize_t stream_vio_s_write(struct roar_stream_server * stream, void *buf, size_t count) {
797 errno = 0;
798
799 if ( !stream )
800  return -1;
801
802 if ( ! stream->vio.write )
803  return -1;
804
805 return stream->vio.write(ROAR_STREAM(stream)->fh, buf, count, stream->vio.inst);
806}
807
808//ll
Note: See TracBrowser for help on using the repository browser.