Merge commit 'elmarco/bt-wip'
[platform/upstream/pulseaudio.git] / src / pulse / stream.h
1 #ifndef foostreamhfoo
2 #define foostreamhfoo
3
4 /***
5   This file is part of PulseAudio.
6
7   Copyright 2004-2006 Lennart Poettering
8   Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10   PulseAudio is free software; you can redistribute it and/or modify
11   it under the terms of the GNU Lesser General Public License as published
12   by the Free Software Foundation; either version 2 of the License,
13   or (at your option) any later version.
14
15   PulseAudio is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with PulseAudio; if not, write to the Free Software
22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23   USA.
24 ***/
25
26 #include <sys/types.h>
27
28 #include <pulse/sample.h>
29 #include <pulse/channelmap.h>
30 #include <pulse/volume.h>
31 #include <pulse/def.h>
32 #include <pulse/cdecl.h>
33 #include <pulse/operation.h>
34
35 /** \page streams Audio Streams
36  *
37  * \section overv_sec Overview
38  *
39  * Audio streams form the central functionality of the sound server. Data is
40  * routed, converted and mixed from several sources before it is passed along
41  * to a final output. Currently, there are three forms of audio streams:
42  *
43  * \li Playback streams - Data flows from the client to the server.
44  * \li Record streams - Data flows from the server to the client.
45  * \li Upload streams - Similar to playback streams, but the data is stored in
46  *                      the sample cache. See \ref scache for more information
47  *                      about controlling the sample cache.
48  *
49  * \section create_sec Creating
50  *
51  * To access a stream, a pa_stream object must be created using
52  * pa_stream_new(). At this point the audio sample format and mapping of
53  * channels must be specified. See \ref sample and \ref channelmap for more
54  * information about those structures.
55  *
56  * This first step will only create a client-side object, representing the
57  * stream. To use the stream, a server-side object must be created and
58  * associated with the local object. Depending on which type of stream is
59  * desired, a different function is needed:
60  *
61  * \li Playback stream - pa_stream_connect_playback()
62  * \li Record stream - pa_stream_connect_record()
63  * \li Upload stream - pa_stream_connect_upload() (see \ref scache)
64  *
65  * Similar to how connections are done in contexts, connecting a stream will
66  * not generate a pa_operation object. Also like contexts, the application
67  * should register a state change callback, using
68  * pa_stream_set_state_callback(), and wait for the stream to enter an active
69  * state.
70  *
71  * \subsection bufattr_subsec Buffer Attributes
72  *
73  * Playback and record streams always have a server-side buffer as
74  * part of the data flow.  The size of this buffer needs to be chosen
75  * in a compromise between low latency and sensitivity for buffer
76  * overflows/underruns.
77  *
78  * The buffer metrics may be controlled by the application. They are
79  * described with a pa_buffer_attr structure which contains a number
80  * of fields:
81  *
82  * \li maxlength - The absolute maximum number of bytes that can be
83  *                 stored in the buffer. If this value is exceeded
84  *                 then data will be lost. It is recommended to pass
85  *                 (uint32_t) -1 here which will cause the server to
86  *                 fill in the maximum possible value.
87  *
88  * \li tlength - The target fill level of the playback buffer. The
89  *               server will only send requests for more data as long
90  *               as the buffer has less than this number of bytes of
91  *               data. If you pass (uint32_t) -1 (which is
92  *               recommended) here the server will choose the longest
93  *               target buffer fill level possible to minimize the
94  *               number of necessary wakeups and maximize drop-out
95  *               safety. This can exceed 2s of buffering. For
96  *               low-latency applications or applications where
97  *               latency matters you should pass a proper value here.
98  *
99  * \li prebuf - Number of bytes that need to be in the buffer before
100  *              playback will commence. Start of playback can be
101  *              forced using pa_stream_trigger() even though the
102  *              prebuffer size hasn't been reached. If a buffer
103  *              underrun occurs, this prebuffering will be again
104  *              enabled. If the playback shall never stop in case of a
105  *              buffer underrun, this value should be set to 0. In
106  *              that case the read index of the output buffer
107  *              overtakes the write index, and hence the fill level of
108  *              the buffer is negative. If you pass (uint32_t) -1 here
109  *              (which is recommended) the server will choose the same
110  *              value as tlength here.
111  *
112  * \li minreq - Minimum free number of the bytes in the playback
113  *              buffer before the server will request more data. It is
114  *              recommended to fill in (uint32_t) -1 here. This value
115  *              influences how much time the sound server has to move
116  *              data from the per-stream server-side playback buffer
117  *              to the hardware playback buffer.
118  *
119  * \li fragsize - Maximum number of bytes that the server will push in
120  *                one chunk for record streams. If you pass (uint32_t)
121  *                -1 (which is recommended) here, the server will
122  *                choose the longest fragment setting possible to
123  *                minimize the number of necessary wakeups and
124  *                maximize drop-out safety. This can exceed 2s of
125  *                buffering. For low-latency applications or
126  *                applications where latency matters you should pass a
127  *                proper value here.
128  *
129  * If PA_STREAM_ADJUST_LATENCY is set, then the tlength/fragsize
130  * parameters will be interpreted slightly differently than described
131  * above when passed to pa_stream_connect_record() and
132  * pa_stream_connect_playback(): the overall latency that is comprised
133  * of both the server side playback buffer length, the hardware
134  * playback buffer length and additional latencies will be adjusted in
135  * a way that it matches tlength resp. fragsize. Set
136  * PA_STREAM_ADJUST_LATENCY if you want to control the overall
137  * playback latency for your stream. Unset it if you want to control
138  * only the latency induced by the server-side, rewritable playback
139  * buffer. The server will try to fulfill the clients latency requests
140  * as good as possible. However if the underlying hardware cannot
141  * change the hardware buffer length or only in a limited range, the
142  * actually resulting latency might be different from what the client
143  * requested. Thus, for synchronization clients always need to check
144  * the actual measured latency via pa_stream_get_latency() or a
145  * similar call, and not make any assumptions. about the latency
146  * available. The function pa_stream_get_buffer_attr() will always
147  * return the actual size of the server-side per-stream buffer in
148  * tlength/fragsize, regardless whether PA_STREAM_ADJUST_LATENCY is
149  * set or not.
150  *
151  * The server-side per-stream playback buffers are indexed by a write and a read
152  * index. The application writes to the write index and the sound
153  * device reads from the read index. The read index is increased
154  * monotonically, while the write index may be freely controlled by
155  * the application. Substracting the read index from the write index
156  * will give you the current fill level of the buffer. The read/write
157  * indexes are 64bit values and measured in bytes, they will never
158  * wrap. The current read/write index may be queried using
159  * pa_stream_get_timing_info() (see below for more information). In
160  * case of a buffer underrun the read index is equal or larger than
161  * the write index. Unless the prebuf value is 0, PulseAudio will
162  * temporarily pause playback in such a case, and wait until the
163  * buffer is filled up to prebuf bytes again. If prebuf is 0, the
164  * read index may be larger than the write index, in which case
165  * silence is played. If the application writes data to indexes lower
166  * than the read index, the data is immediately lost.
167  *
168  * \section transfer_sec Transferring Data
169  *
170  * Once the stream is up, data can start flowing between the client and the
171  * server. Two different access models can be used to transfer the data:
172  *
173  * \li Asynchronous - The application register a callback using
174  *                    pa_stream_set_write_callback() and
175  *                    pa_stream_set_read_callback() to receive notifications
176  *                    that data can either be written or read.
177  * \li Polled - Query the library for available data/space using
178  *              pa_stream_writable_size() and pa_stream_readable_size() and
179  *              transfer data as needed. The sizes are stored locally, in the
180  *              client end, so there is no delay when reading them.
181  *
182  * It is also possible to mix the two models freely.
183  *
184  * Once there is data/space available, it can be transferred using either
185  * pa_stream_write() for playback, or pa_stream_peek() / pa_stream_drop() for
186  * record. Make sure you do not overflow the playback buffers as data will be
187  * dropped.
188  *
189  * \section bufctl_sec Buffer Control
190  *
191  * The transfer buffers can be controlled through a number of operations:
192  *
193  * \li pa_stream_cork() - Start or stop the playback or recording.
194  * \li pa_stream_trigger() - Start playback immediatly and do not wait for
195  *                           the buffer to fill up to the set trigger level.
196  * \li pa_stream_prebuf() - Reenable the playback trigger level.
197  * \li pa_stream_drain() - Wait for the playback buffer to go empty. Will
198  *                         return a pa_operation object that will indicate when
199  *                         the buffer is completely drained.
200  * \li pa_stream_flush() - Drop all data from the playback buffer and do not
201  *                         wait for it to finish playing.
202  *
203  * \section seek_modes Seeking in the Playback Buffer
204  *
205  * A client application may freely seek in the playback buffer. To
206  * accomplish that the pa_stream_write() function takes a seek mode
207  * and an offset argument. The seek mode is one of:
208  *
209  * \li PA_SEEK_RELATIVE - seek relative to the current write index
210  * \li PA_SEEK_ABSOLUTE - seek relative to the beginning of the playback buffer, (i.e. the first that was ever played in the stream)
211  * \li PA_SEEK_RELATIVE_ON_READ - seek relative to the current read index. Use this to write data to the output buffer that should be played as soon as possible
212  * \li PA_SEEK_RELATIVE_END - seek relative to the last byte ever written.
213  *
214  * If an application just wants to append some data to the output
215  * buffer, PA_SEEK_RELATIVE and an offset of 0 should be used.
216  *
217  * After a call to pa_stream_write() the write index will be left at
218  * the position right after the last byte of the written data.
219  *
220  * \section latency_sec Latency
221  *
222  * A major problem with networked audio is the increased latency caused by
223  * the network. To remedy this, PulseAudio supports an advanced system of
224  * monitoring the current latency.
225  *
226  * To get the raw data needed to calculate latencies, call
227  * pa_stream_get_timing_info(). This will give you a pa_timing_info
228  * structure that contains everything that is known about the server
229  * side buffer transport delays and the backend active in the
230  * server. (Besides other things it contains the write and read index
231  * values mentioned above.)
232  *
233  * This structure is updated every time a
234  * pa_stream_update_timing_info() operation is executed. (i.e. before
235  * the first call to this function the timing information structure is
236  * not available!) Since it is a lot of work to keep this structure
237  * up-to-date manually, PulseAudio can do that automatically for you:
238  * if PA_STREAM_AUTO_TIMING_UPDATE is passed when connecting the
239  * stream PulseAudio will automatically update the structure every
240  * 100ms and every time a function is called that might invalidate the
241  * previously known timing data (such as pa_stream_write() or
242  * pa_stream_flush()). Please note however, that there always is a
243  * short time window when the data in the timing information structure
244  * is out-of-date. PulseAudio tries to mark these situations by
245  * setting the write_index_corrupt and read_index_corrupt fields
246  * accordingly.
247  *
248  * The raw timing data in the pa_timing_info structure is usually hard
249  * to deal with. Therefore a simpler interface is available:
250  * you can call pa_stream_get_time() or pa_stream_get_latency(). The
251  * former will return the current playback time of the hardware since
252  * the stream has been started. The latter returns the overall time a sample
253  * that you write now takes to be played by the hardware. These two
254  * functions base their calculations on the same data that is returned
255  * by pa_stream_get_timing_info(). Hence the same rules for keeping
256  * the timing data up-to-date apply here. In case the write or read
257  * index is corrupted, these two functions will fail with
258  * PA_ERR_NODATA set.
259  *
260  * Since updating the timing info structure usually requires a full
261  * network round trip and some applications monitor the timing very
262  * often PulseAudio offers a timing interpolation system. If
263  * PA_STREAM_INTERPOLATE_TIMING is passed when connecting the stream,
264  * pa_stream_get_time() and pa_stream_get_latency() will try to
265  * interpolate the current playback time/latency by estimating the
266  * number of samples that have been played back by the hardware since
267  * the last regular timing update. It is espcially useful to combine
268  * this option with PA_STREAM_AUTO_TIMING_UPDATE, which will enable
269  * you to monitor the current playback time/latency very precisely and
270  * very frequently without requiring a network round trip every time.
271  *
272  * \section flow_sec Overflow and underflow
273  *
274  * Even with the best precautions, buffers will sometime over - or
275  * underflow.  To handle this gracefully, the application can be
276  * notified when this happens. Callbacks are registered using
277  * pa_stream_set_overflow_callback() and
278  * pa_stream_set_underflow_callback().
279  *
280  * \section sync_streams Sychronizing Multiple Playback Streams
281  *
282  * PulseAudio allows applications to fully synchronize multiple
283  * playback streams that are connected to the same output device. That
284  * means the streams will always be played back sample-by-sample
285  * synchronously. If stream operations like pa_stream_cork() are
286  * issued on one of the synchronized streams, they are simultaneously
287  * issued on the others.
288  *
289  * To synchronize a stream to another, just pass the "master" stream
290  * as last argument to pa_stream_connect_playack(). To make sure that
291  * the freshly created stream doesn't start playback right-away, make
292  * sure to pass PA_STREAM_START_CORKED and - after all streams have
293  * been created - uncork them all with a single call to
294  * pa_stream_cork() for the master stream.
295  *
296  * To make sure that a particular stream doesn't stop to play when a
297  * server side buffer underrun happens on it while the other
298  * synchronized streams continue playing and hence deviate you need to
299  * pass a "prebuf" pa_buffer_attr of 0 when connecting it.
300  *
301  * \section disc_sec Disconnecting
302  *
303  * When a stream has served is purpose it must be disconnected with
304  * pa_stream_disconnect(). If you only unreference it, then it will live on
305  * and eat resources both locally and on the server until you disconnect the
306  * context.
307  *
308  */
309
310 /** \file
311  * Audio streams for input, output and sample upload */
312
313 PA_C_DECL_BEGIN
314
315 /** An opaque stream for playback or recording */
316 typedef struct pa_stream pa_stream;
317
318 /** A generic callback for operation completion */
319 typedef void (*pa_stream_success_cb_t) (pa_stream*s, int success, void *userdata);
320
321 /** A generic request callback */
322 typedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t bytes, void *userdata);
323
324 /** A generic notification callback */
325 typedef void (*pa_stream_notify_cb_t)(pa_stream *p, void *userdata);
326
327 /** A callback for asynchronous meta/policy event messages. Well known
328  * event names are PA_STREAM_EVENT_REQUEST_CORK and
329  * PA_STREAM_EVENT_REQUEST_UNCORK. The set of defined events can be
330  * extended at any time. Also, server modules may introduce additional
331  * message types so make sure that your callback function ignores messages
332  * it doesn't know. \since 0.9.15 */
333 typedef void (*pa_stream_event_cb_t)(pa_stream *p, const char *name, pa_proplist *pl, void *userdata);
334
335 /** Create a new, unconnected stream with the specified name and
336  * sample type. It is recommended to use pa_stream_new_with_proplist()
337  * instead and specify some initial properties. */
338 pa_stream* pa_stream_new(
339         pa_context *c                     /**< The context to create this stream in */,
340         const char *name                  /**< A name for this stream */,
341         const pa_sample_spec *ss          /**< The desired sample format */,
342         const pa_channel_map *map         /**< The desired channel map, or NULL for default */);
343
344 /** Create a new, unconnected stream with the specified name and
345  * sample type, and specify the the initial stream property
346  * list. \since 0.9.11 */
347 pa_stream* pa_stream_new_with_proplist(
348         pa_context *c                     /**< The context to create this stream in */,
349         const char *name                  /**< A name for this stream */,
350         const pa_sample_spec *ss          /**< The desired sample format */,
351         const pa_channel_map *map         /**< The desired channel map, or NULL for default */,
352         pa_proplist *p                    /**< The initial property list */);
353
354 /** Decrease the reference counter by one */
355 void pa_stream_unref(pa_stream *s);
356
357 /** Increase the reference counter by one */
358 pa_stream *pa_stream_ref(pa_stream *s);
359
360 /** Return the current state of the stream */
361 pa_stream_state_t pa_stream_get_state(pa_stream *p);
362
363 /** Return the context this stream is attached to */
364 pa_context* pa_stream_get_context(pa_stream *p);
365
366 /** Return the sink input resp. source output index this stream is
367  * identified in the server with. This is useful for usage with the
368  * introspection functions, such as pa_context_get_sink_input_info()
369  * resp. pa_context_get_source_output_info(). */
370 uint32_t pa_stream_get_index(pa_stream *s);
371
372 /** Return the index of the sink or source this stream is connected to
373  * in the server. This is useful for usage with the introspection
374  * functions, such as pa_context_get_sink_info_by_index()
375  * resp. pa_context_get_source_info_by_index(). Please note that
376  * streams may be moved between sinks/sources and thus it is
377  * recommended to use pa_stream_set_moved_callback() to be notified
378  * about this. This function will return with PA_ERR_NOTSUPPORTED when the
379  * server is older than 0.9.8. \since 0.9.8 */
380 uint32_t pa_stream_get_device_index(pa_stream *s);
381
382 /** Return the name of the sink or source this stream is connected to
383  * in the server. This is useful for usage with the introspection
384  * functions, such as pa_context_get_sink_info_by_name()
385  * resp. pa_context_get_source_info_by_name(). Please note that
386  * streams may be moved between sinks/sources and thus it is
387  * recommended to use pa_stream_set_moved_callback() to be notified
388  * about this. This function will return with PA_ERR_NOTSUPPORTED when the
389  * server is older than 0.9.8. \since 0.9.8 */
390 const char *pa_stream_get_device_name(pa_stream *s);
391
392 /** Return 1 if the sink or source this stream is connected to has
393  * been suspended. This will return 0 if not, and negative on
394  * error. This function will return with PA_ERR_NOTSUPPORTED when the
395  * server is older than 0.9.8. \since 0.9.8 */
396 int pa_stream_is_suspended(pa_stream *s);
397
398 /** Return 1 if the this stream has been corked. This will return 0 if
399  * not, and negative on error. \since 0.9.11 */
400 int pa_stream_is_corked(pa_stream *s);
401
402 /** Connect the stream to a sink */
403 int pa_stream_connect_playback(
404         pa_stream *s                  /**< The stream to connect to a sink */,
405         const char *dev               /**< Name of the sink to connect to, or NULL for default */ ,
406         const pa_buffer_attr *attr    /**< Buffering attributes, or NULL for default */,
407         pa_stream_flags_t flags       /**< Additional flags, or 0 for default */,
408         pa_cvolume *volume            /**< Initial volume, or NULL for default */,
409         pa_stream *sync_stream        /**< Synchronize this stream with the specified one, or NULL for a standalone stream*/);
410
411 /** Connect the stream to a source */
412 int pa_stream_connect_record(
413         pa_stream *s                  /**< The stream to connect to a source */ ,
414         const char *dev               /**< Name of the source to connect to, or NULL for default */,
415         const pa_buffer_attr *attr    /**< Buffer attributes, or NULL for default */,
416         pa_stream_flags_t flags       /**< Additional flags, or 0 for default */);
417
418 /** Disconnect a stream from a source/sink */
419 int pa_stream_disconnect(pa_stream *s);
420
421 /** Write some data to the server (for playback sinks), if free_cb is
422  * non-NULL this routine is called when all data has been written out
423  * and an internal reference to the specified data is kept, the data
424  * is not copied. If NULL, the data is copied into an internal
425  * buffer. The client my freely seek around in the output buffer. For
426  * most applications passing 0 and PA_SEEK_RELATIVE as arguments for
427  * offset and seek should be useful.*/
428 int pa_stream_write(
429         pa_stream *p             /**< The stream to use */,
430         const void *data         /**< The data to write */,
431         size_t nbytes            /**< The length of the data to write in bytes*/,
432         pa_free_cb_t free_cb     /**< A cleanup routine for the data or NULL to request an internal copy */,
433         int64_t offset,          /**< Offset for seeking, must be 0 for upload streams */
434         pa_seek_mode_t seek      /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */);
435
436 /** Read the next fragment from the buffer (for recording).
437  * data will point to the actual data and length will contain the size
438  * of the data in bytes (which can be less than a complete framgnet).
439  * Use pa_stream_drop() to actually remove the data from the
440  * buffer. If no data is available will return a NULL pointer */
441 int pa_stream_peek(
442         pa_stream *p                 /**< The stream to use */,
443         const void **data            /**< Pointer to pointer that will point to data */,
444         size_t *nbytes               /**< The length of the data read in bytes */);
445
446 /** Remove the current fragment on record streams. It is invalid to do this without first
447  * calling pa_stream_peek(). */
448 int pa_stream_drop(pa_stream *p);
449
450 /** Return the number of bytes that may be written using pa_stream_write() */
451 size_t pa_stream_writable_size(pa_stream *p);
452
453 /** Return the number of bytes that may be read using pa_stream_peek()*/
454 size_t pa_stream_readable_size(pa_stream *p);
455
456 /** Drain a playback stream. Use this for notification when the buffer is empty */
457 pa_operation* pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
458
459 /** Request a timing info structure update for a stream. Use
460  * pa_stream_get_timing_info() to get access to the raw timing data,
461  * or pa_stream_get_time() or pa_stream_get_latency() to get cleaned
462  * up values. */
463 pa_operation* pa_stream_update_timing_info(pa_stream *p, pa_stream_success_cb_t cb, void *userdata);
464
465 /** Set the callback function that is called whenever the state of the stream changes */
466 void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata);
467
468 /** Set the callback function that is called when new data may be
469  * written to the stream. */
470 void pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
471
472 /** Set the callback function that is called when new data is available from the stream.
473  * Return the number of bytes read.*/
474 void pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
475
476 /** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) */
477 void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
478
479 /** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) */
480 void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
481
482 /** Set the callback function that is called when a the server starts
483  * playback after an underrun or on initial startup. This only informs
484  * that audio is flowing again, it is no indication that audio started
485  * to reach the speakers already. (Only for playback streams). \since
486  * 0.9.11 */
487 void pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
488
489 /** Set the callback function that is called whenever a latency
490  * information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE
491  * streams only. (Only for playback streams) */
492 void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
493
494 /** Set the callback function that is called whenever the stream is
495  * moved to a different sink/source. Use pa_stream_get_device_name()or
496  * pa_stream_get_device_index() to query the new sink/source. This
497  * notification is only generated when the server is at least
498  * 0.9.8. \since 0.9.8 */
499 void pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
500
501 /** Set the callback function that is called whenever the sink/source
502  * this stream is connected to is suspended or resumed. Use
503  * pa_stream_is_suspended() to query the new suspend status. Please
504  * note that the suspend status might also change when the stream is
505  * moved between devices. Thus if you call this function you very
506  * likely want to call pa_stream_set_moved_callback, too. This
507  * notification is only generated when the server is at least
508  * 0.9.8. \since 0.9.8 */
509 void pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
510
511 /** Set the callback function that is called whenver a meta/policy
512  * control event is received.\since 0.9.15 */
513 void pa_stream_set_event_callback(pa_stream *p, pa_stream_event_cb_t cb, void *userdata);
514
515 /** Pause (or resume) playback of this stream temporarily. Available on both playback and recording streams. */
516 pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);
517
518 /** Flush the playback buffer of this stream. Most of the time you're
519  * better off using the parameter delta of pa_stream_write() instead
520  * of this function. Available on both playback and recording
521  * streams. */
522 pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
523
524 /** Reenable prebuffering as specified in the pa_buffer_attr
525  * structure. Available for playback streams only. */
526 pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
527
528 /** Request immediate start of playback on this stream. This disables
529  * prebuffering as specified in the pa_buffer_attr structure,
530  * temporarily. Available for playback streams only. */
531 pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
532
533 /** Rename the stream.*/
534 pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata);
535
536 /** Return the current playback/recording time. This is based on the
537  * data in the timing info structure returned by
538  * pa_stream_get_timing_info(). This function will usually only return
539  * new data if a timing info update has been recieved. Only if timing
540  * interpolation has been requested (PA_STREAM_INTERPOLATE_TIMING)
541  * the data from the last timing update is used for an estimation of
542  * the current playback/recording time based on the local time that
543  * passed since the timing info structure has been acquired. The time
544  * value returned by this function is guaranteed to increase
545  * monotonically. (that means: the returned value is always greater or
546  * equal to the value returned on the last call) This behaviour can
547  * be disabled by using PA_STREAM_NOT_MONOTONIC. This may be
548  * desirable to deal better with bad estimations of transport
549  * latencies, but may have strange effects if the application is not
550  * able to deal with time going 'backwards'. */
551 int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec);
552
553 /** Return the total stream latency. This function is based on
554  * pa_stream_get_time(). In case the stream is a monitoring stream the
555  * result can be negative, i.e. the captured samples are not yet
556  * played. In this case *negative is set to 1. */
557 int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative);
558
559 /** Return the latest raw timing data structure. The returned pointer
560  * points to an internal read-only instance of the timing
561  * structure. The user should make a copy of this structure if he
562  * wants to modify it. An in-place update to this data structure may
563  * be requested using pa_stream_update_timing_info(). If no
564  * pa_stream_update_timing_info() call was issued before, this
565  * function will fail with PA_ERR_NODATA. Please note that the
566  * write_index member field (and only this field) is updated on each
567  * pa_stream_write() call, not just when a timing update has been
568  * recieved. */
569 const pa_timing_info* pa_stream_get_timing_info(pa_stream *s);
570
571 /** Return a pointer to the stream's sample specification. */
572 const pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s);
573
574 /** Return a pointer to the stream's channel map. */
575 const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
576
577 /** Return the per-stream server-side buffer metrics of the
578  * stream. Only valid after the stream has been connected successfuly
579  * and if the server is at least PulseAudio 0.9. This will return the
580  * actual configured buffering metrics, which may differ from what was
581  * requested during pa_stream_connect_record() or
582  * pa_stream_connect_playback(). This call will always return the
583  * actually per-stream server-side buffer metrics, regardless whether
584  * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.0 */
585 const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s);
586
587 /** Change the buffer metrics of the stream during playback. The
588  * server might have chosen different buffer metrics then
589  * requested. The selected metrics may be queried with
590  * pa_stream_get_buffer_attr() as soon as the callback is called. Only
591  * valid after the stream has been connected successfully and if the
592  * server is at least PulseAudio 0.9.8. Please be aware of the
593  * slightly different semantics of the call depending whether
594  * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.8 */
595 pa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata);
596
597 /** Change the stream sampling rate during playback. You need to pass
598  * PA_STREAM_VARIABLE_RATE in the flags parameter of
599  * pa_stream_connect() if you plan to use this function. Only valid
600  * after the stream has been connected successfully and if the server
601  * is at least PulseAudio 0.9.8. \since 0.9.8 */
602 pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata);
603
604 /** Update the property list of the sink input/source output of this
605  * stream, adding new entries. Please note that it is highly
606  * recommended to set as much properties initially via
607  * pa_stream_new_with_proplist() as possible instead a posteriori with
608  * this function, since that information may then be used to route
609  * this stream to the right device. \since 0.9.11 */
610 pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata);
611
612 /** Update the property list of the sink input/source output of this
613  * stream, remove entries. \since 0.9.11 */
614 pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata);
615
616 /** For record streams connected to a monitor source: monitor only a
617  * very specific sink input of the sink. Thus function needs to be
618  * called before pa_stream_connect_record() is called. \since
619  * 0.9.11 */
620 int pa_stream_set_monitor_stream(pa_stream *s, uint32_t sink_input_idx);
621
622 /** Return what has been set with pa_stream_set_monitor_stream()
623  * ebfore. \since 0.9.11 */
624 uint32_t pa_stream_get_monitor_stream(pa_stream *s);
625
626 PA_C_DECL_END
627
628 #endif