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