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"
24 #include "libavutil/common.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "formats.h"
30 
31 /**
32  * Add all refs from a to ret and destroy a.
33  */
34 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
35 do { \
36  type ***tmp; \
37  int i; \
38  \
39  if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
40  sizeof(*tmp)))) \
41  { fail_statement } \
42  ret->refs = tmp; \
43  \
44  for (i = 0; i < a->refcount; i ++) { \
45  ret->refs[ret->refcount] = a->refs[i]; \
46  *ret->refs[ret->refcount++] = ret; \
47  } \
48  \
49  av_freep(&a->refs); \
50  av_freep(&a->fmts); \
51  av_freep(&a); \
52 } while (0)
53 
54 /**
55  * Add all formats common to a and b to a, add b's refs to a and destroy b.
56  * If check is set, nothing is modified and it is only checked whether
57  * the formats are compatible.
58  * If empty_allowed is set and one of a,b->nb is zero, the lists are
59  * merged; otherwise, 0 (for nonmergeability) is returned.
60  */
61 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
62 do { \
63  int i, j, k = 0, skip = 0; \
64  \
65  if (empty_allowed) { \
66  if (!a->nb || !b->nb) { \
67  if (check) \
68  return 1; \
69  if (!a->nb) \
70  FFSWAP(type *, a, b); \
71  skip = 1; \
72  } \
73  } \
74  if (!skip) { \
75  for (i = 0; i < a->nb; i++) \
76  for (j = 0; j < b->nb; j++) \
77  if (a->fmts[i] == b->fmts[j]) { \
78  if (check) \
79  return 1; \
80  a->fmts[k++] = a->fmts[i]; \
81  break; \
82  } \
83  /* Check that there was at least one common format. \
84  * Notice that both a and b are unchanged if not. */ \
85  if (!k) \
86  return 0; \
87  av_assert2(!check); \
88  a->nb = k; \
89  } \
90  \
91  MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
92 } while (0)
93 
95  enum AVMediaType type, int check)
96 {
97  int i, j;
98  int alpha1=0, alpha2=0;
99  int chroma1=0, chroma2=0;
100 
101  av_assert2(check || (a->refcount && b->refcount));
102 
103  if (a == b)
104  return 1;
105 
106  /* Do not lose chroma or alpha in merging.
107  It happens if both lists have formats with chroma (resp. alpha), but
108  the only formats in common do not have it (e.g. YUV+gray vs.
109  RGB+gray): in that case, the merging would select the gray format,
110  possibly causing a lossy conversion elsewhere in the graph.
111  To avoid that, pretend that there are no common formats to force the
112  insertion of a conversion filter. */
113  if (type == AVMEDIA_TYPE_VIDEO)
114  for (i = 0; i < a->nb_formats; i++) {
115  const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
116  for (j = 0; j < b->nb_formats; j++) {
117  const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
118  alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
119  chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
120  if (a->formats[i] == b->formats[j]) {
121  alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
122  chroma1|= adesc->nb_components > 1;
123  }
124  }
125  }
126 
127  // If chroma or alpha can be lost through merging then do not merge
128  if (alpha2 > alpha1 || chroma2 > chroma1)
129  return 0;
130 
131  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
132 
133  return 1;
134 }
135 
136 
137 /**
138  * Check the formats lists for compatibility for merging without actually
139  * merging.
140  *
141  * @return 1 if they are compatible, 0 if not.
142  */
143 static int can_merge_pix_fmts(const void *a, const void *b)
144 {
147 }
148 
149 /**
150  * Merge the formats lists if they are compatible and update all the
151  * references of a and b to point to the combined list and free the old
152  * lists as needed. The combined list usually contains the intersection of
153  * the lists of a and b.
154  *
155  * Both a and b must have owners (i.e. refcount > 0) for these functions.
156  *
157  * @return 1 if merging succeeded, 0 if a and b are incompatible
158  * and negative AVERROR code on failure.
159  * a and b are unmodified if 0 is returned.
160  */
161 static int merge_pix_fmts(void *a, void *b)
162 {
164 }
165 
166 /**
167  * See can_merge_pix_fmts().
168  */
169 static int can_merge_sample_fmts(const void *a, const void *b)
170 {
173 }
174 
175 /**
176  * See merge_pix_fmts().
177  */
178 static int merge_sample_fmts(void *a, void *b)
179 {
181 }
182 
184  AVFilterFormats *b, int check)
185 {
186  av_assert2(check || (a->refcount && b->refcount));
187  if (a == b) return 1;
188 
189  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
190  return 1;
191 }
192 
193 /**
194  * See can_merge_pix_fmts().
195  */
196 static int can_merge_samplerates(const void *a, const void *b)
197 {
199 }
200 
201 /**
202  * See merge_pix_fmts().
203  */
204 static int merge_samplerates(void *a, void *b)
205 {
206  return merge_samplerates_internal(a, b, 0);
207 }
208 
209 /**
210  * See merge_pix_fmts().
211  */
214 {
216  unsigned a_all = a->all_layouts + a->all_counts;
217  unsigned b_all = b->all_layouts + b->all_counts;
218  int ret_max, ret_nb = 0, i, j, round;
219 
220  av_assert2(a->refcount && b->refcount);
221 
222  if (a == b) return 1;
223 
224  /* Put the most generic set in a, to avoid doing everything twice */
225  if (a_all < b_all) {
227  FFSWAP(unsigned, a_all, b_all);
228  }
229  if (a_all) {
230  if (a_all == 1 && !b_all) {
231  /* keep only known layouts in b; works also for b_all = 1 */
232  for (i = j = 0; i < b->nb_channel_layouts; i++)
233  if (KNOWN(&b->channel_layouts[i]) && i != j++) {
234  if (check)
235  return 1;
236  av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
237  }
238  /* Not optimal: the unknown layouts of b may become known after
239  another merge. */
240  if (!j)
241  return 0;
242  b->nb_channel_layouts = j;
243  }
245  return 1;
246  }
247 
248  ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
249  if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
250  return AVERROR(ENOMEM);
251 
252  /* a[known] intersect b[known] */
253  for (i = 0; i < a->nb_channel_layouts; i++) {
254  if (!KNOWN(&a->channel_layouts[i]))
255  continue;
256  for (j = 0; j < b->nb_channel_layouts; j++) {
257  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
258  if (check)
259  return 1;
260  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
261  av_channel_layout_uninit(&a->channel_layouts[i]);
262  av_channel_layout_uninit(&b->channel_layouts[j]);
263  break;
264  }
265  }
266  }
267  /* 1st round: a[known] intersect b[generic]
268  2nd round: a[generic] intersect b[known] */
269  for (round = 0; round < 2; round++) {
270  for (i = 0; i < a->nb_channel_layouts; i++) {
271  AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
272  if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
273  continue;
274  bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
275  for (j = 0; j < b->nb_channel_layouts; j++)
276  if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
277  if (check)
278  return 1;
279  av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
280  }
281  }
282  /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
284  }
285  /* a[generic] intersect b[generic] */
286  for (i = 0; i < a->nb_channel_layouts; i++) {
287  if (KNOWN(&a->channel_layouts[i]))
288  continue;
289  for (j = 0; j < b->nb_channel_layouts; j++)
290  if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
291  if (check)
292  return 1;
293  av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
294  }
295  }
296 
297  if (!ret_nb) {
299  return 0;
300  }
301 
302  if (a->refcount > b->refcount)
304 
306  { av_free(channel_layouts); return AVERROR(ENOMEM); });
307  av_freep(&b->channel_layouts);
308  b->channel_layouts = channel_layouts;
309  b->nb_channel_layouts = ret_nb;
310  return 1;
311 }
312 
313 static int can_merge_channel_layouts(const void *a, const void *b)
314 {
316  (AVFilterChannelLayouts *)b, 1);
317 }
318 
319 static int merge_channel_layouts(void *a, void *b)
320 {
321  return merge_channel_layouts_internal(a, b, 0);
322 }
323 
325  AVFilterFormats *b, int check)
326 {
327  av_assert2(check || (a->refcount && b->refcount));
328 
329  if (a == b)
330  return 1;
331 
332  MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
333 
334  return 1;
335 }
336 
337 static int can_merge_generic(const void *a, const void *b)
338 {
340  (AVFilterFormats *)b, 1);
341 }
342 
343 static int merge_generic(void *a, void *b)
344 {
345  return merge_generic_internal(a, b, 0);
346 }
347 
348 static const AVFilterFormatsMerger mergers_video[] = {
349  {
350  .offset = offsetof(AVFilterFormatsConfig, formats),
351  .merge = merge_pix_fmts,
352  .can_merge = can_merge_pix_fmts,
353  },
354  {
355  .offset = offsetof(AVFilterFormatsConfig, color_spaces),
356  .merge = merge_generic,
357  .can_merge = can_merge_generic,
358  },
359  {
360  .offset = offsetof(AVFilterFormatsConfig, color_ranges),
361  .merge = merge_generic,
362  .can_merge = can_merge_generic,
363  },
364 };
365 
366 static const AVFilterFormatsMerger mergers_audio[] = {
367  {
368  .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
369  .merge = merge_channel_layouts,
370  .can_merge = can_merge_channel_layouts,
371  },
372  {
373  .offset = offsetof(AVFilterFormatsConfig, samplerates),
374  .merge = merge_samplerates,
375  .can_merge = can_merge_samplerates,
376  },
377  {
378  .offset = offsetof(AVFilterFormatsConfig, formats),
379  .merge = merge_sample_fmts,
380  .can_merge = can_merge_sample_fmts,
381  },
382 };
383 
384 static const AVFilterNegotiation negotiate_video = {
386  .mergers = mergers_video,
387  .conversion_filter = "scale",
388  .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
389 };
390 
391 static const AVFilterNegotiation negotiate_audio = {
393  .mergers = mergers_audio,
394  .conversion_filter = "aresample",
395  .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
396 };
397 
399 {
400  switch (link->type) {
401  case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
402  case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
403  default: return NULL;
404  }
405 }
406 
407 int ff_fmt_is_in(int fmt, const int *fmts)
408 {
409  const int *p;
410 
411  for (p = fmts; *p != -1; p++) {
412  if (fmt == *p)
413  return 1;
414  }
415  return 0;
416 }
417 
418 #define MAKE_FORMAT_LIST(type, field, count_field) \
419  type *formats; \
420  int count = 0; \
421  if (fmts) \
422  for (count = 0; fmts[count] != -1; count++) \
423  ; \
424  formats = av_mallocz(sizeof(*formats)); \
425  if (!formats) \
426  return NULL; \
427  formats->count_field = count; \
428  if (count) { \
429  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
430  if (!formats->field) { \
431  av_freep(&formats); \
432  return NULL; \
433  } \
434  }
435 
436 AVFilterFormats *ff_make_format_list(const int *fmts)
437 {
439  while (count--)
440  formats->formats[count] = fmts[count];
441 
442  return formats;
443 }
444 
446 {
448  int count = 0;
449  if (fmts)
450  for (count = 0; fmts[count].nb_channels; count++)
451  ;
452  ch_layouts = av_mallocz(sizeof(*ch_layouts));
453  if (!ch_layouts)
454  return NULL;
455  ch_layouts->nb_channel_layouts = count;
456  if (count) {
457  ch_layouts->channel_layouts =
458  av_calloc(count, sizeof(*ch_layouts->channel_layouts));
459  if (!ch_layouts->channel_layouts) {
461  return NULL;
462  }
463  for (int i = 0; i < count; i++) {
464  int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
465  if (ret < 0)
466  goto fail;
467  }
468  }
469 
470  return ch_layouts;
471 
472 fail:
473  for (int i = 0; i < count; i++)
474  av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
475  av_free(ch_layouts->channel_layouts);
477 
478  return NULL;
479 }
480 
481 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
482 do { \
483  type *fmts; \
484  \
485  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
486  return AVERROR(ENOMEM); \
487  } \
488  \
489  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
490  sizeof(*(*f)->list)); \
491  if (!fmts) { \
492  unref_fn(f); \
493  return AVERROR(ENOMEM); \
494  } \
495  \
496  (*f)->list = fmts; \
497  ASSIGN_FMT(f, fmt, list, nb); \
498 } while (0)
499 
500 #define ASSIGN_FMT(f, fmt, list, nb) \
501 do { \
502  (*f)->list[(*f)->nb++] = fmt; \
503 } while (0)
504 
505 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
506 {
507  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
508  return 0;
509 }
510 
511 #undef ASSIGN_FMT
512 #define ASSIGN_FMT(f, fmt, list, nb) \
513 do { \
514  int ret; \
515  memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
516  ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
517  if (ret < 0) \
518  return ret; \
519  (*f)->nb++; \
520 } while (0)
521 
523  const AVChannelLayout *channel_layout)
524 {
525  av_assert1(!(*l && (*l)->all_layouts));
526  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
527  return 0;
528 }
529 
531 {
532  int fmts[2] = { fmt, -1 };
533  return ff_make_format_list(fmts);
534 }
535 
537 {
539 
540  if (type == AVMEDIA_TYPE_VIDEO) {
541  return ff_formats_pixdesc_filter(0, 0);
542  } else if (type == AVMEDIA_TYPE_AUDIO) {
543  enum AVSampleFormat fmt = 0;
544  while (av_get_sample_fmt_name(fmt)) {
545  if (ff_add_format(&ret, fmt) < 0)
546  return NULL;
547  fmt++;
548  }
549  }
550 
551  return ret;
552 }
553 
554 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
555 {
556  unsigned nb_formats, fmt, flags;
558 
559  while (1) {
560  nb_formats = 0;
561  for (fmt = 0;; fmt++) {
563  if (!desc)
564  break;
565  flags = desc->flags;
566  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
567  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
568  (desc->log2_chroma_w || desc->log2_chroma_h))
570  if ((flags & (want | rej)) != want)
571  continue;
572  if (formats)
573  formats->formats[nb_formats] = fmt;
574  nb_formats++;
575  }
576  if (formats) {
577  av_assert0(formats->nb_formats == nb_formats);
578  return formats;
579  }
580  formats = av_mallocz(sizeof(*formats));
581  if (!formats)
582  return NULL;
583  formats->nb_formats = nb_formats;
584  if (nb_formats) {
585  formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
586  if (!formats->formats) {
587  av_freep(&formats);
588  return NULL;
589  }
590  }
591  }
592 }
593 
595 {
597  int fmt;
598 
599  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
600  if (av_sample_fmt_is_planar(fmt))
601  if (ff_add_format(&ret, fmt) < 0)
602  return NULL;
603 
604  return ret;
605 }
606 
608 {
609  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
610  return ret;
611 }
612 
614 {
616  if (!ret)
617  return NULL;
618  ret->all_layouts = 1;
619  return ret;
620 }
621 
623 {
625  if (!ret)
626  return NULL;
627  ret->all_layouts = ret->all_counts = 1;
628  return ret;
629 }
630 
632 {
635  return NULL;
636  for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
637  if (csp == AVCOL_SPC_RESERVED ||
638  csp == AVCOL_SPC_UNSPECIFIED)
639  continue;
640  if (ff_add_format(&ret, csp) < 0)
641  return NULL;
642  }
643 
644  return ret;
645 }
646 
648 {
650  for (int range = 0; range < AVCOL_RANGE_NB; range++) {
651  if (ff_add_format(&ret, range) < 0)
652  return NULL;
653  }
654 
655  return ret;
656 }
657 
658 #define FORMATS_REF(f, ref, unref_fn) \
659  void *tmp; \
660  \
661  if (!f) \
662  return AVERROR(ENOMEM); \
663  \
664  tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
665  if (!tmp) { \
666  unref_fn(&f); \
667  return AVERROR(ENOMEM); \
668  } \
669  f->refs = tmp; \
670  f->refs[f->refcount++] = ref; \
671  *ref = f; \
672  return 0
673 
675 {
677 }
678 
680 {
682 }
683 
684 #define FIND_REF_INDEX(ref, idx) \
685 do { \
686  int i; \
687  for (i = 0; i < (*ref)->refcount; i ++) \
688  if((*ref)->refs[i] == ref) { \
689  idx = i; \
690  break; \
691  } \
692 } while (0)
693 
694 #define FORMATS_UNREF(ref, list) \
695 do { \
696  int idx = -1; \
697  \
698  if (!*ref) \
699  return; \
700  \
701  FIND_REF_INDEX(ref, idx); \
702  \
703  if (idx >= 0) { \
704  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
705  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
706  --(*ref)->refcount; \
707  } \
708  if (!(*ref)->refcount) { \
709  FREE_LIST(ref, list); \
710  av_free((*ref)->list); \
711  av_free((*ref)->refs); \
712  av_free(*ref); \
713  } \
714  *ref = NULL; \
715 } while (0)
716 
717 #define FREE_LIST(ref, list) do { } while(0)
719 {
721 }
722 
723 #undef FREE_LIST
724 #define FREE_LIST(ref, list) \
725  do { \
726  for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
727  av_channel_layout_uninit(&(*ref)->list[i]); \
728  } while(0)
729 
731 {
733 }
734 
735 #define FORMATS_CHANGEREF(oldref, newref) \
736 do { \
737  int idx = -1; \
738  \
739  FIND_REF_INDEX(oldref, idx); \
740  \
741  if (idx >= 0) { \
742  (*oldref)->refs[idx] = newref; \
743  *newref = *oldref; \
744  *oldref = NULL; \
745  } \
746 } while (0)
747 
749  AVFilterChannelLayouts **newref)
750 {
751  FORMATS_CHANGEREF(oldref, newref);
752 }
753 
755 {
756  FORMATS_CHANGEREF(oldref, newref);
757 }
758 
759 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
760  int i; \
761  \
762  if (!fmts) \
763  return AVERROR(ENOMEM); \
764  \
765  for (i = 0; i < ctx->nb_inputs; i++) { \
766  AVFilterLink *const link = ctx->inputs[i]; \
767  if (link && !link->outcfg.fmts && \
768  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
769  int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
770  if (ret < 0) { \
771  return ret; \
772  } \
773  } \
774  } \
775  for (i = 0; i < ctx->nb_outputs; i++) { \
776  AVFilterLink *const link = ctx->outputs[i]; \
777  if (link && !link->incfg.fmts && \
778  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
779  int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
780  if (ret < 0) { \
781  return ret; \
782  } \
783  } \
784  } \
785  \
786  if (!fmts->refcount) \
787  unref_fn(&fmts); \
788  \
789  return 0;
790 
793 {
796 }
797 
799  const AVChannelLayout *fmts)
800 {
802 }
803 
805 {
807 }
808 
810  AVFilterFormats *samplerates)
811 {
814 }
815 
817  const int *samplerates)
818 {
819  return ff_set_common_samplerates(ctx, ff_make_format_list(samplerates));
820 }
821 
823 {
825 }
826 
828  AVFilterFormats *color_spaces)
829 {
832 }
833 
835  const int *color_ranges)
836 {
837  return ff_set_common_color_spaces(ctx, ff_make_format_list(color_ranges));
838 }
839 
841 {
843 }
844 
846  AVFilterFormats *color_ranges)
847 {
850 }
851 
853  const int *color_ranges)
854 {
855  return ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges));
856 }
857 
859 {
861 }
862 
863 /**
864  * A helper for query_formats() which sets all links to the same list of
865  * formats. If there are no links hooked to this filter, the list of formats is
866  * freed.
867  */
869 {
872 }
873 
875 {
877 }
878 
879 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
880  ref_fn, unref_fn) \
881  if (!fmts) \
882  return AVERROR(ENOMEM); \
883  \
884  for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
885  const AVFilterLink *const link = ctx->inputs[i]; \
886  if (!cfg_in[i]->fmts && \
887  (media_type == AVMEDIA_TYPE_UNKNOWN || \
888  link->type == media_type)) { \
889  int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
890  if (ret < 0) { \
891  return ret; \
892  } \
893  } \
894  } \
895  for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
896  const AVFilterLink *const link = ctx->outputs[i]; \
897  if (!cfg_out[i]->fmts && \
898  (media_type == AVMEDIA_TYPE_UNKNOWN || \
899  link->type == media_type)) { \
900  int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
901  if (ret < 0) { \
902  return ret; \
903  } \
904  } \
905  } \
906  \
907  if (!fmts->refcount) \
908  unref_fn(&fmts); \
909  \
910  return 0;
911 
913  AVFilterFormatsConfig **cfg_in,
914  AVFilterFormatsConfig **cfg_out,
916 {
919 }
920 
922  AVFilterFormatsConfig **cfg_in,
923  AVFilterFormatsConfig **cfg_out,
924  const AVChannelLayout *fmts)
925 {
926  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
927 }
928 
930  AVFilterFormatsConfig **cfg_in,
931  AVFilterFormatsConfig **cfg_out)
932 {
933  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
934 }
935 
937  AVFilterFormatsConfig **cfg_in,
938  AVFilterFormatsConfig **cfg_out,
939  AVFilterFormats *samplerates)
940 {
941  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, samplerates, AVMEDIA_TYPE_AUDIO,
943 }
944 
946  AVFilterFormatsConfig **cfg_in,
947  AVFilterFormatsConfig **cfg_out,
948  const int *samplerates)
949 {
950  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_make_format_list(samplerates));
951 }
952 
954  AVFilterFormatsConfig **cfg_in,
955  AVFilterFormatsConfig **cfg_out)
956 {
957  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
958 }
959 
961  AVFilterFormatsConfig **cfg_in,
962  AVFilterFormatsConfig **cfg_out,
963  AVFilterFormats *color_spaces)
964 {
965  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_spaces, AVMEDIA_TYPE_VIDEO,
967 }
968 
970  AVFilterFormatsConfig **cfg_in,
971  AVFilterFormatsConfig **cfg_out,
972  const int *color_ranges)
973 {
974  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_make_format_list(color_ranges));
975 }
976 
978  AVFilterFormatsConfig **cfg_in,
979  AVFilterFormatsConfig **cfg_out)
980 {
981  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
982 }
983 
985  AVFilterFormatsConfig **cfg_in,
986  AVFilterFormatsConfig **cfg_out,
987  AVFilterFormats *color_ranges)
988 {
989  SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_ranges, AVMEDIA_TYPE_VIDEO,
991 }
992 
994  AVFilterFormatsConfig **cfg_in,
995  AVFilterFormatsConfig **cfg_out,
996  const int *color_ranges)
997 {
998  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_make_format_list(color_ranges));
999 }
1002  AVFilterFormatsConfig **cfg_in,
1003  AVFilterFormatsConfig **cfg_out)
1004 {
1005  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1006 }
1009  AVFilterFormatsConfig **cfg_in,
1010  AVFilterFormatsConfig **cfg_out,
1012 {
1015 }
1018  AVFilterFormatsConfig **cfg_in,
1019  AVFilterFormatsConfig **cfg_out,
1020  const int *fmts)
1021 {
1022  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1023 }
1024 
1027 {
1028  const AVFilter *const f = ctx->filter;
1030  enum AVMediaType type;
1031  int ret;
1032 
1033  switch (f->formats_state) {
1036  formats = ff_make_format_list(f->formats.pixels_list);
1037  break;
1040  formats = ff_make_format_list(f->formats.samples_list);
1041  break;
1044  formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1045  break;
1048  formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1049  break;
1050  default:
1051  av_assert2(!"Unreachable");
1052  /* Intended fallthrough */
1057  formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1058  ctx->nb_outputs ? ctx->outputs[0]->type :
1060  break;
1061  }
1062 
1064  if (ret < 0)
1065  return ret;
1066  if (type != AVMEDIA_TYPE_AUDIO) {
1068  if (ret < 0)
1069  return ret;
1071  if (ret < 0)
1072  return ret;
1073  }
1074  if (type != AVMEDIA_TYPE_VIDEO) {
1076  if (ret < 0)
1077  return ret;
1079  if (ret < 0)
1080  return ret;
1081  }
1082 
1083  return 0;
1084 }
1086 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1087 {
1088  unsigned i, j;
1089 
1090  if (!fmts)
1091  return 0;
1092  if (!fmts->nb_formats) {
1093  av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1094  return AVERROR(EINVAL);
1095  }
1096  for (i = 0; i < fmts->nb_formats; i++) {
1097  for (j = i + 1; j < fmts->nb_formats; j++) {
1098  if (fmts->formats[i] == fmts->formats[j]) {
1099  av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1100  return AVERROR(EINVAL);
1101  }
1102  }
1103  }
1104  return 0;
1105 }
1107 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1108 {
1109  return check_list(log, "pixel format", fmts);
1110 }
1112 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1113 {
1114  return check_list(log, "sample format", fmts);
1115 }
1117 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1118 {
1119  if (!fmts || !fmts->nb_formats)
1120  return 0;
1121  return check_list(log, "sample rate", fmts);
1122 }
1124 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1125 {
1126  for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1127  if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1128  av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1129  return AVERROR(EINVAL);
1130  }
1131  }
1132  return check_list(log, "color space", fmts);
1133 }
1135 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1136 {
1137  return check_list(log, "color range", fmts);
1138 }
1140 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1141 {
1142  return !av_channel_layout_compare(a, b) ||
1143  (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1144  (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1145 }
1148 {
1149  unsigned i, j;
1150 
1151  if (!fmts)
1152  return 0;
1153  if (fmts->all_layouts < fmts->all_counts) {
1154  av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1155  return AVERROR(EINVAL);
1156  }
1157  if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1158  av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1159  return AVERROR(EINVAL);
1160  }
1161  for (i = 0; i < fmts->nb_channel_layouts; i++) {
1162  for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1163  if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1164  av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1165  return AVERROR(EINVAL);
1166  }
1167  }
1168  }
1169  return 0;
1170 }
can_merge_generic
static int can_merge_generic(const void *a, const void *b)
Definition: formats.c:336
merge_generic_internal
static int merge_generic_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition: formats.c:323
formats
formats
Definition: signature.h:47
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
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
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:228
can_merge_sample_fmts
static int can_merge_sample_fmts(const void *a, const void *b)
See can_merge_pix_fmts().
Definition: formats.c:168
merge_formats_internal
static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type, int check)
Definition: formats.c:93
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:435
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:911
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:142
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:983
ff_set_common_color_spaces_from_list
int ff_set_common_color_spaces_from_list(AVFilterContext *ctx, const int *color_ranges)
Equivalent to ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces))
Definition: formats.c:833
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:673
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
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:928
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:1106
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1007
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:815
merge_generic
static int merge_generic(void *a, void *b)
Definition: formats.c:342
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:621
can_merge_channel_layouts
static int can_merge_channel_layouts(const void *a, const void *b)
Definition: formats.c:312
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:839
pixdesc.h
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:660
b
#define b
Definition: input.c:41
mergers_video
static const AVFilterFormatsMerger mergers_video[]
Definition: formats.c:347
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:61
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:920
FF_FILTER_FORMATS_SINGLE_PIXFMT
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
Definition: filters.h:232
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:821
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:182
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:328
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:529
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:992
FORMATS_UNREF
#define FORMATS_UNREF(ref, list)
Definition: formats.c:693
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:1139
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:644
SET_COMMON_FORMATS
#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:758
fail
#define fail()
Definition: checkasm.h:193
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:718
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
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:560
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:535
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:561
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
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:867
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:959
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:878
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ff_formats_ref
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:678
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:873
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
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_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:944
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
AVFilterGraph::aresample_swr_opts
char * aresample_swr_opts
swr options to use for the auto-inserted aresample filters, Access ONLY through AVOptions
Definition: avfilter.h:830
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:797
ff_set_common_samplerates2
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition: formats.c:935
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
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:753
NULL
#define NULL
Definition: coverity.c:32
ff_filter_get_negotiation
const AVFilterNegotiation * ff_filter_get_negotiation(AVFilterLink *link)
Definition: formats.c:397
MAKE_FORMAT_LIST
#define MAKE_FORMAT_LIST(type, field, count_field)
Definition: formats.c:417
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:160
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
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:504
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:406
negotiate_audio
static const AVFilterNegotiation negotiate_audio
Definition: formats.c:390
AVFilterGraph
Definition: avfilter.h:781
merge_samplerates
static int merge_samplerates(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:203
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:803
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:521
ff_all_color_spaces
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition: formats.c:630
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:729
AVFilterFormatsConfig
Lists of formats / etc.
Definition: avfilter.h:111
FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
Definition: filters.h:233
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:1111
AVFilterGraph::scale_sws_opts
char * scale_sws_opts
sws options to use for the auto-inserted scale filters
Definition: avfilter.h:786
MERGE_REF
#define MERGE_REF(ret, a, fmts, type, fail_statement)
Add all refs from a to ret and destroy a.
Definition: formats.c:34
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:1123
AVMediaType
AVMediaType
Definition: avutil.h:199
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:379
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:1025
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:318
merge_channel_layouts_internal
static int merge_channel_layouts_internal(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b, int check)
See merge_pix_fmts().
Definition: formats.c:211
check_list
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
Definition: formats.c:1085
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:851
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
AVMEDIA_TYPE_UNKNOWN
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition: avutil.h:200
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:1146
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:646
ff_all_channel_layouts
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:612
ADD_FORMAT
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:480
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:808
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_ranges)
Definition: formats.c:968
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:717
ff_set_common_color_ranges
int ff_set_common_color_ranges(AVFilterContext *ctx, AVFilterFormats *color_ranges)
Definition: formats.c:844
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:67
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:227
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:553
FORMATS_REF
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:657
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:1116
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:444
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:31
common.h
FORMATS_CHANGEREF
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:734
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
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:857
ch_layouts
static const AVChannelLayout ch_layouts[]
Definition: adpcmenc.c:956
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
ff_planar_sample_fmts
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:593
mergers_audio
static const AVFilterFormatsMerger mergers_audio[]
Definition: formats.c:365
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:643
merge_channel_layouts
static int merge_channel_layouts(void *a, void *b)
Definition: formats.c:318
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:1134
AVFilter
Filter definition.
Definition: avfilter.h:201
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:826
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:782
FF_COUNT2LAYOUT
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition: formats.h:102
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:1000
FF_FILTER_FORMATS_QUERY_FUNC2
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition: filters.h:229
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:606
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:1016
channel_layout.h
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:441
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:195
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
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:448
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVFilterChannelLayouts::nb_channel_layouts
int nb_channel_layouts
number of channel layouts
Definition: formats.h:87
mem.h
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:33
ff_set_common_all_samplerates2
int ff_set_common_all_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition: formats.c:952
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:112
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
negotiate_video
static const AVFilterNegotiation negotiate_video
Definition: formats.c:383
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:444
FF_FILTER_FORMATS_SAMPLEFMTS_LIST
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
Definition: filters.h:231
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
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:976
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:808
ff_channel_layouts_changeref
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:747
merge_sample_fmts
static int merge_sample_fmts(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:177
FF_FILTER_FORMATS_PIXFMT_LIST
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Definition: filters.h:230
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:790