Path: blob/master/dep/ffmpeg/include/libavutil/channel_layout.h
7513 views
/*1* Copyright (c) 2006 Michael Niedermayer <[email protected]>2* Copyright (c) 2008 Peter Ross3*4* This file is part of FFmpeg.5*6* FFmpeg is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public8* License as published by the Free Software Foundation; either9* version 2.1 of the License, or (at your option) any later version.10*11* FFmpeg is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with FFmpeg; if not, write to the Free Software18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19*/2021#ifndef AVUTIL_CHANNEL_LAYOUT_H22#define AVUTIL_CHANNEL_LAYOUT_H2324#include <stdint.h>25#include <stdlib.h>2627#include "version.h"28#include "attributes.h"2930/**31* @file32* @ingroup lavu_audio_channels33* Public libavutil channel layout APIs header.34*/353637/**38* @defgroup lavu_audio_channels Audio channels39* @ingroup lavu_audio40*41* Audio channel layout utility functions42*43* @{44*/4546enum AVChannel {47/// Invalid channel index48AV_CHAN_NONE = -1,49AV_CHAN_FRONT_LEFT,50AV_CHAN_FRONT_RIGHT,51AV_CHAN_FRONT_CENTER,52AV_CHAN_LOW_FREQUENCY,53AV_CHAN_BACK_LEFT,54AV_CHAN_BACK_RIGHT,55AV_CHAN_FRONT_LEFT_OF_CENTER,56AV_CHAN_FRONT_RIGHT_OF_CENTER,57AV_CHAN_BACK_CENTER,58AV_CHAN_SIDE_LEFT,59AV_CHAN_SIDE_RIGHT,60AV_CHAN_TOP_CENTER,61AV_CHAN_TOP_FRONT_LEFT,62AV_CHAN_TOP_FRONT_CENTER,63AV_CHAN_TOP_FRONT_RIGHT,64AV_CHAN_TOP_BACK_LEFT,65AV_CHAN_TOP_BACK_CENTER,66AV_CHAN_TOP_BACK_RIGHT,67/** Stereo downmix. */68AV_CHAN_STEREO_LEFT = 29,69/** See above. */70AV_CHAN_STEREO_RIGHT,71AV_CHAN_WIDE_LEFT,72AV_CHAN_WIDE_RIGHT,73AV_CHAN_SURROUND_DIRECT_LEFT,74AV_CHAN_SURROUND_DIRECT_RIGHT,75AV_CHAN_LOW_FREQUENCY_2,76AV_CHAN_TOP_SIDE_LEFT,77AV_CHAN_TOP_SIDE_RIGHT,78AV_CHAN_BOTTOM_FRONT_CENTER,79AV_CHAN_BOTTOM_FRONT_LEFT,80AV_CHAN_BOTTOM_FRONT_RIGHT,81AV_CHAN_SIDE_SURROUND_LEFT, ///< +90 degrees, Lss, SiL82AV_CHAN_SIDE_SURROUND_RIGHT, ///< -90 degrees, Rss, SiR83AV_CHAN_TOP_SURROUND_LEFT, ///< +110 degrees, Lvs, TpLS84AV_CHAN_TOP_SURROUND_RIGHT, ///< -110 degrees, Rvs, TpRS8586AV_CHAN_BINAURAL_LEFT = 61,87AV_CHAN_BINAURAL_RIGHT,8889/** Channel is empty can be safely skipped. */90AV_CHAN_UNUSED = 0x200,9192/** Channel contains data, but its position is unknown. */93AV_CHAN_UNKNOWN = 0x300,9495/**96* Range of channels between AV_CHAN_AMBISONIC_BASE and97* AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system.98*99* Given a channel id `<i>` between AV_CHAN_AMBISONIC_BASE and100* AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel `<n>` is101* `<n> = <i> - AV_CHAN_AMBISONIC_BASE`.102*103* @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel104* orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels105* implicitly by their position in the stream.106*/107AV_CHAN_AMBISONIC_BASE = 0x400,108// leave space for 1024 ids, which correspond to maximum order-32 harmonics,109// which should be enough for the foreseeable use cases110AV_CHAN_AMBISONIC_END = 0x7ff,111};112113enum AVChannelOrder {114/**115* Only the channel count is specified, without any further information116* about the channel order.117*/118AV_CHANNEL_ORDER_UNSPEC,119/**120* The native channel order, i.e. the channels are in the same order in121* which they are defined in the AVChannel enum. This supports up to 63122* different channels.123*/124AV_CHANNEL_ORDER_NATIVE,125/**126* The channel order does not correspond to any other predefined order and127* is stored as an explicit map. For example, this could be used to support128* layouts with 64 or more channels, or with empty/skipped (AV_CHAN_UNUSED)129* channels at arbitrary positions.130*/131AV_CHANNEL_ORDER_CUSTOM,132/**133* The audio is represented as the decomposition of the sound field into134* spherical harmonics. Each channel corresponds to a single expansion135* component. Channels are ordered according to ACN (Ambisonic Channel136* Number).137*138* The channel with the index n in the stream contains the spherical139* harmonic of degree l and order m given by140* @code{.unparsed}141* l = floor(sqrt(n)),142* m = n - l * (l + 1).143* @endcode144*145* Conversely given a spherical harmonic of degree l and order m, the146* corresponding channel index n is given by147* @code{.unparsed}148* n = l * (l + 1) + m.149* @endcode150*151* Normalization is assumed to be SN3D (Schmidt Semi-Normalization)152* as defined in AmbiX format $ 2.1.153*/154AV_CHANNEL_ORDER_AMBISONIC,155/**156* Number of channel orders, not part of ABI/API157*/158FF_CHANNEL_ORDER_NB159};160161162/**163* @defgroup channel_masks Audio channel masks164*165* A channel layout is a 64-bits integer with a bit set for every channel.166* The number of bits set must be equal to the number of channels.167* The value 0 means that the channel layout is not known.168* @note this data structure is not powerful enough to handle channels169* combinations that have the same channel multiple times, such as170* dual-mono.171*172* @{173*/174#define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT )175#define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT )176#define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER )177#define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY )178#define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT )179#define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT )180#define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER )181#define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER)182#define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER )183#define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT )184#define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT )185#define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER )186#define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT )187#define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER )188#define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT )189#define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT )190#define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER )191#define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT )192#define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT )193#define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT )194#define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT )195#define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT )196#define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT )197#define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT)198#define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2 )199#define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT )200#define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT )201#define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER )202#define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT )203#define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT )204#define AV_CH_SIDE_SURROUND_LEFT (1ULL << AV_CHAN_SIDE_SURROUND_LEFT )205#define AV_CH_SIDE_SURROUND_RIGHT (1ULL << AV_CHAN_SIDE_SURROUND_RIGHT )206#define AV_CH_TOP_SURROUND_LEFT (1ULL << AV_CHAN_TOP_SURROUND_LEFT )207#define AV_CH_TOP_SURROUND_RIGHT (1ULL << AV_CHAN_TOP_SURROUND_RIGHT )208#define AV_CH_BINAURAL_LEFT (1ULL << AV_CHAN_BINAURAL_LEFT )209#define AV_CH_BINAURAL_RIGHT (1ULL << AV_CHAN_BINAURAL_RIGHT )210211/**212* @}213* @defgroup channel_mask_c Audio channel layouts214* @{215* */216#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER)217#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT)218#define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY)219#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER)220#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER)221#define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY)222#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER)223#define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY)224#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)225#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)226#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)227#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY)228#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)229#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY)230#define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER)231#define AV_CH_LAYOUT_6POINT0_FRONT (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)232#define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER)233#define AV_CH_LAYOUT_3POINT1POINT2 (AV_CH_LAYOUT_3POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)234#define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER)235#define AV_CH_LAYOUT_6POINT1_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER)236#define AV_CH_LAYOUT_6POINT1_FRONT (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY)237#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)238#define AV_CH_LAYOUT_7POINT0_FRONT (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)239#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)240#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)241#define AV_CH_LAYOUT_7POINT1_WIDE_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)242#define AV_CH_LAYOUT_5POINT1POINT2 (AV_CH_LAYOUT_5POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)243#define AV_CH_LAYOUT_5POINT1POINT2_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)244#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)245#define AV_CH_LAYOUT_CUBE (AV_CH_LAYOUT_QUAD|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)246#define AV_CH_LAYOUT_5POINT1POINT4_BACK (AV_CH_LAYOUT_5POINT1POINT2|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)247#define AV_CH_LAYOUT_7POINT1POINT2 (AV_CH_LAYOUT_7POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)248#define AV_CH_LAYOUT_7POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)249#define AV_CH_LAYOUT_7POINT2POINT3 (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_CENTER|AV_CH_LOW_FREQUENCY_2)250#define AV_CH_LAYOUT_9POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)251#define AV_CH_LAYOUT_9POINT1POINT6 (AV_CH_LAYOUT_9POINT1POINT4_BACK|AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT)252#define AV_CH_LAYOUT_HEXADECAGONAL (AV_CH_LAYOUT_OCTAGONAL|AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT|AV_CH_TOP_BACK_CENTER|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)253#define AV_CH_LAYOUT_BINAURAL (AV_CH_BINAURAL_LEFT|AV_CH_BINAURAL_RIGHT)254#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)255#define AV_CH_LAYOUT_22POINT2 (AV_CH_LAYOUT_9POINT1POINT6|AV_CH_BACK_CENTER|AV_CH_LOW_FREQUENCY_2|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_CENTER|AV_CH_TOP_BACK_CENTER|AV_CH_BOTTOM_FRONT_CENTER|AV_CH_BOTTOM_FRONT_LEFT|AV_CH_BOTTOM_FRONT_RIGHT)256257#define AV_CH_LAYOUT_7POINT1_TOP_BACK AV_CH_LAYOUT_5POINT1POINT2_BACK258259enum AVMatrixEncoding {260AV_MATRIX_ENCODING_NONE,261AV_MATRIX_ENCODING_DOLBY,262AV_MATRIX_ENCODING_DPLII,263AV_MATRIX_ENCODING_DPLIIX,264AV_MATRIX_ENCODING_DPLIIZ,265AV_MATRIX_ENCODING_DOLBYEX,266AV_MATRIX_ENCODING_DOLBYHEADPHONE,267AV_MATRIX_ENCODING_NB268};269270/**271* @}272*/273274/**275* An AVChannelCustom defines a single channel within a custom order layout276*277* Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the278* public ABI.279*280* No new fields may be added to it without a major version bump.281*/282typedef struct AVChannelCustom {283enum AVChannel id;284char name[16];285void *opaque;286} AVChannelCustom;287288/**289* An AVChannelLayout holds information about the channel layout of audio data.290*291* A channel layout here is defined as a set of channels ordered in a specific292* way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an293* AVChannelLayout carries only the channel count).294* All orders may be treated as if they were AV_CHANNEL_ORDER_UNSPEC by295* ignoring everything but the channel count, as long as av_channel_layout_check()296* considers they are valid.297*298* Unlike most structures in FFmpeg, sizeof(AVChannelLayout) is a part of the299* public ABI and may be used by the caller. E.g. it may be allocated on stack300* or embedded in caller-defined structs.301*302* AVChannelLayout can be initialized as follows:303* - default initialization with {0}, followed by setting all used fields304* correctly;305* - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers;306* - with a constructor function, such as av_channel_layout_default(),307* av_channel_layout_from_mask() or av_channel_layout_from_string().308*309* The channel layout must be uninitialized with av_channel_layout_uninit()310*311* Copying an AVChannelLayout via assigning is forbidden,312* av_channel_layout_copy() must be used instead (and its return value should313* be checked)314*315* No new fields may be added to it without a major version bump, except for316* new elements of the union fitting in sizeof(uint64_t).317*/318typedef struct AVChannelLayout {319/**320* Channel order used in this layout.321* This is a mandatory field.322*/323enum AVChannelOrder order;324325/**326* Number of channels in this layout. Mandatory field.327*/328int nb_channels;329330/**331* Details about which channels are present in this layout.332* For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be333* used.334*/335union {336/**337* This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used338* for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels.339* It is a bitmask, where the position of each set bit means that the340* AVChannel with the corresponding value is present.341*342* I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO343* is present in the layout. Otherwise it is not present.344*345* @note when a channel layout using a bitmask is constructed or346* modified manually (i.e. not using any of the av_channel_layout_*347* functions), the code doing it must ensure that the number of set bits348* is equal to nb_channels.349*/350uint64_t mask;351/**352* This member must be used when the channel order is353* AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each354* element signalling the presence of the AVChannel with the355* corresponding value in map[i].id.356*357* I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the358* i-th channel in the audio data.359*360* When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and361* AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic362* component with ACN index (as defined above)363* n = map[i].id - AV_CHAN_AMBISONIC_BASE.364*365* map[i].name may be filled with a 0-terminated string, in which case366* it will be used for the purpose of identifying the channel with the367* convenience functions below. Otherwise it must be zeroed.368*/369AVChannelCustom *map;370} u;371372/**373* For some private data of the user.374*/375void *opaque;376} AVChannelLayout;377378/**379* Macro to define native channel layouts380*381* @note This doesn't use designated initializers for compatibility with C++ 17 and older.382*/383#define AV_CHANNEL_LAYOUT_MASK(nb, m) \384{ /* .order */ AV_CHANNEL_ORDER_NATIVE, \385/* .nb_channels */ (nb), \386/* .u.mask */ { m }, \387/* .opaque */ NULL }388389/**390* @name Common pre-defined channel layouts391* @{392*/393#define AV_CHANNEL_LAYOUT_MONO AV_CHANNEL_LAYOUT_MASK(1, AV_CH_LAYOUT_MONO)394#define AV_CHANNEL_LAYOUT_STEREO AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO)395#define AV_CHANNEL_LAYOUT_2POINT1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2POINT1)396#define AV_CHANNEL_LAYOUT_2_1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2_1)397#define AV_CHANNEL_LAYOUT_SURROUND AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_SURROUND)398#define AV_CHANNEL_LAYOUT_3POINT1 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_3POINT1)399#define AV_CHANNEL_LAYOUT_4POINT0 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_4POINT0)400#define AV_CHANNEL_LAYOUT_4POINT1 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_4POINT1)401#define AV_CHANNEL_LAYOUT_2_2 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_2_2)402#define AV_CHANNEL_LAYOUT_QUAD AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_QUAD)403#define AV_CHANNEL_LAYOUT_5POINT0 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0)404#define AV_CHANNEL_LAYOUT_5POINT1 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1)405#define AV_CHANNEL_LAYOUT_5POINT0_BACK AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0_BACK)406#define AV_CHANNEL_LAYOUT_5POINT1_BACK AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1_BACK)407#define AV_CHANNEL_LAYOUT_6POINT0 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0)408#define AV_CHANNEL_LAYOUT_6POINT0_FRONT AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0_FRONT)409#define AV_CHANNEL_LAYOUT_3POINT1POINT2 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_3POINT1POINT2)410#define AV_CHANNEL_LAYOUT_HEXAGONAL AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_HEXAGONAL)411#define AV_CHANNEL_LAYOUT_6POINT1 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1)412#define AV_CHANNEL_LAYOUT_6POINT1_BACK AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_BACK)413#define AV_CHANNEL_LAYOUT_6POINT1_FRONT AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_FRONT)414#define AV_CHANNEL_LAYOUT_7POINT0 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0)415#define AV_CHANNEL_LAYOUT_7POINT0_FRONT AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0_FRONT)416#define AV_CHANNEL_LAYOUT_7POINT1 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1)417#define AV_CHANNEL_LAYOUT_7POINT1_WIDE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE)418#define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE_BACK)419#define AV_CHANNEL_LAYOUT_5POINT1POINT2 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_5POINT1POINT2)420#define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_5POINT1POINT2_BACK)421#define AV_CHANNEL_LAYOUT_OCTAGONAL AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_OCTAGONAL)422#define AV_CHANNEL_LAYOUT_CUBE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_CUBE)423#define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_5POINT1POINT4_BACK)424#define AV_CHANNEL_LAYOUT_7POINT1POINT2 AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_7POINT1POINT2)425#define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT1POINT4_BACK)426#define AV_CHANNEL_LAYOUT_7POINT2POINT3 AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT2POINT3)427#define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(14, AV_CH_LAYOUT_9POINT1POINT4_BACK)428#define AV_CHANNEL_LAYOUT_9POINT1POINT6 AV_CHANNEL_LAYOUT_MASK(16, AV_CH_LAYOUT_9POINT1POINT6)429#define AV_CHANNEL_LAYOUT_HEXADECAGONAL AV_CHANNEL_LAYOUT_MASK(16, AV_CH_LAYOUT_HEXADECAGONAL)430#define AV_CHANNEL_LAYOUT_BINAURAL AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_BINAURAL)431#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO_DOWNMIX)432#define AV_CHANNEL_LAYOUT_22POINT2 AV_CHANNEL_LAYOUT_MASK(24, AV_CH_LAYOUT_22POINT2)433434#define AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK435436#define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER \437{ /* .order */ AV_CHANNEL_ORDER_AMBISONIC, \438/* .nb_channels */ 4, \439/* .u.mask */ { 0 }, \440/* .opaque */ NULL }441/** @} */442443struct AVBPrint;444445/**446* Get a human readable string in an abbreviated form describing a given channel.447* This is the inverse function of @ref av_channel_from_string().448*449* @param buf pre-allocated buffer where to put the generated string450* @param buf_size size in bytes of the buffer.451* @param channel the AVChannel whose name to get452* @return amount of bytes needed to hold the output string, or a negative AVERROR453* on failure. If the returned value is bigger than buf_size, then the454* string was truncated.455*/456int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel);457458/**459* bprint variant of av_channel_name().460*461* @note the string will be appended to the bprint buffer.462*/463void av_channel_name_bprint(struct AVBPrint *bp, enum AVChannel channel_id);464465/**466* Get a human readable string describing a given channel.467*468* @param buf pre-allocated buffer where to put the generated string469* @param buf_size size in bytes of the buffer.470* @param channel the AVChannel whose description to get471* @return amount of bytes needed to hold the output string, or a negative AVERROR472* on failure. If the returned value is bigger than buf_size, then the473* string was truncated.474*/475int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel);476477/**478* bprint variant of av_channel_description().479*480* @note the string will be appended to the bprint buffer.481*/482void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_id);483484/**485* This is the inverse function of @ref av_channel_name().486*487* @return the channel with the given name488* AV_CHAN_NONE when name does not identify a known channel489*/490enum AVChannel av_channel_from_string(const char *name);491492/**493* Initialize a custom channel layout with the specified number of channels.494* The channel map will be allocated and the designation of all channels will495* be set to AV_CHAN_UNKNOWN.496*497* This is only a convenience helper function, a custom channel layout can also498* be constructed without using this.499*500* @param channel_layout the layout structure to be initialized501* @param nb_channels the number of channels502*503* @return 0 on success504* AVERROR(EINVAL) if the number of channels <= 0505* AVERROR(ENOMEM) if the channel map could not be allocated506*/507int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels);508509/**510* Initialize a native channel layout from a bitmask indicating which channels511* are present.512*513* @param channel_layout the layout structure to be initialized514* @param mask bitmask describing the channel layout515*516* @return 0 on success517* AVERROR(EINVAL) for invalid mask values518*/519int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask);520521/**522* Initialize a channel layout from a given string description.523* The input string can be represented by:524* - the formal channel layout name (returned by av_channel_layout_describe())525* - single or multiple channel names (returned by av_channel_name(), eg. "FL",526* or concatenated with "+", each optionally containing a custom name after527* a "@", eg. "FL@Left+FR@Right+LFE")528* - a decimal or hexadecimal value of a native channel layout (eg. "4" or "0x4")529* - the number of channels with default layout (eg. "4c")530* - the number of unordered channels (eg. "4C" or "4 channels")531* - the ambisonic order followed by optional non-diegetic channels (eg.532* "ambisonic 2+stereo")533* On error, the channel layout will remain uninitialized, but not necessarily534* untouched.535*536* @param channel_layout uninitialized channel layout for the result537* @param str string describing the channel layout538* @return 0 on success parsing the channel layout539* AVERROR(EINVAL) if an invalid channel layout string was provided540* AVERROR(ENOMEM) if there was not enough memory541*/542int av_channel_layout_from_string(AVChannelLayout *channel_layout,543const char *str);544545/**546* Get the default channel layout for a given number of channels.547*548* @param ch_layout the layout structure to be initialized549* @param nb_channels number of channels550*/551void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels);552553/**554* Iterate over all standard channel layouts.555*556* @param opaque a pointer where libavutil will store the iteration state. Must557* point to NULL to start the iteration.558*559* @return the standard channel layout or NULL when the iteration is560* finished561*/562const AVChannelLayout *av_channel_layout_standard(void **opaque);563564/**565* Free any allocated data in the channel layout and reset the channel566* count to 0.567*568* @param channel_layout the layout structure to be uninitialized569*/570void av_channel_layout_uninit(AVChannelLayout *channel_layout);571572/**573* Make a copy of a channel layout. This differs from just assigning src to dst574* in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM.575*576* @note the destination channel_layout will be always uninitialized before copy.577*578* @param dst destination channel layout579* @param src source channel layout580* @return 0 on success, a negative AVERROR on error.581*/582int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src);583584/**585* Get a human-readable string describing the channel layout properties.586* The string will be in the same format that is accepted by587* @ref av_channel_layout_from_string(), allowing to rebuild the same588* channel layout, except for opaque pointers.589*590* @param channel_layout channel layout to be described591* @param buf pre-allocated buffer where to put the generated string592* @param buf_size size in bytes of the buffer.593* @return amount of bytes needed to hold the output string, or a negative AVERROR594* on failure. If the returned value is bigger than buf_size, then the595* string was truncated.596*/597int av_channel_layout_describe(const AVChannelLayout *channel_layout,598char *buf, size_t buf_size);599600/**601* bprint variant of av_channel_layout_describe().602*603* @note the string will be appended to the bprint buffer.604* @return 0 on success, or a negative AVERROR value on failure.605*/606int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,607struct AVBPrint *bp);608609/**610* Get the channel with the given index in a channel layout.611*612* @param channel_layout input channel layout613* @param idx index of the channel614* @return channel with the index idx in channel_layout on success or615* AV_CHAN_NONE on failure (if idx is not valid or the channel order is616* unspecified)617*/618enum AVChannel619av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx);620621/**622* Get the index of a given channel in a channel layout. In case multiple623* channels are found, only the first match will be returned.624*625* @param channel_layout input channel layout626* @param channel the channel whose index to obtain627* @return index of channel in channel_layout on success or a negative number if628* channel is not present in channel_layout.629*/630int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout,631enum AVChannel channel);632633/**634* Get the index in a channel layout of a channel described by the given string.635* In case multiple channels are found, only the first match will be returned.636*637* This function accepts channel names in the same format as638* @ref av_channel_from_string().639*640* @param channel_layout input channel layout641* @param name string describing the channel whose index to obtain642* @return a channel index described by the given string, or a negative AVERROR643* value.644*/645int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout,646const char *name);647648/**649* Get a channel described by the given string.650*651* This function accepts channel names in the same format as652* @ref av_channel_from_string().653*654* @param channel_layout input channel layout655* @param name string describing the channel to obtain656* @return a channel described by the given string in channel_layout on success657* or AV_CHAN_NONE on failure (if the string is not valid or the channel658* order is unspecified)659*/660enum AVChannel661av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,662const char *name);663664/**665* Find out what channels from a given set are present in a channel layout,666* without regard for their positions.667*668* @param channel_layout input channel layout669* @param mask a combination of AV_CH_* representing a set of channels670* @return a bitfield representing all the channels from mask that are present671* in channel_layout672*/673uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,674uint64_t mask);675676/**677* Check whether a channel layout is valid, i.e. can possibly describe audio678* data.679*680* @param channel_layout input channel layout681* @return 1 if channel_layout is valid, 0 otherwise.682*/683int av_channel_layout_check(const AVChannelLayout *channel_layout);684685/**686* Check whether two channel layouts are semantically the same, i.e. the same687* channels are present on the same positions in both.688*689* If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is690* not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC,691* they are considered equal iff the channel counts are the same in both.692*693* @param chl input channel layout694* @param chl1 input channel layout695* @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative696* AVERROR code if one or both are invalid.697*/698int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1);699700/**701* Return the order if the layout is n-th order standard-order ambisonic.702* The presence of optional extra non-diegetic channels at the end is not taken703* into account.704*705* @param channel_layout input channel layout706* @return the order of the layout, a negative error code otherwise.707*/708int av_channel_layout_ambisonic_order(const AVChannelLayout *channel_layout);709710/**711* The conversion must be lossless.712*/713#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS (1 << 0)714715/**716* The specified retype target order is ignored and the simplest possible717* (canonical) order is used for which the input layout can be losslessy718* represented.719*/720#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL (1 << 1)721722/**723* Change the AVChannelOrder of a channel layout.724*725* Change of AVChannelOrder can be either lossless or lossy. In case of a726* lossless conversion all the channel designations and the associated channel727* names (if any) are kept. On a lossy conversion the channel names and channel728* designations might be lost depending on the capabilities of the desired729* AVChannelOrder. Note that some conversions are simply not possible in which730* case this function returns AVERROR(ENOSYS).731*732* The following conversions are supported:733*734* Any -> Custom : Always possible, always lossless.735* Any -> Unspecified: Always possible, lossless if channel designations736* are all unknown and channel names are not used, lossy otherwise.737* Custom -> Ambisonic : Possible if it contains ambisonic channels with738* optional non-diegetic channels in the end. Lossy if the channels have739* custom names, lossless otherwise.740* Custom -> Native : Possible if it contains native channels in native741* order. Lossy if the channels have custom names, lossless otherwise.742*743* On error this function keeps the original channel layout untouched.744*745* @param channel_layout channel layout which will be changed746* @param order the desired channel layout order747* @param flags a combination of AV_CHANNEL_LAYOUT_RETYPE_FLAG_* constants748* @return 0 if the conversion was successful and lossless or if the channel749* layout was already in the desired order750* >0 if the conversion was successful but lossy751* AVERROR(ENOSYS) if the conversion was not possible (or would be752* lossy and AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS was specified)753* AVERROR(EINVAL), AVERROR(ENOMEM) on error754*/755int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags);756757/**758* @}759*/760761#endif /* AVUTIL_CHANNEL_LAYOUT_H */762763764