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