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