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/avassert.h"
23 #include "libavutil/bprint.h"
25 #include "libavutil/common.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "avfilter.h"
29 #include "filters.h"
30 #include "formats.h"
31 
32 /**
33  * Add all refs from a to ret and destroy a.
34  */
35 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
36 do { \
37  type ***tmp; \
38  int i; \
39  \
40  if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
41  sizeof(*tmp)))) \
42  { fail_statement } \
43  ret->refs = tmp; \
44  \
45  for (i = 0; i < a->refcount; i ++) { \
46  ret->refs[ret->refcount] = a->refs[i]; \
47  *ret->refs[ret->refcount++] = ret; \
48  } \
49  \
50  av_freep(&a->refs); \
51  av_freep(&a->fmts); \
52  av_freep(&a); \
53 } while (0)
54 
55 /**
56  * Add all formats common to a and b to a, add b's refs to a and destroy b.
57  * If check is set, nothing is modified and it is only checked whether
58  * the formats are compatible.
59  * If empty_allowed is set and one of a,b->nb is zero, the lists are
60  * merged; otherwise, 0 (for nonmergeability) is returned.
61  */
62 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
63 do { \
64  int i, j, k = 0, skip = 0; \
65  \
66  if (empty_allowed) { \
67  if (!a->nb || !b->nb) { \
68  if (check) \
69  return 1; \
70  if (!a->nb) \
71  FFSWAP(type *, a, b); \
72  skip = 1; \
73  } \
74  } \
75  if (!skip) { \
76  for (i = 0; i < a->nb; i++) \
77  for (j = 0; j < b->nb; j++) \
78  if (a->fmts[i] == b->fmts[j]) { \
79  if (check) \
80  return 1; \
81  a->fmts[k++] = a->fmts[i]; \
82  break; \
83  } \
84  /* Check that there was at least one common format. \
85  * Notice that both a and b are unchanged if not. */ \
86  if (!k) \
87  return 0; \
88  av_assert2(!check); \
89  a->nb = k; \
90  } \
91  \
92  MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
93 } while (0)
94 
96  enum AVMediaType type, int check)
97 {
98  int i, j;
99  int alpha1=0, alpha2=0;
100  int chroma1=0, chroma2=0;
101 
102  av_assert2(check || (a->refcount && b->refcount));
103 
104  if (a == b)
105  return 1;
106 
107  /* Do not lose chroma or alpha in merging.
108  It happens if both lists have formats with chroma (resp. alpha), but
109  the only formats in common do not have it (e.g. YUV+gray vs.
110  RGB+gray): in that case, the merging would select the gray format,
111  possibly causing a lossy conversion elsewhere in the graph.
112  To avoid that, pretend that there are no common formats to force the
113  insertion of a conversion filter. */
114  if (type == AVMEDIA_TYPE_VIDEO)
115  for (i = 0; i < a->nb_formats; i++) {
116  const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
117  for (j = 0; j < b->nb_formats; j++) {
118  const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
119  alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
120  chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
121  if (a->formats[i] == b->formats[j]) {
122  alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
123  chroma1|= adesc->nb_components > 1;
124  }
125  }
126  }
127 
128  // If chroma or alpha can be lost through merging then do not merge
129  if (alpha2 > alpha1 || chroma2 > chroma1)
130  return 0;
131 
132  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
133 
134  return 1;
135 }
136 
137 
138 /**
139  * Check the formats lists for compatibility for merging without actually
140  * merging.
141  *
142  * @return 1 if they are compatible, 0 if not.
143  */
144 static int can_merge_pix_fmts(const void *a, const void *b)
145 {
148 }
149 
150 /**
151  * Merge the formats lists if they are compatible and update all the
152  * references of a and b to point to the combined list and free the old
153  * lists as needed. The combined list usually contains the intersection of
154  * the lists of a and b.
155  *
156  * Both a and b must have owners (i.e. refcount > 0) for these functions.
157  *
158  * @return 1 if merging succeeded, 0 if a and b are incompatible
159  * and negative AVERROR code on failure.
160  * a and b are unmodified if 0 is returned.
161  */
162 static int merge_pix_fmts(void *a, void *b)
163 {
165 }
166 
167 /**
168  * See can_merge_pix_fmts().
169  */
170 static int can_merge_sample_fmts(const void *a, const void *b)
171 {
174 }
175 
176 /**
177  * See merge_pix_fmts().
178  */
179 static int merge_sample_fmts(void *a, void *b)
180 {
182 }
183 
185  AVFilterFormats *b, int check)
186 {
187  av_assert2(check || (a->refcount && b->refcount));
188  if (a == b) return 1;
189 
190  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
191  return 1;
192 }
193 
194 /**
195  * See can_merge_pix_fmts().
196  */
197 static int can_merge_samplerates(const void *a, const void *b)
198 {
200 }
201 
202 /**
203  * See merge_pix_fmts().
204  */
205 static int merge_samplerates(void *a, void *b)
206 {
207  return merge_samplerates_internal(a, b, 0);
208 }
209 
210 /**
211  * See merge_pix_fmts().
212  */
215 {
217  unsigned a_all = a->all_layouts + a->all_counts;
218  unsigned b_all = b->all_layouts + b->all_counts;
219  int ret_max, ret_nb = 0, i, j, round;
220 
221  av_assert2(a->refcount && b->refcount);
222 
223  if (a == b) return 1;
224 
225  /* Put the most generic set in a, to avoid doing everything twice */
226  if (a_all < b_all) {
228  FFSWAP(unsigned, a_all, b_all);
229  }
230  if (a_all) {
231  if (a_all == 1 && !b_all) {
232  /* keep only known layouts in b; works also for b_all = 1 */
233  for (i = j = 0; i < b->nb_channel_layouts; i++)
234  if (KNOWN(&b->channel_layouts[i]) && i != j++) {
235  if (check)
236  return 1;
237  av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
238  }
239  /* Not optimal: the unknown layouts of b may become known after
240  another merge. */
241  if (!j)
242  return 0;
243  b->nb_channel_layouts = j;
244  }
246  return 1;
247  }
248 
249  ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
250  if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
251  return AVERROR(ENOMEM);
252 
253  /* a[known] intersect b[known] */
254  for (i = 0; i < a->nb_channel_layouts; i++) {
255  if (!KNOWN(&a->channel_layouts[i]))
256  continue;
257  for (j = 0; j < b->nb_channel_layouts; j++) {
258  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
259  if (check)
260  return 1;
261  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
262  av_channel_layout_uninit(&a->channel_layouts[i]);
263  av_channel_layout_uninit(&b->channel_layouts[j]);
264  break;
265  }
266  }
267  }
268  /* 1st round: a[known] intersect b[generic]
269  2nd round: a[generic] intersect b[known] */
270  for (round = 0; round < 2; round++) {
271  for (i = 0; i < a->nb_channel_layouts; i++) {
272  AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
273  if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
274  continue;
275  bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
276  for (j = 0; j < b->nb_channel_layouts; j++)
277  if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
278  if (check)
279  return 1;
280  av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
281  }
282  }
283  /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
285  }
286  /* a[generic] intersect b[generic] */
287  for (i = 0; i < a->nb_channel_layouts; i++) {
288  if (KNOWN(&a->channel_layouts[i]))
289  continue;
290  for (j = 0; j < b->nb_channel_layouts; j++)
291  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
292  if (check)
293  return 1;
294  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
295  }
296  }
297 
298  if (!ret_nb) {
300  return 0;
301  }
302 
303  if (a->refcount > b->refcount)
305 
307  { av_free(channel_layouts); return AVERROR(ENOMEM); });
308  av_freep(&b->channel_layouts);
309  b->channel_layouts = channel_layouts;
310  b->nb_channel_layouts = ret_nb;
311  return 1;
312 }
313 
314 static int can_merge_channel_layouts(const void *a, const void *b)
315 {
317  (AVFilterChannelLayouts *)b, 1);
318 }
319 
320 static int merge_channel_layouts(void *a, void *b)
321 {
322  return merge_channel_layouts_internal(a, b, 0);
323 }
324 
326  AVFilterFormats *b, int check)
327 {
328  av_assert2(check || (a->refcount && b->refcount));
329 
330  if (a == b)
331  return 1;
332 
333  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
334 
335  return 1;
336 }
337 
338 static int can_merge_generic(const void *a, const void *b)
339 {
341  (AVFilterFormats *)b, 1);
342 }
343 
344 static int merge_generic(void *a, void *b)
345 {
346  return merge_generic_internal(a, b, 0);
347 }
348 
349 #define PRINT_NAME(type, type_name) \
350 static void print_##type_name(AVBPrint *bp, const void *fmtsp) \
351 { \
352  const AVFilterFormats *fmts = fmtsp; \
353  for (int i = 0; i < fmts->nb_formats; i++) { \
354  const char *name = av_##type_name(fmts->formats[i]); \
355  av_bprint_chars(bp, ' ', i ? 1 : 0); \
356  av_bprint_append_data(bp, name, name ? strlen(name) : 0); \
357  } \
358 }
359 
360 PRINT_NAME(enum AVSampleFormat, get_sample_fmt_name)
361 PRINT_NAME(enum AVPixelFormat, get_pix_fmt_name)
362 PRINT_NAME(enum AVColorSpace, color_space_name)
363 PRINT_NAME(enum AVColorRange, color_range_name)
364 PRINT_NAME(enum AVAlphaMode, alpha_mode_name)
365 
366 static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
367 {
368  const AVFilterChannelLayouts *layouts = layoutsp;
369  for (int i = 0; i < layouts->nb_channel_layouts; i++) {
370  av_bprint_chars(bp, ' ', i ? 1 : 0);
371  av_channel_layout_describe_bprint(&layouts->channel_layouts[i], bp);
372  }
373 }
374 
375 static void print_sample_rate(AVBPrint *bp, const void *ratesp)
376 {
377  const AVFilterFormats *rates = ratesp;
378  for (int i = 0; i < rates->nb_formats; i++)
379  av_bprintf(bp, "%s%d", i ? " " : "", rates->formats[i]);
380 }
381 
382 #define CONVERSION_FILTER_SWSCALE \
383  .conversion_filter = "scale", \
384  .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
385 
386 #define CONVERSION_FILTER_ARESAMPLE \
387  .conversion_filter = "aresample", \
388  .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
389 
390 static const AVFilterFormatsMerger mergers_video[] = {
391  {
392  .name = "Pixel formats",
393  .offset = offsetof(AVFilterFormatsConfig, formats),
394  .merge = merge_pix_fmts,
395  .can_merge = can_merge_pix_fmts,
396  .print_list = print_get_pix_fmt_name,
398  },
399  {
400  .name = "Color spaces",
401  .offset = offsetof(AVFilterFormatsConfig, color_spaces),
402  .merge = merge_generic,
403  .can_merge = can_merge_generic,
404  .print_list = print_color_space_name,
406  },
407  {
408  .name = "Color ranges",
409  .offset = offsetof(AVFilterFormatsConfig, color_ranges),
410  .merge = merge_generic,
411  .can_merge = can_merge_generic,
412  .print_list = print_color_range_name,
414  },
415  {
416  .name = "Alpha modes",
417  .offset = offsetof(AVFilterFormatsConfig, alpha_modes),
418  .merge = merge_generic,
419  .can_merge = can_merge_generic,
420  .print_list = print_alpha_mode_name,
421  .conversion_filter = "premultiply_dynamic",
422  },
423 };
424 
425 static const AVFilterFormatsMerger mergers_audio[] = {
426  {
427  .name = "Channel layouts",
428  .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
429  .merge = merge_channel_layouts,
430  .can_merge = can_merge_channel_layouts,
431  .print_list = print_channel_layout_desc,
433  },
434  {
435  .name = "Sample rates",
436  .offset = offsetof(AVFilterFormatsConfig, samplerates),
437  .merge = merge_samplerates,
438  .can_merge = can_merge_samplerates,
439  .print_list = print_sample_rate,
441  },
442  {
443  .name = "Sample formats",
444  .offset = offsetof(AVFilterFormatsConfig, formats),
445  .merge = merge_sample_fmts,
446  .can_merge = can_merge_sample_fmts,
447  .print_list = print_get_sample_fmt_name,
449  },
450 };
451 
452 static const AVFilterNegotiation negotiate_video = {
454  .mergers = mergers_video,
455 };
456 
457 static const AVFilterNegotiation negotiate_audio = {
459  .mergers = mergers_audio,
460 };
461 
463 {
464  switch (link->type) {
465  case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
466  case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
467  default: return NULL;
468  }
469 }
470 
471 int ff_fmt_is_in(int fmt, const int *fmts)
472 {
473  const int *p;
474 
475  for (p = fmts; *p != -1; p++) {
476  if (fmt == *p)
477  return 1;
478  }
479  return 0;
480 }
481 
482 #define MAKE_FORMAT_LIST(type, field, count_field) \
483  type *formats; \
484  int count = 0; \
485  if (fmts) \
486  for (count = 0; fmts[count] != -1; count++) \
487  ; \
488  formats = av_mallocz(sizeof(*formats)); \
489  if (!formats) \
490  return NULL; \
491  formats->count_field = count; \
492  if (count) { \
493  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
494  if (!formats->field) { \
495  av_freep(&formats); \
496  return NULL; \
497  } \
498  }
499 
500 #define MAKE_FORMAT_LIST_TYPE(name, type) \
501  AVFilterFormats *ff_make_ ## name ## _list(const type* fmts) \
502  { \
503  MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats); \
504  while (count--) \
505  formats->formats[count] = (int)fmts[count]; \
506  return formats; \
507  }
508 
511 MAKE_FORMAT_LIST_TYPE(pixel_format, enum AVPixelFormat)
512 
514 {
516  int count = 0;
517  if (fmts)
518  for (count = 0; fmts[count].nb_channels; count++)
519  ;
520  ch_layouts = av_mallocz(sizeof(*ch_layouts));
521  if (!ch_layouts)
522  return NULL;
523  ch_layouts->nb_channel_layouts = count;
524  if (count) {
525  ch_layouts->channel_layouts =
526  av_calloc(count, sizeof(*ch_layouts->channel_layouts));
527  if (!ch_layouts->channel_layouts) {
529  return NULL;
530  }
531  for (int i = 0; i < count; i++) {
532  int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
533  if (ret < 0)
534  goto fail;
535  }
536  }
537 
538  return ch_layouts;
539 
540 fail:
541  for (int i = 0; i < count; i++)
542  av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
543  av_free(ch_layouts->channel_layouts);
545 
546  return NULL;
547 }
548 
549 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
550 do { \
551  type *fmts; \
552  \
553  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
554  return AVERROR(ENOMEM); \
555  } \
556  \
557  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
558  sizeof(*(*f)->list)); \
559  if (!fmts) { \
560  unref_fn(f); \
561  return AVERROR(ENOMEM); \
562  } \
563  \
564  (*f)->list = fmts; \
565  ASSIGN_FMT(f, fmt, list, nb); \
566 } while (0)
567 
568 #define ASSIGN_FMT(f, fmt, list, nb) \
569 do { \
570  (*f)->list[(*f)->nb++] = fmt; \
571 } while (0)
572 
573 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
574 {
575  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
576  return 0;
577 }
578 
579 #undef ASSIGN_FMT
580 #define ASSIGN_FMT(f, fmt, list, nb) \
581 do { \
582  int ret; \
583  memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
584  ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
585  if (ret < 0) \
586  return ret; \
587  (*f)->nb++; \
588 } while (0)
589 
591  const AVChannelLayout *channel_layout)
592 {
593  av_assert1(!(*l && (*l)->all_layouts));
594  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
595  return 0;
596 }
597 
599 {
600  int fmts[2] = { fmt, -1 };
601  return ff_make_format_list(fmts);
602 }
603 
605 {
607 
608  if (type == AVMEDIA_TYPE_VIDEO) {
609  return ff_formats_pixdesc_filter(0, 0);
610  } else if (type == AVMEDIA_TYPE_AUDIO) {
611  enum AVSampleFormat fmt = 0;
612  while (av_get_sample_fmt_name(fmt)) {
613  if (ff_add_format(&ret, fmt) < 0)
614  return NULL;
615  fmt++;
616  }
617  }
618 
619  return ret;
620 }
621 
622 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
623 {
624  unsigned nb_formats, fmt, flags;
626 
627  while (1) {
628  nb_formats = 0;
629  for (fmt = 0;; fmt++) {
631  if (!desc)
632  break;
633  flags = desc->flags;
634  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
635  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
636  (desc->log2_chroma_w || desc->log2_chroma_h))
638  if ((flags & (want | rej)) != want)
639  continue;
640  if (formats)
641  formats->formats[nb_formats] = fmt;
642  nb_formats++;
643  }
644  if (formats) {
645  av_assert0(formats->nb_formats == nb_formats);
646  return formats;
647  }
648  formats = av_mallocz(sizeof(*formats));
649  if (!formats)
650  return NULL;
651  formats->nb_formats = nb_formats;
652  if (nb_formats) {
653  formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
654  if (!formats->formats) {
655  av_freep(&formats);
656  return NULL;
657  }
658  }
659  }
660 }
661 
663 {
665  int fmt;
666 
667  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
668  if (av_sample_fmt_is_planar(fmt))
669  if (ff_add_format(&ret, fmt) < 0)
670  return NULL;
671 
672  return ret;
673 }
674 
676 {
677  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
678  return ret;
679 }
680 
682 {
684  if (!ret)
685  return NULL;
686  ret->all_layouts = 1;
687  return ret;
688 }
689 
691 {
693  if (!ret)
694  return NULL;
695  ret->all_layouts = ret->all_counts = 1;
696  return ret;
697 }
698 
700 {
703  return NULL;
704  for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
705  if (csp == AVCOL_SPC_RESERVED ||
706  csp == AVCOL_SPC_UNSPECIFIED)
707  continue;
708  if (ff_add_format(&ret, csp) < 0)
709  return NULL;
710  }
711 
712  return ret;
713 }
714 
716 {
718  for (int range = 0; range < AVCOL_RANGE_NB; range++) {
719  if (ff_add_format(&ret, range) < 0)
720  return NULL;
721  }
722 
723  return ret;
724 }
725 
727 {
729  for (int range = 0; range < AVALPHA_MODE_NB; range++) {
730  if (ff_add_format(&ret, range) < 0)
731  return NULL;
732  }
733 
734  return ret;
735 }
736 
737 #define FORMATS_REF(f, ref, unref_fn) \
738  void *tmp; \
739  \
740  if (!f) \
741  return AVERROR(ENOMEM); \
742  \
743  tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs)); \
744  if (!tmp) { \
745  unref_fn(&f); \
746  return AVERROR(ENOMEM); \
747  } \
748  f->refs = tmp; \
749  f->refs[f->refcount++] = ref; \
750  *ref = f; \
751  return 0
752 
754 {
756 }
757 
759 {
761 }
762 
763 #define FIND_REF_INDEX(ref, idx) \
764 do { \
765  int i; \
766  for (i = 0; i < (*ref)->refcount; i ++) \
767  if((*ref)->refs[i] == ref) { \
768  idx = i; \
769  break; \
770  } \
771 } while (0)
772 
773 #define FORMATS_UNREF(ref, list) \
774 do { \
775  int idx = -1; \
776  \
777  if (!*ref) \
778  return; \
779  \
780  FIND_REF_INDEX(ref, idx); \
781  \
782  if (idx >= 0) { \
783  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
784  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
785  --(*ref)->refcount; \
786  } \
787  if (!(*ref)->refcount) { \
788  FREE_LIST(ref, list); \
789  av_free((*ref)->list); \
790  av_free((*ref)->refs); \
791  av_free(*ref); \
792  } \
793  *ref = NULL; \
794 } while (0)
795 
796 #define FREE_LIST(ref, list) do { } while(0)
798 {
800 }
801 
802 #undef FREE_LIST
803 #define FREE_LIST(ref, list) \
804  do { \
805  for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
806  av_channel_layout_uninit(&(*ref)->list[i]); \
807  } while(0)
808 
810 {
812 }
813 
814 #define FORMATS_CHANGEREF(oldref, newref) \
815 do { \
816  int idx = -1; \
817  \
818  FIND_REF_INDEX(oldref, idx); \
819  \
820  if (idx >= 0) { \
821  (*oldref)->refs[idx] = newref; \
822  *newref = *oldref; \
823  *oldref = NULL; \
824  } \
825 } while (0)
826 
828  AVFilterChannelLayouts **newref)
829 {
830  FORMATS_CHANGEREF(oldref, newref);
831 }
832 
834 {
835  FORMATS_CHANGEREF(oldref, newref);
836 }
837 
838 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
839  int i; \
840  \
841  if (!fmts) \
842  return AVERROR(ENOMEM); \
843  \
844  for (i = 0; i < ctx->nb_inputs; i++) { \
845  AVFilterLink *const link = ctx->inputs[i]; \
846  if (link && !link->outcfg.fmts && \
847  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
848  int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
849  if (ret < 0) { \
850  return ret; \
851  } \
852  } \
853  } \
854  for (i = 0; i < ctx->nb_outputs; i++) { \
855  AVFilterLink *const link = ctx->outputs[i]; \
856  if (link && !link->incfg.fmts && \
857  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
858  int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
859  if (ret < 0) { \
860  return ret; \
861  } \
862  } \
863  } \
864  \
865  if (!fmts->refcount) \
866  unref_fn(&fmts); \
867  \
868  return 0;
869 
872 {
875 }
876 
878  const AVChannelLayout *fmts)
879 {
881 }
882 
884 {
886 }
887 
890 {
893 }
894 
896  const int *samplerates)
897 {
899 }
900 
902 {
904 }
905 
908 {
911 }
912 
914  const int *color_spaces)
915 {
917 }
918 
920 {
922 }
923 
926 {
929 }
930 
932  const int *color_ranges)
933 {
935 }
936 
938 {
940 }
941 
944 {
947 }
948 
950  const int *alpha_modes)
951 {
953 }
954 
956 {
958 }
959 
960 /**
961  * A helper for query_formats() which sets all links to the same list of
962  * formats. If there are no links hooked to this filter, the list of formats is
963  * freed.
964  */
966 {
969 }
970 
972 {
974 }
975 
977 {
979 }
980 
982 {
984 }
985 
986 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
987  ref_fn, unref_fn) \
988  if (!fmts) \
989  return AVERROR(ENOMEM); \
990  \
991  for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
992  const AVFilterLink *const link = ctx->inputs[i]; \
993  if (!cfg_in[i]->fmts && \
994  (media_type == AVMEDIA_TYPE_UNKNOWN || \
995  link->type == media_type)) { \
996  int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
997  if (ret < 0) { \
998  return ret; \
999  } \
1000  } \
1001  } \
1002  for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
1003  const AVFilterLink *const link = ctx->outputs[i]; \
1004  if (!cfg_out[i]->fmts && \
1005  (media_type == AVMEDIA_TYPE_UNKNOWN || \
1006  link->type == media_type)) { \
1007  int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
1008  if (ret < 0) { \
1009  return ret; \
1010  } \
1011  } \
1012  } \
1013  \
1014  if (!fmts->refcount) \
1015  unref_fn(&fmts); \
1016  \
1017  return 0;
1020  AVFilterFormatsConfig **cfg_in,
1021  AVFilterFormatsConfig **cfg_out,
1023 {
1026 }
1029  AVFilterFormatsConfig **cfg_in,
1030  AVFilterFormatsConfig **cfg_out,
1031  const AVChannelLayout *fmts)
1032 {
1033  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
1034 }
1037  AVFilterFormatsConfig **cfg_in,
1038  AVFilterFormatsConfig **cfg_out)
1039 {
1040  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
1041 }
1044  AVFilterFormatsConfig **cfg_in,
1045  AVFilterFormatsConfig **cfg_out,
1047 {
1050 }
1053  AVFilterFormatsConfig **cfg_in,
1054  AVFilterFormatsConfig **cfg_out,
1055  const int *samplerates)
1056 {
1058 }
1061  AVFilterFormatsConfig **cfg_in,
1062  AVFilterFormatsConfig **cfg_out)
1063 {
1064  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1065 }
1068  AVFilterFormatsConfig **cfg_in,
1069  AVFilterFormatsConfig **cfg_out,
1071 {
1074 }
1077  AVFilterFormatsConfig **cfg_in,
1078  AVFilterFormatsConfig **cfg_out,
1079  const int *color_spaces)
1080 {
1082 }
1085  AVFilterFormatsConfig **cfg_in,
1086  AVFilterFormatsConfig **cfg_out)
1087 {
1088  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
1089 }
1092  AVFilterFormatsConfig **cfg_in,
1093  AVFilterFormatsConfig **cfg_out,
1095 {
1098 }
1101  AVFilterFormatsConfig **cfg_in,
1102  AVFilterFormatsConfig **cfg_out,
1103  const int *color_ranges)
1104 {
1106 }
1109  AVFilterFormatsConfig **cfg_in,
1110  AVFilterFormatsConfig **cfg_out)
1111 {
1112  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1113 }
1116  AVFilterFormatsConfig **cfg_in,
1117  AVFilterFormatsConfig **cfg_out,
1119 {
1122 }
1125  AVFilterFormatsConfig **cfg_in,
1126  AVFilterFormatsConfig **cfg_out,
1127  const int *alpha_modes)
1128 {
1130 }
1133  AVFilterFormatsConfig **cfg_in,
1134  AVFilterFormatsConfig **cfg_out)
1135 {
1136  return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_all_alpha_modes());
1137 }
1140  AVFilterFormatsConfig **cfg_in,
1141  AVFilterFormatsConfig **cfg_out,
1143 {
1146 }
1149  AVFilterFormatsConfig **cfg_in,
1150  AVFilterFormatsConfig **cfg_out,
1151  const int *fmts)
1152 {
1153  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1154 }
1157  AVFilterFormatsConfig **cfg_in,
1158  AVFilterFormatsConfig **cfg_out,
1159  const enum AVSampleFormat *fmts)
1160 {
1161  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_sample_format_list(fmts));
1162 }
1165  AVFilterFormatsConfig **cfg_in,
1166  AVFilterFormatsConfig **cfg_out,
1167  const enum AVPixelFormat *fmts)
1168 {
1169  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_pixel_format_list(fmts));
1170 }
1173 {
1174  const FFFilter *const f = fffilter(ctx->filter);
1176  enum AVMediaType type;
1177  int ret;
1178 
1179  switch (f->formats_state) {
1182  formats = ff_make_format_list(f->formats.pixels_list);
1183  break;
1186  formats = ff_make_format_list(f->formats.samples_list);
1187  break;
1190  formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1191  break;
1194  formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1195  break;
1196  default:
1197  av_assert2(!"Unreachable");
1198  /* Intended fallthrough */
1203  formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1204  ctx->nb_outputs ? ctx->outputs[0]->type :
1206  break;
1207  }
1208 
1210  if (ret < 0)
1211  return ret;
1212  if (type != AVMEDIA_TYPE_AUDIO) {
1214  if (ret < 0)
1215  return ret;
1217  if (ret < 0)
1218  return ret;
1220  if (ret < 0)
1221  return ret;
1222  }
1223  if (type != AVMEDIA_TYPE_VIDEO) {
1225  if (ret < 0)
1226  return ret;
1228  if (ret < 0)
1229  return ret;
1230  }
1231 
1232  return 0;
1233 }
1235 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1236 {
1237  unsigned i, j;
1238 
1239  if (!fmts)
1240  return 0;
1241  if (!fmts->nb_formats) {
1242  av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1243  return AVERROR(EINVAL);
1244  }
1245  for (i = 0; i < fmts->nb_formats; i++) {
1246  for (j = i + 1; j < fmts->nb_formats; j++) {
1247  if (fmts->formats[i] == fmts->formats[j]) {
1248  av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1249  return AVERROR(EINVAL);
1250  }
1251  }
1252  }
1253  return 0;
1254 }
1256 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1257 {
1258  return check_list(log, "pixel format", fmts);
1259 }
1261 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1262 {
1263  return check_list(log, "sample format", fmts);
1264 }
1266 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1267 {
1268  if (!fmts || !fmts->nb_formats)
1269  return 0;
1270  return check_list(log, "sample rate", fmts);
1271 }
1273 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1274 {
1275  for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1276  if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1277  av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1278  return AVERROR(EINVAL);
1279  }
1280  }
1281  return check_list(log, "color space", fmts);
1282 }
1284 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1285 {
1286  return check_list(log, "color range", fmts);
1287 }
1289 int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1290 {
1291  return check_list(log, "alpha mode", fmts);
1292 }
1294 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1295 {
1296  return !av_channel_layout_compare(a, b) ||
1297  (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1298  (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1299 }
1302 {
1303  unsigned i, j;
1304 
1305  if (!fmts)
1306  return 0;
1307  if (fmts->all_layouts < fmts->all_counts) {
1308  av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1309  return AVERROR(EINVAL);
1310  }
1311  if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1312  av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1313  return AVERROR(EINVAL);
1314  }
1315  for (i = 0; i < fmts->nb_channel_layouts; i++) {
1316  for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1317  if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1318  av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1319  return AVERROR(EINVAL);
1320  }
1321  }
1322  }
1323  return 0;
1324 }
can_merge_generic
static int can_merge_generic(const void *a, const void *b)
Definition: formats.c:337
flags
const SwsFlags flags[]
Definition: swscale.c:61
merge_generic_internal
static int merge_generic_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition: formats.c:324
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:1131
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVFilterFormatsConfig::samplerates
AVFilterFormats * samplerates
Lists of supported sample rates, only for audio.
Definition: avfilter.h:131
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:381
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
FF_FILTER_FORMATS_QUERY_FUNC
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition: filters.h:229
can_merge_sample_fmts
static int can_merge_sample_fmts(const void *a, const void *b)
See can_merge_pix_fmts().
Definition: formats.c:169
merge_formats_internal
static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type, int check)
Definition: formats.c:94
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:1018
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:143
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:1090
ff_set_common_alpha_modes
int ff_set_common_alpha_modes(AVFilterContext *ctx, AVFilterFormats *alpha_modes)
Definition: formats.c:941
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:752
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:3456
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:1035
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:1255
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1138
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:894
PRINT_NAME
#define PRINT_NAME(type, type_name)
Definition: formats.c:348
merge_generic
static int merge_generic(void *a, void *b)
Definition: formats.c:343
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:689
can_merge_channel_layouts
static int can_merge_channel_layouts(const void *a, const void *b)
Definition: formats.c:313
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:1163
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:918
pixdesc.h
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:720
b
#define b
Definition: input.c:42
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:389
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:62
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:1027
FF_FILTER_FORMATS_SINGLE_PIXFMT
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
Definition: filters.h:233
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:900
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:183
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:597
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:1099
FORMATS_UNREF
#define FORMATS_UNREF(ref, list)
Definition: formats.c:772
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:599
CONVERSION_FILTER_ARESAMPLE
#define CONVERSION_FILTER_ARESAMPLE
Definition: formats.c:385
fffilter
static const FFFilter * fffilter(const AVFilter *f)
Definition: filters.h:463
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:1293
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:704
SET_COMMON_FORMATS
#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:837
fail
#define fail()
Definition: checkasm.h:217
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:778
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:912
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:657
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:603
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:658
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:964
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:1066
FFFilter
Definition: filters.h:266
check
#define check(x, y, S, v)
Definition: motion_est_template.c:405
SET_COMMON_FORMATS2
#define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:985
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:980
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:757
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:970
ff_make_format_list
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:41
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
filters.h
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:975
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:1114
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:1051
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AVFilterFormatsConfig::color_spaces
AVFilterFormats * color_spaces
Lists of supported YUV color metadata, only for YUV video.
Definition: avfilter.h:141
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:876
ff_set_common_samplerates2
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition: formats.c:1042
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:832
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:1075
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:161
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:1288
print_sample_rate
static void print_sample_rate(AVBPrint *bp, const void *ratesp)
Definition: formats.c:374
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:572
AVFilterFormats::nb_formats
unsigned nb_formats
number of formats
Definition: formats.h:65
ff_fmt_is_in
int ff_fmt_is_in(int fmt, const int *fmts)
Tell if an integer is contained in the provided -1-terminated list of integers.
Definition: formats.c:470
negotiate_audio
static const AVFilterNegotiation negotiate_audio
Definition: formats.c:456
ff_filter_get_negotiation
const AVFilterNegotiation * ff_filter_get_negotiation(const AVFilterLink *link)
Definition: formats.c:461
merge_samplerates
static int merge_samplerates(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:204
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:882
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:589
ff_all_color_spaces
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition: formats.c:698
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:808
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:121
FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
Definition: filters.h:234
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:1260
AVAlphaMode
AVAlphaMode
Correlation between the alpha channel and color values.
Definition: pixfmt.h:810
MERGE_REF
#define MERGE_REF(ret, a, fmts, type, fail_statement)
Add all refs from a to ret and destroy a.
Definition: formats.c:35
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:1272
AVMediaType
AVMediaType
Definition: avutil.h:198
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:463
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:1171
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:212
check_list
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
Definition: formats.c:1234
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:930
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:814
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:1300
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:714
AVFilterFormatsConfig::color_ranges
AVFilterFormats * color_ranges
AVColorRange.
Definition: avfilter.h:142
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:680
ADD_FORMAT
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:548
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:809
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:796
ff_set_common_color_ranges
int ff_set_common_color_ranges(AVFilterContext *ctx, AVFilterFormats *color_ranges)
Definition: formats.c:923
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:1123
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:68
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:228
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:621
bprint.h
MAKE_FORMAT_LIST_TYPE
#define MAKE_FORMAT_LIST_TYPE(name, type)
Definition: formats.c:499
FORMATS_REF
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:736
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:1265
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:700
common.h
FORMATS_CHANGEREF
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:813
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
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:954
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:936
ch_layouts
static const AVChannelLayout ch_layouts[]
Definition: adpcmenc.c:956
ff_planar_sample_fmts
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:661
mergers_audio
static const AVFilterFormatsMerger mergers_audio[]
Definition: formats.c:424
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:703
merge_channel_layouts
static int merge_channel_layouts(void *a, void *b)
Definition: formats.c:319
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
ff_formats_check_color_ranges
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition: formats.c:1283
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:905
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:783
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:1155
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:1107
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:230
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:674
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:1147
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:948
rates
static const int rates[]
Definition: swresample.c:101
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:442
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:196
ff_all_alpha_modes
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition: formats.c:725
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
AVFilterContext
An instance of a filter.
Definition: avfilter.h:274
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:449
desc
const char * desc
Definition: libsvtav1.c:78
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
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:1059
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:451
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:512
FF_FILTER_FORMATS_SAMPLEFMTS_LIST
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
Definition: filters.h:232
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
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:1083
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:887
print_channel_layout_desc
static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
Definition: formats.c:365
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:826
merge_sample_fmts
static int merge_sample_fmts(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:178
AVColorRange
AVColorRange
Visual content value range.
Definition: pixfmt.h:742
AVFilterFormatsConfig::alpha_modes
AVFilterFormats * alpha_modes
List of supported alpha modes, only for video with an alpha channel.
Definition: avfilter.h:147
FF_FILTER_FORMATS_PIXFMT_LIST
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Definition: filters.h:231
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:869