FFmpeg 7.1.3
Loading...
Searching...
No Matches
channel_layout.h
Go to the documentation of this file.
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/**
39 * @defgroup lavu_audio_channels Audio channels
40 * @ingroup lavu_audio
41 *
42 * Audio channel layout utility functions
43 *
44 * @{
45 */
46
48 ///< Invalid channel index
68 /** Stereo downmix. */
70 /** See above. */
82 AV_CHAN_SIDE_SURROUND_LEFT, ///< +90 degrees, Lss, SiL
83 AV_CHAN_SIDE_SURROUND_RIGHT, ///< -90 degrees, Rss, SiR
84 AV_CHAN_TOP_SURROUND_LEFT, ///< +110 degrees, Lvs, TpLS
85 AV_CHAN_TOP_SURROUND_RIGHT, ///< -110 degrees, Rvs, TpRS
86
87 /** Channel is empty can be safely skipped. */
89
90 /** Channel contains data, but its position is unknown. */
92
93 /**
94 * Range of channels between AV_CHAN_AMBISONIC_BASE and
95 * AV_CHAN_AMBISONIC_END represent Ambisonic components using the ACN system.
96 *
97 * Given a channel id `<i>` between AV_CHAN_AMBISONIC_BASE and
98 * AV_CHAN_AMBISONIC_END (inclusive), the ACN index of the channel `<n>` is
99 * `<n> = <i> - AV_CHAN_AMBISONIC_BASE`.
100 *
101 * @note these values are only used for AV_CHANNEL_ORDER_CUSTOM channel
102 * orderings, the AV_CHANNEL_ORDER_AMBISONIC ordering orders the channels
103 * implicitly by their position in the stream.
104 */
106 // leave space for 1024 ids, which correspond to maximum order-32 harmonics,
107 // which should be enough for the foreseeable use cases
109};
110
112 /**
113 * Only the channel count is specified, without any further information
114 * about the channel order.
115 */
117 /**
118 * The native channel order, i.e. the channels are in the same order in
119 * which they are defined in the AVChannel enum. This supports up to 63
120 * different channels.
121 */
123 /**
124 * The channel order does not correspond to any other predefined order and
125 * is stored as an explicit map. For example, this could be used to support
126 * layouts with 64 or more channels, or with empty/skipped (AV_CHAN_UNUSED)
127 * channels at arbitrary positions.
128 */
130 /**
131 * The audio is represented as the decomposition of the sound field into
132 * spherical harmonics. Each channel corresponds to a single expansion
133 * component. Channels are ordered according to ACN (Ambisonic Channel
134 * Number).
135 *
136 * The channel with the index n in the stream contains the spherical
137 * harmonic of degree l and order m given by
138 * @code{.unparsed}
139 * l = floor(sqrt(n)),
140 * m = n - l * (l + 1).
141 * @endcode
142 *
143 * Conversely given a spherical harmonic of degree l and order m, the
144 * corresponding channel index n is given by
145 * @code{.unparsed}
146 * n = l * (l + 1) + m.
147 * @endcode
148 *
149 * Normalization is assumed to be SN3D (Schmidt Semi-Normalization)
150 * as defined in AmbiX format $ 2.1.
151 */
153 /**
154 * Number of channel orders, not part of ABI/API
155 */
158
159
160/**
161 * @defgroup channel_masks Audio channel masks
162 *
163 * A channel layout is a 64-bits integer with a bit set for every channel.
164 * The number of bits set must be equal to the number of channels.
165 * The value 0 means that the channel layout is not known.
166 * @note this data structure is not powerful enough to handle channels
167 * combinations that have the same channel multiple times, such as
168 * dual-mono.
169 *
170 * @{
171 */
172#define AV_CH_FRONT_LEFT (1ULL << AV_CHAN_FRONT_LEFT )
173#define AV_CH_FRONT_RIGHT (1ULL << AV_CHAN_FRONT_RIGHT )
174#define AV_CH_FRONT_CENTER (1ULL << AV_CHAN_FRONT_CENTER )
175#define AV_CH_LOW_FREQUENCY (1ULL << AV_CHAN_LOW_FREQUENCY )
176#define AV_CH_BACK_LEFT (1ULL << AV_CHAN_BACK_LEFT )
177#define AV_CH_BACK_RIGHT (1ULL << AV_CHAN_BACK_RIGHT )
178#define AV_CH_FRONT_LEFT_OF_CENTER (1ULL << AV_CHAN_FRONT_LEFT_OF_CENTER )
179#define AV_CH_FRONT_RIGHT_OF_CENTER (1ULL << AV_CHAN_FRONT_RIGHT_OF_CENTER)
180#define AV_CH_BACK_CENTER (1ULL << AV_CHAN_BACK_CENTER )
181#define AV_CH_SIDE_LEFT (1ULL << AV_CHAN_SIDE_LEFT )
182#define AV_CH_SIDE_RIGHT (1ULL << AV_CHAN_SIDE_RIGHT )
183#define AV_CH_TOP_CENTER (1ULL << AV_CHAN_TOP_CENTER )
184#define AV_CH_TOP_FRONT_LEFT (1ULL << AV_CHAN_TOP_FRONT_LEFT )
185#define AV_CH_TOP_FRONT_CENTER (1ULL << AV_CHAN_TOP_FRONT_CENTER )
186#define AV_CH_TOP_FRONT_RIGHT (1ULL << AV_CHAN_TOP_FRONT_RIGHT )
187#define AV_CH_TOP_BACK_LEFT (1ULL << AV_CHAN_TOP_BACK_LEFT )
188#define AV_CH_TOP_BACK_CENTER (1ULL << AV_CHAN_TOP_BACK_CENTER )
189#define AV_CH_TOP_BACK_RIGHT (1ULL << AV_CHAN_TOP_BACK_RIGHT )
190#define AV_CH_STEREO_LEFT (1ULL << AV_CHAN_STEREO_LEFT )
191#define AV_CH_STEREO_RIGHT (1ULL << AV_CHAN_STEREO_RIGHT )
192#define AV_CH_WIDE_LEFT (1ULL << AV_CHAN_WIDE_LEFT )
193#define AV_CH_WIDE_RIGHT (1ULL << AV_CHAN_WIDE_RIGHT )
194#define AV_CH_SURROUND_DIRECT_LEFT (1ULL << AV_CHAN_SURROUND_DIRECT_LEFT )
195#define AV_CH_SURROUND_DIRECT_RIGHT (1ULL << AV_CHAN_SURROUND_DIRECT_RIGHT)
196#define AV_CH_LOW_FREQUENCY_2 (1ULL << AV_CHAN_LOW_FREQUENCY_2 )
197#define AV_CH_TOP_SIDE_LEFT (1ULL << AV_CHAN_TOP_SIDE_LEFT )
198#define AV_CH_TOP_SIDE_RIGHT (1ULL << AV_CHAN_TOP_SIDE_RIGHT )
199#define AV_CH_BOTTOM_FRONT_CENTER (1ULL << AV_CHAN_BOTTOM_FRONT_CENTER )
200#define AV_CH_BOTTOM_FRONT_LEFT (1ULL << AV_CHAN_BOTTOM_FRONT_LEFT )
201#define AV_CH_BOTTOM_FRONT_RIGHT (1ULL << AV_CHAN_BOTTOM_FRONT_RIGHT )
202#define AV_CH_SIDE_SURROUND_LEFT (1ULL << AV_CHAN_SIDE_SURROUND_LEFT )
203#define AV_CH_SIDE_SURROUND_RIGHT (1ULL << AV_CHAN_SIDE_SURROUND_RIGHT )
204#define AV_CH_TOP_SURROUND_LEFT (1ULL << AV_CHAN_TOP_SURROUND_LEFT )
205#define AV_CH_TOP_SURROUND_RIGHT (1ULL << AV_CHAN_TOP_SURROUND_RIGHT )
206
207/**
208 * @}
209 * @defgroup channel_mask_c Audio channel layouts
210 * @{
211 * */
212#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER)
213#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT)
214#define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY)
215#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER)
216#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER)
217#define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY)
218#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER)
219#define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY)
220#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
221#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
222#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT)
223#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY)
224#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
225#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY)
226#define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER)
227#define AV_CH_LAYOUT_6POINT0_FRONT (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
228#define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER)
229#define AV_CH_LAYOUT_3POINT1POINT2 (AV_CH_LAYOUT_3POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)
230#define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER)
231#define AV_CH_LAYOUT_6POINT1_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER)
232#define AV_CH_LAYOUT_6POINT1_FRONT (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY)
233#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
234#define AV_CH_LAYOUT_7POINT0_FRONT (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
235#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT)
236#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
237#define AV_CH_LAYOUT_7POINT1_WIDE_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
238#define AV_CH_LAYOUT_5POINT1POINT2_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)
239#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT)
240#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)
241#define AV_CH_LAYOUT_5POINT1POINT4_BACK (AV_CH_LAYOUT_5POINT1POINT2_BACK|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)
242#define AV_CH_LAYOUT_7POINT1POINT2 (AV_CH_LAYOUT_7POINT1|AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT)
243#define AV_CH_LAYOUT_7POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_LEFT|AV_CH_TOP_BACK_RIGHT)
244#define AV_CH_LAYOUT_7POINT2POINT3 (AV_CH_LAYOUT_7POINT1POINT2|AV_CH_TOP_BACK_CENTER|AV_CH_LOW_FREQUENCY_2)
245#define AV_CH_LAYOUT_9POINT1POINT4_BACK (AV_CH_LAYOUT_7POINT1POINT4_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER)
246#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)
247#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT)
248#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)
249
250#define AV_CH_LAYOUT_7POINT1_TOP_BACK AV_CH_LAYOUT_5POINT1POINT2_BACK
251
262
263/**
264 * @}
265 */
266
267/**
268 * An AVChannelCustom defines a single channel within a custom order layout
269 *
270 * Unlike most structures in FFmpeg, sizeof(AVChannelCustom) is a part of the
271 * public ABI.
272 *
273 * No new fields may be added to it without a major version bump.
274 */
275typedef struct AVChannelCustom {
277 char name[16];
278 void *opaque;
280
281/**
282 * An AVChannelLayout holds information about the channel layout of audio data.
283 *
284 * A channel layout here is defined as a set of channels ordered in a specific
285 * way (unless the channel order is AV_CHANNEL_ORDER_UNSPEC, in which case an
286 * AVChannelLayout carries only the channel count).
287 * All orders may be treated as if they were AV_CHANNEL_ORDER_UNSPEC by
288 * ignoring everything but the channel count, as long as av_channel_layout_check()
289 * considers they are valid.
290 *
291 * Unlike most structures in FFmpeg, sizeof(AVChannelLayout) is a part of the
292 * public ABI and may be used by the caller. E.g. it may be allocated on stack
293 * or embedded in caller-defined structs.
294 *
295 * AVChannelLayout can be initialized as follows:
296 * - default initialization with {0}, followed by setting all used fields
297 * correctly;
298 * - by assigning one of the predefined AV_CHANNEL_LAYOUT_* initializers;
299 * - with a constructor function, such as av_channel_layout_default(),
300 * av_channel_layout_from_mask() or av_channel_layout_from_string().
301 *
302 * The channel layout must be unitialized with av_channel_layout_uninit()
303 *
304 * Copying an AVChannelLayout via assigning is forbidden,
305 * av_channel_layout_copy()