source: roaraudio/libroarpulse/stream.c @ 3466:6d461930b82b

Last change on this file since 3466:6d461930b82b was 3466:6d461930b82b, checked in by phi, 14 years ago

more debug lions, corrected number of fragments

File size: 23.7 KB
Line 
1//stream.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41struct _roar_pa_stream_cb {
42 union {
43  pa_stream_notify_cb_t  ncb;
44  pa_stream_request_cb_t rcb;
45  pa_stream_success_cb_t scb;
46 } cb;
47 void * userdata;
48};
49
50struct pa_stream {
51 size_t                  refc;
52 pa_context            * c;
53 struct roar_vio_calls   vio;
54 struct roar_stream      stream;
55 pa_stream_state_t       state;
56 pa_sample_spec          sspec;
57 pa_io_event           * io_event;
58 pa_timing_info          timinginfo;
59 pa_buffer_attr          bufattr;
60 pa_stream_direction_t   dir;
61 struct roar_buffer    * iobuffer;
62 struct {
63  size_t size;
64  size_t num;
65 } fragments;
66 struct {
67  struct _roar_pa_stream_cb change_state;
68  struct _roar_pa_stream_cb write;
69  struct _roar_pa_stream_cb read;
70  struct _roar_pa_stream_cb overflow;
71  struct _roar_pa_stream_cb underflow;
72  struct _roar_pa_stream_cb latency;
73  struct _roar_pa_stream_cb drain;
74 } cb;
75 struct {
76  pa_operation * drain;
77 } op;
78};
79
80typedef void pa_proplist;
81void pa_stream_set_state(pa_stream *s, pa_stream_state_t st);
82
83pa_stream* pa_stream_new_with_proplist(
84        pa_context *c                     ,
85        const char *name                  ,
86        const pa_sample_spec *ss          ,
87        const pa_channel_map *map         ,
88        pa_proplist *p                    );
89
90/** Create a new, unconnected stream with the specified name and sample type */
91pa_stream* pa_stream_new(
92        pa_context *c                     /**< The context to create this stream in */,
93        const char *name                  /**< A name for this stream */,
94        const pa_sample_spec *ss          /**< The desired sample format */,
95        const pa_channel_map *map         /**< The desired channel map, or NULL for default */) {
96 return pa_stream_new_with_proplist(c, name, ss, map, NULL);
97}
98
99pa_stream* pa_stream_new_with_proplist(
100        pa_context *c                     ,
101        const char *name                  ,
102        const pa_sample_spec *ss          ,
103        const pa_channel_map *map         ,
104        pa_proplist *p                    ) {
105 pa_stream * s;
106
107 ROAR_DBG("pa_stream_new_with_proplist(c=%p, name='%s', ss=%p, map=%p, p=%p) = ?", c, name, ss, map, p);
108
109 if ( p != NULL )
110  return NULL;
111
112 if ( (s = roar_mm_malloc(sizeof(pa_stream))) == NULL )
113  return NULL;
114
115 memset(s, 0, sizeof(pa_stream));
116
117 memcpy(&(s->sspec), ss, sizeof(pa_sample_spec));
118
119 ROAR_DBG("pa_stream_new_with_proplist(c=%p, name='%s', ss=%p, map=%p, p=%p) = ?", c, name, ss, map, p);
120
121 s->fragments.num  = 4;
122 s->fragments.size = 2048;
123
124 s->state = PA_STREAM_UNCONNECTED;
125 s->c     = c;
126 pa_context_ref(c);
127
128 ROAR_DBG("pa_stream_new_with_proplist(c=%p, name='%s', ss=%p, map=%p, p=%p) = ?", c, name, ss, map, p);
129
130 return s;
131}
132
133static void _pa_stream_free(pa_stream * s) {
134 pa_stream_disconnect(s);
135 pa_context_unref(s->c);
136 roar_mm_free(s);
137}
138
139/** Decrease the reference counter by one */
140void pa_stream_unref(pa_stream *s) {
141 if ( s == NULL )
142  return;
143
144 s->refc--;
145
146 if (s->refc < 1 )
147  _pa_stream_free(s);
148}
149
150/** Increase the reference counter by one */
151pa_stream *pa_stream_ref(pa_stream *s) {
152 if ( s == NULL )
153  return NULL;
154
155 s->refc++;
156
157 return s;
158}
159
160/** Return the current state of the stream */
161pa_stream_state_t pa_stream_get_state(pa_stream *p) {
162 if ( p == NULL )
163  return PA_STREAM_FAILED;
164
165 return p->state;
166}
167
168/** Return the context this stream is attached to */
169pa_context* pa_stream_get_context(pa_stream *p) {
170 if ( p == NULL )
171  return NULL;
172
173 return p->c;
174}
175
176/** Return the device (sink input or source output) index this stream is connected to */
177uint32_t pa_stream_get_index(pa_stream *s) {
178 return 0;
179}
180
181static void _roar_pa_stream_ioecb(pa_mainloop_api     * ea,
182                                  pa_io_event         * e,
183                                  int                   fd,
184                                  pa_io_event_flags_t   events,
185                                  void                * userdata) {
186 pa_stream * s = userdata;
187 void * data;
188 size_t len;
189 size_t ret;
190
191 ROAR_DBG("_roar_pa_stream_ioecb(*) = ?");
192
193 switch (s->dir) {
194  case PA_STREAM_PLAYBACK:
195    while ( s->iobuffer != NULL ) {
196     if ( roar_buffer_get_data(s->iobuffer, &data) == -1 )
197      return;
198
199     if ( roar_buffer_get_len(s->iobuffer, &len) == -1 )
200      return;
201
202     if ( (ret = roar_vio_write(&(s->vio), data, len)) == -1 )
203      return;
204
205     ROAR_DBG("_roar_pa_stream_ioecb(*): vio write() = %lli", (long long int) ret);
206
207     // TODO: handle errors
208     if ( ret == len ) {
209      roar_buffer_next(&(s->iobuffer));
210     } else {
211      roar_buffer_set_offset(s->iobuffer, ret);
212     }
213    }
214
215    if ( s->iobuffer == NULL ) {
216     ROAR_DBG("_roar_pa_stream_ioecb(*): disable IO events");
217     ea->io_enable(e, PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR);
218    }
219   break;
220  case PA_STREAM_RECORD:
221   break;
222  default:
223   return;
224 }
225
226 ROAR_DBG("_roar_pa_stream_ioecb(*) = (void)");
227}
228
229static int _roar_pa_stream_open (pa_stream *s,
230                                 const char *dev,
231                                 const pa_buffer_attr *attr,
232                                 pa_stream_flags_t flags,
233                                 pa_cvolume *volume,
234                                 pa_stream *sync_stream,
235                                 pa_stream_direction_t dir) {
236 struct roar_connection * con;
237 pa_mainloop_api * api;
238 pa_io_event_flags_t event_flags = PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR;
239 int fh;
240 int ctl = -1;
241
242 ROAR_DBG("_roar_pa_stream_open(s=%p, dev='%s', attr=%p, flags=%i, volume=%p, sync_stream=%p, dir=%i) = ?", s, dev, attr, flags, volume, sync_stream, dir);
243
244 if ( s == NULL )
245  return -1;
246
247 volume = NULL;
248
249 if ( attr != NULL || flags != 0 || volume != NULL || sync_stream != NULL ) {
250  pa_stream_set_state(s, PA_STREAM_FAILED);
251  return -1;
252 }
253
254 if ( (con = roar_pa_context_get_con(s->c)) == NULL ) {
255  pa_stream_set_state(s, PA_STREAM_FAILED);
256  return -1;
257 }
258
259 s->dir = dir;
260
261 switch (dir) {
262  case PA_STREAM_PLAYBACK:
263    s->stream.dir = ROAR_DIR_PLAY;
264    ctl           = ROAR_VIO_CTL_GET_SELECT_WRITE_FH;
265    event_flags  |= PA_IO_EVENT_OUTPUT;
266   break;
267  case PA_STREAM_RECORD:
268    s->stream.dir = ROAR_DIR_MONITOR;
269    ctl           = ROAR_VIO_CTL_GET_SELECT_READ_FH;
270    event_flags  |= PA_IO_EVENT_INPUT;
271   break;
272  default:
273    pa_stream_set_state(s, PA_STREAM_FAILED);
274    return -1;
275   break;
276 }
277
278 if ( roar_pa_sspec2auinfo(&(s->stream.info), &(s->sspec)) == -1 ) {
279  pa_stream_set_state(s, PA_STREAM_FAILED);
280  return -1;
281 }
282
283 if ( roar_vio_simple_new_stream_obj(&(s->vio), con, &(s->stream),
284                                     s->stream.info.rate, s->stream.info.channels,
285                                     s->stream.info.bits, s->stream.info.codec,
286                                     s->stream.dir) == -1 ) {
287  pa_stream_set_state(s, PA_STREAM_FAILED);
288  return -1;
289 }
290
291 api = roar_pa_context_get_api(s->c);
292
293 if ( api != NULL && api->io_new != NULL ) {
294  if ( roar_vio_ctl(&(s->vio), ctl, &fh) != -1 ) {
295   s->io_event = api->io_new(api, fh, event_flags, _roar_pa_stream_ioecb, s);
296  }
297 }
298
299 // TODO: update s->fragments.
300
301 s->bufattr.maxlength = s->fragments.size * s->fragments.num;
302 s->bufattr.tlength   = s->fragments.size;
303 s->bufattr.prebuf    = 0;
304 s->bufattr.minreq    = 1;
305 s->bufattr.fragsize  = s->fragments.size;
306
307 pa_stream_set_state(s, PA_STREAM_READY);
308
309 return 0;
310}
311
312/** Connect the stream to a sink */
313int pa_stream_connect_playback(
314        pa_stream *s                  /**< The stream to connect to a sink */,
315        const char *dev               /**< Name of the sink to connect to, or NULL for default */ ,
316        const pa_buffer_attr *attr    /**< Buffering attributes, or NULL for default */,
317        pa_stream_flags_t flags       /**< Additional flags, or 0 for default */,
318        pa_cvolume *volume            /**< Initial volume, or NULL for default */,
319        pa_stream *sync_stream        /**< Synchronize this stream with the specified one, or NULL for a standalone stream*/) {
320 return _roar_pa_stream_open(s, dev, attr, flags, volume, sync_stream, PA_STREAM_PLAYBACK);
321}
322
323/** Connect the stream to a source */
324int pa_stream_connect_record(
325        pa_stream *s                  /**< The stream to connect to a source */ ,
326        const char *dev               /**< Name of the source to connect to, or NULL for default */,
327        const pa_buffer_attr *attr    /**< Buffer attributes, or NULL for default */,
328        pa_stream_flags_t flags       /**< Additional flags, or 0 for default */) {
329 return _roar_pa_stream_open(s, dev, attr, flags, NULL, NULL, PA_STREAM_RECORD);
330}
331
332/** Disconnect a stream from a source/sink */
333int pa_stream_disconnect(pa_stream *s) {
334 pa_mainloop_api * api;
335
336 if ( s == NULL )
337  return -1;
338
339 if ( s->state != PA_STREAM_READY )
340  return -1;
341
342 if ( s->io_event != NULL ) {
343  api = roar_pa_context_get_api(s->c);
344
345  if ( api != NULL && api->io_free != NULL ) {
346   api->io_free(s->io_event);
347   s->io_event = NULL;
348  }
349 }
350
351 roar_vio_close(&(s->vio));
352
353 pa_stream_set_state(s, PA_STREAM_TERMINATED);
354
355 return 0;
356}
357
358/** Write some data to the server (for playback sinks), if free_cb is
359 * non-NULL this routine is called when all data has been written out
360 * and an internal reference to the specified data is kept, the data
361 * is not copied. If NULL, the data is copied into an internal
362 * buffer. The client my freely seek around in the output buffer. For
363 * most applications passing 0 and PA_SEEK_RELATIVE as arguments for
364 * offset and seek should be useful.*/
365int pa_stream_write(
366        pa_stream *p             /**< The stream to use */,
367        const void *data         /**< The data to write */,
368        size_t length            /**< The length of the data to write */,
369        pa_free_cb_t free_cb     /**< A cleanup routine for the data or NULL to request an internal copy */,
370        int64_t offset,          /**< Offset for seeking, must be 0 for upload streams */
371        pa_seek_mode_t seek      /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */) {
372 pa_mainloop_api    * api;
373 struct roar_buffer * buf;
374 void               * bufdata;
375
376 ROAR_DBG("pa_stream_write(p=%p, data=%p, length=%llu, free_cb=%p, offset=%lli, seek=%i) = ?", p, data, (long long unsigned int) length, free_cb, offset, seek);
377
378 // TODO: implement seeking in output buffer
379
380 if ( p == NULL )
381  return -1;
382
383 if ( offset != 0 || seek != PA_SEEK_RELATIVE )
384  return -1;
385
386 if ( data == NULL ) {
387  if ( length == 0 ) {
388   if ( free_cb != NULL )
389    free_cb(NULL);
390
391   return 0;
392  } else {
393   return -1;
394  }
395 }
396
397 // seems we have a valid write from here.
398
399 if ( roar_buffer_new(&buf, length) == -1 ) {
400  if ( free_cb != NULL )
401   free_cb((void*)data);
402
403  return -1;
404 }
405
406 if ( roar_buffer_get_data(buf, &bufdata) == -1 ) {
407  if ( free_cb != NULL )
408   free_cb((void*)data);
409
410  return -1;
411 }
412
413 memcpy(bufdata, data, length);
414 if ( free_cb != NULL )
415  free_cb((void*)data);
416
417 if ( p->iobuffer == NULL ) {
418  p->iobuffer = buf;
419 } else {
420  if ( roar_buffer_add(p->iobuffer, buf) == -1 )
421   return -1;
422 }
423
424 if ( p->io_event != NULL ) {
425  api = roar_pa_context_get_api(p->c);
426  if ( api != NULL ) {
427   ROAR_DBG("pa_stream_write(*): enable IO events");
428   api->io_enable(p->io_event, PA_IO_EVENT_OUTPUT|PA_IO_EVENT_HANGUP|PA_IO_EVENT_ERROR);
429  }
430 }
431
432 return 0;
433}
434
435/** Read the next fragment from the buffer (for recording).
436 * data will point to the actual data and length will contain the size
437 * of the data in bytes (which can be less than a complete framgnet).
438 * Use pa_stream_drop() to actually remove the data from the
439 * buffer. If no data is available will return a NULL pointer  \since 0.8 */
440int pa_stream_peek(
441        pa_stream *p                 /**< The stream to use */,
442        const void **data            /**< Pointer to pointer that will point to data */,
443        size_t *length              /**< The length of the data read */) {
444 if ( data == NULL || length == NULL )
445  return -1;
446
447 *data   = NULL;
448 *length = 0;
449
450 if ( p == NULL )
451  return -1;
452
453 if ( p->iobuffer == NULL )
454  return 0;
455
456 if ( roar_buffer_get_len(p->iobuffer, length) == -1 ) {
457  *length = 0;
458  return -1;
459 }
460
461 if ( roar_buffer_get_data(p->iobuffer, (void**)data) == -1 ) {
462  *length = 0;
463  *data   = NULL;
464  return -1;
465 }
466
467 return 0;
468}
469
470/** Remove the current fragment on record streams. It is invalid to do this without first
471 * calling pa_stream_peek(). \since 0.8 */
472int pa_stream_drop(pa_stream *p) {
473 if ( p == NULL )
474  return -1;
475
476 if ( p->iobuffer == NULL )
477  return -1;
478
479 return roar_buffer_next(&(p->iobuffer));
480}
481
482/** Return the nember of bytes that may be written using pa_stream_write() */
483size_t pa_stream_writable_size(pa_stream *p) {
484 struct roar_buffer_stats stats;
485
486 ROAR_DBG("pa_stream_writable_size(p=%p) = ?", p);
487
488 if ( p == NULL ) {
489  ROAR_DBG("pa_stream_writable_size(p=%p) = 0", p);
490  return 0;
491 }
492
493 if ( p->iobuffer == NULL ) {
494  ROAR_DBG("pa_stream_writable_size(p=%p) = %llu", p, (long long unsigned)(p->fragments.num*p->fragments.size));
495  return p->fragments.num * p->fragments.size / 2;
496 }
497
498 if ( roar_buffer_ring_stats(p->iobuffer, &stats) == -1 ) {
499  ROAR_DBG("pa_stream_writable_size(p=%p) = 0", p);
500  return 0;
501 }
502
503 ROAR_DBG("pa_stream_writable_size(p=%p): stats={.parts=%i, .bytes=%i, ...}", p, stats.parts, stats.bytes);
504
505 if ( stats.parts > p->fragments.num ) {
506  ROAR_DBG("pa_stream_writable_size(p=%p) = 0", p);
507  return 0;
508 }
509
510 if ( stats.parts > (p->fragments.num/2) )
511  stats.parts = p->fragments.num / 2;
512
513 ROAR_DBG("pa_stream_writable_size(p=%p) = %llu", p, (long long unsigned)((p->fragments.num - stats.parts)*p->fragments.size));
514 return (p->fragments.num - stats.parts)*p->fragments.size;
515}
516
517/** Return the number of bytes that may be read using pa_stream_read() \since 0.8 */
518size_t pa_stream_readable_size(pa_stream *p) {
519 struct roar_buffer_stats stats;
520
521 if ( p == NULL )
522  return 0;
523
524 if ( p->iobuffer == NULL )
525  return 0;
526
527 if ( roar_buffer_ring_stats(p->iobuffer, &stats) == -1 )
528  return 0;
529
530 return stats.bytes;
531}
532
533/** Drain a playback stream. Use this for notification when the buffer is empty */
534pa_operation* pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *userdata) {
535 if ( s == NULL )
536  return NULL;
537
538 s->cb.drain.cb.scb   = cb;
539 s->cb.drain.userdata = userdata;
540
541 if ( s->op.drain == NULL ) {
542  s->op.drain = roar_pa_operation_new(PA_OPERATION_RUNNING);
543 }
544
545 pa_operation_ref(s->op.drain);
546
547 return s->op.drain;
548}
549
550/** Request a timing info structure update for a stream. Use
551 * pa_stream_get_timing_info() to get access to the raw timing data,
552 * or pa_stream_get_time() or pa_stream_get_latency() to get cleaned
553 * up values. */
554pa_operation* pa_stream_update_timing_info(pa_stream *p, pa_stream_success_cb_t cb, void *userdata) {
555 int suc = 1;
556
557 if ( p == NULL )
558  return NULL;
559
560 if ( roar_get_stream(roar_pa_context_get_con(p->c), &(p->stream), p->stream.id) == -1 ) {
561  suc = 0;
562 }
563
564 // p->timinginfo
565 pa_gettimeofday(&(p->timinginfo.timestamp)); // we should interpolate between time before call and after
566
567 p->timinginfo.synchronized_clocks    = 0;
568 p->timinginfo.sink_usec              = 0;
569 p->timinginfo.source_usec            = 0;
570 p->timinginfo.transport_usec         = 0;
571 p->timinginfo.playing                = p->iobuffer != NULL;
572 p->timinginfo.write_index_corrupt    = 1;
573 p->timinginfo.write_index            = p->stream.pos * pa_frame_size(&(p->sspec));
574 p->timinginfo.read_index_corrupt     = 1;
575 p->timinginfo.read_index             = p->stream.pos * pa_frame_size(&(p->sspec));
576#if 0 /* newer versions */
577 p->timinginfo.configured_sink_usec   = p->timinginfo.sink_usec;
578 p->timinginfo.configured_source_usec = p->timinginfo.source_usec;
579 p->timinginfo.since_underrun         = 0;
580#endif
581
582 if ( cb != NULL ) {
583  cb(p, suc, userdata);
584 }
585
586 return roar_pa_op_new_done();
587}
588
589/** Set the callback function that is called whenever the state of the stream changes */
590void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata) {
591 ROAR_DBG("pa_stream_set_state_callback(s=%p, cb=%p, userdata=%p) = ?", s, cb, userdata);
592
593 if ( s == NULL )
594  return;
595
596 s->cb.change_state.cb.ncb    = cb;
597 s->cb.change_state.userdata  = userdata;
598}
599
600void pa_stream_set_state(pa_stream *s, pa_stream_state_t st) {
601 if ( s == NULL )
602  return;
603
604 ROAR_DBG("pa_stream_set_state(s=%p, st=%i): State: %i->%i", s, st, s->state, st);
605
606 s->state = st;
607
608 if ( s->cb.change_state.cb.ncb != NULL ) {
609  ROAR_DBG("pa_stream_set_state(s=%p, st=%i): calling callback at %p", s, st, s->cb.change_state.cb.ncb);
610  s->cb.change_state.cb.ncb(s, s->cb.change_state.userdata);
611 }
612 ROAR_DBG("pa_stream_set_state(s=%p, st=%i) = (void)", s, st);
613}
614
615/** Set the callback function that is called when new data may be
616 * written to the stream. */
617void pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata) {
618 if ( p == NULL )
619  return;
620
621 p->cb.write.cb.rcb    = cb;
622 p->cb.write.userdata  = userdata;
623}
624
625/** Set the callback function that is called when new data is available from the stream.
626 * Return the number of bytes read. \since 0.8 */
627void pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata) {
628 if ( p == NULL )
629  return;
630
631 p->cb.read.cb.rcb    = cb;
632 p->cb.read.userdata  = userdata;
633}
634
635/** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) \since 0.8 */
636void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata) {
637 if ( p == NULL )
638  return;
639
640 p->cb.overflow.cb.ncb    = cb;
641 p->cb.overflow.userdata  = userdata;
642}
643
644/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) \since 0.8 */
645void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata) {
646 if ( p == NULL )
647  return;
648
649 p->cb.underflow.cb.ncb    = cb;
650 p->cb.underflow.userdata  = userdata;
651}
652
653/** Set the callback function that is called whenever a latency information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE streams only. (Only for playback streams) \since 0.8.2 */
654void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata) {
655 if ( p == NULL )
656  return;
657
658 p->cb.latency.cb.ncb    = cb;
659 p->cb.latency.userdata  = userdata;
660}
661
662/** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. \since 0.3 */
663pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);
664
665/** Flush the playback buffer of this stream. Most of the time you're
666 * better off using the parameter delta of pa_stream_write() instead of this
667 * function. Available on both playback and recording streams. \since 0.3 */
668pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata) {
669 return pa_stream_drain(s, cb, userdata); // where is the differance to drain?
670}
671/** Reenable prebuffering as specified in the pa_buffer_attr
672 * structure. Available for playback streams only. \since 0.6 */
673pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
674
675/** Request immediate start of playback on this stream. This disables
676 * prebuffering as specified in the pa_buffer_attr
677 * structure, temporarily. Available for playback streams only. \since 0.3 */
678pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
679
680/** Rename the stream. \since 0.5 */
681pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata);
682
683/** Return the current playback/recording time. This is based on the
684 * data in the timing info structure returned by
685 * pa_stream_get_timing_info(). This function will usually only return
686 * new data if a timing info update has been recieved. Only if timing
687 * interpolation has been requested (PA_STREAM_INTERPOLATE_TIMING)
688 * the data from the last timing update is used for an estimation of
689 * the current playback/recording time based on the local time that
690 * passed since the timing info structure has been acquired. The time
691 * value returned by this function is guaranteed to increase
692 * monotonically. (that means: the returned value is always greater or
693 * equal to the value returned on the last call) This behaviour can
694 * be disabled by using PA_STREAM_NOT_MONOTONOUS. This may be
695 * desirable to deal better with bad estimations of transport
696 * latencies, but may have strange effects if the application is not
697 * able to deal with time going 'backwards'. \since 0.6 */
698int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec) {
699 if ( s == NULL || r_usec == NULL )
700  return -1;
701
702 *r_usec = s->stream.pos * 1000000 / s->stream.info.rate / s->stream.info.channels;
703
704 return 0;
705}
706
707/** Return the total stream latency. This function is based on
708 * pa_stream_get_time(). In case the stream is a monitoring stream the
709 * result can be negative, i.e. the captured samples are not yet
710 * played. In this case *negative is set to 1. \since 0.6 */
711int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative) {
712 // TODO: Fix this:
713 // sinks: lateny of stream, mixer, output...
714 // sources: mixer, output, negative
715
716 if ( r_usec != NULL )
717  *r_usec = 0;
718
719 if ( negative != NULL )
720  *negative = 0;
721
722 return 0;
723}
724
725/** Return the latest raw timing data structure. The returned pointer
726 * points to an internal read-only instance of the timing
727 * structure. The user should make a copy of this structure if he
728 * wants to modify it. An in-place update to this data structure may
729 * be requested using pa_stream_update_timing_info(). If no
730 * pa_stream_update_timing_info() call was issued before, this
731 * function will fail with PA_ERR_NODATA. Please note that the
732 * write_index member field (and only this field) is updated on each
733 * pa_stream_write() call, not just when a timing update has been
734 * recieved. \since 0.8 */
735const pa_timing_info* pa_stream_get_timing_info(pa_stream *s) {
736 if ( s == NULL )
737  return NULL;
738
739 return &(s->timinginfo);
740}
741
742/** Return a pointer to the stream's sample specification. \since 0.6 */
743const pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s) {
744 if ( s == NULL )
745  return NULL;
746
747 return &(s->sspec);
748}
749
750/** Return a pointer to the stream's channel map. \since 0.8 */
751const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
752
753/** Return the buffer metrics of the stream. Only valid after the
754 * stream has been connected successfuly and if the server is at least
755 * PulseAudio 0.9. \since 0.9.0 */
756const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s) {
757 if ( s == NULL )
758  return NULL;
759
760 return &(s->bufattr);
761}
762
763//ll
Note: See TracBrowser for help on using the repository browser.