1 module pulse.simple; 2 3 import pulse.channelmap; 4 import pulse.sample; 5 import pulse.def; 6 7 extern (C): 8 9 /*** 10 This file is part of PulseAudio. 11 12 Copyright 2004-2006 Lennart Poettering 13 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB 14 15 PulseAudio is free software; you can redistribute it and/or modify 16 it under the terms of the GNU Lesser General Public License as published 17 by the Free Software Foundation; either version 2.1 of the License, 18 or (at your option) any later version. 19 20 PulseAudio is distributed in the hope that it will be useful, but 21 WITHOUT ANY WARRANTY; without even the implied warranty of 22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 General Public License for more details. 24 25 You should have received a copy of the GNU Lesser General Public License 26 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 27 ***/ 28 29 /** \page simple Simple API 30 * 31 * \section overv_sec Overview 32 * 33 * The simple API is designed for applications with very basic sound 34 * playback or capture needs. It can only support a single stream per 35 * connection and has no support for handling of complex features like 36 * events, channel mappings and volume control. It is, however, very simple 37 * to use and quite sufficient for many programs. 38 * 39 * \section conn_sec Connecting 40 * 41 * The first step before using the sound system is to connect to the 42 * server. This is normally done this way: 43 * 44 * \code 45 * pa_simple *s; 46 * pa_sample_spec ss; 47 * 48 * ss.format = PA_SAMPLE_S16NE; 49 * ss.channels = 2; 50 * ss.rate = 44100; 51 * 52 * s = pa_simple_new(NULL, // Use the default server. 53 * "Fooapp", // Our application's name. 54 * PA_STREAM_PLAYBACK, 55 * NULL, // Use the default device. 56 * "Music", // Description of our stream. 57 * &ss, // Our sample format. 58 * NULL, // Use default channel map 59 * NULL, // Use default buffering attributes. 60 * NULL, // Ignore error code. 61 * ); 62 * \endcode 63 * 64 * At this point a connected object is returned, or NULL if there was a 65 * problem connecting. 66 * 67 * \section transfer_sec Transferring data 68 * 69 * Once the connection is established to the server, data can start flowing. 70 * Using the connection is very similar to the normal read() and write() 71 * system calls. The main difference is that they're called pa_simple_read() 72 * and pa_simple_write(). Note that these operations always block. 73 * 74 * \section ctrl_sec Buffer control 75 * 76 * \li pa_simple_get_latency() - Will return the total latency of 77 * the playback or record pipeline, respectively. 78 * \li pa_simple_flush() - Will throw away all data currently in buffers. 79 * 80 * If a playback stream is used then the following operation is available: 81 * 82 * \li pa_simple_drain() - Will wait for all sent data to finish playing. 83 * 84 * \section cleanup_sec Cleanup 85 * 86 * Once playback or capture is complete, the connection should be closed 87 * and resources freed. This is done through: 88 * 89 * \code 90 * pa_simple_free(s); 91 * \endcode 92 */ 93 94 /** \file 95 * A simple but limited synchronous playback and recording 96 * API. This is a synchronous, simplified wrapper around the standard 97 * asynchronous API. 98 * 99 * See also \subpage simple 100 */ 101 102 /** \example pacat-simple.c 103 * A simple playback tool using the simple API */ 104 105 /** \example parec-simple.c 106 * A simple recording tool using the simple API */ 107 108 /** \struct pa_simple 109 * An opaque simple connection object */ 110 struct pa_simple; 111 112 /** Create a new connection to the server. */ 113 114 /**< Server name, or NULL for default */ 115 /**< A descriptive name for this client (application name, ...) */ 116 /**< Open this stream for recording or playback? */ 117 /**< Sink (resp. source) name, or NULL for default */ 118 /**< A descriptive name for this stream (application name, song title, ...) */ 119 /**< The sample type to use */ 120 /**< The channel map to use, or NULL for default */ 121 /**< Buffering attributes, or NULL for default */ 122 /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ 123 pa_simple* pa_simple_new ( 124 const(char)* server, 125 const(char)* name, 126 pa_stream_direction_t dir, 127 const(char)* dev, 128 const(char)* stream_name, 129 const(pa_sample_spec)* ss, 130 const(pa_channel_map)* map, 131 const(pa_buffer_attr)* attr, 132 int* error); 133 134 /** Close and free the connection to the server. The connection object becomes invalid when this is called. */ 135 void pa_simple_free (pa_simple* s); 136 137 /** Write some data to the server. Returns zero on success, negative on error. */ 138 int pa_simple_write (pa_simple* s, const(void)* data, size_t bytes, int* error); 139 140 /** Wait until all data already written is played by the daemon. 141 * Returns zero on success, negative on error. */ 142 int pa_simple_drain (pa_simple* s, int* error); 143 144 /** Read some data from the server. This function blocks until \a bytes amount 145 * of data has been received from the server, or until an error occurs. 146 * Returns zero on success, negative on failure. */ 147 148 /**< The connection object. */ 149 /**< A pointer to a buffer. */ 150 /**< The number of bytes to read. */ 151 152 /**< A pointer where the error code is stored when the function returns 153 * a negative value. It is OK to pass NULL here. */ 154 int pa_simple_read (pa_simple* s, void* data, size_t bytes, int* error); 155 156 /** Return the playback or record latency. */ 157 pa_usec_t pa_simple_get_latency (pa_simple* s, int* error); 158 159 /** Flush the playback or record buffer. This discards any audio in the buffer. 160 * Returns zero on success, negative on error. */ 161 int pa_simple_flush (pa_simple* s, int* error); 162