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