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