channel_layout.h 31 KB

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