FFmpeg
Loading...
Searching...
No Matches
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
23#include "libavutil/avassert.h"
24#include "libavutil/bprint.h"
26#include "libavutil/common.h"
27#include "libavutil/mem.h"
28#include "libavutil/pixdesc.h"
29#include "avfilter.h"
30#include "filters.h"
31#include "formats.h"
32
33/**
34 * Add all refs from a to ret and destroy a.
35 */
36#define MERGE_REF(ret, a, fmts, type, fail_statement) \
37do { \
38 type ***tmp; \
39 int i; \
40 \
41 if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
42 sizeof(*tmp)))) \
43 { fail_statement } \
44 ret->refs = tmp; \
45 \
46 for (i = 0; i < a->refcount; i ++) { \
47 ret->refs[ret->refcount] = a->refs[i]; \
48 *ret->refs[ret->refcount++] = ret; \
49 } \
50 \
51 av_freep(&a->refs); \
52 av_freep(&a->fmts); \
53 av_freep(&a); \
54} while (0)
55
56/**
57 * Add all formats common to a and b to a, add b's refs to a and destroy b.
58 * If check is set, nothing is modified and it is only checked whether
59 * the formats are compatible.
60 * If empty_allowed is set and one of a,b->nb is zero, the lists are
61 * merged; otherwise, 0 (for nonmergeability) is returned.
62 */
63#define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
64do { \
65 int i, j, k = 0, skip = 0; \
66 \
67 if (empty_allowed) { \
68 if (!a->nb || !b->nb) { \
69 if (check) \
70 return 1; \
71 if (!a->nb) \
72 FFSWAP(type *, a, b); \
73 skip = 1; \
74 } \
75 } \
76 if (!skip) { \
77 for (i = 0; i < a->nb; i++) \
78 for (j = 0; j < b->nb; j++) \
79 if (a->fmts[i] == b->fmts[j]) { \
80 if (check) \
81 return 1; \
82 a->fmts[k++] = a->fmts[i]; \
83 break; \
84 } \
85 /* Check that there was at least one common format. \
86 * Notice that both a and b are unchanged if not. */ \
87 if (!k) \
88 return 0; \
89 av_assert2(!check); \
90 a->nb = k; \
91 } \
92 \
93 MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
94} while (0)
97 enum AVMediaType type, int check)
98{
99 int i, j;
100 int alpha1=0, alpha2=0;
101 int chroma1=0, chroma2=0;
102
103 av_assert2(check || (a->refcount && b->refcount));
104
105 if (a == b)
106 return 1;
107
108 /* Do not lose chroma or alpha in merging.
109 It happens if both lists have formats with chroma (resp. alpha), but
110 the only formats in common do not have it (e.g. YUV+gray vs.
111 RGB+gray): in that case, the merging would select the gray format,
112 possibly causing a lossy conversion elsewhere in the graph.
113 To avoid that, pretend that there are no common formats to force the
114 insertion of a conversion filter. */
116 for (i = 0; i < a->nb_formats; i++) {
117 const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
118 for (j = 0; j < b->nb_formats; j++) {
119 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
120 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
121 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
122 if (a->formats[i] == b->formats[j]) {
123 alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
124 chroma1|= adesc->nb_components > 1;
125 }
126 }
127 }
128
129 // If chroma or alpha can be lost through merging then do not merge
130 if (alpha2 > alpha1 || chroma2 > chroma1)
131 return 0;
132
133 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
134
135 return 1;
136}
137
138
139/**
140 * Check the formats lists for compatibility for merging without actually
141 * merging.
142 *
143 * @return 1 if they are compatible, 0 if not.
144 */
145static int can_merge_pix_fmts(const void *a, const void *b)
146{
149}
150
151/**
152 * Merge the formats lists if they are compatible and update all the
153 * references of a and b to point to the combined list and free the old
154 * lists as needed. The combined list usually contains the intersection of
155 * the lists of a and b.
156 *
157 * Both a and b must have owners (i.e. refcount > 0) for these functions.
158 *
159 * @return 1 if merging succeeded, 0 if a and b are incompatible
160 * and negative AVERROR code on failure.
161 * a and b are unmodified if 0 is returned.
162 */
163static int merge_pix_fmts(void *a, void *b)
164{
166}
167
168/**
169 * See can_merge_pix_fmts().
170 */
171static int can_merge_sample_fmts(const void *a, const void *b)
172{
175}
176
177/**
178 * See merge_pix_fmts().
179 */
180static int merge_sample_fmts(void *a, void *b)
181{
183}
186 AVFilterFormats *b, int check)
187{
188 av_assert2(check || (a->refcount && b->refcount));
189 if (a == b) return 1;
190
191 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
192 return 1;
193}
194
195/**
196 * See can_merge_pix_fmts().
197 */
198static int can_merge_samplerates(const void *a, const void *b)
199{
201}
202
203/**
204 * See merge_pix_fmts().
205 */
206static int merge_samplerates(void *a, void *b)
207{
208 return merge_samplerates_internal(a, b, 0);
209}
210
211/**
212 * See merge_pix_fmts().
213 */
216{
218 unsigned a_all = a->all_layouts + a->all_counts;
219 unsigned b_all = b->all_layouts + b->all_counts;
220 int ret_max, ret_nb = 0, i, j, round;
221
222 av_assert2(a->refcount && b->refcount);
223
224 if (a == b) return 1;
225
226 /* Put the most generic set in a, to avoid doing everything twice */
227 if (a_all < b_all) {
229 FFSWAP(unsigned, a_all, b_all);
230 }
231 if (a_all) {
232 if (a_all == 1 && !b_all) {
233 /* keep only known layouts in b; works also for b_all = 1 */
234 for (i = j = 0; i < b->nb_channel_layouts; i++)
235 if (KNOWN(&b->channel_layouts[i]) && i != j++) {
236 if (check)
237 return 1;
238 av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
239 }
240 /* Not optimal: the unknown layouts of b may become known after
241 another merge. */
242 if (!j)
243 return 0;
244 b->nb_channel_layouts = j;
245 }
247 return 1;
248 }
249
250 ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
251 if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
252 return AVERROR(ENOMEM);
253
254 /* a[known] intersect b[known] */
255 for (i = 0; i < a->nb_channel_layouts; i++) {
256 if (!KNOWN(&a->channel_layouts[i]))
257 continue;
258 for (j = 0; j < b->nb_channel_layouts; j++) {
259 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
260 if (check)
261 return 1;
262 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
263 av_channel_layout_uninit(&a->channel_layouts[i]);
264 av_channel_layout_uninit(&b->channel_layouts[j]);
265 break;
266 }
267 }
268 }
269 /* 1st round: a[known] intersect b[generic]
270 2nd round: a[generic] intersect b[known] */
271 for (round = 0; round < 2; round++) {
272 for (i = 0; i < a->nb_channel_layouts; i++) {
273 AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
274 if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
275 continue;
276 bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
277 for (j = 0; j < b->nb_channel_layouts; j++)
278 if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
279 if (check)
280 return 1;
282 }
283 }
284 /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
286 }
287 /* a[generic] intersect b[generic] */
288 for (i = 0; i < a->nb_channel_layouts; i++) {
289 if (KNOWN(&a->channel_layouts[i]))
290 continue;
291 for (j = 0; j < b->nb_channel_layouts; j++)
292 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
293 if (check)
294 return 1;
295 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
296 }
297 }
298
299 if (!ret_nb) {
301 return 0;
302 }
303
304 if (a->refcount > b->refcount)
306
308 { av_free(channel_layouts); return AVERROR(ENOMEM); });
309 av_freep(&b->channel_layouts);
310 b->channel_layouts = channel_layouts;
311 b->nb_channel_layouts = ret_nb;
312 return 1;
313}
315static int can_merge_channel_layouts(const void *a, const void *b)
316{
319}
321static int merge_channel_layouts(void *a, void *b)
322{
324}
327 AVFilterFormats *b, int check)
328{
329 av_assert2(check || (a->refcount && b->refcount));
330
331 if (a == b)
332 return 1;
333
334 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
335
336 return 1;
337}
339static int can_merge_generic(const void *a, const void *b)
340{
342 (AVFilterFormats *)b, 1);
343}
345static int merge_generic(void *a, void *b)
346{
347 return merge_generic_internal(a, b, 0);
348}
350#define PRINT_NAME(type, type_name) \
351static void print_##type_name(AVBPrint *bp, const void *fmtsp) \
352{ \
353 const AVFilterFormats *fmts = fmtsp; \
354 for (int i = 0; i < fmts->nb_formats; i++) { \
355 const char *name = av_##type_name(fmts->formats[i]); \
356 av_bprint_chars(bp, ' ', i ? 1 : 0); \
357 av_bprint_append_data(bp, name, name ? strlen(name) : 0); \
358 } \
359}
360
361PRINT_NAME(enum AVSampleFormat, get_sample_fmt_name)
362PRINT_NAME(enum AVPixelFormat, get_pix_fmt_name)
363PRINT_NAME(enum AVColorSpace, color_space_name)
364PRINT_NAME(enum AVColorRange, color_range_name)
365PRINT_NAME(enum AVAlphaMode, alpha_mode_name)
366PRINT_NAME(enum AVChromaLocation, chroma_location_name)
368static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
369{
370 const AVFilterChannelLayouts *layouts = layoutsp;
371 for (int i = 0; i < layouts->nb_channel_layouts; i++) {
372 av_bprint_chars(bp, ' ', i ? 1 : 0);
373 av_channel_layout_describe_bprint(&layouts->channel_layouts[i], bp);
374 }
375}
377static void print_sample_rate(AVBPrint *bp, const void *ratesp)
378{
379 const AVFilterFormats *rates = ratesp;
380 for (int i = 0; i < rates->nb_formats; i++)
381 av_bprintf(bp, "%s%d", i ? " " : "", rates->formats[i]);
382}
384#define CONVERSION_FILTER_SWSCALE \
385 .conversion_filter = "scale", \
386 .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
388#define CONVERSION_FILTER_ARESAMPLE \
389 .conversion_filter = "aresample", \
390 .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
392static const AVFilterFormatsMerger mergers_video[] = {
393 {
394 .name = "Pixel formats",
395 .offset = offsetof(AVFilterFormatsConfig, formats),
396 .merge = merge_pix_fmts,
397 .can_merge = can_merge_pix_fmts,
398 .print_list = print_get_pix_fmt_name,
400 },
401 {
402 .name = "Color spaces",
403 .offset = offsetof(AVFilterFormatsConfig, color_spaces),
404 .merge = merge_generic,
405 .can_merge = can_merge_generic,
406 .print_list = print_color_space_name,
408 },
409 {
410 .name = "Color ranges",
411 .offset = offsetof(AVFilterFormatsConfig, color_ranges),
412 .merge = merge_generic,
413 .can_merge = can_merge_generic,
414 .print_list = print_color_range_name,
416 },
417 {
418 .name = "Alpha modes",
419 .offset = offsetof(AVFilterFormatsConfig, alpha_modes),
420 .merge = merge_generic,
421 .can_merge = can_merge_generic,
422 .print_list = print_alpha_mode_name,
423 .conversion_filter = "premultiply_dynamic",
424 },
425 {
426 .name = "Chroma locations",
427 .offset = offsetof(AVFilterFormatsConfig, chroma_locations),
428 .merge = merge_generic,
429 .can_merge = can_merge_generic,
430 .print_list = print_chroma_location_name,
432 },
433};
435static const AVFilterFormatsMerger mergers_audio[] = {
436 {
437 .name = "Channel layouts",
438 .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
439 .merge = merge_channel_layouts,
440 .can_merge = can_merge_channel_layouts,
441 .print_list = print_channel_layout_desc,
443 },
444 {
445 .name = "Sample rates",
446 .offset = offsetof(AVFilterFormatsConfig, samplerates),
447 .merge = merge_samplerates,
448 .can_merge = can_merge_samplerates,
449 .print_list = print_sample_rate,
451 },
452 {
453 .name = "Sample formats",
454 .offset = offsetof(AVFilterFormatsConfig, formats),
455 .merge = merge_sample_fmts,
456 .can_merge = can_merge_sample_fmts,
457 .print_list = print_get_sample_fmt_name,
459 },
460};
463 .nb_mergers = FF_ARRAY_ELEMS(mergers_video),
464 .mergers = mergers_video,
465};
468 .nb_mergers = FF_ARRAY_ELEMS(mergers_audio),
469 .mergers = mergers_audio,
470};
473{
474 switch (link->type) {
477 default: return NULL;
478 }
479}
481int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
482{
483 for (; *fmts != AV_PIX_FMT_NONE; ++fmts) {
484 if (fmt == *fmts)
485 return 1;
486 }
487 return 0;
488}
490#define MAKE_FORMAT_LIST(type, field, count_field) \
491 type *formats; \
492 int count = 0; \
493 if (fmts) \
494 for (count = 0; fmts[count] != -1; count++) \
495 ; \
496 formats = av_mallocz(sizeof(*formats)); \
497 if (!formats) \
498 return NULL; \
499 formats->count_field = count; \
500 if (count) { \
501 formats->field = av_malloc_array(count, sizeof(*formats->field)); \
502 if (!formats->field) { \
503 av_freep(&formats); \
504 return NULL; \
505 } \
506 }
508#define MAKE_FORMAT_LIST_TYPE(name, type) \
509 AVFilterFormats *ff_make_ ## name ## _list(const type* fmts) \
510 { \
511 MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats); \
512 while (count--) \
513 formats->formats[count] = (int)fmts[count]; \
514 return formats; \
515 }
516
519MAKE_FORMAT_LIST_TYPE(pixel_format, enum AVPixelFormat)
522{
523 AVFilterChannelLayouts *ch_layouts;
524 int count = 0;
525 if (fmts)
526 for (count = 0; fmts[count].nb_channels; count++)
527 ;
528 ch_layouts = av_mallocz(sizeof(*ch_layouts));
529 if (!ch_layouts)
530 return NULL;
531 ch_layouts->nb_channel_layouts = count;
532 if (count) {
533 ch_layouts->channel_layouts =
534 av_calloc(count, sizeof(*ch_layouts->channel_layouts));
535 if (!ch_layouts->channel_layouts) {
536 av_freep(&ch_layouts);
537 return NULL;
538 }
539 for (int i = 0; i < count; i++) {
540 int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
541 if (ret < 0)
542 goto fail;
543 }
544 }
545
546 return ch_layouts;
547
548fail:
549 for (int i = 0; i < count; i++)
551 av_free(ch_layouts->channel_layouts);
552 av_freep(&ch_layouts);
553
554 return NULL;
555}
557#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
558do { \
559 type *fmts; \
560 \
561 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
562 return AVERROR(ENOMEM); \
563 } \
564 \
565 fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
566 sizeof(*(*f)->list)); \
567 if (!fmts) { \
568 unref_fn(f); \
569 return AVERROR(ENOMEM); \
570 } \
571 \
572 (*f)->list = fmts; \
573 ASSIGN_FMT(f, fmt, list, nb); \
574} while (0)
576#define ASSIGN_FMT(f, fmt, list, nb) \
577do { \
578 (*f)->list[(*f)->nb++] = fmt; \
579} while (0)
582{
583 ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
584 return 0;
585}
586
587#undef ASSIGN_FMT
588#define ASSIGN_FMT(f, fmt, list, nb) \
589do { \
590 int ret; \
591 memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
592 ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
593 if (ret < 0) \
594 return ret; \
595 (*f)->nb++; \
596} while (0)
599 const AVChannelLayout *channel_layout)
600{
601 av_assert1(!(*l && (*l)->all_layouts));
602 ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
603 return 0;
604}
607{
608 int fmts[2] = { fmt, -1 };
609 return ff_make_format_list(fmts);
610}
613{
614 AVFilterFormats *ret = NULL;
615
616 if (type == AVMEDIA_TYPE_VIDEO) {
617 return ff_formats_pixdesc_filter(0, 0);
618 } else if (type == AVMEDIA_TYPE_AUDIO) {
619 enum AVSampleFormat fmt = 0;
620 while (av_get_sample_fmt_name(fmt)) {
621 if (ff_add_format(&ret, fmt) < 0)
622 return NULL;
623 fmt++;
624 }
625 }
626
627 return ret;
628}
630AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
631{
632 unsigned nb_formats, fmt, flags;
634
635 while (1) {
636 nb_formats = 0;
637 for (fmt = 0;; fmt++) {
639 if (!desc)
640 break;
641 flags = desc->flags;
642 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
643 !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
644 (desc->log2_chroma_w || desc->log2_chroma_h))
646 if ((flags & (want | rej)) != want)
647 continue;
648 if (formats)
649 formats->formats[nb_formats] = fmt;
650 nb_formats++;
651 }
652 if (formats) {
653 av_assert0(formats->nb_formats == nb_formats);
654 return formats;
655 }
656 formats = av_mallocz(sizeof(*formats));
657 if (!formats)
658 return NULL;
659 formats->nb_formats = nb_formats;
660 if (nb_formats) {
661 formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
662 if (!formats->formats) {
664 return NULL;
665 }
666 }
667 }
668}
671{
672 AVFilterFormats *ret = NULL;
673 int fmt;
674
675 for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
677 if (ff_add_format(&ret, fmt) < 0)
678 return NULL;
679
680 return ret;
681}
684{
685 AVFilterFormats *ret = av_mallocz(sizeof(*ret));
686 return ret;
687}
690{
691 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
692 if (!ret)
693 return NULL;
694 ret->all_layouts = 1;
695 return ret;
696}
699{
700 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
701 if (!ret)
702 return NULL;
703 ret->all_layouts = ret->all_counts = 1;
704 return ret;
705}
708{
709 AVFilterFormats *ret = NULL;
711 return NULL;
712 for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
713 if (csp == AVCOL_SPC_RESERVED ||
715 continue;
716 if (ff_add_format(&ret, csp) < 0)
717 return NULL;
718 }
719
720 return ret;
721}
724{
725 AVFilterFormats *ret = NULL;
726 for (int range = 0; range < AVCOL_RANGE_NB; range++) {
727 if (ff_add_format(&ret, range) < 0)
728 return NULL;
729 }
730
731 return ret;
732}
735{
736 AVFilterFormats *ret = NULL;
737 for (int am = 0; am < AVALPHA_MODE_NB; am++) {
738 if (ff_add_format(&ret, am) < 0)
739 return NULL;
740 }
741
742 return ret;
743}
746{
747 AVFilterFormats *ret = NULL;
748 for (int loc = 0; loc < AVCHROMA_LOC_NB; loc++) {
749 if (ff_add_format(&ret, loc) < 0)
750 return NULL;
751 }
752
753 return ret;
754}
756#define FORMATS_REF(f, ref, unref_fn) \
757 void *tmp; \
758 \
759 if (!f) \
760 return AVERROR(ENOMEM); \
761 \
762 tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs)); \
763 if (!tmp) { \
764 unref_fn(&f); \
765 return AVERROR(ENOMEM); \
766 } \
767 f->refs = tmp; \
768 f->refs[f->refcount++] = ref; \
769 *ref = f; \
770 return 0
775}
780}
782#define FIND_REF_INDEX(ref, idx) \
783do { \
784 int i; \
785 for (i = 0; i < (*ref)->refcount; i ++) \
786 if((*ref)->refs[i] == ref) { \
787 idx = i; \
788 break; \
789 } \
790} while (0)
792#define FORMATS_UNREF(ref, list) \
793do { \
794 int idx = -1; \
795 \
796 if (!*ref) \
797 return; \
798 \
799 FIND_REF_INDEX(ref, idx); \
800 \
801 if (idx >= 0) { \
802 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
803 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
804 --(*ref)->refcount; \
805 } \
806 if (!(*ref)->refcount) { \
807 FREE_LIST(ref, list); \
808 av_free((*ref)->list); \
809 av_free((*ref)->refs); \
810 av_free(*ref); \
811 } \
812 *ref = NULL; \
813} while (0)
815#define FREE_LIST(ref, list) do { } while(0)
817{
819}
820
821#undef FREE_LIST
822#define FREE_LIST(ref, list) \
823 do { \
824 for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
825 av_channel_layout_uninit(&(*ref)->list[i]); \
826 } while(0)
831}
833#define FORMATS_CHANGEREF(oldref, newref) \
834do { \
835 int idx = -1; \
836 \
837 FIND_REF_INDEX(oldref, idx); \
838 \
839 if (idx >= 0) { \
840 (*oldref)->refs[idx] = newref; \
841 *newref = *oldref; \
842 *oldref = NULL; \
843 } \
844} while (0)
847 AVFilterChannelLayouts **newref)
848{
849 FORMATS_CHANGEREF(oldref, newref);
850}
853{
854 FORMATS_CHANGEREF(oldref, newref);
855}
857#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
858 int i; \
859 \
860 if (!fmts) \
861 return AVERROR(ENOMEM); \
862 \
863 for (i = 0; i < ctx->nb_inputs; i++) { \
864 AVFilterLink *const link = ctx->inputs[i]; \
865 if (link && !link->outcfg.fmts && \
866 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
867 int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
868 if (ret < 0) { \
869 return ret; \
870 } \
871 } \
872 } \
873 for (i = 0; i < ctx->nb_outputs; i++) { \
874 AVFilterLink *const link = ctx->outputs[i]; \
875 if (link && !link->incfg.fmts && \
876 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
877 int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
878 if (ret < 0) { \
879 return ret; \
880 } \
881 } \
882 } \
883 \
884 if (!fmts->refcount) \
885 unref_fn(&fmts); \
886 \
887 return 0;
894}
900}
905}
912}
915 const int *samplerates)
916{
918}
923}
930}
933 const int *color_spaces)
934{
936}
941}
948}
951 const int *color_ranges)
952{
954}
959}
966}
969 const int *alpha_modes)
970{
972}
977}
984}
987 const int *chroma_locations)
988{
989 return ff_set_common_chroma_locations(ctx, ff_make_format_list(chroma_locations));
990}
995}
996
997/**
998 * A helper for query_formats() which sets all links to the same list of
999 * formats. If there are no links hooked to this filter, the list of formats is
1000 * freed.
1006}
1011}
1016}
1021}
1023#define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
1024 ref_fn, unref_fn) \
1025 if (!fmts) \
1026 return AVERROR(ENOMEM); \
1027 \
1028 for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
1029 const AVFilterLink *const link = ctx->inputs[i]; \
1030 if (!cfg_in[i]->fmts && \
1031 (media_type == AVMEDIA_TYPE_UNKNOWN || \
1032 link->type == media_type)) { \
1033 int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
1034 if (ret < 0) { \
1035 return ret; \
1036 } \
1037 } \
1038 } \
1039 for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
1040 const AVFilterLink *const link = ctx->outputs[i]; \
1041 if (!cfg_out[i]->fmts && \
1042 (media_type == AVMEDIA_TYPE_UNKNOWN || \
1043 link->type == media_type)) { \
1044 int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
1045 if (ret < 0) { \
1046 return ret; \
1047 } \
1048 } \
1049 } \
1050 \
1051 if (!fmts->refcount) \
1052 unref_fn(&fmts); \
1053 \
1054 return 0;
1063}
1071}
1078}
1081 AVFilterFormatsConfig **cfg_in,
1082 AVFilterFormatsConfig **cfg_out,
1083 AVFilterFormats *samplerates)
1084{
1085 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, samplerates, AVMEDIA_TYPE_AUDIO,
1087}
1090 AVFilterFormatsConfig **cfg_in,
1091 AVFilterFormatsConfig **cfg_out,
1092 const int *samplerates)
1093{
1094 return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_make_format_list(samplerates));
1095}
1098 AVFilterFormatsConfig **cfg_in,
1099 AVFilterFormatsConfig **cfg_out)
1100{
1101 return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1102}
1105 AVFilterFormatsConfig **cfg_in,
1106 AVFilterFormatsConfig **cfg_out,
1107 AVFilterFormats *color_spaces)
1108{
1109 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_spaces, AVMEDIA_TYPE_VIDEO,
1111}
1114 AVFilterFormatsConfig **cfg_in,
1115 AVFilterFormatsConfig **cfg_out,
1116 const int *color_spaces)
1117{
1118 return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_make_format_list(color_spaces));
1119}
1126}
1129 AVFilterFormatsConfig **cfg_in,
1130 AVFilterFormatsConfig **cfg_out,
1131 AVFilterFormats *color_ranges)
1132{
1133 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_ranges, AVMEDIA_TYPE_VIDEO,
1135}
1138 AVFilterFormatsConfig **cfg_in,
1139 AVFilterFormatsConfig **cfg_out,
1140 const int *color_ranges)
1141{
1142 return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_make_format_list(color_ranges));
1143}
1150}
1153 AVFilterFormatsConfig **cfg_in,
1154 AVFilterFormatsConfig **cfg_out,
1155 AVFilterFormats *alpha_modes)
1156{
1157 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, alpha_modes, AVMEDIA_TYPE_VIDEO,
1159}
1162 AVFilterFormatsConfig **cfg_in,
1163 AVFilterFormatsConfig **cfg_out,
1164 const int *alpha_modes)
1165{
1166 return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_make_format_list(alpha_modes));
1167}
1170 AVFilterFormatsConfig **cfg_in,
1171 AVFilterFormatsConfig **cfg_out)
1172{
1173 return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_all_alpha_modes());
1174}
1177 AVFilterFormatsConfig **cfg_in,
1178 AVFilterFormatsConfig **cfg_out,
1179 AVFilterFormats *chroma_locations)
1180{
1181 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, chroma_locations, AVMEDIA_TYPE_VIDEO,
1183}
1186 AVFilterFormatsConfig **cfg_in,
1187 AVFilterFormatsConfig **cfg_out,
1188 const int *chroma_locations)
1189{
1190 return ff_set_common_chroma_locations2(ctx, cfg_in, cfg_out,
1191 ff_make_format_list(chroma_locations));
1192}
1199}
1208}
1211 AVFilterFormatsConfig **cfg_in,
1212 AVFilterFormatsConfig **cfg_out,
1213 const int *fmts)
1214{
1215 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1216}
1219 AVFilterFormatsConfig **cfg_in,
1220 AVFilterFormatsConfig **cfg_out,
1221 const enum AVSampleFormat *fmts)
1222{
1223 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_sample_format_list(fmts));
1224}
1227 AVFilterFormatsConfig **cfg_in,
1228 AVFilterFormatsConfig **cfg_out,
1229 const enum AVPixelFormat *fmts)
1230{
1231 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_pixel_format_list(fmts));
1232}
1235{
1236 const FFFilter *const f = fffilter(ctx->filter);
1238 enum AVMediaType type;
1239 int ret;
1240
1241 switch (f->formats_state) {
1244 formats = ff_make_pixel_format_list(f->formats.pixels_list);
1245 break;
1248 formats = ff_make_sample_format_list(f->formats.samples_list);
1249 break;
1252 formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1253 break;
1256 formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1257 break;
1258 default:
1259 av_assert2(!"Unreachable");
1265 formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1266 ctx->nb_outputs ? ctx->outputs[0]->type :
1268 break;
1269 }
1270
1272 if (ret < 0)
1273 return ret;
1274 if (type != AVMEDIA_TYPE_AUDIO) {
1276 if (ret < 0)
1277 return ret;
1279 if (ret < 0)
1280 return ret;
1282 if (ret < 0)
1283 return ret;
1285 if (ret < 0)
1286 return ret;
1287 }
1288 if (type != AVMEDIA_TYPE_VIDEO) {
1290 if (ret < 0)
1291 return ret;
1293 if (ret < 0)
1294 return ret;
1295 }
1296
1297 return 0;
1298}
1300static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1301{
1302 unsigned i, j;
1303
1304 if (!fmts)
1305 return 0;
1306 if (!fmts->nb_formats) {
1307 av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1308 return AVERROR(EINVAL);
1309 }
1310 for (i = 0; i < fmts->nb_formats; i++) {
1311 for (j = i + 1; j < fmts->nb_formats; j++) {
1312 if (fmts->formats[i] == fmts->formats[j]) {
1313 av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1314 return AVERROR(EINVAL);
1315 }
1316 }
1317 }
1318 return 0;
1319}
1321int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1322{
1323 return check_list(log, "pixel format", fmts);
1324}
1326int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1327{
1328 return check_list(log, "sample format", fmts);
1329}
1331int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1332{
1333 if (!fmts || !fmts->nb_formats)
1334 return 0;
1335 return check_list(log, "sample rate", fmts);
1336}
1338int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1339{
1340 for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1341 if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1342 av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1343 return AVERROR(EINVAL);
1344 }
1345 }
1346 return check_list(log, "color space", fmts);
1347}
1349int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1350{
1351 return check_list(log, "color range", fmts);
1352}
1354int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1355{
1356 return check_list(log, "alpha mode", fmts);
1357}
1359int ff_formats_check_chroma_locations(void *log, const AVFilterFormats *fmts)
1360{
1361 return check_list(log, "chroma location", fmts);
1362}
1364static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1365{
1366 return !av_channel_layout_compare(a, b) ||
1367 (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1368 (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1369}
1372{
1373 unsigned i, j;
1374
1375 if (!fmts)
1376 return 0;
1377 if (fmts->all_layouts < fmts->all_counts) {
1378 av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1379 return AVERROR(EINVAL);
1380 }
1381 if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1382 av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1383 return AVERROR(EINVAL);
1384 }
1385 for (i = 0; i < fmts->nb_channel_layouts; i++) {
1386 for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1387 if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1388 av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1389 return AVERROR(EINVAL);
1390 }
1391 }
1392 }
1393 return 0;
1394}
static const char *const format[]
Definition af_aiir.c:445
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition avassert.h:68
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Main libavfilter public API header.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:121
AVBPrint public header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
Public libavutil channel layout APIs header.
common internal and external API header
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static const uint16_t channel_layouts[7]
Definition dca_lbr.c:112
const AVFilterNegotiation * ff_filter_get_negotiation(const AVFilterLink *link)
Definition formats.c:471
int ff_set_common_alpha_modes(AVFilterContext *ctx, AVFilterFormats *alpha_modes)
Definition formats.c:960
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition formats.c:688
void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref, AVFilterChannelLayouts **newref)
Definition formats.c:845
AVFilterFormats * ff_all_formats(enum AVMediaType type)
Return a list of all formats supported by FFmpeg for the given media type.
Definition formats.c:611
int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample rates list.
Definition formats.c:1330
static const AVFilterNegotiation negotiate_audio
Definition formats.c:466
int ff_set_pixel_formats_from_list(AVFilterContext *ctx, const enum AVPixelFormat *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_pixel_format_list(fmts))
Definition formats.c:1017
static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b, enum AVMediaType type, int check)
Definition formats.c:95
int ff_set_common_chroma_locations_from_list(AVFilterContext *ctx, const int *chroma_locations)
Equivalent to ff_set_common_chroma_locations(ctx, ff_make_format_list(chroma_locations))
Definition formats.c:985
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb)
Definition formats.c:556
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:1233
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add ref as a new reference to formats.
Definition formats.c:776
int ff_set_common_color_spaces(AVFilterContext *ctx, AVFilterFormats *color_spaces)
Definition formats.c:924
AVFilterFormats * ff_all_color_spaces(void)
Construct an AVFilterFormats representing all possible color spaces.
Definition formats.c:706
#define FORMATS_CHANGEREF(oldref, newref)
Definition formats.c:832
#define PRINT_NAME(type, type_name)
Definition formats.c:349
static void print_channel_layout_desc(AVBPrint *bp, const void *layoutsp)
Definition formats.c:367
static int merge_sample_fmts(void *a, void *b)
See merge_pix_fmts().
Definition formats.c:179
int ff_set_common_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *samplerates)
Definition formats.c:1079
static void print_sample_rate(AVBPrint *bp, const void *ratesp)
Definition formats.c:376
AVFilterFormats * ff_make_formats_list_singleton(int fmt)
Equivalent to ff_make_format_list({const int[]}{ fmt, -1 })
Definition formats.c:605
int ff_set_common_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_ranges)
Definition formats.c:1127
#define MERGE_REF(ret, a, fmts, type, fail_statement)
Add all refs from a to ret and destroy a.
Definition formats.c:36
static int merge_samplerates(void *a, void *b)
See merge_pix_fmts().
Definition formats.c:205
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
Definition formats.c:1299
static const AVFilterFormatsMerger mergers_video[]
Definition formats.c:391
int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
Tell if a pixel format is contained in the provided AV_PIX_FMT_NONE-terminated list.
Definition formats.c:480
static int merge_pix_fmts(void *a, void *b)
Merge the formats lists if they are compatible and update all the references of a and b to point to t...
Definition formats.c:162
int ff_formats_check_chroma_locations(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid formats list for chroma locations.
Definition formats.c:1358
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:1001
int ff_set_common_alpha_modes_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *alpha_modes)
Definition formats.c:1160
int ff_set_common_formats2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *formats)
Definition formats.c:1200
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition formats.c:580
void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
Remove a reference to a channel layouts list.
Definition formats.c:827
int ff_set_common_all_samplerates2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1096
int ff_set_common_all_alpha_modes2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1168
AVFilterFormats * ff_formats_pixdesc_filter(unsigned want, unsigned rej)
Construct a formats list containing all pixel formats with certain properties.
Definition formats.c:629
static const AVFilterFormatsMerger mergers_audio[]
Definition formats.c:434
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:1055
#define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, ref_fn, unref_fn)
Definition formats.c:1022
static int merge_generic_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition formats.c:325
static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
Definition formats.c:1363
#define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed)
Add all formats common to a and b to a, add b's refs to a and destroy b.
Definition formats.c:63
#define CONVERSION_FILTER_ARESAMPLE
Definition formats.c:387
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition formats.c:669
int ff_set_common_all_color_ranges2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1144
static int can_merge_sample_fmts(const void *a, const void *b)
See can_merge_pix_fmts().
Definition formats.c:170
int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid pixel formats list.
Definition formats.c:1320
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:931
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:895
#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn)
Definition formats.c:856
int ff_set_common_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *fmts)
Definition formats.c:1209
int ff_add_channel_layout(AVFilterChannelLayouts **l, const AVChannelLayout *channel_layout)
Definition formats.c:597
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:949
int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
Check that fmts is a valid sample formats list.
Definition formats.c:1325
int ff_set_sample_formats_from_list(AVFilterContext *ctx, const enum AVSampleFormat *fmts)
Equivalent to ff_set_common_formats(ctx, ff_make_sample_format_list(fmts))
Definition formats.c:1012
int ff_set_common_chroma_locations(AVFilterContext *ctx, AVFilterFormats *chroma_locations)
Definition formats.c:978
static int can_merge_generic(const void *a, const void *b)
Definition formats.c:338
#define CONVERSION_FILTER_SWSCALE
Definition formats.c:383
int ff_set_common_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *color_spaces)
Definition formats.c:1103
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:1007
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:1337
int ff_set_common_chroma_locations2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *chroma_locations)
Definition formats.c:1175
static int merge_channel_layouts(void *a, void *b)
Definition formats.c:320
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition formats.c:906
int ff_set_common_color_ranges_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_ranges)
Definition formats.c:1136
static const AVFilterNegotiation negotiate_video
Definition formats.c:461
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:815
int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *samplerates)
Definition formats.c:1088
AVFilterFormats * ff_all_color_ranges(void)
Construct an AVFilterFormats representing all possible color ranges.
Definition formats.c:722
int ff_set_common_alpha_modes2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, AVFilterFormats *alpha_modes)
Definition formats.c:1151
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition formats.c:697
static int can_merge_channel_layouts(const void *a, const void *b)
Definition formats.c:314
int ff_set_common_all_color_spaces2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1120
void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
Definition formats.c:851
int ff_set_common_all_channel_counts2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1072
int ff_set_common_chroma_locations_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *chroma_locations)
Definition formats.c:1184
int ff_set_common_color_spaces_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const int *color_spaces)
Definition formats.c:1112
static int can_merge_pix_fmts(const void *a, const void *b)
Check the formats lists for compatibility for merging without actually merging.
Definition formats.c:144
int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
Definition formats.c:1348
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:913
#define FORMATS_REF(f, ref, unref_fn)
Definition formats.c:755
AVFilterFormats * ff_all_alpha_modes(void)
Construct an AVFilterFormats representing all possible alpha modes.
Definition formats.c:733
AVFilterFormats * ff_all_chroma_locations(void)
Construct an AVFilterFormats representing all possible chroma locations.
Definition formats.c:744
int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
Check that fmts is a valid channel layouts list.
Definition formats.c:1370
static int can_merge_samplerates(const void *a, const void *b)
See can_merge_pix_fmts().
Definition formats.c:197
int ff_set_common_all_samplerates(AVFilterContext *ctx)
Equivalent to ff_set_common_samplerates(ctx, ff_all_samplerates())
Definition formats.c:919
#define FORMATS_UNREF(ref, list)
Definition formats.c:791
AVFilterChannelLayouts * ff_make_channel_layout_list(const AVChannelLayout *fmts)
Definition formats.c:520
int ff_set_common_all_channel_counts(AVFilterContext *ctx)
Equivalent to ff_set_common_channel_layouts(ctx, ff_all_channel_counts())
Definition formats.c:901
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition formats.c:1064
int ff_set_common_color_ranges(AVFilterContext *ctx, AVFilterFormats *color_ranges)
Definition formats.c:942
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition formats.c:771
static int merge_channel_layouts_internal(AVFilterChannelLayouts *a, AVFilterChannelLayouts *b, int check)
See merge_pix_fmts().
Definition formats.c:213
int ff_set_common_all_alpha_modes(AVFilterContext *ctx)
Equivalent to ff_set_common_alpha_modes(ctx, ff_all_alpha_modes())
Definition formats.c:973
AVFilterFormats * ff_all_samplerates(void)
Definition formats.c:682
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:1353
int ff_set_common_all_color_spaces(AVFilterContext *ctx)
Equivalent to ff_set_common_color_spaces(ctx, ff_all_color_spaces())
Definition formats.c:937
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:967
int ff_set_pixel_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVPixelFormat *fmts)
Definition formats.c:1225
int ff_set_sample_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVSampleFormat *fmts)
Definition formats.c:1217
int ff_set_common_all_chroma_locations2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition formats.c:1193
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:888
#define MAKE_FORMAT_LIST_TYPE(name, type)
Definition formats.c:507
static int merge_generic(void *a, void *b)
Definition formats.c:344
static int merge_samplerates_internal(AVFilterFormats *a, AVFilterFormats *b, int check)
Definition formats.c:184
int ff_set_common_all_chroma_locations(AVFilterContext *ctx)
Equivalent to ff_set_common_chroma_locations(ctx, ff_all_chroma_locations())
Definition formats.c:991
int ff_set_common_all_color_ranges(AVFilterContext *ctx)
Equivalent to ff_set_common_color_ranges(ctx, ff_all_color_ranges())
Definition formats.c:955
av_warn_unused_result AVFilterFormats * ff_make_sample_format_list(const enum AVSampleFormat *fmts)
Create a list of supported sample formats.
#define FF_PIX_FMT_FLAG_SW_FLAT_SUB
Definition formats.h:503
#define FF_COUNT2LAYOUT(c)
Encode a channel count as a channel layout.
Definition formats.h:102
av_warn_unused_result AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
#define KNOWN(l)
Definition formats.h:111
av_warn_unused_result AVFilterFormats * ff_make_pixel_format_list(const enum AVPixelFormat *fmts)
Create a list of supported pixel formats.
#define fail
Definition test.h:479
int av_channel_layout_describe_bprint(const AVChannelLayout *channel_layout, AVBPrint *bp)
bprint variant of av_channel_layout_describe().
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition bprint.c:129
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
AVMediaType
Definition avutil.h:198
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AVMEDIA_TYPE_UNKNOWN
Usually treated as AVMEDIA_TYPE_DATA.
Definition avutil.h:199
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition samplefmt.c:115
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition samplefmt.c:109
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:52
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
int a
#define b
Definition input.c:43
uint32_t type
Definition jpegmpfenc.c:80
@ FF_FILTER_FORMATS_QUERY_FUNC
formats.query active.
Definition filters.h:245
@ FF_FILTER_FORMATS_SINGLE_PIXFMT
formats.pix_fmt active
Definition filters.h:249
@ FF_FILTER_FORMATS_SAMPLEFMTS_LIST
formats.samples_list active.
Definition filters.h:248
@ FF_FILTER_FORMATS_SINGLE_SAMPLEFMT
formats.sample_fmt active.
Definition filters.h:250
@ FF_FILTER_FORMATS_PASSTHROUGH
The default value meaning that this filter supports all formats and (for audio) sample rates and chan...
Definition filters.h:244
@ FF_FILTER_FORMATS_PIXFMT_LIST
formats.pixels_list active.
Definition filters.h:247
@ FF_FILTER_FORMATS_QUERY_FUNC2
formats.query_func2 active.
Definition filters.h:246
static const FFFilter * fffilter(const AVFilter *f)
Definition filters.h:479
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
const char * desc
Definition libsvtav1.c:83
#define FFSWAP(type, a, b)
Definition macros.h:52
enum AVColorRange range
enum AVSampleFormat sample_format
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
#define check(x, y, S, v)
enum MovChannelLayoutTag * layouts
Definition mov_chan.c:335
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition pixdesc.h:147
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition pixdesc.h:132
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:807
@ AVCHROMA_LOC_NB
Not part of ABI.
Definition pixfmt.h:815
AVColorRange
Visual content value range.
Definition pixfmt.h:753
@ AVCOL_RANGE_NB
Not part of ABI.
Definition pixfmt.h:789
AVAlphaMode
Correlation between the alpha channel and color values.
Definition pixfmt.h:821
@ AVALPHA_MODE_NB
Not part of ABI.
Definition pixfmt.h:825
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
AVColorSpace
YUV colorspace type.
Definition pixfmt.h:711
@ AVCOL_SPC_NB
Not part of ABI.
Definition pixfmt.h:731
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
Definition pixfmt.h:715
const char * name
Definition qsvenc.c:142
formats
Definition signature.h:47
#define FF_ARRAY_ELEMS(a)
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
A list of supported channel layouts.
Definition formats.h:85
char all_layouts
accept any known channel layout
Definition formats.h:88
char all_counts
accept any channel layout or count
Definition formats.h:89
AVChannelLayout * channel_layouts
list of channel layouts
Definition formats.h:86
int nb_channel_layouts
number of channel layouts
Definition formats.h:87
An instance of a filter.
Definition avfilter.h:279
Lists of formats / etc.
Definition avfilter.h:120
A list of supported formats for one end of a filter link.
Definition formats.h:64
int * formats
list of media formats
Definition formats.h:66
unsigned nb_formats
number of formats
Definition formats.h:65
Callbacks and properties to describe the steps of a format negotiation.
Definition formats.h:704
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
#define av_free(p)
#define av_malloc_array(a, b)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
static const int rates[]
Definition swresample.c:100