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 #define CONVERSION_FILTER_SWSCALE \
349  .conversion_filter = "scale", \
350  .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
351 
352 #define CONVERSION_FILTER_ARESAMPLE \
353  .conversion_filter = "aresample", \
354  .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
355 
356 static const AVFilterFormatsMerger mergers_video[] = {
357  {
358  .offset = offsetof(AVFilterFormatsConfig, formats),
359  .merge = merge_pix_fmts,
360  .can_merge = can_merge_pix_fmts,
362  },
363  {
364  .offset = offsetof(AVFilterFormatsConfig, color_spaces),
365  .merge = merge_generic,
366  .can_merge = can_merge_generic,
368  },
369  {
370  .offset = offsetof(AVFilterFormatsConfig, color_ranges),
371  .merge = merge_generic,
372  .can_merge = can_merge_generic,
374  },
375  {
376  .offset = offsetof(AVFilterFormatsConfig, alpha_modes),
377  .merge = merge_generic,
378  .can_merge = can_merge_generic,
379  .conversion_filter = "premultiply_dynamic",
380  },
381 };
382 
383 static const AVFilterFormatsMerger mergers_audio[] = {
384  {
385  .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
386  .merge = merge_channel_layouts,
387  .can_merge = can_merge_channel_layouts,
389  },
390  {
391  .offset = offsetof(AVFilterFormatsConfig, samplerates),
392  .merge = merge_samplerates,
393  .can_merge = can_merge_samplerates,
395  },
396  {
397  .offset = offsetof(AVFilterFormatsConfig, formats),
398  .merge = merge_sample_fmts,
399  .can_merge = can_merge_sample_fmts,
401  },
402 };
403 
404 static const AVFilterNegotiation negotiate_video = {
406  .mergers = mergers_video,
407 };
408 
409 static const AVFilterNegotiation negotiate_audio = {
411  .mergers = mergers_audio,
412 };
413 
415 {
416  switch (link->type) {
417  case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
418  case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
419  default: return NULL;
420  }
421 }
422 
423 int ff_fmt_is_in(int fmt, const int *fmts)
424 {
425  const int *p;
426 
427  for (p = fmts; *p != -1; p++) {
428  if (fmt == *p)
429  return 1;
430  }
431  return 0;
432 }
433 
434 #define MAKE_FORMAT_LIST(type, field, count_field) \
435  type *formats; \
436  int count = 0; \
437  if (fmts) \
438  for (count = 0; fmts[count] != -1; count++) \
439  ; \
440  formats = av_mallocz(sizeof(*formats)); \
441  if (!formats) \
442  return NULL; \
443  formats->count_field = count; \
444  if (count) { \
445  formats->field = av_malloc_array(count, sizeof(*formats->field)); \
446  if (!formats->field) { \
447  av_freep(&formats); \
448  return NULL; \
449  } \
450  }
451 
452 AVFilterFormats *ff_make_format_list(const int *fmts)
453 {
455  while (count--)
456  formats->formats[count] = fmts[count];
457 
458  return formats;
459 }
460 
462 {
464  int count = 0;
465  if (fmts)
466  for (count = 0; fmts[count].nb_channels; count++)
467  ;
468  ch_layouts = av_mallocz(sizeof(*ch_layouts));
469  if (!ch_layouts)
470  return NULL;
471  ch_layouts->nb_channel_layouts = count;
472  if (count) {
473  ch_layouts->channel_layouts =
474  av_calloc(count, sizeof(*ch_layouts->channel_layouts));
475  if (!ch_layouts->channel_layouts) {
477  return NULL;
478  }
479  for (int i = 0; i < count; i++) {
480  int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
481  if (ret < 0)
482  goto fail;
483  }
484  }
485 
486  return ch_layouts;
487 
488 fail:
489  for (int i = 0; i < count; i++)
490  av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
491  av_free(ch_layouts->channel_layouts);
493 
494  return NULL;
495 }
496 
497 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
498 do { \
499  type *fmts; \
500  \
501  if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
502  return AVERROR(ENOMEM); \
503  } \
504  \
505  fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
506  sizeof(*(*f)->list)); \
507  if (!fmts) { \
508  unref_fn(f); \
509  return AVERROR(ENOMEM); \
510  } \
511  \
512  (*f)->list = fmts; \
513  ASSIGN_FMT(f, fmt, list, nb); \
514 } while (0)
515 
516 #define ASSIGN_FMT(f, fmt, list, nb) \
517 do { \
518  (*f)->list[(*f)->nb++] = fmt; \
519 } while (0)
520 
521 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
522 {
523  ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
524  return 0;
525 }
526 
527 #undef ASSIGN_FMT
528 #define ASSIGN_FMT(f, fmt, list, nb) \
529 do { \
530  int ret; \
531  memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
532  ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
533  if (ret < 0) \
534  return ret; \
535  (*f)->nb++; \
536 } while (0)
537 
539  const AVChannelLayout *channel_layout)
540 {
541  av_assert1(!(*l && (*l)->all_layouts));
542  ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
543  return 0;
544 }
545 
547 {
548  int fmts[2] = { fmt, -1 };
549  return ff_make_format_list(fmts);
550 }
551 
553 {
555 
556  if (type == AVMEDIA_TYPE_VIDEO) {
557  return ff_formats_pixdesc_filter(0, 0);
558  } else if (type == AVMEDIA_TYPE_AUDIO) {
559  enum AVSampleFormat fmt = 0;
560  while (av_get_sample_fmt_name(fmt)) {
561  if (ff_add_format(&ret, fmt) < 0)
562  return NULL;
563  fmt++;
564  }
565  }
566 
567  return ret;
568 }
569 
570 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
571 {
572  unsigned nb_formats, fmt, flags;
574 
575  while (1) {
576  nb_formats = 0;
577  for (fmt = 0;; fmt++) {
579  if (!desc)
580  break;
581  flags = desc->flags;
582  if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
583  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
584  (desc->log2_chroma_w || desc->log2_chroma_h))
586  if ((flags & (want | rej)) != want)
587  continue;
588  if (formats)
589  formats->formats[nb_formats] = fmt;
590  nb_formats++;
591  }
592  if (formats) {
593  av_assert0(formats->nb_formats == nb_formats);
594  return formats;
595  }
596  formats = av_mallocz(sizeof(*formats));
597  if (!formats)
598  return NULL;
599  formats->nb_formats = nb_formats;
600  if (nb_formats) {
601  formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
602  if (!formats->formats) {
603  av_freep(&formats);
604  return NULL;
605  }
606  }
607  }
608 }
609 
611 {
613  int fmt;
614 
615  for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
616  if (av_sample_fmt_is_planar(fmt))
617  if (ff_add_format(&ret, fmt) < 0)
618  return NULL;
619 
620  return ret;
621 }
622 
624 {
625  AVFilterFormats *ret = av_mallocz(sizeof(*ret));
626  return ret;
627 }
628 
630 {
632  if (!ret)
633  return NULL;
634  ret->all_layouts = 1;
635  return ret;
636 }
637 
639 {
641  if (!ret)
642  return NULL;
643  ret->all_layouts = ret->all_counts = 1;
644  return ret;
645 }
646 
648 {
651  return NULL;
652  for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
653  if (csp == AVCOL_SPC_RESERVED ||
654  csp == AVCOL_SPC_UNSPECIFIED)
655  continue;
656  if (ff_add_format(&ret, csp) < 0)
657  return NULL;
658  }
659 
660  return ret;
661 }
662 
664 {
666  for (int range = 0; range < AVCOL_RANGE_NB; range++) {
667  if (ff_add_format(&ret, range) < 0)
668  return NULL;
669  }
670 
671  return ret;
672 }
673 
675 {
677  for (int range = 0; range < AVALPHA_MODE_NB; range++) {
678  if (ff_add_format(&ret, range) < 0)
679  return NULL;
680  }
681 
682  return ret;
683 }
684 
685 #define FORMATS_REF(f, ref, unref_fn) \
686  void *tmp; \
687  \
688  if (!f) \
689  return AVERROR(ENOMEM); \
690  \
691  tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
692  if (!tmp) { \
693  unref_fn(&f); \
694  return AVERROR(ENOMEM); \
695  } \
696  f->refs = tmp; \
697  f->refs[f->refcount++] = ref; \
698  *ref = f; \
699  return 0
700 
702 {
704 }
705 
707 {
709 }
710 
711 #define FIND_REF_INDEX(ref, idx) \
712 do { \
713  int i; \
714  for (i = 0; i < (*ref)->refcount; i ++) \
715  if((*ref)->refs[i] == ref) { \
716  idx = i; \
717  break; \
718  } \
719 } while (0)
720 
721 #define FORMATS_UNREF(ref, list) \
722 do { \
723  int idx = -1; \
724  \
725  if (!*ref) \
726  return; \
727  \
728  FIND_REF_INDEX(ref, idx); \
729  \
730  if (idx >= 0) { \
731  memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
732  sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
733  --(*ref)->refcount; \
734  } \
735  if (!(*ref)->refcount) { \
736  FREE_LIST(ref, list); \
737  av_free((*ref)->list); \
738  av_free((*ref)->refs); \
739  av_free(*ref); \
740  } \
741  *ref = NULL; \
742 } while (0)
743 
744 #define FREE_LIST(ref, list) do { } while(0)
746 {
748 }
749 
750 #undef FREE_LIST
751 #define FREE_LIST(ref, list) \
752  do { \
753  for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
754  av_channel_layout_uninit(&(*ref)->list[i]); \
755  } while(0)
756 
758 {
760 }
761 
762 #define FORMATS_CHANGEREF(oldref, newref) \
763 do { \
764  int idx = -1; \
765  \
766  FIND_REF_INDEX(oldref, idx); \
767  \
768  if (idx >= 0) { \
769  (*oldref)->refs[idx] = newref; \
770  *newref = *oldref; \
771  *oldref = NULL; \
772  } \
773 } while (0)
774 
776  AVFilterChannelLayouts **newref)
777 {
778  FORMATS_CHANGEREF(oldref, newref);
779 }
780 
782 {
783  FORMATS_CHANGEREF(oldref, newref);
784 }
785 
786 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
787  int i; \
788  \
789  if (!fmts) \
790  return AVERROR(ENOMEM); \
791  \
792  for (i = 0; i < ctx->nb_inputs; i++) { \
793  AVFilterLink *const link = ctx->inputs[i]; \
794  if (link && !link->outcfg.fmts && \
795  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
796  int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
797  if (ret < 0) { \
798  return ret; \
799  } \
800  } \
801  } \
802  for (i = 0; i < ctx->nb_outputs; i++) { \
803  AVFilterLink *const link = ctx->outputs[i]; \
804  if (link && !link->incfg.fmts && \
805  (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
806  int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
807  if (ret < 0) { \
808  return ret; \
809  } \
810  } \
811  } \
812  \
813  if (!fmts->refcount) \
814  unref_fn(&fmts); \
815  \
816  return 0;
817 
820 {
823 }
824 
826  const AVChannelLayout *fmts)
827 {
829 }
830 
832 {
834 }
835 
838 {
841 }
842 
844  const int *samplerates)
845 {
847 }
848 
850 {
852 }
853 
856 {
859 }
860 
862  const int *color_spaces)
863 {
865 }
866 
868 {
870 }
871 
874 {
877 }
878 
880  const int *color_ranges)
881 {
883 }
884 
886 {
888 }
889 
892 {
895 }
896 
898  const int *alpha_modes)
899 {
901 }
902 
904 {
906 }
907 
908 /**
909  * A helper for query_formats() which sets all links to the same list of
910  * formats. If there are no links hooked to this filter, the list of formats is
911  * freed.
912  */
914 {
917 }
918 
920 {
922 }
923 
924 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
925  ref_fn, unref_fn) \
926  if (!fmts) \
927  return AVERROR(ENOMEM); \
928  \
929  for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
930  const AVFilterLink *const link = ctx->inputs[i]; \
931  if (!cfg_in[i]->fmts && \
932  (media_type == AVMEDIA_TYPE_UNKNOWN || \
933  link->type == media_type)) { \
934  int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
935  if (ret < 0) { \
936  return ret; \
937  } \
938  } \
939  } \
940  for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
941  const AVFilterLink *const link = ctx->outputs[i]; \
942  if (!cfg_out[i]->fmts && \
943  (media_type == AVMEDIA_TYPE_UNKNOWN || \
944  link->type == media_type)) { \
945  int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
946  if (ret < 0) { \
947  return ret; \
948  } \
949  } \
950  } \
951  \
952  if (!fmts->refcount) \
953  unref_fn(&fmts); \
954  \
955  return 0;
956 
958  AVFilterFormatsConfig **cfg_in,
959  AVFilterFormatsConfig **cfg_out,
961 {
964 }
965 
967  AVFilterFormatsConfig **cfg_in,
968  AVFilterFormatsConfig **cfg_out,
969  const AVChannelLayout *fmts)
970 {
971  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
972 }
973 
975  AVFilterFormatsConfig **cfg_in,
976  AVFilterFormatsConfig **cfg_out)
977 {
978  return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
979 }
980 
982  AVFilterFormatsConfig **cfg_in,
983  AVFilterFormatsConfig **cfg_out,
985 {
988 }
989 
991  AVFilterFormatsConfig **cfg_in,
992  AVFilterFormatsConfig **cfg_out,
993  const int *samplerates)
994 {
996 }
997 
999  AVFilterFormatsConfig **cfg_in,
1000  AVFilterFormatsConfig **cfg_out)
1001 {
1002  return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1003 }
1006  AVFilterFormatsConfig **cfg_in,
1007  AVFilterFormatsConfig **cfg_out,
1009 {
1012 }
1015  AVFilterFormatsConfig **cfg_in,
1016  AVFilterFormatsConfig **cfg_out,
1017  const int *color_spaces)
1018 {
1020 }
1023  AVFilterFormatsConfig **cfg_in,
1024  AVFilterFormatsConfig **cfg_out)
1025 {
1026  return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
1027 }
1030  AVFilterFormatsConfig **cfg_in,
1031  AVFilterFormatsConfig **cfg_out,
1033 {
1036 }
1039  AVFilterFormatsConfig **cfg_in,
1040  AVFilterFormatsConfig **cfg_out,
1041  const int *color_ranges)
1042 {
1044 }
1047  AVFilterFormatsConfig **cfg_in,
1048  AVFilterFormatsConfig **cfg_out)
1049 {
1050  return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1051 }
1054  AVFilterFormatsConfig **cfg_in,
1055  AVFilterFormatsConfig **cfg_out,
1057 {
1060 }
1063  AVFilterFormatsConfig **cfg_in,
1064  AVFilterFormatsConfig **cfg_out,
1065  const int *alpha_modes)
1066 {
1068 }
1071  AVFilterFormatsConfig **cfg_in,
1072  AVFilterFormatsConfig **cfg_out)
1073 {
1074  return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_all_alpha_modes());
1075 }
1078  AVFilterFormatsConfig **cfg_in,
1079  AVFilterFormatsConfig **cfg_out,
1081 {
1084 }
1087  AVFilterFormatsConfig **cfg_in,
1088  AVFilterFormatsConfig **cfg_out,
1089  const int *fmts)
1090 {
1091  return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1092 }
1093 
1096 {
1097  const FFFilter *const f = fffilter(ctx->filter);
1099  enum AVMediaType type;
1100  int ret;
1101 
1102  switch (f->formats_state) {
1105  formats = ff_make_format_list(f->formats.pixels_list);
1106  break;
1109  formats = ff_make_format_list(f->formats.samples_list);
1110  break;
1113  formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1114  break;
1117  formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1118  break;
1119  default:
1120  av_assert2(!"Unreachable");
1121  /* Intended fallthrough */
1126  formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1127  ctx->nb_outputs ? ctx->outputs[0]->type :
1129  break;
1130  }
1131 
1133  if (ret < 0)
1134  return ret;
1135  if (type != AVMEDIA_TYPE_AUDIO) {
1137  if (ret < 0)
1138  return ret;
1140  if (ret < 0)
1141  return ret;
1143  if (ret < 0)
1144  return ret;
1145  }
1146  if (type != AVMEDIA_TYPE_VIDEO) {
1148  if (ret < 0)
1149  return ret;
1151  if (ret < 0)
1152  return ret;
1153  }
1154 
1155  return 0;
1156 }
1158 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1159 {
1160  unsigned i, j;
1161 
1162  if (!fmts)
1163  return 0;
1164  if (!fmts->nb_formats) {
1165  av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1166  return AVERROR(EINVAL);
1167  }
1168  for (i = 0; i < fmts->nb_formats; i++) {
1169  for (j = i + 1; j < fmts->nb_formats; j++) {
1170  if (fmts->formats[i] == fmts->formats[j]) {
1171  av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1172  return AVERROR(EINVAL);
1173  }
1174  }
1175  }
1176  return 0;
1177 }
1179 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1180 {
1181  return check_list(log, "pixel format", fmts);
1182 }
1184 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1185 {
1186  return check_list(log, "sample format", fmts);
1187 }
1189 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1190 {
1191  if (!fmts || !fmts->nb_formats)
1192  return 0;
1193  return check_list(log, "sample rate", fmts);
1194 }
1196 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1197 {
1198  for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1199  if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1200  av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1201  return AVERROR(EINVAL);
1202  }
1203  }
1204  return check_list(log, "color space", fmts);
1205 }
1207 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1208 {
1209  return check_list(log, "color range", fmts);
1210 }
1212 int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1213 {
1214  return check_list(log, "alpha mode", fmts);
1215 }
1217 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1218 {
1219  return !av_channel_layout_compare(a, b) ||
1220  (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1221  (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1222 }
1225 {
1226  unsigned i, j;
1227 
1228  if (!fmts)
1229  return 0;
1230  if (fmts->all_layouts < fmts->all_counts) {
1231  av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1232  return AVERROR(EINVAL);
1233  }
1234  if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1235  av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1236  return AVERROR(EINVAL);
1237  }
1238  for (i = 0; i < fmts->nb_channel_layouts; i++) {
1239  for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1240  if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1241  av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1242  return AVERROR(EINVAL);
1243  }
1244  }
1245  }
1246  return 0;
1247 }
can_merge_generic
static int can_merge_generic(const void *a, const void *b)
Definition: formats.c:336
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:323
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:1069
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
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:347
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: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:451
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:956
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:1028
ff_set_common_alpha_modes
int ff_set_common_alpha_modes(AVFilterContext *ctx, AVFilterFormats *alpha_modes)
Definition: formats.c:889
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:700
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3447
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:973
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:1178
ff_set_common_formats2
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition: formats.c:1076
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:842
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:637
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:866
pixdesc.h
AVCOL_SPC_NB
@ AVCOL_SPC_NB
Not part of ABI.
Definition: pixfmt.h:710
b
#define b
Definition: input.c:42
mergers_video
static const AVFilterFormatsMerger mergers_video[]
Definition: formats.c:355
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:965
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:848
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: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:545
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:1037
FORMATS_UNREF
#define FORMATS_UNREF(ref, list)
Definition: formats.c:720
CONVERSION_FILTER_ARESAMPLE
#define CONVERSION_FILTER_ARESAMPLE
Definition: formats.c:351
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:1216
AVCOL_SPC_RESERVED
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition: pixfmt.h:694
SET_COMMON_FORMATS
#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn)
Definition: formats.c:785
fail
#define fail()
Definition: checkasm.h:200
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:768
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:860
AVFilterNegotiation
Callbacks and properties to describe the steps of a format negotiation.
Definition: formats.h:609
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:551
AVFilterNegotiation::nb_mergers
unsigned nb_mergers
Definition: formats.h:610
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:912
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:1004
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:923
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:705
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:918
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_common_alpha_modes2
int ff_set_common_alpha_modes2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *alpha_modes)
Definition: formats.c:1052
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:989
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:824
ff_set_common_samplerates2
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition: formats.c:980
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:780
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:1013
NULL
#define NULL
Definition: coverity.c:32
ff_filter_get_negotiation
const AVFilterNegotiation * ff_filter_get_negotiation(AVFilterLink *link)
Definition: formats.c:413
MAKE_FORMAT_LIST
#define MAKE_FORMAT_LIST(type, field, count_field)
Definition: formats.c:433
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_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:1211
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:520
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:422
negotiate_audio
static const AVFilterNegotiation negotiate_audio
Definition: formats.c:408
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:830
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition: formats.c:537
ff_all_color_spaces
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition: formats.c:646
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:756
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:1183
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:1195
AVMediaType
AVMediaType
Definition: avutil.h:198
FF_PIX_FMT_FLAG_SW_FLAT_SUB
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition: formats.h:419
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:1094
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:211
check_list
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
Definition: formats.c:1157
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:878
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:804
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:1223
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:662
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:628
ADD_FORMAT
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition: formats.c:496
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:744
ff_set_common_color_ranges
int ff_set_common_color_ranges(AVFilterContext *ctx, AVFilterFormats *color_ranges)
Definition: formats.c:871
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:1061
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:569
FORMATS_REF
#define FORMATS_REF(f, ref, unref_fn)
Definition: formats.c:684
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:1188
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
common.h
FORMATS_CHANGEREF
#define FORMATS_CHANGEREF(oldref, newref)
Definition: formats.c:761
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:902
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:884
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:609
mergers_audio
static const AVFilterFormatsMerger mergers_audio[]
Definition: formats.c:382
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:693
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:1206
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:853
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
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:1045
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:622
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:1085
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:896
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:195
ff_all_alpha_modes
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition: formats.c:673
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:79
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
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:997
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:403
ff_make_channel_layout_list
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition: formats.c:460
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:1021
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:835
ff_channel_layouts_changeref
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition: formats.c:774
merge_sample_fmts
static int merge_sample_fmts(void *a, void *b)
See merge_pix_fmts().
Definition: formats.c:177
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:817