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