channel_layout.h (32367B)
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_SILENCE) 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 150 /** 151 * @defgroup channel_masks Audio channel masks 152 * 153 * A channel layout is a 64-bits integer with a bit set for every channel. 154 * The number of bits set must be equal to the number of channels. 155 * The value 0 means that the channel layout is not known. 156 * @note this data structure is not powerful enough to handle channels 157 * combinations that have the same channel multiple times, such as 158 * dual-mono. 159 * 160 * @{ 161 */ 162 #define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT) 163 #define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT) 164 #define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER) 165 #define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY) 166 #define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT) 167 #define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT) 168 #define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER) 169 #define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER) 170 #define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER) 171 #define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT) 172 #define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT) 173 #define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER) 174 #define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT) 175 #define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER) 176 #define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT) 177 #define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT) 178 #define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER) 179 #define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT) 180 #define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT) 181 #define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT) 182 #define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT) 183 #define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT) 184 #define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT) 185 #define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT) 186 #define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2) 187 #define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT) 188 #define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT) 189 #define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER) 190 #define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT) 191 #define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT) 192 193 #if FF_API_OLD_CHANNEL_LAYOUT 194 /** Channel mask value used for AVCodecContext.request_channel_layout 195 to indicate that the user requests the channel order of the decoder output 196 to be the native codec channel order. 197 @deprecated channel order is now indicated in a special field in 198 AVChannelLayout 199 */ 200 # define AV_CH_LAYOUT_NATIVE 0x8000000000000000ULL 201 #endif 202 203 /** 204 * @} 205 * @defgroup channel_mask_c Audio channel layouts 206 * @{ 207 * */ 208 #define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER) 209 #define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT) 210 #define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO | AV_CH_LOW_FREQUENCY) 211 #define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER) 212 #define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER) 213 #define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND | AV_CH_LOW_FREQUENCY) 214 #define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND | AV_CH_BACK_CENTER) 215 #define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0 | AV_CH_LOW_FREQUENCY) 216 #define AV_CH_LAYOUT_2_2 \ 217 (AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT) 218 #define AV_CH_LAYOUT_QUAD \ 219 (AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT) 220 #define AV_CH_LAYOUT_5POINT0 \ 221 (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 \ 224 (AV_CH_LAYOUT_SURROUND | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT) 225 #define AV_CH_LAYOUT_5POINT1_BACK \ 226 (AV_CH_LAYOUT_5POINT0_BACK | AV_CH_LOW_FREQUENCY) 227 #define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_CENTER) 228 #define AV_CH_LAYOUT_6POINT0_FRONT \ 229 (AV_CH_LAYOUT_2_2 | AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER) 230 #define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK | AV_CH_BACK_CENTER) 231 #define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_CENTER) 232 #define AV_CH_LAYOUT_6POINT1_BACK \ 233 (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_BACK_CENTER) 234 #define AV_CH_LAYOUT_6POINT1_FRONT \ 235 (AV_CH_LAYOUT_6POINT0_FRONT | AV_CH_LOW_FREQUENCY) 236 #define AV_CH_LAYOUT_7POINT0 \ 237 (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT) 238 #define AV_CH_LAYOUT_7POINT0_FRONT \ 239 (AV_CH_LAYOUT_5POINT0 | AV_CH_FRONT_LEFT_OF_CENTER | \ 240 AV_CH_FRONT_RIGHT_OF_CENTER) 241 #define AV_CH_LAYOUT_7POINT1 \ 242 (AV_CH_LAYOUT_5POINT1 | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT) 243 #define AV_CH_LAYOUT_7POINT1_WIDE \ 244 (AV_CH_LAYOUT_5POINT1 | AV_CH_FRONT_LEFT_OF_CENTER | \ 245 AV_CH_FRONT_RIGHT_OF_CENTER) 246 #define AV_CH_LAYOUT_7POINT1_WIDE_BACK \ 247 (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_FRONT_LEFT_OF_CENTER | \ 248 AV_CH_FRONT_RIGHT_OF_CENTER) 249 #define AV_CH_LAYOUT_7POINT1_TOP_BACK \ 250 (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT) 251 #define AV_CH_LAYOUT_OCTAGONAL \ 252 (AV_CH_LAYOUT_5POINT0 | AV_CH_BACK_LEFT | AV_CH_BACK_CENTER | \ 253 AV_CH_BACK_RIGHT) 254 #define AV_CH_LAYOUT_CUBE \ 255 (AV_CH_LAYOUT_QUAD | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT | \ 256 AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT) 257 #define AV_CH_LAYOUT_HEXADECAGONAL \ 258 (AV_CH_LAYOUT_OCTAGONAL | AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT | \ 259 AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT | AV_CH_TOP_BACK_CENTER | \ 260 AV_CH_TOP_FRONT_CENTER | AV_CH_TOP_FRONT_LEFT | AV_CH_TOP_FRONT_RIGHT) 261 #define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT) 262 #define AV_CH_LAYOUT_22POINT2 \ 263 (AV_CH_LAYOUT_5POINT1_BACK | AV_CH_FRONT_LEFT_OF_CENTER | \ 264 AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_BACK_CENTER | AV_CH_LOW_FREQUENCY_2 | \ 265 AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT | AV_CH_TOP_FRONT_LEFT | \ 266 AV_CH_TOP_FRONT_RIGHT | AV_CH_TOP_FRONT_CENTER | AV_CH_TOP_CENTER | \ 267 AV_CH_TOP_BACK_LEFT | AV_CH_TOP_BACK_RIGHT | AV_CH_TOP_SIDE_LEFT | \ 268 AV_CH_TOP_SIDE_RIGHT | AV_CH_TOP_BACK_CENTER | AV_CH_BOTTOM_FRONT_CENTER | \ 269 AV_CH_BOTTOM_FRONT_LEFT | AV_CH_BOTTOM_FRONT_RIGHT) 270 271 enum AVMatrixEncoding { 272 AV_MATRIX_ENCODING_NONE, 273 AV_MATRIX_ENCODING_DOLBY, 274 AV_MATRIX_ENCODING_DPLII, 275 AV_MATRIX_ENCODING_DPLIIX, 276 AV_MATRIX_ENCODING_DPLIIZ, 277 AV_MATRIX_ENCODING_DOLBYEX, 278 AV_MATRIX_ENCODING_DOLBYHEADPHONE, 279 AV_MATRIX_ENCODING_NB 280 }; 281 282 /** 283 * @} 284 */ 285 286 /** 287 * An AVChannelCustom defines a single channel within a custom order layout 288 * 289 * Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the 290 * public ABI. 291 * 292 * No new fields may be added to it without a major version bump. 293 */ 294 typedef struct AVChannelCustom { 295 enum AVChannel id; 296 char name[16]; 297 void* opaque; 298 } AVChannelCustom; 299 300 /** 301 * An AVChannelLayout holds information about the channel layout of audio data. 302 * 303 * A channel layout here is defined as a set of channels ordered in a specific 304 * way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an 305 * AVChannelLayout carries only the channel count). 306 * All orders may be treated as if they were AV_CHANNEL_ORDER_UNSPEC by 307 * ignoring everything but the channel count, as long as 308 * av_channel_layout_check() considers they are valid. 309 * 310 * Unlike most structures in FFmpeg, sizeof(AVChannelLayout) is a part of the 311 * public ABI and may be used by the caller. E.g. it may be allocated on stack 312 * or embedded in caller-defined structs. 313 * 314 * AVChannelLayout can be initialized as follows: 315 * - default initialization with {0}, followed by setting all used fields 316 * correctly; 317 * - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers; 318 * - with a constructor function, such as av_channel_layout_default(), 319 * av_channel_layout_from_mask() or av_channel_layout_from_string(). 320 * 321 * The channel layout must be unitialized with av_channel_layout_uninit() 322 * 323 * Copying an AVChannelLayout via assigning is forbidden, 324 * av_channel_layout_copy() must be used instead (and its return value should 325 * be checked) 326 * 327 * No new fields may be added to it without a major version bump, except for 328 * new elements of the union fitting in sizeof(uint64_t). 329 */ 330 typedef struct AVChannelLayout { 331 /** 332 * Channel order used in this layout. 333 * This is a mandatory field. 334 */ 335 enum AVChannelOrder order; 336 337 /** 338 * Number of channels in this layout. Mandatory field. 339 */ 340 int nb_channels; 341 342 /** 343 * Details about which channels are present in this layout. 344 * For AV_CHANNEL_ORDER_UNSPEC, this field is undefined and must not be 345 * used. 346 */ 347 union { 348 /** 349 * This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used 350 * for AV_CHANNEL_ORDER_AMBISONIC to signal non-diegetic channels. 351 * It is a bitmask, where the position of each set bit means that the 352 * AVChannel with the corresponding value is present. 353 * 354 * I.e. when (mask & (1 << AV_CHAN_FOO)) is non-zero, then AV_CHAN_FOO 355 * is present in the layout. Otherwise it is not present. 356 * 357 * @note when a channel layout using a bitmask is constructed or 358 * modified manually (i.e. not using any of the av_channel_layout_* 359 * functions), the code doing it must ensure that the number of set bits 360 * is equal to nb_channels. 361 */ 362 uint64_t mask; 363 /** 364 * This member must be used when the channel order is 365 * AV_CHANNEL_ORDER_CUSTOM. It is a nb_channels-sized array, with each 366 * element signalling the presence of the AVChannel with the 367 * corresponding value in map[i].id. 368 * 369 * I.e. when map[i].id is equal to AV_CHAN_FOO, then AV_CH_FOO is the 370 * i-th channel in the audio data. 371 * 372 * When map[i].id is in the range between AV_CHAN_AMBISONIC_BASE and 373 * AV_CHAN_AMBISONIC_END (inclusive), the channel contains an ambisonic 374 * component with ACN index (as defined above) 375 * n = map[i].id - AV_CHAN_AMBISONIC_BASE. 376 * 377 * map[i].name may be filled with a 0-terminated string, in which case 378 * it will be used for the purpose of identifying the channel with the 379 * convenience functions below. Otherise it must be zeroed. 380 */ 381 AVChannelCustom* map; 382 } u; 383 384 /** 385 * For some private data of the user. 386 */ 387 void* opaque; 388 } AVChannelLayout; 389 390 #define AV_CHANNEL_LAYOUT_MASK(nb, m) \ 391 { \ 392 .order = AV_CHANNEL_ORDER_NATIVE, .nb_channels = (nb), .u = {.mask = (m) } \ 393 } 394 395 /** 396 * @name Common pre-defined channel layouts 397 * @{ 398 */ 399 #define AV_CHANNEL_LAYOUT_MONO AV_CHANNEL_LAYOUT_MASK(1, AV_CH_LAYOUT_MONO) 400 #define AV_CHANNEL_LAYOUT_STEREO AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO) 401 #define AV_CHANNEL_LAYOUT_2POINT1 \ 402 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2POINT1) 403 #define AV_CHANNEL_LAYOUT_2_1 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_2_1) 404 #define AV_CHANNEL_LAYOUT_SURROUND \ 405 AV_CHANNEL_LAYOUT_MASK(3, AV_CH_LAYOUT_SURROUND) 406 #define AV_CHANNEL_LAYOUT_3POINT1 \ 407 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_3POINT1) 408 #define AV_CHANNEL_LAYOUT_4POINT0 \ 409 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_4POINT0) 410 #define AV_CHANNEL_LAYOUT_4POINT1 \ 411 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_4POINT1) 412 #define AV_CHANNEL_LAYOUT_2_2 AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_2_2) 413 #define AV_CHANNEL_LAYOUT_QUAD AV_CHANNEL_LAYOUT_MASK(4, AV_CH_LAYOUT_QUAD) 414 #define AV_CHANNEL_LAYOUT_5POINT0 \ 415 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0) 416 #define AV_CHANNEL_LAYOUT_5POINT1 \ 417 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1) 418 #define AV_CHANNEL_LAYOUT_5POINT0_BACK \ 419 AV_CHANNEL_LAYOUT_MASK(5, AV_CH_LAYOUT_5POINT0_BACK) 420 #define AV_CHANNEL_LAYOUT_5POINT1_BACK \ 421 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_5POINT1_BACK) 422 #define AV_CHANNEL_LAYOUT_6POINT0 \ 423 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0) 424 #define AV_CHANNEL_LAYOUT_6POINT0_FRONT \ 425 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_6POINT0_FRONT) 426 #define AV_CHANNEL_LAYOUT_HEXAGONAL \ 427 AV_CHANNEL_LAYOUT_MASK(6, AV_CH_LAYOUT_HEXAGONAL) 428 #define AV_CHANNEL_LAYOUT_6POINT1 \ 429 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1) 430 #define AV_CHANNEL_LAYOUT_6POINT1_BACK \ 431 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_BACK) 432 #define AV_CHANNEL_LAYOUT_6POINT1_FRONT \ 433 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_6POINT1_FRONT) 434 #define AV_CHANNEL_LAYOUT_7POINT0 \ 435 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0) 436 #define AV_CHANNEL_LAYOUT_7POINT0_FRONT \ 437 AV_CHANNEL_LAYOUT_MASK(7, AV_CH_LAYOUT_7POINT0_FRONT) 438 #define AV_CHANNEL_LAYOUT_7POINT1 \ 439 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1) 440 #define AV_CHANNEL_LAYOUT_7POINT1_WIDE \ 441 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE) 442 #define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK \ 443 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_WIDE_BACK) 444 #define AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK \ 445 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_7POINT1_TOP_BACK) 446 #define AV_CHANNEL_LAYOUT_OCTAGONAL \ 447 AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_OCTAGONAL) 448 #define AV_CHANNEL_LAYOUT_CUBE AV_CHANNEL_LAYOUT_MASK(8, AV_CH_LAYOUT_CUBE) 449 #define AV_CHANNEL_LAYOUT_HEXADECAGONAL \ 450 AV_CHANNEL_LAYOUT_MASK(16, AV_CH_LAYOUT_HEXADECAGONAL) 451 #define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX \ 452 AV_CHANNEL_LAYOUT_MASK(2, AV_CH_LAYOUT_STEREO_DOWNMIX) 453 #define AV_CHANNEL_LAYOUT_22POINT2 \ 454 AV_CHANNEL_LAYOUT_MASK(24, AV_CH_LAYOUT_22POINT2) 455 #define AV_CHANNEL_LAYOUT_AMBISONIC_FIRST_ORDER \ 456 { \ 457 .order = AV_CHANNEL_ORDER_AMBISONIC, .nb_channels = 4, .u = {.mask = 0 } \ 458 } 459 /** @} */ 460 461 struct AVBPrint; 462 463 #if FF_API_OLD_CHANNEL_LAYOUT 464 /** 465 * @name Deprecated Functions 466 * @{ 467 */ 468 469 /** 470 * Return a channel layout id that matches name, or 0 if no match is found. 471 * 472 * name can be one or several of the following notations, 473 * separated by '+' or '|': 474 * - the name of an usual channel layout (mono, stereo, 4.0, quad, 5.0, 475 * 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix); 476 * - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC, 477 * SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR); 478 * - a number of channels, in decimal, followed by 'c', yielding 479 * the default channel layout for that number of channels (@see 480 * av_get_default_channel_layout); 481 * - a channel layout mask, in hexadecimal starting with "0x" (see the 482 * AV_CH_* macros). 483 * 484 * Example: "stereo+FC" = "2c+FC" = "2c+1c" = "0x7" 485 * 486 * @deprecated use av_channel_layout_from_string() 487 */ 488 attribute_deprecated uint64_t av_get_channel_layout(const char* name); 489 490 /** 491 * Return a channel layout and the number of channels based on the specified 492 * name. 493 * 494 * This function is similar to (@see av_get_channel_layout), but can also parse 495 * unknown channel layout specifications. 496 * 497 * @param[in] name channel layout specification string 498 * @param[out] channel_layout parsed channel layout (0 if unknown) 499 * @param[out] nb_channels number of channels 500 * 501 * @return 0 on success, AVERROR(EINVAL) if the parsing fails. 502 * @deprecated use av_channel_layout_from_string() 503 */ 504 attribute_deprecated int av_get_extended_channel_layout( 505 const char* name, uint64_t* channel_layout, int* nb_channels); 506 507 /** 508 * Return a description of a channel layout. 509 * If nb_channels is <= 0, it is guessed from the channel_layout. 510 * 511 * @param buf put here the string containing the channel layout 512 * @param buf_size size in bytes of the buffer 513 * @param nb_channels number of channels 514 * @param channel_layout channel layout bitset 515 * @deprecated use av_channel_layout_describe() 516 */ 517 attribute_deprecated void av_get_channel_layout_string(char* buf, int buf_size, 518 int nb_channels, 519 uint64_t channel_layout); 520 521 /** 522 * Append a description of a channel layout to a bprint buffer. 523 * @deprecated use av_channel_layout_describe() 524 */ 525 attribute_deprecated void av_bprint_channel_layout(struct AVBPrint* bp, 526 int nb_channels, 527 uint64_t channel_layout); 528 529 /** 530 * Return the number of channels in the channel layout. 531 * @deprecated use AVChannelLayout.nb_channels 532 */ 533 attribute_deprecated int av_get_channel_layout_nb_channels( 534 uint64_t channel_layout); 535 536 /** 537 * Return default channel layout for a given number of channels. 538 * 539 * @deprecated use av_channel_layout_default() 540 */ 541 attribute_deprecated int64_t av_get_default_channel_layout(int nb_channels); 542 543 /** 544 * Get the index of a channel in channel_layout. 545 * 546 * @param channel_layout channel layout bitset 547 * @param channel a channel layout describing exactly one channel which must be 548 * present in channel_layout. 549 * 550 * @return index of channel in channel_layout on success, a negative AVERROR 551 * on error. 552 * 553 * @deprecated use av_channel_layout_index_from_channel() 554 */ 555 attribute_deprecated int av_get_channel_layout_channel_index( 556 uint64_t channel_layout, uint64_t channel); 557 558 /** 559 * Get the channel with the given index in channel_layout. 560 * @deprecated use av_channel_layout_channel_from_index() 561 */ 562 attribute_deprecated uint64_t 563 av_channel_layout_extract_channel(uint64_t channel_layout, int index); 564 565 /** 566 * Get the name of a given channel. 567 * 568 * @return channel name on success, NULL on error. 569 * 570 * @deprecated use av_channel_name() 571 */ 572 attribute_deprecated const char* av_get_channel_name(uint64_t channel); 573 574 /** 575 * Get the description of a given channel. 576 * 577 * @param channel a channel layout with a single channel 578 * @return channel description on success, NULL on error 579 * @deprecated use av_channel_description() 580 */ 581 attribute_deprecated const char* av_get_channel_description(uint64_t channel); 582 583 /** 584 * Get the value and name of a standard channel layout. 585 * 586 * @param[in] index index in an internal list, starting at 0 587 * @param[out] layout channel layout mask 588 * @param[out] name name of the layout 589 * @return 0 if the layout exists, 590 * <0 if index is beyond the limits 591 * @deprecated use av_channel_layout_standard() 592 */ 593 attribute_deprecated int av_get_standard_channel_layout(unsigned index, 594 uint64_t* layout, 595 const char** name); 596 /** 597 * @} 598 */ 599 #endif 600 601 /** 602 * Get a human readable string in an abbreviated form describing a given 603 * channel. This is the inverse function of @ref av_channel_from_string(). 604 * 605 * @param buf pre-allocated buffer where to put the generated string 606 * @param buf_size size in bytes of the buffer. 607 * @param channel the AVChannel whose name to get 608 * @return amount of bytes needed to hold the output string, or a negative 609 * AVERROR on failure. If the returned value is bigger than buf_size, then the 610 * string was truncated. 611 */ 612 int av_channel_name(char* buf, size_t buf_size, enum AVChannel channel); 613 614 /** 615 * bprint variant of av_channel_name(). 616 * 617 * @note the string will be appended to the bprint buffer. 618 */ 619 void av_channel_name_bprint(struct AVBPrint* bp, enum AVChannel channel_id); 620 621 /** 622 * Get a human readable string describing a given channel. 623 * 624 * @param buf pre-allocated buffer where to put the generated string 625 * @param buf_size size in bytes of the buffer. 626 * @param channel the AVChannel whose description to get 627 * @return amount of bytes needed to hold the output string, or a negative 628 * AVERROR on failure. If the returned value is bigger than buf_size, then the 629 * string was truncated. 630 */ 631 int av_channel_description(char* buf, size_t buf_size, enum AVChannel channel); 632 633 /** 634 * bprint variant of av_channel_description(). 635 * 636 * @note the string will be appended to the bprint buffer. 637 */ 638 void av_channel_description_bprint(struct AVBPrint* bp, 639 enum AVChannel channel_id); 640 641 /** 642 * This is the inverse function of @ref av_channel_name(). 643 * 644 * @return the channel with the given name 645 * AV_CHAN_NONE when name does not identify a known channel 646 */ 647 enum AVChannel av_channel_from_string(const char* name); 648 649 /** 650 * Initialize a native channel layout from a bitmask indicating which channels 651 * are present. 652 * 653 * @param channel_layout the layout structure to be initialized 654 * @param mask bitmask describing the channel layout 655 * 656 * @return 0 on success 657 * AVERROR(EINVAL) for invalid mask values 658 */ 659 int av_channel_layout_from_mask(AVChannelLayout* channel_layout, uint64_t mask); 660 661 /** 662 * Initialize a channel layout from a given string description. 663 * The input string can be represented by: 664 * - the formal channel layout name (returned by av_channel_layout_describe()) 665 * - single or multiple channel names (returned by av_channel_name(), eg. "FL", 666 * or concatenated with "+", each optionally containing a custom name after 667 * a "@", eg. "FL@Left+FR@Right+LFE") 668 * - a decimal or hexadecimal value of a native channel layout (eg. "4" or 669 * "0x4") 670 * - the number of channels with default layout (eg. "4c") 671 * - the number of unordered channels (eg. "4C" or "4 channels") 672 * - the ambisonic order followed by optional non-diegetic channels (eg. 673 * "ambisonic 2+stereo") 674 * 675 * @param channel_layout input channel layout 676 * @param str string describing the channel layout 677 * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise 678 */ 679 int av_channel_layout_from_string(AVChannelLayout* channel_layout, 680 const char* str); 681 682 /** 683 * Get the default channel layout for a given number of channels. 684 * 685 * @param ch_layout the layout structure to be initialized 686 * @param nb_channels number of channels 687 */ 688 void av_channel_layout_default(AVChannelLayout* ch_layout, int nb_channels); 689 690 /** 691 * Iterate over all standard channel layouts. 692 * 693 * @param opaque a pointer where libavutil will store the iteration state. Must 694 * point to NULL to start the iteration. 695 * 696 * @return the standard channel layout or NULL when the iteration is 697 * finished 698 */ 699 const AVChannelLayout* av_channel_layout_standard(void** opaque); 700 701 /** 702 * Free any allocated data in the channel layout and reset the channel 703 * count to 0. 704 * 705 * @param channel_layout the layout structure to be uninitialized 706 */ 707 void av_channel_layout_uninit(AVChannelLayout* channel_layout); 708 709 /** 710 * Make a copy of a channel layout. This differs from just assigning src to dst 711 * in that it allocates and copies the map for AV_CHANNEL_ORDER_CUSTOM. 712 * 713 * @note the destination channel_layout will be always uninitialized before 714 * copy. 715 * 716 * @param dst destination channel layout 717 * @param src source channel layout 718 * @return 0 on success, a negative AVERROR on error. 719 */ 720 int av_channel_layout_copy(AVChannelLayout* dst, const AVChannelLayout* src); 721 722 /** 723 * Get a human-readable string describing the channel layout properties. 724 * The string will be in the same format that is accepted by 725 * @ref av_channel_layout_from_string(), allowing to rebuild the same 726 * channel layout, except for opaque pointers. 727 * 728 * @param channel_layout channel layout to be described 729 * @param buf pre-allocated buffer where to put the generated string 730 * @param buf_size size in bytes of the buffer. 731 * @return amount of bytes needed to hold the output string, or a negative 732 * AVERROR on failure. If the returned value is bigger than buf_size, then the 733 * string was truncated. 734 */ 735 int av_channel_layout_describe(const AVChannelLayout* channel_layout, char* buf, 736 size_t buf_size); 737 738 /** 739 * bprint variant of av_channel_layout_describe(). 740 * 741 * @note the string will be appended to the bprint buffer. 742 * @return 0 on success, or a negative AVERROR value on failure. 743 */ 744 int av_channel_layout_describe_bprint(const AVChannelLayout* channel_layout, 745 struct AVBPrint* bp); 746 747 /** 748 * Get the channel with the given index in a channel layout. 749 * 750 * @param channel_layout input channel layout 751 * @param idx index of the channel 752 * @return channel with the index idx in channel_layout on success or 753 * AV_CHAN_NONE on failure (if idx is not valid or the channel order is 754 * unspecified) 755 */ 756 enum AVChannel av_channel_layout_channel_from_index( 757 const AVChannelLayout* channel_layout, unsigned int idx); 758 759 /** 760 * Get the index of a given channel in a channel layout. In case multiple 761 * channels are found, only the first match will be returned. 762 * 763 * @param channel_layout input channel layout 764 * @param channel the channel whose index to obtain 765 * @return index of channel in channel_layout on success or a negative number if 766 * channel is not present in channel_layout. 767 */ 768 int av_channel_layout_index_from_channel(const AVChannelLayout* channel_layout, 769 enum AVChannel channel); 770 771 /** 772 * Get the index in a channel layout of a channel described by the given string. 773 * In case multiple channels are found, only the first match will be returned. 774 * 775 * This function accepts channel names in the same format as 776 * @ref av_channel_from_string(). 777 * 778 * @param channel_layout input channel layout 779 * @param name string describing the channel whose index to obtain 780 * @return a channel index described by the given string, or a negative AVERROR 781 * value. 782 */ 783 int av_channel_layout_index_from_string(const AVChannelLayout* channel_layout, 784 const char* name); 785 786 /** 787 * Get a channel described by the given string. 788 * 789 * This function accepts channel names in the same format as 790 * @ref av_channel_from_string(). 791 * 792 * @param channel_layout input channel layout 793 * @param name string describing the channel to obtain 794 * @return a channel described by the given string in channel_layout on success 795 * or AV_CHAN_NONE on failure (if the string is not valid or the channel 796 * order is unspecified) 797 */ 798 enum AVChannel av_channel_layout_channel_from_string( 799 const AVChannelLayout* channel_layout, const char* name); 800 801 /** 802 * Find out what channels from a given set are present in a channel layout, 803 * without regard for their positions. 804 * 805 * @param channel_layout input channel layout 806 * @param mask a combination of AV_CH_* representing a set of channels 807 * @return a bitfield representing all the channels from mask that are present 808 * in channel_layout 809 */ 810 uint64_t av_channel_layout_subset(const AVChannelLayout* channel_layout, 811 uint64_t mask); 812 813 /** 814 * Check whether a channel layout is valid, i.e. can possibly describe audio 815 * data. 816 * 817 * @param channel_layout input channel layout 818 * @return 1 if channel_layout is valid, 0 otherwise. 819 */ 820 int av_channel_layout_check(const AVChannelLayout* channel_layout); 821 822 /** 823 * Check whether two channel layouts are semantically the same, i.e. the same 824 * channels are present on the same positions in both. 825 * 826 * If one of the channel layouts is AV_CHANNEL_ORDER_UNSPEC, while the other is 827 * not, they are considered to be unequal. If both are AV_CHANNEL_ORDER_UNSPEC, 828 * they are considered equal iff the channel counts are the same in both. 829 * 830 * @param chl input channel layout 831 * @param chl1 input channel layout 832 * @return 0 if chl and chl1 are equal, 1 if they are not equal. A negative 833 * AVERROR code if one or both are invalid. 834 */ 835 int av_channel_layout_compare(const AVChannelLayout* chl, 836 const AVChannelLayout* chl1); 837 838 /** 839 * @} 840 */ 841 842 #endif /* AVUTIL_CHANNEL_LAYOUT_H */