Path: blob/master/dep/ffmpeg/include/libavutil/channel_layout.h
4216 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, TpRS8586/** Channel is empty can be safely skipped. */87AV_CHAN_UNUSED = 0x200,8889/** Channel contains data, but its position is unknown. */90AV_CHAN_UNKNOWN = 0x300,9192/**93* Range of channels between AV_CHAN_AMBISONIC_BASE and94* AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system.95*96* Given a channel id `<i>` between AV_CHAN_AMBISONIC_BASE and97* AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel `<n>` is98* `<n> = <i> - AV_CHAN_AMBISONIC_BASE`.99*100* @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel101* orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels102* implicitly by their position in the stream.103*/104AV_CHAN_AMBISONIC_BASE = 0x400,105// leave space for 1024 ids, which correspond to maximum order-32 harmonics,106// which should be enough for the foreseeable use cases107AV_CHAN_AMBISONIC_END = 0x7ff,108};109110enum AVChannelOrder {111/**112* Only the channel count is specified, without any further information113* about the channel order.114*/115AV_CHANNEL_ORDER_UNSPEC,116/**117* The native channel order, i.e. the channels are in the same order in118* which they are defined in the AVChannel enum. This supports up to 63119* different channels.120*/121AV_CHANNEL_ORDER_NATIVE,122/**123* The channel order does not correspond to any other predefined order and124* is stored as an explicit map. For example, this could be used to support125* layouts with 64 or more channels, or with empty/skipped (AV_CHAN_UNUSED)126* channels at arbitrary positions.127*/128AV_CHANNEL_ORDER_CUSTOM,129/**130* The audio is represented as the decomposition of the sound field into131* spherical harmonics. Each channel corresponds to a single expansion132* component. Channels are ordered according to ACN (Ambisonic Channel133* Number).134*135* The channel with the index n in the stream contains the spherical136* harmonic of degree l and order m given by137* @code{.unparsed}138* l = floor(sqrt(n)),139* m = n - l * (l + 1).140* @endcode141*142* Conversely given a spherical harmonic of degree l and order m, the143* corresponding channel index n is given by144* @code{.unparsed}145* n = l * (l + 1) + m.146* @endcode147*148* Normalization is assumed to be SN3D (Schmidt Semi-Normalization)149* as defined in AmbiX format $ 2.1.150*/151AV_CHANNEL_ORDER_AMBISONIC,152/**153* Number of channel orders, not part of ABI/API154*/155FF_CHANNEL_ORDER_NB156};157158159/**160* @defgroup channel_masks Audio channel masks161*162* A channel layout is a 64-bits integer with a bit set for every channel.163* The number of bits set must be equal to the number of channels.164* The value 0 means that the channel layout is not known.165* @note this data structure is not powerful enough to handle channels166* combinations that have the same channel multiple times, such as167* dual-mono.168*169* @{170*/171#define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT )172#define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT )173#define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER )174#define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY )175#define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT )176#define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT )177#define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER )178#define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER)179#define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER )180#define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT )181#define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT )182#define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER )183#define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT )184#define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER )185#define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT )186#define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT )187#define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER )188#define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT )189#define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT )190#define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT )191#define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT )192#define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT )193#define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT )194#define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT)195#define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2 )196#define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT )197#define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT )198#define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER )199#define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT )200#define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT )201#define AV_CH_SIDE_SURROUND_LEFT (1ULL << AV_CHAN_SIDE_SURROUND_LEFT )202#define AV_CH_SIDE_SURROUND_RIGHT (1ULL << AV_CHAN_SIDE_SURROUND_RIGHT )203#define AV_CH_TOP_SURROUND_LEFT (1ULL << AV_CHAN_TOP_SURROUND_LEFT )204#define AV_CH_TOP_SURROUND_RIGHT (1ULL << AV_CHAN_TOP_SURROUND_RIGHT )205206/**207* @}208* @defgroup channel_mask_c Audio channel layouts209* @{210* */211#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER)212#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT)213#define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY)214#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER)215#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER)216#define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY)217#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER)218#define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY)219#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)220#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)221#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)222#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY)223#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)224#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY)225#define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER)226#define AV_CH_LAYOUT_6POINT0_FRONT (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)227#define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER)228#define AV_CH_LAYOUT_3POINT1POINT2 (AV_CH_LAYOUT_3POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)229#define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER)230#define AV_CH_LAYOUT_6POINT1_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER)231#define AV_CH_LAYOUT_6POINT1_FRONT (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY)232#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)233#define AV_CH_LAYOUT_7POINT0_FRONT (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)234#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)235#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)236#define AV_CH_LAYOUT_7POINT1_WIDE_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)237#define AV_CH_LAYOUT_5POINT1POINT2_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)238#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)239#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)240#define AV_CH_LAYOUT_5POINT1POINT4_BACK (AV_CH_LAYOUT_5POINT1POINT2_BACK|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)241#define AV_CH_LAYOUT_7POINT1POINT2 (AV_CH_LAYOUT_7POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)242#define AV_CH_LAYOUT_7POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)243#define AV_CH_LAYOUT_7POINT2POINT3 (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_CENTER|AV_CH_LOW_FREQUENCY_2)244#define AV_CH_LAYOUT_9POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)245#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)246#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)247#define AV_CH_LAYOUT_22POINT2 (AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_BACK_CENTER|AV_CH_LOW_FREQUENCY_2|AV_CH_TOP_FRONT_CENTER|AV_CH_TOP_CENTER|AV_CH_TOP_SIDE_LEFT|AV_CH_TOP_SIDE_RIGHT|AV_CH_TOP_BACK_CENTER|AV_CH_BOTTOM_FRONT_CENTER|AV_CH_BOTTOM_FRONT_LEFT|AV_CH_BOTTOM_FRONT_RIGHT)248249#define AV_CH_LAYOUT_7POINT1_TOP_BACK AV_CH_LAYOUT_5POINT1POINT2_BACK250251enum AVMatrixEncoding {252AV_MATRIX_ENCODING_NONE,253AV_MATRIX_ENCODING_DOLBY,254AV_MATRIX_ENCODING_DPLII,255AV_MATRIX_ENCODING_DPLIIX,256AV_MATRIX_ENCODING_DPLIIZ,257AV_MATRIX_ENCODING_DOLBYEX,258AV_MATRIX_ENCODING_DOLBYHEADPHONE,259AV_MATRIX_ENCODING_NB260};261262/**263* @}264*/265266/**267* An AVChannelCustom defines a single channel within a custom order layout268*269* Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the270* public ABI.271*272* No new fields may be added to it without a major version bump.273*/274typedef struct AVChannelCustom {275enum AVChannel id;276char name[16];277void *opaque;278} AVChannelCustom;279280/**281* An AVChannelLayout holds information about the channel layout of audio data.282*283* A channel layout here is defined as a set of channels ordered in a specific284* way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an285* AVChannelLayout carries only the channel count).286* All orders may be treated as if they were AV_CHANNEL_ORDER_UNSPEC by287* ignoring everything but the channel count, as long as av_channel_layout_check()288* considers they are valid.289*290* Unlike most structures in FFmpeg, sizeof(AVChannelLayout) is a part of the291* public ABI and may be used by the caller. E.g. it may be allocated on stack292* or embedded in caller-defined structs.293*294* AVChannelLayout can be initialized as follows:295* - default initialization with {0}, followed by setting all used fields296* correctly;297* - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers;298* - with a constructor function, such as av_channel_layout_default(),299* av_channel_layout_from_mask() or av_channel_layout_from_string().300*301* The channel layout must be unitialized with av_channel_layout_uninit()302*303* Copying an AVChannelLayout via assigning is forbidden,304* av_channel_layout_copy() must be used instead (and its return value should305* be checked)306*307* No new fields may be added to it without a major version bump, except for308* new elements of the union fitting in sizeof(uint64_t).309*/310typedef struct AVChannelLayout {311/**312* Channel order used in this layout.313* This is a mandatory field.314*/315enum AVChannelOrder order;316317/**318* Number of channels in this layout. Mandatory field.319*/320int nb_channels;321322/**323* Details about which channels are present in this layout.324* For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be325* used.326*/327union {328/**329* This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used330* for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels.331* It is a bitmask, where the position of each set bit means that the332* AVChannel with the corresponding value is present.333*334* I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO335* is present in the layout. Otherwise it is not present.336*337* @note when a channel layout using a bitmask is constructed or338* modified manually (i.e. not using any of the av_channel_layout_*339* functions), the code doing it must ensure that the number of set bits340* is equal to nb_channels.341*/342uint64_t mask;343/**344* This member must be used when the channel order is345* AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each346* element signalling the presence of the AVChannel with the347* corresponding value in map[i].id.348*349* I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the350* i-th channel in the audio data.351*352* When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and353* AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic354* component with ACN index (as defined above)355* n = map[i].id - AV_CHAN_AMBISONIC_BASE.356*357* map[i].name may be filled with a 0-terminated string, in which case358* it will be used for the purpose of identifying the channel with the359* convenience functions below. Otherise it must be zeroed.360*/361AVChannelCustom *map;362} u;363364/**365* For some private data of the user.366*/367void *opaque;368} AVChannelLayout;369370/**371* Macro to define native channel layouts372*373* @note This doesn't use designated initializers for compatibility with C++ 17 and older.374*/375#define AV_CHANNEL_LAYOUT_MASK(nb, m) \376{ /* .order */ AV_CHANNEL_ORDER_NATIVE, \377/* .nb_channels */ (nb), \378/* .u.mask */ { m }, \379/* .opaque */ NULL }380381/**382* @name Common pre-defined channel layouts383* @{384*/385#define AV_CHANNEL_LAYOUT_MONO AV_CHANNEL_LAYOUT_MASK(1, AV_CH_LAYOUT_MONO)386#define AV_CHANNEL_LAYOUT_STEREO AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO)387#define AV_CHANNEL_LAYOUT_2POINT1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2POINT1)388#define AV_CHANNEL_LAYOUT_2_1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2_1)389#define AV_CHANNEL_LAYOUT_SURROUND AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_SURROUND)390#define AV_CHANNEL_LAYOUT_3POINT1 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_3POINT1)391#define AV_CHANNEL_LAYOUT_4POINT0 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_4POINT0)392#define AV_CHANNEL_LAYOUT_4POINT1 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_4POINT1)393#define AV_CHANNEL_LAYOUT_2_2 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_2_2)394#define AV_CHANNEL_LAYOUT_QUAD AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_QUAD)395#define AV_CHANNEL_LAYOUT_5POINT0 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0)396#define AV_CHANNEL_LAYOUT_5POINT1 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1)397#define AV_CHANNEL_LAYOUT_5POINT0_BACK AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0_BACK)398#define AV_CHANNEL_LAYOUT_5POINT1_BACK AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1_BACK)399#define AV_CHANNEL_LAYOUT_6POINT0 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0)400#define AV_CHANNEL_LAYOUT_6POINT0_FRONT AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0_FRONT)401#define AV_CHANNEL_LAYOUT_3POINT1POINT2 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_3POINT1POINT2)402#define AV_CHANNEL_LAYOUT_HEXAGONAL AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_HEXAGONAL)403#define AV_CHANNEL_LAYOUT_6POINT1 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1)404#define AV_CHANNEL_LAYOUT_6POINT1_BACK AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_BACK)405#define AV_CHANNEL_LAYOUT_6POINT1_FRONT AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_FRONT)406#define AV_CHANNEL_LAYOUT_7POINT0 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0)407#define AV_CHANNEL_LAYOUT_7POINT0_FRONT AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0_FRONT)408#define AV_CHANNEL_LAYOUT_7POINT1 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1)409#define AV_CHANNEL_LAYOUT_7POINT1_WIDE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE)410#define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE_BACK)411#define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_5POINT1POINT2_BACK)412#define AV_CHANNEL_LAYOUT_OCTAGONAL AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_OCTAGONAL)413#define AV_CHANNEL_LAYOUT_CUBE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_CUBE)414#define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_5POINT1POINT4_BACK)415#define AV_CHANNEL_LAYOUT_7POINT1POINT2 AV_CHANNEL_LAYOUT_MASK(10, AV_CH_LAYOUT_7POINT1POINT2)416#define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT1POINT4_BACK)417#define AV_CHANNEL_LAYOUT_7POINT2POINT3 AV_CHANNEL_LAYOUT_MASK(12, AV_CH_LAYOUT_7POINT2POINT3)418#define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK AV_CHANNEL_LAYOUT_MASK(14, AV_CH_LAYOUT_9POINT1POINT4_BACK)419#define AV_CHANNEL_LAYOUT_HEXADECAGONAL AV_CHANNEL_LAYOUT_MASK(16, AV_CH_LAYOUT_HEXADECAGONAL)420#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO_DOWNMIX)421#define AV_CHANNEL_LAYOUT_22POINT2 AV_CHANNEL_LAYOUT_MASK(24, AV_CH_LAYOUT_22POINT2)422423#define AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK424425#define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER \426{ /* .order */ AV_CHANNEL_ORDER_AMBISONIC, \427/* .nb_channels */ 4, \428/* .u.mask */ { 0 }, \429/* .opaque */ NULL }430/** @} */431432struct AVBPrint;433434/**435* Get a human readable string in an abbreviated form describing a given channel.436* This is the inverse function of @ref av_channel_from_string().437*438* @param buf pre-allocated buffer where to put the generated string439* @param buf_size size in bytes of the buffer.440* @param channel the AVChannel whose name to get441* @return amount of bytes needed to hold the output string, or a negative AVERROR442* on failure. If the returned value is bigger than buf_size, then the443* string was truncated.444*/445int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel);446447/**448* bprint variant of av_channel_name().449*450* @note the string will be appended to the bprint buffer.451*/452void av_channel_name_bprint(struct AVBPrint *bp, enum AVChannel channel_id);453454/**455* Get a human readable string describing a given channel.456*457* @param buf pre-allocated buffer where to put the generated string458* @param buf_size size in bytes of the buffer.459* @param channel the AVChannel whose description to get460* @return amount of bytes needed to hold the output string, or a negative AVERROR461* on failure. If the returned value is bigger than buf_size, then the462* string was truncated.463*/464int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel);465466/**467* bprint variant of av_channel_description().468*469* @note the string will be appended to the bprint buffer.470*/471void av_channel_description_bprint(struct AVBPrint *bp, enum AVChannel channel_id);472473/**474* This is the inverse function of @ref av_channel_name().475*476* @return the channel with the given name477* AV_CHAN_NONE when name does not identify a known channel478*/479enum AVChannel av_channel_from_string(const char *name);480481/**482* Initialize a custom channel layout with the specified number of channels.483* The channel map will be allocated and the designation of all channels will484* be set to AV_CHAN_UNKNOWN.485*486* This is only a convenience helper function, a custom channel layout can also487* be constructed without using this.488*489* @param channel_layout the layout structure to be initialized490* @param nb_channels the number of channels491*492* @return 0 on success493* AVERROR(EINVAL) if the number of channels <= 0494* AVERROR(ENOMEM) if the channel map could not be allocated495*/496int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels);497498/**499* Initialize a native channel layout from a bitmask indicating which channels500* are present.501*502* @param channel_layout the layout structure to be initialized503* @param mask bitmask describing the channel layout504*505* @return 0 on success506* AVERROR(EINVAL) for invalid mask values507*/508int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask);509510/**511* Initialize a channel layout from a given string description.512* The input string can be represented by:513* - the formal channel layout name (returned by av_channel_layout_describe())514* - single or multiple channel names (returned by av_channel_name(), eg. "FL",515* or concatenated with "+", each optionally containing a custom name after516* a "@", eg. "FL@Left+FR@Right+LFE")517* - a decimal or hexadecimal value of a native channel layout (eg. "4" or "0x4")518* - the number of channels with default layout (eg. "4c")519* - the number of unordered channels (eg. "4C" or "4 channels")520* - the ambisonic order followed by optional non-diegetic channels (eg.521* "ambisonic 2+stereo")522* On error, the channel layout will remain uninitialized, but not necessarily523* untouched.524*525* @param channel_layout uninitialized channel layout for the result526* @param str string describing the channel layout527* @return 0 on success parsing the channel layout528* AVERROR(EINVAL) if an invalid channel layout string was provided529* AVERROR(ENOMEM) if there was not enough memory530*/531int av_channel_layout_from_string(AVChannelLayout *channel_layout,532const char *str);533534/**535* Get the default channel layout for a given number of channels.536*537* @param ch_layout the layout structure to be initialized538* @param nb_channels number of channels539*/540void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels);541542/**543* Iterate over all standard channel layouts.544*545* @param opaque a pointer where libavutil will store the iteration state. Must546* point to NULL to start the iteration.547*548* @return the standard channel layout or NULL when the iteration is549* finished550*/551const AVChannelLayout *av_channel_layout_standard(void **opaque);552553/**554* Free any allocated data in the channel layout and reset the channel555* count to 0.556*557* @param channel_layout the layout structure to be uninitialized558*/559void av_channel_layout_uninit(AVChannelLayout *channel_layout);560561/**562* Make a copy of a channel layout. This differs from just assigning src to dst563* in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM.564*565* @note the destination channel_layout will be always uninitialized before copy.566*567* @param dst destination channel layout568* @param src source channel layout569* @return 0 on success, a negative AVERROR on error.570*/571int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src);572573/**574* Get a human-readable string describing the channel layout properties.575* The string will be in the same format that is accepted by576* @ref av_channel_layout_from_string(), allowing to rebuild the same577* channel layout, except for opaque pointers.578*579* @param channel_layout channel layout to be described580* @param buf pre-allocated buffer where to put the generated string581* @param buf_size size in bytes of the buffer.582* @return amount of bytes needed to hold the output string, or a negative AVERROR583* on failure. If the returned value is bigger than buf_size, then the584* string was truncated.585*/586int av_channel_layout_describe(const AVChannelLayout *channel_layout,587char *buf, size_t buf_size);588589/**590* bprint variant of av_channel_layout_describe().591*592* @note the string will be appended to the bprint buffer.593* @return 0 on success, or a negative AVERROR value on failure.594*/595int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout,596struct AVBPrint *bp);597598/**599* Get the channel with the given index in a channel layout.600*601* @param channel_layout input channel layout602* @param idx index of the channel603* @return channel with the index idx in channel_layout on success or604* AV_CHAN_NONE on failure (if idx is not valid or the channel order is605* unspecified)606*/607enum AVChannel608av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx);609610/**611* Get the index of a given channel in a channel layout. In case multiple612* channels are found, only the first match will be returned.613*614* @param channel_layout input channel layout615* @param channel the channel whose index to obtain616* @return index of channel in channel_layout on success or a negative number if617* channel is not present in channel_layout.618*/619int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout,620enum AVChannel channel);621622/**623* Get the index in a channel layout of a channel described by the given string.624* In case multiple channels are found, only the first match will be returned.625*626* This function accepts channel names in the same format as627* @ref av_channel_from_string().628*629* @param channel_layout input channel layout630* @param name string describing the channel whose index to obtain631* @return a channel index described by the given string, or a negative AVERROR632* value.633*/634int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout,635const char *name);636637/**638* Get a channel described by the given string.639*640* This function accepts channel names in the same format as641* @ref av_channel_from_string().642*643* @param channel_layout input channel layout644* @param name string describing the channel to obtain645* @return a channel described by the given string in channel_layout on success646* or AV_CHAN_NONE on failure (if the string is not valid or the channel647* order is unspecified)648*/649enum AVChannel650av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout,651const char *name);652653/**654* Find out what channels from a given set are present in a channel layout,655* without regard for their positions.656*657* @param channel_layout input channel layout658* @param mask a combination of AV_CH_* representing a set of channels659* @return a bitfield representing all the channels from mask that are present660* in channel_layout661*/662uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,663uint64_t mask);664665/**666* Check whether a channel layout is valid, i.e. can possibly describe audio667* data.668*669* @param channel_layout input channel layout670* @return 1 if channel_layout is valid, 0 otherwise.671*/672int av_channel_layout_check(const AVChannelLayout *channel_layout);673674/**675* Check whether two channel layouts are semantically the same, i.e. the same676* channels are present on the same positions in both.677*678* If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is679* not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC,680* they are considered equal iff the channel counts are the same in both.681*682* @param chl input channel layout683* @param chl1 input channel layout684* @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative685* AVERROR code if one or both are invalid.686*/687int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1);688689/**690* Return the order if the layout is n-th order standard-order ambisonic.691* The presence of optional extra non-diegetic channels at the end is not taken692* into account.693*694* @param channel_layout input channel layout695* @return the order of the layout, a negative error code otherwise.696*/697int av_channel_layout_ambisonic_order(const AVChannelLayout *channel_layout);698699/**700* The conversion must be lossless.701*/702#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS (1 << 0)703704/**705* The specified retype target order is ignored and the simplest possible706* (canonical) order is used for which the input layout can be losslessy707* represented.708*/709#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL (1 << 1)710711/**712* Change the AVChannelOrder of a channel layout.713*714* Change of AVChannelOrder can be either lossless or lossy. In case of a715* lossless conversion all the channel designations and the associated channel716* names (if any) are kept. On a lossy conversion the channel names and channel717* designations might be lost depending on the capabilities of the desired718* AVChannelOrder. Note that some conversions are simply not possible in which719* case this function returns AVERROR(ENOSYS).720*721* The following conversions are supported:722*723* Any -> Custom : Always possible, always lossless.724* Any -> Unspecified: Always possible, lossless if channel designations725* are all unknown and channel names are not used, lossy otherwise.726* Custom -> Ambisonic : Possible if it contains ambisonic channels with727* optional non-diegetic channels in the end. Lossy if the channels have728* custom names, lossless otherwise.729* Custom -> Native : Possible if it contains native channels in native730* order. Lossy if the channels have custom names, lossless otherwise.731*732* On error this function keeps the original channel layout untouched.733*734* @param channel_layout channel layout which will be changed735* @param order the desired channel layout order736* @param flags a combination of AV_CHANNEL_LAYOUT_RETYPE_FLAG_* constants737* @return 0 if the conversion was successful and lossless or if the channel738* layout was already in the desired order739* >0 if the conversion was successful but lossy740* AVERROR(ENOSYS) if the conversion was not possible (or would be741* lossy and AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS was specified)742* AVERROR(EINVAL), AVERROR(ENOMEM) on error743*/744int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags);745746/**747* @}748*/749750#endif /* AVUTIL_CHANNEL_LAYOUT_H */751752753