FFmpeg
channel_layout.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * audio channel layout utility functions
24  */
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "avassert.h"
31 #include "channel_layout.h"
32 #include "bprint.h"
33 #include "common.h"
34 #include "error.h"
35 #include "macros.h"
36 #include "opt.h"
37 
38 #define CHAN_IS_AMBI(x) ((x) >= AV_CHAN_AMBISONIC_BASE &&\
39  (x) <= AV_CHAN_AMBISONIC_END)
40 
41 struct channel_name {
42  const char *name;
43  const char *description;
44 };
45 
46 static const struct channel_name channel_names[] = {
47  [AV_CHAN_FRONT_LEFT ] = { "FL", "front left" },
48  [AV_CHAN_FRONT_RIGHT ] = { "FR", "front right" },
49  [AV_CHAN_FRONT_CENTER ] = { "FC", "front center" },
50  [AV_CHAN_LOW_FREQUENCY ] = { "LFE", "low frequency" },
51  [AV_CHAN_BACK_LEFT ] = { "BL", "back left" },
52  [AV_CHAN_BACK_RIGHT ] = { "BR", "back right" },
53  [AV_CHAN_FRONT_LEFT_OF_CENTER ] = { "FLC", "front left-of-center" },
54  [AV_CHAN_FRONT_RIGHT_OF_CENTER] = { "FRC", "front right-of-center" },
55  [AV_CHAN_BACK_CENTER ] = { "BC", "back center" },
56  [AV_CHAN_SIDE_LEFT ] = { "SL", "side left" },
57  [AV_CHAN_SIDE_RIGHT ] = { "SR", "side right" },
58  [AV_CHAN_TOP_CENTER ] = { "TC", "top center" },
59  [AV_CHAN_TOP_FRONT_LEFT ] = { "TFL", "top front left" },
60  [AV_CHAN_TOP_FRONT_CENTER ] = { "TFC", "top front center" },
61  [AV_CHAN_TOP_FRONT_RIGHT ] = { "TFR", "top front right" },
62  [AV_CHAN_TOP_BACK_LEFT ] = { "TBL", "top back left" },
63  [AV_CHAN_TOP_BACK_CENTER ] = { "TBC", "top back center" },
64  [AV_CHAN_TOP_BACK_RIGHT ] = { "TBR", "top back right" },
65  [AV_CHAN_STEREO_LEFT ] = { "DL", "downmix left" },
66  [AV_CHAN_STEREO_RIGHT ] = { "DR", "downmix right" },
67  [AV_CHAN_WIDE_LEFT ] = { "WL", "wide left" },
68  [AV_CHAN_WIDE_RIGHT ] = { "WR", "wide right" },
69  [AV_CHAN_SURROUND_DIRECT_LEFT ] = { "SDL", "surround direct left" },
70  [AV_CHAN_SURROUND_DIRECT_RIGHT] = { "SDR", "surround direct right" },
71  [AV_CHAN_LOW_FREQUENCY_2 ] = { "LFE2", "low frequency 2" },
72  [AV_CHAN_TOP_SIDE_LEFT ] = { "TSL", "top side left" },
73  [AV_CHAN_TOP_SIDE_RIGHT ] = { "TSR", "top side right" },
74  [AV_CHAN_BOTTOM_FRONT_CENTER ] = { "BFC", "bottom front center" },
75  [AV_CHAN_BOTTOM_FRONT_LEFT ] = { "BFL", "bottom front left" },
76  [AV_CHAN_BOTTOM_FRONT_RIGHT ] = { "BFR", "bottom front right" },
77 };
78 
79 void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
80 {
81  if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
82  channel_id <= AV_CHAN_AMBISONIC_END)
83  av_bprintf(bp, "AMBI%d", channel_id - AV_CHAN_AMBISONIC_BASE);
84  else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) &&
85  channel_names[channel_id].name)
86  av_bprintf(bp, "%s", channel_names[channel_id].name);
87  else if (channel_id == AV_CHAN_NONE)
88  av_bprintf(bp, "NONE");
89  else if (channel_id == AV_CHAN_UNKNOWN)
90  av_bprintf(bp, "UNK");
91  else if (channel_id == AV_CHAN_UNUSED)
92  av_bprintf(bp, "UNSD");
93  else
94  av_bprintf(bp, "USR%d", channel_id);
95 }
96 
97 int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
98 {
99  AVBPrint bp;
100 
101  if (!buf && buf_size)
102  return AVERROR(EINVAL);
103 
104  av_bprint_init_for_buffer(&bp, buf, buf_size);
105  av_channel_name_bprint(&bp, channel_id);
106 
107  if (bp.len >= INT_MAX)
108  return AVERROR(ERANGE);
109  return bp.len + 1;
110 }
111 
112 void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
113 {
114  if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
115  channel_id <= AV_CHAN_AMBISONIC_END)
116  av_bprintf(bp, "ambisonic ACN %d", channel_id - AV_CHAN_AMBISONIC_BASE);
117  else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) &&
118  channel_names[channel_id].description)
119  av_bprintf(bp, "%s", channel_names[channel_id].description);
120  else if (channel_id == AV_CHAN_NONE)
121  av_bprintf(bp, "none");
122  else if (channel_id == AV_CHAN_UNKNOWN)
123  av_bprintf(bp, "unknown");
124  else if (channel_id == AV_CHAN_UNUSED)
125  av_bprintf(bp, "unused");
126  else
127  av_bprintf(bp, "user %d", channel_id);
128 }
129 
130 int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel_id)
131 {
132  AVBPrint bp;
133 
134  if (!buf && buf_size)
135  return AVERROR(EINVAL);
136 
137  av_bprint_init_for_buffer(&bp, buf, buf_size);
138  av_channel_description_bprint(&bp, channel_id);
139 
140  if (bp.len >= INT_MAX)
141  return AVERROR(ERANGE);
142  return bp.len + 1;
143 }
144 
145 enum AVChannel av_channel_from_string(const char *str)
146 {
147  int i;
148  char *endptr = (char *)str;
149  enum AVChannel id = AV_CHAN_NONE;
150 
151  if (!strncmp(str, "AMBI", 4)) {
152  i = strtol(str + 4, NULL, 0);
154  return AV_CHAN_NONE;
155  return AV_CHAN_AMBISONIC_BASE + i;
156  }
157 
158  for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
159  if (channel_names[i].name && !strcmp(str, channel_names[i].name))
160  return i;
161  }
162  if (!strcmp(str, "UNK"))
163  return AV_CHAN_UNKNOWN;
164  if (!strcmp(str, "UNSD"))
165  return AV_CHAN_UNUSED;
166 
167  if (!strncmp(str, "USR", 3)) {
168  const char *p = str + 3;
169  id = strtol(p, &endptr, 0);
170  }
171  if (id >= 0 && !*endptr)
172  return id;
173 
174  return AV_CHAN_NONE;
175 }
176 
178  const char *name;
180 };
181 
182 static const struct channel_layout_name channel_layout_map[] = {
183  { "mono", AV_CHANNEL_LAYOUT_MONO },
184  { "stereo", AV_CHANNEL_LAYOUT_STEREO },
185  { "2.1", AV_CHANNEL_LAYOUT_2POINT1 },
186  { "3.0", AV_CHANNEL_LAYOUT_SURROUND },
187  { "3.0(back)", AV_CHANNEL_LAYOUT_2_1 },
188  { "4.0", AV_CHANNEL_LAYOUT_4POINT0 },
189  { "quad", AV_CHANNEL_LAYOUT_QUAD },
190  { "quad(side)", AV_CHANNEL_LAYOUT_2_2 },
191  { "3.1", AV_CHANNEL_LAYOUT_3POINT1 },
193  { "5.0(side)", AV_CHANNEL_LAYOUT_5POINT0 },
194  { "4.1", AV_CHANNEL_LAYOUT_4POINT1 },
196  { "5.1(side)", AV_CHANNEL_LAYOUT_5POINT1 },
197  { "6.0", AV_CHANNEL_LAYOUT_6POINT0 },
198  { "6.0(front)", AV_CHANNEL_LAYOUT_6POINT0_FRONT },
199  { "3.1.2", AV_CHANNEL_LAYOUT_3POINT1POINT2 },
200  { "hexagonal", AV_CHANNEL_LAYOUT_HEXAGONAL },
201  { "6.1", AV_CHANNEL_LAYOUT_6POINT1 },
202  { "6.1(back)", AV_CHANNEL_LAYOUT_6POINT1_BACK },
203  { "6.1(front)", AV_CHANNEL_LAYOUT_6POINT1_FRONT },
204  { "7.0", AV_CHANNEL_LAYOUT_7POINT0 },
205  { "7.0(front)", AV_CHANNEL_LAYOUT_7POINT0_FRONT },
206  { "7.1", AV_CHANNEL_LAYOUT_7POINT1 },
207  { "7.1(wide)", AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK },
208  { "7.1(wide-side)", AV_CHANNEL_LAYOUT_7POINT1_WIDE },
210  { "octagonal", AV_CHANNEL_LAYOUT_OCTAGONAL },
211  { "cube", AV_CHANNEL_LAYOUT_CUBE },
213  { "7.1.2", AV_CHANNEL_LAYOUT_7POINT1POINT2 },
215  { "7.2.3", AV_CHANNEL_LAYOUT_7POINT2POINT3 },
217  { "hexadecagonal", AV_CHANNEL_LAYOUT_HEXADECAGONAL },
218  { "downmix", AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, },
219  { "22.2", AV_CHANNEL_LAYOUT_22POINT2, },
220 };
221 
222 int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
223 {
225 
226  if (nb_channels <= 0)
227  return AVERROR(EINVAL);
228 
229  map = av_calloc(nb_channels, sizeof(*channel_layout->u.map));
230  if (!map)
231  return AVERROR(ENOMEM);
232  for (int i = 0; i < nb_channels; i++)
233  map[i].id = AV_CHAN_UNKNOWN;
234 
235  channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
236  channel_layout->nb_channels = nb_channels;
237  channel_layout->u.map = map;
238 
239  return 0;
240 }
241 
243  uint64_t mask)
244 {
245  if (!mask)
246  return AVERROR(EINVAL);
247 
248  channel_layout->order = AV_CHANNEL_ORDER_NATIVE;
249  channel_layout->nb_channels = av_popcount64(mask);
250  channel_layout->u.mask = mask;
251 
252  return 0;
253 }
254 
255 static int parse_channel_list(AVChannelLayout *ch_layout, const char *str)
256 {
257  int ret;
258  int nb_channels = 0;
260  AVChannelCustom custom = {0};
261 
262  while (*str) {
263  char *channel, *chname;
264  int ret = av_opt_get_key_value(&str, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname);
265  if (ret < 0) {
266  av_freep(&map);
267  return ret;
268  }
269  if (*str)
270  str++; // skip separator
271  if (!channel) {
272  channel = chname;
273  chname = NULL;
274  }
275  av_strlcpy(custom.name, chname ? chname : "", sizeof(custom.name));
277  av_free(channel);
278  av_free(chname);
279  if (custom.id == AV_CHAN_NONE) {
280  av_freep(&map);
281  return AVERROR(EINVAL);
282  }
283 
284  av_dynarray2_add((void **)&map, &nb_channels, sizeof(custom), (void *)&custom);
285  if (!map)
286  return AVERROR(ENOMEM);
287  }
288 
289  if (!nb_channels)
290  return AVERROR(EINVAL);
291 
292  ch_layout->order = AV_CHANNEL_ORDER_CUSTOM;
293  ch_layout->u.map = map;
294  ch_layout->nb_channels = nb_channels;
295 
297  av_assert0(ret == 0);
298 
299  return 0;
300 }
301 
303  const char *str)
304 {
305  int i, matches, ret;
306  int channels = 0, nb_channels = 0;
307  char *chlist, *end;
308  uint64_t mask = 0;
309 
310  /* channel layout names */
311  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
312  if (channel_layout_map[i].name && !strcmp(str, channel_layout_map[i].name)) {
313  *channel_layout = channel_layout_map[i].layout;
314  return 0;
315  }
316  }
317 
318  /* This function is a channel layout initializer, so we have to
319  * zero-initialize before we start setting fields individually. */
320  memset(channel_layout, 0, sizeof(*channel_layout));
321 
322  /* ambisonic */
323  if (!strncmp(str, "ambisonic ", 10)) {
324  const char *p = str + 10;
325  char *endptr;
326  AVChannelLayout extra = {0};
327  int order;
328 
329  order = strtol(p, &endptr, 0);
330  if (order < 0 || order + 1 > INT_MAX / (order + 1) ||
331  (*endptr && *endptr != '+'))
332  return AVERROR(EINVAL);
333 
334  channel_layout->order = AV_CHANNEL_ORDER_AMBISONIC;
335  channel_layout->nb_channels = (order + 1) * (order + 1);
336 
337  if (*endptr) {
338  int ret = av_channel_layout_from_string(&extra, endptr + 1);
339  if (ret < 0)
340  return ret;
341  if (extra.nb_channels >= INT_MAX - channel_layout->nb_channels) {
342  av_channel_layout_uninit(&extra);
343  return AVERROR(EINVAL);
344  }
345 
346  if (extra.order == AV_CHANNEL_ORDER_NATIVE) {
347  channel_layout->u.mask = extra.u.mask;
348  } else {
349  channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
350  channel_layout->u.map =
351  av_calloc(channel_layout->nb_channels + extra.nb_channels,
352  sizeof(*channel_layout->u.map));
353  if (!channel_layout->u.map) {
354  av_channel_layout_uninit(&extra);
355  return AVERROR(ENOMEM);
356  }
357 
358  for (i = 0; i < channel_layout->nb_channels; i++)
359  channel_layout->u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
360  for (i = 0; i < extra.nb_channels; i++) {
362  if (CHAN_IS_AMBI(ch)) {
363  av_channel_layout_uninit(channel_layout);
364  av_channel_layout_uninit(&extra);
365  return AVERROR(EINVAL);
366  }
367  channel_layout->u.map[channel_layout->nb_channels + i].id = ch;
368  if (extra.order == AV_CHANNEL_ORDER_CUSTOM &&
369  extra.u.map[i].name[0])
370  av_strlcpy(channel_layout->u.map[channel_layout->nb_channels + i].name,
371  extra.u.map[i].name,
372  sizeof(channel_layout->u.map[channel_layout->nb_channels + i].name));
373  }
374  }
375  channel_layout->nb_channels += extra.nb_channels;
376  av_channel_layout_uninit(&extra);
377  }
378 
379  return 0;
380  }
381 
382  chlist = av_strdup(str);
383  if (!chlist)
384  return AVERROR(ENOMEM);
385 
386  /* channel names */
387  matches = av_sscanf(str, "%d channels (%[^)]", &nb_channels, chlist);
388  ret = parse_channel_list(channel_layout, chlist);
389  av_freep(&chlist);
390  if (ret < 0 && ret != AVERROR(EINVAL))
391  return ret;
392 
393  if (ret >= 0) {
394  end = strchr(str, ')');
395  if (matches == 2 && (nb_channels != channel_layout->nb_channels || !end || *++end)) {
396  av_channel_layout_uninit(channel_layout);
397  return AVERROR(EINVAL);
398  }
399  return 0;
400  }
401 
402  errno = 0;
403  mask = strtoull(str, &end, 0);
404 
405  /* channel layout mask */
406  if (!errno && !*end && !strchr(str, '-') && mask) {
407  av_channel_layout_from_mask(channel_layout, mask);
408  return 0;
409  }
410 
411  errno = 0;
412  channels = strtol(str, &end, 10);
413 
414  /* number of channels */
415  if (!errno && !strcmp(end, "c") && channels > 0) {
416  av_channel_layout_default(channel_layout, channels);
417  if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE)
418  return 0;
419  }
420 
421  /* number of unordered channels */
422  if (!errno && (!strcmp(end, "C") || !strcmp(end, " channels"))
423  && channels > 0) {
424  channel_layout->order = AV_CHANNEL_ORDER_UNSPEC;
425  channel_layout->nb_channels = channels;
426  return 0;
427  }
428 
429  return AVERROR(EINVAL);
430 }
431 
433 {
434  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM)
435  av_freep(&channel_layout->u.map);
436  memset(channel_layout, 0, sizeof(*channel_layout));
437 }
438 
440 {
442  *dst = *src;
443  if (src->order == AV_CHANNEL_ORDER_CUSTOM) {
444  dst->u.map = av_malloc_array(src->nb_channels, sizeof(*dst->u.map));
445  if (!dst->u.map)
446  return AVERROR(ENOMEM);
447  memcpy(dst->u.map, src->u.map, src->nb_channels * sizeof(*src->u.map));
448  }
449  return 0;
450 }
451 
452 static int64_t masked_description(const AVChannelLayout *channel_layout, int start_channel)
453 {
454  uint64_t mask = 0;
455  for (int i = start_channel; i < channel_layout->nb_channels; i++) {
456  enum AVChannel ch = channel_layout->u.map[i].id;
457  if (ch >= 0 && ch < 63 && mask < (1ULL << ch))
458  mask |= (1ULL << ch);
459  else
460  return AVERROR(EINVAL);
461  }
462  return mask;
463 }
464 
465 static int has_channel_names(const AVChannelLayout *channel_layout)
466 {
467  if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
468  return 0;
469  for (int i = 0; i < channel_layout->nb_channels; i++)
470  if (channel_layout->u.map[i].name[0])
471  return 1;
472  return 0;
473 }
474 
475 /**
476  * If the layout is n-th order standard-order ambisonic, with optional
477  * extra non-diegetic channels at the end, return the order.
478  * Return a negative error code otherwise.
479  */
480 static int ambisonic_order(const AVChannelLayout *channel_layout)
481 {
482  int i, highest_ambi, order;
483 
484  highest_ambi = -1;
485  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC)
486  highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1;
487  else {
488  const AVChannelCustom *map = channel_layout->u.map;
489  av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM);
490 
491  for (i = 0; i < channel_layout->nb_channels; i++) {
492  int is_ambi = CHAN_IS_AMBI(map[i].id);
493 
494  /* ambisonic following non-ambisonic */
495  if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id))
496  return AVERROR(EINVAL);
497 
498  /* non-default ordering */
499  if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i)
500  return AVERROR(EINVAL);
501 
502  if (CHAN_IS_AMBI(map[i].id))
503  highest_ambi = i;
504  }
505  }
506  /* no ambisonic channels*/
507  if (highest_ambi < 0)
508  return AVERROR(EINVAL);
509 
510  order = floor(sqrt(highest_ambi));
511  /* incomplete order - some harmonics are missing */
512  if ((order + 1) * (order + 1) != highest_ambi + 1)
513  return AVERROR(EINVAL);
514 
515  return order;
516 }
517 
518 static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout)
519 {
520  int has_known_channel = 0;
521  int order;
522 
523  if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
524  return channel_layout->order;
525 
526  if (has_channel_names(channel_layout))
528 
529  for (int i = 0; i < channel_layout->nb_channels && !has_known_channel; i++)
530  if (channel_layout->u.map[i].id != AV_CHAN_UNKNOWN)
531  has_known_channel = 1;
532  if (!has_known_channel)
534 
535  if (masked_description(channel_layout, 0) > 0)
537 
538  order = ambisonic_order(channel_layout);
539  if (order >= 0 && masked_description(channel_layout, (order + 1) * (order + 1)) >= 0)
541 
543 }
544 
545 /**
546  * If the custom layout is n-th order standard-order ambisonic, with optional
547  * extra non-diegetic channels at the end, write its string description in bp.
548  * Return a negative error code otherwise.
549  */
550 static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout)
551 {
552  int nb_ambi_channels;
553  int order = ambisonic_order(channel_layout);
554  if (order < 0)
555  return order;
556 
557  av_bprintf(bp, "ambisonic %d", order);
558 
559  /* extra channels present */
560  nb_ambi_channels = (order + 1) * (order + 1);
561  if (nb_ambi_channels < channel_layout->nb_channels) {
562  AVChannelLayout extra = { 0 };
563 
564  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) {
566  extra.nb_channels = av_popcount64(channel_layout->u.mask);
567  extra.u.mask = channel_layout->u.mask;
568  } else {
569  int64_t mask;
570  if (!has_channel_names(channel_layout) &&
571  (mask = masked_description(channel_layout, nb_ambi_channels)) > 0) {
573  extra.nb_channels = av_popcount64(mask);
574  extra.u.mask = mask;
575  } else {
577  extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
578  extra.u.map = channel_layout->u.map + nb_ambi_channels;
579  }
580  }
581 
582  av_bprint_chars(bp, '+', 1);
584  /* Not calling uninit here on extra because we don't own the u.map pointer */
585  }
586 
587  return 0;
588 }
589 
591  AVBPrint *bp)
592 {
593  int i;
594 
595  switch (channel_layout->order) {
597  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
598  if (channel_layout->u.mask == channel_layout_map[i].layout.u.mask) {
599  av_bprintf(bp, "%s", channel_layout_map[i].name);
600  return 0;
601  }
602  // fall-through
604  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
605  int64_t mask;
606  int res = try_describe_ambisonic(bp, channel_layout);
607  if (res >= 0)
608  return 0;
609  if (!has_channel_names(channel_layout) &&
610  (mask = masked_description(channel_layout, 0)) > 0) {
612  .nb_channels = av_popcount64(mask),
613  .u.mask = mask };
614  return av_channel_layout_describe_bprint(&native, bp);
615  }
616  }
617  if (channel_layout->nb_channels)
618  av_bprintf(bp, "%d channels (", channel_layout->nb_channels);
619  for (i = 0; i < channel_layout->nb_channels; i++) {
620  enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i);
621 
622  if (i)
623  av_bprintf(bp, "+");
624  av_channel_name_bprint(bp, ch);
625  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM &&
626  channel_layout->u.map[i].name[0])
627  av_bprintf(bp, "@%s", channel_layout->u.map[i].name);
628  }
629  if (channel_layout->nb_channels) {
630  av_bprintf(bp, ")");
631  return 0;
632  }
633  // fall-through
635  av_bprintf(bp, "%d channels", channel_layout->nb_channels);
636  return 0;
638  return try_describe_ambisonic(bp, channel_layout);
639  default:
640  return AVERROR(EINVAL);
641  }
642 }
643 
644 int av_channel_layout_describe(const AVChannelLayout *channel_layout,
645  char *buf, size_t buf_size)
646 {
647  AVBPrint bp;
648  int ret;
649 
650  if (!buf && buf_size)
651  return AVERROR(EINVAL);
652 
653  av_bprint_init_for_buffer(&bp, buf, buf_size);
654  ret = av_channel_layout_describe_bprint(channel_layout, &bp);
655  if (ret < 0)
656  return ret;
657 
658  if (bp.len >= INT_MAX)
659  return AVERROR(ERANGE);
660  return bp.len + 1;
661 }
662 
663 enum AVChannel
665  unsigned int idx)
666 {
667  int i;
668 
669  if (idx >= channel_layout->nb_channels)
670  return AV_CHAN_NONE;
671 
672  switch (channel_layout->order) {
674  return channel_layout->u.map[idx].id;
676  int ambi_channels = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask);
677  if (idx < ambi_channels)
678  return AV_CHAN_AMBISONIC_BASE + idx;
679  idx -= ambi_channels;
680  }
681  // fall-through
683  for (i = 0; i < 64; i++) {
684  if ((1ULL << i) & channel_layout->u.mask && !idx--)
685  return i;
686  }
687  default:
688  return AV_CHAN_NONE;
689  }
690 }
691 
692 enum AVChannel
694  const char *str)
695 {
696  int index = av_channel_layout_index_from_string(channel_layout, str);
697 
698  if (index < 0)
699  return AV_CHAN_NONE;
700 
701  return av_channel_layout_channel_from_index(channel_layout, index);
702 }
703 
705  enum AVChannel channel)
706 {
707  int i;
708 
709  if (channel == AV_CHAN_NONE)
710  return AVERROR(EINVAL);
711 
712  switch (channel_layout->order) {
714  for (i = 0; i < channel_layout->nb_channels; i++)
715  if (channel_layout->u.map[i].id == channel)
716  return i;
717  return AVERROR(EINVAL);
720  uint64_t mask = channel_layout->u.mask;
721  int ambi_channels = channel_layout->nb_channels - av_popcount64(mask);
722  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC &&
724  if (channel - AV_CHAN_AMBISONIC_BASE >= ambi_channels)
725  return AVERROR(EINVAL);
727  }
728  if ((unsigned)channel > 63 || !(mask & (1ULL << channel)))
729  return AVERROR(EINVAL);
730  mask &= (1ULL << channel) - 1;
731  return av_popcount64(mask) + ambi_channels;
732  }
733  default:
734  return AVERROR(EINVAL);
735  }
736 }
737 
739  const char *str)
740 {
741  char *chname;
742  enum AVChannel ch = AV_CHAN_NONE;
743 
744  switch (channel_layout->order) {
746  chname = strstr(str, "@");
747  if (chname) {
748  char buf[16];
749  chname++;
750  av_strlcpy(buf, str, FFMIN(sizeof(buf), chname - str));
751  if (!*chname)
752  chname = NULL;
753  ch = av_channel_from_string(buf);
754  if (ch == AV_CHAN_NONE && *buf)
755  return AVERROR(EINVAL);
756  }
757  for (int i = 0; chname && i < channel_layout->nb_channels; i++) {
758  if (!strcmp(chname, channel_layout->u.map[i].name) &&
759  (ch == AV_CHAN_NONE || ch == channel_layout->u.map[i].id))
760  return i;
761  }
762  // fall-through
765  ch = av_channel_from_string(str);
766  if (ch == AV_CHAN_NONE)
767  return AVERROR(EINVAL);
768  return av_channel_layout_index_from_channel(channel_layout, ch);
769  }
770 
771  return AVERROR(EINVAL);
772 }
773 
774 int av_channel_layout_check(const AVChannelLayout *channel_layout)
775 {
776  if (channel_layout->nb_channels <= 0)
777  return 0;
778 
779  switch (channel_layout->order) {
781  return av_popcount64(channel_layout->u.mask) == channel_layout->nb_channels;
783  if (!channel_layout->u.map)
784  return 0;
785  for (int i = 0; i < channel_layout->nb_channels; i++) {
786  if (channel_layout->u.map[i].id == AV_CHAN_NONE)
787  return 0;
788  }
789  return 1;
791  /* If non-diegetic channels are present, ensure they are taken into account */
792  return av_popcount64(channel_layout->u.mask) < channel_layout->nb_channels;
794  return 1;
795  default:
796  return 0;
797  }
798 }
799 
801 {
802  int i;
803 
804  /* different channel counts -> not equal */
805  if (chl->nb_channels != chl1->nb_channels)
806  return 1;
807 
808  /* if only one is unspecified -> not equal */
809  if ((chl->order == AV_CHANNEL_ORDER_UNSPEC) !=
810  (chl1->order == AV_CHANNEL_ORDER_UNSPEC))
811  return 1;
812  /* both are unspecified -> equal */
813  else if (chl->order == AV_CHANNEL_ORDER_UNSPEC)
814  return 0;
815 
816  /* can compare masks directly */
817  if ((chl->order == AV_CHANNEL_ORDER_NATIVE ||
819  chl->order == chl1->order)
820  return chl->u.mask != chl1->u.mask;
821 
822  /* compare channel by channel */
823  for (i = 0; i < chl->nb_channels; i++)
826  return 1;
827  return 0;
828 }
829 
830 void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
831 {
832  int i;
833  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
834  if (nb_channels == channel_layout_map[i].layout.nb_channels) {
835  *ch_layout = channel_layout_map[i].layout;
836  return;
837  }
838 
839  ch_layout->order = AV_CHANNEL_ORDER_UNSPEC;
840  ch_layout->nb_channels = nb_channels;
841 }
842 
844 {
845  uintptr_t i = (uintptr_t)*opaque;
846  const AVChannelLayout *ch_layout = NULL;
847 
849  ch_layout = &channel_layout_map[i].layout;
850  *opaque = (void*)(i + 1);
851  }
852 
853  return ch_layout;
854 }
855 
856 uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,
857  uint64_t mask)
858 {
859  uint64_t ret = 0;
860  int i;
861 
862  switch (channel_layout->order) {
865  return channel_layout->u.mask & mask;
867  for (i = 0; i < 64; i++)
868  if (mask & (1ULL << i) && av_channel_layout_index_from_channel(channel_layout, i) >= 0)
869  ret |= (1ULL << i);
870  break;
871  }
872 
873  return ret;
874 }
875 
876 int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
877 {
878  int allow_lossy = !(flags & AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS);
879  int lossy;
880 
881  if (!av_channel_layout_check(channel_layout))
882  return AVERROR(EINVAL);
883 
885  order = canonical_order(channel_layout);
886 
887  if (channel_layout->order == order)
888  return 0;
889 
890  switch (order) {
892  int nb_channels = channel_layout->nb_channels;
893  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
894  lossy = 0;
895  for (int i = 0; i < nb_channels; i++) {
896  if (channel_layout->u.map[i].id != AV_CHAN_UNKNOWN || channel_layout->u.map[i].name[0]) {
897  lossy = 1;
898  break;
899  }
900  }
901  } else {
902  lossy = 1;
903  }
904  if (!lossy || allow_lossy) {
905  void *opaque = channel_layout->opaque;
906  av_channel_layout_uninit(channel_layout);
907  channel_layout->order = AV_CHANNEL_ORDER_UNSPEC;
908  channel_layout->nb_channels = nb_channels;
909  channel_layout->opaque = opaque;
910  return lossy;
911  }
912  return AVERROR(ENOSYS);
913  }
915  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
916  int64_t mask = masked_description(channel_layout, 0);
917  if (mask < 0)
918  return AVERROR(ENOSYS);
919  lossy = has_channel_names(channel_layout);
920  if (!lossy || allow_lossy) {
921  void *opaque = channel_layout->opaque;
922  av_channel_layout_uninit(channel_layout);
923  av_channel_layout_from_mask(channel_layout, mask);
924  channel_layout->opaque = opaque;
925  return lossy;
926  }
927  }
928  return AVERROR(ENOSYS);
930  AVChannelLayout custom = { 0 };
931  int ret = av_channel_layout_custom_init(&custom, channel_layout->nb_channels);
932  void *opaque = channel_layout->opaque;
933  if (ret < 0)
934  return ret;
935  if (channel_layout->order != AV_CHANNEL_ORDER_UNSPEC)
936  for (int i = 0; i < channel_layout->nb_channels; i++)
937  custom.u.map[i].id = av_channel_layout_channel_from_index(channel_layout, i);
938  av_channel_layout_uninit(channel_layout);
939  *channel_layout = custom;
940  channel_layout->opaque = opaque;
941  return 0;
942  }
944  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
945  int64_t mask;
946  int nb_channels = channel_layout->nb_channels;
947  int order = ambisonic_order(channel_layout);
948  if (order < 0)
949  return AVERROR(ENOSYS);
950  mask = masked_description(channel_layout, (order + 1) * (order + 1));
951  if (mask < 0)
952  return AVERROR(ENOSYS);
953  lossy = has_channel_names(channel_layout);
954  if (!lossy || allow_lossy) {
955  void *opaque = channel_layout->opaque;
956  av_channel_layout_uninit(channel_layout);
957  channel_layout->order = AV_CHANNEL_ORDER_AMBISONIC;
958  channel_layout->nb_channels = nb_channels;
959  channel_layout->u.mask = mask;
960  channel_layout->opaque = opaque;
961  return lossy;
962  }
963  }
964  return AVERROR(ENOSYS);
965  default:
966  return AVERROR(EINVAL);
967  }
968 }
AVChannelOrder
AVChannelOrder
Definition: channel_layout.h:107
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
Definition: channel_layout.h:413
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AV_CHANNEL_LAYOUT_OCTAGONAL
#define AV_CHANNEL_LAYOUT_OCTAGONAL
Definition: channel_layout.h:405
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK
Definition: channel_layout.h:409
AVChannelLayout::u
union AVChannelLayout::@352 u
Details about which channels are present in this layout.
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:379
AV_CHANNEL_LAYOUT_4POINT1
#define AV_CHANNEL_LAYOUT_4POINT1
Definition: channel_layout.h:385
AV_CHANNEL_LAYOUT_HEXAGONAL
#define AV_CHANNEL_LAYOUT_HEXAGONAL
Definition: channel_layout.h:395
av_popcount64
#define av_popcount64
Definition: common.h:155
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:72
int64_t
long long int64_t
Definition: coverity.c:34
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:354
ambisonic_order
static int ambisonic_order(const AVChannelLayout *channel_layout)
If the layout is n-th order standard-order ambisonic, with optional extra non-diegetic channels at th...
Definition: channel_layout.c:480
AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_2_2
Definition: channel_layout.h:386
av_channel_layout_channel_from_index
enum AVChannel av_channel_layout_channel_from_index(const AVChannelLayout *channel_layout, unsigned int idx)
Get the channel with the given index in a channel layout.
Definition: channel_layout.c:664
av_dynarray2_add
void * av_dynarray2_add(void **tab_ptr, int *nb_ptr, size_t elem_size, const uint8_t *elem_data)
Add an element of size elem_size to a dynamic array.
Definition: mem.c:341
channel_layout_name::name
const char * name
Definition: channel_layout.c:178
channel_name
Definition: channel_layout.c:41
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:308
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:335
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
AV_CHANNEL_LAYOUT_7POINT2POINT3
#define AV_CHANNEL_LAYOUT_7POINT2POINT3
Definition: channel_layout.h:410
channel_name::description
const char * description
Definition: channel_layout.c:43
av_channel_layout_describe_bprint
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
Definition: channel_layout.c:590
AV_CHANNEL_LAYOUT_7POINT1_WIDE
#define AV_CHANNEL_LAYOUT_7POINT1_WIDE
Definition: channel_layout.h:402
AV_CHAN_SURROUND_DIRECT_LEFT
@ AV_CHAN_SURROUND_DIRECT_LEFT
Definition: channel_layout.h:74
av_channel_description_bprint
void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
bprint variant of av_channel_description().
Definition: channel_layout.c:112
AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
Definition: channel_layout.h:411
av_bprint_init_for_buffer
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
Definition: bprint.c:85
AV_CHANNEL_LAYOUT_7POINT1POINT2
#define AV_CHANNEL_LAYOUT_7POINT1POINT2
Definition: channel_layout.h:408
AV_CHAN_TOP_BACK_RIGHT
@ AV_CHAN_TOP_BACK_RIGHT
Definition: channel_layout.h:67
macros.h
av_opt_get_key_value
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition: opt.c:1834
AV_CHANNEL_LAYOUT_2POINT1
#define AV_CHANNEL_LAYOUT_2POINT1
Definition: channel_layout.h:380
channel_name::name
const char * name
Definition: channel_layout.c:42
try_describe_ambisonic
static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout)
If the custom layout is n-th order standard-order ambisonic, with optional extra non-diegetic channel...
Definition: channel_layout.c:550
channel_layout_name
Definition: channel_layout.c:177
AV_CHANNEL_LAYOUT_6POINT1_FRONT
#define AV_CHANNEL_LAYOUT_6POINT1_FRONT
Definition: channel_layout.h:398
AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_SURROUND
Definition: channel_layout.h:382
AV_CHAN_STEREO_RIGHT
@ AV_CHAN_STEREO_RIGHT
See above.
Definition: channel_layout.h:71
avassert.h
description
Tag description
Definition: snow.txt:206
AV_CHAN_BOTTOM_FRONT_LEFT
@ AV_CHAN_BOTTOM_FRONT_LEFT
Definition: channel_layout.h:80
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
mask
static const uint16_t mask[17]
Definition: lzw.c:38
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:644
AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_4POINT0
Definition: channel_layout.h:384
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:401
AVChannelCustom
An AVChannelCustom defines a single channel within a custom order layout.
Definition: channel_layout.h:267
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
AV_CHAN_UNKNOWN
@ AV_CHAN_UNKNOWN
Channel contains data, but its position is unknown.
Definition: channel_layout.h:87
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
av_channel_layout_from_mask
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:242
AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
Definition: channel_layout.h:390
AV_CHAN_SIDE_RIGHT
@ AV_CHAN_SIDE_RIGHT
Definition: channel_layout.h:60
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
av_channel_layout_index_from_string
int av_channel_layout_index_from_string(const AVChannelLayout *channel_layout, const char *str)
Get the index in a channel layout of a channel described by the given string.
Definition: channel_layout.c:738
av_channel_layout_standard
const AVChannelLayout * av_channel_layout_standard(void **opaque)
Iterate over all standard channel layouts.
Definition: channel_layout.c:843
channels
channels
Definition: aptx.h:31
CHAN_IS_AMBI
#define CHAN_IS_AMBI(x)
Definition: channel_layout.c:38
AV_CHAN_TOP_SIDE_LEFT
@ AV_CHAN_TOP_SIDE_LEFT
Definition: channel_layout.h:77
has_channel_names
static int has_channel_names(const AVChannelLayout *channel_layout)
Definition: channel_layout.c:465
AV_CHAN_TOP_SIDE_RIGHT
@ AV_CHAN_TOP_SIDE_RIGHT
Definition: channel_layout.h:78
AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK
#define AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK
Definition: channel_layout.h:403
AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS
#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS
The conversion must be lossless.
Definition: channel_layout.h:685
av_sscanf
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
Definition: avsscanf.c:962
AV_CHANNEL_ORDER_AMBISONIC
@ AV_CHANNEL_ORDER_AMBISONIC
The audio is represented as the decomposition of the sound field into spherical harmonics.
Definition: channel_layout.h:148
NULL
#define NULL
Definition: coverity.c:32
AV_CHANNEL_LAYOUT_3POINT1POINT2
#define AV_CHANNEL_LAYOUT_3POINT1POINT2
Definition: channel_layout.h:394
channel_layout_name::layout
AVChannelLayout layout
Definition: channel_layout.c:179
AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
The specified retype target order is ignored and the simplest possible (canonical) order is used for ...
Definition: channel_layout.h:692
AV_CHAN_TOP_BACK_CENTER
@ AV_CHAN_TOP_BACK_CENTER
Definition: channel_layout.h:66
channel_names
static const struct channel_name channel_names[]
Definition: channel_layout.c:46
AV_CHAN_BOTTOM_FRONT_RIGHT
@ AV_CHAN_BOTTOM_FRONT_RIGHT
Definition: channel_layout.h:81
AV_CHAN_TOP_CENTER
@ AV_CHAN_TOP_CENTER
Definition: channel_layout.h:61
index
int index
Definition: gxfenc.c:89
AV_CHAN_FRONT_RIGHT_OF_CENTER
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:57
AV_CHANNEL_LAYOUT_22POINT2
#define AV_CHANNEL_LAYOUT_22POINT2
Definition: channel_layout.h:414
error.h
parse_channel_list
static int parse_channel_list(AVChannelLayout *ch_layout, const char *str)
Definition: channel_layout.c:255
AV_CHAN_FRONT_RIGHT
@ AV_CHAN_FRONT_RIGHT
Definition: channel_layout.h:51
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:52
channel_layout_map
static const struct channel_layout_name channel_layout_map[]
Definition: channel_layout.c:182
AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
Definition: channel_layout.h:404
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:53
AV_CHAN_BACK_RIGHT
@ AV_CHAN_BACK_RIGHT
Definition: channel_layout.h:55
AV_CHAN_SIDE_LEFT
@ AV_CHAN_SIDE_LEFT
Definition: channel_layout.h:59
AV_CHAN_AMBISONIC_END
@ AV_CHAN_AMBISONIC_END
Definition: channel_layout.h:104
AV_CHANNEL_LAYOUT_6POINT0
#define AV_CHANNEL_LAYOUT_6POINT0
Definition: channel_layout.h:392
av_channel_description
int av_channel_description(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string describing a given channel.
Definition: channel_layout.c:130
av_channel_layout_retype
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
Change the AVChannelOrder of a channel layout.
Definition: channel_layout.c:876
AV_OPT_FLAG_IMPLICIT_KEY
@ AV_OPT_FLAG_IMPLICIT_KEY
Accept to parse a value without a key; the key will then be returned as NULL.
Definition: opt.h:635
AV_CHAN_TOP_FRONT_RIGHT
@ AV_CHAN_TOP_FRONT_RIGHT
Definition: channel_layout.h:64
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:118
AV_CHAN_FRONT_LEFT_OF_CENTER
@ AV_CHAN_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:56
AV_CHAN_UNUSED
@ AV_CHAN_UNUSED
Channel is empty can be safely skipped.
Definition: channel_layout.h:84
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:800
av_channel_layout_custom_init
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
Definition: channel_layout.c:222
AV_CHANNEL_LAYOUT_HEXADECAGONAL
#define AV_CHANNEL_LAYOUT_HEXADECAGONAL
Definition: channel_layout.h:412
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:830
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
AV_CHANNEL_LAYOUT_6POINT1_BACK
#define AV_CHANNEL_LAYOUT_6POINT1_BACK
Definition: channel_layout.h:397
AVChannel
AVChannel
Definition: channel_layout.h:47
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:302
AV_CHANNEL_LAYOUT_CUBE
#define AV_CHANNEL_LAYOUT_CUBE
Definition: channel_layout.h:406
bprint.h
AV_CHAN_SURROUND_DIRECT_RIGHT
@ AV_CHAN_SURROUND_DIRECT_RIGHT
Definition: channel_layout.h:75
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AV_CHANNEL_LAYOUT_QUAD
#define AV_CHANNEL_LAYOUT_QUAD
Definition: channel_layout.h:387
av_channel_name
int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
Get a human readable string in an abbreviated form describing a given channel.
Definition: channel_layout.c:97
canonical_order
static enum AVChannelOrder canonical_order(AVChannelLayout *channel_layout)
Definition: channel_layout.c:518
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
common.h
AV_CHANNEL_LAYOUT_7POINT0_FRONT
#define AV_CHANNEL_LAYOUT_7POINT0_FRONT
Definition: channel_layout.h:400
AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
Definition: channel_layout.h:407
AV_CHANNEL_LAYOUT_3POINT1
#define AV_CHANNEL_LAYOUT_3POINT1
Definition: channel_layout.h:383
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVChannelCustom::name
char name[16]
Definition: channel_layout.h:269
AV_CHAN_STEREO_LEFT
@ AV_CHAN_STEREO_LEFT
Stereo downmix.
Definition: channel_layout.h:69
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
ret
ret
Definition: filter_design.txt:187
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:774
AV_CHANNEL_LAYOUT_7POINT0
#define AV_CHANNEL_LAYOUT_7POINT0
Definition: channel_layout.h:399
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
id
enum AVCodecID id
Definition: dts2pts.c:364
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:58
av_channel_from_string
enum AVChannel av_channel_from_string(const char *str)
This is the inverse function of av_channel_name().
Definition: channel_layout.c:145
AV_CHANNEL_LAYOUT_2_1
#define AV_CHANNEL_LAYOUT_2_1
Definition: channel_layout.h:381
AV_CHAN_NONE
@ AV_CHAN_NONE
Invalid channel index.
Definition: channel_layout.h:49
AV_CHANNEL_ORDER_CUSTOM
@ AV_CHANNEL_ORDER_CUSTOM
The channel order does not correspond to any other predefined order and is stored as an explicit map.
Definition: channel_layout.h:125
AVChannelLayout::opaque
void * opaque
For some private data of the user.
Definition: channel_layout.h:360
channel_layout.h
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
av_channel_layout_subset
uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout, uint64_t mask)
Find out what channels from a given set are present in a channel layout, without regard for their pos...
Definition: channel_layout.c:856
AV_CHAN_TOP_BACK_LEFT
@ AV_CHAN_TOP_BACK_LEFT
Definition: channel_layout.h:65
av_channel_layout_channel_from_string
enum AVChannel av_channel_layout_channel_from_string(const AVChannelLayout *channel_layout, const char *str)
Get a channel described by the given string.
Definition: channel_layout.c:693
av_channel_layout_index_from_channel
int av_channel_layout_index_from_channel(const AVChannelLayout *channel_layout, enum AVChannel channel)
Get the index of a given channel in a channel layout.
Definition: channel_layout.c:704
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:432
AV_CHAN_BACK_LEFT
@ AV_CHAN_BACK_LEFT
Definition: channel_layout.h:54
AV_CHANNEL_LAYOUT_6POINT0_FRONT
#define AV_CHANNEL_LAYOUT_6POINT0_FRONT
Definition: channel_layout.h:393
masked_description
static int64_t masked_description(const AVChannelLayout *channel_layout, int start_channel)
Definition: channel_layout.c:452
AV_CHAN_BOTTOM_FRONT_CENTER
@ AV_CHAN_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:79
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:439
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
AV_CHAN_TOP_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
Definition: channel_layout.h:63
AV_CHAN_WIDE_RIGHT
@ AV_CHAN_WIDE_RIGHT
Definition: channel_layout.h:73
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:71
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:378
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AV_CHAN_TOP_FRONT_LEFT
@ AV_CHAN_TOP_FRONT_LEFT
Definition: channel_layout.h:62
AV_CHAN_AMBISONIC_BASE
@ AV_CHAN_AMBISONIC_BASE
Range of channels between AV_CHAN_AMBISONIC_BASE and AV_CHAN_AMBISONIC_END represent Ambisonic compon...
Definition: channel_layout.h:101
AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:391
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_strlcpy
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:85
AV_CHANNEL_LAYOUT_6POINT1
#define AV_CHANNEL_LAYOUT_6POINT1
Definition: channel_layout.h:396
AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT0
Definition: channel_layout.h:388
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:145
AV_CHAN_FRONT_LEFT
@ AV_CHAN_FRONT_LEFT
Definition: channel_layout.h:50
AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_5POINT1
Definition: channel_layout.h:389
av_channel_name_bprint
void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
bprint variant of av_channel_name().
Definition: channel_layout.c:79
AVChannelCustom::id
enum AVChannel id
Definition: channel_layout.h:268
channel
channel
Definition: ebur128.h:39