1 module pulse.format;
2 
3 import pulse.proplist;
4 import pulse.sample;
5 import pulse.channelmap;
6 
7 extern (C):
8 
9 /***
10   This file is part of PulseAudio.
11 
12   Copyright 2011 Intel Corporation
13   Copyright 2011 Collabora Multimedia
14   Copyright 2011 Arun Raghavan <arun.raghavan@collabora.co.uk>
15 
16   PulseAudio is free software; you can redistribute it and/or modify
17   it under the terms of the GNU Lesser General Public License as published
18   by the Free Software Foundation; either version 2.1 of the License,
19   or (at your option) any later version.
20 
21   PulseAudio is distributed in the hope that it will be useful, but
22   WITHOUT ANY WARRANTY; without even the implied warranty of
23   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24   General Public License for more details.
25 
26   You should have received a copy of the GNU Lesser General Public License
27   along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
28 ***/
29 
30 /** \file
31  * Utility functions for handling a stream or sink format. */
32 
33 /** Represents the type of encoding used in a stream or accepted by a sink. \since 1.0 */
34 enum pa_encoding
35 {
36     PA_ENCODING_ANY = 0,
37     /**< Any encoding format, PCM or compressed */
38 
39     PA_ENCODING_PCM = 1,
40     /**< Any PCM format */
41 
42     PA_ENCODING_AC3_IEC61937 = 2,
43     /**< AC3 data encapsulated in IEC 61937 header/padding */
44 
45     PA_ENCODING_EAC3_IEC61937 = 3,
46     /**< EAC3 data encapsulated in IEC 61937 header/padding */
47 
48     PA_ENCODING_MPEG_IEC61937 = 4,
49     /**< MPEG-1 or MPEG-2 (Part 3, not AAC) data encapsulated in IEC 61937 header/padding */
50 
51     PA_ENCODING_DTS_IEC61937 = 5,
52     /**< DTS data encapsulated in IEC 61937 header/padding */
53 
54     PA_ENCODING_MPEG2_AAC_IEC61937 = 6,
55     /**< MPEG-2 AAC data encapsulated in IEC 61937 header/padding. \since 4.0 */
56 
57     PA_ENCODING_TRUEHD_IEC61937 = 7,
58     /**< Dolby TrueHD data encapsulated in IEC 61937 header/padding. \since 13.0 */
59 
60     PA_ENCODING_DTSHD_IEC61937 = 8,
61     /**< DTS-HD Master Audio encapsulated in IEC 61937 header/padding. \since 13.0 */
62 
63     /* Remeber to update
64      * https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/SupportedAudioFormats/
65      * when adding new encodings! */
66 
67     PA_ENCODING_MAX = 9,
68     /**< Valid encoding types must be less than this value */
69 
70     PA_ENCODING_INVALID = -1
71     /**< Represents an invalid encoding */
72 }
73 
74 alias pa_encoding_t = pa_encoding;
75 
76 /** \cond fulldocs */
77 enum PA_ENCODING_ANY = pa_encoding_t.PA_ENCODING_ANY;
78 enum PA_ENCODING_PCM = pa_encoding_t.PA_ENCODING_PCM;
79 enum PA_ENCODING_AC3_IEC61937 = pa_encoding_t.PA_ENCODING_AC3_IEC61937;
80 enum PA_ENCODING_EAC3_IEC61937 = pa_encoding_t.PA_ENCODING_EAC3_IEC61937;
81 enum PA_ENCODING_MPEG_IEC61937 = pa_encoding_t.PA_ENCODING_MPEG_IEC61937;
82 enum PA_ENCODING_DTS_IEC61937 = pa_encoding_t.PA_ENCODING_DTS_IEC61937;
83 enum PA_ENCODING_MPEG2_AAC_IEC61937 = pa_encoding_t.PA_ENCODING_MPEG2_AAC_IEC61937;
84 enum PA_ENCODING_TRUEHD_IEC61937 = pa_encoding_t.PA_ENCODING_TRUEHD_IEC61937;
85 enum PA_ENCODING_DTSHD_IEC61937 = pa_encoding_t.PA_ENCODING_DTSHD_IEC61937;
86 enum PA_ENCODING_MAX = pa_encoding_t.PA_ENCODING_MAX;
87 enum PA_ENCODING_INVALID = pa_encoding_t.PA_ENCODING_INVALID;
88 /** \endcond */
89 
90 /** Returns a printable string representing the given encoding type. \since 1.0 */
91 const(char)* pa_encoding_to_string (pa_encoding_t e);
92 
93 /** Converts a string of the form returned by \a pa_encoding_to_string() back to
94  * a \a pa_encoding_t. \since 1.0 */
95 pa_encoding_t pa_encoding_from_string (const(char)* encoding);
96 
97 /** Represents the format of data provided in a stream or processed by a sink. \since 1.0 */
98 struct pa_format_info
99 {
100     pa_encoding_t encoding;
101     /**< The encoding used for the format */
102 
103     pa_proplist* plist;
104     /**< Additional encoding-specific properties such as sample rate, bitrate, etc. */
105 }
106 
107 /** Allocates a new \a pa_format_info structure. Clients must initialise at
108  * least the encoding field themselves. Free with pa_format_info_free. \since 1.0 */
109 pa_format_info* pa_format_info_new ();
110 
111 /** Returns a new \a pa_format_info struct and representing the same format as \a src. \since 1.0 */
112 pa_format_info* pa_format_info_copy (const(pa_format_info)* src);
113 
114 /** Frees a \a pa_format_info structure. \since 1.0 */
115 void pa_format_info_free (pa_format_info* f);
116 
117 /** Returns non-zero when the format info structure is valid. \since 1.0 */
118 int pa_format_info_valid (const(pa_format_info)* f);
119 
120 /** Returns non-zero when the format info structure represents a PCM
121  * (i.e.\ uncompressed data) format. \since 1.0 */
122 int pa_format_info_is_pcm (const(pa_format_info)* f);
123 
124 /** Returns non-zero if the format represented by \a first is a subset of
125  * the format represented by \a second. This means that \a second must
126  * have all the fields that \a first does, but the reverse need not
127  * be true. This is typically expected to be used to check if a
128  * stream's format is compatible with a given sink. In such a case,
129  * \a first would be the sink's format and \a second would be the
130  * stream's. \since 1.0 */
131 int pa_format_info_is_compatible (const(pa_format_info)* first, const(pa_format_info)* second);
132 
133 /** Maximum required string length for
134  * pa_format_info_snprint(). Please note that this value can change
135  * with any release without warning and without being considered API
136  * or ABI breakage. You should not use this definition anywhere where
137  * it might become part of an ABI. \since 1.0 */
138 enum PA_FORMAT_INFO_SNPRINT_MAX = 256;
139 
140 /** Make a human-readable string representing the given format. Returns \a s. \since 1.0 */
141 char* pa_format_info_snprint (char* s, size_t l, const(pa_format_info)* f);
142 
143 /** Parse a human-readable string of the form generated by
144  * \a pa_format_info_snprint() into a pa_format_info structure. \since 1.0 */
145 pa_format_info* pa_format_info_from_string (const(char)* str);
146 
147 /** Utility function to take a \a pa_sample_spec and generate the corresponding
148  * \a pa_format_info.
149  *
150  * Note that if you want the server to choose some of the stream parameters,
151  * for example the sample rate, so that they match the device parameters, then
152  * you shouldn't use this function. In order to allow the server to choose
153  * a parameter value, that parameter must be left unspecified in the
154  * pa_format_info object, and this function always specifies all parameters. An
155  * exception is the channel map: if you pass NULL for the channel map, then the
156  * channel map will be left unspecified, allowing the server to choose it.
157  *
158  * \since 2.0 */
159 pa_format_info* pa_format_info_from_sample_spec (const(pa_sample_spec)* ss, const(pa_channel_map)* map);
160 
161 /** Utility function to generate a \a pa_sample_spec and \a pa_channel_map corresponding to a given \a pa_format_info. The
162  * conversion for PCM formats is straight-forward. For non-PCM formats, if there is a fixed size-time conversion (i.e. all
163  * IEC61937-encapsulated formats), a "fake" sample spec whose size-time conversion corresponds to this format is provided and
164  * the channel map argument is ignored. For formats with variable size-time conversion, this function will fail. Returns a
165  * negative integer if conversion failed and 0 on success. \since 2.0 */
166 int pa_format_info_to_sample_spec (const(pa_format_info)* f, pa_sample_spec* ss, pa_channel_map* map);
167 
168 /** Represents the type of value type of a property on a \ref pa_format_info. \since 2.0 */
169 enum pa_prop_type_t
170 {
171     PA_PROP_TYPE_INT = 0,
172     /**< Integer property */
173 
174     PA_PROP_TYPE_INT_RANGE = 1,
175     /**< Integer range property */
176 
177     PA_PROP_TYPE_INT_ARRAY = 2,
178     /**< Integer array property */
179 
180     PA_PROP_TYPE_STRING = 3,
181     /**< String property */
182 
183     PA_PROP_TYPE_STRING_ARRAY = 4,
184     /**< String array property */
185 
186     PA_PROP_TYPE_INVALID = -1
187     /**< Represents an invalid type */
188 }
189 
190 /** \cond fulldocs */
191 enum PA_PROP_TYPE_INT = pa_prop_type_t.PA_PROP_TYPE_INT;
192 enum PA_PROP_TYPE_INT_RANGE = pa_prop_type_t.PA_PROP_TYPE_INT_RANGE;
193 enum PA_PROP_TYPE_INT_ARRAY = pa_prop_type_t.PA_PROP_TYPE_INT_ARRAY;
194 enum PA_PROP_TYPE_STRING = pa_prop_type_t.PA_PROP_TYPE_STRING;
195 enum PA_PROP_TYPE_STRING_ARRAY = pa_prop_type_t.PA_PROP_TYPE_STRING_ARRAY;
196 enum PA_PROP_TYPE_INVALID = pa_prop_type_t.PA_PROP_TYPE_INVALID;
197 /** \endcond */
198 
199 /** Gets the type of property \a key in a given \ref pa_format_info. \since 2.0 */
200 pa_prop_type_t pa_format_info_get_prop_type (const(pa_format_info)* f, const(char)* key);
201 
202 /** Gets an integer property from the given format info. Returns 0 on success and a negative integer on failure. \since 2.0 */
203 int pa_format_info_get_prop_int (const(pa_format_info)* f, const(char)* key, int* v);
204 /** Gets an integer range property from the given format info. Returns 0 on success and a negative integer on failure.
205  * \since 2.0 */
206 int pa_format_info_get_prop_int_range (const(pa_format_info)* f, const(char)* key, int* min, int* max);
207 /** Gets an integer array property from the given format info. \a values contains the values and \a n_values contains the
208  * number of elements. The caller must free \a values using \ref pa_xfree. Returns 0 on success and a negative integer on
209  * failure. \since 2.0 */
210 int pa_format_info_get_prop_int_array (const(pa_format_info)* f, const(char)* key, int** values, int* n_values);
211 /** Gets a string property from the given format info.  The caller must free the returned string using \ref pa_xfree. Returns
212  * 0 on success and a negative integer on failure. \since 2.0 */
213 int pa_format_info_get_prop_string (const(pa_format_info)* f, const(char)* key, char** v);
214 /** Gets a string array property from the given format info. \a values contains the values and \a n_values contains
215  * the number of elements. The caller must free \a values using \ref pa_format_info_free_string_array. Returns 0 on success and
216  * a negative integer on failure. \since 2.0 */
217 int pa_format_info_get_prop_string_array (const(pa_format_info)* f, const(char)* key, char*** values, int* n_values);
218 
219 /** Frees a string array returned by \ref pa_format_info_get_prop_string_array. \since 2.0 */
220 void pa_format_info_free_string_array (char** values, int n_values);
221 
222 /** Gets the sample format stored in the format info. Returns a negative error
223  * code on failure. If the sample format property is not set at all, returns a
224  * negative integer. \since 13.0 */
225 int pa_format_info_get_sample_format (const(pa_format_info)* f, pa_sample_format_t* sf);
226 
227 /** Gets the sample rate stored in the format info. Returns a negative error
228  * code on failure. If the sample rate property is not set at all, returns a
229  * negative integer. \since 13.0 */
230 int pa_format_info_get_rate (const(pa_format_info)* f, uint* rate);
231 
232 /** Gets the channel count stored in the format info. Returns a negative error
233  * code on failure. If the channels property is not set at all, returns a
234  * negative integer. \since 13.0 */
235 int pa_format_info_get_channels (const(pa_format_info)* f, ubyte* channels);
236 
237 /** Gets the channel map stored in the format info. Returns a negative error
238  * code on failure. If the channel map property is not
239  * set at all, returns a negative integer. \since 13.0 */
240 int pa_format_info_get_channel_map (const(pa_format_info)* f, pa_channel_map* map);
241 
242 /** Sets an integer property on the given format info. \since 1.0 */
243 void pa_format_info_set_prop_int (pa_format_info* f, const(char)* key, int value);
244 /** Sets a property with a list of integer values on the given format info. \since 1.0 */
245 void pa_format_info_set_prop_int_array (pa_format_info* f, const(char)* key, const(int)* values, int n_values);
246 /** Sets a property which can have any value in a given integer range on the given format info. \since 1.0 */
247 void pa_format_info_set_prop_int_range (pa_format_info* f, const(char)* key, int min, int max);
248 /** Sets a string property on the given format info. \since 1.0 */
249 void pa_format_info_set_prop_string (pa_format_info* f, const(char)* key, const(char)* value);
250 /** Sets a property with a list of string values on the given format info. \since 1.0 */
251 void pa_format_info_set_prop_string_array (pa_format_info* f, const(char)* key, const(char*)* values, int n_values);
252 
253 /** Convenience method to set the sample format as a property on the given
254  * format.
255  *
256  * Note for PCM: If the sample format is left unspecified in the pa_format_info
257  * object, then the server will select the stream sample format. In that case
258  * the stream sample format will most likely match the device sample format,
259  * meaning that sample format conversion will be avoided.
260  *
261  * \since 1.0 */
262 void pa_format_info_set_sample_format (pa_format_info* f, pa_sample_format_t sf);
263 
264 /** Convenience method to set the sampling rate as a property on the given
265  * format.
266  *
267  * Note for PCM: If the sample rate is left unspecified in the pa_format_info
268  * object, then the server will select the stream sample rate. In that case the
269  * stream sample rate will most likely match the device sample rate, meaning
270  * that sample rate conversion will be avoided.
271  *
272  * \since 1.0 */
273 void pa_format_info_set_rate (pa_format_info* f, int rate);
274 
275 /** Convenience method to set the number of channels as a property on the given
276  * format.
277  *
278  * Note for PCM: If the channel count is left unspecified in the pa_format_info
279  * object, then the server will select the stream channel count. In that case
280  * the stream channel count will most likely match the device channel count,
281  * meaning that up/downmixing will be avoided.
282  *
283  * \since 1.0 */
284 void pa_format_info_set_channels (pa_format_info* f, int channels);
285 
286 /** Convenience method to set the channel map as a property on the given
287  * format.
288  *
289  * Note for PCM: If the channel map is left unspecified in the pa_format_info
290  * object, then the server will select the stream channel map. In that case the
291  * stream channel map will most likely match the device channel map, meaning
292  * that remixing will be avoided.
293  *
294  * \since 1.0 */
295 void pa_format_info_set_channel_map (pa_format_info* f, const(pa_channel_map)* map);
296