]> code.delx.au - pulseaudio/blob - src/pulse/stream.h
Merge branch 'master' of git://0pointer.de/pulseaudio into dbus-work
[pulseaudio] / 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.1 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 const 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 /** Prepare writing data to the server (for playback streams). This
422 * function may be used to optimize the number of memory copies when
423 * doing playback ("zero-copy"). It is recommended to call this
424 * function before each call to pa_stream_write(). Pass in the address
425 * to a pointer and an address of the number of bytes you want to
426 * write. On return the two values will contain a pointer where you
427 * can place the data to write and the maximum number of bytes you can
428 * write. On return *nbytes can be smaller or have the same value as
429 * you passed in. You need to be able to handle both cases. Accessing
430 * memory beyond the returned *nbytes value is invalid. Acessing the
431 * memory returned after the following pa_stream_write() or
432 * pa_stream_cancel_write() is invalid. On invocation only *nbytes
433 * needs to be initialized, on return both *data and *nbytes will be
434 * valid. If you place (size_t) -1 in *nbytes on invocation the memory
435 * size will be chosen automatically (which is recommended to
436 * do). After placing your data in the memory area returned call
437 * pa_stream_write() with data set to an address within this memory
438 * area and an nbytes value that is smaller or equal to what was
439 * returned by this function to actually execute the write. An
440 * invocation of pa_stream_write() should follow "quickly" on
441 * pa_stream_begin_write(). It is not recommended letting an unbounded
442 * amount of time pass after calling pa_stream_begin_write() and
443 * before calling pa_stream_write(). If you want to cancel a
444 * previously called pa_stream_begin_write() without calling
445 * pa_stream_write() use pa_stream_cancel_write(). Calling
446 * pa_stream_begin_write() twice without calling pa_stream_write() or
447 * pa_stream_cancel_write() in between will return exactly the same
448 * pointer/nbytes values.\since 0.9.16 */
449 int pa_stream_begin_write(
450 pa_stream *p,
451 void **data,
452 size_t *nbytes);
453
454 /** Reverses the effect of pa_stream_begin_write() dropping all data
455 * that has already been placed in the memory area returned by
456 * pa_stream_begin_write(). Only valid to call if
457 * pa_stream_begin_write() was called before and neither
458 * pa_stream_cancel_write() nor pa_stream_write() have been called
459 * yet. Accessing the memory previously returned by
460 * pa_stream_begin_write() after this call is invalid. Any further
461 * explicit freeing of the memory area is not necessary. \since
462 * 0.9.16 */
463 int pa_stream_cancel_write(
464 pa_stream *p);
465
466 /** Write some data to the server (for playback streams), if free_cb
467 * is non-NULL this routine is called when all data has been written
468 * out and an internal reference to the specified data is kept, the
469 * data is not copied. If NULL, the data is copied into an internal
470 * buffer. The client may freely seek around in the output buffer. For
471 * most applications passing 0 and PA_SEEK_RELATIVE as arguments for
472 * offset and seek should be useful. Afte ther write call succeeded
473 * the write index will be a the position after where this chunk of
474 * data has been written to.
475 *
476 * As an optimization for avoiding needless memory copies you may call
477 * pa_stream_begin_write() before this call and then place your audio
478 * data directly in the memory area returned by that call. Then, pass
479 * a pointer to that memory area to pa_stream_write(). After the
480 * invocation of pa_stream_write() the memory area may no longer be
481 * accessed. Any further explicit freeing of the memory area is not
482 * necessary. It is OK to write the memory area returned by
483 * pa_stream_begin_write() only partially with this call, skipping
484 * bytes both at the end and at the beginning of the reserved memory
485 * area.*/
486 int pa_stream_write(
487 pa_stream *p /**< The stream to use */,
488 const void *data /**< The data to write */,
489 size_t nbytes /**< The length of the data to write in bytes*/,
490 pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */,
491 int64_t offset, /**< Offset for seeking, must be 0 for upload streams */
492 pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */);
493
494 /** Read the next fragment from the buffer (for recording streams).
495 * data will point to the actual data and nbytes will contain the size
496 * of the data in bytes (which can be less or more than a complete
497 * fragment). Use pa_stream_drop() to actually remove the data from
498 * the buffer. If no data is available this will return a NULL
499 * pointer */
500 int pa_stream_peek(
501 pa_stream *p /**< The stream to use */,
502 const void **data /**< Pointer to pointer that will point to data */,
503 size_t *nbytes /**< The length of the data read in bytes */);
504
505 /** Remove the current fragment on record streams. It is invalid to do this without first
506 * calling pa_stream_peek(). */
507 int pa_stream_drop(pa_stream *p);
508
509 /** Return the number of bytes that may be written using pa_stream_write() */
510 size_t pa_stream_writable_size(pa_stream *p);
511
512 /** Return the number of bytes that may be read using pa_stream_peek()*/
513 size_t pa_stream_readable_size(pa_stream *p);
514
515 /** Drain a playback stream. Use this for notification when the buffer
516 * is empty. Please note that only one drain operation per stream may
517 * be issued at a time. */
518 pa_operation* pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
519
520 /** Request a timing info structure update for a stream. Use
521 * pa_stream_get_timing_info() to get access to the raw timing data,
522 * or pa_stream_get_time() or pa_stream_get_latency() to get cleaned
523 * up values. */
524 pa_operation* pa_stream_update_timing_info(pa_stream *p, pa_stream_success_cb_t cb, void *userdata);
525
526 /** Set the callback function that is called whenever the state of the stream changes */
527 void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata);
528
529 /** Set the callback function that is called when new data may be
530 * written to the stream. */
531 void pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
532
533 /** Set the callback function that is called when new data is available from the stream.
534 * Return the number of bytes read.*/
535 void pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);
536
537 /** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) */
538 void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
539
540 /** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) */
541 void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
542
543 /** Set the callback function that is called when a the server starts
544 * playback after an underrun or on initial startup. This only informs
545 * that audio is flowing again, it is no indication that audio started
546 * to reach the speakers already. (Only for playback streams). \since
547 * 0.9.11 */
548 void pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
549
550 /** Set the callback function that is called whenever a latency
551 * information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE
552 * streams only. (Only for playback streams) */
553 void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
554
555 /** Set the callback function that is called whenever the stream is
556 * moved to a different sink/source. Use pa_stream_get_device_name()or
557 * pa_stream_get_device_index() to query the new sink/source. This
558 * notification is only generated when the server is at least
559 * 0.9.8. \since 0.9.8 */
560 void pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
561
562 /** Set the callback function that is called whenever the sink/source
563 * this stream is connected to is suspended or resumed. Use
564 * pa_stream_is_suspended() to query the new suspend status. Please
565 * note that the suspend status might also change when the stream is
566 * moved between devices. Thus if you call this function you very
567 * likely want to call pa_stream_set_moved_callback, too. This
568 * notification is only generated when the server is at least
569 * 0.9.8. \since 0.9.8 */
570 void pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
571
572 /** Set the callback function that is called whenver a meta/policy
573 * control event is received.\since 0.9.15 */
574 void pa_stream_set_event_callback(pa_stream *p, pa_stream_event_cb_t cb, void *userdata);
575
576 /** Set the callback function that is called whenver the buffer
577 * attributes on the server side change. Please note that the buffer
578 * attributes can change when moving a stream to a different
579 * sink/source too, hence if you use this callback you should use
580 * pa_stream_set_moved_callback() as well. \since 0.9.15 */
581 void pa_stream_set_buffer_attr_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);
582
583 /** Pause (or resume) playback of this stream temporarily. Available
584 * on both playback and recording streams. If b is 1 the stream is
585 * paused. If b is 0 the stream is resumed. The pause/resume operation
586 * is executed as quickly as possible. If a cork is very quickly
587 * followed by an uncork or the other way round this might not
588 * actually have any effect on the stream that is output. You can use
589 * pa_stream_is_corked() to find out whether the stream is currently
590 * paused or not. Normally a stream will be created in uncorked
591 * state. If you pass PA_STREAM_START_CORKED as flag during connection
592 * of the stream it will be created in corked state. */
593 pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);
594
595 /** Flush the playback buffer of this stream. Most of the time you're
596 * better off using the parameter delta of pa_stream_write() instead
597 * of this function. Available on both playback and recording
598 * streams. */
599 pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
600
601 /** Reenable prebuffering as specified in the pa_buffer_attr
602 * structure. Available for playback streams only. */
603 pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
604
605 /** Request immediate start of playback on this stream. This disables
606 * prebuffering as specified in the pa_buffer_attr structure,
607 * temporarily. Available for playback streams only. */
608 pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);
609
610 /** Rename the stream. */
611 pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata);
612
613 /** Return the current playback/recording time. This is based on the
614 * data in the timing info structure returned by
615 * pa_stream_get_timing_info().
616 *
617 * This function will usually only return new data if a timing info
618 * update has been recieved. Only if timing interpolation has been
619 * requested (PA_STREAM_INTERPOLATE_TIMING) the data from the last
620 * timing update is used for an estimation of the current
621 * playback/recording time based on the local time that passed since
622 * the timing info structure has been acquired.
623 *
624 * The time value returned by this function is guaranteed to increase
625 * monotonically. (that means: the returned value is always greater
626 * or equal to the value returned on the last call). This behaviour
627 * can be disabled by using PA_STREAM_NOT_MONOTONIC. This may be
628 * desirable to deal better with bad estimations of transport
629 * latencies, but may have strange effects if the application is not
630 * able to deal with time going 'backwards'.
631 *
632 * The time interpolator activated by PA_STREAM_INTERPOLATE_TIMING
633 * favours 'smooth' time graphs over accurate ones to improve the
634 * smoothness of UI operations that are tied to the audio clock. If
635 * accuracy is more important to you you might need to estimate your
636 * timing based on the data from pa_stream_get_timing_info() yourself
637 * or not work with interpolated timing at all and instead always
638 * query on the server side for the most up to date timing with
639 * pa_stream_update_timing_info().
640 *
641 * If no timing information has been
642 * recieved yet this call will return PA_ERR_NODATA. For more details
643 * see pa_stream_get_timing_info(). */
644 int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec);
645
646 /** Return the total stream latency. This function is based on
647 * pa_stream_get_time().
648 *
649 * In case the stream is a monitoring stream the result can be
650 * negative, i.e. the captured samples are not yet played. In this
651 * case *negative is set to 1.
652 *
653 * If no timing information has been recieved yet this call will
654 * return PA_ERR_NODATA. For more details see
655 * pa_stream_get_timing_info() and pa_stream_get_time(). */
656 int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative);
657
658 /** Return the latest raw timing data structure. The returned pointer
659 * points to an internal read-only instance of the timing
660 * structure. The user should make a copy of this structure if he
661 * wants to modify it. An in-place update to this data structure may
662 * be requested using pa_stream_update_timing_info().
663 *
664 * If no timing information has been received before (i.e. by
665 * requesting pa_stream_update_timing_info() or by using
666 * PA_STREAM_AUTO_TIMING_UPDATE), this function will fail with
667 * PA_ERR_NODATA.
668 *
669 * Please note that the write_index member field (and only this field)
670 * is updated on each pa_stream_write() call, not just when a timing
671 * update has been recieved. */
672 const pa_timing_info* pa_stream_get_timing_info(pa_stream *s);
673
674 /** Return a pointer to the stream's sample specification. */
675 const pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s);
676
677 /** Return a pointer to the stream's channel map. */
678 const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);
679
680 /** Return the per-stream server-side buffer metrics of the
681 * stream. Only valid after the stream has been connected successfuly
682 * and if the server is at least PulseAudio 0.9. This will return the
683 * actual configured buffering metrics, which may differ from what was
684 * requested during pa_stream_connect_record() or
685 * pa_stream_connect_playback(). This call will always return the
686 * actually per-stream server-side buffer metrics, regardless whether
687 * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.0 */
688 const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s);
689
690 /** Change the buffer metrics of the stream during playback. The
691 * server might have chosen different buffer metrics then
692 * requested. The selected metrics may be queried with
693 * pa_stream_get_buffer_attr() as soon as the callback is called. Only
694 * valid after the stream has been connected successfully and if the
695 * server is at least PulseAudio 0.9.8. Please be aware of the
696 * slightly different semantics of the call depending whether
697 * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.8 */
698 pa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata);
699
700 /** Change the stream sampling rate during playback. You need to pass
701 * PA_STREAM_VARIABLE_RATE in the flags parameter of
702 * pa_stream_connect() if you plan to use this function. Only valid
703 * after the stream has been connected successfully and if the server
704 * is at least PulseAudio 0.9.8. \since 0.9.8 */
705 pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata);
706
707 /** Update the property list of the sink input/source output of this
708 * stream, adding new entries. Please note that it is highly
709 * recommended to set as much properties initially via
710 * pa_stream_new_with_proplist() as possible instead a posteriori with
711 * this function, since that information may then be used to route
712 * this stream to the right device. \since 0.9.11 */
713 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);
714
715 /** Update the property list of the sink input/source output of this
716 * stream, remove entries. \since 0.9.11 */
717 pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata);
718
719 /** For record streams connected to a monitor source: monitor only a
720 * very specific sink input of the sink. Thus function needs to be
721 * called before pa_stream_connect_record() is called. \since
722 * 0.9.11 */
723 int pa_stream_set_monitor_stream(pa_stream *s, uint32_t sink_input_idx);
724
725 /** Return what has been set with pa_stream_set_monitor_stream()
726 * ebfore. \since 0.9.11 */
727 uint32_t pa_stream_get_monitor_stream(pa_stream *s);
728
729 PA_C_DECL_END
730
731 #endif