Path: blob/master/thirdparty/linuxbsd_headers/pulse/stream.h
9905 views
#ifndef foostreamhfoo1#define foostreamhfoo23/***4This file is part of PulseAudio.56Copyright 2004-2006 Lennart Poettering7Copyright 2006 Pierre Ossman <[email protected]> for Cendio AB89PulseAudio is free software; you can redistribute it and/or modify10it under the terms of the GNU Lesser General Public License as published11by the Free Software Foundation; either version 2.1 of the License,12or (at your option) any later version.1314PulseAudio is distributed in the hope that it will be useful, but15WITHOUT ANY WARRANTY; without even the implied warranty of16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU17General Public License for more details.1819You should have received a copy of the GNU Lesser General Public License20along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.21***/2223#include <sys/types.h>2425#include <pulse/sample.h>26#include <pulse/format.h>27#include <pulse/channelmap.h>28#include <pulse/volume.h>29#include <pulse/def.h>30#include <pulse/cdecl.h>31#include <pulse/operation.h>32#include <pulse/context.h>33#include <pulse/proplist.h>3435/** \page streams Audio Streams36*37* \section overv_sec Overview38*39* Audio streams form the central functionality of the sound server. Data is40* routed, converted and mixed from several sources before it is passed along41* to a final output. Currently, there are three forms of audio streams:42*43* \li Playback streams - Data flows from the client to the server.44* \li Record streams - Data flows from the server to the client.45* \li Upload streams - Similar to playback streams, but the data is stored in46* the sample cache. See \ref scache for more information47* about controlling the sample cache.48*49* \section create_sec Creating50*51* To access a stream, a pa_stream object must be created using52* pa_stream_new() or pa_stream_new_extended(). pa_stream_new() is for PCM53* streams only, while pa_stream_new_extended() can be used for both PCM and54* compressed audio streams. At this point the application must specify what55* stream format(s) it supports. See \ref sample and \ref channelmap for more56* information on the stream format parameters. FIXME: Those references only57* talk about PCM parameters, we should also have an overview page for how the58* pa_format_info based stream format configuration works. Bug filed:59* https://bugs.freedesktop.org/show_bug.cgi?id=7226560*61* This first step will only create a client-side object, representing the62* stream. To use the stream, a server-side object must be created and63* associated with the local object. Depending on which type of stream is64* desired, a different function is needed:65*66* \li Playback stream - pa_stream_connect_playback()67* \li Record stream - pa_stream_connect_record()68* \li Upload stream - pa_stream_connect_upload() (see \ref scache)69*70* Similar to how connections are done in contexts, connecting a stream will71* not generate a pa_operation object. Also like contexts, the application72* should register a state change callback, using73* pa_stream_set_state_callback(), and wait for the stream to enter an active74* state.75*76* Note: there is a user-controllable slider in mixer applications such as77* pavucontrol corresponding to each of the created streams. Multiple78* (especially identically named) volume sliders for the same application might79* confuse the user. Also, the server supports only a limited number of80* simultaneous streams. Because of this, it is not always appropriate to81* create multiple streams in one application that needs to output multiple82* sounds. The rough guideline is: if there is no use case that would require83* separate user-initiated volume changes for each stream, perform the mixing84* inside the application.85*86* \subsection bufattr_subsec Buffer Attributes87*88* Playback and record streams always have a server-side buffer as89* part of the data flow. The size of this buffer needs to be chosen90* in a compromise between low latency and sensitivity for buffer91* overflows/underruns.92*93* The buffer metrics may be controlled by the application. They are94* described with a pa_buffer_attr structure which contains a number95* of fields:96*97* \li maxlength - The absolute maximum number of bytes that can be98* stored in the buffer. If this value is exceeded99* then data will be lost. It is recommended to pass100* (uint32_t) -1 here which will cause the server to101* fill in the maximum possible value.102*103* \li tlength - The target fill level of the playback buffer. The104* server will only send requests for more data as long105* as the buffer has less than this number of bytes of106* data. If you pass (uint32_t) -1 (which is107* recommended) here the server will choose the longest108* target buffer fill level possible to minimize the109* number of necessary wakeups and maximize drop-out110* safety. This can exceed 2s of buffering. For111* low-latency applications or applications where112* latency matters you should pass a proper value here.113*114* \li prebuf - Number of bytes that need to be in the buffer before115* playback will commence. Start of playback can be116* forced using pa_stream_trigger() even though the117* prebuffer size hasn't been reached. If a buffer118* underrun occurs, this prebuffering will be again119* enabled. If the playback shall never stop in case of a120* buffer underrun, this value should be set to 0. In121* that case the read index of the output buffer122* overtakes the write index, and hence the fill level of123* the buffer is negative. If you pass (uint32_t) -1 here124* (which is recommended) the server will choose the same125* value as tlength here.126*127* \li minreq - Minimum number of free bytes in the playback128* buffer before the server will request more data. It is129* recommended to fill in (uint32_t) -1 here. This value130* influences how much time the sound server has to move131* data from the per-stream server-side playback buffer132* to the hardware playback buffer.133*134* \li fragsize - Maximum number of bytes that the server will push in135* one chunk for record streams. If you pass (uint32_t)136* -1 (which is recommended) here, the server will137* choose the longest fragment setting possible to138* minimize the number of necessary wakeups and139* maximize drop-out safety. This can exceed 2s of140* buffering. For low-latency applications or141* applications where latency matters you should pass a142* proper value here.143*144* If PA_STREAM_ADJUST_LATENCY is set, then the tlength/fragsize145* parameters will be interpreted slightly differently than described146* above when passed to pa_stream_connect_record() and147* pa_stream_connect_playback(): the overall latency that is comprised148* of both the server side playback buffer length, the hardware149* playback buffer length and additional latencies will be adjusted in150* a way that it matches tlength resp. fragsize. Set151* PA_STREAM_ADJUST_LATENCY if you want to control the overall152* playback latency for your stream. Unset it if you want to control153* only the latency induced by the server-side, rewritable playback154* buffer. The server will try to fulfill the client's latency requests155* as good as possible. However if the underlying hardware cannot156* change the hardware buffer length or only in a limited range, the157* actually resulting latency might be different from what the client158* requested. Thus, for synchronization clients always need to check159* the actual measured latency via pa_stream_get_latency() or a160* similar call, and not make any assumptions about the latency161* available. The function pa_stream_get_buffer_attr() will always162* return the actual size of the server-side per-stream buffer in163* tlength/fragsize, regardless whether PA_STREAM_ADJUST_LATENCY is164* set or not.165*166* The server-side per-stream playback buffers are indexed by a write and a read167* index. The application writes to the write index and the sound168* device reads from the read index. The read index is increased169* monotonically, while the write index may be freely controlled by170* the application. Subtracting the read index from the write index171* will give you the current fill level of the buffer. The read/write172* indexes are 64bit values and measured in bytes, they will never173* wrap. The current read/write index may be queried using174* pa_stream_get_timing_info() (see below for more information). In175* case of a buffer underrun the read index is equal or larger than176* the write index. Unless the prebuf value is 0, PulseAudio will177* temporarily pause playback in such a case, and wait until the178* buffer is filled up to prebuf bytes again. If prebuf is 0, the179* read index may be larger than the write index, in which case180* silence is played. If the application writes data to indexes lower181* than the read index, the data is immediately lost.182*183* \section transfer_sec Transferring Data184*185* Once the stream is up, data can start flowing between the client and the186* server. Two different access models can be used to transfer the data:187*188* \li Asynchronous - The application register a callback using189* pa_stream_set_write_callback() and190* pa_stream_set_read_callback() to receive notifications191* that data can either be written or read.192* \li Polled - Query the library for available data/space using193* pa_stream_writable_size() and pa_stream_readable_size() and194* transfer data as needed. The sizes are stored locally, in the195* client end, so there is no delay when reading them.196*197* It is also possible to mix the two models freely.198*199* Once there is data/space available, it can be transferred using either200* pa_stream_write() for playback, or pa_stream_peek() / pa_stream_drop() for201* record. Make sure you do not overflow the playback buffers as data will be202* dropped.203*204* \section bufctl_sec Buffer Control205*206* The transfer buffers can be controlled through a number of operations:207*208* \li pa_stream_cork() - Start or stop the playback or recording.209* \li pa_stream_trigger() - Start playback immediately and do not wait for210* the buffer to fill up to the set trigger level.211* \li pa_stream_prebuf() - Reenable the playback trigger level.212* \li pa_stream_drain() - Wait for the playback buffer to go empty. Will213* return a pa_operation object that will indicate when214* the buffer is completely drained.215* \li pa_stream_flush() - Drop all data from the playback or record buffer. Do not216* wait for it to finish playing.217*218* \section seek_modes Seeking in the Playback Buffer219*220* A client application may freely seek in the playback buffer. To221* accomplish that the pa_stream_write() function takes a seek mode222* and an offset argument. The seek mode is one of:223*224* \li PA_SEEK_RELATIVE - seek relative to the current write index225* \li PA_SEEK_ABSOLUTE - seek relative to the beginning of the playback buffer, (i.e. the first that was ever played in the stream)226* \li PA_SEEK_RELATIVE_ON_READ - seek relative to the current read index. Use this to write data to the output buffer that should be played as soon as possible227* \li PA_SEEK_RELATIVE_END - seek relative to the last byte ever written.228*229* If an application just wants to append some data to the output230* buffer, PA_SEEK_RELATIVE and an offset of 0 should be used.231*232* After a call to pa_stream_write() the write index will be left at233* the position right after the last byte of the written data.234*235* \section latency_sec Latency236*237* A major problem with networked audio is the increased latency caused by238* the network. To remedy this, PulseAudio supports an advanced system of239* monitoring the current latency.240*241* To get the raw data needed to calculate latencies, call242* pa_stream_get_timing_info(). This will give you a pa_timing_info243* structure that contains everything that is known about the server244* side buffer transport delays and the backend active in the245* server. (Besides other things it contains the write and read index246* values mentioned above.)247*248* This structure is updated every time a249* pa_stream_update_timing_info() operation is executed. (i.e. before250* the first call to this function the timing information structure is251* not available!) Since it is a lot of work to keep this structure252* up-to-date manually, PulseAudio can do that automatically for you:253* if PA_STREAM_AUTO_TIMING_UPDATE is passed when connecting the254* stream PulseAudio will automatically update the structure every255* 100ms and every time a function is called that might invalidate the256* previously known timing data (such as pa_stream_write() or257* pa_stream_flush()). Please note however, that there always is a258* short time window when the data in the timing information structure259* is out-of-date. PulseAudio tries to mark these situations by260* setting the write_index_corrupt and read_index_corrupt fields261* accordingly.262*263* The raw timing data in the pa_timing_info structure is usually hard264* to deal with. Therefore a simpler interface is available:265* you can call pa_stream_get_time() or pa_stream_get_latency(). The266* former will return the current playback time of the hardware since267* the stream has been started. The latter returns the overall time a sample268* that you write now takes to be played by the hardware. These two269* functions base their calculations on the same data that is returned270* by pa_stream_get_timing_info(). Hence the same rules for keeping271* the timing data up-to-date apply here. In case the write or read272* index is corrupted, these two functions will fail with273* -PA_ERR_NODATA set.274*275* Since updating the timing info structure usually requires a full276* network round trip and some applications monitor the timing very277* often PulseAudio offers a timing interpolation system. If278* PA_STREAM_INTERPOLATE_TIMING is passed when connecting the stream,279* pa_stream_get_time() and pa_stream_get_latency() will try to280* interpolate the current playback time/latency by estimating the281* number of samples that have been played back by the hardware since282* the last regular timing update. It is especially useful to combine283* this option with PA_STREAM_AUTO_TIMING_UPDATE, which will enable284* you to monitor the current playback time/latency very precisely and285* very frequently without requiring a network round trip every time.286*287* \section flow_sec Overflow and underflow288*289* Even with the best precautions, buffers will sometime over - or290* underflow. To handle this gracefully, the application can be291* notified when this happens. Callbacks are registered using292* pa_stream_set_overflow_callback() and293* pa_stream_set_underflow_callback().294*295* \section sync_streams Synchronizing Multiple Playback Streams296*297* PulseAudio allows applications to fully synchronize multiple298* playback streams that are connected to the same output device. That299* means the streams will always be played back sample-by-sample300* synchronously. If stream operations like pa_stream_cork() are301* issued on one of the synchronized streams, they are simultaneously302* issued on the others.303*304* To synchronize a stream to another, just pass the "master" stream305* as last argument to pa_stream_connect_playback(). To make sure that306* the freshly created stream doesn't start playback right-away, make307* sure to pass PA_STREAM_START_CORKED and -- after all streams have308* been created -- uncork them all with a single call to309* pa_stream_cork() for the master stream.310*311* To make sure that a particular stream doesn't stop to play when a312* server side buffer underrun happens on it while the other313* synchronized streams continue playing and hence deviate, you need to314* pass a "prebuf" pa_buffer_attr of 0 when connecting it.315*316* \section disc_sec Disconnecting317*318* When a stream has served is purpose it must be disconnected with319* pa_stream_disconnect(). If you only unreference it, then it will live on320* and eat resources both locally and on the server until you disconnect the321* context.322*323*/324325/** \file326* Audio streams for input, output and sample upload327*328* See also \subpage streams329*/330331PA_C_DECL_BEGIN332333/** An opaque stream for playback or recording */334typedef struct pa_stream pa_stream;335336/** A generic callback for operation completion */337typedef void (*pa_stream_success_cb_t) (pa_stream*s, int success, void *userdata);338339/** A generic request callback */340typedef void (*pa_stream_request_cb_t)(pa_stream *p, size_t nbytes, void *userdata);341342/** A generic notification callback */343typedef void (*pa_stream_notify_cb_t)(pa_stream *p, void *userdata);344345/** A callback for asynchronous meta/policy event messages. Well known346* event names are PA_STREAM_EVENT_REQUEST_CORK and347* PA_STREAM_EVENT_REQUEST_UNCORK. The set of defined events can be348* extended at any time. Also, server modules may introduce additional349* message types so make sure that your callback function ignores messages350* it doesn't know. \since 0.9.15 */351typedef void (*pa_stream_event_cb_t)(pa_stream *p, const char *name, pa_proplist *pl, void *userdata);352353/** Create a new, unconnected stream with the specified name and354* sample type. It is recommended to use pa_stream_new_with_proplist()355* instead and specify some initial properties. */356pa_stream* pa_stream_new(357pa_context *c /**< The context to create this stream in */,358const char *name /**< A name for this stream */,359const pa_sample_spec *ss /**< The desired sample format */,360const pa_channel_map *map /**< The desired channel map, or NULL for default */);361362/** Create a new, unconnected stream with the specified name and363* sample type, and specify the initial stream property364* list. \since 0.9.11 */365pa_stream* pa_stream_new_with_proplist(366pa_context *c /**< The context to create this stream in */,367const char *name /**< A name for this stream */,368const pa_sample_spec *ss /**< The desired sample format */,369const pa_channel_map *map /**< The desired channel map, or NULL for default */,370pa_proplist *p /**< The initial property list */);371372/** Create a new, unconnected stream with the specified name, the set of formats373* this client can provide, and an initial list of properties. While374* connecting, the server will select the most appropriate format which the375* client must then provide. \since 1.0 */376pa_stream *pa_stream_new_extended(377pa_context *c /**< The context to create this stream in */,378const char *name /**< A name for this stream */,379pa_format_info * const * formats /**< The list of formats that can be provided */,380unsigned int n_formats /**< The number of formats being passed in */,381pa_proplist *p /**< The initial property list */);382383/** Decrease the reference counter by one. */384void pa_stream_unref(pa_stream *s);385386/** Increase the reference counter by one. */387pa_stream *pa_stream_ref(pa_stream *s);388389/** Return the current state of the stream. */390pa_stream_state_t pa_stream_get_state(pa_stream *p);391392/** Return the context this stream is attached to. */393pa_context* pa_stream_get_context(pa_stream *p);394395/** Return the sink input resp.\ source output index this stream is396* identified in the server with. This is useful with the397* introspection functions such as pa_context_get_sink_input_info()398* or pa_context_get_source_output_info(). */399uint32_t pa_stream_get_index(pa_stream *s);400401/** Return the index of the sink or source this stream is connected to402* in the server. This is useful with the introspection403* functions such as pa_context_get_sink_info_by_index() or404* pa_context_get_source_info_by_index().405*406* Please note that streams may be moved between sinks/sources and thus407* it is recommended to use pa_stream_set_moved_callback() to be notified408* about this. This function will return with -PA_ERR_NOTSUPPORTED when the409* server is older than 0.9.8. \since 0.9.8 */410uint32_t pa_stream_get_device_index(pa_stream *s);411412/** Return the name of the sink or source this stream is connected to413* in the server. This is useful with the introspection414* functions such as pa_context_get_sink_info_by_name()415* or pa_context_get_source_info_by_name().416*417* Please note that streams may be moved between sinks/sources and thus418* it is recommended to use pa_stream_set_moved_callback() to be notified419* about this. This function will return with -PA_ERR_NOTSUPPORTED when the420* server is older than 0.9.8. \since 0.9.8 */421const char *pa_stream_get_device_name(pa_stream *s);422423/** Return 1 if the sink or source this stream is connected to has424* been suspended. This will return 0 if not, and a negative value on425* error. This function will return with -PA_ERR_NOTSUPPORTED when the426* server is older than 0.9.8. \since 0.9.8 */427int pa_stream_is_suspended(pa_stream *s);428429/** Return 1 if the this stream has been corked. This will return 0 if430* not, and a negative value on error. \since 0.9.11 */431int pa_stream_is_corked(pa_stream *s);432433/** Connect the stream to a sink. It is strongly recommended to pass434* NULL in both \a dev and \a volume and to set neither435* PA_STREAM_START_MUTED nor PA_STREAM_START_UNMUTED -- unless these436* options are directly dependent on user input or configuration.437*438* If you follow this rule then the sound server will have the full439* flexibility to choose the device, volume and mute status440* automatically, based on server-side policies, heuristics and stored441* information from previous uses. Also the server may choose to442* reconfigure audio devices to make other sinks/sources or443* capabilities available to be able to accept the stream.444*445* Before 0.9.20 it was not defined whether the \a volume parameter was446* interpreted relative to the sink's current volume or treated as447* an absolute device volume. Since 0.9.20 it is an absolute volume when448* the sink is in flat volume mode, and relative otherwise, thus449* making sure the volume passed here has always the same semantics as450* the volume passed to pa_context_set_sink_input_volume(). It is possible451* to figure out whether flat volume mode is in effect for a given sink452* by calling pa_context_get_sink_info_by_name().453*454* Since 5.0, it's possible to specify a single-channel volume even if the455* stream has multiple channels. In that case the same volume is applied to all456* channels. */457int pa_stream_connect_playback(458pa_stream *s /**< The stream to connect to a sink */,459const char *dev /**< Name of the sink to connect to, or NULL for default */ ,460const pa_buffer_attr *attr /**< Buffering attributes, or NULL for default */,461pa_stream_flags_t flags /**< Additional flags, or 0 for default */,462const pa_cvolume *volume /**< Initial volume, or NULL for default */,463pa_stream *sync_stream /**< Synchronize this stream with the specified one, or NULL for a standalone stream */);464465/** Connect the stream to a source. */466int pa_stream_connect_record(467pa_stream *s /**< The stream to connect to a source */ ,468const char *dev /**< Name of the source to connect to, or NULL for default */,469const pa_buffer_attr *attr /**< Buffer attributes, or NULL for default */,470pa_stream_flags_t flags /**< Additional flags, or 0 for default */);471472/** Disconnect a stream from a source/sink. */473int pa_stream_disconnect(pa_stream *s);474475/** Prepare writing data to the server (for playback streams). This476* function may be used to optimize the number of memory copies when477* doing playback ("zero-copy"). It is recommended to call this478* function before each call to pa_stream_write().479*480* Pass in the address to a pointer and an address of the number of481* bytes you want to write. On return the two values will contain a482* pointer where you can place the data to write and the maximum number483* of bytes you can write. \a *nbytes can be smaller or have the same484* value as you passed in. You need to be able to handle both cases.485* Accessing memory beyond the returned \a *nbytes value is invalid.486* Accessing the memory returned after the following pa_stream_write()487* or pa_stream_cancel_write() is invalid.488*489* On invocation only \a *nbytes needs to be initialized, on return both490* *data and *nbytes will be valid. If you place (size_t) -1 in *nbytes491* on invocation the memory size will be chosen automatically (which is492* recommended to do). After placing your data in the memory area493* returned, call pa_stream_write() with \a data set to an address494* within this memory area and an \a nbytes value that is smaller or495* equal to what was returned by this function to actually execute the496* write.497*498* An invocation of pa_stream_write() should follow "quickly" on499* pa_stream_begin_write(). It is not recommended letting an unbounded500* amount of time pass after calling pa_stream_begin_write() and501* before calling pa_stream_write(). If you want to cancel a502* previously called pa_stream_begin_write() without calling503* pa_stream_write() use pa_stream_cancel_write(). Calling504* pa_stream_begin_write() twice without calling pa_stream_write() or505* pa_stream_cancel_write() in between will return exactly the same506* \a data pointer and \a nbytes values. \since 0.9.16 */507int pa_stream_begin_write(508pa_stream *p,509void **data,510size_t *nbytes);511512/** Reverses the effect of pa_stream_begin_write() dropping all data513* that has already been placed in the memory area returned by514* pa_stream_begin_write(). Only valid to call if515* pa_stream_begin_write() was called before and neither516* pa_stream_cancel_write() nor pa_stream_write() have been called517* yet. Accessing the memory previously returned by518* pa_stream_begin_write() after this call is invalid. Any further519* explicit freeing of the memory area is not necessary. \since520* 0.9.16 */521int pa_stream_cancel_write(522pa_stream *p);523524/** Write some data to the server (for playback streams).525* If \a free_cb is non-NULL this routine is called when all data has526* been written out. An internal reference to the specified data is527* kept, the data is not copied. If NULL, the data is copied into an528* internal buffer.529*530* The client may freely seek around in the output buffer. For531* most applications it is typical to pass 0 and PA_SEEK_RELATIVE532* as values for the arguments \a offset and \a seek. After the write533* call succeeded the write index will be at the position after where534* this chunk of data has been written to.535*536* As an optimization for avoiding needless memory copies you may call537* pa_stream_begin_write() before this call and then place your audio538* data directly in the memory area returned by that call. Then, pass539* a pointer to that memory area to pa_stream_write(). After the540* invocation of pa_stream_write() the memory area may no longer be541* accessed. Any further explicit freeing of the memory area is not542* necessary. It is OK to write the memory area returned by543* pa_stream_begin_write() only partially with this call, skipping544* bytes both at the end and at the beginning of the reserved memory545* area.*/546int pa_stream_write(547pa_stream *p /**< The stream to use */,548const void *data /**< The data to write */,549size_t nbytes /**< The length of the data to write in bytes, must be in multiples of the stream's sample spec frame size */,550pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */,551int64_t offset /**< Offset for seeking, must be 0 for upload streams, must be in multiples of the stream's sample spec frame size */,552pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */);553554/** Function does exactly the same as pa_stream_write() with the difference555* that free_cb_data is passed to free_cb instead of data. \since 6.0 */556int pa_stream_write_ext_free(557pa_stream *p /**< The stream to use */,558const void *data /**< The data to write */,559size_t nbytes /**< The length of the data to write in bytes */,560pa_free_cb_t free_cb /**< A cleanup routine for the data or NULL to request an internal copy */,561void *free_cb_data /**< Argument passed to free_cb function */,562int64_t offset /**< Offset for seeking, must be 0 for upload streams */,563pa_seek_mode_t seek /**< Seek mode, must be PA_SEEK_RELATIVE for upload streams */);564565/** Read the next fragment from the buffer (for recording streams).566* If there is data at the current read index, \a data will point to567* the actual data and \a nbytes will contain the size of the data in568* bytes (which can be less or more than a complete fragment).569*570* If there is no data at the current read index, it means that either571* the buffer is empty or it contains a hole (that is, the write index572* is ahead of the read index but there's no data where the read index573* points at). If the buffer is empty, \a data will be NULL and574* \a nbytes will be 0. If there is a hole, \a data will be NULL and575* \a nbytes will contain the length of the hole.576*577* Use pa_stream_drop() to actually remove the data from the buffer578* and move the read index forward. pa_stream_drop() should not be579* called if the buffer is empty, but it should be called if there is580* a hole. */581int pa_stream_peek(582pa_stream *p /**< The stream to use */,583const void **data /**< Pointer to pointer that will point to data */,584size_t *nbytes /**< The length of the data read in bytes */);585586/** Remove the current fragment on record streams. It is invalid to do this without first587* calling pa_stream_peek(). */588int pa_stream_drop(pa_stream *p);589590/** Return the number of bytes requested by the server that have not yet591* been written.592*593* It is possible to write more than this amount, up to the stream's594* buffer_attr.maxlength bytes. This is usually not desirable, though, as595* it would increase stream latency to be higher than requested596* (buffer_attr.tlength).597*/598size_t pa_stream_writable_size(pa_stream *p);599600/** Return the number of bytes that may be read using pa_stream_peek(). */601size_t pa_stream_readable_size(pa_stream *p);602603/** Drain a playback stream. Use this for notification when the604* playback buffer is empty after playing all the audio in the buffer.605* Please note that only one drain operation per stream may be issued606* at a time. */607pa_operation* pa_stream_drain(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);608609/** Request a timing info structure update for a stream. Use610* pa_stream_get_timing_info() to get access to the raw timing data,611* or pa_stream_get_time() or pa_stream_get_latency() to get cleaned612* up values. */613pa_operation* pa_stream_update_timing_info(pa_stream *p, pa_stream_success_cb_t cb, void *userdata);614615/** Set the callback function that is called whenever the state of the stream changes. */616void pa_stream_set_state_callback(pa_stream *s, pa_stream_notify_cb_t cb, void *userdata);617618/** Set the callback function that is called when new data may be619* written to the stream. */620void pa_stream_set_write_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);621622/** Set the callback function that is called when new data is available from the stream. */623void pa_stream_set_read_callback(pa_stream *p, pa_stream_request_cb_t cb, void *userdata);624625/** Set the callback function that is called when a buffer overflow happens. (Only for playback streams) */626void pa_stream_set_overflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);627628/** Return at what position the latest underflow occurred, or -1 if this information is not629* known (e.g.\ if no underflow has occurred, or server is older than 1.0).630* Can be used inside the underflow callback to get information about the current underflow.631* (Only for playback streams) \since 1.0 */632int64_t pa_stream_get_underflow_index(pa_stream *p);633634/** Set the callback function that is called when a buffer underflow happens. (Only for playback streams) */635void pa_stream_set_underflow_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);636637/** Set the callback function that is called when a the server starts638* playback after an underrun or on initial startup. This only informs639* that audio is flowing again, it is no indication that audio started640* to reach the speakers already. (Only for playback streams) \since641* 0.9.11 */642void pa_stream_set_started_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);643644/** Set the callback function that is called whenever a latency645* information update happens. Useful on PA_STREAM_AUTO_TIMING_UPDATE646* streams only. */647void pa_stream_set_latency_update_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);648649/** Set the callback function that is called whenever the stream is650* moved to a different sink/source. Use pa_stream_get_device_name() or651* pa_stream_get_device_index() to query the new sink/source. This652* notification is only generated when the server is at least653* 0.9.8. \since 0.9.8 */654void pa_stream_set_moved_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);655656/** Set the callback function that is called whenever the sink/source657* this stream is connected to is suspended or resumed. Use658* pa_stream_is_suspended() to query the new suspend status. Please659* note that the suspend status might also change when the stream is660* moved between devices. Thus if you call this function you very661* likely want to call pa_stream_set_moved_callback() too. This662* notification is only generated when the server is at least663* 0.9.8. \since 0.9.8 */664void pa_stream_set_suspended_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);665666/** Set the callback function that is called whenever a meta/policy667* control event is received. \since 0.9.15 */668void pa_stream_set_event_callback(pa_stream *p, pa_stream_event_cb_t cb, void *userdata);669670/** Set the callback function that is called whenever the buffer671* attributes on the server side change. Please note that the buffer672* attributes can change when moving a stream to a different673* sink/source too, hence if you use this callback you should use674* pa_stream_set_moved_callback() as well. \since 0.9.15 */675void pa_stream_set_buffer_attr_callback(pa_stream *p, pa_stream_notify_cb_t cb, void *userdata);676677/** Pause (or resume) playback of this stream temporarily. Available678* on both playback and recording streams. If \a b is 1 the stream is679* paused. If \a b is 0 the stream is resumed. The pause/resume operation680* is executed as quickly as possible. If a cork is very quickly681* followed by an uncork or the other way round, this might not682* actually have any effect on the stream that is output. You can use683* pa_stream_is_corked() to find out whether the stream is currently684* paused or not. Normally a stream will be created in uncorked685* state. If you pass PA_STREAM_START_CORKED as a flag when connecting686* the stream, it will be created in corked state. */687pa_operation* pa_stream_cork(pa_stream *s, int b, pa_stream_success_cb_t cb, void *userdata);688689/** Flush the playback or record buffer of this stream. This discards any audio data690* in the buffer. Most of the time you're better off using the parameter691* \a seek of pa_stream_write() instead of this function. */692pa_operation* pa_stream_flush(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);693694/** Reenable prebuffering if specified in the pa_buffer_attr695* structure. Available for playback streams only. */696pa_operation* pa_stream_prebuf(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);697698/** Request immediate start of playback on this stream. This disables699* prebuffering temporarily if specified in the pa_buffer_attr structure.700* Available for playback streams only. */701pa_operation* pa_stream_trigger(pa_stream *s, pa_stream_success_cb_t cb, void *userdata);702703/** Rename the stream. */704pa_operation* pa_stream_set_name(pa_stream *s, const char *name, pa_stream_success_cb_t cb, void *userdata);705706/** Return the current playback/recording time. This is based on the707* data in the timing info structure returned by708* pa_stream_get_timing_info().709*710* This function will usually only return new data if a timing info711* update has been received. Only if timing interpolation has been712* requested (PA_STREAM_INTERPOLATE_TIMING) the data from the last713* timing update is used for an estimation of the current714* playback/recording time based on the local time that passed since715* the timing info structure has been acquired.716*717* The time value returned by this function is guaranteed to increase718* monotonically (the returned value is always greater719* or equal to the value returned by the last call). This behaviour720* can be disabled by using PA_STREAM_NOT_MONOTONIC. This may be721* desirable to better deal with bad estimations of transport722* latencies, but may have strange effects if the application is not723* able to deal with time going 'backwards'.724*725* The time interpolator activated by PA_STREAM_INTERPOLATE_TIMING726* favours 'smooth' time graphs over accurate ones to improve the727* smoothness of UI operations that are tied to the audio clock. If728* accuracy is more important to you, you might need to estimate your729* timing based on the data from pa_stream_get_timing_info() yourself730* or not work with interpolated timing at all and instead always731* query the server side for the most up to date timing with732* pa_stream_update_timing_info().733*734* If no timing information has been735* received yet this call will return -PA_ERR_NODATA. For more details736* see pa_stream_get_timing_info(). */737int pa_stream_get_time(pa_stream *s, pa_usec_t *r_usec);738739/** Determine the total stream latency. This function is based on740* pa_stream_get_time().741*742* The latency is stored in \a *r_usec. In case the stream is a743* monitoring stream the result can be negative, i.e. the captured744* samples are not yet played. In this case \a *negative is set to 1.745*746* If no timing information has been received yet, this call will747* return -PA_ERR_NODATA. On success, it will return 0.748*749* For more details see pa_stream_get_timing_info() and750* pa_stream_get_time(). */751int pa_stream_get_latency(pa_stream *s, pa_usec_t *r_usec, int *negative);752753/** Return the latest raw timing data structure. The returned pointer754* refers to an internal read-only instance of the timing755* structure. The user should make a copy of this structure if he756* wants to modify it. An in-place update to this data structure may757* be requested using pa_stream_update_timing_info().758*759* If no timing information has been received before (i.e. by760* requesting pa_stream_update_timing_info() or by using761* PA_STREAM_AUTO_TIMING_UPDATE), this function will fail with762* -PA_ERR_NODATA.763*764* Please note that the write_index member field (and only this field)765* is updated on each pa_stream_write() call, not just when a timing766* update has been received. */767const pa_timing_info* pa_stream_get_timing_info(pa_stream *s);768769/** Return a pointer to the stream's sample specification. */770const pa_sample_spec* pa_stream_get_sample_spec(pa_stream *s);771772/** Return a pointer to the stream's channel map. */773const pa_channel_map* pa_stream_get_channel_map(pa_stream *s);774775/** Return a pointer to the stream's format. \since 1.0 */776const pa_format_info* pa_stream_get_format_info(pa_stream *s);777778/** Return the per-stream server-side buffer metrics of the779* stream. Only valid after the stream has been connected successfully780* and if the server is at least PulseAudio 0.9. This will return the781* actual configured buffering metrics, which may differ from what was782* requested during pa_stream_connect_record() or783* pa_stream_connect_playback(). This call will always return the784* actual per-stream server-side buffer metrics, regardless whether785* PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.0 */786const pa_buffer_attr* pa_stream_get_buffer_attr(pa_stream *s);787788/** Change the buffer metrics of the stream during playback. The789* server might have chosen different buffer metrics then790* requested. The selected metrics may be queried with791* pa_stream_get_buffer_attr() as soon as the callback is called. Only792* valid after the stream has been connected successfully and if the793* server is at least PulseAudio 0.9.8. Please be aware of the794* slightly different semantics of the call depending whether795* PA_STREAM_ADJUST_LATENCY is set or not. \since 0.9.8 */796pa_operation *pa_stream_set_buffer_attr(pa_stream *s, const pa_buffer_attr *attr, pa_stream_success_cb_t cb, void *userdata);797798/** Change the stream sampling rate during playback. You need to pass799* PA_STREAM_VARIABLE_RATE in the flags parameter of800* pa_stream_connect_playback() if you plan to use this function. Only valid801* after the stream has been connected successfully and if the server802* is at least PulseAudio 0.9.8. \since 0.9.8 */803pa_operation *pa_stream_update_sample_rate(pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata);804805/** Update the property list of the sink input/source output of this806* stream, adding new entries. Please note that it is highly807* recommended to set as many properties initially via808* pa_stream_new_with_proplist() as possible instead a posteriori with809* this function, since that information may be used to route810* this stream to the right device. \since 0.9.11 */811pa_operation *pa_stream_proplist_update(pa_stream *s, pa_update_mode_t mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata);812813/** Update the property list of the sink input/source output of this814* stream, remove entries. \since 0.9.11 */815pa_operation *pa_stream_proplist_remove(pa_stream *s, const char *const keys[], pa_stream_success_cb_t cb, void *userdata);816817/** For record streams connected to a monitor source: monitor only a818* very specific sink input of the sink. This function needs to be819* called before pa_stream_connect_record() is called. \since820* 0.9.11 */821int pa_stream_set_monitor_stream(pa_stream *s, uint32_t sink_input_idx);822823/** Return the sink input index previously set with824* pa_stream_set_monitor_stream().825* \since 0.9.11 */826uint32_t pa_stream_get_monitor_stream(pa_stream *s);827828PA_C_DECL_END829830#endif831832833