tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

channel_layout.h (32067B)


      1 /*
      2 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
      3 * Copyright (c) 2008 Peter Ross
      4 *
      5 * This file is part of FFmpeg.
      6 *
      7 * FFmpeg is free software; you can redistribute it and/or
      8 * modify it under the terms of the GNU Lesser General Public
      9 * License as published by the Free Software Foundation; either
     10 * version 2.1 of the License, or (at your option) any later version.
     11 *
     12 * FFmpeg is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15 * Lesser General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU Lesser General Public
     18 * License along with FFmpeg; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     20 */
     21 
     22 #ifndef AVUTIL_CHANNEL_LAYOUT_H
     23 #define AVUTIL_CHANNEL_LAYOUT_H
     24 
     25 #include <stdint.h>
     26 #include <stdlib.h>
     27 
     28 #include "version.h"
     29 #include "attributes.h"
     30 
     31 /**
     32 * @file
     33 * @ingroup lavu_audio_channels
     34 * Public libavutil channel layout APIs header.
     35 */
     36 
     37 /**
     38 * @defgroup lavu_audio_channels Audio channels
     39 * @ingroup lavu_audio
     40 *
     41 * Audio channel layout utility functions
     42 *
     43 * @{
     44 */
     45 
     46 enum AVChannel {
     47  ///< Invalid channel index
     48  AV_CHAN_NONE = -1,
     49  AV_CHAN_FRONT_LEFT,
     50  AV_CHAN_FRONT_RIGHT,
     51  AV_CHAN_FRONT_CENTER,
     52  AV_CHAN_LOW_FREQUENCY,
     53  AV_CHAN_BACK_LEFT,
     54  AV_CHAN_BACK_RIGHT,
     55  AV_CHAN_FRONT_LEFT_OF_CENTER,
     56  AV_CHAN_FRONT_RIGHT_OF_CENTER,
     57  AV_CHAN_BACK_CENTER,
     58  AV_CHAN_SIDE_LEFT,
     59  AV_CHAN_SIDE_RIGHT,
     60  AV_CHAN_TOP_CENTER,
     61  AV_CHAN_TOP_FRONT_LEFT,
     62  AV_CHAN_TOP_FRONT_CENTER,
     63  AV_CHAN_TOP_FRONT_RIGHT,
     64  AV_CHAN_TOP_BACK_LEFT,
     65  AV_CHAN_TOP_BACK_CENTER,
     66  AV_CHAN_TOP_BACK_RIGHT,
     67  /** Stereo downmix. */
     68  AV_CHAN_STEREO_LEFT = 29,
     69  /** See above. */
     70  AV_CHAN_STEREO_RIGHT,
     71  AV_CHAN_WIDE_LEFT,
     72  AV_CHAN_WIDE_RIGHT,
     73  AV_CHAN_SURROUND_DIRECT_LEFT,
     74  AV_CHAN_SURROUND_DIRECT_RIGHT,
     75  AV_CHAN_LOW_FREQUENCY_2,
     76  AV_CHAN_TOP_SIDE_LEFT,
     77  AV_CHAN_TOP_SIDE_RIGHT,
     78  AV_CHAN_BOTTOM_FRONT_CENTER,
     79  AV_CHAN_BOTTOM_FRONT_LEFT,
     80  AV_CHAN_BOTTOM_FRONT_RIGHT,
     81 
     82  /** Channel is empty can be safely skipped. */
     83  AV_CHAN_UNUSED = 0x200,
     84 
     85  /** Channel contains data, but its position is unknown. */
     86  AV_CHAN_UNKNOWN = 0x300,
     87 
     88  /**
     89   * Range of channels between AV_CHAN_AMBISONIC_BASE and
     90   * AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system.
     91   *
     92   * Given a channel id `<i>` between AV_CHAN_AMBISONIC_BASE and
     93   * AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel `<n>` is
     94   * `<n> = <i> - AV_CHAN_AMBISONIC_BASE`.
     95   *
     96   * @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel
     97   * orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels
     98   * implicitly by their position in the stream.
     99   */
    100  AV_CHAN_AMBISONIC_BASE = 0x400,
    101  // leave space for 1024 ids, which correspond to maximum order-32 harmonics,
    102  // which should be enough for the foreseeable use cases
    103  AV_CHAN_AMBISONIC_END = 0x7ff,
    104 };
    105 
    106 enum AVChannelOrder {
    107  /**
    108   * Only the channel count is specified, without any further information
    109   * about the channel order.
    110   */
    111  AV_CHANNEL_ORDER_UNSPEC,
    112  /**
    113   * The native channel order, i.e. the channels are in the same order in
    114   * which they are defined in the AVChannel enum. This supports up to 63
    115   * different channels.
    116   */
    117  AV_CHANNEL_ORDER_NATIVE,
    118  /**
    119   * The channel order does not correspond to any other predefined order and
    120   * is stored as an explicit map. For example, this could be used to support
    121   * layouts with 64 or more channels, or with empty/skipped (AV_CHAN_UNUSED)
    122   * channels at arbitrary positions.
    123   */
    124  AV_CHANNEL_ORDER_CUSTOM,
    125  /**
    126   * The audio is represented as the decomposition of the sound field into
    127   * spherical harmonics. Each channel corresponds to a single expansion
    128   * component. Channels are ordered according to ACN (Ambisonic Channel
    129   * Number).
    130   *
    131   * The channel with the index n in the stream contains the spherical
    132   * harmonic of degree l and order m given by
    133   * @code{.unparsed}
    134   *   l   = floor(sqrt(n)),
    135   *   m   = n - l * (l + 1).
    136   * @endcode
    137   *
    138   * Conversely given a spherical harmonic of degree l and order m, the
    139   * corresponding channel index n is given by
    140   * @code{.unparsed}
    141   *   n = l * (l + 1) + m.
    142   * @endcode
    143   *
    144   * Normalization is assumed to be SN3D (Schmidt Semi-Normalization)
    145   * as defined in AmbiX format $ 2.1.
    146   */
    147  AV_CHANNEL_ORDER_AMBISONIC,
    148  /**
    149   * Number of channel orders, not part of ABI/API
    150   */
    151  FF_CHANNEL_ORDER_NB
    152 };
    153 
    154 /**
    155 * @defgroup channel_masks Audio channel masks
    156 *
    157 * A channel layout is a 64-bits integer with a bit set for every channel.
    158 * The number of bits set must be equal to the number of channels.
    159 * The value 0 means that the channel layout is not known.
    160 * @note this data structure is not powerful enough to handle channels
    161 * combinations that have the same channel multiple times, such as
    162 * dual-mono.
    163 *
    164 * @{
    165 */
    166 #define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT)
    167 #define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT)
    168 #define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER)
    169 #define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY)
    170 #define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT)
    171 #define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT)
    172 #define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER)
    173 #define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER)
    174 #define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER)
    175 #define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT)
    176 #define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT)
    177 #define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER)
    178 #define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT)
    179 #define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER)
    180 #define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT)
    181 #define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT)
    182 #define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER)
    183 #define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT)
    184 #define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT)
    185 #define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT)
    186 #define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT)
    187 #define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT)
    188 #define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT)
    189 #define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT)
    190 #define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2)
    191 #define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT)
    192 #define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT)
    193 #define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER)
    194 #define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT)
    195 #define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT)
    196 
    197 /**
    198 * @}
    199 * @defgroup channel_mask_c Audio channel layouts
    200 * @{
    201 * */
    202 #define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER)
    203 #define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
    204 #define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY)
    205 #define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER)
    206 #define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER)
    207 #define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY)
    208 #define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND | AV_CH_BACK_CENTER)
    209 #define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY)
    210 #define AV_CH_LAYOUT_2_2 \
    211  (AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
    212 #define AV_CH_LAYOUT_QUAD \
    213  (AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
    214 #define AV_CH_LAYOUT_5POINT0 \
    215  (AV_CH_LAYOUT_SURROUND | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
    216 #define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0 | AV_CH_LOW_FREQUENCY)
    217 #define AV_CH_LAYOUT_5POINT0_BACK \
    218  (AV_CH_LAYOUT_SURROUND | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
    219 #define AV_CH_LAYOUT_5POINT1_BACK \
    220  (AV_CH_LAYOUT_5POINT0_BACK | AV_CH_LOW_FREQUENCY)
    221 #define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_CENTER)
    222 #define AV_CH_LAYOUT_6POINT0_FRONT \
    223  (AV_CH_LAYOUT_2_2 | AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
    224 #define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK | AV_CH_BACK_CENTER)
    225 #define AV_CH_LAYOUT_3POINT1POINT2 \
    226  (AV_CH_LAYOUT_3POINT1 | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT)
    227 #define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER)
    228 #define AV_CH_LAYOUT_6POINT1_BACK \
    229  (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_BACK_CENTER)
    230 #define AV_CH_LAYOUT_6POINT1_FRONT \
    231  (AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_LOW_FREQUENCY)
    232 #define AV_CH_LAYOUT_7POINT0 \
    233  (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
    234 #define AV_CH_LAYOUT_7POINT0_FRONT                     \
    235  (AV_CH_LAYOUT_5POINT0 | AV_CH_FRONT_LEFT_OF_CENTER | \
    236   AV_CH_FRONT_RIGHT_OF_CENTER)
    237 #define AV_CH_LAYOUT_7POINT1 \
    238  (AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
    239 #define AV_CH_LAYOUT_7POINT1_WIDE                      \
    240  (AV_CH_LAYOUT_5POINT1 | AV_CH_FRONT_LEFT_OF_CENTER | \
    241   AV_CH_FRONT_RIGHT_OF_CENTER)
    242 #define AV_CH_LAYOUT_7POINT1_WIDE_BACK                      \
    243  (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_FRONT_LEFT_OF_CENTER | \
    244   AV_CH_FRONT_RIGHT_OF_CENTER)
    245 #define AV_CH_LAYOUT_5POINT1POINT2_BACK \
    246  (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT)
    247 #define AV_CH_LAYOUT_OCTAGONAL                                  \
    248  (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT | AV_CH_BACK_CENTER | \
    249   AV_CH_BACK_RIGHT)
    250 #define AV_CH_LAYOUT_CUBE                                             \
    251  (AV_CH_LAYOUT_QUAD | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT | \
    252   AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT)
    253 #define AV_CH_LAYOUT_5POINT1POINT4_BACK \
    254  (AV_CH_LAYOUT_5POINT1POINT2_BACK | AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT)
    255 #define AV_CH_LAYOUT_7POINT1POINT2 \
    256  (AV_CH_LAYOUT_7POINT1 | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT)
    257 #define AV_CH_LAYOUT_7POINT1POINT4_BACK \
    258  (AV_CH_LAYOUT_7POINT1POINT2 | AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT)
    259 #define AV_CH_LAYOUT_7POINT2POINT3 \
    260  (AV_CH_LAYOUT_7POINT1POINT2 | AV_CH_TOP_BACK_CENTER | AV_CH_LOW_FREQUENCY_2)
    261 #define AV_CH_LAYOUT_9POINT1POINT4_BACK                           \
    262  (AV_CH_LAYOUT_7POINT1POINT4_BACK | AV_CH_FRONT_LEFT_OF_CENTER | \
    263   AV_CH_FRONT_RIGHT_OF_CENTER)
    264 #define AV_CH_LAYOUT_HEXADECAGONAL                                      \
    265  (AV_CH_LAYOUT_OCTAGONAL | AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT |        \
    266   AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT | AV_CH_TOP_BACK_CENTER | \
    267   AV_CH_TOP_FRONT_CENTER | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT)
    268 #define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
    269 #define AV_CH_LAYOUT_22POINT2                                                 \
    270  (AV_CH_LAYOUT_7POINT1POINT4_BACK | AV_CH_FRONT_LEFT_OF_CENTER |             \
    271   AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_BACK_CENTER | AV_CH_LOW_FREQUENCY_2 |  \
    272   AV_CH_TOP_FRONT_CENTER | AV_CH_TOP_CENTER | AV_CH_TOP_SIDE_LEFT |          \
    273   AV_CH_TOP_SIDE_RIGHT | AV_CH_TOP_BACK_CENTER | AV_CH_BOTTOM_FRONT_CENTER | \
    274   AV_CH_BOTTOM_FRONT_LEFT | AV_CH_BOTTOM_FRONT_RIGHT)
    275 
    276 #define AV_CH_LAYOUT_7POINT1_TOP_BACK AV_CH_LAYOUT_5POINT1POINT2_BACK
    277 
    278 enum AVMatrixEncoding {
    279  AV_MATRIX_ENCODING_NONE,
    280  AV_MATRIX_ENCODING_DOLBY,
    281  AV_MATRIX_ENCODING_DPLII,
    282  AV_MATRIX_ENCODING_DPLIIX,
    283  AV_MATRIX_ENCODING_DPLIIZ,
    284  AV_MATRIX_ENCODING_DOLBYEX,
    285  AV_MATRIX_ENCODING_DOLBYHEADPHONE,
    286  AV_MATRIX_ENCODING_NB
    287 };
    288 
    289 /**
    290 * @}
    291 */
    292 
    293 /**
    294 * An AVChannelCustom defines a single channel within a custom order layout
    295 *
    296 * Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the
    297 * public ABI.
    298 *
    299 * No new fields may be added to it without a major version bump.
    300 */
    301 typedef struct AVChannelCustom {
    302  enum AVChannel id;
    303  char name[16];
    304  void* opaque;
    305 } AVChannelCustom;
    306 
    307 /**
    308 * An AVChannelLayout holds information about the channel layout of audio data.
    309 *
    310 * A channel layout here is defined as a set of channels ordered in a specific
    311 * way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an
    312 * AVChannelLayout carries only the channel count).
    313 * All orders may be treated as if they were AV_CHANNEL_ORDER_UNSPEC by
    314 * ignoring everything but the channel count, as long as
    315 * av_channel_layout_check() considers they are valid.
    316 *
    317 * Unlike most structures in FFmpeg, sizeof(AVChannelLayout) is a part of the
    318 * public ABI and may be used by the caller. E.g. it may be allocated on stack
    319 * or embedded in caller-defined structs.
    320 *
    321 * AVChannelLayout can be initialized as follows:
    322 * - default initialization with {0}, followed by setting all used fields
    323 *   correctly;
    324 * - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers;
    325 * - with a constructor function, such as av_channel_layout_default(),
    326 *   av_channel_layout_from_mask() or av_channel_layout_from_string().
    327 *
    328 * The channel layout must be unitialized with av_channel_layout_uninit()
    329 *
    330 * Copying an AVChannelLayout via assigning is forbidden,
    331 * av_channel_layout_copy() must be used instead (and its return value should
    332 * be checked)
    333 *
    334 * No new fields may be added to it without a major version bump, except for
    335 * new elements of the union fitting in sizeof(uint64_t).
    336 */
    337 typedef struct AVChannelLayout {
    338  /**
    339   * Channel order used in this layout.
    340   * This is a mandatory field.
    341   */
    342  enum AVChannelOrder order;
    343 
    344  /**
    345   * Number of channels in this layout. Mandatory field.
    346   */
    347  int nb_channels;
    348 
    349  /**
    350   * Details about which channels are present in this layout.
    351   * For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be
    352   * used.
    353   */
    354  union {
    355    /**
    356     * This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used
    357     * for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels.
    358     * It is a bitmask, where the position of each set bit means that the
    359     * AVChannel with the corresponding value is present.
    360     *
    361     * I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO
    362     * is present in the layout. Otherwise it is not present.
    363     *
    364     * @note when a channel layout using a bitmask is constructed or
    365     * modified manually (i.e.  not using any of the av_channel_layout_*
    366     * functions), the code doing it must ensure that the number of set bits
    367     * is equal to nb_channels.
    368     */
    369    uint64_t mask;
    370    /**
    371     * This member must be used when the channel order is
    372     * AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each
    373     * element signalling the presence of the AVChannel with the
    374     * corresponding value in map[i].id.
    375     *
    376     * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the
    377     * i-th channel in the audio data.
    378     *
    379     * When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and
    380     * AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic
    381     * component with ACN index (as defined above)
    382     * n = map[i].id - AV_CHAN_AMBISONIC_BASE.
    383     *
    384     * map[i].name may be filled with a 0-terminated string, in which case
    385     * it will be used for the purpose of identifying the channel with the
    386     * convenience functions below. Otherise it must be zeroed.
    387     */
    388    AVChannelCustom* map;
    389  } u;
    390 
    391  /**
    392   * For some private data of the user.
    393   */
    394  void* opaque;
    395 } AVChannelLayout;
    396 
    397 /**
    398 * Macro to define native channel layouts
    399 *
    400 * @note This doesn't use designated initializers for compatibility with C++ 17
    401 * and older.
    402 */
    403 #define AV_CHANNEL_LAYOUT_MASK(nb, m)                                    \
    404  { /* .order */                                                         \
    405    AV_CHANNEL_ORDER_NATIVE, /* .nb_channels */ (nb), /* .u.mask */ {m}, \
    406        /* .opaque */ NULL                                               \
    407  }
    408 
    409 /**
    410 * @name Common pre-defined channel layouts
    411 * @{
    412 */
    413 #define AV_CHANNEL_LAYOUT_MONO AV_CHANNEL_LAYOUT_MASK(1, AV_CH_LAYOUT_MONO)
    414 #define AV_CHANNEL_LAYOUT_STEREO AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO)
    415 #define AV_CHANNEL_LAYOUT_2POINT1 \
    416  AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2POINT1)
    417 #define AV_CHANNEL_LAYOUT_2_1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2_1)
    418 #define AV_CHANNEL_LAYOUT_SURROUND \
    419  AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_SURROUND)
    420 #define AV_CHANNEL_LAYOUT_3POINT1 \
    421  AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_3POINT1)
    422 #define AV_CHANNEL_LAYOUT_4POINT0 \
    423  AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_4POINT0)
    424 #define AV_CHANNEL_LAYOUT_4POINT1 \
    425  AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_4POINT1)
    426 #define AV_CHANNEL_LAYOUT_2_2 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_2_2)
    427 #define AV_CHANNEL_LAYOUT_QUAD AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_QUAD)
    428 #define AV_CHANNEL_LAYOUT_5POINT0 \
    429  AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0)
    430 #define AV_CHANNEL_LAYOUT_5POINT1 \
    431  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1)
    432 #define AV_CHANNEL_LAYOUT_5POINT0_BACK \
    433  AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0_BACK)
    434 #define AV_CHANNEL_LAYOUT_5POINT1_BACK \
    435  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1_BACK)
    436 #define AV_CHANNEL_LAYOUT_6POINT0 \
    437  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0)
    438 #define AV_CHANNEL_LAYOUT_6POINT0_FRONT \
    439  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0_FRONT)
    440 #define AV_CHANNEL_LAYOUT_3POINT1POINT2 \
    441  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_3POINT1POINT2)
    442 #define AV_CHANNEL_LAYOUT_HEXAGONAL \
    443  AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_HEXAGONAL)
    444 #define AV_CHANNEL_LAYOUT_6POINT1 \
    445  AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1)
    446 #define AV_CHANNEL_LAYOUT_6POINT1_BACK \
    447  AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_BACK)
    448 #define AV_CHANNEL_LAYOUT_6POINT1_FRONT \
    449  AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_FRONT)
    450 #define AV_CHANNEL_LAYOUT_7POINT0 \
    451  AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0)
    452 #define AV_CHANNEL_LAYOUT_7POINT0_FRONT \
    453  AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0_FRONT)
    454 #define AV_CHANNEL_LAYOUT_7POINT1 \
    455  AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1)
    456 #define AV_CHANNEL_LAYOUT_7POINT1_WIDE \
    457  AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE)
    458 #define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK \
    459  AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE_BACK)
    460 #define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK \
    461  AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_5POINT1POINT2_BACK)
    462 #define AV_CHANNEL_LAYOUT_OCTAGONAL \
    463  AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_OCTAGONAL)
    464 #define AV_CHANNEL_LAYOUT_CUBE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_CUBE)
    465 #define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK \
    466  AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_5POINT1POINT4_BACK)
    467 #define AV_CHANNEL_LAYOUT_7POINT1POINT2 \
    468  AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_7POINT1POINT2)
    469 #define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK \
    470  AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT1POINT4_BACK)
    471 #define AV_CHANNEL_LAYOUT_7POINT2POINT3 \
    472  AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT2POINT3)
    473 #define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK \
    474  AV_CHANNEL_LAYOUT_MASK(14, AV_CH_LAYOUT_9POINT1POINT4_BACK)
    475 #define AV_CHANNEL_LAYOUT_HEXADECAGONAL \
    476  AV_CHANNEL_LAYOUT_MASK(16, AV_CH_LAYOUT_HEXADECAGONAL)
    477 #define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX \
    478  AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO_DOWNMIX)
    479 #define AV_CHANNEL_LAYOUT_22POINT2 \
    480  AV_CHANNEL_LAYOUT_MASK(24, AV_CH_LAYOUT_22POINT2)
    481 
    482 #define AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
    483 
    484 #define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER                          \
    485  { /* .order */                                                         \
    486    AV_CHANNEL_ORDER_AMBISONIC, /* .nb_channels */ 4, /* .u.mask */ {0}, \
    487        /* .opaque */ NULL                                               \
    488  }
    489 /** @} */
    490 
    491 struct AVBPrint;
    492 
    493 /**
    494 * Get a human readable string in an abbreviated form describing a given
    495 * channel. This is the inverse function of @ref av_channel_from_string().
    496 *
    497 * @param buf pre-allocated buffer where to put the generated string
    498 * @param buf_size size in bytes of the buffer.
    499 * @param channel the AVChannel whose name to get
    500 * @return amount of bytes needed to hold the output string, or a negative
    501 * AVERROR on failure. If the returned value is bigger than buf_size, then the
    502 *         string was truncated.
    503 */
    504 int av_channel_name(char* buf, size_t buf_size, enum AVChannel channel);
    505 
    506 /**
    507 * bprint variant of av_channel_name().
    508 *
    509 * @note the string will be appended to the bprint buffer.
    510 */
    511 void av_channel_name_bprint(struct AVBPrint* bp, enum AVChannel channel_id);
    512 
    513 /**
    514 * Get a human readable string describing a given channel.
    515 *
    516 * @param buf pre-allocated buffer where to put the generated string
    517 * @param buf_size size in bytes of the buffer.
    518 * @param channel the AVChannel whose description to get
    519 * @return amount of bytes needed to hold the output string, or a negative
    520 * AVERROR on failure. If the returned value is bigger than buf_size, then the
    521 *         string was truncated.
    522 */
    523 int av_channel_description(char* buf, size_t buf_size, enum AVChannel channel);
    524 
    525 /**
    526 * bprint variant of av_channel_description().
    527 *
    528 * @note the string will be appended to the bprint buffer.
    529 */
    530 void av_channel_description_bprint(struct AVBPrint* bp,
    531                                   enum AVChannel channel_id);
    532 
    533 /**
    534 * This is the inverse function of @ref av_channel_name().
    535 *
    536 * @return the channel with the given name
    537 *         AV_CHAN_NONE when name does not identify a known channel
    538 */
    539 enum AVChannel av_channel_from_string(const char* name);
    540 
    541 /**
    542 * Initialize a custom channel layout with the specified number of channels.
    543 * The channel map will be allocated and the designation of all channels will
    544 * be set to AV_CHAN_UNKNOWN.
    545 *
    546 * This is only a convenience helper function, a custom channel layout can also
    547 * be constructed without using this.
    548 *
    549 * @param channel_layout the layout structure to be initialized
    550 * @param nb_channels the number of channels
    551 *
    552 * @return 0 on success
    553 *         AVERROR(EINVAL) if the number of channels <= 0
    554 *         AVERROR(ENOMEM) if the channel map could not be allocated
    555 */
    556 int av_channel_layout_custom_init(AVChannelLayout* channel_layout,
    557                                  int nb_channels);
    558 
    559 /**
    560 * Initialize a native channel layout from a bitmask indicating which channels
    561 * are present.
    562 *
    563 * @param channel_layout the layout structure to be initialized
    564 * @param mask bitmask describing the channel layout
    565 *
    566 * @return 0 on success
    567 *         AVERROR(EINVAL) for invalid mask values
    568 */
    569 int av_channel_layout_from_mask(AVChannelLayout* channel_layout, uint64_t mask);
    570 
    571 /**
    572 * Initialize a channel layout from a given string description.
    573 * The input string can be represented by:
    574 *  - the formal channel layout name (returned by av_channel_layout_describe())
    575 *  - single or multiple channel names (returned by av_channel_name(), eg. "FL",
    576 *    or concatenated with "+", each optionally containing a custom name after
    577 *    a "@", eg. "FL@Left+FR@Right+LFE")
    578 *  - a decimal or hexadecimal value of a native channel layout (eg. "4" or
    579 * "0x4")
    580 *  - the number of channels with default layout (eg. "4c")
    581 *  - the number of unordered channels (eg. "4C" or "4 channels")
    582 *  - the ambisonic order followed by optional non-diegetic channels (eg.
    583 *    "ambisonic 2+stereo")
    584 * On error, the channel layout will remain uninitialized, but not necessarily
    585 * untouched.
    586 *
    587 * @param channel_layout uninitialized channel layout for the result
    588 * @param str string describing the channel layout
    589 * @return 0 on success parsing the channel layout
    590 *         AVERROR(EINVAL) if an invalid channel layout string was provided
    591 *         AVERROR(ENOMEM) if there was not enough memory
    592 */
    593 int av_channel_layout_from_string(AVChannelLayout* channel_layout,
    594                                  const char* str);
    595 
    596 /**
    597 * Get the default channel layout for a given number of channels.
    598 *
    599 * @param ch_layout the layout structure to be initialized
    600 * @param nb_channels number of channels
    601 */
    602 void av_channel_layout_default(AVChannelLayout* ch_layout, int nb_channels);
    603 
    604 /**
    605 * Iterate over all standard channel layouts.
    606 *
    607 * @param opaque a pointer where libavutil will store the iteration state. Must
    608 *               point to NULL to start the iteration.
    609 *
    610 * @return the standard channel layout or NULL when the iteration is
    611 *         finished
    612 */
    613 const AVChannelLayout* av_channel_layout_standard(void** opaque);
    614 
    615 /**
    616 * Free any allocated data in the channel layout and reset the channel
    617 * count to 0.
    618 *
    619 * @param channel_layout the layout structure to be uninitialized
    620 */
    621 void av_channel_layout_uninit(AVChannelLayout* channel_layout);
    622 
    623 /**
    624 * Make a copy of a channel layout. This differs from just assigning src to dst
    625 * in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM.
    626 *
    627 * @note the destination channel_layout will be always uninitialized before
    628 * copy.
    629 *
    630 * @param dst destination channel layout
    631 * @param src source channel layout
    632 * @return 0 on success, a negative AVERROR on error.
    633 */
    634 int av_channel_layout_copy(AVChannelLayout* dst, const AVChannelLayout* src);
    635 
    636 /**
    637 * Get a human-readable string describing the channel layout properties.
    638 * The string will be in the same format that is accepted by
    639 * @ref av_channel_layout_from_string(), allowing to rebuild the same
    640 * channel layout, except for opaque pointers.
    641 *
    642 * @param channel_layout channel layout to be described
    643 * @param buf pre-allocated buffer where to put the generated string
    644 * @param buf_size size in bytes of the buffer.
    645 * @return amount of bytes needed to hold the output string, or a negative
    646 * AVERROR on failure. If the returned value is bigger than buf_size, then the
    647 *         string was truncated.
    648 */
    649 int av_channel_layout_describe(const AVChannelLayout* channel_layout, char* buf,
    650                               size_t buf_size);
    651 
    652 /**
    653 * bprint variant of av_channel_layout_describe().
    654 *
    655 * @note the string will be appended to the bprint buffer.
    656 * @return 0 on success, or a negative AVERROR value on failure.
    657 */
    658 int av_channel_layout_describe_bprint(const AVChannelLayout* channel_layout,
    659                                      struct AVBPrint* bp);
    660 
    661 /**
    662 * Get the channel with the given index in a channel layout.
    663 *
    664 * @param channel_layout input channel layout
    665 * @param idx index of the channel
    666 * @return channel with the index idx in channel_layout on success or
    667 *         AV_CHAN_NONE on failure (if idx is not valid or the channel order is
    668 *         unspecified)
    669 */
    670 enum AVChannel av_channel_layout_channel_from_index(
    671    const AVChannelLayout* channel_layout, unsigned int idx);
    672 
    673 /**
    674 * Get the index of a given channel in a channel layout. In case multiple
    675 * channels are found, only the first match will be returned.
    676 *
    677 * @param channel_layout input channel layout
    678 * @param channel the channel whose index to obtain
    679 * @return index of channel in channel_layout on success or a negative number if
    680 *         channel is not present in channel_layout.
    681 */
    682 int av_channel_layout_index_from_channel(const AVChannelLayout* channel_layout,
    683                                         enum AVChannel channel);
    684 
    685 /**
    686 * Get the index in a channel layout of a channel described by the given string.
    687 * In case multiple channels are found, only the first match will be returned.
    688 *
    689 * This function accepts channel names in the same format as
    690 * @ref av_channel_from_string().
    691 *
    692 * @param channel_layout input channel layout
    693 * @param name string describing the channel whose index to obtain
    694 * @return a channel index described by the given string, or a negative AVERROR
    695 *         value.
    696 */
    697 int av_channel_layout_index_from_string(const AVChannelLayout* channel_layout,
    698                                        const char* name);
    699 
    700 /**
    701 * Get a channel described by the given string.
    702 *
    703 * This function accepts channel names in the same format as
    704 * @ref av_channel_from_string().
    705 *
    706 * @param channel_layout input channel layout
    707 * @param name string describing the channel to obtain
    708 * @return a channel described by the given string in channel_layout on success
    709 *         or AV_CHAN_NONE on failure (if the string is not valid or the channel
    710 *         order is unspecified)
    711 */
    712 enum AVChannel av_channel_layout_channel_from_string(
    713    const AVChannelLayout* channel_layout, const char* name);
    714 
    715 /**
    716 * Find out what channels from a given set are present in a channel layout,
    717 * without regard for their positions.
    718 *
    719 * @param channel_layout input channel layout
    720 * @param mask a combination of AV_CH_* representing a set of channels
    721 * @return a bitfield representing all the channels from mask that are present
    722 *         in channel_layout
    723 */
    724 uint64_t av_channel_layout_subset(const AVChannelLayout* channel_layout,
    725                                  uint64_t mask);
    726 
    727 /**
    728 * Check whether a channel layout is valid, i.e. can possibly describe audio
    729 * data.
    730 *
    731 * @param channel_layout input channel layout
    732 * @return 1 if channel_layout is valid, 0 otherwise.
    733 */
    734 int av_channel_layout_check(const AVChannelLayout* channel_layout);
    735 
    736 /**
    737 * Check whether two channel layouts are semantically the same, i.e. the same
    738 * channels are present on the same positions in both.
    739 *
    740 * If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is
    741 * not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC,
    742 * they are considered equal iff the channel counts are the same in both.
    743 *
    744 * @param chl input channel layout
    745 * @param chl1 input channel layout
    746 * @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative
    747 *         AVERROR code if one or both are invalid.
    748 */
    749 int av_channel_layout_compare(const AVChannelLayout* chl,
    750                              const AVChannelLayout* chl1);
    751 
    752 /**
    753 * The conversion must be lossless.
    754 */
    755 #define AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS (1 << 0)
    756 
    757 /**
    758 * The specified retype target order is ignored and the simplest possible
    759 * (canonical) order is used for which the input layout can be losslessy
    760 * represented.
    761 */
    762 #define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL (1 << 1)
    763 
    764 /**
    765 * Change the AVChannelOrder of a channel layout.
    766 *
    767 * Change of AVChannelOrder can be either lossless or lossy. In case of a
    768 * lossless conversion all the channel designations and the associated channel
    769 * names (if any) are kept. On a lossy conversion the channel names and channel
    770 * designations might be lost depending on the capabilities of the desired
    771 * AVChannelOrder. Note that some conversions are simply not possible in which
    772 * case this function returns AVERROR(ENOSYS).
    773 *
    774 * The following conversions are supported:
    775 *
    776 * Any       -> Custom     : Always possible, always lossless.
    777 * Any       -> Unspecified: Always possible, lossless if channel designations
    778 *   are all unknown and channel names are not used, lossy otherwise.
    779 * Custom    -> Ambisonic  : Possible if it contains ambisonic channels with
    780 *   optional non-diegetic channels in the end. Lossy if the channels have
    781 *   custom names, lossless otherwise.
    782 * Custom    -> Native     : Possible if it contains native channels in native
    783 *     order. Lossy if the channels have custom names, lossless otherwise.
    784 *
    785 * On error this function keeps the original channel layout untouched.
    786 *
    787 * @param channel_layout channel layout which will be changed
    788 * @param order the desired channel layout order
    789 * @param flags a combination of AV_CHANNEL_LAYOUT_RETYPE_FLAG_* constants
    790 * @return 0 if the conversion was successful and lossless or if the channel
    791 *           layout was already in the desired order
    792 *         >0 if the conversion was successful but lossy
    793 *         AVERROR(ENOSYS) if the conversion was not possible (or would be
    794 *           lossy and AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS was specified)
    795 *         AVERROR(EINVAL), AVERROR(ENOMEM) on error
    796 */
    797 int av_channel_layout_retype(AVChannelLayout* channel_layout,
    798                             enum AVChannelOrder order, int flags);
    799 
    800 /**
    801 * @}
    802 */
    803 
    804 #endif /* AVUTIL_CHANNEL_LAYOUT_H */