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 static const char *get_channel_name(enum AVChannel channel_id)
80 {
81  if ((unsigned) channel_id >= FF_ARRAY_ELEMS(channel_names) ||
82  !channel_names[channel_id].name)
83  return NULL;
84  return channel_names[channel_id].name;
85 }
86 
87 void av_channel_name_bprint(AVBPrint *bp, enum AVChannel channel_id)
88 {
89  if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
90  channel_id <= AV_CHAN_AMBISONIC_END)
91  av_bprintf(bp, "AMBI%d", channel_id - AV_CHAN_AMBISONIC_BASE);
92  else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) &&
93  channel_names[channel_id].name)
94  av_bprintf(bp, "%s", channel_names[channel_id].name);
95  else if (channel_id == AV_CHAN_NONE)
96  av_bprintf(bp, "NONE");
97  else
98  av_bprintf(bp, "USR%d", channel_id);
99 }
100 
101 int av_channel_name(char *buf, size_t buf_size, enum AVChannel channel_id)
102 {
103  AVBPrint bp;
104 
105  if (!buf && buf_size)
106  return AVERROR(EINVAL);
107 
108  av_bprint_init_for_buffer(&bp, buf, buf_size);
109  av_channel_name_bprint(&bp, channel_id);
110 
111  if (bp.len >= INT_MAX)
112  return AVERROR(ERANGE);
113  return bp.len + 1;
114 }
115 
116 void av_channel_description_bprint(AVBPrint *bp, enum AVChannel channel_id)
117 {
118  if (channel_id >= AV_CHAN_AMBISONIC_BASE &&
119  channel_id <= AV_CHAN_AMBISONIC_END)
120  av_bprintf(bp, "ambisonic ACN %d", channel_id - AV_CHAN_AMBISONIC_BASE);
121  else if ((unsigned)channel_id < FF_ARRAY_ELEMS(channel_names) &&
122  channel_names[channel_id].description)
123  av_bprintf(bp, "%s", channel_names[channel_id].description);
124  else if (channel_id == AV_CHAN_NONE)
125  av_bprintf(bp, "none");
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 (!strncmp(str, "USR", 3)) {
163  const char *p = str + 3;
164  id = strtol(p, &endptr, 0);
165  }
166  if (id >= 0 && !*endptr)
167  return id;
168 
169  return AV_CHAN_NONE;
170 }
171 
173  const char *name;
175 };
176 
177 static const struct channel_layout_name channel_layout_map[] = {
178  { "mono", AV_CHANNEL_LAYOUT_MONO },
179  { "stereo", AV_CHANNEL_LAYOUT_STEREO },
180  { "2.1", AV_CHANNEL_LAYOUT_2POINT1 },
181  { "3.0", AV_CHANNEL_LAYOUT_SURROUND },
182  { "3.0(back)", AV_CHANNEL_LAYOUT_2_1 },
183  { "4.0", AV_CHANNEL_LAYOUT_4POINT0 },
184  { "quad", AV_CHANNEL_LAYOUT_QUAD },
185  { "quad(side)", AV_CHANNEL_LAYOUT_2_2 },
186  { "3.1", AV_CHANNEL_LAYOUT_3POINT1 },
188  { "5.0(side)", AV_CHANNEL_LAYOUT_5POINT0 },
189  { "4.1", AV_CHANNEL_LAYOUT_4POINT1 },
191  { "5.1(side)", AV_CHANNEL_LAYOUT_5POINT1 },
192  { "6.0", AV_CHANNEL_LAYOUT_6POINT0 },
193  { "6.0(front)", AV_CHANNEL_LAYOUT_6POINT0_FRONT },
194  { "3.1.2", AV_CHANNEL_LAYOUT_3POINT1POINT2 },
195  { "hexagonal", AV_CHANNEL_LAYOUT_HEXAGONAL },
196  { "6.1", AV_CHANNEL_LAYOUT_6POINT1 },
197  { "6.1(back)", AV_CHANNEL_LAYOUT_6POINT1_BACK },
198  { "6.1(front)", AV_CHANNEL_LAYOUT_6POINT1_FRONT },
199  { "7.0", AV_CHANNEL_LAYOUT_7POINT0 },
200  { "7.0(front)", AV_CHANNEL_LAYOUT_7POINT0_FRONT },
201  { "7.1", AV_CHANNEL_LAYOUT_7POINT1 },
202  { "7.1(wide)", AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK },
203  { "7.1(wide-side)", AV_CHANNEL_LAYOUT_7POINT1_WIDE },
205  { "octagonal", AV_CHANNEL_LAYOUT_OCTAGONAL },
206  { "cube", AV_CHANNEL_LAYOUT_CUBE },
208  { "7.1.2", AV_CHANNEL_LAYOUT_7POINT1POINT2 },
210  { "7.2.3", AV_CHANNEL_LAYOUT_7POINT2POINT3 },
212  { "hexadecagonal", AV_CHANNEL_LAYOUT_HEXADECAGONAL },
213  { "downmix", AV_CHANNEL_LAYOUT_STEREO_DOWNMIX, },
214  { "22.2", AV_CHANNEL_LAYOUT_22POINT2, },
215 };
216 
217 #if FF_API_OLD_CHANNEL_LAYOUT
219 static uint64_t get_channel_layout_single(const char *name, int name_len)
220 {
221  int i;
222  char *end;
223  int64_t layout;
224 
225  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
226  if (strlen(channel_layout_map[i].name) == name_len &&
227  !memcmp(channel_layout_map[i].name, name, name_len))
228  return channel_layout_map[i].layout.u.mask;
229  }
230  for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
231  if (channel_names[i].name &&
232  strlen(channel_names[i].name) == name_len &&
233  !memcmp(channel_names[i].name, name, name_len))
234  return (int64_t)1 << i;
235 
236  errno = 0;
237  i = strtol(name, &end, 10);
238 
239  if (!errno && (end + 1 - name == name_len && *end == 'c'))
241 
242  errno = 0;
243  layout = strtoll(name, &end, 0);
244  if (!errno && end - name == name_len)
245  return FFMAX(layout, 0);
246  return 0;
247 }
248 
249 uint64_t av_get_channel_layout(const char *name)
250 {
251  const char *n, *e;
252  const char *name_end = name + strlen(name);
253  int64_t layout = 0, layout_single;
254 
255  for (n = name; n < name_end; n = e + 1) {
256  for (e = n; e < name_end && *e != '+' && *e != '|'; e++);
257  layout_single = get_channel_layout_single(n, e - n);
258  if (!layout_single)
259  return 0;
260  layout |= layout_single;
261  }
262  return layout;
263 }
264 
265 int av_get_extended_channel_layout(const char *name, uint64_t* channel_layout, int* nb_channels)
266 {
267  int nb = 0;
268  char *end;
269  uint64_t layout = av_get_channel_layout(name);
270 
271  if (layout) {
272  *channel_layout = layout;
274  return 0;
275  }
276 
277  nb = strtol(name, &end, 10);
278  if (!errno && *end == 'C' && *(end + 1) == '\0' && nb > 0 && nb < 64) {
279  *channel_layout = 0;
280  *nb_channels = nb;
281  return 0;
282  }
283 
284  return AVERROR(EINVAL);
285 }
286 
287 void av_bprint_channel_layout(struct AVBPrint *bp,
288  int nb_channels, uint64_t channel_layout)
289 {
290  int i;
291 
292  if (nb_channels <= 0)
293  nb_channels = av_get_channel_layout_nb_channels(channel_layout);
294 
295  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
296  if (nb_channels == channel_layout_map[i].layout.nb_channels &&
297  channel_layout == channel_layout_map[i].layout.u.mask) {
298  av_bprintf(bp, "%s", channel_layout_map[i].name);
299  return;
300  }
301 
302  av_bprintf(bp, "%d channels", nb_channels);
303  if (channel_layout) {
304  int i, ch;
305  av_bprintf(bp, " (");
306  for (i = 0, ch = 0; i < 64; i++) {
307  if ((channel_layout & (UINT64_C(1) << i))) {
308  const char *name = get_channel_name(i);
309  if (name) {
310  if (ch > 0)
311  av_bprintf(bp, "+");
312  av_bprintf(bp, "%s", name);
313  }
314  ch++;
315  }
316  }
317  av_bprintf(bp, ")");
318  }
319 }
320 
321 void av_get_channel_layout_string(char *buf, int buf_size,
322  int nb_channels, uint64_t channel_layout)
323 {
324  AVBPrint bp;
325 
326  av_bprint_init_for_buffer(&bp, buf, buf_size);
327  av_bprint_channel_layout(&bp, nb_channels, channel_layout);
328 }
329 
330 int av_get_channel_layout_nb_channels(uint64_t channel_layout)
331 {
332  return av_popcount64(channel_layout);
333 }
334 
335 int64_t av_get_default_channel_layout(int nb_channels) {
336  int i;
337  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
338  if (nb_channels == channel_layout_map[i].layout.nb_channels)
339  return channel_layout_map[i].layout.u.mask;
340  return 0;
341 }
342 
343 int av_get_channel_layout_channel_index(uint64_t channel_layout,
344  uint64_t channel)
345 {
346  if (!(channel_layout & channel) ||
348  return AVERROR(EINVAL);
349  channel_layout &= channel - 1;
350  return av_get_channel_layout_nb_channels(channel_layout);
351 }
352 
353 const char *av_get_channel_name(uint64_t channel)
354 {
355  int i;
357  return NULL;
358  for (i = 0; i < 64; i++)
359  if ((1ULL<<i) & channel)
360  return get_channel_name(i);
361  return NULL;
362 }
363 
364 const char *av_get_channel_description(uint64_t channel)
365 {
366  int i;
368  return NULL;
369  for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++)
370  if ((1ULL<<i) & channel)
371  return channel_names[i].description;
372  return NULL;
373 }
374 
375 uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
376 {
377  int i;
378 
379  if (av_get_channel_layout_nb_channels(channel_layout) <= index)
380  return 0;
381 
382  for (i = 0; i < 64; i++) {
383  if ((1ULL << i) & channel_layout && !index--)
384  return 1ULL << i;
385  }
386  return 0;
387 }
388 
390  const char **name)
391 {
393  return AVERROR_EOF;
396  return 0;
397 }
399 #endif
400 
402  uint64_t mask)
403 {
404  if (!mask)
405  return AVERROR(EINVAL);
406 
407  channel_layout->order = AV_CHANNEL_ORDER_NATIVE;
408  channel_layout->nb_channels = av_popcount64(mask);
409  channel_layout->u.mask = mask;
410 
411  return 0;
412 }
413 
415  const char *str)
416 {
417  int i;
418  int channels = 0, nb_channels = 0, native = 1;
419  enum AVChannel highest_channel = AV_CHAN_NONE;
420  const char *dup;
421  char *chlist, *end;
422  uint64_t mask = 0;
423 
424  /* channel layout names */
425  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++) {
426  if (channel_layout_map[i].name && !strcmp(str, channel_layout_map[i].name)) {
427  *channel_layout = channel_layout_map[i].layout;
428  return 0;
429  }
430  }
431 
432  /* ambisonic */
433  if (!strncmp(str, "ambisonic ", 10)) {
434  const char *p = str + 10;
435  char *endptr;
436  AVChannelLayout extra = {0};
437  int order;
438 
439  order = strtol(p, &endptr, 0);
440  if (order < 0 || order + 1 > INT_MAX / (order + 1) ||
441  (*endptr && *endptr != '+'))
442  return AVERROR(EINVAL);
443 
444  channel_layout->order = AV_CHANNEL_ORDER_AMBISONIC;
445  channel_layout->nb_channels = (order + 1) * (order + 1);
446 
447  if (*endptr) {
448  int ret = av_channel_layout_from_string(&extra, endptr + 1);
449  if (ret < 0)
450  return ret;
451  if (extra.nb_channels >= INT_MAX - channel_layout->nb_channels) {
452  av_channel_layout_uninit(&extra);
453  return AVERROR(EINVAL);
454  }
455 
456  if (extra.order == AV_CHANNEL_ORDER_NATIVE) {
457  channel_layout->u.mask = extra.u.mask;
458  } else {
459  channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
460  channel_layout->u.map =
461  av_calloc(channel_layout->nb_channels + extra.nb_channels,
462  sizeof(*channel_layout->u.map));
463  if (!channel_layout->u.map) {
464  av_channel_layout_uninit(&extra);
465  return AVERROR(ENOMEM);
466  }
467 
468  for (i = 0; i < channel_layout->nb_channels; i++)
469  channel_layout->u.map[i].id = AV_CHAN_AMBISONIC_BASE + i;
470  for (i = 0; i < extra.nb_channels; i++) {
472  if (CHAN_IS_AMBI(ch)) {
473  av_channel_layout_uninit(&extra);
474  return AVERROR(EINVAL);
475  }
476  channel_layout->u.map[channel_layout->nb_channels + i].id = ch;
477  if (extra.order == AV_CHANNEL_ORDER_CUSTOM &&
478  extra.u.map[i].name[0])
479  av_strlcpy(channel_layout->u.map[channel_layout->nb_channels + i].name,
480  extra.u.map[i].name,
481  sizeof(channel_layout->u.map[channel_layout->nb_channels + i].name));
482  }
483  }
484  channel_layout->nb_channels += extra.nb_channels;
485  av_channel_layout_uninit(&extra);
486  }
487 
488  return 0;
489  }
490 
491  chlist = av_strdup(str);
492  if (!chlist)
493  return AVERROR(ENOMEM);
494 
495  /* channel names */
496  av_sscanf(str, "%d channels (%[^)]", &nb_channels, chlist);
497  end = strchr(str, ')');
498 
499  dup = chlist;
500  while (*dup) {
501  char *channel, *chname;
502  int ret = av_opt_get_key_value(&dup, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname);
503  if (ret < 0) {
504  av_free(chlist);
505  return ret;
506  }
507  if (*dup)
508  dup++; // skip separator
509  if (channel && !*channel)
510  av_freep(&channel);
511  for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
512  if (channel_names[i].name && !strcmp(channel ? channel : chname, channel_names[i].name)) {
513  if (channel || i < highest_channel || mask & (1ULL << i))
514  native = 0; // Not a native layout, use a custom one
515  highest_channel = i;
516  mask |= 1ULL << i;
517  break;
518  }
519  }
520 
521  if (!channel && i >= FF_ARRAY_ELEMS(channel_names)) {
522  char *endptr = chname;
523  enum AVChannel id = AV_CHAN_NONE;
524 
525  if (!strncmp(chname, "USR", 3)) {
526  const char *p = chname + 3;
527  id = strtol(p, &endptr, 0);
528  }
529  if (id < 0 || *endptr) {
530  native = 0; // Unknown channel name
531  channels = 0;
532  mask = 0;
533  av_free(chname);
534  break;
535  }
536  if (id > 63)
537  native = 0; // Not a native layout, use a custom one
538  else {
539  if (id < highest_channel || mask & (1ULL << id))
540  native = 0; // Not a native layout, use a custom one
541  highest_channel = id;
542  mask |= 1ULL << id;
543  }
544  }
545  channels++;
546  av_free(channel);
547  av_free(chname);
548  }
549 
550  if (mask && native) {
551  av_free(chlist);
552  if (nb_channels && ((nb_channels != channels) || (!end || *++end)))
553  return AVERROR(EINVAL);
554  av_channel_layout_from_mask(channel_layout, mask);
555  return 0;
556  }
557 
558  /* custom layout of channel names */
559  if (channels && !native) {
560  int idx = 0;
561 
562  if (nb_channels && ((nb_channels != channels) || (!end || *++end))) {
563  av_free(chlist);
564  return AVERROR(EINVAL);
565  }
566 
567  channel_layout->u.map = av_calloc(channels, sizeof(*channel_layout->u.map));
568  if (!channel_layout->u.map) {
569  av_free(chlist);
570  return AVERROR(ENOMEM);
571  }
572 
573  channel_layout->order = AV_CHANNEL_ORDER_CUSTOM;
574  channel_layout->nb_channels = channels;
575 
576  dup = chlist;
577  while (*dup) {
578  char *channel, *chname;
579  int ret = av_opt_get_key_value(&dup, "@", "+", AV_OPT_FLAG_IMPLICIT_KEY, &channel, &chname);
580  if (ret < 0) {
581  av_freep(&channel_layout->u.map);
582  av_free(chlist);
583  return ret;
584  }
585  if (*dup)
586  dup++; // skip separator
587  for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) {
588  if (channel_names[i].name && !strcmp(channel ? channel : chname, channel_names[i].name)) {
589  channel_layout->u.map[idx].id = i;
590  if (channel)
591  av_strlcpy(channel_layout->u.map[idx].name, chname, sizeof(channel_layout->u.map[idx].name));
592  idx++;
593  break;
594  }
595  }
596  if (i >= FF_ARRAY_ELEMS(channel_names)) {
597  const char *p = (channel ? channel : chname) + 3;
598  channel_layout->u.map[idx].id = strtol(p, NULL, 0);
599  if (channel)
600  av_strlcpy(channel_layout->u.map[idx].name, chname, sizeof(channel_layout->u.map[idx].name));
601  idx++;
602  }
603  av_free(channel);
604  av_free(chname);
605  }
606  av_free(chlist);
607 
608  return 0;
609  }
610  av_freep(&chlist);
611 
612  errno = 0;
613  mask = strtoull(str, &end, 0);
614 
615  /* channel layout mask */
616  if (!errno && !*end && !strchr(str, '-') && mask) {
617  av_channel_layout_from_mask(channel_layout, mask);
618  return 0;
619  }
620 
621  errno = 0;
622  channels = strtol(str, &end, 10);
623 
624  /* number of channels */
625  if (!errno && !strcmp(end, "c") && channels > 0) {
626  av_channel_layout_default(channel_layout, channels);
627  if (channel_layout->order == AV_CHANNEL_ORDER_NATIVE)
628  return 0;
629  }
630 
631  /* number of unordered channels */
632  if (!errno && (!strcmp(end, "C") || !strcmp(end, " channels"))
633  && channels > 0) {
634  channel_layout->order = AV_CHANNEL_ORDER_UNSPEC;
635  channel_layout->nb_channels = channels;
636  return 0;
637  }
638 
639  return AVERROR(EINVAL);
640 }
641 
643 {
644  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM)
645  av_freep(&channel_layout->u.map);
646  memset(channel_layout, 0, sizeof(*channel_layout));
647 }
648 
650 {
652  *dst = *src;
653  if (src->order == AV_CHANNEL_ORDER_CUSTOM) {
654  dst->u.map = av_malloc_array(src->nb_channels, sizeof(*dst->u.map));
655  if (!dst->u.map)
656  return AVERROR(ENOMEM);
657  memcpy(dst->u.map, src->u.map, src->nb_channels * sizeof(*src->u.map));
658  }
659  return 0;
660 }
661 
662 /**
663  * If the layout is n-th order standard-order ambisonic, with optional
664  * extra non-diegetic channels at the end, return the order.
665  * Return a negative error code otherwise.
666  */
667 static int ambisonic_order(const AVChannelLayout *channel_layout)
668 {
669  int i, highest_ambi, order;
670 
671  highest_ambi = -1;
672  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC)
673  highest_ambi = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask) - 1;
674  else {
675  const AVChannelCustom *map = channel_layout->u.map;
676  av_assert0(channel_layout->order == AV_CHANNEL_ORDER_CUSTOM);
677 
678  for (i = 0; i < channel_layout->nb_channels; i++) {
679  int is_ambi = CHAN_IS_AMBI(map[i].id);
680 
681  /* ambisonic following non-ambisonic */
682  if (i > 0 && is_ambi && !CHAN_IS_AMBI(map[i - 1].id))
683  return AVERROR(EINVAL);
684 
685  /* non-default ordering */
686  if (is_ambi && map[i].id - AV_CHAN_AMBISONIC_BASE != i)
687  return AVERROR(EINVAL);
688 
689  if (CHAN_IS_AMBI(map[i].id))
690  highest_ambi = i;
691  }
692  }
693  /* no ambisonic channels*/
694  if (highest_ambi < 0)
695  return AVERROR(EINVAL);
696 
697  order = floor(sqrt(highest_ambi));
698  /* incomplete order - some harmonics are missing */
699  if ((order + 1) * (order + 1) != highest_ambi + 1)
700  return AVERROR(EINVAL);
701 
702  return order;
703 }
704 
705 /**
706  * If the custom layout is n-th order standard-order ambisonic, with optional
707  * extra non-diegetic channels at the end, write its string description in bp.
708  * Return a negative error code otherwise.
709  */
710 static int try_describe_ambisonic(AVBPrint *bp, const AVChannelLayout *channel_layout)
711 {
712  int nb_ambi_channels;
713  int order = ambisonic_order(channel_layout);
714  if (order < 0)
715  return order;
716 
717  av_bprintf(bp, "ambisonic %d", order);
718 
719  /* extra channels present */
720  nb_ambi_channels = (order + 1) * (order + 1);
721  if (nb_ambi_channels < channel_layout->nb_channels) {
722  AVChannelLayout extra = { 0 };
723 
724  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC) {
726  extra.nb_channels = av_popcount64(channel_layout->u.mask);
727  extra.u.mask = channel_layout->u.mask;
728  } else {
730  extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
731  extra.u.map = channel_layout->u.map + nb_ambi_channels;
732  }
733 
734  av_bprint_chars(bp, '+', 1);
736  /* Not calling uninit here on extra because we don't own the u.map pointer */
737  }
738 
739  return 0;
740 }
741 
743  AVBPrint *bp)
744 {
745  int i;
746 
747  switch (channel_layout->order) {
749  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
750  if (channel_layout->u.mask == channel_layout_map[i].layout.u.mask) {
751  av_bprintf(bp, "%s", channel_layout_map[i].name);
752  return 0;
753  }
754  // fall-through
756  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
757  int res = try_describe_ambisonic(bp, channel_layout);
758  if (res >= 0)
759  return 0;
760  }
761  if (channel_layout->nb_channels)
762  av_bprintf(bp, "%d channels (", channel_layout->nb_channels);
763  for (i = 0; i < channel_layout->nb_channels; i++) {
764  enum AVChannel ch = av_channel_layout_channel_from_index(channel_layout, i);
765 
766  if (i)
767  av_bprintf(bp, "+");
768  av_channel_name_bprint(bp, ch);
769  if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM &&
770  channel_layout->u.map[i].name[0])
771  av_bprintf(bp, "@%s", channel_layout->u.map[i].name);
772  }
773  if (channel_layout->nb_channels) {
774  av_bprintf(bp, ")");
775  return 0;
776  }
777  // fall-through
779  av_bprintf(bp, "%d channels", channel_layout->nb_channels);
780  return 0;
782  return try_describe_ambisonic(bp, channel_layout);
783  default:
784  return AVERROR(EINVAL);
785  }
786 }
787 
788 int av_channel_layout_describe(const AVChannelLayout *channel_layout,
789  char *buf, size_t buf_size)
790 {
791  AVBPrint bp;
792  int ret;
793 
794  if (!buf && buf_size)
795  return AVERROR(EINVAL);
796 
797  av_bprint_init_for_buffer(&bp, buf, buf_size);
798  ret = av_channel_layout_describe_bprint(channel_layout, &bp);
799  if (ret < 0)
800  return ret;
801 
802  if (bp.len >= INT_MAX)
803  return AVERROR(ERANGE);
804  return bp.len + 1;
805 }
806 
807 enum AVChannel
809  unsigned int idx)
810 {
811  int i;
812 
813  if (idx >= channel_layout->nb_channels)
814  return AV_CHAN_NONE;
815 
816  switch (channel_layout->order) {
818  return channel_layout->u.map[idx].id;
820  int ambi_channels = channel_layout->nb_channels - av_popcount64(channel_layout->u.mask);
821  if (idx < ambi_channels)
822  return AV_CHAN_AMBISONIC_BASE + idx;
823  idx -= ambi_channels;
824  }
825  // fall-through
827  for (i = 0; i < 64; i++) {
828  if ((1ULL << i) & channel_layout->u.mask && !idx--)
829  return i;
830  }
831  default:
832  return AV_CHAN_NONE;
833  }
834 }
835 
836 enum AVChannel
838  const char *str)
839 {
840  int index = av_channel_layout_index_from_string(channel_layout, str);
841 
842  if (index < 0)
843  return AV_CHAN_NONE;
844 
845  return av_channel_layout_channel_from_index(channel_layout, index);
846 }
847 
849  enum AVChannel channel)
850 {
851  int i;
852 
853  if (channel == AV_CHAN_NONE)
854  return AVERROR(EINVAL);
855 
856  switch (channel_layout->order) {
858  for (i = 0; i < channel_layout->nb_channels; i++)
859  if (channel_layout->u.map[i].id == channel)
860  return i;
861  return AVERROR(EINVAL);
864  uint64_t mask = channel_layout->u.mask;
865  int ambi_channels = channel_layout->nb_channels - av_popcount64(mask);
866  if (channel_layout->order == AV_CHANNEL_ORDER_AMBISONIC &&
868  if (channel - AV_CHAN_AMBISONIC_BASE >= ambi_channels)
869  return AVERROR(EINVAL);
871  }
872  if ((unsigned)channel > 63 || !(mask & (1ULL << channel)))
873  return AVERROR(EINVAL);
874  mask &= (1ULL << channel) - 1;
875  return av_popcount64(mask) + ambi_channels;
876  }
877  default:
878  return AVERROR(EINVAL);
879  }
880 }
881 
883  const char *str)
884 {
885  char *chname;
886  enum AVChannel ch = AV_CHAN_NONE;
887 
888  switch (channel_layout->order) {
890  chname = strstr(str, "@");
891  if (chname) {
892  char buf[16];
893  chname++;
894  av_strlcpy(buf, str, FFMIN(sizeof(buf), chname - str));
895  if (!*chname)
896  chname = NULL;
897  ch = av_channel_from_string(buf);
898  if (ch == AV_CHAN_NONE && *buf)
899  return AVERROR(EINVAL);
900  }
901  for (int i = 0; chname && i < channel_layout->nb_channels; i++) {
902  if (!strcmp(chname, channel_layout->u.map[i].name) &&
903  (ch == AV_CHAN_NONE || ch == channel_layout->u.map[i].id))
904  return i;
905  }
906  // fall-through
909  ch = av_channel_from_string(str);
910  if (ch == AV_CHAN_NONE)
911  return AVERROR(EINVAL);
912  return av_channel_layout_index_from_channel(channel_layout, ch);
913  }
914 
915  return AVERROR(EINVAL);
916 }
917 
918 int av_channel_layout_check(const AVChannelLayout *channel_layout)
919 {
920  if (channel_layout->nb_channels <= 0)
921  return 0;
922 
923  switch (channel_layout->order) {
925  return av_popcount64(channel_layout->u.mask) == channel_layout->nb_channels;
927  if (!channel_layout->u.map)
928  return 0;
929  for (int i = 0; i < channel_layout->nb_channels; i++) {
930  if (channel_layout->u.map[i].id == AV_CHAN_NONE)
931  return 0;
932  }
933  return 1;
935  /* If non-diegetic channels are present, ensure they are taken into account */
936  return av_popcount64(channel_layout->u.mask) < channel_layout->nb_channels;
938  return 1;
939  default:
940  return 0;
941  }
942 }
943 
945 {
946  int i;
947 
948  /* different channel counts -> not equal */
949  if (chl->nb_channels != chl1->nb_channels)
950  return 1;
951 
952  /* if only one is unspecified -> not equal */
953  if ((chl->order == AV_CHANNEL_ORDER_UNSPEC) !=
954  (chl1->order == AV_CHANNEL_ORDER_UNSPEC))
955  return 1;
956  /* both are unspecified -> equal */
957  else if (chl->order == AV_CHANNEL_ORDER_UNSPEC)
958  return 0;
959 
960  /* can compare masks directly */
961  if ((chl->order == AV_CHANNEL_ORDER_NATIVE ||
963  chl->order == chl1->order)
964  return chl->u.mask != chl1->u.mask;
965 
966  /* compare channel by channel */
967  for (i = 0; i < chl->nb_channels; i++)
970  return 1;
971  return 0;
972 }
973 
974 void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
975 {
976  int i;
977  for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map); i++)
978  if (nb_channels == channel_layout_map[i].layout.nb_channels) {
979  *ch_layout = channel_layout_map[i].layout;
980  return;
981  }
982 
983  ch_layout->order = AV_CHANNEL_ORDER_UNSPEC;
984  ch_layout->nb_channels = nb_channels;
985 }
986 
988 {
989  uintptr_t i = (uintptr_t)*opaque;
990  const AVChannelLayout *ch_layout = NULL;
991 
993  ch_layout = &channel_layout_map[i].layout;
994  *opaque = (void*)(i + 1);
995  }
996 
997  return ch_layout;
998 }
999 
1000 uint64_t av_channel_layout_subset(const AVChannelLayout *channel_layout,
1001  uint64_t mask)
1002 {
1003  uint64_t ret = 0;
1004  int i;
1005 
1006  switch (channel_layout->order) {
1009  return channel_layout->u.mask & mask;
1011  for (i = 0; i < 64; i++)
1012  if (mask & (1ULL << i) && av_channel_layout_index_from_channel(channel_layout, i) >= 0)
1013  ret |= (1ULL << i);
1014  break;
1015  }
1016 
1017  return ret;
1018 }
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
av_get_channel_layout_string
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Definition: channel_layout.c:321
AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
#define AV_CHANNEL_LAYOUT_STEREO_DOWNMIX
Definition: channel_layout.h:419
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:411
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:415
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:385
AV_CHANNEL_LAYOUT_4POINT1
#define AV_CHANNEL_LAYOUT_4POINT1
Definition: channel_layout.h:391
AV_CHANNEL_LAYOUT_HEXAGONAL
#define AV_CHANNEL_LAYOUT_HEXAGONAL
Definition: channel_layout.h:401
av_popcount64
#define av_popcount64
Definition: common.h:153
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:72
av_get_channel_name
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
Definition: channel_layout.c:353
AVChannelLayout::map
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
Definition: channel_layout.h:360
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:667
AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_2_2
Definition: channel_layout.h:392
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:808
channel_layout_name::name
const char * name
Definition: channel_layout.c:173
av_get_standard_channel_layout
int av_get_standard_channel_layout(unsigned index, uint64_t *layout, const char **name)
Get the value and name of a standard channel layout.
Definition: channel_layout.c:389
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:536
channel_name
Definition: channel_layout.c:41
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:314
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
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:341
av_get_channel_layout_nb_channels
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: channel_layout.c:330
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:319
AV_CHANNEL_LAYOUT_7POINT2POINT3
#define AV_CHANNEL_LAYOUT_7POINT2POINT3
Definition: channel_layout.h:416
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:742
av_channel_layout_extract_channel
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
Definition: channel_layout.c:375
AV_CHANNEL_LAYOUT_7POINT1_WIDE
#define AV_CHANNEL_LAYOUT_7POINT1_WIDE
Definition: channel_layout.h:408
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:116
AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_9POINT1POINT4_BACK
Definition: channel_layout.h:417
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:414
AV_CHAN_TOP_BACK_RIGHT
@ AV_CHAN_TOP_BACK_RIGHT
Definition: channel_layout.h:67
macros.h
AV_CHANNEL_LAYOUT_2POINT1
#define AV_CHANNEL_LAYOUT_2POINT1
Definition: channel_layout.h:386
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:710
channel_layout_name
Definition: channel_layout.c:172
AV_CHANNEL_LAYOUT_6POINT1_FRONT
#define AV_CHANNEL_LAYOUT_6POINT1_FRONT
Definition: channel_layout.h:404
av_get_channel_layout_channel_index
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
Definition: channel_layout.c:343
AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_SURROUND
Definition: channel_layout.h:388
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
av_get_channel_description
const char * av_get_channel_description(uint64_t channel)
Get the description of a given channel.
Definition: channel_layout.c:364
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:788
AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_4POINT0
Definition: channel_layout.h:390
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:407
AVChannelCustom
An AVChannelCustom defines a single channel within a custom order layout.
Definition: channel_layout.h:273
floor
static __device__ float floor(float a)
Definition: cuda_runtime.h:173
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
FF_ENABLE_DEPRECATION_WARNINGS 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:401
AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
Definition: channel_layout.h:396
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:882
av_channel_layout_standard
const AVChannelLayout * av_channel_layout_standard(void **opaque)
Iterate over all standard channel layouts.
Definition: channel_layout.c:987
get_channel_name
static const char * get_channel_name(enum AVChannel channel_id)
Definition: channel_layout.c:79
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
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:409
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:400
channel_layout_name::layout
AVChannelLayout layout
Definition: channel_layout.c:174
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_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:249
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:420
error.h
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:177
AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK
Definition: channel_layout.h:410
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:309
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:398
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_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_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:944
AV_CHANNEL_LAYOUT_HEXADECAGONAL
#define AV_CHANNEL_LAYOUT_HEXADECAGONAL
Definition: channel_layout.h:418
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:974
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:403
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:414
AV_CHANNEL_LAYOUT_CUBE
#define AV_CHANNEL_LAYOUT_CUBE
Definition: channel_layout.h:412
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:245
AV_CHANNEL_LAYOUT_QUAD
#define AV_CHANNEL_LAYOUT_QUAD
Definition: channel_layout.h:393
get_channel_layout_single
static FF_DISABLE_DEPRECATION_WARNINGS uint64_t get_channel_layout_single(const char *name, int name_len)
Definition: channel_layout.c:219
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:101
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:406
AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
#define AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK
Definition: channel_layout.h:413
AV_CHANNEL_LAYOUT_3POINT1
#define AV_CHANNEL_LAYOUT_3POINT1
Definition: channel_layout.h:389
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVChannelCustom::name
char name[16]
Definition: channel_layout.h:275
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
av_bprint_channel_layout
void av_bprint_channel_layout(struct AVBPrint *bp, int nb_channels, uint64_t channel_layout)
Append a description of a channel layout to a bprint buffer.
Definition: channel_layout.c:287
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:918
AV_CHANNEL_LAYOUT_7POINT0
#define AV_CHANNEL_LAYOUT_7POINT0
Definition: channel_layout.h:405
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:1645
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
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:387
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
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
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:1000
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:837
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:848
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:642
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:399
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:649
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
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:384
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:397
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:402
AVChannelLayout::u
union AVChannelLayout::@334 u
Details about which channels are present in this layout.
av_get_extended_channel_layout
int av_get_extended_channel_layout(const char *name, uint64_t *channel_layout, int *nb_channels)
Return a channel layout and the number of channels based on the specified name.
Definition: channel_layout.c:265
AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT0
Definition: channel_layout.h:394
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:395
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:87
AVChannelCustom::id
enum AVChannel id
Definition: channel_layout.h:274
channel
channel
Definition: ebur128.h:39
av_get_default_channel_layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Definition: channel_layout.c:335