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