1#ifndef foochannelmaphfoo
2#define foochannelmaphfoo
3
4/***
5 This file is part of PulseAudio.
6
7 Copyright 2005-2006 Lennart Poettering
8 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
9
10 PulseAudio is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published
12 by the Free Software Foundation; either version 2.1 of the License,
13 or (at your option) any later version.
14
15 PulseAudio is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <pulse/sample.h>
25#include <pulse/cdecl.h>
26#include <pulse/gccmacro.h>
27#include <pulse/version.h>
28
29/** \page channelmap Channel Maps
30 *
31 * \section overv_sec Overview
32 *
33 * Channel maps provide a way to associate channels in a stream with a
34 * specific speaker position. This relieves applications of having to
35 * make sure their channel order is identical to the final output.
36 *
37 * \section init_sec Initialisation
38 *
39 * A channel map consists of an array of \ref pa_channel_position values,
40 * one for each channel. This array is stored together with a channel count
41 * in a pa_channel_map structure.
42 *
43 * Before filling the structure, the application must initialise it using
44 * pa_channel_map_init(). There are also a number of convenience functions
45 * for standard channel mappings:
46 *
47 * \li pa_channel_map_init_mono() - Create a channel map with only mono audio.
48 * \li pa_channel_map_init_stereo() - Create a standard stereo mapping.
49 * \li pa_channel_map_init_auto() - Create a standard channel map for a specific number of channels
50 * \li pa_channel_map_init_extend() - Similar to
51 * pa_channel_map_init_auto() but synthesize a channel map if no
52 * predefined one is known for the specified number of channels.
53 *
54 * \section conv_sec Convenience Functions
55 *
56 * The library contains a number of convenience functions for dealing with
57 * channel maps:
58 *
59 * \li pa_channel_map_valid() - Tests if a channel map is valid.
60 * \li pa_channel_map_equal() - Tests if two channel maps are identical.
61 * \li pa_channel_map_snprint() - Creates a textual description of a channel
62 * map.
63 */
64
65/** \file
66 * Constants and routines for channel mapping handling
67 *
68 * See also \subpage channelmap
69 */
70
71PA_C_DECL_BEGIN
72
73/** A list of channel labels */
74typedef enum pa_channel_position {
75 PA_CHANNEL_POSITION_INVALID = -1,
76 PA_CHANNEL_POSITION_MONO = 0,
77
78 PA_CHANNEL_POSITION_FRONT_LEFT, /**< Apple, Dolby call this 'Left' */
79 PA_CHANNEL_POSITION_FRONT_RIGHT, /**< Apple, Dolby call this 'Right' */
80 PA_CHANNEL_POSITION_FRONT_CENTER, /**< Apple, Dolby call this 'Center' */
81
82/** \cond fulldocs */
83 PA_CHANNEL_POSITION_LEFT = PA_CHANNEL_POSITION_FRONT_LEFT,
84 PA_CHANNEL_POSITION_RIGHT = PA_CHANNEL_POSITION_FRONT_RIGHT,
85 PA_CHANNEL_POSITION_CENTER = PA_CHANNEL_POSITION_FRONT_CENTER,
86/** \endcond */
87
88 PA_CHANNEL_POSITION_REAR_CENTER, /**< Microsoft calls this 'Back Center', Apple calls this 'Center Surround', Dolby calls this 'Surround Rear Center' */
89 PA_CHANNEL_POSITION_REAR_LEFT, /**< Microsoft calls this 'Back Left', Apple calls this 'Left Surround' (!), Dolby calls this 'Surround Rear Left' */
90 PA_CHANNEL_POSITION_REAR_RIGHT, /**< Microsoft calls this 'Back Right', Apple calls this 'Right Surround' (!), Dolby calls this 'Surround Rear Right' */
91
92 PA_CHANNEL_POSITION_LFE, /**< Microsoft calls this 'Low Frequency', Apple calls this 'LFEScreen' */
93/** \cond fulldocs */
94 PA_CHANNEL_POSITION_SUBWOOFER = PA_CHANNEL_POSITION_LFE,
95/** \endcond */
96
97 PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, /**< Apple, Dolby call this 'Left Center' */
98 PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, /**< Apple, Dolby call this 'Right Center */
99
100 PA_CHANNEL_POSITION_SIDE_LEFT, /**< Apple calls this 'Left Surround Direct', Dolby calls this 'Surround Left' (!) */
101 PA_CHANNEL_POSITION_SIDE_RIGHT, /**< Apple calls this 'Right Surround Direct', Dolby calls this 'Surround Right' (!) */
102
103 PA_CHANNEL_POSITION_AUX0,
104 PA_CHANNEL_POSITION_AUX1,
105 PA_CHANNEL_POSITION_AUX2,
106 PA_CHANNEL_POSITION_AUX3,
107 PA_CHANNEL_POSITION_AUX4,
108 PA_CHANNEL_POSITION_AUX5,
109 PA_CHANNEL_POSITION_AUX6,
110 PA_CHANNEL_POSITION_AUX7,
111 PA_CHANNEL_POSITION_AUX8,
112 PA_CHANNEL_POSITION_AUX9,
113 PA_CHANNEL_POSITION_AUX10,
114 PA_CHANNEL_POSITION_AUX11,
115 PA_CHANNEL_POSITION_AUX12,
116 PA_CHANNEL_POSITION_AUX13,
117 PA_CHANNEL_POSITION_AUX14,
118 PA_CHANNEL_POSITION_AUX15,
119 PA_CHANNEL_POSITION_AUX16,
120 PA_CHANNEL_POSITION_AUX17,
121 PA_CHANNEL_POSITION_AUX18,
122 PA_CHANNEL_POSITION_AUX19,
123 PA_CHANNEL_POSITION_AUX20,
124 PA_CHANNEL_POSITION_AUX21,
125 PA_CHANNEL_POSITION_AUX22,
126 PA_CHANNEL_POSITION_AUX23,
127 PA_CHANNEL_POSITION_AUX24,
128 PA_CHANNEL_POSITION_AUX25,
129 PA_CHANNEL_POSITION_AUX26,
130 PA_CHANNEL_POSITION_AUX27,
131 PA_CHANNEL_POSITION_AUX28,
132 PA_CHANNEL_POSITION_AUX29,
133 PA_CHANNEL_POSITION_AUX30,
134 PA_CHANNEL_POSITION_AUX31,
135
136 PA_CHANNEL_POSITION_TOP_CENTER, /**< Apple calls this 'Top Center Surround' */
137
138 PA_CHANNEL_POSITION_TOP_FRONT_LEFT, /**< Apple calls this 'Vertical Height Left' */
139 PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, /**< Apple calls this 'Vertical Height Right' */
140 PA_CHANNEL_POSITION_TOP_FRONT_CENTER, /**< Apple calls this 'Vertical Height Center' */
141
142 PA_CHANNEL_POSITION_TOP_REAR_LEFT, /**< Microsoft and Apple call this 'Top Back Left' */
143 PA_CHANNEL_POSITION_TOP_REAR_RIGHT, /**< Microsoft and Apple call this 'Top Back Right' */
144 PA_CHANNEL_POSITION_TOP_REAR_CENTER, /**< Microsoft and Apple call this 'Top Back Center' */
145
146 PA_CHANNEL_POSITION_MAX
147} pa_channel_position_t;
148
149/** \cond fulldocs */
150#define PA_CHANNEL_POSITION_INVALID PA_CHANNEL_POSITION_INVALID
151#define PA_CHANNEL_POSITION_MONO PA_CHANNEL_POSITION_MONO
152#define PA_CHANNEL_POSITION_LEFT PA_CHANNEL_POSITION_LEFT
153#define PA_CHANNEL_POSITION_RIGHT PA_CHANNEL_POSITION_RIGHT
154#define PA_CHANNEL_POSITION_CENTER PA_CHANNEL_POSITION_CENTER
155#define PA_CHANNEL_POSITION_FRONT_LEFT PA_CHANNEL_POSITION_FRONT_LEFT
156#define PA_CHANNEL_POSITION_FRONT_RIGHT PA_CHANNEL_POSITION_FRONT_RIGHT
157#define PA_CHANNEL_POSITION_FRONT_CENTER PA_CHANNEL_POSITION_FRONT_CENTER
158#define PA_CHANNEL_POSITION_REAR_CENTER PA_CHANNEL_POSITION_REAR_CENTER
159#define PA_CHANNEL_POSITION_REAR_LEFT PA_CHANNEL_POSITION_REAR_LEFT
160#define PA_CHANNEL_POSITION_REAR_RIGHT PA_CHANNEL_POSITION_REAR_RIGHT
161#define PA_CHANNEL_POSITION_LFE PA_CHANNEL_POSITION_LFE
162#define PA_CHANNEL_POSITION_SUBWOOFER PA_CHANNEL_POSITION_SUBWOOFER
163#define PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER
164#define PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER
165#define PA_CHANNEL_POSITION_SIDE_LEFT PA_CHANNEL_POSITION_SIDE_LEFT
166#define PA_CHANNEL_POSITION_SIDE_RIGHT PA_CHANNEL_POSITION_SIDE_RIGHT
167#define PA_CHANNEL_POSITION_AUX0 PA_CHANNEL_POSITION_AUX0
168#define PA_CHANNEL_POSITION_AUX1 PA_CHANNEL_POSITION_AUX1
169#define PA_CHANNEL_POSITION_AUX2 PA_CHANNEL_POSITION_AUX2
170#define PA_CHANNEL_POSITION_AUX3 PA_CHANNEL_POSITION_AUX3
171#define PA_CHANNEL_POSITION_AUX4 PA_CHANNEL_POSITION_AUX4
172#define PA_CHANNEL_POSITION_AUX5 PA_CHANNEL_POSITION_AUX5
173#define PA_CHANNEL_POSITION_AUX6 PA_CHANNEL_POSITION_AUX6
174#define PA_CHANNEL_POSITION_AUX7 PA_CHANNEL_POSITION_AUX7
175#define PA_CHANNEL_POSITION_AUX8 PA_CHANNEL_POSITION_AUX8
176#define PA_CHANNEL_POSITION_AUX9 PA_CHANNEL_POSITION_AUX9
177#define PA_CHANNEL_POSITION_AUX10 PA_CHANNEL_POSITION_AUX10
178#define PA_CHANNEL_POSITION_AUX11 PA_CHANNEL_POSITION_AUX11
179#define PA_CHANNEL_POSITION_AUX12 PA_CHANNEL_POSITION_AUX12
180#define PA_CHANNEL_POSITION_AUX13 PA_CHANNEL_POSITION_AUX13
181#define PA_CHANNEL_POSITION_AUX14 PA_CHANNEL_POSITION_AUX14
182#define PA_CHANNEL_POSITION_AUX15 PA_CHANNEL_POSITION_AUX15
183#define PA_CHANNEL_POSITION_AUX16 PA_CHANNEL_POSITION_AUX16
184#define PA_CHANNEL_POSITION_AUX17 PA_CHANNEL_POSITION_AUX17
185#define PA_CHANNEL_POSITION_AUX18 PA_CHANNEL_POSITION_AUX18
186#define PA_CHANNEL_POSITION_AUX19 PA_CHANNEL_POSITION_AUX19
187#define PA_CHANNEL_POSITION_AUX20 PA_CHANNEL_POSITION_AUX20
188#define PA_CHANNEL_POSITION_AUX21 PA_CHANNEL_POSITION_AUX21
189#define PA_CHANNEL_POSITION_AUX22 PA_CHANNEL_POSITION_AUX22
190#define PA_CHANNEL_POSITION_AUX23 PA_CHANNEL_POSITION_AUX23
191#define PA_CHANNEL_POSITION_AUX24 PA_CHANNEL_POSITION_AUX24
192#define PA_CHANNEL_POSITION_AUX25 PA_CHANNEL_POSITION_AUX25
193#define PA_CHANNEL_POSITION_AUX26 PA_CHANNEL_POSITION_AUX26
194#define PA_CHANNEL_POSITION_AUX27 PA_CHANNEL_POSITION_AUX27
195#define PA_CHANNEL_POSITION_AUX28 PA_CHANNEL_POSITION_AUX28
196#define PA_CHANNEL_POSITION_AUX29 PA_CHANNEL_POSITION_AUX29
197#define PA_CHANNEL_POSITION_AUX30 PA_CHANNEL_POSITION_AUX30
198#define PA_CHANNEL_POSITION_AUX31 PA_CHANNEL_POSITION_AUX31
199#define PA_CHANNEL_POSITION_TOP_CENTER PA_CHANNEL_POSITION_TOP_CENTER
200#define PA_CHANNEL_POSITION_TOP_FRONT_LEFT PA_CHANNEL_POSITION_TOP_FRONT_LEFT
201#define PA_CHANNEL_POSITION_TOP_FRONT_RIGHT PA_CHANNEL_POSITION_TOP_FRONT_RIGHT
202#define PA_CHANNEL_POSITION_TOP_FRONT_CENTER PA_CHANNEL_POSITION_TOP_FRONT_CENTER
203#define PA_CHANNEL_POSITION_TOP_REAR_LEFT PA_CHANNEL_POSITION_TOP_REAR_LEFT
204#define PA_CHANNEL_POSITION_TOP_REAR_RIGHT PA_CHANNEL_POSITION_TOP_REAR_RIGHT
205#define PA_CHANNEL_POSITION_TOP_REAR_CENTER PA_CHANNEL_POSITION_TOP_REAR_CENTER
206#define PA_CHANNEL_POSITION_MAX PA_CHANNEL_POSITION_MAX
207/** \endcond */
208
209/** A mask of channel positions. \since 0.9.16 */
210typedef uint64_t pa_channel_position_mask_t;
211
212/** Makes a bit mask from a channel position. \since 0.9.16 */
213#define PA_CHANNEL_POSITION_MASK(f) ((pa_channel_position_mask_t) (1ULL << (f)))
214
215/** A list of channel mapping definitions for pa_channel_map_init_auto() */
216typedef enum pa_channel_map_def {
217 PA_CHANNEL_MAP_AIFF,
218 /**< The mapping from RFC3551, which is based on AIFF-C */
219
220/** \cond fulldocs */
221 PA_CHANNEL_MAP_ALSA,
222 /**< The default mapping used by ALSA. This mapping is probably
223 * not too useful since ALSA's default channel mapping depends on
224 * the device string used. */
225/** \endcond */
226
227 PA_CHANNEL_MAP_AUX,
228 /**< Only aux channels */
229
230 PA_CHANNEL_MAP_WAVEEX,
231 /**< Microsoft's WAVEFORMATEXTENSIBLE mapping. This mapping works
232 * as if all LSBs of dwChannelMask are set. */
233
234/** \cond fulldocs */
235 PA_CHANNEL_MAP_OSS,
236 /**< The default channel mapping used by OSS as defined in the OSS
237 * 4.0 API specs. This mapping is probably not too useful since
238 * the OSS API has changed in this respect and no longer knows a
239 * default channel mapping based on the number of channels. */
240/** \endcond */
241
242 /**< Upper limit of valid channel mapping definitions */
243 PA_CHANNEL_MAP_DEF_MAX,
244
245 PA_CHANNEL_MAP_DEFAULT = PA_CHANNEL_MAP_AIFF
246 /**< The default channel map */
247} pa_channel_map_def_t;
248
249/** \cond fulldocs */
250#define PA_CHANNEL_MAP_AIFF PA_CHANNEL_MAP_AIFF
251#define PA_CHANNEL_MAP_ALSA PA_CHANNEL_MAP_ALSA
252#define PA_CHANNEL_MAP_AUX PA_CHANNEL_MAP_AUX
253#define PA_CHANNEL_MAP_WAVEEX PA_CHANNEL_MAP_WAVEEX
254#define PA_CHANNEL_MAP_OSS PA_CHANNEL_MAP_OSS
255#define PA_CHANNEL_MAP_DEF_MAX PA_CHANNEL_MAP_DEF_MAX
256#define PA_CHANNEL_MAP_DEFAULT PA_CHANNEL_MAP_DEFAULT
257/** \endcond */
258
259/** A channel map which can be used to attach labels to specific
260 * channels of a stream. These values are relevant for conversion and
261 * mixing of streams */
262typedef struct pa_channel_map {
263 uint8_t channels;
264 /**< Number of channels */
265
266 pa_channel_position_t map[PA_CHANNELS_MAX];
267 /**< Channel labels */
268} pa_channel_map;
269
270/** Initialize the specified channel map and return a pointer to
271 * it. The channel map will have a defined state but
272 * pa_channel_map_valid() will fail for it. */
273pa_channel_map* pa_channel_map_init(pa_channel_map *m);
274
275/** Initialize the specified channel map for monaural audio and return a pointer to it */
276pa_channel_map* pa_channel_map_init_mono(pa_channel_map *m);
277
278/** Initialize the specified channel map for stereophonic audio and return a pointer to it */
279pa_channel_map* pa_channel_map_init_stereo(pa_channel_map *m);
280
281/** Initialize the specified channel map for the specified number of
282 * channels using default labels and return a pointer to it. This call
283 * will fail (return NULL) if there is no default channel map known for this
284 * specific number of channels and mapping. */
285pa_channel_map* pa_channel_map_init_auto(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
286
287/** Similar to pa_channel_map_init_auto() but instead of failing if no
288 * default mapping is known with the specified parameters it will
289 * synthesize a mapping based on a known mapping with fewer channels
290 * and fill up the rest with AUX0...AUX31 channels \since 0.9.11 */
291pa_channel_map* pa_channel_map_init_extend(pa_channel_map *m, unsigned channels, pa_channel_map_def_t def);
292
293/** Return a text label for the specified channel position */
294const char* pa_channel_position_to_string(pa_channel_position_t pos) PA_GCC_PURE;
295
296/** The inverse of pa_channel_position_to_string(). \since 0.9.16 */
297pa_channel_position_t pa_channel_position_from_string(const char *s) PA_GCC_PURE;
298
299/** Return a human readable text label for the specified channel position. \since 0.9.7 */
300const char* pa_channel_position_to_pretty_string(pa_channel_position_t pos);
301
302/** The maximum length of strings returned by
303 * pa_channel_map_snprint(). Please note that this value can change
304 * with any release without warning and without being considered API
305 * or ABI breakage. You should not use this definition anywhere where
306 * it might become part of an ABI. */
307#define PA_CHANNEL_MAP_SNPRINT_MAX 336
308
309/** Make a human readable string from the specified channel map */
310char* pa_channel_map_snprint(char *s, size_t l, const pa_channel_map *map);
311
312/** Parse a channel position list or well-known mapping name into a
313 * channel map structure. This turns the output of
314 * pa_channel_map_snprint() and pa_channel_map_to_name() back into a
315 * pa_channel_map */
316pa_channel_map *pa_channel_map_parse(pa_channel_map *map, const char *s);
317
318/** Compare two channel maps. Return 1 if both match. */
319int pa_channel_map_equal(const pa_channel_map *a, const pa_channel_map *b) PA_GCC_PURE;
320
321/** Return non-zero if the specified channel map is considered valid */
322int pa_channel_map_valid(const pa_channel_map *map) PA_GCC_PURE;
323
324/** Return non-zero if the specified channel map is compatible with
325 * the specified sample spec. \since 0.9.12 */
326int pa_channel_map_compatible(const pa_channel_map *map, const pa_sample_spec *ss) PA_GCC_PURE;
327
328/** Returns non-zero if every channel defined in b is also defined in a. \since 0.9.15 */
329int pa_channel_map_superset(const pa_channel_map *a, const pa_channel_map *b) PA_GCC_PURE;
330
331/** Returns non-zero if it makes sense to apply a volume 'balance'
332 * with this mapping, i.e.\ if there are left/right channels
333 * available. \since 0.9.15 */
334int pa_channel_map_can_balance(const pa_channel_map *map) PA_GCC_PURE;
335
336/** Returns non-zero if it makes sense to apply a volume 'fade'
337 * (i.e.\ 'balance' between front and rear) with this mapping, i.e.\ if
338 * there are front/rear channels available. \since 0.9.15 */
339int pa_channel_map_can_fade(const pa_channel_map *map) PA_GCC_PURE;
340
341/** Returns non-zero if it makes sense to apply a volume 'lfe balance'
342 * (i.e.\ 'balance' between LFE and non-LFE channels) with this mapping,
343 * i.e.\ if there are LFE and non-LFE channels available. \since 8.0 */
344int pa_channel_map_can_lfe_balance(const pa_channel_map *map) PA_GCC_PURE;
345
346/** Tries to find a well-known channel mapping name for this channel
347 * mapping, i.e.\ "stereo", "surround-71" and so on. If the channel
348 * mapping is unknown NULL will be returned. This name can be parsed
349 * with pa_channel_map_parse() \since 0.9.15 */
350const char* pa_channel_map_to_name(const pa_channel_map *map) PA_GCC_PURE;
351
352/** Tries to find a human readable text label for this channel
353mapping, i.e.\ "Stereo", "Surround 7.1" and so on. If the channel
354mapping is unknown NULL will be returned. \since 0.9.15 */
355const char* pa_channel_map_to_pretty_name(const pa_channel_map *map) PA_GCC_PURE;
356
357/** Returns non-zero if the specified channel position is available at
358 * least once in the channel map. \since 0.9.16 */
359int pa_channel_map_has_position(const pa_channel_map *map, pa_channel_position_t p) PA_GCC_PURE;
360
361/** Generates a bit mask from a channel map. \since 0.9.16 */
362pa_channel_position_mask_t pa_channel_map_mask(const pa_channel_map *map) PA_GCC_PURE;
363
364PA_C_DECL_END
365
366#endif
367