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