FFmpeg
formats.c
Go to the documentation of this file.
1 /*
2  * Filter layer - format negotiation
3  * Copyright (c) 2007 Bobby Bingham
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/attributes.h"
23 #include "libavutil/avassert.h"
24 #include "libavutil/bprint.h"
26 #include "libavutil/common.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 #include "formats.h"
32 
33 /**
34  * Add all refs from a to ret and destroy a.
35  */
36 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
37 do { \
38  type ***tmp; \
39  int i; \
40  \
41  if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
42  sizeof(*tmp)))) \
43  { fail_statement } \
44  ret->refs = tmp; \
45  \
46  for (i = 0; i < a->refcount; i ++) { \
47  ret->refs[ret->refcount] = a->refs[i]; \
48  *ret->refs[ret->refcount++] = ret; \
49  } \
50  \
51  av_freep(&a->refs); \
52  av_freep(&a->fmts); \
53  av_freep(&a); \
54 } while (0)
55 
56 /**
57  * Add all formats common to a and b to a, add b's refs to a and destroy b.
58  * If check is set, nothing is modified and it is only checked whether
59  * the formats are compatible.
60  * If empty_allowed is set and one of a,b->nb is zero, the lists are
61  * merged; otherwise, 0 (for nonmergeability) is returned.
62  */
63 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
64 do { \
65  int i, j, k = 0, skip = 0; \
66  \
67  if (empty_allowed) { \
68  if (!a->nb || !b->nb) { \
69  if (check) \
70  return 1; \
71  if (!a->nb) \
72  FFSWAP(type *, a, b); \
73  skip = 1; \
74  } \
75  } \
76  if (!skip) { \
77  for (i = 0; i < a->nb; i++) \
78  for (j = 0; j < b->nb; j++) \
79  if (a->fmts[i] == b->fmts[j]) { \
80  if (check) \
81  return 1; \
82  a->fmts[k++] = a->fmts[i]; \
83  break; \
84  } \
85  /* Check that there was at least one common format. \
86  * Notice that both a and b are unchanged if not. */ \
87  if (!k) \
88  return 0; \
89  av_assert2(!check); \
90  a->nb = k; \
91  } \
92  \
93  MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
94 } while (0)
95 
97  enum AVMediaType type, int check)
98 {
99  int i, j;
100  int alpha1=0, alpha2=0;
101  int chroma1=0, chroma2=0;
102 
103  av_assert2(check || (a->refcount && b->refcount));
104 
105  if (a == b)
106  return 1;
107 
108  /* Do not lose chroma or alpha in merging.
109  It happens if both lists have formats with chroma (resp. alpha), but
110  the only formats in common do not have it (e.g. YUV+gray vs.
111  RGB+gray): in that case, the merging would select the gray format,
112  possibly causing a lossy conversion elsewhere in the graph.
113  To avoid that, pretend that there are no common formats to force the
114  insertion of a conversion filter. */
115  if (type == AVMEDIA_TYPE_VIDEO)
116  for (i = 0; i < a->nb_formats; i++) {
117  const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
118  for (j = 0; j < b->nb_formats; j++) {
119  const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
120  alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
121  chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
122  if (a->formats[i] == b->formats[j]) {
123  alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
124  chroma1|= adesc->nb_components > 1;
125  }
126  }
127  }
128 
129  // If chroma or alpha can be lost through merging then do not merge
130  if (alpha2 > alpha1 || chroma2 > chroma1)
131  return 0;
132 
133  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
134 
135  return 1;
136 }
137 
138 
139 /**
140  * Check the formats lists for compatibility for merging without actually
141  * merging.
142  *
143  * @return 1 if they are compatible, 0 if not.
144  */
145 static int can_merge_pix_fmts(const void *a, const void *b)
146 {
149 }
150 
151 /**
152  * Merge the formats lists if they are compatible and update all the
153  * references of a and b to point to the combined list and free the old
154  * lists as needed. The combined list usually contains the intersection of
155  * the lists of a and b.
156  *
157  * Both a and b must have owners (i.e. refcount > 0) for these functions.
158  *
159  * @return 1 if merging succeeded, 0 if a and b are incompatible
160  * and negative AVERROR code on failure.
161  * a and b are unmodified if 0 is returned.
162  */
163 static int merge_pix_fmts(void *a, void *b)
164 {
166 }
167 
168 /**
169  * See can_merge_pix_fmts().
170  */
171 static int can_merge_sample_fmts(const void *a, const void *b)
172 {
175 }
176 
177 /**
178  * See merge_pix_fmts().
179  */
180 static int merge_sample_fmts(void *a, void *b)
181 {
183 }
184 
186  AVFilterFormats *b, int check)
187 {
188  av_assert2(check || (a->refcount && b->refcount));
189  if (a == b) return 1;
190 
191  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
192  return 1;
193 }
194 
195 /**
196  * See can_merge_pix_fmts().
197  */
198 static int can_merge_samplerates(const void *a, const void *b)
199 {
201 }
202 
203 /**
204  * See merge_pix_fmts().
205  */
206 static int merge_samplerates(void *a, void *b)
207 {
208  return merge_samplerates_internal(a, b, 0);
209 }
210 
211 /**
212  * See merge_pix_fmts().
213  */
216 {
218  unsigned a_all = a->all_layouts + a->all_counts;
219  unsigned b_all = b->all_layouts + b->all_counts;
220  int ret_max, ret_nb = 0, i, j, round;
221 
222  av_assert2(a->refcount && b->refcount);
223 
224  if (a == b) return 1;
225 
226  /* Put the most generic set in a, to avoid doing everything twice */
227  if (a_all < b_all) {
229  FFSWAP(unsigned, a_all, b_all);
230  }
231  if (a_all) {
232  if (a_all == 1 && !b_all) {
233  /* keep only known layouts in b; works also for b_all = 1 */
234  for (i = j = 0; i < b->nb_channel_layouts; i++)
235  if (KNOWN(&b->channel_layouts[i]) && i != j++) {
236  if (check)
237  return 1;
238  av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
239  }
240  /* Not optimal: the unknown layouts of b may become known after
241  another merge. */
242  if (!j)
243  return 0;
244  b->nb_channel_layouts = j;
245  }
247  return 1;
248  }
249 
250  ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
251  if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
252  return AVERROR(ENOMEM);
253 
254  /* a[known] intersect b[known] */
255  for (i = 0; i < a->nb_channel_layouts; i++) {
256  if (!KNOWN(&a->channel_layouts[i]))
257  continue;
258  for (j = 0; j < b->nb_channel_layouts; j++) {
259  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
260  if (check)
261  return 1;
262  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
263  av_channel_layout_uninit(&a->channel_layouts[i]);
264  av_channel_layout_uninit(&b->channel_layouts[j]);
265  break;
266  }
267  }
268  }
269  /* 1st round: a[known] intersect b[generic]
270  2nd round: a[generic] intersect b[known] */
271  for (round = 0; round < 2; round++) {
272  for (i = 0; i < a->nb_channel_layouts; i++) {
273  AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
274  if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
275  continue;
276  bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
277  for (j = 0; j < b->nb_channel_layouts; j++)
278  if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
279  if (check)
280  return 1;
281  av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
282  }
283  }
284  /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
286  }
287  /* a[generic] intersect b[generic] */
288  for (i = 0; i < a->nb_channel_layouts; i++) {
289  if (KNOWN(&a->channel_layouts[i]))
290  continue;
291  for (j = 0; j < b->nb_channel_layouts; j++)
292  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
293  if (check)
294  return 1;
295  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
296  }
297  }
298 
299  if (!ret_nb) {
301  return 0;
302  }
303 
304  if (a->refcount > b->refcount)
306 
308  { av_free(channel_layouts); return AVERROR(ENOMEM); });
309  av_freep(&b->channel_layouts);
310  b->channel_layouts = channel_layouts;
311  b->nb_channel_layouts = ret_nb;
312  return 1;
313 }
314 
315 static int can_merge_channel_layouts(const void *a, const void *b)
316 {
318  (AVFilterChannelLayouts *)b, 1);
319 }
320 
321 static int merge_channel_layouts(void *a, void *b)
322 {
323  return merge_channel_layouts_internal(a, b, 0);
324 }
325 
327  AVFilterFormats *b, int check)
328 {
329  av_assert2(check || (a->refcount && b->refcount));
330 
331  if (a == b)
332  return 1;
333 
334  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
335 
336  return 1;
337 }
338 
339 static int can_merge_generic(const void *a, const void *b)
340 {
342  (AVFilterFormats *)b, 1);
343 }
344 
345 static int merge_generic(void *a, void *b)
346 {
347  return merge_generic_internal(a, b, 0);
348 }
349 
350 #define PRINT_NAME(type, type_name) \
351 static void print_##type_name(AVBPrint *bp, const void *fmtsp) \
352 { \
353  const AVFilterFormats *fmts = fmtsp; \
354  for (int i = 0; i < fmts->nb_formats; i++) { \
355  const char *name = av_##type_name(fmts->formats[i]); \
356  av_bprint_chars(bp, ' ', i ? 1 : 0); \
357  av_bprint_append_data(bp, name, name ? strlen(name) : 0); \
358  } \
359 }
360 
361 PRINT_NAME(enum AVSampleFormat, get_sample_fmt_name)
362 PRINT_NAME(enum AVPixelFormat, get_pix_fmt_name)
363 PRINT_NAME(enum AVColorSpace, color_space_name)
364 PRINT_NAME(enum AVColorRange, color_range_name)
365 PRINT_NAME(enum AVAlphaMode, alpha_mode_name)
366 
367 static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
368 {
369  const AVFilterChannelLayouts *layouts = layoutsp;
370  for (int i = 0; i < layouts->nb_channel_layouts; i++) {
371  av_bprint_chars(bp, ' ', i ? 1 : 0);
372  av_channel_layout_describe_bprint(&layouts->channel_layouts[i], bp);
373  }
374 }
375 
376 static void print_sample_rate(AVBPrint *bp, const void *ratesp)
377 {
378  const AVFilterFormats *rates = ratesp;
379  for (int i = 0; i < rates->nb_formats; i++)
380  av_bprintf(bp, "%s%d", i ? " " : "", rates->formats[i]);
381 }
382 
383 #define CONVERSION_FILTER_SWSCALE \
384  .conversion_filter = "scale", \
385  .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
386 
387 #define CONVERSION_FILTER_ARESAMPLE \
388  .conversion_filter = "aresample", \
389  .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
390 
391 static const AVFilterFormatsMerger mergers_video[] = {
392  {
393  .name = "Pixel formats",
394  .offset = offsetof(AVFilterFormatsConfig, formats),
395  .merge = merge_pix_fmts,
396  .can_merge = can_merge_pix_fmts,
397  .print_list = print_get_pix_fmt_name,
399  },
400  {
401  .name = "Color spaces",
402  .offset = offsetof(AVFilterFormatsConfig, color_spaces),
403  .merge = merge_generic,
404  .can_merge = can_merge_generic,
405  .print_list = print_color_space_name,
407  },
408  {
409  .name = "Color ranges",
410  .offset = offsetof(AVFilterFormatsConfig, color_ranges),
411  .merge = merge_generic,
412  .can_merge = can_merge_generic,
413  .print_list = print_color_range_name,
415  },
416  {
417  .name = "Alpha modes",
418  .offset = offsetof(AVFilterFormatsConfig, alpha_modes),
419  .merge = merge_generic,
420  .can_merge = can_merge_generic,
421  .print_list = print_alpha_mode_name,
422  .conversion_filter = "premultiply_dynamic",
423  },
424 };
425 
426 static const AVFilterFormatsMerger mergers_audio[] = {
427  {
428  .name = "Channel layouts",
429  .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
430  .merge = merge_channel_layouts,
431  .can_merge = can_merge_channel_layouts,
432  .print_list = print_channel_layout_desc,
434  },
435  {
436  .name = "Sample rates",
437  .offset = offsetof(AVFilterFormatsConfig, samplerates),
438  .merge = merge_samplerates,
439  .can_merge = can_merge_samplerates,
440  .print_list = print_sample_rate,
442  },
443  {
444  .name = "Sample formats",
445  .offset = offsetof(AVFilterFormatsConfig, formats),
446  .merge = merge_sample_fmts,
447  .can_merge = can_merge_sample_fmts,
448  .print_list = print_get_sample_fmt_name,
450  },
451 };
452 
453 static const AVFilterNegotiation negotiate_video = {
455  .mergers = mergers_video,
456 };
457 
458 static const AVFilterNegotiation negotiate_audio = {
460  .mergers = mergers_audio,
461 };
462 
464 {
465  switch (link->type) {
466  case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
467  case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
468  default: return NULL;
469  }
470 }
471 
472 int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
473 {
474  for (; *fmts != AV_PIX_FMT_NONE; ++fmts) {
475  if (fmt == *fmts)
476  return 1;
477  }
478  return 0;
479 }
480 
481 #define MAKE_FORMAT_LIST(type, field, count_field) \
482  type *formats; \
483  int count = 0; \
484  if (fmts) \
485  for (count = 0; fmts[count] != -1; count++) \
486  ; \
487  formats = av_mallocz(sizeof(*formats)); \
488  if (!formats) \
489  return NULL; \
490  formats->count_field = count; \
491  if (count) { \
492  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
493  if (!formats->field) { \
494  av_freep(&formats); \
495  return NULL; \
496  } \
497  }
498 
499 #define MAKE_FORMAT_LIST_TYPE(name, type) \
500  AVFilterFormats *ff_make_ ## name ## _list(const type* fmts) \
501  { \
502  MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats); \
503  while (count--) \
504  formats->formats[count] = (int)fmts[count]; \
505  return formats; \
506  }
507 
510 MAKE_FORMAT_LIST_TYPE(pixel_format, enum AVPixelFormat)
511 
513 {
514  AVFilterChannelLayouts *ch_layouts;
515  int count = 0;
516  if (fmts)
517  for (count = 0; fmts[count].nb_channels; count++)
518  ;
519  ch_layouts = av_mallocz(sizeof(*ch_layouts));
520  if (!ch_layouts)
521  return NULL;
522  ch_layouts->nb_channel_layouts = count;
523  if (count) {
524  ch_layouts->channel_layouts =
525  av_calloc(count, sizeof(*ch_layouts->channel_layouts));
526  if (!ch_layouts->channel_layouts) {
527  av_freep(&ch_layouts);
528  return NULL;
529  }
530  for (int i = 0; i < count; i++) {
531  int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
532  if (ret < 0)
533  goto fail;
534  }
535  }
536 
537  return ch_layouts;
538 
539 fail:
540  for (int i = 0; i < count; i++)
542  av_free(ch_layouts->channel_layouts);
543  av_freep(&ch_layouts);
544 
545  return NULL;
546 }
547 
548 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
549 do { \
550  type *fmts; \
551  \
552  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
553  return AVERROR(ENOMEM); \
554  } \
555  \
556  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
557  sizeof(*(*f)->list)); \
558  if (!fmts) { \
559  unref_fn(f); \
560  return AVERROR(ENOMEM); \
561  } \
562  \
563  (*f)->list = fmts; \
564  ASSIGN_FMT(f, fmt, list, nb); \
565 } while (0)
566 
567 #define ASSIGN_FMT(f, fmt, list, nb) \
568 do { \
569  (*f)->list[(*f)->nb++] = fmt; \
570 } while (0)
571 
572 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
573 {
574  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
575  return 0;
576 }
577 
578 #undef ASSIGN_FMT
579 #define ASSIGN_FMT(f, fmt, list, nb) \
580 do { \
581  int ret; \
582  memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
583  ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
584  if (ret < 0) \
585  return ret; \
586  (*f)->nb++; \
587 } while (0)
588 
590  const AVChannelLayout *channel_layout)
591 {
592  av_assert1(!(*l && (*l)->all_layouts));
593  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
594  return 0;
595 }
596 
598 {
599  int fmts[2] = { fmt, -1 };
600  return ff_make_format_list(fmts);
601 }
602 
604 {
606 
607  if (type == AVMEDIA_TYPE_VIDEO) {
608  return ff_formats_pixdesc_filter(0, 0);
609  } else if (type == AVMEDIA_TYPE_AUDIO) {
610  enum AVSampleFormat fmt = 0;
611  while (av_get_sample_fmt_name(fmt)) {
612  if (ff_add_format(&ret, fmt) < 0)
613  return NULL;
614  fmt++;
615  }
616  }
617 
618  return ret;
619 }
620 
621 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
622 {
623  unsigned nb_formats, fmt, flags;
625 
626  while (1) {
627  nb_formats = 0;
628  for (fmt = 0;; fmt++) {
630  if (!desc)
631  break;
632  flags = desc->flags;
633  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
634  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
635  (desc->log2_chroma_w || desc->log2_chroma_h))
637  if ((flags & (want | rej)) != want)
638  continue;
639  if (formats)
640  formats->formats[nb_formats] = fmt;
641  nb_formats++;
642  }
643  if (formats) {
644  av_assert0(formats->nb_formats == nb_formats);
645  return formats;
646  }
647  formats = av_mallocz(sizeof(*formats));
648  if (!formats)
649  return NULL;
650  formats->nb_formats = nb_formats;
651  if (nb_formats) {
652  formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
653  if (!formats->formats) {
654  av_freep(&formats);
655  return NULL;
656  }
657  }
658  }
659 }
660 
662 {
664  int fmt;
665 
666  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
667  if (av_sample_fmt_is_planar(fmt))
668  if (ff_add_format(&ret, fmt) < 0)
669  return NULL;
670 
671  return ret;
672 }
673 
675 {
676  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
677  return ret;
678 }
679 
681 {
683  if (!ret)
684  return NULL;
685  ret->all_layouts = 1;
686  return ret;
687 }
688 
690 {
692  if (!ret)
693  return NULL;
694  ret->all_layouts = ret->all_counts = 1;
695  return ret;
696 }
697 
699 {
702  return NULL;
703  for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
704  if (csp == AVCOL_SPC_RESERVED ||
705  csp == AVCOL_SPC_UNSPECIFIED)
706  continue;
707  if (ff_add_format(&ret, csp) < 0)
708  return NULL;
709  }
710 
711  return ret;
712 }
713 
715 {
717  for (int range = 0; range < AVCOL_RANGE_NB; range++) {
718  if (ff_add_format(&ret, range) < 0)
719  return NULL;
720  }
721 
722  return ret;
723 }
724 
726 {
729  return NULL;
730  return ret;
731 }
732 
734 {
736  for (int am = 0; am < AVALPHA_MODE_NB; am++) {
737  if (ff_add_format(&ret, am) < 0)
738  return NULL;
739  }
740 
741  return ret;
742 }
743 
744 #define FORMATS_REF(f, ref, unref_fn) \
745  void *tmp; \
746  \
747  if (!f) \
748  return AVERROR(ENOMEM); \
749  \
750  tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs)); \
751  if (!tmp) { \
752  unref_fn(&f); \
753  return AVERROR(ENOMEM); \
754  } \
755  f->refs = tmp; \
756  f->refs[f->refcount++] = ref; \
757  *ref = f; \
758  return 0
759 
761 {
763 }
764 
766 {
768 }
769 
770 #define FIND_REF_INDEX(ref, idx) \
771 do { \
772  int i; \
773  for (i = 0; i < (*ref)->refcount; i ++) \
774  if((*ref)->refs[i] == ref) { \
775  idx = i; \
776  break; \
777  } \
778 } while (0)
779 
780 #define FORMATS_UNREF(ref, list) \
781 do { \
782  int idx = -1; \
783  \
784  if (!*ref) \
785  return; \
786  \
787  FIND_REF_INDEX(ref, idx); \
788  \
789  if (idx >= 0) { \
790  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
791  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
792  --(*ref)->refcount; \
793  } \
794  if (!(*ref)->refcount) { \
795  FREE_LIST(ref, list); \
796  av_free((*ref)->list); \
797  av_free((*ref)->refs); \
798  av_free(*ref); \
799  } \
800  *ref = NULL; \
801 } while (0)
802 
803 #define FREE_LIST(ref, list) do { } while(0)
805 {
807 }
808 
809 #undef FREE_LIST
810 #define FREE_LIST(ref, list) \
811  do { \
812  for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
813  av_channel_layout_uninit(&(*ref)->list[i]); \
814  } while(0)
815 
817 {
819 }
820 
821 #define FORMATS_CHANGEREF(oldref, newref) \
822 do { \
823  int idx = -1; \
824  \
825  FIND_REF_INDEX(oldref, idx); \
826  \
827  if (idx >= 0) { \
828  (*oldref)->refs[idx] = newref; \
829  *newref = *oldref; \
830  *oldref = NULL; \
831  } \
832 } while (0)
833 
835  AVFilterChannelLayouts **newref)
836 {
837  FORMATS_CHANGEREF(oldref, newref);
838 }
839 
841 {
842  FORMATS_CHANGEREF(oldref, newref);
843 }
844 
845 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
846  int i; \
847  \
848  if (!fmts) \
849  return AVERROR(ENOMEM); \
850  \
851  for (i = 0; i < ctx->nb_inputs; i++) { \
852  AVFilterLink *const link = ctx->inputs[i]; \
853  if (link && !link->outcfg.fmts && \
854  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
855  int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
856  if (ret < 0) { \
857  return ret; \
858  } \
859  } \
860  } \
861  for (i = 0; i < ctx->nb_outputs; i++) { \
862  AVFilterLink *const link = ctx->outputs[i]; \
863  if (link && !link->incfg.fmts && \
864  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
865  int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
866  if (ret < 0) { \
867  return ret; \
868  } \
869  } \
870  } \
871  \
872  if (!fmts->refcount) \
873  unref_fn(&fmts); \
874  \
875  return 0;
876 
879 {
882 }
883 
885  const AVChannelLayout *fmts)
886 {
888 }
889 
891 {
893 }
894 
896  AVFilterFormats *samplerates)
897 {
900 }
901 
903  const int *samplerates)
904 {
905  return ff_set_common_samplerates(ctx, ff_make_format_list(samplerates));
906 }
907 
909 {
911 }
912 
914  AVFilterFormats *color_spaces)
915 {
918 }
919 
921  const int *color_spaces)
922 {
923  return ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces));
924 }
925 
927 {
929 }
930 
932  AVFilterFormats *color_ranges)
933 {
936 }
937 
939  const int *color_ranges)
940 {
941  return ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges));
942 }
943 
945 {
947 }
948 
950  AVFilterFormats *alpha_modes)
951 {
954 }
955 
957  const int *alpha_modes)
958 {
959  return ff_set_common_alpha_modes(ctx, ff_make_format_list(alpha_modes));
960 }
961 
963 {
965 }
966 
968 {
970 }
971 
972 /**
973  * A helper for query_formats() which sets all links to the same list of
974  * formats. If there are no links hooked to this filter, the list of formats is
975  * freed.
976  */
978 {
981 }
982 
984 {
986 }
987 
989 {
991 }
992 
994 {
996 }
997 
998 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
999  ref_fn, unref_fn) \
1000  if (!fmts) \
1001  return AVERROR(ENOMEM); \
1002  \
1003  for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
1004  const AVFilterLink *const link = ctx->inputs[i]; \
1005  if (!cfg_in[i]->fmts && \
1006  (media_type == AVMEDIA_TYPE_UNKNOWN || \
1007  link->type == media_type)) { \
1008  int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
1009  if (ret < 0) { \
1010  return ret; \
1011  } \
1012  } \
1013  } \
1014  for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
1015  const AVFilterLink *const link = ctx->outputs[i]; \
1016  if (!cfg_out[i]->fmts && \
1017  (media_type == AVMEDIA_TYPE_UNKNOWN || \
1018  link->type == media_type)) { \
1019  int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
1020  if (ret < 0) { \
1021  return ret; \
1022  } \
1023  } \
1024  } \
1025  \
1026  if (!fmts->refcount) \
1027  unref_fn(&fmts); \
1028  \
1029  return 0;
1032  AVFilterFormatsConfig **cfg_in,
1033  AVFilterFormatsConfig **cfg_out,
1035 {
1038 }
1041  AVFilterFormatsConfig **cfg_in,
1042  AVFilterFormatsConfig **cfg_out,
1043  const AVChannelLayout *fmts)
1044 {
1045  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
1046 }
1049  AVFilterFormatsConfig **cfg_in,
1050  AVFilterFormatsConfig **cfg_out)
1051 {
1052  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
1053 }
1056  AVFilterFormatsConfig **cfg_in,
1057  AVFilterFormatsConfig **cfg_out,
1058  AVFilterFormats *samplerates)
1059 {
1060  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, samplerates, AVMEDIA_TYPE_AUDIO,
1062 }
1065  AVFilterFormatsConfig **cfg_in,
1066  AVFilterFormatsConfig **cfg_out,
1067  const int *samplerates)
1068 {
1069  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_make_format_list(samplerates));
1070 }
1073  AVFilterFormatsConfig **cfg_in,
1074  AVFilterFormatsConfig **cfg_out)
1075 {
1076  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1077 }
1080  AVFilterFormatsConfig **cfg_in,
1081  AVFilterFormatsConfig **cfg_out,
1082  AVFilterFormats *color_spaces)
1083 {
1084  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_spaces, AVMEDIA_TYPE_VIDEO,
1086 }
1089  AVFilterFormatsConfig **cfg_in,
1090  AVFilterFormatsConfig **cfg_out,
1091  const int *color_spaces)
1092 {
1093  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_make_format_list(color_spaces));
1094 }
1097  AVFilterFormatsConfig **cfg_in,
1098  AVFilterFormatsConfig **cfg_out)
1099 {
1100  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
1101 }
1104  AVFilterFormatsConfig **cfg_in,
1105  AVFilterFormatsConfig **cfg_out,
1106  AVFilterFormats *color_ranges)
1107 {
1108  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_ranges, AVMEDIA_TYPE_VIDEO,
1110 }
1113  AVFilterFormatsConfig **cfg_in,
1114  AVFilterFormatsConfig **cfg_out,
1115  const int *color_ranges)
1116 {
1117  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_make_format_list(color_ranges));
1118 }
1121  AVFilterFormatsConfig **cfg_in,
1122  AVFilterFormatsConfig **cfg_out)
1123 {
1124  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1125 }
1128  AVFilterFormatsConfig **cfg_in,
1129  AVFilterFormatsConfig **cfg_out,
1130  AVFilterFormats *alpha_modes)
1131 {
1132  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, alpha_modes, AVMEDIA_TYPE_VIDEO,
1134 }
1137  AVFilterFormatsConfig **cfg_in,
1138  AVFilterFormatsConfig **cfg_out,
1139  const int *alpha_modes)
1140 {
1141  return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_make_format_list(alpha_modes));
1142 }
1145  AVFilterFormatsConfig **cfg_in,
1146  AVFilterFormatsConfig **cfg_out)
1147 {
1148  return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_all_alpha_modes());
1149 }
1152  AVFilterFormatsConfig **cfg_in,
1153  AVFilterFormatsConfig **cfg_out,
1155 {
1158 }
1161  AVFilterFormatsConfig **cfg_in,
1162  AVFilterFormatsConfig **cfg_out,
1163  const int *fmts)
1164 {
1165  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1166 }
1169  AVFilterFormatsConfig **cfg_in,
1170  AVFilterFormatsConfig **cfg_out,
1171  const enum AVSampleFormat *fmts)
1172 {
1173  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_sample_format_list(fmts));
1174 }
1177  AVFilterFormatsConfig **cfg_in,
1178  AVFilterFormatsConfig **cfg_out,
1179  const enum AVPixelFormat *fmts)
1180 {
1181  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_pixel_format_list(fmts));
1182 }
1185 {
1186  const FFFilter *const f = fffilter(ctx->filter);
1188  enum AVMediaType type;
1189  int ret;
1190 
1191  switch (f->formats_state) {
1194  formats = ff_make_pixel_format_list(f->formats.pixels_list);
1195  break;
1198  formats = ff_make_sample_format_list(f->formats.samples_list);
1199  break;
1202  formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1203  break;
1206  formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1207  break;
1208  default:
1209  av_assert2(!"Unreachable");
1215  formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1216  ctx->nb_outputs ? ctx->outputs[0]->type :
1218  break;
1219  }
1220 
1222  if (ret < 0)
1223  return ret;
1224  if (type != AVMEDIA_TYPE_AUDIO) {
1226  if (ret < 0)
1227  return ret;
1229  if (ret < 0)
1230  return ret;
1232  if (ret < 0)
1233  return ret;
1234  }
1235  if (type != AVMEDIA_TYPE_VIDEO) {
1237  if (ret < 0)
1238  return ret;
1240  if (ret < 0)
1241  return ret;
1242  }
1243 
1244  return 0;
1245 }
1247 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1248 {
1249  unsigned i, j;
1250 
1251  if (!fmts)
1252  return 0;
1253  if (!fmts->nb_formats) {
1254  av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1255  return AVERROR(EINVAL);
1256  }
1257  for (i = 0; i < fmts->nb_formats; i++) {
1258  for (j = i + 1; j < fmts->nb_formats; j++) {
1259  if (fmts->formats[i] == fmts->formats[j]) {
1260  av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1261  return AVERROR(EINVAL);
1262  }
1263  }
1264  }
1265  return 0;
1266 }
1268 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1269 {
1270  return check_list(log, "pixel format", fmts);
1271 }
1273 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1274 {
1275  return check_list(log, "sample format", fmts);
1276 }
1278 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1279 {
1280  if (!fmts || !fmts->nb_formats)
1281  return 0;
1282  return check_list(log, "sample rate", fmts);
1283 }
1285 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1286 {
1287  for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1288  if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1289  av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1290  return AVERROR(EINVAL);
1291  }
1292  }
1293  return check_list(log, "color space", fmts);
1294 }
1296 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1297 {
1298  return check_list(log, "color range", fmts);
1299 }
1301 int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1302 {
1303  return check_list(log, "alpha mode", fmts);
1304 }
1306 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1307 {
1308  return !av_channel_layout_compare(a, b) ||
1309  (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1310  (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1311 }
1314 {
1315  unsigned i, j;
1316 
1317  if (!fmts)
1318  return 0;
1319  if (fmts->all_layouts < fmts->all_counts) {
1320  av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1321  return AVERROR(EINVAL);
1322  }
1323  if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1324  av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1325  return AVERROR(EINVAL);
1326  }
1327  for (i = 0; i < fmts->nb_channel_layouts; i++) {
1328  for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1329  if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1330  av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1331  return AVERROR(EINVAL);
1332  }
1333  }
1334  }
1335  return 0;
1336 }
can_merge_generic
static int can_merge_generic(const void *a, const void *b)
Definition: formats.c:338
merge_generic_internal
static int merge_generic_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition: formats.c:325
formats
formats
Definition: signature.h:47
ff_set_common_all_alpha_modes2
int ff_set_common_all_alpha_modes2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:1143
FF_FILTER_FORMATS_PIXFMT_LIST
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Definition: filters.h:232
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
CONVERSION_FILTER_SWSCALE
#define CONVERSION_FILTER_SWSCALE
Definition: formats.c:382
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
can_merge_sample_fmts
static int can_merge_sample_fmts(const void *a, const void *b)
See can_merge_pix_fmts().
Definition: formats.c:170
AVALPHA_MODE_STRAIGHT
@ AVALPHA_MODE_STRAIGHT
Alpha channel is independent of color values.
Definition: pixfmt.h:819
merge_formats_internal
static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type, int check)
Definition: formats.c:95
ff_set_common_channel_layouts2
int ff_set_common_channel_layouts2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterChannelLayouts *channel_layouts)
Helpers for query_formats2() which set all free audio links to the same list of channel layouts/sampl...
Definition: formats.c:1030
FF_FILTER_FORMATS_SAMPLEFMTS_LIST
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
Definition: filters.h:233
can_merge_pix_fmts
static int can_merge_pix_fmts(const void *a, const void *b)
Check the formats lists for compatibility for merging without actually merging.
Definition: formats.c:144
ff_set_common_color_ranges2
int ff_set_common_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_ranges)
Definition: formats.c:1102
ff_set_common_alpha_modes
int ff_set_common_alpha_modes(AVFilterContext *ctx, AVFilterFormats *alpha_modes)
Definition: formats.c:948
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:759
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:335
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3460
ff_set_common_all_channel_counts2
int ff_set_common_all_channel_counts2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:1047
ff_formats_check_pixel_formats
int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid pixel formats list.
Definition: formats.c:1267
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1150
int64_t
long long int64_t
Definition: coverity.c:34
ff_set_common_samplerates_from_list
int ff_set_common_samplerates_from_list(AVFilterContext *ctx, const int *samplerates)
Equivalent to ff_set_common_samplerates(ctx, ff_make_format_list(samplerates))
Definition: formats.c:901
PRINT_NAME
#define PRINT_NAME(type, type_name)
Definition: formats.c:349
merge_generic
static int merge_generic(void *a, void *b)
Definition: formats.c:344
normalize.log
log
Definition: normalize.py:21
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:688
can_merge_channel_layouts
static int can_merge_channel_layouts(const void *a, const void *b)
Definition: formats.c:314
ff_set_pixel_formats_from_list2
int ff_set_pixel_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVPixelFormat *fmts)
Definition: formats.c:1175
ff_set_common_all_color_spaces
int ff_set_common_all_color_spaces(AVFilterContext *ctx)
Equivalent to ff_set_common_color_spaces(ctx, ff_all_color_spaces())
Definition: formats.c:925
pixdesc.h
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:726
b
#define b
Definition: input.c:43
ff_make_pixel_format_list
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
mergers_video
static const AVFilterFormatsMerger mergers_video[]
Definition: formats.c:390
filters.h
MERGE_FORMATS
#define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed)
Add all formats common to a and b to a, add b's refs to a and destroy b.
Definition: formats.c:63
ff_set_common_channel_layouts_from_list2
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition: formats.c:1039
ff_set_common_all_samplerates
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition: formats.c:907
AVFilterFormats::formats
int * formats
list of media formats
Definition: formats.h:66
merge_samplerates_internal
static int merge_samplerates_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition: formats.c:184
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:329
ff_make_formats_list_singleton
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition: formats.c:596
ff_set_common_color_ranges_from_list2
int ff_set_common_color_ranges_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_ranges)
Definition: formats.c:1111
FORMATS_UNREF
#define FORMATS_UNREF(ref, list)
Definition: formats.c:779
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:600
CONVERSION_FILTER_ARESAMPLE
#define CONVERSION_FILTER_ARESAMPLE
Definition: formats.c:386
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
layouts_compatible
static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
Definition: formats.c:1305
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:710
SET_COMMON_FORMATS
#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:844
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
AVCOL_RANGE_NB
@ AVCOL_RANGE_NB
Not part of ABI.
Definition: pixfmt.h:784
type
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 type
Definition: writing_filters.txt:86
ff_set_common_color_spaces_from_list
int ff_set_common_color_spaces_from_list(AVFilterContext *ctx, const int *color_spaces)
Equivalent to ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces))
Definition: formats.c:919
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:669
ff_all_formats
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition: formats.c:602
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:670
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:976
ff_set_common_color_spaces2
int ff_set_common_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_spaces)
Definition: formats.c:1078
FFFilter
Definition: filters.h:267
check
#define check(x, y, S, v)
Definition: motion_est_template.c:405
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
SET_COMMON_FORMATS2
#define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:997
ff_set_pixel_formats_from_list
int ff_set_pixel_formats_from_list(AVFilterContext *ctx, const enum AVPixelFormat *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_pixel_format_list(fmts))
Definition: formats.c:992
FF_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: filters.h:230
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:201
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:764
ff_set_common_formats_from_list
int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_format_list(fmts))
Definition: formats.c:982
ff_make_format_list
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:464
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:114
ff_set_sample_formats_from_list
int ff_set_sample_formats_from_list(AVFilterContext *ctx, const enum AVSampleFormat *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_sample_format_list(fmts))
Definition: formats.c:987
ff_set_common_alpha_modes2
int ff_set_common_alpha_modes2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *alpha_modes)
Definition: formats.c:1126
ff_set_common_samplerates_from_list2
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition: formats.c:1063
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
ff_set_common_channel_layouts_from_list
int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx, const AVChannelLayout *fmts)
Equivalent to ff_set_common_channel_layouts(ctx, ff_make_channel_layout_list(fmts))
Definition: formats.c:883
ff_set_common_samplerates2
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition: formats.c:1054
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
link
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 link
Definition: filter_design.txt:23
ff_formats_changeref
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Definition: formats.c:839
fail
#define fail
Definition: test.h:478
ff_set_common_color_spaces_from_list2
int ff_set_common_color_spaces_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_spaces)
Definition: formats.c:1087
NULL
#define NULL
Definition: coverity.c:32
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
merge_pix_fmts
static int merge_pix_fmts(void *a, void *b)
Merge the formats lists if they are compatible and update all the references of a and b to point to t...
Definition: formats.c:162
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
ff_formats_check_alpha_modes
int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for alpha modes.
Definition: formats.c:1300
av_fallthrough
#define av_fallthrough
Definition: attributes.h:67
print_sample_rate
static void print_sample_rate(AVBPrint *bp, const void *ratesp)
Definition: formats.c:375
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:571
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
negotiate_audio
static const AVFilterNegotiation negotiate_audio
Definition: formats.c:457
ff_filter_get_negotiation
const AVFilterNegotiation * ff_filter_get_negotiation(const AVFilterLink *link)
Definition: formats.c:462
attributes.h
merge_samplerates
static int merge_samplerates(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:205
ff_set_common_all_channel_counts
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition: formats.c:889
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:588
ff_all_color_spaces
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition: formats.c:697
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
ff_channel_layouts_unref
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition: formats.c:815
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:120
ff_formats_check_sample_formats
int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample formats list.
Definition: formats.c:1272
AVAlphaMode
AVAlphaMode
Correlation between the alpha channel and color values.
Definition: pixfmt.h:816
MERGE_REF
#define MERGE_REF(ret, a, fmts, type, fail_statement)
Add all refs from a to ret and destroy a.
Definition: formats.c:36
f
f
Definition: af_crystalizer.c:122
ff_formats_check_color_spaces
int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for YUV colorspace metadata.
Definition: formats.c:1284
AVMediaType
AVMediaType
Definition: avutil.h:198
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:475
ff_default_query_formats
int ff_default_query_formats(AVFilterContext *ctx)
Sets all remaining unset filter lists for all inputs/outputs to their corresponding ff_all_*() lists.
Definition: formats.c:1183
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
merge_channel_layouts_internal
static int merge_channel_layouts_internal(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b, int check)
See merge_pix_fmts().
Definition: formats.c:213
check_list
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
Definition: formats.c:1246
ff_set_common_color_ranges_from_list
int ff_set_common_color_ranges_from_list(AVFilterContext *ctx, const int *color_ranges)
Equivalent to ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges))
Definition: formats.c:937
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AVFilterChannelLayouts::channel_layouts
AVChannelLayout * channel_layouts
list of channel layouts
Definition: formats.h:86
AVFilterChannelLayouts::all_layouts
char all_layouts
accept any known channel layout
Definition: formats.h:88
AVFilterChannelLayouts::all_counts
char all_counts
accept any channel layout or count
Definition: formats.h:89
AVALPHA_MODE_NB
@ AVALPHA_MODE_NB
Not part of ABI.
Definition: pixfmt.h:820
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:199
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2594
ff_formats_check_channel_layouts
int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
Check that fmts is a valid channel layouts list.
Definition: formats.c:1312
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
ff_all_color_ranges
AVFilterFormats * ff_all_color_ranges(void)
Construct an AVFilterFormats representing all possible color ranges.
Definition: formats.c:713
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:679
FF_FILTER_FORMATS_PASSTHROUGH
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
Definition: filters.h:229
ADD_FORMAT
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:547
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:811
ff_formats_unref
void ff_formats_unref(AVFilterFormats **ref)
If *ref is non-NULL, remove *ref as a reference to the format list it currently points to,...
Definition: formats.c:803
ff_set_common_color_ranges
int ff_set_common_color_ranges(AVFilterContext *ctx, AVFilterFormats *color_ranges)
Definition: formats.c:930
ff_set_common_alpha_modes_from_list2
int ff_set_common_alpha_modes_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *alpha_modes)
Definition: formats.c:1135
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
ff_formats_pixdesc_filter
AVFilterFormats * ff_formats_pixdesc_filter(unsigned want, unsigned rej)
Construct a formats list containing all pixel formats with certain properties.
Definition: formats.c:620
bprint.h
MAKE_FORMAT_LIST_TYPE
#define MAKE_FORMAT_LIST_TYPE(name, type)
Definition: formats.c:498
FORMATS_REF
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:743
ff_formats_check_sample_rates
int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample rates list.
Definition: formats.c:1277
round
static av_always_inline av_const double round(double x)
Definition: libm.h:446
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
AVColorSpace
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:706
common.h
FORMATS_CHANGEREF
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:820
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:58
ff_set_common_all_alpha_modes
int ff_set_common_all_alpha_modes(AVFilterContext *ctx)
Equivalent to ff_set_common_alpha_modes(ctx, ff_all_alpha_modes())
Definition: formats.c:966
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
ff_set_common_all_color_ranges
int ff_set_common_all_color_ranges(AVFilterContext *ctx)
Equivalent to ff_set_common_color_ranges(ctx, ff_all_color_ranges())
Definition: formats.c:943
ff_planar_sample_fmts
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:660
mergers_audio
static const AVFilterFormatsMerger mergers_audio[]
Definition: formats.c:425
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:709
merge_channel_layouts
static int merge_channel_layouts(void *a, void *b)
Definition: formats.c:320
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
Definition: filters.h:235
ff_formats_check_color_ranges
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition: formats.c:1295
ff_make_sample_format_list
av_warn_unused_result AVFilterFormats * ff_make_sample_format_list(const enum AVSampleFormat *fmts)
Create a list of supported sample formats.
ret
ret
Definition: filter_design.txt:187
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
ff_set_common_color_spaces
int ff_set_common_color_spaces(AVFilterContext *ctx, AVFilterFormats *color_spaces)
Definition: formats.c:912
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:785
FF_COUNT2LAYOUT
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
ff_set_sample_formats_from_list2
int ff_set_sample_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVSampleFormat *fmts)
Definition: formats.c:1167
ff_set_common_all_color_ranges2
int ff_set_common_all_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:1119
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:673
ff_set_common_formats_from_list2
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition: formats.c:1159
channel_layout.h
ff_set_common_alpha_modes_from_list
int ff_set_common_alpha_modes_from_list(AVFilterContext *ctx, const int *alpha_modes)
Equivalent to ff_set_common_alpha_modes(ctx, ff_make_format_list(alpha_modes))
Definition: formats.c:955
rates
static const int rates[]
Definition: swresample.c:101
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
avfilter.h
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:443
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
KNOWN
#define KNOWN(l)
Definition: formats.h:111
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
can_merge_samplerates
static int can_merge_samplerates(const void *a, const void *b)
See can_merge_pix_fmts().
Definition: formats.c:197
ff_all_alpha_modes
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition: formats.c:732
AVFilterContext
An instance of a filter.
Definition: avfilter.h:273
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:450
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
AVFilterChannelLayouts::nb_channel_layouts
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
mem.h
ff_pixfmt_is_in
int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
Tell if a pixel format is contained in the provided AV_PIX_FMT_NONE-terminated list.
Definition: formats.c:471
sample_format
enum AVSampleFormat sample_format
Definition: mediacodecdec_common.c:101
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ff_set_common_all_samplerates2
int ff_set_common_all_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:1071
ff_set_common_alpha_mode_straight
int ff_set_common_alpha_mode_straight(AVFilterContext *ctx)
Equivalent to ff_set_common_alpha_modes(ctx, ff_alpha_mode_straight())
Definition: formats.c:961
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:112
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
negotiate_video
static const AVFilterNegotiation negotiate_video
Definition: formats.c:452
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:511
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:231
ff_set_common_all_color_spaces2
int ff_set_common_all_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:1095
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:894
print_channel_layout_desc
static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
Definition: formats.c:366
FF_FILTER_FORMATS_SINGLE_PIXFMT
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
Definition: filters.h:234
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:130
ff_channel_layouts_changeref
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:833
merge_sample_fmts
static int merge_sample_fmts(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:179
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:748
ff_alpha_mode_straight
AVFilterFormats * ff_alpha_mode_straight(void)
Construct an AVFilterFormats with only premultiplied alpha.
Definition: formats.c:724
ff_set_common_channel_layouts
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *channel_layouts)
Helpers for query_formats() which set all free audio links to the same list of channel layouts/sample...
Definition: formats.c:876