FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/formats.c
Date: 2026-10-06 20:08:58
Exec Total Coverage
Lines: 363 468 77.6%
Functions: 75 102 73.5%
Branches: 528 748 70.6%

Line Branch Exec Source
1 /*
2 * Filter layer - format negotiation
3 * Copyright (c) 2007 Bobby Bingham
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/attributes.h"
23 #include "libavutil/avassert.h"
24 #include "libavutil/bprint.h"
25 #include "libavutil/channel_layout.h"
26 #include "libavutil/common.h"
27 #include "libavutil/mem.h"
28 #include "libavutil/pixdesc.h"
29 #include "avfilter.h"
30 #include "filters.h"
31 #include "formats.h"
32
33 /**
34 * Add all refs from a to ret and destroy a.
35 */
36 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
37 do { \
38 type ***tmp; \
39 int i; \
40 \
41 if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
42 sizeof(*tmp)))) \
43 { fail_statement } \
44 ret->refs = tmp; \
45 \
46 for (i = 0; i < a->refcount; i ++) { \
47 ret->refs[ret->refcount] = a->refs[i]; \
48 *ret->refs[ret->refcount++] = ret; \
49 } \
50 \
51 av_freep(&a->refs); \
52 av_freep(&a->fmts); \
53 av_freep(&a); \
54 } while (0)
55
56 /**
57 * Add all formats common to a and b to a, add b's refs to a and destroy b.
58 * If check is set, nothing is modified and it is only checked whether
59 * the formats are compatible.
60 * If empty_allowed is set and one of a,b->nb is zero, the lists are
61 * merged; otherwise, 0 (for nonmergeability) is returned.
62 */
63 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
64 do { \
65 int i, j, k = 0, skip = 0; \
66 \
67 if (empty_allowed) { \
68 if (!a->nb || !b->nb) { \
69 if (check) \
70 return 1; \
71 if (!a->nb) \
72 FFSWAP(type *, a, b); \
73 skip = 1; \
74 } \
75 } \
76 if (!skip) { \
77 for (i = 0; i < a->nb; i++) \
78 for (j = 0; j < b->nb; j++) \
79 if (a->fmts[i] == b->fmts[j]) { \
80 if (check) \
81 return 1; \
82 a->fmts[k++] = a->fmts[i]; \
83 break; \
84 } \
85 /* Check that there was at least one common format. \
86 * Notice that both a and b are unchanged if not. */ \
87 if (!k) \
88 return 0; \
89 av_assert2(!check); \
90 a->nb = k; \
91 } \
92 \
93 MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
94 } while (0)
95
96 74959 static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b,
97 enum AVMediaType type, int check)
98 {
99 int i, j;
100 74959 int alpha1=0, alpha2=0;
101 74959 int chroma1=0, chroma2=0;
102
103 av_assert2(check || (a->refcount && b->refcount));
104
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 74959 times.
74959 if (a == b)
106 ✗ return 1;
107
108 /* Do not lose chroma or alpha in merging.
109 It happens if both lists have formats with chroma (resp. alpha), but
110 the only formats in common do not have it (e.g. YUV+gray vs.
111 RGB+gray): in that case, the merging would select the gray format,
112 possibly causing a lossy conversion elsewhere in the graph.
113 To avoid that, pretend that there are no common formats to force the
114 insertion of a conversion filter. */
115
2/2
✓ Branch 0 taken 62275 times.
✓ Branch 1 taken 12684 times.
74959 if (type == AVMEDIA_TYPE_VIDEO)
116
2/2
✓ Branch 0 taken 3475037 times.
✓ Branch 1 taken 62275 times.
3537312 for (i = 0; i < a->nb_formats; i++) {
117 3475037 const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
118
2/2
✓ Branch 0 taken 207403577 times.
✓ Branch 1 taken 3475037 times.
210878614 for (j = 0; j < b->nb_formats; j++) {
119 207403577 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
120 207403577 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
121
4/4
✓ Branch 0 taken 180847898 times.
✓ Branch 1 taken 26555679 times.
✓ Branch 2 taken 156671941 times.
✓ Branch 3 taken 24175957 times.
207403577 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
122
2/2
✓ Branch 0 taken 786391 times.
✓ Branch 1 taken 206617186 times.
207403577 if (a->formats[i] == b->formats[j]) {
123 786391 alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
124 786391 chroma1|= adesc->nb_components > 1;
125 }
126 }
127 }
128
129 // If chroma or alpha can be lost through merging then do not merge
130
4/4
✓ Branch 0 taken 74936 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 559 times.
✓ Branch 3 taken 74377 times.
74959 if (alpha2 > alpha1 || chroma2 > chroma1)
131 582 return 0;
132
133
14/16
✓ Branch 0 taken 74377 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 440016 times.
✓ Branch 3 taken 52504823 times.
✓ Branch 4 taken 35248 times.
✓ Branch 5 taken 404768 times.
✓ Branch 6 taken 52944839 times.
✓ Branch 7 taken 2005196 times.
✓ Branch 8 taken 2445212 times.
✓ Branch 9 taken 39129 times.
✓ Branch 10 taken 862 times.
✓ Branch 11 taken 38267 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 38267 times.
✓ Branch 15 taken 84661 times.
✓ Branch 16 taken 38267 times.
55073825 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
134
135 38267 return 1;
136 }
137
138
139 /**
140 * Check the formats lists for compatibility for merging without actually
141 * merging.
142 *
143 * @return 1 if they are compatible, 0 if not.
144 */
145 30756 static int can_merge_pix_fmts(const void *a, const void *b)
146 {
147 30756 return merge_formats_internal((AVFilterFormats *)a,
148 (AVFilterFormats *)b, AVMEDIA_TYPE_VIDEO, 1);
149 }
150
151 /**
152 * Merge the formats lists if they are compatible and update all the
153 * references of a and b to point to the combined list and free the old
154 * lists as needed. The combined list usually contains the intersection of
155 * the lists of a and b.
156 *
157 * Both a and b must have owners (i.e. refcount > 0) for these functions.
158 *
159 * @return 1 if merging succeeded, 0 if a and b are incompatible
160 * and negative AVERROR code on failure.
161 * a and b are unmodified if 0 is returned.
162 */
163 31519 static int merge_pix_fmts(void *a, void *b)
164 {
165 31519 return merge_formats_internal(a, b, AVMEDIA_TYPE_VIDEO, 0);
166 }
167
168 /**
169 * See can_merge_pix_fmts().
170 */
171 5936 static int can_merge_sample_fmts(const void *a, const void *b)
172 {
173 5936 return merge_formats_internal((AVFilterFormats *)a,
174 (AVFilterFormats *)b, AVMEDIA_TYPE_AUDIO, 1);
175 }
176
177 /**
178 * See merge_pix_fmts().
179 */
180 6748 static int merge_sample_fmts(void *a, void *b)
181 {
182 6748 return merge_formats_internal(a, b, AVMEDIA_TYPE_AUDIO, 0);
183 }
184
185 12684 static int merge_samplerates_internal(AVFilterFormats *a,
186 AVFilterFormats *b, int check)
187 {
188 av_assert2(check || (a->refcount && b->refcount));
189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12684 times.
12684 if (a == b) return 1;
190
191
23/24
✓ Branch 0 taken 8126 times.
✓ Branch 1 taken 4558 times.
✓ Branch 2 taken 7819 times.
✓ Branch 3 taken 307 times.
✓ Branch 4 taken 5706 times.
✓ Branch 5 taken 6671 times.
✓ Branch 6 taken 2685 times.
✓ Branch 7 taken 3986 times.
✓ Branch 8 taken 307 times.
✓ Branch 9 taken 6671 times.
✓ Branch 10 taken 298 times.
✓ Branch 11 taken 685 times.
✓ Branch 12 taken 221 times.
✓ Branch 13 taken 77 times.
✓ Branch 14 taken 983 times.
✓ Branch 15 taken 9 times.
✓ Branch 16 taken 307 times.
✓ Branch 17 taken 86 times.
✓ Branch 18 taken 9 times.
✓ Branch 19 taken 77 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 6748 times.
✓ Branch 23 taken 27772 times.
✓ Branch 24 taken 6748 times.
41227 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
192 6748 return 1;
193 }
194
195 /**
196 * See can_merge_pix_fmts().
197 */
198 5936 static int can_merge_samplerates(const void *a, const void *b)
199 {
200 5936 return merge_samplerates_internal((AVFilterFormats *)a, (AVFilterFormats *)b, 1);
201 }
202
203 /**
204 * See merge_pix_fmts().
205 */
206 6748 static int merge_samplerates(void *a, void *b)
207 {
208 6748 return merge_samplerates_internal(a, b, 0);
209 }
210
211 /**
212 * See merge_pix_fmts().
213 */
214 7650 static int merge_channel_layouts_internal(AVFilterChannelLayouts *a,
215 AVFilterChannelLayouts *b, int check)
216 {
217 7650 AVChannelLayout *channel_layouts = NULL;
218 7650 unsigned a_all = a->all_layouts + a->all_counts;
219 7650 unsigned b_all = b->all_layouts + b->all_counts;
220 7650 int ret_max, ret_nb = 0, i, j, round;
221
222 av_assert2(a->refcount && b->refcount);
223
224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7650 times.
7650 if (a == b) return 1;
225
226 /* Put the most generic set in a, to avoid doing everything twice */
227
2/2
✓ Branch 0 taken 3892 times.
✓ Branch 1 taken 3758 times.
7650 if (a_all < b_all) {
228 3892 FFSWAP(AVFilterChannelLayouts *, a, b);
229 3892 FFSWAP(unsigned, a_all, b_all);
230 }
231
2/2
✓ Branch 0 taken 7307 times.
✓ Branch 1 taken 343 times.
7650 if (a_all) {
232
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 7237 times.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
7307 if (a_all == 1 && !b_all) {
233 /* keep only known layouts in b; works also for b_all = 1 */
234
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 70 times.
140 for (i = j = 0; i < b->nb_channel_layouts; i++)
235
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 70 times.
70 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
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!j)
243 ✗ return 0;
244 70 b->nb_channel_layouts = j;
245 }
246
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 7307 times.
✓ Branch 3 taken 12531 times.
✓ Branch 4 taken 7307 times.
19838 MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, return AVERROR(ENOMEM););
247 7307 return 1;
248 }
249
250 343 ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
251
3/4
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 253 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 90 times.
343 if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
252 ✗ return AVERROR(ENOMEM);
253
254 /* a[known] intersect b[known] */
255
2/2
✓ Branch 0 taken 343 times.
✓ Branch 1 taken 99 times.
442 for (i = 0; i < a->nb_channel_layouts; i++) {
256
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 340 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
343 if (!KNOWN(&a->channel_layouts[i]))
257 3 continue;
258
2/2
✓ Branch 0 taken 506 times.
✓ Branch 1 taken 7 times.
513 for (j = 0; j < b->nb_channel_layouts; j++) {
259
2/2
✓ Branch 1 taken 333 times.
✓ Branch 2 taken 173 times.
506 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
260
2/2
✓ Branch 0 taken 244 times.
✓ Branch 1 taken 89 times.
333 if (check)
261 244 return 1;
262 89 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
263 89 av_channel_layout_uninit(&a->channel_layouts[i]);
264 89 av_channel_layout_uninit(&b->channel_layouts[j]);
265 89 break;
266 }
267 }
268 }
269 /* 1st round: a[known] intersect b[generic]
270 2nd round: a[generic] intersect b[known] */
271
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 98 times.
296 for (round = 0; round < 2; round++) {
272
2/2
✓ Branch 0 taken 333 times.
✓ Branch 1 taken 197 times.
530 for (i = 0; i < a->nb_channel_layouts; i++) {
273 333 AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
274
5/6
✓ Branch 1 taken 155 times.
✓ Branch 2 taken 178 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 150 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
333 if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
275 183 continue;
276 150 bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
277
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 149 times.
299 for (j = 0; j < b->nb_channel_layouts; j++)
278
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 149 times.
150 if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
279
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (check)
280 1 return 1;
281 ✗ av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
282 }
283 }
284 /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
285 197 FFSWAP(AVFilterChannelLayouts *, a, b);
286 }
287 /* a[generic] intersect b[generic] */
288
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 97 times.
195 for (i = 0; i < a->nb_channel_layouts; i++) {
289
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 2 times.
98 if (KNOWN(&a->channel_layouts[i]))
290 96 continue;
291
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (j = 0; j < b->nb_channel_layouts; j++)
292
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
293
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if (check)
294 1 return 1;
295 1 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
296 }
297 }
298
299
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 90 times.
97 if (!ret_nb) {
300 7 av_free(channel_layouts);
301 7 return 0;
302 }
303
304
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 69 times.
90 if (a->refcount > b->refcount)
305 21 FFSWAP(AVFilterChannelLayouts *, a, b);
306
307
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 90 times.
✓ Branch 4 taken 178 times.
✓ Branch 5 taken 90 times.
268 MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts,
308 { av_free(channel_layouts); return AVERROR(ENOMEM); });
309 90 av_freep(&b->channel_layouts);
310 90 b->channel_layouts = channel_layouts;
311 90 b->nb_channel_layouts = ret_nb;
312 90 return 1;
313 }
314
315 5936 static int can_merge_channel_layouts(const void *a, const void *b)
316 {
317 5936 return merge_channel_layouts_internal((AVFilterChannelLayouts *)a,
318 (AVFilterChannelLayouts *)b, 1);
319 }
320
321 1714 static int merge_channel_layouts(void *a, void *b)
322 {
323 1714 return merge_channel_layouts_internal(a, b, 0);
324 }
325
326 250580 static int merge_generic_internal(AVFilterFormats *a,
327 AVFilterFormats *b, int check)
328 {
329 av_assert2(check || (a->refcount && b->refcount));
330
331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 250580 times.
250580 if (a == b)
332 ✗ return 1;
333
334
14/16
✓ Branch 0 taken 250580 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 761017 times.
✓ Branch 3 taken 2443264 times.
✓ Branch 4 taken 124320 times.
✓ Branch 5 taken 636697 times.
✓ Branch 6 taken 3204281 times.
✓ Branch 7 taken 25661 times.
✓ Branch 8 taken 786678 times.
✓ Branch 9 taken 126260 times.
✓ Branch 10 taken 204 times.
✓ Branch 11 taken 126056 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 126056 times.
✓ Branch 15 taken 233769 times.
✓ Branch 16 taken 126056 times.
3589971 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
335
336 126056 return 1;
337 }
338
339 124524 static int can_merge_generic(const void *a, const void *b)
340 {
341 124524 return merge_generic_internal((AVFilterFormats *)a,
342 (AVFilterFormats *)b, 1);
343 }
344
345 126056 static int merge_generic(void *a, void *b)
346 {
347 126056 return merge_generic_internal(a, b, 0);
348 }
349
350 #define PRINT_NAME(type, type_name) \
351 static void print_##type_name(AVBPrint *bp, const void *fmtsp) \
352 { \
353 const AVFilterFormats *fmts = fmtsp; \
354 for (int i = 0; i < fmts->nb_formats; i++) { \
355 const char *name = av_##type_name(fmts->formats[i]); \
356 av_bprint_chars(bp, ' ', i ? 1 : 0); \
357 av_bprint_append_data(bp, name, name ? strlen(name) : 0); \
358 } \
359 }
360
361 ✗ PRINT_NAME(enum AVSampleFormat, get_sample_fmt_name)
362 ✗ PRINT_NAME(enum AVPixelFormat, get_pix_fmt_name)
363 ✗ PRINT_NAME(enum AVColorSpace, color_space_name)
364 ✗ PRINT_NAME(enum AVColorRange, color_range_name)
365 ✗ PRINT_NAME(enum AVAlphaMode, alpha_mode_name)
366 ✗ PRINT_NAME(enum AVChromaLocation, chroma_location_name)
367
368 ✗ static 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 ✗ }
376
377 ✗ static 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 ✗ }
383
384 #define CONVERSION_FILTER_SWSCALE \
385 .conversion_filter = "scale", \
386 .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
387
388 #define CONVERSION_FILTER_ARESAMPLE \
389 .conversion_filter = "aresample", \
390 .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
391
392 static 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,
399 CONVERSION_FILTER_SWSCALE
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,
407 CONVERSION_FILTER_SWSCALE
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,
415 CONVERSION_FILTER_SWSCALE
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,
431 CONVERSION_FILTER_SWSCALE
432 },
433 };
434
435 static 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,
442 CONVERSION_FILTER_ARESAMPLE
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,
450 CONVERSION_FILTER_ARESAMPLE
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,
458 CONVERSION_FILTER_ARESAMPLE
459 },
460 };
461
462 static const AVFilterNegotiation negotiate_video = {
463 .nb_mergers = FF_ARRAY_ELEMS(mergers_video),
464 .mergers = mergers_video,
465 };
466
467 static const AVFilterNegotiation negotiate_audio = {
468 .nb_mergers = FF_ARRAY_ELEMS(mergers_audio),
469 .mergers = mergers_audio,
470 };
471
472 64561 const AVFilterNegotiation *ff_filter_get_negotiation(const AVFilterLink *link)
473 {
474
2/3
✓ Branch 0 taken 33892 times.
✓ Branch 1 taken 30669 times.
✗ Branch 2 not taken.
64561 switch (link->type) {
475 33892 case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
476 30669 case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
477 ✗ default: return NULL;
478 }
479 }
480
481 194 int ff_pixfmt_is_in(enum AVPixelFormat fmt, const enum AVPixelFormat *fmts)
482 {
483
2/2
✓ Branch 0 taken 2185 times.
✓ Branch 1 taken 107 times.
2292 for (; *fmts != AV_PIX_FMT_NONE; ++fmts) {
484
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 2098 times.
2185 if (fmt == *fmts)
485 87 return 1;
486 }
487 107 return 0;
488 }
489
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 }
507
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
517
8/12
✓ Branch 0 taken 1129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2245 times.
✓ Branch 3 taken 1129 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1129 times.
✓ Branch 7 taken 1129 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1129 times.
✓ Branch 13 taken 2245 times.
✓ Branch 14 taken 1129 times.
5619 MAKE_FORMAT_LIST_TYPE(format, int)
518
8/12
✓ Branch 0 taken 2098 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2535 times.
✓ Branch 3 taken 2098 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2098 times.
✓ Branch 7 taken 2098 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 2098 times.
✓ Branch 13 taken 2535 times.
✓ Branch 14 taken 2098 times.
7168 MAKE_FORMAT_LIST_TYPE(sample_format, enum AVSampleFormat)
519
8/12
✓ Branch 0 taken 1694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46824 times.
✓ Branch 3 taken 1694 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1694 times.
✓ Branch 7 taken 1694 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1694 times.
✓ Branch 13 taken 46824 times.
✓ Branch 14 taken 1694 times.
95342 MAKE_FORMAT_LIST_TYPE(pixel_format, enum AVPixelFormat)
520
521 359 AVFilterChannelLayouts *ff_make_channel_layout_list(const AVChannelLayout *fmts)
522 {
523 AVFilterChannelLayouts *ch_layouts;
524 359 int count = 0;
525
1/2
✓ Branch 0 taken 359 times.
✗ Branch 1 not taken.
359 if (fmts)
526
2/2
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 359 times.
1286 for (count = 0; fmts[count].nb_channels; count++)
527 ;
528 359 ch_layouts = av_mallocz(sizeof(*ch_layouts));
529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (!ch_layouts)
530 ✗ return NULL;
531 359 ch_layouts->nb_channel_layouts = count;
532
1/2
✓ Branch 0 taken 359 times.
✗ Branch 1 not taken.
359 if (count) {
533 718 ch_layouts->channel_layouts =
534 359 av_calloc(count, sizeof(*ch_layouts->channel_layouts));
535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 359 times.
359 if (!ch_layouts->channel_layouts) {
536 ✗ av_freep(&ch_layouts);
537 ✗ return NULL;
538 }
539
2/2
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 359 times.
1286 for (int i = 0; i < count; i++) {
540 927 int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 927 times.
927 if (ret < 0)
542 ✗ goto fail;
543 }
544 }
545
546 359 return ch_layouts;
547
548 ✗ fail:
549 ✗ for (int i = 0; i < count; i++)
550 ✗ av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
551 ✗ av_free(ch_layouts->channel_layouts);
552 ✗ av_freep(&ch_layouts);
553
554 ✗ return NULL;
555 }
556
557 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
558 do { \
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)
575
576 #define ASSIGN_FMT(f, fmt, list, nb) \
577 do { \
578 (*f)->list[(*f)->nb++] = fmt; \
579 } while (0)
580
581 5106921 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
582 {
583
4/6
✓ Branch 0 taken 293397 times.
✓ Branch 1 taken 4813524 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 293397 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 5106921 times.
5106921 ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
584 5106921 return 0;
585 }
586
587 #undef ASSIGN_FMT
588 #define ASSIGN_FMT(f, fmt, list, nb) \
589 do { \
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)
597
598 2431 int ff_add_channel_layout(AVFilterChannelLayouts **l,
599 const AVChannelLayout *channel_layout)
600 {
601 av_assert1(!(*l && (*l)->all_layouts));
602
5/8
✓ Branch 0 taken 1578 times.
✓ Branch 1 taken 853 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1578 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2431 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2431 times.
2431 ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
603 2431 return 0;
604 }
605
606 102 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
607 {
608 102 int fmts[2] = { fmt, -1 };
609 102 return ff_make_format_list(fmts);
610 }
611
612 48585 AVFilterFormats *ff_all_formats(enum AVMediaType type)
613 {
614 48585 AVFilterFormats *ret = NULL;
615
616
2/2
✓ Branch 0 taken 37072 times.
✓ Branch 1 taken 11513 times.
48585 if (type == AVMEDIA_TYPE_VIDEO) {
617 37072 return ff_formats_pixdesc_filter(0, 0);
618
1/2
✓ Branch 0 taken 11513 times.
✗ Branch 1 not taken.
11513 } else if (type == AVMEDIA_TYPE_AUDIO) {
619 11513 enum AVSampleFormat fmt = 0;
620
2/2
✓ Branch 1 taken 149669 times.
✓ Branch 2 taken 11513 times.
161182 while (av_get_sample_fmt_name(fmt)) {
621
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 149669 times.
149669 if (ff_add_format(&ret, fmt) < 0)
622 ✗ return NULL;
623 149669 fmt++;
624 }
625 }
626
627 11513 return ret;
628 }
629
630 37726 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
631 {
632 unsigned nb_formats, fmt, flags;
633 37726 AVFilterFormats *formats = NULL;
634
635 while (1) {
636 75452 nb_formats = 0;
637 20447492 for (fmt = 0;; fmt++) {
638 20447492 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
639
2/2
✓ Branch 0 taken 75452 times.
✓ Branch 1 taken 20372040 times.
20447492 if (!desc)
640 75452 break;
641 20372040 flags = desc->flags;
642
2/2
✓ Branch 0 taken 19089356 times.
✓ Branch 1 taken 1282684 times.
20372040 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
643
2/2
✓ Branch 0 taken 8903336 times.
✓ Branch 1 taken 10186020 times.
19089356 !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
644
3/4
✓ Branch 0 taken 8148816 times.
✓ Branch 1 taken 754520 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8148816 times.
8903336 (desc->log2_chroma_w || desc->log2_chroma_h))
645 754520 flags |= FF_PIX_FMT_FLAG_SW_FLAT_SUB;
646
2/2
✓ Branch 0 taken 22604 times.
✓ Branch 1 taken 20349436 times.
20372040 if ((flags & (want | rej)) != want)
647 22604 continue;
648
2/2
✓ Branch 0 taken 10174718 times.
✓ Branch 1 taken 10174718 times.
20349436 if (formats)
649 10174718 formats->formats[nb_formats] = fmt;
650 20349436 nb_formats++;
651 }
652
2/2
✓ Branch 0 taken 37726 times.
✓ Branch 1 taken 37726 times.
75452 if (formats) {
653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37726 times.
37726 av_assert0(formats->nb_formats == nb_formats);
654 37726 return formats;
655 }
656 37726 formats = av_mallocz(sizeof(*formats));
657
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37726 times.
37726 if (!formats)
658 ✗ return NULL;
659 37726 formats->nb_formats = nb_formats;
660
1/2
✓ Branch 0 taken 37726 times.
✗ Branch 1 not taken.
37726 if (nb_formats) {
661 37726 formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
662
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37726 times.
37726 if (!formats->formats) {
663 ✗ av_freep(&formats);
664 ✗ return NULL;
665 }
666 }
667 }
668 }
669
670 65 AVFilterFormats *ff_planar_sample_fmts(void)
671 {
672 65 AVFilterFormats *ret = NULL;
673 int fmt;
674
675
2/2
✓ Branch 1 taken 845 times.
✓ Branch 2 taken 65 times.
910 for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
676
2/2
✓ Branch 1 taken 390 times.
✓ Branch 2 taken 455 times.
845 if (av_sample_fmt_is_planar(fmt))
677
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 390 times.
390 if (ff_add_format(&ret, fmt) < 0)
678 ✗ return NULL;
679
680 65 return ret;
681 }
682
683 47976 AVFilterFormats *ff_all_samplerates(void)
684 {
685 47976 AVFilterFormats *ret = av_mallocz(sizeof(*ret));
686 47976 return ret;
687 }
688
689 70 AVFilterChannelLayouts *ff_all_channel_layouts(void)
690 {
691 70 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
692
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!ret)
693 ✗ return NULL;
694 70 ret->all_layouts = 1;
695 70 return ret;
696 }
697
698 48637 AVFilterChannelLayouts *ff_all_channel_counts(void)
699 {
700 48637 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48637 times.
48637 if (!ret)
702 ✗ return NULL;
703 48637 ret->all_layouts = ret->all_counts = 1;
704 48637 return ret;
705 }
706
707 60428 AVFilterFormats *ff_all_color_spaces(void)
708 {
709 60428 AVFilterFormats *ret = NULL;
710
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 60428 times.
60428 if (ff_add_format(&ret, AVCOL_SPC_UNSPECIFIED) < 0)
711 ✗ return NULL;
712
2/2
✓ Branch 0 taken 1087704 times.
✓ Branch 1 taken 60428 times.
1148132 for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
713
4/4
✓ Branch 0 taken 1027276 times.
✓ Branch 1 taken 60428 times.
✓ Branch 2 taken 60428 times.
✓ Branch 3 taken 966848 times.
1087704 if (csp == AVCOL_SPC_RESERVED ||
714 csp == AVCOL_SPC_UNSPECIFIED)
715 120856 continue;
716
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 966848 times.
966848 if (ff_add_format(&ret, csp) < 0)
717 ✗ return NULL;
718 }
719
720 60428 return ret;
721 }
722
723 60428 AVFilterFormats *ff_all_color_ranges(void)
724 {
725 60428 AVFilterFormats *ret = NULL;
726
2/2
✓ Branch 0 taken 181284 times.
✓ Branch 1 taken 60428 times.
241712 for (int range = 0; range < AVCOL_RANGE_NB; range++) {
727
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 181284 times.
181284 if (ff_add_format(&ret, range) < 0)
728 ✗ return NULL;
729 }
730
731 60428 return ret;
732 }
733
734 46721 AVFilterFormats *ff_all_alpha_modes(void)
735 {
736 46721 AVFilterFormats *ret = NULL;
737
2/2
✓ Branch 0 taken 140163 times.
✓ Branch 1 taken 46721 times.
186884 for (int am = 0; am < AVALPHA_MODE_NB; am++) {
738
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 140163 times.
140163 if (ff_add_format(&ret, am) < 0)
739 ✗ return NULL;
740 }
741
742 46721 return ret;
743 }
744
745 60420 AVFilterFormats *ff_all_chroma_locations(void)
746 {
747 60420 AVFilterFormats *ret = NULL;
748
2/2
✓ Branch 0 taken 422940 times.
✓ Branch 1 taken 60420 times.
483360 for (int loc = 0; loc < AVCHROMA_LOC_NB; loc++) {
749
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 422940 times.
422940 if (ff_add_format(&ret, loc) < 0)
750 ✗ return NULL;
751 }
752
753 60420 return ret;
754 }
755
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
771
772 13496 int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
773 {
774
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13496 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13496 times.
13496 FORMATS_REF(f, ref, ff_channel_layouts_unref);
775 }
776
777 361816 int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
778 {
779
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 361816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 361816 times.
361816 FORMATS_REF(f, ref, ff_formats_unref);
780 }
781
782 #define FIND_REF_INDEX(ref, idx) \
783 do { \
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)
791
792 #define FORMATS_UNREF(ref, list) \
793 do { \
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)
814
815 #define FREE_LIST(ref, list) do { } while(0)
816 1265556 void ff_formats_unref(AVFilterFormats **ref)
817 {
818
10/10
✓ Branch 0 taken 765151 times.
✓ Branch 1 taken 500405 times.
✓ Branch 2 taken 361816 times.
✓ Branch 3 taken 179910 times.
✓ Branch 4 taken 541726 times.
✓ Branch 5 taken 138589 times.
✓ Branch 6 taken 361816 times.
✓ Branch 7 taken 138589 times.
✓ Branch 8 taken 212949 times.
✓ Branch 9 taken 287456 times.
1445466 FORMATS_UNREF(ref, formats);
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)
827
828 215009 void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
829 {
830
12/12
✓ Branch 0 taken 160966 times.
✓ Branch 1 taken 54043 times.
✓ Branch 2 taken 13496 times.
✓ Branch 3 taken 14918 times.
✓ Branch 4 taken 28414 times.
✓ Branch 5 taken 40547 times.
✓ Branch 6 taken 13496 times.
✓ Branch 7 taken 40547 times.
✓ Branch 8 taken 43247 times.
✓ Branch 9 taken 10796 times.
✓ Branch 11 taken 2700 times.
✓ Branch 12 taken 43247 times.
232627 FORMATS_UNREF(ref, channel_layouts);
831 }
832
833 #define FORMATS_CHANGEREF(oldref, newref) \
834 do { \
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)
845
846 812 void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref,
847 AVFilterChannelLayouts **newref)
848 {
849
4/6
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 1883 times.
✓ Branch 2 taken 2695 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 812 times.
✗ Branch 5 not taken.
2695 FORMATS_CHANGEREF(oldref, newref);
850 812 }
851
852 5449 void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
853 {
854
4/6
✓ Branch 0 taken 5449 times.
✓ Branch 1 taken 8862 times.
✓ Branch 2 taken 14311 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5449 times.
✗ Branch 5 not taken.
14311 FORMATS_CHANGEREF(oldref, newref);
855 5449 }
856
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;
888
889 45239 int ff_set_common_channel_layouts(AVFilterContext *ctx,
890 AVFilterChannelLayouts *channel_layouts)
891 {
892
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 45239 times.
✓ Branch 2 taken 37900 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35854 times.
✓ Branch 5 taken 2046 times.
✓ Branch 6 taken 4702 times.
✓ Branch 7 taken 31152 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4702 times.
✓ Branch 11 taken 37900 times.
✓ Branch 12 taken 45239 times.
✓ Branch 13 taken 36777 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 33165 times.
✓ Branch 16 taken 3612 times.
✓ Branch 17 taken 3136 times.
✓ Branch 18 taken 30029 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 3136 times.
✓ Branch 22 taken 36777 times.
✓ Branch 23 taken 45239 times.
✓ Branch 24 taken 40547 times.
✓ Branch 25 taken 4692 times.
119916 SET_COMMON_FORMATS(ctx, channel_layouts, AVMEDIA_TYPE_AUDIO,
893 ff_channel_layouts_ref, ff_channel_layouts_unref);
894 }
895
896 ✗ int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
897 const AVChannelLayout *fmts)
898 {
899 ✗ return ff_set_common_channel_layouts(ctx, ff_make_channel_layout_list(fmts));
900 }
901
902 45239 int ff_set_common_all_channel_counts(AVFilterContext *ctx)
903 {
904 45239 return ff_set_common_channel_layouts(ctx, ff_all_channel_counts());
905 }
906
907 45243 int ff_set_common_samplerates(AVFilterContext *ctx,
908 AVFilterFormats *samplerates)
909 {
910
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 45243 times.
✓ Branch 2 taken 37910 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35976 times.
✓ Branch 5 taken 1934 times.
✓ Branch 6 taken 4824 times.
✓ Branch 7 taken 31152 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4824 times.
✓ Branch 11 taken 37910 times.
✓ Branch 12 taken 45243 times.
✓ Branch 13 taken 36781 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 33342 times.
✓ Branch 16 taken 3439 times.
✓ Branch 17 taken 3313 times.
✓ Branch 18 taken 30029 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 3313 times.
✓ Branch 22 taken 36781 times.
✓ Branch 23 taken 45243 times.
✓ Branch 24 taken 40501 times.
✓ Branch 25 taken 4742 times.
119934 SET_COMMON_FORMATS(ctx, samplerates, AVMEDIA_TYPE_AUDIO,
911 ff_formats_ref, ff_formats_unref);
912 }
913
914 ✗ int ff_set_common_samplerates_from_list(AVFilterContext *ctx,
915 const int *samplerates)
916 {
917 ✗ return ff_set_common_samplerates(ctx, ff_make_format_list(samplerates));
918 }
919
920 45243 int ff_set_common_all_samplerates(AVFilterContext *ctx)
921 {
922 45243 return ff_set_common_samplerates(ctx, ff_all_samplerates());
923 }
924
925 46717 int ff_set_common_color_spaces(AVFilterContext *ctx,
926 AVFilterFormats *color_spaces)
927 {
928
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
✓ Branch 2 taken 38246 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31415 times.
✓ Branch 5 taken 6831 times.
✓ Branch 6 taken 24710 times.
✓ Branch 7 taken 6705 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 24710 times.
✓ Branch 11 taken 38246 times.
✓ Branch 12 taken 46717 times.
✓ Branch 13 taken 38255 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 26304 times.
✓ Branch 16 taken 11951 times.
✓ Branch 17 taken 19590 times.
✓ Branch 18 taken 6714 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 19590 times.
✓ Branch 22 taken 38255 times.
✓ Branch 23 taken 46717 times.
✓ Branch 24 taken 20090 times.
✓ Branch 25 taken 26627 times.
123218 SET_COMMON_FORMATS(ctx, color_spaces, AVMEDIA_TYPE_VIDEO,
929 ff_formats_ref, ff_formats_unref);
930 }
931
932 ✗ int ff_set_common_color_spaces_from_list(AVFilterContext *ctx,
933 const int *color_spaces)
934 {
935 ✗ return ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces));
936 }
937
938 46717 int ff_set_common_all_color_spaces(AVFilterContext *ctx)
939 {
940 46717 return ff_set_common_color_spaces(ctx, ff_all_color_spaces());
941 }
942
943 46717 int ff_set_common_color_ranges(AVFilterContext *ctx,
944 AVFilterFormats *color_ranges)
945 {
946
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
✓ Branch 2 taken 38246 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29217 times.
✓ Branch 5 taken 9029 times.
✓ Branch 6 taken 22512 times.
✓ Branch 7 taken 6705 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 22512 times.
✓ Branch 11 taken 38246 times.
✓ Branch 12 taken 46717 times.
✓ Branch 13 taken 38255 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 24106 times.
✓ Branch 16 taken 14149 times.
✓ Branch 17 taken 17392 times.
✓ Branch 18 taken 6714 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 17392 times.
✓ Branch 22 taken 38255 times.
✓ Branch 23 taken 46717 times.
✓ Branch 24 taken 22288 times.
✓ Branch 25 taken 24429 times.
123218 SET_COMMON_FORMATS(ctx, color_ranges, AVMEDIA_TYPE_VIDEO,
947 ff_formats_ref, ff_formats_unref);
948 }
949
950 ✗ int ff_set_common_color_ranges_from_list(AVFilterContext *ctx,
951 const int *color_ranges)
952 {
953 ✗ return ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges));
954 }
955
956 46717 int ff_set_common_all_color_ranges(AVFilterContext *ctx)
957 {
958 46717 return ff_set_common_color_ranges(ctx, ff_all_color_ranges());
959 }
960
961 46717 int ff_set_common_alpha_modes(AVFilterContext *ctx,
962 AVFilterFormats *alpha_modes)
963 {
964
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
✓ Branch 2 taken 38246 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 38202 times.
✓ Branch 5 taken 44 times.
✓ Branch 6 taken 31497 times.
✓ Branch 7 taken 6705 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 31497 times.
✓ Branch 11 taken 38246 times.
✓ Branch 12 taken 46717 times.
✓ Branch 13 taken 38255 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 37896 times.
✓ Branch 16 taken 359 times.
✓ Branch 17 taken 31182 times.
✓ Branch 18 taken 6714 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 31182 times.
✓ Branch 22 taken 38255 times.
✓ Branch 23 taken 46717 times.
✓ Branch 24 taken 8495 times.
✓ Branch 25 taken 38222 times.
123218 SET_COMMON_FORMATS(ctx, alpha_modes, AVMEDIA_TYPE_VIDEO,
965 ff_formats_ref, ff_formats_unref);
966 }
967
968 ✗ int ff_set_common_alpha_modes_from_list(AVFilterContext *ctx,
969 const int *alpha_modes)
970 {
971 ✗ return ff_set_common_alpha_modes(ctx, ff_make_format_list(alpha_modes));
972 }
973
974 46717 int ff_set_common_all_alpha_modes(AVFilterContext *ctx)
975 {
976 46717 return ff_set_common_alpha_modes(ctx, ff_all_alpha_modes());
977 }
978
979 46717 int ff_set_common_chroma_locations(AVFilterContext *ctx,
980 AVFilterFormats *chroma_locations)
981 {
982
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
✓ Branch 2 taken 38246 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 30716 times.
✓ Branch 5 taken 7530 times.
✓ Branch 6 taken 24011 times.
✓ Branch 7 taken 6705 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 24011 times.
✓ Branch 11 taken 38246 times.
✓ Branch 12 taken 46717 times.
✓ Branch 13 taken 38255 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 29643 times.
✓ Branch 16 taken 8612 times.
✓ Branch 17 taken 22929 times.
✓ Branch 18 taken 6714 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 22929 times.
✓ Branch 22 taken 38255 times.
✓ Branch 23 taken 46717 times.
✓ Branch 24 taken 16748 times.
✓ Branch 25 taken 29969 times.
123218 SET_COMMON_FORMATS(ctx, chroma_locations, AVMEDIA_TYPE_VIDEO,
983 ff_formats_ref, ff_formats_unref);
984 }
985
986 ✗ int ff_set_common_chroma_locations_from_list(AVFilterContext *ctx,
987 const int *chroma_locations)
988 {
989 ✗ return ff_set_common_chroma_locations(ctx, ff_make_format_list(chroma_locations));
990 }
991
992 46717 int ff_set_common_all_chroma_locations(AVFilterContext *ctx)
993 {
994 46717 return ff_set_common_chroma_locations(ctx, ff_all_chroma_locations());
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.
1001 */
1002 46755 int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
1003 {
1004
15/20
✗ Branch 0 not taken.
✓ Branch 1 taken 46755 times.
✓ Branch 2 taken 38299 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15181 times.
✓ Branch 5 taken 23118 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15181 times.
✓ Branch 9 taken 38299 times.
✓ Branch 10 taken 46755 times.
✓ Branch 11 taken 38293 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7799 times.
✓ Branch 14 taken 30494 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 7799 times.
✓ Branch 18 taken 38293 times.
✓ Branch 19 taken 46755 times.
✓ Branch 20 taken 30457 times.
✓ Branch 21 taken 16298 times.
123347 SET_COMMON_FORMATS(ctx, formats, AVMEDIA_TYPE_UNKNOWN,
1005 ff_formats_ref, ff_formats_unref);
1006 }
1007
1008 ✗ int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
1009 {
1010 ✗ return ff_set_common_formats(ctx, ff_make_format_list(fmts));
1011 }
1012
1013 4 int ff_set_sample_formats_from_list(AVFilterContext *ctx, const enum AVSampleFormat *fmts)
1014 {
1015 4 return ff_set_common_formats(ctx, ff_make_sample_format_list(fmts));
1016 }
1017
1018 ✗ int ff_set_pixel_formats_from_list(AVFilterContext *ctx, const enum AVPixelFormat *fmts)
1019 {
1020 ✗ return ff_set_common_formats(ctx, ff_make_pixel_format_list(fmts));
1021 }
1022
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;
1055
1056 1759 int ff_set_common_channel_layouts2(const AVFilterContext *ctx,
1057 AVFilterFormatsConfig **cfg_in,
1058 AVFilterFormatsConfig **cfg_out,
1059 AVFilterChannelLayouts *channel_layouts)
1060 {
1061
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1759 times.
✓ Branch 2 taken 247 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 247 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 247 times.
✓ Branch 9 taken 247 times.
✓ Branch 10 taken 1759 times.
✓ Branch 11 taken 1759 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1759 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1759 times.
✓ Branch 18 taken 1759 times.
✓ Branch 19 taken 1759 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1759 times.
3765 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, channel_layouts, AVMEDIA_TYPE_AUDIO,
1062 ff_channel_layouts_ref, ff_channel_layouts_unref);
1063 }
1064
1065 356 int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx,
1066 AVFilterFormatsConfig **cfg_in,
1067 AVFilterFormatsConfig **cfg_out,
1068 const AVChannelLayout *fmts)
1069 {
1070 356 return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
1071 }
1072
1073 ✗ int ff_set_common_all_channel_counts2(const AVFilterContext *ctx,
1074 AVFilterFormatsConfig **cfg_in,
1075 AVFilterFormatsConfig **cfg_out)
1076 {
1077 ✗ return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
1078 }
1079
1080 1744 int ff_set_common_samplerates2(const AVFilterContext *ctx,
1081 AVFilterFormatsConfig **cfg_in,
1082 AVFilterFormatsConfig **cfg_out,
1083 AVFilterFormats *samplerates)
1084 {
1085
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1744 times.
✓ Branch 2 taken 232 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 232 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 232 times.
✓ Branch 9 taken 232 times.
✓ Branch 10 taken 1744 times.
✓ Branch 11 taken 1744 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1744 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1744 times.
✓ Branch 18 taken 1744 times.
✓ Branch 19 taken 1744 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1744 times.
3720 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, samplerates, AVMEDIA_TYPE_AUDIO,
1086 ff_formats_ref, ff_formats_unref);
1087 }
1088
1089 341 int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx,
1090 AVFilterFormatsConfig **cfg_in,
1091 AVFilterFormatsConfig **cfg_out,
1092 const int *samplerates)
1093 {
1094 341 return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_make_format_list(samplerates));
1095 }
1096
1097 ✗ int ff_set_common_all_samplerates2(const AVFilterContext *ctx,
1098 AVFilterFormatsConfig **cfg_in,
1099 AVFilterFormatsConfig **cfg_out)
1100 {
1101 ✗ return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1102 }
1103
1104 5127 int ff_set_common_color_spaces2(const AVFilterContext *ctx,
1105 AVFilterFormatsConfig **cfg_in,
1106 AVFilterFormatsConfig **cfg_out,
1107 AVFilterFormats *color_spaces)
1108 {
1109
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 5127 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 20 times.
✓ Branch 10 taken 5127 times.
✓ Branch 11 taken 5127 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 5127 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 5127 times.
✓ Branch 18 taken 5127 times.
✓ Branch 19 taken 5127 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 5127 times.
10274 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_spaces, AVMEDIA_TYPE_VIDEO,
1110 ff_formats_ref, ff_formats_unref);
1111 }
1112
1113 ✗ int ff_set_common_color_spaces_from_list2(const AVFilterContext *ctx,
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 }
1120
1121 ✗ int ff_set_common_all_color_spaces2(const AVFilterContext *ctx,
1122 AVFilterFormatsConfig **cfg_in,
1123 AVFilterFormatsConfig **cfg_out)
1124 {
1125 ✗ return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
1126 }
1127
1128 7325 int ff_set_common_color_ranges2(const AVFilterContext *ctx,
1129 AVFilterFormatsConfig **cfg_in,
1130 AVFilterFormatsConfig **cfg_out,
1131 AVFilterFormats *color_ranges)
1132 {
1133
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 7325 times.
✓ Branch 2 taken 2218 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2218 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2218 times.
✓ Branch 9 taken 2218 times.
✓ Branch 10 taken 7325 times.
✓ Branch 11 taken 7325 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7325 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 7325 times.
✓ Branch 18 taken 7325 times.
✓ Branch 19 taken 7325 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 7325 times.
16868 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_ranges, AVMEDIA_TYPE_VIDEO,
1134 ff_formats_ref, ff_formats_unref);
1135 }
1136
1137 ✗ int ff_set_common_color_ranges_from_list2(const AVFilterContext *ctx,
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 }
1144
1145 ✗ int ff_set_common_all_color_ranges2(const AVFilterContext *ctx,
1146 AVFilterFormatsConfig **cfg_in,
1147 AVFilterFormatsConfig **cfg_out)
1148 {
1149 ✗ return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1150 }
1151
1152 353 int ff_set_common_alpha_modes2(const AVFilterContext *ctx,
1153 AVFilterFormatsConfig **cfg_in,
1154 AVFilterFormatsConfig **cfg_out,
1155 AVFilterFormats *alpha_modes)
1156 {
1157
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 353 times.
✓ Branch 2 taken 39 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 39 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 39 times.
✓ Branch 9 taken 39 times.
✓ Branch 10 taken 353 times.
✓ Branch 11 taken 353 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 353 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 353 times.
✓ Branch 18 taken 353 times.
✓ Branch 19 taken 353 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 353 times.
745 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, alpha_modes, AVMEDIA_TYPE_VIDEO,
1158 ff_formats_ref, ff_formats_unref);
1159 }
1160
1161 ✗ int ff_set_common_alpha_modes_from_list2(const AVFilterContext *ctx,
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 }
1168
1169 ✗ int ff_set_common_all_alpha_modes2(const AVFilterContext *ctx,
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 }
1175
1176 1798 int ff_set_common_chroma_locations2(const AVFilterContext *ctx,
1177 AVFilterFormatsConfig **cfg_in,
1178 AVFilterFormatsConfig **cfg_out,
1179 AVFilterFormats *chroma_locations)
1180 {
1181
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1798 times.
✓ Branch 2 taken 719 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 719 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 719 times.
✓ Branch 9 taken 719 times.
✓ Branch 10 taken 1798 times.
✓ Branch 11 taken 1798 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1798 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1798 times.
✓ Branch 18 taken 1798 times.
✓ Branch 19 taken 1798 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1798 times.
4315 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, chroma_locations, AVMEDIA_TYPE_VIDEO,
1182 ff_formats_ref, ff_formats_unref);
1183 }
1184
1185 ✗ int ff_set_common_chroma_locations_from_list2(const AVFilterContext *ctx,
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 }
1193
1194 ✗ int ff_set_common_all_chroma_locations2(const AVFilterContext *ctx,
1195 AVFilterFormatsConfig **cfg_in,
1196 AVFilterFormatsConfig **cfg_out)
1197 {
1198 ✗ return ff_set_common_chroma_locations2(ctx, cfg_in, cfg_out, ff_all_chroma_locations());
1199 }
1200
1201 21874 int ff_set_common_formats2(const AVFilterContext *ctx,
1202 AVFilterFormatsConfig **cfg_in,
1203 AVFilterFormatsConfig **cfg_out,
1204 AVFilterFormats *formats)
1205 {
1206
12/16
✗ Branch 0 not taken.
✓ Branch 1 taken 21874 times.
✓ Branch 2 taken 14498 times.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 14498 times.
✓ Branch 7 taken 14502 times.
✓ Branch 8 taken 21874 times.
✓ Branch 9 taken 21902 times.
✓ Branch 10 taken 5 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 21902 times.
✓ Branch 14 taken 21907 times.
✓ Branch 15 taken 21874 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 21874 times.
58283 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, formats, AVMEDIA_TYPE_UNKNOWN,
1207 ff_formats_ref, ff_formats_unref);
1208 }
1209
1210 ✗ int ff_set_common_formats_from_list2(const AVFilterContext *ctx,
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 }
1217
1218 2033 int ff_set_sample_formats_from_list2(const AVFilterContext *ctx,
1219 AVFilterFormatsConfig **cfg_in,
1220 AVFilterFormatsConfig **cfg_out,
1221 const enum AVSampleFormat *fmts)
1222 {
1223 2033 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_sample_format_list(fmts));
1224 }
1225
1226 101 int ff_set_pixel_formats_from_list2(const AVFilterContext *ctx,
1227 AVFilterFormatsConfig **cfg_in,
1228 AVFilterFormatsConfig **cfg_out,
1229 const enum AVPixelFormat *fmts)
1230 {
1231 101 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_pixel_format_list(fmts));
1232 }
1233
1234 46751 int ff_default_query_formats(AVFilterContext *ctx)
1235 {
1236 46751 const FFFilter *const f = fffilter(ctx->filter);
1237 AVFilterFormats *formats;
1238 enum AVMediaType type;
1239 int ret;
1240
1241
5/5
✓ Branch 0 taken 1478 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 45205 times.
46751 switch (f->formats_state) {
1242 1478 case FF_FILTER_FORMATS_PIXFMT_LIST:
1243 1478 type = AVMEDIA_TYPE_VIDEO;
1244 1478 formats = ff_make_pixel_format_list(f->formats.pixels_list);
1245 1478 break;
1246 21 case FF_FILTER_FORMATS_SAMPLEFMTS_LIST:
1247 21 type = AVMEDIA_TYPE_AUDIO;
1248 21 formats = ff_make_sample_format_list(f->formats.samples_list);
1249 21 break;
1250 34 case FF_FILTER_FORMATS_SINGLE_PIXFMT:
1251 34 type = AVMEDIA_TYPE_VIDEO;
1252 34 formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1253 34 break;
1254 13 case FF_FILTER_FORMATS_SINGLE_SAMPLEFMT:
1255 13 type = AVMEDIA_TYPE_AUDIO;
1256 13 formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1257 13 break;
1258 45205 default:
1259 av_assert2(!"Unreachable");
1260 av_fallthrough;
1261 case FF_FILTER_FORMATS_PASSTHROUGH:
1262 case FF_FILTER_FORMATS_QUERY_FUNC:
1263 case FF_FILTER_FORMATS_QUERY_FUNC2:
1264 45205 type = AVMEDIA_TYPE_UNKNOWN;
1265
2/2
✓ Branch 0 taken 37718 times.
✓ Branch 1 taken 7487 times.
52692 formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1266
1/2
✓ Branch 0 taken 7487 times.
✗ Branch 1 not taken.
7487 ctx->nb_outputs ? ctx->outputs[0]->type :
1267 AVMEDIA_TYPE_VIDEO);
1268 45205 break;
1269 }
1270
1271 46751 ret = ff_set_common_formats(ctx, formats);
1272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46751 times.
46751 if (ret < 0)
1273 ✗ return ret;
1274
2/2
✓ Branch 0 taken 46717 times.
✓ Branch 1 taken 34 times.
46751 if (type != AVMEDIA_TYPE_AUDIO) {
1275 46717 ret = ff_set_common_all_color_spaces(ctx);
1276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
46717 if (ret < 0)
1277 ✗ return ret;
1278 46717 ret = ff_set_common_all_color_ranges(ctx);
1279
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
46717 if (ret < 0)
1280 ✗ return ret;
1281 46717 ret = ff_set_common_all_alpha_modes(ctx);
1282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
46717 if (ret < 0)
1283 ✗ return ret;
1284 46717 ret = ff_set_common_all_chroma_locations(ctx);
1285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46717 times.
46717 if (ret < 0)
1286 ✗ return ret;
1287 }
1288
2/2
✓ Branch 0 taken 45239 times.
✓ Branch 1 taken 1512 times.
46751 if (type != AVMEDIA_TYPE_VIDEO) {
1289 45239 ret = ff_set_common_all_channel_counts(ctx);
1290
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45239 times.
45239 if (ret < 0)
1291 ✗ return ret;
1292 45239 ret = ff_set_common_all_samplerates(ctx);
1293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45239 times.
45239 if (ret < 0)
1294 ✗ return ret;
1295 }
1296
1297 46751 return 0;
1298 }
1299
1300 271758 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1301 {
1302 unsigned i, j;
1303
1304
2/2
✓ Branch 0 taken 157021 times.
✓ Branch 1 taken 114737 times.
271758 if (!fmts)
1305 157021 return 0;
1306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114737 times.
114737 if (!fmts->nb_formats) {
1307 ✗ av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1308 ✗ return AVERROR(EINVAL);
1309 }
1310
2/2
✓ Branch 0 taken 3952438 times.
✓ Branch 1 taken 114737 times.
4067175 for (i = 0; i < fmts->nb_formats; i++) {
1311
2/2
✓ Branch 0 taken 395895798 times.
✓ Branch 1 taken 3952438 times.
399848236 for (j = i + 1; j < fmts->nb_formats; j++) {
1312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 395895798 times.
395895798 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 114737 return 0;
1319 }
1320
1321 51694 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1322 {
1323 51694 return check_list(log, "pixel format", fmts);
1324 }
1325
1326 10668 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1327 {
1328 10668 return check_list(log, "sample format", fmts);
1329 }
1330
1331 10668 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1332 {
1333
4/4
✓ Branch 0 taken 5373 times.
✓ Branch 1 taken 5295 times.
✓ Branch 2 taken 2753 times.
✓ Branch 3 taken 2620 times.
10668 if (!fmts || !fmts->nb_formats)
1334 8048 return 0;
1335 2620 return check_list(log, "sample rate", fmts);
1336 }
1337
1338 51694 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1339 {
1340
4/4
✓ Branch 0 taken 132897 times.
✓ Branch 1 taken 32912 times.
✓ Branch 2 taken 114115 times.
✓ Branch 3 taken 18782 times.
165809 for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 114115 times.
114115 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 51694 return check_list(log, "color space", fmts);
1347 }
1348
1349 51694 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1350 {
1351 51694 return check_list(log, "color range", fmts);
1352 }
1353
1354 51694 int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1355 {
1356 51694 return check_list(log, "alpha mode", fmts);
1357 }
1358
1359 51694 int ff_formats_check_chroma_locations(void *log, const AVFilterFormats *fmts)
1360 {
1361 51694 return check_list(log, "chroma location", fmts);
1362 }
1363
1364 5390 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1365 {
1366 5390 return !av_channel_layout_compare(a, b) ||
1367
3/12
✓ Branch 0 taken 5390 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5390 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5390 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
10780 (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1368
2/10
✗ Branch 0 not taken.
✓ Branch 1 taken 5390 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5390 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
5390 (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1369 }
1370
1371 10668 int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
1372 {
1373 unsigned i, j;
1374
1375
2/2
✓ Branch 0 taken 5010 times.
✓ Branch 1 taken 5658 times.
10668 if (!fmts)
1376 5010 return 0;
1377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5658 times.
5658 if (fmts->all_layouts < fmts->all_counts) {
1378 ✗ av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1379 ✗ return AVERROR(EINVAL);
1380 }
1381
3/4
✓ Branch 0 taken 2184 times.
✓ Branch 1 taken 3474 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2184 times.
5658 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
2/2
✓ Branch 0 taken 3320 times.
✓ Branch 1 taken 5658 times.
8978 for (i = 0; i < fmts->nb_channel_layouts; i++) {
1386
2/2
✓ Branch 0 taken 5390 times.
✓ Branch 1 taken 3320 times.
8710 for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1387
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5390 times.
5390 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 5658 return 0;
1394 }
1395