153a5a1b3Sopenharmony_ci#ifndef foostreamhfoo 253a5a1b3Sopenharmony_ci#define foostreamhfoo 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci/*** 553a5a1b3Sopenharmony_ci This file is part of PulseAudio. 653a5a1b3Sopenharmony_ci 753a5a1b3Sopenharmony_ci Copyright 2004-2006 Lennart Poettering 853a5a1b3Sopenharmony_ci Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB 953a5a1b3Sopenharmony_ci 1053a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 1153a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 1253a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 1353a5a1b3Sopenharmony_ci or (at your option) any later version. 1453a5a1b3Sopenharmony_ci 1553a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1653a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1753a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1853a5a1b3Sopenharmony_ci General Public License for more details. 1953a5a1b3Sopenharmony_ci 2053a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 2153a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 2253a5a1b3Sopenharmony_ci***/ 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include <sys/types.h> 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <pulse/sample.h> 2753a5a1b3Sopenharmony_ci#include <pulse/format.h> 2853a5a1b3Sopenharmony_ci#include <pulse/channelmap.h> 2953a5a1b3Sopenharmony_ci#include <pulse/volume.h> 3053a5a1b3Sopenharmony_ci#include <pulse/def.h> 3153a5a1b3Sopenharmony_ci#include <pulse/cdecl.h> 3253a5a1b3Sopenharmony_ci#include <pulse/operation.h> 3353a5a1b3Sopenharmony_ci#include <pulse/context.h> 3453a5a1b3Sopenharmony_ci#include <pulse/proplist.h> 3553a5a1b3Sopenharmony_ci 3653a5a1b3Sopenharmony_ci/** \page streams Audio Streams 3753a5a1b3Sopenharmony_ci * 3853a5a1b3Sopenharmony_ci * \section overv_sec Overview 3953a5a1b3Sopenharmony_ci * 4053a5a1b3Sopenharmony_ci * Audio streams form the central functionality of the sound server. Data is 4153a5a1b3Sopenharmony_ci * routed, converted and mixed from several sources before it is passed along 4253a5a1b3Sopenharmony_ci * to a final output. Currently, there are three forms of audio streams: 4353a5a1b3Sopenharmony_ci * 4453a5a1b3Sopenharmony_ci * \li Playback streams - Data flows from the client to the server. 4553a5a1b3Sopenharmony_ci * \li Record streams - Data flows from the server to the client. 4653a5a1b3Sopenharmony_ci * \li Upload streams - Similar to playback streams, but the data is stored in 4753a5a1b3Sopenharmony_ci * the sample cache. See \ref scache for more information 4853a5a1b3Sopenharmony_ci * about controlling the sample cache. 4953a5a1b3Sopenharmony_ci * 5053a5a1b3Sopenharmony_ci * \section create_sec Creating 5153a5a1b3Sopenharmony_ci * 5253a5a1b3Sopenharmony_ci * To access a stream, a pa_stream object must be created using 5353a5a1b3Sopenharmony_ci * pa_stream_new() or pa_stream_new_extended(). pa_stream_new() is for PCM 5453a5a1b3Sopenharmony_ci * streams only, while pa_stream_new_extended() can be used for both PCM and 5553a5a1b3Sopenharmony_ci * compressed audio streams. At this point the application must specify what 5653a5a1b3Sopenharmony_ci * stream format(s) it supports. See \ref sample and \ref channelmap for more 5753a5a1b3Sopenharmony_ci * information on the stream format parameters. FIXME: Those references only 5853a5a1b3Sopenharmony_ci * talk about PCM parameters, we should also have an overview page for how the 5953a5a1b3Sopenharmony_ci * pa_format_info based stream format configuration works. Bug filed: 6053a5a1b3Sopenharmony_ci * https://bugs.freedesktop.org/show_bug.cgi?id=72265 6153a5a1b3Sopenharmony_ci * 6253a5a1b3Sopenharmony_ci * This first step will only create a client-side object, representing the 6353a5a1b3Sopenharmony_ci * stream. To use the stream, a server-side object must be created and 6453a5a1b3Sopenharmony_ci * associated with the local object. Depending on which type of stream is 6553a5a1b3Sopenharmony_ci * desired, a different function is needed: 6653a5a1b3Sopenharmony_ci * 6753a5a1b3Sopenharmony_ci * \li Playback stream - pa_stream_connect_playback() 6853a5a1b3Sopenharmony_ci * \li Record stream - pa_stream_connect_record() 6953a5a1b3Sopenharmony_ci * \li Upload stream - pa_stream_connect_upload() (see \ref scache) 7053a5a1b3Sopenharmony_ci * 7153a5a1b3Sopenharmony_ci * Similar to how connections are done in contexts, connecting a stream will 7253a5a1b3Sopenharmony_ci * not generate a pa_operation object. Also like contexts, the application 7353a5a1b3Sopenharmony_ci * should register a state change callback, using 7453a5a1b3Sopenharmony_ci * pa_stream_set_state_callback(), and wait for the stream to enter an active 7553a5a1b3Sopenharmony_ci * state. 7653a5a1b3Sopenharmony_ci * 7753a5a1b3Sopenharmony_ci * Note: there is a user-controllable slider in mixer applications such as 7853a5a1b3Sopenharmony_ci * pavucontrol corresponding to each of the created streams. Multiple 7953a5a1b3Sopenharmony_ci * (especially identically named) volume sliders for the same application might 8053a5a1b3Sopenharmony_ci * confuse the user. Also, the server supports only a limited number of 8153a5a1b3Sopenharmony_ci * simultaneous streams. Because of this, it is not always appropriate to 8253a5a1b3Sopenharmony_ci * create multiple streams in one application that needs to output multiple 8353a5a1b3Sopenharmony_ci * sounds. The rough guideline is: if there is no use case that would require 8453a5a1b3Sopenharmony_ci * separate user-initiated volume changes for each stream, perform the mixing 8553a5a1b3Sopenharmony_ci * inside the application. 8653a5a1b3Sopenharmony_ci * 8753a5a1b3Sopenharmony_ci * \subsection bufattr_subsec Buffer Attributes 8853a5a1b3Sopenharmony_ci * 8953a5a1b3Sopenharmony_ci * Playback and record streams always have a server-side buffer as 9053a5a1b3Sopenharmony_ci * part of the data flow. The size of this buffer needs to be chosen 9153a5a1b3Sopenharmony_ci * in a compromise between low latency and sensitivity for buffer 9253a5a1b3Sopenharmony_ci * overflows/underruns. 9353a5a1b3Sopenharmony_ci * 9453a5a1b3Sopenharmony_ci * The buffer metrics may be controlled by the application. They are 9553a5a1b3Sopenharmony_ci * described with a pa_buffer_attr structure. 9653a5a1b3Sopenharmony_ci * 9753a5a1b3Sopenharmony_ci * If PA_STREAM_ADJUST_LATENCY is set, then the tlength/fragsize 9853a5a1b3Sopenharmony_ci * parameters of the pa_buffer_attr structure will be interpreted 9953a5a1b3Sopenharmony_ci * slightly differently than otherwise when passed to 10053a5a1b3Sopenharmony_ci * pa_stream_connect_record() and pa_stream_connect_playback(): the 10153a5a1b3Sopenharmony_ci * overall latency that is comprised of both the server side playback 10253a5a1b3Sopenharmony_ci * buffer length, the hardware playback buffer length and additional 10353a5a1b3Sopenharmony_ci * latencies will be adjusted in a way that it matches tlength resp. 10453a5a1b3Sopenharmony_ci * fragsize. Set PA_STREAM_ADJUST_LATENCY if you want to control the 10553a5a1b3Sopenharmony_ci * overall playback latency for your stream. Unset it if you want to 10653a5a1b3Sopenharmony_ci * control only the latency induced by the server-side, rewritable 10753a5a1b3Sopenharmony_ci * playback buffer. The server will try to fulfill the client's latency 10853a5a1b3Sopenharmony_ci * requests as good as possible. However if the underlying hardware cannot 10953a5a1b3Sopenharmony_ci * change the hardware buffer length or only in a limited range, the 11053a5a1b3Sopenharmony_ci * actually resulting latency might be different from what the client 11153a5a1b3Sopenharmony_ci * requested. Thus, for synchronization clients always need to check 11253a5a1b3Sopenharmony_ci * the actual measured latency via pa_stream_get_latency() or a 11353a5a1b3Sopenharmony_ci * similar call, and not make any assumptions about the latency 11453a5a1b3Sopenharmony_ci * available. The function pa_stream_get_buffer_attr() will always 11553a5a1b3Sopenharmony_ci * return the actual size of the server-side per-stream buffer in 11653a5a1b3Sopenharmony_ci * tlength/fragsize, regardless whether PA_STREAM_ADJUST_LATENCY is 11753a5a1b3Sopenharmony_ci * set or not. 11853a5a1b3Sopenharmony_ci * 11953a5a1b3Sopenharmony_ci * The server-side per-stream playback buffers are indexed by a write and 12053a5a1b3Sopenharmony_ci * a read index. The application writes to the write index and the sound 12153a5a1b3Sopenharmony_ci * device reads from the read index. The read index is increased 12253a5a1b3Sopenharmony_ci * monotonically, while the write index may be freely controlled by 12353a5a1b3Sopenharmony_ci * the application. Subtracting the read index from the write index 12453a5a1b3Sopenharmony_ci * will give you the current fill level of the buffer. The read/write 12553a5a1b3Sopenharmony_ci * indexes are 64bit values and measured in bytes, they will never 12653a5a1b3Sopenharmony_ci * wrap. The current read/write index may be queried using 12753a5a1b3Sopenharmony_ci * pa_stream_get_timing_info() (see below for more information). In 12853a5a1b3Sopenharmony_ci * case of a buffer underrun the read index is equal or larger than 12953a5a1b3Sopenharmony_ci * the write index. Unless the prebuf value is 0, PulseAudio will 13053a5a1b3Sopenharmony_ci * temporarily pause playback in such a case, and wait until the 13153a5a1b3Sopenharmony_ci * buffer is filled up to prebuf bytes again. If prebuf is 0, the 13253a5a1b3Sopenharmony_ci * read index may be larger than the write index, in which case 13353a5a1b3Sopenharmony_ci * silence is played. If the application writes data to indexes lower 13453a5a1b3Sopenharmony_ci * than the read index, the data is immediately lost. 13553a5a1b3Sopenharmony_ci * 13653a5a1b3Sopenharmony_ci * \section transfer_sec Transferring Data 13753a5a1b3Sopenharmony_ci * 13853a5a1b3Sopenharmony_ci * Once the stream is up, data can start flowing between the client and the 13953a5a1b3Sopenharmony_ci * server. Two different access models can be used to transfer the data: 14053a5a1b3Sopenharmony_ci * 14153a5a1b3Sopenharmony_ci * \li Asynchronous - The application registers a callback using 14253a5a1b3Sopenharmony_ci * pa_stream_set_write_callback() and 14353a5a1b3Sopenharmony_ci * pa_stream_set_read_callback() to receive notifications 14453a5a1b3Sopenharmony_ci * that data can either be written or read. 14553a5a1b3Sopenharmony_ci * \li Polled - Query the library for available data/space using 14653a5a1b3Sopenharmony_ci * pa_stream_writable_size() and pa_stream_readable_size() and 14753a5a1b3Sopenharmony_ci * transfer data as needed. The sizes are stored locally, in the 14853a5a1b3Sopenharmony_ci * client end, so there is no delay when reading them. 14953a5a1b3Sopenharmony_ci * 15053a5a1b3Sopenharmony_ci * It is also possible to mix the two models freely. 15153a5a1b3Sopenharmony_ci * 15253a5a1b3Sopenharmony_ci * Once there is data/space available, it can be transferred using either 15353a5a1b3Sopenharmony_ci * pa_stream_write() for playback, or pa_stream_peek() / pa_stream_drop() for 15453a5a1b3Sopenharmony_ci * record. Make sure you do not overflow the playback buffers as data will be 15553a5a1b3Sopenharmony_ci * dropped. 15653a5a1b3Sopenharmony_ci * 15753a5a1b3Sopenharmony_ci * \section bufctl_sec Buffer Control 15853a5a1b3Sopenharmony_ci * 15953a5a1b3Sopenharmony_ci * The transfer buffers can be controlled through a number of operations: 16053a5a1b3Sopenharmony_ci * 16153a5a1b3Sopenharmony_ci * \li pa_stream_cork() - Start or stop the playback or recording. 16253a5a1b3Sopenharmony_ci * \li pa_stream_trigger() - Start playback immediately and do not wait for 16353a5a1b3Sopenharmony_ci * the buffer to fill up to the set trigger level. 16453a5a1b3Sopenharmony_ci * \li pa_stream_prebuf() - Reenable the playback trigger level. 16553a5a1b3Sopenharmony_ci * \li pa_stream_drain() - Wait for the playback buffer to go empty. Will 16653a5a1b3Sopenharmony_ci * return a pa_operation object that will indicate when 16753a5a1b3Sopenharmony_ci * the buffer is completely drained. 16853a5a1b3Sopenharmony_ci * \li pa_stream_flush() - Drop all data from the playback or record buffer. Do not 16953a5a1b3Sopenharmony_ci * wait for it to finish playing. 17053a5a1b3Sopenharmony_ci * 17153a5a1b3Sopenharmony_ci * \section seek_modes Seeking in the Playback Buffer 17253a5a1b3Sopenharmony_ci * 17353a5a1b3Sopenharmony_ci * A client application may freely seek in the playback buffer. To 17453a5a1b3Sopenharmony_ci * accomplish that the pa_stream_write() function takes a seek mode 17553a5a1b3Sopenharmony_ci * and an offset argument. The seek mode is one of: 17653a5a1b3Sopenharmony_ci * 17753a5a1b3Sopenharmony_ci * \li PA_SEEK_RELATIVE - seek relative to the current write index. 17853a5a1b3Sopenharmony_ci * \li PA_SEEK_ABSOLUTE - seek relative to the beginning of the playback buffer, 17953a5a1b3Sopenharmony_ci * (i.e. the first that was ever played in the stream). 18053a5a1b3Sopenharmony_ci * \li PA_SEEK_RELATIVE_ON_READ - seek relative to the current read index. Use 18153a5a1b3Sopenharmony_ci * this to write data to the output buffer that should be played as soon as possible. 18253a5a1b3Sopenharmony_ci * \li PA_SEEK_RELATIVE_END - seek relative to the last byte ever written. 18353a5a1b3Sopenharmony_ci * 18453a5a1b3Sopenharmony_ci * If an application just wants to append some data to the output 18553a5a1b3Sopenharmony_ci * buffer, PA_SEEK_RELATIVE and an offset of 0 should be used. 18653a5a1b3Sopenharmony_ci * 18753a5a1b3Sopenharmony_ci * After a call to pa_stream_write() the write index will be left at 18853a5a1b3Sopenharmony_ci * the position right after the last byte of the written data. 18953a5a1b3Sopenharmony_ci * 19053a5a1b3Sopenharmony_ci * \section latency_sec Latency 19153a5a1b3Sopenharmony_ci * 19253a5a1b3Sopenharmony_ci * A major problem with networked audio is the increased latency caused by 19353a5a1b3Sopenharmony_ci * the network. To remedy this, PulseAudio supports an advanced system of 19453a5a1b3Sopenharmony_ci * monitoring the current latency. 19553a5a1b3Sopenharmony_ci * 19653a5a1b3Sopenharmony_ci * To get the raw data needed to calculate latencies, call 19753a5a1b3Sopenharmony_ci * pa_stream_get_timing_info(). This will give you a pa_timing_info 19853a5a1b3Sopenharmony_ci * structure that contains everything that is known about the server 19953a5a1b3Sopenharmony_ci * side buffer transport delays and the backend active in the 20053a5a1b3Sopenharmony_ci * server. (Besides other things it contains the write and read index 20153a5a1b3Sopenharmony_ci * values mentioned above.) 20253a5a1b3Sopenharmony_ci * 20353a5a1b3Sopenharmony_ci * This structure is updated every time a 20453a5a1b3Sopenharmony_ci * pa_stream_update_timing_info() operation is executed. (i.e. before 20553a5a1b3Sopenharmony_ci * the first call to this function the timing information structure is 20653a5a1b3Sopenharmony_ci * not available!) Since it is a lot of work to keep this structure 20753a5a1b3Sopenharmony_ci * up-to-date manually, PulseAudio can do that automatically for you: 20853a5a1b3Sopenharmony_ci * if PA_STREAM_AUTO_TIMING_UPDATE is passed when connecting the 20953a5a1b3Sopenharmony_ci * stream PulseAudio will automatically update the structure every 21053a5a1b3Sopenharmony_ci * 100ms and every time a function is called that might invalidate the 21153a5a1b3Sopenharmony_ci * previously known timing data (such as pa_stream_write() or 21253a5a1b3Sopenharmony_ci * pa_stream_flush()). Please note however, that there always is a 21353a5a1b3Sopenharmony_ci * short time window when the data in the timing information structure 21453a5a1b3Sopenharmony_ci * is out-of-date. PulseAudio tries to mark these situations by 21553a5a1b3Sopenharmony_ci * setting the write_index_corrupt and read_index_corrupt fields 21653a5a1b3Sopenharmony_ci * accordingly. 21753a5a1b3Sopenharmony_ci * 21853a5a1b3Sopenharmony_ci * The raw timing data in the pa_timing_info structure is usually hard 21953a5a1b3Sopenharmony_ci * to deal with. Therefore a simpler interface is available: 22053a5a1b3Sopenharmony_ci * you can call pa_stream_get_time() or pa_stream_get_latency(). The 22153a5a1b3Sopenharmony_ci * former will return the current playback time of the hardware since 22253a5a1b3Sopenharmony_ci * the stream has been started. The latter returns the overall time a sample 22353a5a1b3Sopenharmony_ci * that you write now takes to be played by the hardware. These two 22453a5a1b3Sopenharmony_ci * functions base their calculations on the same data that is returned 22553a5a1b3Sopenharmony_ci * by pa_stream_get_timing_info(). Hence the same rules for keeping 22653a5a1b3Sopenharmony_ci * the timing data up-to-date apply here. In case the write or read 22753a5a1b3Sopenharmony_ci * index is corrupted, these two functions will fail with 22853a5a1b3Sopenharmony_ci * -PA_ERR_NODATA set. 22953a5a1b3Sopenharmony_ci * 23053a5a1b3Sopenharmony_ci * Since updating the timing info structure usually requires a full 23153a5a1b3Sopenharmony_ci * network round trip and some applications monitor the timing very 23253a5a1b3Sopenharmony_ci * often PulseAudio offers a timing interpolation system. If 23353a5a1b3Sopenharmony_ci * PA_STREAM_INTERPOLATE_TIMING is passed when connecting the stream, 23453a5a1b3Sopenharmony_ci * pa_stream_get_time() and pa_stream_get_latency() will try to 23553a5a1b3Sopenharmony_ci * interpolate the current playback time/latency by estimating the 23653a5a1b3Sopenharmony_ci * number of samples that have been played back by the hardware since 23753a5a1b3Sopenharmony_ci * the last regular timing update. It is especially useful to combine 23853a5a1b3Sopenharmony_ci * this option with PA_STREAM_AUTO_TIMING_UPDATE, which will enable 23953a5a1b3Sopenharmony_ci * you to monitor the current playback time/latency very precisely and 24053a5a1b3Sopenharmony_ci * very frequently without requiring a network round trip every time. 24153a5a1b3Sopenharmony_ci * 24253a5a1b3Sopenharmony_ci * \section flow_sec Overflow and underflow 24353a5a1b3Sopenharmony_ci * 24453a5a1b3Sopenharmony_ci * Even with the best precautions, buffers will sometime over - or 24553a5a1b3Sopenharmony_ci * underflow. To handle this gracefully, the application can be 24653a5a1b3Sopenharmony_ci * notified when this happens. Callbacks are registered using 24753a5a1b3Sopenharmony_ci * pa_stream_set_overflow_callback() and 24853a5a1b3Sopenharmony_ci * pa_stream_set_underflow_callback(). 24953a5a1b3Sopenharmony_ci * 25053a5a1b3Sopenharmony_ci * \section sync_streams Synchronizing Multiple Playback Streams 25153a5a1b3Sopenharmony_ci * 25253a5a1b3Sopenharmony_ci * PulseAudio allows applications to fully synchronize multiple 25353a5a1b3Sopenharmony_ci * playback streams that are connected to the same output device. That 25453a5a1b3Sopenharmony_ci * means the streams will always be played back sample-by-sample 25553a5a1b3Sopenharmony_ci * synchronously. If stream operations like pa_stream_cork() are 25653a5a1b3Sopenharmony_ci * issued on one of the synchronized streams, they are simultaneously 25753a5a1b3Sopenharmony_ci * issued on the others. 25853a5a1b3Sopenharmony_ci * 25953a5a1b3Sopenharmony_ci * To synchronize a stream to another, just pass the "master" stream 26053a5a1b3Sopenharmony_ci * as last argument to pa_stream_connect_playback(). To make sure that 26153a5a1b3Sopenharmony_ci * the freshly created stream doesn't start playback right-away, make 26253a5a1b3Sopenharmony_ci * sure to pass PA_STREAM_START_CORKED and -- after all streams have 26353a5a1b3Sopenharmony_ci * been created -- uncork them all with a single call to 26453a5a1b3Sopenharmony_ci * pa_stream_cork() for the master stream. 26553a5a1b3Sopenharmony_ci * 26653a5a1b3Sopenharmony_ci * To make sure that a particular stream doesn't stop playing when a 26753a5a1b3Sopenharmony_ci * server side buffer underrun happens on it while the other 26853a5a1b3Sopenharmony_ci * synchronized streams continue playing and hence deviate, you need to 26953a5a1b3Sopenharmony_ci * pass a pa_buffer_attr with prebuf set to 0 when connecting. 27053a5a1b3Sopenharmony_ci * 27153a5a1b3Sopenharmony_ci * \section disc_sec Disconnecting 27253a5a1b3Sopenharmony_ci * 27353a5a1b3Sopenharmony_ci * When a stream has served is purpose it must be disconnected with 27453a5a1b3Sopenharmony_ci * pa_stream_disconnect(). If you only unreference it, then it will live on 27553a5a1b3Sopenharmony_ci * and eat resources both locally and on the server until you disconnect the 27653a5a1b3Sopenharmony_ci * context. 27753a5a1b3Sopenharmony_ci * 27853a5a1b3Sopenharmony_ci */ 27953a5a1b3Sopenharmony_ci 28053a5a1b3Sopenharmony_ci/** \file 28153a5a1b3Sopenharmony_ci * Audio streams for input, output and sample upload 28253a5a1b3Sopenharmony_ci * 28353a5a1b3Sopenharmony_ci * See also \subpage streams 28453a5a1b3Sopenharmony_ci */ 28553a5a1b3Sopenharmony_ci 28653a5a1b3Sopenharmony_ciPA_C_DECL_BEGIN 28753a5a1b3Sopenharmony_ci 28853a5a1b3Sopenharmony_ci/** An opaque stream for playback or recording */ 28953a5a1b3Sopenharmony_citypedef struct pa_stream pa_stream; 29053a5a1b3Sopenharmony_ci 29153a5a1b3Sopenharmony_ci/** A generic callback for operation completion */ 29253a5a1b3Sopenharmony_citypedef void (*pa_stream_success_cb_t) (pa_stream*s, int success, void *userdata); 29353a5a1b3Sopenharmony_ci 29453a5a1b3Sopenharmony_ci/** A generic request callback */ 29553a5a1b3Sopenharmony_citypedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t nbytes, void *userdata); 29653a5a1b3Sopenharmony_ci 29753a5a1b3Sopenharmony_ci/** A generic notification callback */ 29853a5a1b3Sopenharmony_citypedef void (*pa_stream_notify_cb_t)(pa_stream *p, void *userdata); 29953a5a1b3Sopenharmony_ci 30053a5a1b3Sopenharmony_ci/** A callback for asynchronous meta/policy event messages. Well known 30153a5a1b3Sopenharmony_ci * event names are PA_STREAM_EVENT_REQUEST_CORK and 30253a5a1b3Sopenharmony_ci * PA_STREAM_EVENT_REQUEST_UNCORK. The set of defined events can be 30353a5a1b3Sopenharmony_ci * extended at any time. Also, server modules may introduce additional 30453a5a1b3Sopenharmony_ci * message types so make sure that your callback function ignores messages 30553a5a1b3Sopenharmony_ci * it doesn't know. \since 0.9.15 */ 30653a5a1b3Sopenharmony_citypedef void (*pa_stream_event_cb_t)(pa_stream *p, const char *name, pa_proplist *pl, void *userdata); 30753a5a1b3Sopenharmony_ci 30853a5a1b3Sopenharmony_ci/** Create a new, unconnected stream with the specified name and 30953a5a1b3Sopenharmony_ci * sample type. It is recommended to use pa_stream_new_with_proplist() 31053a5a1b3Sopenharmony_ci * instead and specify some initial properties. */ 31153a5a1b3Sopenharmony_cipa_stream* pa_stream_new( 31253a5a1b3Sopenharmony_ci pa_context *c /**< The context to create this stream in */, 31353a5a1b3Sopenharmony_ci const char *name /**< A name for this stream */, 31453a5a1b3Sopenharmony_ci const pa_sample_spec *ss /**< The desired sample format */, 31553a5a1b3Sopenharmony_ci const pa_channel_map *map /**< The desired channel map, or NULL for default */); 31653a5a1b3Sopenharmony_ci 31753a5a1b3Sopenharmony_ci/** Create a new, unconnected stream with the specified name and 31853a5a1b3Sopenharmony_ci * sample type, and specify the initial stream property 31953a5a1b3Sopenharmony_ci * list. \since 0.9.11 */ 32053a5a1b3Sopenharmony_cipa_stream* pa_stream_new_with_proplist( 32153a5a1b3Sopenharmony_ci pa_context *c /**< The context to create this stream in */, 32253a5a1b3Sopenharmony_ci const char *name /**< A name for this stream */, 32353a5a1b3Sopenharmony_ci const pa_sample_spec *ss /**< The desired sample format */, 32453a5a1b3Sopenharmony_ci const pa_channel_map *map /**< The desired channel map, or NULL for default */, 32553a5a1b3Sopenharmony_ci pa_proplist *p /**< The initial property list */); 32653a5a1b3Sopenharmony_ci 32753a5a1b3Sopenharmony_ci/** Create a new, unconnected stream with the specified name, the set of formats 32853a5a1b3Sopenharmony_ci * this client can provide, and an initial list of properties. While 32953a5a1b3Sopenharmony_ci * connecting, the server will select the most appropriate format which the 33053a5a1b3Sopenharmony_ci * client must then provide. \since 1.0 */ 33153a5a1b3Sopenharmony_cipa_stream *pa_stream_new_extended( 33253a5a1b3Sopenharmony_ci pa_context *c /**< The context to create this stream in */, 33353a5a1b3Sopenharmony_ci const char *name /**< A name for this stream */, 33453a5a1b3Sopenharmony_ci pa_format_info * const * formats /**< The list of formats that can be provided */, 33553a5a1b3Sopenharmony_ci unsigned int n_formats /**< The number of formats being passed in */, 33653a5a1b3Sopenharmony_ci pa_proplist *p /**< The initial property list */); 33753a5a1b3Sopenharmony_ci 33853a5a1b3Sopenharmony_ci/** Decrease the reference counter by one. */ 33953a5a1b3Sopenharmony_civoid pa_stream_unref(pa_stream *s); 34053a5a1b3Sopenharmony_ci 34153a5a1b3Sopenharmony_ci/** Increase the reference counter by one. */ 34253a5a1b3Sopenharmony_cipa_stream *pa_stream_ref(pa_stream *s); 34353a5a1b3Sopenharmony_ci 34453a5a1b3Sopenharmony_ci/** Return the current state of the stream. */ 34553a5a1b3Sopenharmony_cipa_stream_state_t pa_stream_get_state(const pa_stream *p); 34653a5a1b3Sopenharmony_ci 34753a5a1b3Sopenharmony_civoid pa_stream_terminate(pa_stream *s); 34853a5a1b3Sopenharmony_ci 34953a5a1b3Sopenharmony_ci/** Return the context this stream is attached to. */ 35053a5a1b3Sopenharmony_cipa_context* pa_stream_get_context(const pa_stream *p); 35153a5a1b3Sopenharmony_ci 35253a5a1b3Sopenharmony_ci/** Return the sink input resp.\ source output index this stream is 35353a5a1b3Sopenharmony_ci * identified in the server with. This is useful with the 35453a5a1b3Sopenharmony_ci * introspection functions such as pa_context_get_sink_input_info() 35553a5a1b3Sopenharmony_ci * or pa_context_get_source_output_info(). This returns PA_INVALID_INDEX 35653a5a1b3Sopenharmony_ci * on failure. */ 35753a5a1b3Sopenharmony_ciuint32_t pa_stream_get_index(const pa_stream *s); 35853a5a1b3Sopenharmony_ci 35953a5a1b3Sopenharmony_ci/** Return the index of the sink or source this stream is connected to 36053a5a1b3Sopenharmony_ci * in the server. This is useful with the introspection 36153a5a1b3Sopenharmony_ci * functions such as pa_context_get_sink_info_by_index() or 36253a5a1b3Sopenharmony_ci * pa_context_get_source_info_by_index(). 36353a5a1b3Sopenharmony_ci * 36453a5a1b3Sopenharmony_ci * Please note that streams may be moved between sinks/sources and thus 36553a5a1b3Sopenharmony_ci * it is recommended to use pa_stream_set_moved_callback() to be notified 36653a5a1b3Sopenharmony_ci * about this. This function will return with PA_INVALID_INDEX on failure, 36753a5a1b3Sopenharmony_ci * including the being server older than 0.9.8. \since 0.9.8 */ 36853a5a1b3Sopenharmony_ciuint32_t pa_stream_get_device_index(const pa_stream *s); 36953a5a1b3Sopenharmony_ci 37053a5a1b3Sopenharmony_ci/** Return the name of the sink or source this stream is connected to 37153a5a1b3Sopenharmony_ci * in the server. This is useful with the introspection 37253a5a1b3Sopenharmony_ci * functions such as pa_context_get_sink_info_by_name() 37353a5a1b3Sopenharmony_ci * or pa_context_get_source_info_by_name(). 37453a5a1b3Sopenharmony_ci * 37553a5a1b3Sopenharmony_ci * Please note that streams may be moved between sinks/sources and thus 37653a5a1b3Sopenharmony_ci * it is recommended to use pa_stream_set_moved_callback() to be notified 37753a5a1b3Sopenharmony_ci * about this. This function will fail when the server is older than 37853a5a1b3Sopenharmony_ci * 0.9.8. \since 0.9.8 */ 37953a5a1b3Sopenharmony_ciconst char *pa_stream_get_device_name(const pa_stream *s); 38053a5a1b3Sopenharmony_ci 38153a5a1b3Sopenharmony_ci/** Return 1 if the sink or source this stream is connected to has 38253a5a1b3Sopenharmony_ci * been suspended. This will return 0 if not, and a negative value on 38353a5a1b3Sopenharmony_ci * error. This function will return with -PA_ERR_NOTSUPPORTED when the 38453a5a1b3Sopenharmony_ci * server is older than 0.9.8. \since 0.9.8 */ 38553a5a1b3Sopenharmony_ciint pa_stream_is_suspended(const pa_stream *s); 38653a5a1b3Sopenharmony_ci 38753a5a1b3Sopenharmony_ci/** Return 1 if the this stream has been corked. This will return 0 if 38853a5a1b3Sopenharmony_ci * not, and a negative value on error. \since 0.9.11 */ 38953a5a1b3Sopenharmony_ciint pa_stream_is_corked(const pa_stream *s); 39053a5a1b3Sopenharmony_ci 39153a5a1b3Sopenharmony_ci/** Connect the stream to a sink. It is strongly recommended to pass 39253a5a1b3Sopenharmony_ci * NULL in both \a dev and \a volume and to set neither 39353a5a1b3Sopenharmony_ci * PA_STREAM_START_MUTED nor PA_STREAM_START_UNMUTED -- unless these 39453a5a1b3Sopenharmony_ci * options are directly dependent on user input or configuration. 39553a5a1b3Sopenharmony_ci * 39653a5a1b3Sopenharmony_ci * If you follow this rule then the sound server will have the full 39753a5a1b3Sopenharmony_ci * flexibility to choose the device, volume and mute status 39853a5a1b3Sopenharmony_ci * automatically, based on server-side policies, heuristics and stored 39953a5a1b3Sopenharmony_ci * information from previous uses. Also the server may choose to 40053a5a1b3Sopenharmony_ci * reconfigure audio devices to make other sinks/sources or 40153a5a1b3Sopenharmony_ci * capabilities available to be able to accept the stream. 40253a5a1b3Sopenharmony_ci * 40353a5a1b3Sopenharmony_ci * Before 0.9.20 it was not defined whether the \a volume parameter was 40453a5a1b3Sopenharmony_ci * interpreted relative to the sink's current volume or treated as 40553a5a1b3Sopenharmony_ci * an absolute device volume. Since 0.9.20 it is an absolute volume when 40653a5a1b3Sopenharmony_ci * the sink is in flat volume mode, and relative otherwise, thus 40753a5a1b3Sopenharmony_ci * making sure the volume passed here has always the same semantics as 40853a5a1b3Sopenharmony_ci * the volume passed to pa_context_set_sink_input_volume(). It is possible 40953a5a1b3Sopenharmony_ci * to figure out whether flat volume mode is in effect for a given sink 41053a5a1b3Sopenharmony_ci * by calling pa_context_get_sink_info_by_name(). 41153a5a1b3Sopenharmony_ci * 41253a5a1b3Sopenharmony_ci * Since 5.0, it's possible to specify a single-channel volume even if the 41353a5a1b3Sopenharmony_ci * stream has multiple channels. In that case the same volume is applied to all 41453a5a1b3Sopenharmony_ci * channels. 41553a5a1b3Sopenharmony_ci * 41653a5a1b3Sopenharmony_ci * Returns zero on success. */ 41753a5a1b3Sopenharmony_ciint pa_stream_connect_playback( 41853a5a1b3Sopenharmony_ci pa_stream *s /**< The stream to connect to a sink */, 41953a5a1b3Sopenharmony_ci const char *dev /**< Name of the sink to connect to, or NULL to let the server decide */ , 42053a5a1b3Sopenharmony_ci const pa_buffer_attr *attr /**< Buffering attributes, or NULL for default */, 42153a5a1b3Sopenharmony_ci pa_stream_flags_t flags /**< Additional flags, or 0 for default */, 42253a5a1b3Sopenharmony_ci const pa_cvolume *volume /**< Initial volume, or NULL for default */, 42353a5a1b3Sopenharmony_ci pa_stream *sync_stream /**< Synchronize this stream with the specified one, or NULL for a standalone stream */); 42453a5a1b3Sopenharmony_ci 42553a5a1b3Sopenharmony_ci/** Connect the stream to a source. Returns zero on success. */ 42653a5a1b3Sopenharmony_ciint pa_stream_connect_record( 42753a5a1b3Sopenharmony_ci pa_stream *s /**< The stream to connect to a source */ , 42853a5a1b3Sopenharmony_ci const char *dev /**< Name of the source to connect to, or NULL to let the server decide */, 42953a5a1b3Sopenharmony_ci const pa_buffer_attr *attr /**< Buffer attributes, or NULL for default */, 43053a5a1b3Sopenharmony_ci pa_stream_flags_t flags /**< Additional flags, or 0 for default */); 43153a5a1b3Sopenharmony_ci 43253a5a1b3Sopenharmony_ci/** Disconnect a stream from a source/sink. Returns zero on success. */ 43353a5a1b3Sopenharmony_ciint pa_stream_disconnect(pa_stream *s); 43453a5a1b3Sopenharmony_ci 43553a5a1b3Sopenharmony_ci/** Prepare writing data to the server (for playback streams). This 43653a5a1b3Sopenharmony_ci * function may be used to optimize the number of memory copies when 43753a5a1b3Sopenharmony_ci * doing playback ("zero-copy"). It is recommended to call this 43853a5a1b3Sopenharmony_ci * function before each call to pa_stream_write(). 43953a5a1b3Sopenharmony_ci * 44053a5a1b3Sopenharmony_ci * Pass in the address to a pointer and an address of the number of 44153a5a1b3Sopenharmony_ci * bytes you want to write. On return the two values will contain a 44253a5a1b3Sopenharmony_ci * pointer where you can place the data to write and the maximum number 44353a5a1b3Sopenharmony_ci * of bytes you can write. \a *nbytes can be smaller or have the same 44453a5a1b3Sopenharmony_ci * value as you passed in. You need to be able to handle both cases. 44553a5a1b3Sopenharmony_ci * Accessing memory beyond the returned \a *nbytes value is invalid. 44653a5a1b3Sopenharmony_ci * Accessing the memory returned after the following pa_stream_write() 44753a5a1b3Sopenharmony_ci * or pa_stream_cancel_write() is invalid. 44853a5a1b3Sopenharmony_ci * 44953a5a1b3Sopenharmony_ci * On invocation only \a *nbytes needs to be initialized, on return both 45053a5a1b3Sopenharmony_ci * *data and *nbytes will be valid. If you place (size_t) -1 in *nbytes 45153a5a1b3Sopenharmony_ci * on invocation the memory size will be chosen automatically (which is 45253a5a1b3Sopenharmony_ci * recommended to do). After placing your data in the memory area 45353a5a1b3Sopenharmony_ci * returned, call pa_stream_write() with \a data set to an address 45453a5a1b3Sopenharmony_ci * within this memory area and an \a nbytes value that is smaller or 45553a5a1b3Sopenharmony_ci * equal to what was returned by this function to actually execute the 45653a5a1b3Sopenharmony_ci * write. 45753a5a1b3Sopenharmony_ci * 45853a5a1b3Sopenharmony_ci * An invocation of pa_stream_write() should follow "quickly" on 45953a5a1b3Sopenharmony_ci * pa_stream_begin_write(). It is not recommended letting an unbounded 46053a5a1b3Sopenharmony_ci * amount of time pass after calling pa_stream_begin_write() and 46153a5a1b3Sopenharmony_ci * before calling pa_stream_write(). If you want to cancel a 46253a5a1b3Sopenharmony_ci * previously called pa_stream_begin_write() without calling 46353a5a1b3Sopenharmony_ci * pa_stream_write() use pa_stream_cancel_write(). Calling 46453a5a1b3Sopenharmony_ci * pa_stream_begin_write() twice without calling pa_stream_write() or 46553a5a1b3Sopenharmony_ci * pa_stream_cancel_write() in between will return exactly the same 46653a5a1b3Sopenharmony_ci * \a data pointer and \a nbytes values. 46753a5a1b3Sopenharmony_ci * 46853a5a1b3Sopenharmony_ci * On success, will return zero and a valid (non-NULL) pointer. If the 46953a5a1b3Sopenharmony_ci * return value is non-zero, or the pointer is NULL, this indicates an 47053a5a1b3Sopenharmony_ci * error. Callers should also pay careful attention to the returned 47153a5a1b3Sopenharmony_ci * length, which may not be the same as that passed in, as mentioned above. 47253a5a1b3Sopenharmony_ci * 47353a5a1b3Sopenharmony_ci * \since 0.9.16 */ 47453a5a1b3Sopenharmony_ciint pa_stream_begin_write( 47553a5a1b3Sopenharmony_ci pa_stream *p, 47653a5a1b3Sopenharmony_ci void **data, 47753a5a1b3Sopenharmony_ci size_t *nbytes); 47853a5a1b3Sopenharmony_ci 47953a5a1b3Sopenharmony_ci/** Reverses the effect of pa_stream_begin_write() dropping all data 48053a5a1b3Sopenharmony_ci * that has already been placed in the memory area returned by 48153a5a1b3Sopenharmony_ci * pa_stream_begin_write(). Only valid to call if 48253a5a1b3Sopenharmony_ci * pa_stream_begin_write() was called before and neither 48353a5a1b3Sopenharmony_ci * pa_stream_cancel_write() nor pa_stream_write() have been called 48453a5a1b3Sopenharmony_ci * yet. Accessing the memory previously returned by 48553a5a1b3Sopenharmony_ci * pa_stream_begin_write() after this call is invalid. Any further 48653a5a1b3Sopenharmony_ci * explicit freeing of the memory area is not necessary. 48753a5a1b3Sopenharmony_ci * Returns zero on success. \since 0.9.16 */ 48853a5a1b3Sopenharmony_ciint pa_stream_cancel_write( 48953a5a1b3Sopenharmony_ci pa_stream *p); 49053a5a1b3Sopenharmony_ci 49153a5a1b3Sopenharmony_ci/** Write some data to the server (for playback streams). 49253a5a1b3Sopenharmony_ci * If \a free_cb is non-NULL this routine is called when all data has 49353a5a1b3Sopenharmony_ci * been written out. An internal reference to the specified data is 49453a5a1b3Sopenharmony_ci * kept, the data is not copied. If NULL, the data is copied into an 49553a5a1b3Sopenharmony_ci * internal buffer. 49653a5a1b3Sopenharmony_ci * 49753a5a1b3Sopenharmony_ci * The client may freely seek around in the output buffer. For 49853a5a1b3Sopenharmony_ci * most applications it is typical to pass 0 and PA_SEEK_RELATIVE 49953a5a1b3Sopenharmony_ci * as values for the arguments \a offset and \a seek respectively. 50053a5a1b3Sopenharmony_ci * After a successful write call the write index will be at the 50153a5a1b3Sopenharmony_ci * position after where this chunk of data has been written to. 50253a5a1b3Sopenharmony_ci * 50353a5a1b3Sopenharmony_ci * As an optimization for avoiding needless memory copies you may call 50453a5a1b3Sopenharmony_ci * pa_stream_begin_write() before this call and then place your audio 50553a5a1b3Sopenharmony_ci * data directly in the memory area returned by that call. Then, pass 50653a5a1b3Sopenharmony_ci * a pointer to that memory area to pa_stream_write(). After the 50753a5a1b3Sopenharmony_ci * invocation of pa_stream_write() the memory area may no longer be 50853a5a1b3Sopenharmony_ci * accessed. Any further explicit freeing of the memory area is not 50953a5a1b3Sopenharmony_ci * necessary. It is OK to write to the memory area returned by 51053a5a1b3Sopenharmony_ci * pa_stream_begin_write() only partially with this call, skipping 51153a5a1b3Sopenharmony_ci * bytes both at the end and at the beginning of the reserved memory 51253a5a1b3Sopenharmony_ci * area. 51353a5a1b3Sopenharmony_ci * 51453a5a1b3Sopenharmony_ci * Returns zero on success. */ 51553a5a1b3Sopenharmony_ciint pa_stream_write( 51653a5a1b3Sopenharmony_ci pa_stream *p /**< The stream to use */, 51753a5a1b3Sopenharmony_ci const void *data /**< The data to write */, 51853a5a1b3Sopenharmony_ci size_t nbytes /**< The length of the data to write in bytes, must be in multiples of the stream's sample spec frame size */, 51953a5a1b3Sopenharmony_ci pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */, 52053a5a1b3Sopenharmony_ci int64_t offset /**< Offset for seeking, must be 0 for upload streams, must be in multiples of the stream's sample spec frame size */, 52153a5a1b3Sopenharmony_ci pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */); 52253a5a1b3Sopenharmony_ci 52353a5a1b3Sopenharmony_ci/** Function does exactly the same as pa_stream_write() with the difference 52453a5a1b3Sopenharmony_ci * that free_cb_data is passed to free_cb instead of data. \since 6.0 */ 52553a5a1b3Sopenharmony_ciint pa_stream_write_ext_free( 52653a5a1b3Sopenharmony_ci pa_stream *p /**< The stream to use */, 52753a5a1b3Sopenharmony_ci const void *data /**< The data to write */, 52853a5a1b3Sopenharmony_ci size_t nbytes /**< The length of the data to write in bytes */, 52953a5a1b3Sopenharmony_ci pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */, 53053a5a1b3Sopenharmony_ci void *free_cb_data /**< Argument passed to free_cb function */, 53153a5a1b3Sopenharmony_ci int64_t offset /**< Offset for seeking, must be 0 for upload streams */, 53253a5a1b3Sopenharmony_ci pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */); 53353a5a1b3Sopenharmony_ci 53453a5a1b3Sopenharmony_ci/** Read the next fragment from the buffer (for recording streams). 53553a5a1b3Sopenharmony_ci * If there is data at the current read index, \a data will point to 53653a5a1b3Sopenharmony_ci * the actual data and \a nbytes will contain the size of the data in 53753a5a1b3Sopenharmony_ci * bytes (which can be less or more than a complete fragment). 53853a5a1b3Sopenharmony_ci * 53953a5a1b3Sopenharmony_ci * If there is no data at the current read index, it means that either 54053a5a1b3Sopenharmony_ci * the buffer is empty or it contains a hole (that is, the write index 54153a5a1b3Sopenharmony_ci * is ahead of the read index but there's no data where the read index 54253a5a1b3Sopenharmony_ci * points at). If the buffer is empty, \a data will be NULL and 54353a5a1b3Sopenharmony_ci * \a nbytes will be 0. If there is a hole, \a data will be NULL and 54453a5a1b3Sopenharmony_ci * \a nbytes will contain the length of the hole. 54553a5a1b3Sopenharmony_ci * 54653a5a1b3Sopenharmony_ci * Use pa_stream_drop() to actually remove the data from the buffer 54753a5a1b3Sopenharmony_ci * and move the read index forward. pa_stream_drop() should not be 54853a5a1b3Sopenharmony_ci * called if the buffer is empty, but it should be called if there is 54953a5a1b3Sopenharmony_ci * a hole. 55053a5a1b3Sopenharmony_ci * 55153a5a1b3Sopenharmony_ci * Returns zero on success, negative on error. */ 55253a5a1b3Sopenharmony_ciint pa_stream_peek( 55353a5a1b3Sopenharmony_ci pa_stream *p /**< The stream to use */, 55453a5a1b3Sopenharmony_ci const void **data /**< Pointer to pointer that will point to data */, 55553a5a1b3Sopenharmony_ci size_t *nbytes /**< The length of the data read in bytes */); 55653a5a1b3Sopenharmony_ci 55753a5a1b3Sopenharmony_ci/** Remove the current fragment on record streams. It is invalid to do this without first 55853a5a1b3Sopenharmony_ci * calling pa_stream_peek(). Returns zero on success. */ 55953a5a1b3Sopenharmony_ciint pa_stream_drop(pa_stream *p); 56053a5a1b3Sopenharmony_ci 56153a5a1b3Sopenharmony_ci/** Return the number of bytes requested by the server that have not yet 56253a5a1b3Sopenharmony_ci * been written. 56353a5a1b3Sopenharmony_ci * 56453a5a1b3Sopenharmony_ci * It is possible to write more than this amount, up to the stream's 56553a5a1b3Sopenharmony_ci * buffer_attr.maxlength bytes. This is usually not desirable, though, as 56653a5a1b3Sopenharmony_ci * it would increase stream latency to be higher than requested 56753a5a1b3Sopenharmony_ci * (buffer_attr.tlength). 56853a5a1b3Sopenharmony_ci * 56953a5a1b3Sopenharmony_ci * (size_t) -1 is returned on error. 57053a5a1b3Sopenharmony_ci */ 57153a5a1b3Sopenharmony_cisize_t pa_stream_writable_size(const pa_stream *p); 57253a5a1b3Sopenharmony_ci 57353a5a1b3Sopenharmony_ci/** Return the number of bytes that may be read using pa_stream_peek(). 57453a5a1b3Sopenharmony_ci * 57553a5a1b3Sopenharmony_ci * (size_t) -1 is returned on error. */ 57653a5a1b3Sopenharmony_cisize_t pa_stream_readable_size(const pa_stream *p); 57753a5a1b3Sopenharmony_ci 57853a5a1b3Sopenharmony_ci/** Drain a playback stream. Use this for notification when the 57953a5a1b3Sopenharmony_ci * playback buffer is empty after playing all the audio in the buffer. 58053a5a1b3Sopenharmony_ci * Please note that only one drain operation per stream may be issued 58153a5a1b3Sopenharmony_ci * at a time. */ 58253a5a1b3Sopenharmony_cipa_operation* pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *userdata); 58353a5a1b3Sopenharmony_ci 58453a5a1b3Sopenharmony_ci/** Request a timing info structure update for a stream. Use 58553a5a1b3Sopenharmony_ci * pa_stream_get_timing_info() to get access to the raw timing data, 58653a5a1b3Sopenharmony_ci * or pa_stream_get_time() or pa_stream_get_latency() to get cleaned 58753a5a1b3Sopenharmony_ci * up values. */ 58853a5a1b3Sopenharmony_cipa_operation* pa_stream_update_timing_info(pa_stream *p, pa_stream_success_cb_t cb, void *userdata); 58953a5a1b3Sopenharmony_ci 59053a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever the state of the stream changes. */ 59153a5a1b3Sopenharmony_civoid pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata); 59253a5a1b3Sopenharmony_ci 59353a5a1b3Sopenharmony_ci/** Set the callback function that is called when new data may be 59453a5a1b3Sopenharmony_ci * written to the stream. */ 59553a5a1b3Sopenharmony_civoid pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata); 59653a5a1b3Sopenharmony_ci 59753a5a1b3Sopenharmony_ci/** Set the callback function that is called when new data is available from the stream. */ 59853a5a1b3Sopenharmony_civoid pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata); 59953a5a1b3Sopenharmony_ci 60053a5a1b3Sopenharmony_ci/** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) */ 60153a5a1b3Sopenharmony_civoid pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 60253a5a1b3Sopenharmony_ci 60353a5a1b3Sopenharmony_ci/** Return at what position the latest underflow occurred, or -1 if this information is not 60453a5a1b3Sopenharmony_ci * known (e.g.\ if no underflow has occurred, or server is older than 1.0). 60553a5a1b3Sopenharmony_ci * Can be used inside the underflow callback to get information about the current underflow. 60653a5a1b3Sopenharmony_ci * (Only for playback streams) \since 1.0 */ 60753a5a1b3Sopenharmony_ciint64_t pa_stream_get_underflow_index(const pa_stream *p); 60853a5a1b3Sopenharmony_ci 60953a5a1b3Sopenharmony_ci/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) */ 61053a5a1b3Sopenharmony_civoid pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 61153a5a1b3Sopenharmony_ci 61253a5a1b3Sopenharmony_civoid pa_stream_set_underflow_ohos_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata); 61353a5a1b3Sopenharmony_ci 61453a5a1b3Sopenharmony_ci/** Set the callback function that is called when the server starts 61553a5a1b3Sopenharmony_ci * playback after an underrun or on initial startup. This only informs 61653a5a1b3Sopenharmony_ci * that audio is flowing again, it is no indication that audio started 61753a5a1b3Sopenharmony_ci * to reach the speakers already. (Only for playback streams) \since 61853a5a1b3Sopenharmony_ci * 0.9.11 */ 61953a5a1b3Sopenharmony_civoid pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 62053a5a1b3Sopenharmony_ci 62153a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever a latency 62253a5a1b3Sopenharmony_ci * information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE 62353a5a1b3Sopenharmony_ci * streams only. */ 62453a5a1b3Sopenharmony_civoid pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 62553a5a1b3Sopenharmony_ci 62653a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever the stream is 62753a5a1b3Sopenharmony_ci * moved to a different sink/source. Use pa_stream_get_device_name() or 62853a5a1b3Sopenharmony_ci * pa_stream_get_device_index() to query the new sink/source. This 62953a5a1b3Sopenharmony_ci * notification is only generated when the server is at least 63053a5a1b3Sopenharmony_ci * 0.9.8. \since 0.9.8 */ 63153a5a1b3Sopenharmony_civoid pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 63253a5a1b3Sopenharmony_ci 63353a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever the sink/source 63453a5a1b3Sopenharmony_ci * this stream is connected to is suspended or resumed. Use 63553a5a1b3Sopenharmony_ci * pa_stream_is_suspended() to query the new suspend status. Please 63653a5a1b3Sopenharmony_ci * note that the suspend status might also change when the stream is 63753a5a1b3Sopenharmony_ci * moved between devices. Thus if you call this function you very 63853a5a1b3Sopenharmony_ci * likely want to call pa_stream_set_moved_callback() too. This 63953a5a1b3Sopenharmony_ci * notification is only generated when the server is at least 64053a5a1b3Sopenharmony_ci * 0.9.8. \since 0.9.8 */ 64153a5a1b3Sopenharmony_civoid pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 64253a5a1b3Sopenharmony_ci 64353a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever a meta/policy 64453a5a1b3Sopenharmony_ci * control event is received. \since 0.9.15 */ 64553a5a1b3Sopenharmony_civoid pa_stream_set_event_callback(pa_stream *p, pa_stream_event_cb_t cb, void *userdata); 64653a5a1b3Sopenharmony_ci 64753a5a1b3Sopenharmony_ci/** Set the callback function that is called whenever the buffer 64853a5a1b3Sopenharmony_ci * attributes on the server side change. Please note that the buffer 64953a5a1b3Sopenharmony_ci * attributes can change when moving a stream to a different 65053a5a1b3Sopenharmony_ci * sink/source too, hence if you use this callback you should use 65153a5a1b3Sopenharmony_ci * pa_stream_set_moved_callback() as well. \since 0.9.15 */ 65253a5a1b3Sopenharmony_civoid pa_stream_set_buffer_attr_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata); 65353a5a1b3Sopenharmony_ci 65453a5a1b3Sopenharmony_ci/** Pause (or resume) playback of this stream temporarily. Available 65553a5a1b3Sopenharmony_ci * on both playback and recording streams. If \a b is 1 the stream is 65653a5a1b3Sopenharmony_ci * paused. If \a b is 0 the stream is resumed. The pause/resume operation 65753a5a1b3Sopenharmony_ci * is executed as quickly as possible. If a cork is very quickly 65853a5a1b3Sopenharmony_ci * followed by an uncork or the other way round, this might not 65953a5a1b3Sopenharmony_ci * actually have any effect on the stream that is output. You can use 66053a5a1b3Sopenharmony_ci * pa_stream_is_corked() to find out whether the stream is currently 66153a5a1b3Sopenharmony_ci * paused or not. Normally a stream will be created in uncorked 66253a5a1b3Sopenharmony_ci * state. If you pass PA_STREAM_START_CORKED as a flag when connecting 66353a5a1b3Sopenharmony_ci * the stream, it will be created in corked state. */ 66453a5a1b3Sopenharmony_cipa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata); 66553a5a1b3Sopenharmony_ci 66653a5a1b3Sopenharmony_ci/** Flush the playback or record buffer of this stream. This discards any audio data 66753a5a1b3Sopenharmony_ci * in the buffer. Most of the time you're better off using the parameter 66853a5a1b3Sopenharmony_ci * \a seek of pa_stream_write() instead of this function. */ 66953a5a1b3Sopenharmony_cipa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata); 67053a5a1b3Sopenharmony_ci 67153a5a1b3Sopenharmony_ci/** Reenable prebuffering if specified in the pa_buffer_attr 67253a5a1b3Sopenharmony_ci * structure. Available for playback streams only. */ 67353a5a1b3Sopenharmony_cipa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata); 67453a5a1b3Sopenharmony_ci 67553a5a1b3Sopenharmony_ci/** Request immediate start of playback on this stream. This disables 67653a5a1b3Sopenharmony_ci * prebuffering temporarily if specified in the pa_buffer_attr structure. 67753a5a1b3Sopenharmony_ci * Available for playback streams only. */ 67853a5a1b3Sopenharmony_cipa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata); 67953a5a1b3Sopenharmony_ci 68053a5a1b3Sopenharmony_ci/** Rename the stream. */ 68153a5a1b3Sopenharmony_cipa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata); 68253a5a1b3Sopenharmony_ci 68353a5a1b3Sopenharmony_ci/** Return the current playback/recording time. This is based on the 68453a5a1b3Sopenharmony_ci * data in the timing info structure returned by 68553a5a1b3Sopenharmony_ci * pa_stream_get_timing_info(). The returned time is in the sound card 68653a5a1b3Sopenharmony_ci * clock domain, which usually runs at a slightly different rate than 68753a5a1b3Sopenharmony_ci * the system clock. 68853a5a1b3Sopenharmony_ci * 68953a5a1b3Sopenharmony_ci * This function will usually only return new data if a timing info 69053a5a1b3Sopenharmony_ci * update has been received. Only if timing interpolation has been 69153a5a1b3Sopenharmony_ci * requested (PA_STREAM_INTERPOLATE_TIMING) the data from the last 69253a5a1b3Sopenharmony_ci * timing update is used for an estimation of the current 69353a5a1b3Sopenharmony_ci * playback/recording time based on the local time that passed since 69453a5a1b3Sopenharmony_ci * the timing info structure has been acquired. 69553a5a1b3Sopenharmony_ci * 69653a5a1b3Sopenharmony_ci * The time value returned by this function is guaranteed to increase 69753a5a1b3Sopenharmony_ci * monotonically (the returned value is always greater 69853a5a1b3Sopenharmony_ci * or equal to the value returned by the last call). This behaviour 69953a5a1b3Sopenharmony_ci * can be disabled by using PA_STREAM_NOT_MONOTONIC. This may be 70053a5a1b3Sopenharmony_ci * desirable to better deal with bad estimations of transport 70153a5a1b3Sopenharmony_ci * latencies, but may have strange effects if the application is not 70253a5a1b3Sopenharmony_ci * able to deal with time going 'backwards'. 70353a5a1b3Sopenharmony_ci * 70453a5a1b3Sopenharmony_ci * The time interpolator activated by PA_STREAM_INTERPOLATE_TIMING 70553a5a1b3Sopenharmony_ci * favours 'smooth' time graphs over accurate ones to improve the 70653a5a1b3Sopenharmony_ci * smoothness of UI operations that are tied to the audio clock. If 70753a5a1b3Sopenharmony_ci * accuracy is more important to you, you might need to estimate your 70853a5a1b3Sopenharmony_ci * timing based on the data from pa_stream_get_timing_info() yourself 70953a5a1b3Sopenharmony_ci * or not work with interpolated timing at all and instead always 71053a5a1b3Sopenharmony_ci * query the server side for the most up to date timing with 71153a5a1b3Sopenharmony_ci * pa_stream_update_timing_info(). 71253a5a1b3Sopenharmony_ci * 71353a5a1b3Sopenharmony_ci * If no timing information has been 71453a5a1b3Sopenharmony_ci * received yet this call will return -PA_ERR_NODATA. For more details 71553a5a1b3Sopenharmony_ci * see pa_stream_get_timing_info(). 71653a5a1b3Sopenharmony_ci * 71753a5a1b3Sopenharmony_ci * Returns zero on success, negative on error. */ 71853a5a1b3Sopenharmony_ciint pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec); 71953a5a1b3Sopenharmony_ci 72053a5a1b3Sopenharmony_ci/** Determine the total stream latency. This function is based on 72153a5a1b3Sopenharmony_ci * pa_stream_get_time(). The returned time is in the sound card clock 72253a5a1b3Sopenharmony_ci * domain, which usually runs at a slightly different rate than the 72353a5a1b3Sopenharmony_ci * system clock. 72453a5a1b3Sopenharmony_ci * 72553a5a1b3Sopenharmony_ci * The latency is stored in \a *r_usec. In case the stream is a 72653a5a1b3Sopenharmony_ci * monitoring stream the result can be negative, i.e. the captured 72753a5a1b3Sopenharmony_ci * samples are not yet played. In this case \a *negative is set to 1. 72853a5a1b3Sopenharmony_ci * 72953a5a1b3Sopenharmony_ci * If no timing information has been received yet, this call will 73053a5a1b3Sopenharmony_ci * return -PA_ERR_NODATA. On success, it will return 0. 73153a5a1b3Sopenharmony_ci * 73253a5a1b3Sopenharmony_ci * For more details see pa_stream_get_timing_info() and 73353a5a1b3Sopenharmony_ci * pa_stream_get_time(). */ 73453a5a1b3Sopenharmony_ciint pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative); 73553a5a1b3Sopenharmony_ci 73653a5a1b3Sopenharmony_ci/** Return the latest raw timing data structure. The returned pointer 73753a5a1b3Sopenharmony_ci * refers to an internal read-only instance of the timing 73853a5a1b3Sopenharmony_ci * structure. The user should make a copy of this structure if 73953a5a1b3Sopenharmony_ci * wanting to modify it. An in-place update to this data structure 74053a5a1b3Sopenharmony_ci * may be requested using pa_stream_update_timing_info(). 74153a5a1b3Sopenharmony_ci * 74253a5a1b3Sopenharmony_ci * If no timing information has been received before (i.e. by 74353a5a1b3Sopenharmony_ci * requesting pa_stream_update_timing_info() or by using 74453a5a1b3Sopenharmony_ci * PA_STREAM_AUTO_TIMING_UPDATE), this function will return NULL. 74553a5a1b3Sopenharmony_ci * 74653a5a1b3Sopenharmony_ci * Please note that the write_index member field (and only this field) 74753a5a1b3Sopenharmony_ci * is updated on each pa_stream_write() call, not just when a timing 74853a5a1b3Sopenharmony_ci * update has been received. */ 74953a5a1b3Sopenharmony_ciconst pa_timing_info* pa_stream_get_timing_info(pa_stream *s); 75053a5a1b3Sopenharmony_ci 75153a5a1b3Sopenharmony_ci/** Return a pointer to the stream's sample specification. */ 75253a5a1b3Sopenharmony_ciconst pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s); 75353a5a1b3Sopenharmony_ci 75453a5a1b3Sopenharmony_ci/** Return a pointer to the stream's channel map. */ 75553a5a1b3Sopenharmony_ciconst pa_channel_map* pa_stream_get_channel_map(pa_stream *s); 75653a5a1b3Sopenharmony_ci 75753a5a1b3Sopenharmony_ci/** Return a pointer to the stream's format. \since 1.0 */ 75853a5a1b3Sopenharmony_ciconst pa_format_info* pa_stream_get_format_info(const pa_stream *s); 75953a5a1b3Sopenharmony_ci 76053a5a1b3Sopenharmony_ci/** Return the per-stream server-side buffer metrics of the 76153a5a1b3Sopenharmony_ci * stream. Only valid after the stream has been connected successfully 76253a5a1b3Sopenharmony_ci * and if the server is at least PulseAudio 0.9. This will return the 76353a5a1b3Sopenharmony_ci * actual configured buffering metrics, which may differ from what was 76453a5a1b3Sopenharmony_ci * requested during pa_stream_connect_record() or 76553a5a1b3Sopenharmony_ci * pa_stream_connect_playback(). This call will always return the 76653a5a1b3Sopenharmony_ci * actual per-stream server-side buffer metrics, regardless whether 76753a5a1b3Sopenharmony_ci * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.0 */ 76853a5a1b3Sopenharmony_ciconst pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s); 76953a5a1b3Sopenharmony_ci 77053a5a1b3Sopenharmony_ci/** Change the buffer metrics of the stream during playback. The 77153a5a1b3Sopenharmony_ci * server might have chosen different buffer metrics than 77253a5a1b3Sopenharmony_ci * requested. The selected metrics may be queried with 77353a5a1b3Sopenharmony_ci * pa_stream_get_buffer_attr() as soon as the callback is called. Only 77453a5a1b3Sopenharmony_ci * valid after the stream has been connected successfully and if the 77553a5a1b3Sopenharmony_ci * server is at least PulseAudio 0.9.8. Please be aware of the 77653a5a1b3Sopenharmony_ci * slightly different semantics of the call depending whether 77753a5a1b3Sopenharmony_ci * PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.8 */ 77853a5a1b3Sopenharmony_cipa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata); 77953a5a1b3Sopenharmony_ci 78053a5a1b3Sopenharmony_ci/** Change the stream sampling rate during playback. You need to pass 78153a5a1b3Sopenharmony_ci * PA_STREAM_VARIABLE_RATE in the flags parameter of 78253a5a1b3Sopenharmony_ci * pa_stream_connect_playback() if you plan to use this function. Only valid 78353a5a1b3Sopenharmony_ci * after the stream has been connected successfully and if the server 78453a5a1b3Sopenharmony_ci * is at least PulseAudio 0.9.8. \since 0.9.8 */ 78553a5a1b3Sopenharmony_cipa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata); 78653a5a1b3Sopenharmony_ci 78753a5a1b3Sopenharmony_ci/** Update the property list of the sink input/source output of this 78853a5a1b3Sopenharmony_ci * stream, adding new entries. Please note that it is highly 78953a5a1b3Sopenharmony_ci * recommended to set as many properties initially via 79053a5a1b3Sopenharmony_ci * pa_stream_new_with_proplist() as possible instead a posteriori with 79153a5a1b3Sopenharmony_ci * this function, since that information may be used to route 79253a5a1b3Sopenharmony_ci * this stream to the right device. \since 0.9.11 */ 79353a5a1b3Sopenharmony_cipa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata); 79453a5a1b3Sopenharmony_ci 79553a5a1b3Sopenharmony_ci/** Update the property list of the sink input/source output of this 79653a5a1b3Sopenharmony_ci * stream, remove entries. \since 0.9.11 */ 79753a5a1b3Sopenharmony_cipa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata); 79853a5a1b3Sopenharmony_ci 79953a5a1b3Sopenharmony_ci/** For record streams connected to a monitor source: monitor only a 80053a5a1b3Sopenharmony_ci * very specific sink input of the sink. This function needs to be 80153a5a1b3Sopenharmony_ci * called before pa_stream_connect_record() is called. 80253a5a1b3Sopenharmony_ci * Returns zero on success, negative on error. \since 0.9.11 */ 80353a5a1b3Sopenharmony_ciint pa_stream_set_monitor_stream(pa_stream *s, uint32_t sink_input_idx); 80453a5a1b3Sopenharmony_ci 80553a5a1b3Sopenharmony_ci/** Return the sink input index previously set with 80653a5a1b3Sopenharmony_ci * pa_stream_set_monitor_stream(). Returns PA_INVALID_INDEX 80753a5a1b3Sopenharmony_ci * on failure. \since 0.9.11 */ 80853a5a1b3Sopenharmony_ciuint32_t pa_stream_get_monitor_stream(const pa_stream *s); 80953a5a1b3Sopenharmony_ci 81053a5a1b3Sopenharmony_ciPA_C_DECL_END 81153a5a1b3Sopenharmony_ci 81253a5a1b3Sopenharmony_ci#endif 813