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