FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/formats.c
Date: 2025-10-10 03:51:19
Exec Total Coverage
Lines: 343 422 81.3%
Functions: 67 80 83.8%
Branches: 470 644 73.0%

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/avassert.h"
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "libavutil/mem.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "formats.h"
30
31 /**
32 * Add all refs from a to ret and destroy a.
33 */
34 #define MERGE_REF(ret, a, fmts, type, fail_statement) \
35 do { \
36 type ***tmp; \
37 int i; \
38 \
39 if (!(tmp = av_realloc_array(ret->refs, ret->refcount + a->refcount, \
40 sizeof(*tmp)))) \
41 { fail_statement } \
42 ret->refs = tmp; \
43 \
44 for (i = 0; i < a->refcount; i ++) { \
45 ret->refs[ret->refcount] = a->refs[i]; \
46 *ret->refs[ret->refcount++] = ret; \
47 } \
48 \
49 av_freep(&a->refs); \
50 av_freep(&a->fmts); \
51 av_freep(&a); \
52 } while (0)
53
54 /**
55 * Add all formats common to a and b to a, add b's refs to a and destroy b.
56 * If check is set, nothing is modified and it is only checked whether
57 * the formats are compatible.
58 * If empty_allowed is set and one of a,b->nb is zero, the lists are
59 * merged; otherwise, 0 (for nonmergeability) is returned.
60 */
61 #define MERGE_FORMATS(a, b, fmts, nb, type, check, empty_allowed) \
62 do { \
63 int i, j, k = 0, skip = 0; \
64 \
65 if (empty_allowed) { \
66 if (!a->nb || !b->nb) { \
67 if (check) \
68 return 1; \
69 if (!a->nb) \
70 FFSWAP(type *, a, b); \
71 skip = 1; \
72 } \
73 } \
74 if (!skip) { \
75 for (i = 0; i < a->nb; i++) \
76 for (j = 0; j < b->nb; j++) \
77 if (a->fmts[i] == b->fmts[j]) { \
78 if (check) \
79 return 1; \
80 a->fmts[k++] = a->fmts[i]; \
81 break; \
82 } \
83 /* Check that there was at least one common format. \
84 * Notice that both a and b are unchanged if not. */ \
85 if (!k) \
86 return 0; \
87 av_assert2(!check); \
88 a->nb = k; \
89 } \
90 \
91 MERGE_REF(a, b, fmts, type, return AVERROR(ENOMEM);); \
92 } while (0)
93
94 71645 static int merge_formats_internal(AVFilterFormats *a, AVFilterFormats *b,
95 enum AVMediaType type, int check)
96 {
97 int i, j;
98 71645 int alpha1=0, alpha2=0;
99 71645 int chroma1=0, chroma2=0;
100
101 av_assert2(check || (a->refcount && b->refcount));
102
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71645 times.
71645 if (a == b)
104 return 1;
105
106 /* Do not lose chroma or alpha in merging.
107 It happens if both lists have formats with chroma (resp. alpha), but
108 the only formats in common do not have it (e.g. YUV+gray vs.
109 RGB+gray): in that case, the merging would select the gray format,
110 possibly causing a lossy conversion elsewhere in the graph.
111 To avoid that, pretend that there are no common formats to force the
112 insertion of a conversion filter. */
113
2/2
✓ Branch 0 taken 60426 times.
✓ Branch 1 taken 11219 times.
71645 if (type == AVMEDIA_TYPE_VIDEO)
114
2/2
✓ Branch 0 taken 3313946 times.
✓ Branch 1 taken 60426 times.
3374372 for (i = 0; i < a->nb_formats; i++) {
115 3313946 const AVPixFmtDescriptor *const adesc = av_pix_fmt_desc_get(a->formats[i]);
116
2/2
✓ Branch 0 taken 189698821 times.
✓ Branch 1 taken 3313946 times.
193012767 for (j = 0; j < b->nb_formats; j++) {
117 189698821 const AVPixFmtDescriptor *bdesc = av_pix_fmt_desc_get(b->formats[j]);
118 189698821 alpha2 |= adesc->flags & bdesc->flags & AV_PIX_FMT_FLAG_ALPHA;
119
4/4
✓ Branch 0 taken 165555484 times.
✓ Branch 1 taken 24143337 times.
✓ Branch 2 taken 143708103 times.
✓ Branch 3 taken 21847381 times.
189698821 chroma2|= adesc->nb_components > 1 && bdesc->nb_components > 1;
120
2/2
✓ Branch 0 taken 727012 times.
✓ Branch 1 taken 188971809 times.
189698821 if (a->formats[i] == b->formats[j]) {
121 727012 alpha1 |= adesc->flags & AV_PIX_FMT_FLAG_ALPHA;
122 727012 chroma1|= adesc->nb_components > 1;
123 }
124 }
125 }
126
127 // If chroma or alpha can be lost through merging then do not merge
128
4/4
✓ Branch 0 taken 71624 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 553 times.
✓ Branch 3 taken 71071 times.
71645 if (alpha2 > alpha1 || chroma2 > chroma1)
129 574 return 0;
130
131
14/16
✓ Branch 0 taken 71071 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 407562 times.
✓ Branch 3 taken 48191714 times.
✓ Branch 4 taken 33944 times.
✓ Branch 5 taken 373618 times.
✓ Branch 6 taken 48599276 times.
✓ Branch 7 taken 1919890 times.
✓ Branch 8 taken 2327452 times.
✓ Branch 9 taken 37127 times.
✓ Branch 10 taken 678 times.
✓ Branch 11 taken 36449 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 36449 times.
✓ Branch 15 taken 81044 times.
✓ Branch 16 taken 36449 times.
50637337 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
132
133 36449 return 1;
134 }
135
136
137 /**
138 * Check the formats lists for compatibility for merging without actually
139 * merging.
140 *
141 * @return 1 if they are compatible, 0 if not.
142 */
143 29902 static int can_merge_pix_fmts(const void *a, const void *b)
144 {
145 29902 return merge_formats_internal((AVFilterFormats *)a,
146 (AVFilterFormats *)b, AVMEDIA_TYPE_VIDEO, 1);
147 }
148
149 /**
150 * Merge the formats lists if they are compatible and update all the
151 * references of a and b to point to the combined list and free the old
152 * lists as needed. The combined list usually contains the intersection of
153 * the lists of a and b.
154 *
155 * Both a and b must have owners (i.e. refcount > 0) for these functions.
156 *
157 * @return 1 if merging succeeded, 0 if a and b are incompatible
158 * and negative AVERROR code on failure.
159 * a and b are unmodified if 0 is returned.
160 */
161 30524 static int merge_pix_fmts(void *a, void *b)
162 {
163 30524 return merge_formats_internal(a, b, AVMEDIA_TYPE_VIDEO, 0);
164 }
165
166 /**
167 * See can_merge_pix_fmts().
168 */
169 5294 static int can_merge_sample_fmts(const void *a, const void *b)
170 {
171 5294 return merge_formats_internal((AVFilterFormats *)a,
172 (AVFilterFormats *)b, AVMEDIA_TYPE_AUDIO, 1);
173 }
174
175 /**
176 * See merge_pix_fmts().
177 */
178 5925 static int merge_sample_fmts(void *a, void *b)
179 {
180 5925 return merge_formats_internal(a, b, AVMEDIA_TYPE_AUDIO, 0);
181 }
182
183 11219 static int merge_samplerates_internal(AVFilterFormats *a,
184 AVFilterFormats *b, int check)
185 {
186 av_assert2(check || (a->refcount && b->refcount));
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11219 times.
11219 if (a == b) return 1;
188
189
23/24
✓ Branch 0 taken 7102 times.
✓ Branch 1 taken 4117 times.
✓ Branch 2 taken 6973 times.
✓ Branch 3 taken 129 times.
✓ Branch 4 taken 5214 times.
✓ Branch 5 taken 5876 times.
✓ Branch 6 taken 2374 times.
✓ Branch 7 taken 3502 times.
✓ Branch 8 taken 129 times.
✓ Branch 9 taken 5876 times.
✓ Branch 10 taken 123 times.
✓ Branch 11 taken 48 times.
✓ Branch 12 taken 74 times.
✓ Branch 13 taken 49 times.
✓ Branch 14 taken 171 times.
✓ Branch 15 taken 6 times.
✓ Branch 16 taken 129 times.
✓ Branch 17 taken 55 times.
✓ Branch 18 taken 6 times.
✓ Branch 19 taken 49 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 5925 times.
✓ Branch 23 taken 26413 times.
✓ Branch 24 taken 5925 times.
37735 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 1);
190 5925 return 1;
191 }
192
193 /**
194 * See can_merge_pix_fmts().
195 */
196 5294 static int can_merge_samplerates(const void *a, const void *b)
197 {
198 5294 return merge_samplerates_internal((AVFilterFormats *)a, (AVFilterFormats *)b, 1);
199 }
200
201 /**
202 * See merge_pix_fmts().
203 */
204 5925 static int merge_samplerates(void *a, void *b)
205 {
206 5925 return merge_samplerates_internal(a, b, 0);
207 }
208
209 /**
210 * See merge_pix_fmts().
211 */
212 6621 static int merge_channel_layouts_internal(AVFilterChannelLayouts *a,
213 AVFilterChannelLayouts *b, int check)
214 {
215 6621 AVChannelLayout *channel_layouts = NULL;
216 6621 unsigned a_all = a->all_layouts + a->all_counts;
217 6621 unsigned b_all = b->all_layouts + b->all_counts;
218 6621 int ret_max, ret_nb = 0, i, j, round;
219
220 av_assert2(a->refcount && b->refcount);
221
222
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6621 times.
6621 if (a == b) return 1;
223
224 /* Put the most generic set in a, to avoid doing everything twice */
225
2/2
✓ Branch 0 taken 3333 times.
✓ Branch 1 taken 3288 times.
6621 if (a_all < b_all) {
226 3333 FFSWAP(AVFilterChannelLayouts *, a, b);
227 3333 FFSWAP(unsigned, a_all, b_all);
228 }
229
2/2
✓ Branch 0 taken 6440 times.
✓ Branch 1 taken 181 times.
6621 if (a_all) {
230
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 6370 times.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
6440 if (a_all == 1 && !b_all) {
231 /* keep only known layouts in b; works also for b_all = 1 */
232
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 70 times.
140 for (i = j = 0; i < b->nb_channel_layouts; i++)
233
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++) {
234 if (check)
235 return 1;
236 av_channel_layout_copy(&b->channel_layouts[j], &b->channel_layouts[i]);
237 }
238 /* Not optimal: the unknown layouts of b may become known after
239 another merge. */
240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!j)
241 return 0;
242 70 b->nb_channel_layouts = j;
243 }
244
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 6440 times.
✓ Branch 3 taken 11120 times.
✓ Branch 4 taken 6440 times.
17560 MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts, return AVERROR(ENOMEM););
245 6440 return 1;
246 }
247
248 181 ret_max = a->nb_channel_layouts + b->nb_channel_layouts;
249
3/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 116 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 65 times.
181 if (!check && !(channel_layouts = av_calloc(ret_max, sizeof(*channel_layouts))))
250 return AVERROR(ENOMEM);
251
252 /* a[known] intersect b[known] */
253
2/2
✓ Branch 0 taken 181 times.
✓ Branch 1 taken 73 times.
254 for (i = 0; i < a->nb_channel_layouts; i++) {
254
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 180 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
181 if (!KNOWN(&a->channel_layouts[i]))
255 1 continue;
256
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 7 times.
283 for (j = 0; j < b->nb_channel_layouts; j++) {
257
2/2
✓ Branch 1 taken 173 times.
✓ Branch 2 taken 103 times.
276 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
258
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 65 times.
173 if (check)
259 108 return 1;
260 65 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
261 65 av_channel_layout_uninit(&a->channel_layouts[i]);
262 65 av_channel_layout_uninit(&b->channel_layouts[j]);
263 65 break;
264 }
265 }
266 }
267 /* 1st round: a[known] intersect b[generic]
268 2nd round: a[generic] intersect b[known] */
269
2/2
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 72 times.
218 for (round = 0; round < 2; round++) {
270
2/2
✓ Branch 0 taken 232 times.
✓ Branch 1 taken 145 times.
377 for (i = 0; i < a->nb_channel_layouts; i++) {
271 232 AVChannelLayout *fmt = &a->channel_layouts[i], bfmt = { 0 };
272
5/6
✓ Branch 1 taken 102 times.
✓ Branch 2 taken 130 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 101 times.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
232 if (!av_channel_layout_check(fmt) || !KNOWN(fmt))
273 131 continue;
274 101 bfmt = FF_COUNT2LAYOUT(fmt->nb_channels);
275
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 100 times.
201 for (j = 0; j < b->nb_channel_layouts; j++)
276
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 100 times.
101 if (!av_channel_layout_compare(&b->channel_layouts[j], &bfmt)) {
277
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (check)
278 1 return 1;
279 av_channel_layout_copy(&channel_layouts[ret_nb++], fmt);
280 }
281 }
282 /* 1st round: swap to prepare 2nd round; 2nd round: put it back */
283 145 FFSWAP(AVFilterChannelLayouts *, a, b);
284 }
285 /* a[generic] intersect b[generic] */
286
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 72 times.
144 for (i = 0; i < a->nb_channel_layouts; i++) {
287
3/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 65 times.
✗ Branch 3 not taken.
72 if (KNOWN(&a->channel_layouts[i]))
288 72 continue;
289 for (j = 0; j < b->nb_channel_layouts; j++)
290 if (!av_channel_layout_compare(&a->channel_layouts[i], &b->channel_layouts[j])) {
291 if (check)
292 return 1;
293 av_channel_layout_copy(&channel_layouts[ret_nb++], &a->channel_layouts[i]);
294 }
295 }
296
297
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 65 times.
72 if (!ret_nb) {
298 7 av_free(channel_layouts);
299 7 return 0;
300 }
301
302
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 53 times.
65 if (a->refcount > b->refcount)
303 12 FFSWAP(AVFilterChannelLayouts *, a, b);
304
305
3/4
✗ Branch 1 not taken.
✓ Branch 2 taken 65 times.
✓ Branch 4 taken 131 times.
✓ Branch 5 taken 65 times.
196 MERGE_REF(b, a, channel_layouts, AVFilterChannelLayouts,
306 { av_free(channel_layouts); return AVERROR(ENOMEM); });
307 65 av_freep(&b->channel_layouts);
308 65 b->channel_layouts = channel_layouts;
309 65 b->nb_channel_layouts = ret_nb;
310 65 return 1;
311 }
312
313 5294 static int can_merge_channel_layouts(const void *a, const void *b)
314 {
315 5294 return merge_channel_layouts_internal((AVFilterChannelLayouts *)a,
316 (AVFilterChannelLayouts *)b, 1);
317 }
318
319 1327 static int merge_channel_layouts(void *a, void *b)
320 {
321 1327 return merge_channel_layouts_internal(a, b, 0);
322 }
323
324 181269 static int merge_generic_internal(AVFilterFormats *a,
325 AVFilterFormats *b, int check)
326 {
327 av_assert2(check || (a->refcount && b->refcount));
328
329
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 181269 times.
181269 if (a == b)
330 return 1;
331
332
14/16
✓ Branch 0 taken 181269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 510732 times.
✓ Branch 3 taken 1768972 times.
✓ Branch 4 taken 90258 times.
✓ Branch 5 taken 420474 times.
✓ Branch 6 taken 2279704 times.
✓ Branch 7 taken 19156 times.
✓ Branch 8 taken 529888 times.
✓ Branch 9 taken 91011 times.
✓ Branch 10 taken 64 times.
✓ Branch 11 taken 90947 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 90947 times.
✓ Branch 15 taken 167739 times.
✓ Branch 16 taken 90947 times.
2557610 MERGE_FORMATS(a, b, formats, nb_formats, AVFilterFormats, check, 0);
333
334 90947 return 1;
335 }
336
337 90322 static int can_merge_generic(const void *a, const void *b)
338 {
339 90322 return merge_generic_internal((AVFilterFormats *)a,
340 (AVFilterFormats *)b, 1);
341 }
342
343 90947 static int merge_generic(void *a, void *b)
344 {
345 90947 return merge_generic_internal(a, b, 0);
346 }
347
348 #define CONVERSION_FILTER_SWSCALE \
349 .conversion_filter = "scale", \
350 .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts),
351
352 #define CONVERSION_FILTER_ARESAMPLE \
353 .conversion_filter = "aresample", \
354 .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts),
355
356 static const AVFilterFormatsMerger mergers_video[] = {
357 {
358 .offset = offsetof(AVFilterFormatsConfig, formats),
359 .merge = merge_pix_fmts,
360 .can_merge = can_merge_pix_fmts,
361 CONVERSION_FILTER_SWSCALE
362 },
363 {
364 .offset = offsetof(AVFilterFormatsConfig, color_spaces),
365 .merge = merge_generic,
366 .can_merge = can_merge_generic,
367 CONVERSION_FILTER_SWSCALE
368 },
369 {
370 .offset = offsetof(AVFilterFormatsConfig, color_ranges),
371 .merge = merge_generic,
372 .can_merge = can_merge_generic,
373 CONVERSION_FILTER_SWSCALE
374 },
375 {
376 .offset = offsetof(AVFilterFormatsConfig, alpha_modes),
377 .merge = merge_generic,
378 .can_merge = can_merge_generic,
379 .conversion_filter = "premultiply_dynamic",
380 },
381 };
382
383 static const AVFilterFormatsMerger mergers_audio[] = {
384 {
385 .offset = offsetof(AVFilterFormatsConfig, channel_layouts),
386 .merge = merge_channel_layouts,
387 .can_merge = can_merge_channel_layouts,
388 CONVERSION_FILTER_ARESAMPLE
389 },
390 {
391 .offset = offsetof(AVFilterFormatsConfig, samplerates),
392 .merge = merge_samplerates,
393 .can_merge = can_merge_samplerates,
394 CONVERSION_FILTER_ARESAMPLE
395 },
396 {
397 .offset = offsetof(AVFilterFormatsConfig, formats),
398 .merge = merge_sample_fmts,
399 .can_merge = can_merge_sample_fmts,
400 CONVERSION_FILTER_ARESAMPLE
401 },
402 };
403
404 static const AVFilterNegotiation negotiate_video = {
405 .nb_mergers = FF_ARRAY_ELEMS(mergers_video),
406 .mergers = mergers_video,
407 };
408
409 static const AVFilterNegotiation negotiate_audio = {
410 .nb_mergers = FF_ARRAY_ELEMS(mergers_audio),
411 .mergers = mergers_audio,
412 };
413
414 36500 const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link)
415 {
416
2/3
✓ Branch 0 taken 30571 times.
✓ Branch 1 taken 5929 times.
✗ Branch 2 not taken.
36500 switch (link->type) {
417 30571 case AVMEDIA_TYPE_VIDEO: return &negotiate_video;
418 5929 case AVMEDIA_TYPE_AUDIO: return &negotiate_audio;
419 default: return NULL;
420 }
421 }
422
423 194 int ff_fmt_is_in(int fmt, const int *fmts)
424 {
425 const int *p;
426
427
2/2
✓ Branch 0 taken 2185 times.
✓ Branch 1 taken 107 times.
2292 for (p = fmts; *p != -1; p++) {
428
2/2
✓ Branch 0 taken 87 times.
✓ Branch 1 taken 2098 times.
2185 if (fmt == *p)
429 87 return 1;
430 }
431 107 return 0;
432 }
433
434 #define MAKE_FORMAT_LIST(type, field, count_field) \
435 type *formats; \
436 int count = 0; \
437 if (fmts) \
438 for (count = 0; fmts[count] != -1; count++) \
439 ; \
440 formats = av_mallocz(sizeof(*formats)); \
441 if (!formats) \
442 return NULL; \
443 formats->count_field = count; \
444 if (count) { \
445 formats->field = av_malloc_array(count, sizeof(*formats->field)); \
446 if (!formats->field) { \
447 av_freep(&formats); \
448 return NULL; \
449 } \
450 }
451
452 4367 AVFilterFormats *ff_make_format_list(const int *fmts)
453 {
454
6/10
✓ Branch 0 taken 4367 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46939 times.
✓ Branch 3 taken 4367 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4367 times.
✓ Branch 7 taken 4367 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 4367 times.
51306 MAKE_FORMAT_LIST(AVFilterFormats, formats, nb_formats);
455
2/2
✓ Branch 0 taken 46939 times.
✓ Branch 1 taken 4367 times.
51306 while (count--)
456 46939 formats->formats[count] = fmts[count];
457
458 4367 return formats;
459 }
460
461 214 AVFilterChannelLayouts *ff_make_channel_layout_list(const AVChannelLayout *fmts)
462 {
463 AVFilterChannelLayouts *ch_layouts;
464 214 int count = 0;
465
1/2
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
214 if (fmts)
466
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 214 times.
752 for (count = 0; fmts[count].nb_channels; count++)
467 ;
468 214 ch_layouts = av_mallocz(sizeof(*ch_layouts));
469
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
214 if (!ch_layouts)
470 return NULL;
471 214 ch_layouts->nb_channel_layouts = count;
472
1/2
✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
214 if (count) {
473 428 ch_layouts->channel_layouts =
474 214 av_calloc(count, sizeof(*ch_layouts->channel_layouts));
475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 214 times.
214 if (!ch_layouts->channel_layouts) {
476 av_freep(&ch_layouts);
477 return NULL;
478 }
479
2/2
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 214 times.
752 for (int i = 0; i < count; i++) {
480 538 int ret = av_channel_layout_copy(&ch_layouts->channel_layouts[i], &fmts[i]);
481
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 538 times.
538 if (ret < 0)
482 goto fail;
483 }
484 }
485
486 214 return ch_layouts;
487
488 fail:
489 for (int i = 0; i < count; i++)
490 av_channel_layout_uninit(&ch_layouts->channel_layouts[i]);
491 av_free(ch_layouts->channel_layouts);
492 av_freep(&ch_layouts);
493
494 return NULL;
495 }
496
497 #define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
498 do { \
499 type *fmts; \
500 \
501 if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
502 return AVERROR(ENOMEM); \
503 } \
504 \
505 fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
506 sizeof(*(*f)->list)); \
507 if (!fmts) { \
508 unref_fn(f); \
509 return AVERROR(ENOMEM); \
510 } \
511 \
512 (*f)->list = fmts; \
513 ASSIGN_FMT(f, fmt, list, nb); \
514 } while (0)
515
516 #define ASSIGN_FMT(f, fmt, list, nb) \
517 do { \
518 (*f)->list[(*f)->nb++] = fmt; \
519 } while (0)
520
521 4453731 int ff_add_format(AVFilterFormats **avff, int64_t fmt)
522 {
523
4/6
✓ Branch 0 taken 220503 times.
✓ Branch 1 taken 4233228 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 220503 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 4453731 times.
4453731 ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
524 4453731 return 0;
525 }
526
527 #undef ASSIGN_FMT
528 #define ASSIGN_FMT(f, fmt, list, nb) \
529 do { \
530 int ret; \
531 memset((*f)->list + (*f)->nb, 0, sizeof(*(*f)->list)); \
532 ret = av_channel_layout_copy(&(*f)->list[(*f)->nb], fmt); \
533 if (ret < 0) \
534 return ret; \
535 (*f)->nb++; \
536 } while (0)
537
538 2271 int ff_add_channel_layout(AVFilterChannelLayouts **l,
539 const AVChannelLayout *channel_layout)
540 {
541 av_assert1(!(*l && (*l)->all_layouts));
542
5/8
✓ Branch 0 taken 1427 times.
✓ Branch 1 taken 844 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1427 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2271 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2271 times.
2271 ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, AVChannelLayout, channel_layouts, nb_channel_layouts);
543 2271 return 0;
544 }
545
546 70 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
547 {
548 70 int fmts[2] = { fmt, -1 };
549 70 return ff_make_format_list(fmts);
550 }
551
552 46105 AVFilterFormats *ff_all_formats(enum AVMediaType type)
553 {
554 46105 AVFilterFormats *ret = NULL;
555
556
2/2
✓ Branch 0 taken 35943 times.
✓ Branch 1 taken 10162 times.
46105 if (type == AVMEDIA_TYPE_VIDEO) {
557 35943 return ff_formats_pixdesc_filter(0, 0);
558
1/2
✓ Branch 0 taken 10162 times.
✗ Branch 1 not taken.
10162 } else if (type == AVMEDIA_TYPE_AUDIO) {
559 10162 enum AVSampleFormat fmt = 0;
560
2/2
✓ Branch 1 taken 121944 times.
✓ Branch 2 taken 10162 times.
132106 while (av_get_sample_fmt_name(fmt)) {
561
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 121944 times.
121944 if (ff_add_format(&ret, fmt) < 0)
562 return NULL;
563 121944 fmt++;
564 }
565 }
566
567 10162 return ret;
568 }
569
570 36588 AVFilterFormats *ff_formats_pixdesc_filter(unsigned want, unsigned rej)
571 {
572 unsigned nb_formats, fmt, flags;
573 36588 AVFilterFormats *formats = NULL;
574
575 while (1) {
576 73176 nb_formats = 0;
577 19611168 for (fmt = 0;; fmt++) {
578 19611168 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
579
2/2
✓ Branch 0 taken 73176 times.
✓ Branch 1 taken 19537992 times.
19611168 if (!desc)
580 73176 break;
581 19537992 flags = desc->flags;
582
2/2
✓ Branch 0 taken 18367176 times.
✓ Branch 1 taken 1170816 times.
19537992 if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
583
2/2
✓ Branch 0 taken 8634768 times.
✓ Branch 1 taken 9732408 times.
18367176 !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
584
3/4
✓ Branch 0 taken 7903008 times.
✓ Branch 1 taken 731760 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7903008 times.
8634768 (desc->log2_chroma_w || desc->log2_chroma_h))
585 731760 flags |= FF_PIX_FMT_FLAG_SW_FLAT_SUB;
586
2/2
✓ Branch 0 taken 21420 times.
✓ Branch 1 taken 19516572 times.
19537992 if ((flags & (want | rej)) != want)
587 21420 continue;
588
2/2
✓ Branch 0 taken 9758286 times.
✓ Branch 1 taken 9758286 times.
19516572 if (formats)
589 9758286 formats->formats[nb_formats] = fmt;
590 19516572 nb_formats++;
591 }
592
2/2
✓ Branch 0 taken 36588 times.
✓ Branch 1 taken 36588 times.
73176 if (formats) {
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36588 times.
36588 av_assert0(formats->nb_formats == nb_formats);
594 36588 return formats;
595 }
596 36588 formats = av_mallocz(sizeof(*formats));
597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36588 times.
36588 if (!formats)
598 return NULL;
599 36588 formats->nb_formats = nb_formats;
600
1/2
✓ Branch 0 taken 36588 times.
✗ Branch 1 not taken.
36588 if (nb_formats) {
601 36588 formats->formats = av_malloc_array(nb_formats, sizeof(*formats->formats));
602
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36588 times.
36588 if (!formats->formats) {
603 av_freep(&formats);
604 return NULL;
605 }
606 }
607 }
608 }
609
610 61 AVFilterFormats *ff_planar_sample_fmts(void)
611 {
612 61 AVFilterFormats *ret = NULL;
613 int fmt;
614
615
2/2
✓ Branch 1 taken 732 times.
✓ Branch 2 taken 61 times.
793 for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
616
2/2
✓ Branch 1 taken 366 times.
✓ Branch 2 taken 366 times.
732 if (av_sample_fmt_is_planar(fmt))
617
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 366 times.
366 if (ff_add_format(&ret, fmt) < 0)
618 return NULL;
619
620 61 return ret;
621 }
622
623 45496 AVFilterFormats *ff_all_samplerates(void)
624 {
625 45496 AVFilterFormats *ret = av_mallocz(sizeof(*ret));
626 45496 return ret;
627 }
628
629 70 AVFilterChannelLayouts *ff_all_channel_layouts(void)
630 {
631 70 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
70 if (!ret)
633 return NULL;
634 70 ret->all_layouts = 1;
635 70 return ret;
636 }
637
638 46157 AVFilterChannelLayouts *ff_all_channel_counts(void)
639 {
640 46157 AVFilterChannelLayouts *ret = av_mallocz(sizeof(*ret));
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46157 times.
46157 if (!ret)
642 return NULL;
643 46157 ret->all_layouts = ret->all_counts = 1;
644 46157 return ret;
645 }
646
647 57688 AVFilterFormats *ff_all_color_spaces(void)
648 {
649 57688 AVFilterFormats *ret = NULL;
650
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 57688 times.
57688 if (ff_add_format(&ret, AVCOL_SPC_UNSPECIFIED) < 0)
651 return NULL;
652
2/2
✓ Branch 0 taken 1038384 times.
✓ Branch 1 taken 57688 times.
1096072 for (int csp = 0; csp < AVCOL_SPC_NB; csp++) {
653
4/4
✓ Branch 0 taken 980696 times.
✓ Branch 1 taken 57688 times.
✓ Branch 2 taken 57688 times.
✓ Branch 3 taken 923008 times.
1038384 if (csp == AVCOL_SPC_RESERVED ||
654 csp == AVCOL_SPC_UNSPECIFIED)
655 115376 continue;
656
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 923008 times.
923008 if (ff_add_format(&ret, csp) < 0)
657 return NULL;
658 }
659
660 57688 return ret;
661 }
662
663 57688 AVFilterFormats *ff_all_color_ranges(void)
664 {
665 57688 AVFilterFormats *ret = NULL;
666
2/2
✓ Branch 0 taken 173064 times.
✓ Branch 1 taken 57688 times.
230752 for (int range = 0; range < AVCOL_RANGE_NB; range++) {
667
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 173064 times.
173064 if (ff_add_format(&ret, range) < 0)
668 return NULL;
669 }
670
671 57688 return ret;
672 }
673
674 44562 AVFilterFormats *ff_all_alpha_modes(void)
675 {
676 44562 AVFilterFormats *ret = NULL;
677
2/2
✓ Branch 0 taken 133686 times.
✓ Branch 1 taken 44562 times.
178248 for (int range = 0; range < AVALPHA_MODE_NB; range++) {
678
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 133686 times.
133686 if (ff_add_format(&ret, range) < 0)
679 return NULL;
680 }
681
682 44562 return ret;
683 }
684
685 #define FORMATS_REF(f, ref, unref_fn) \
686 void *tmp; \
687 \
688 if (!f) \
689 return AVERROR(ENOMEM); \
690 \
691 tmp = av_realloc_array(f->refs, f->refcount + 1, sizeof(*f->refs)); \
692 if (!tmp) { \
693 unref_fn(&f); \
694 return AVERROR(ENOMEM); \
695 } \
696 f->refs = tmp; \
697 f->refs[f->refcount++] = ref; \
698 *ref = f; \
699 return 0
700
701 11850 int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
702 {
703
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11850 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11850 times.
11850 FORMATS_REF(f, ref, ff_channel_layouts_unref);
704 }
705
706 286102 int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
707 {
708
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 286102 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 286102 times.
286102 FORMATS_REF(f, ref, ff_formats_unref);
709 }
710
711 #define FIND_REF_INDEX(ref, idx) \
712 do { \
713 int i; \
714 for (i = 0; i < (*ref)->refcount; i ++) \
715 if((*ref)->refs[i] == ref) { \
716 idx = i; \
717 break; \
718 } \
719 } while (0)
720
721 #define FORMATS_UNREF(ref, list) \
722 do { \
723 int idx = -1; \
724 \
725 if (!*ref) \
726 return; \
727 \
728 FIND_REF_INDEX(ref, idx); \
729 \
730 if (idx >= 0) { \
731 memmove((*ref)->refs + idx, (*ref)->refs + idx + 1, \
732 sizeof(*(*ref)->refs) * ((*ref)->refcount - idx - 1)); \
733 --(*ref)->refcount; \
734 } \
735 if (!(*ref)->refcount) { \
736 FREE_LIST(ref, list); \
737 av_free((*ref)->list); \
738 av_free((*ref)->refs); \
739 av_free(*ref); \
740 } \
741 *ref = NULL; \
742 } while (0)
743
744 #define FREE_LIST(ref, list) do { } while(0)
745 1009932 void ff_formats_unref(AVFilterFormats **ref)
746 {
747
10/10
✓ Branch 0 taken 608680 times.
✓ Branch 1 taken 401252 times.
✓ Branch 2 taken 286102 times.
✓ Branch 3 taken 144215 times.
✓ Branch 4 taken 430317 times.
✓ Branch 5 taken 115150 times.
✓ Branch 6 taken 286102 times.
✓ Branch 7 taken 115150 times.
✓ Branch 8 taken 173633 times.
✓ Branch 9 taken 227619 times.
1154147 FORMATS_UNREF(ref, formats);
748 }
749
750 #undef FREE_LIST
751 #define FREE_LIST(ref, list) \
752 do { \
753 for (int i = 0; i < (*ref)->nb_channel_layouts; i++) \
754 av_channel_layout_uninit(&(*ref)->list[i]); \
755 } while(0)
756
757 205409 void ff_channel_layouts_unref(AVFilterChannelLayouts **ref)
758 {
759
12/12
✓ Branch 0 taken 154616 times.
✓ Branch 1 taken 50793 times.
✓ Branch 2 taken 11850 times.
✓ Branch 3 taken 8911 times.
✓ Branch 4 taken 20761 times.
✓ Branch 5 taken 38943 times.
✓ Branch 6 taken 11850 times.
✓ Branch 7 taken 38943 times.
✓ Branch 8 taken 41363 times.
✓ Branch 9 taken 9430 times.
✓ Branch 11 taken 2420 times.
✓ Branch 12 taken 41363 times.
216740 FORMATS_UNREF(ref, channel_layouts);
760 }
761
762 #define FORMATS_CHANGEREF(oldref, newref) \
763 do { \
764 int idx = -1; \
765 \
766 FIND_REF_INDEX(oldref, idx); \
767 \
768 if (idx >= 0) { \
769 (*oldref)->refs[idx] = newref; \
770 *newref = *oldref; \
771 *oldref = NULL; \
772 } \
773 } while (0)
774
775 631 void ff_channel_layouts_changeref(AVFilterChannelLayouts **oldref,
776 AVFilterChannelLayouts **newref)
777 {
778
4/6
✓ Branch 0 taken 631 times.
✓ Branch 1 taken 1641 times.
✓ Branch 2 taken 2272 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 631 times.
✗ Branch 5 not taken.
2272 FORMATS_CHANGEREF(oldref, newref);
779 631 }
780
781 3750 void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
782 {
783
4/6
✓ Branch 0 taken 3750 times.
✓ Branch 1 taken 8054 times.
✓ Branch 2 taken 11804 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3750 times.
✗ Branch 5 not taken.
11804 FORMATS_CHANGEREF(oldref, newref);
784 3750 }
785
786 #define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
787 int i; \
788 \
789 if (!fmts) \
790 return AVERROR(ENOMEM); \
791 \
792 for (i = 0; i < ctx->nb_inputs; i++) { \
793 AVFilterLink *const link = ctx->inputs[i]; \
794 if (link && !link->outcfg.fmts && \
795 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
796 int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts); \
797 if (ret < 0) { \
798 return ret; \
799 } \
800 } \
801 } \
802 for (i = 0; i < ctx->nb_outputs; i++) { \
803 AVFilterLink *const link = ctx->outputs[i]; \
804 if (link && !link->incfg.fmts && \
805 (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
806 int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts); \
807 if (ret < 0) { \
808 return ret; \
809 } \
810 } \
811 } \
812 \
813 if (!fmts->refcount) \
814 unref_fn(&fmts); \
815 \
816 return 0;
817
818 43152 int ff_set_common_channel_layouts(AVFilterContext *ctx,
819 AVFilterChannelLayouts *channel_layouts)
820 {
821
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 43152 times.
✓ Branch 2 taken 36105 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34398 times.
✓ Branch 5 taken 1707 times.
✓ Branch 6 taken 4218 times.
✓ Branch 7 taken 30180 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4218 times.
✓ Branch 11 taken 36105 times.
✓ Branch 12 taken 43152 times.
✓ Branch 13 taken 35020 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 31891 times.
✓ Branch 16 taken 3129 times.
✓ Branch 17 taken 2796 times.
✓ Branch 18 taken 29095 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 2796 times.
✓ Branch 22 taken 35020 times.
✓ Branch 23 taken 43152 times.
✓ Branch 24 taken 38943 times.
✓ Branch 25 taken 4209 times.
114277 SET_COMMON_FORMATS(ctx, channel_layouts, AVMEDIA_TYPE_AUDIO,
822 ff_channel_layouts_ref, ff_channel_layouts_unref);
823 }
824
825 int ff_set_common_channel_layouts_from_list(AVFilterContext *ctx,
826 const AVChannelLayout *fmts)
827 {
828 return ff_set_common_channel_layouts(ctx, ff_make_channel_layout_list(fmts));
829 }
830
831 43152 int ff_set_common_all_channel_counts(AVFilterContext *ctx)
832 {
833 43152 return ff_set_common_channel_layouts(ctx, ff_all_channel_counts());
834 }
835
836 43153 int ff_set_common_samplerates(AVFilterContext *ctx,
837 AVFilterFormats *samplerates)
838 {
839
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 43153 times.
✓ Branch 2 taken 36107 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 34522 times.
✓ Branch 5 taken 1585 times.
✓ Branch 6 taken 4342 times.
✓ Branch 7 taken 30180 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 4342 times.
✓ Branch 11 taken 36107 times.
✓ Branch 12 taken 43153 times.
✓ Branch 13 taken 35021 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 32071 times.
✓ Branch 16 taken 2950 times.
✓ Branch 17 taken 2976 times.
✓ Branch 18 taken 29095 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 2976 times.
✓ Branch 22 taken 35021 times.
✓ Branch 23 taken 43153 times.
✓ Branch 24 taken 38887 times.
✓ Branch 25 taken 4266 times.
114281 SET_COMMON_FORMATS(ctx, samplerates, AVMEDIA_TYPE_AUDIO,
840 ff_formats_ref, ff_formats_unref);
841 }
842
843 int ff_set_common_samplerates_from_list(AVFilterContext *ctx,
844 const int *samplerates)
845 {
846 return ff_set_common_samplerates(ctx, ff_make_format_list(samplerates));
847 }
848
849 43153 int ff_set_common_all_samplerates(AVFilterContext *ctx)
850 {
851 43153 return ff_set_common_samplerates(ctx, ff_all_samplerates());
852 }
853
854 44562 int ff_set_common_color_spaces(AVFilterContext *ctx,
855 AVFilterFormats *color_spaces)
856 {
857
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
✓ Branch 2 taken 36421 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 29882 times.
✓ Branch 5 taken 6539 times.
✓ Branch 6 taken 23999 times.
✓ Branch 7 taken 5883 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 23999 times.
✓ Branch 11 taken 36421 times.
✓ Branch 12 taken 44562 times.
✓ Branch 13 taken 36430 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 24854 times.
✓ Branch 16 taken 11576 times.
✓ Branch 17 taken 18962 times.
✓ Branch 18 taken 5892 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 18962 times.
✓ Branch 22 taken 36430 times.
✓ Branch 23 taken 44562 times.
✓ Branch 24 taken 18755 times.
✓ Branch 25 taken 25807 times.
117413 SET_COMMON_FORMATS(ctx, color_spaces, AVMEDIA_TYPE_VIDEO,
858 ff_formats_ref, ff_formats_unref);
859 }
860
861 int ff_set_common_color_spaces_from_list(AVFilterContext *ctx,
862 const int *color_spaces)
863 {
864 return ff_set_common_color_spaces(ctx, ff_make_format_list(color_spaces));
865 }
866
867 44562 int ff_set_common_all_color_spaces(AVFilterContext *ctx)
868 {
869 44562 return ff_set_common_color_spaces(ctx, ff_all_color_spaces());
870 }
871
872 44562 int ff_set_common_color_ranges(AVFilterContext *ctx,
873 AVFilterFormats *color_ranges)
874 {
875
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
✓ Branch 2 taken 36421 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27764 times.
✓ Branch 5 taken 8657 times.
✓ Branch 6 taken 21881 times.
✓ Branch 7 taken 5883 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 21881 times.
✓ Branch 11 taken 36421 times.
✓ Branch 12 taken 44562 times.
✓ Branch 13 taken 36430 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 22736 times.
✓ Branch 16 taken 13694 times.
✓ Branch 17 taken 16844 times.
✓ Branch 18 taken 5892 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 16844 times.
✓ Branch 22 taken 36430 times.
✓ Branch 23 taken 44562 times.
✓ Branch 24 taken 20873 times.
✓ Branch 25 taken 23689 times.
117413 SET_COMMON_FORMATS(ctx, color_ranges, AVMEDIA_TYPE_VIDEO,
876 ff_formats_ref, ff_formats_unref);
877 }
878
879 int ff_set_common_color_ranges_from_list(AVFilterContext *ctx,
880 const int *color_ranges)
881 {
882 return ff_set_common_color_ranges(ctx, ff_make_format_list(color_ranges));
883 }
884
885 44562 int ff_set_common_all_color_ranges(AVFilterContext *ctx)
886 {
887 44562 return ff_set_common_color_ranges(ctx, ff_all_color_ranges());
888 }
889
890 44562 int ff_set_common_alpha_modes(AVFilterContext *ctx,
891 AVFilterFormats *alpha_modes)
892 {
893
19/24
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
✓ Branch 2 taken 36421 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 36382 times.
✓ Branch 5 taken 39 times.
✓ Branch 6 taken 30499 times.
✓ Branch 7 taken 5883 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 30499 times.
✓ Branch 11 taken 36421 times.
✓ Branch 12 taken 44562 times.
✓ Branch 13 taken 36430 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 36076 times.
✓ Branch 16 taken 354 times.
✓ Branch 17 taken 30184 times.
✓ Branch 18 taken 5892 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 30184 times.
✓ Branch 22 taken 36430 times.
✓ Branch 23 taken 44562 times.
✓ Branch 24 taken 7530 times.
✓ Branch 25 taken 37032 times.
117413 SET_COMMON_FORMATS(ctx, alpha_modes, AVMEDIA_TYPE_VIDEO,
894 ff_formats_ref, ff_formats_unref);
895 }
896
897 int ff_set_common_alpha_modes_from_list(AVFilterContext *ctx,
898 const int *alpha_modes)
899 {
900 return ff_set_common_alpha_modes(ctx, ff_make_format_list(alpha_modes));
901 }
902
903 44562 int ff_set_common_all_alpha_modes(AVFilterContext *ctx)
904 {
905 44562 return ff_set_common_alpha_modes(ctx, ff_all_alpha_modes());
906 }
907
908 /**
909 * A helper for query_formats() which sets all links to the same list of
910 * formats. If there are no links hooked to this filter, the list of formats is
911 * freed.
912 */
913 44596 int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
914 {
915
15/20
✗ Branch 0 not taken.
✓ Branch 1 taken 44596 times.
✓ Branch 2 taken 36465 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14415 times.
✓ Branch 5 taken 22050 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14415 times.
✓ Branch 9 taken 36465 times.
✓ Branch 10 taken 44596 times.
✓ Branch 11 taken 36464 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7316 times.
✓ Branch 14 taken 29148 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 7316 times.
✓ Branch 18 taken 36464 times.
✓ Branch 19 taken 44596 times.
✓ Branch 20 taken 29105 times.
✓ Branch 21 taken 15491 times.
117525 SET_COMMON_FORMATS(ctx, formats, AVMEDIA_TYPE_UNKNOWN,
916 ff_formats_ref, ff_formats_unref);
917 }
918
919 1 int ff_set_common_formats_from_list(AVFilterContext *ctx, const int *fmts)
920 {
921 1 return ff_set_common_formats(ctx, ff_make_format_list(fmts));
922 }
923
924 #define SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, fmts, media_type, \
925 ref_fn, unref_fn) \
926 if (!fmts) \
927 return AVERROR(ENOMEM); \
928 \
929 for (unsigned i = 0; i < ctx->nb_inputs; i++) { \
930 const AVFilterLink *const link = ctx->inputs[i]; \
931 if (!cfg_in[i]->fmts && \
932 (media_type == AVMEDIA_TYPE_UNKNOWN || \
933 link->type == media_type)) { \
934 int ret = ref_fn(fmts, &cfg_in[i]->fmts); \
935 if (ret < 0) { \
936 return ret; \
937 } \
938 } \
939 } \
940 for (unsigned i = 0; i < ctx->nb_outputs; i++) { \
941 const AVFilterLink *const link = ctx->outputs[i]; \
942 if (!cfg_out[i]->fmts && \
943 (media_type == AVMEDIA_TYPE_UNKNOWN || \
944 link->type == media_type)) { \
945 int ret = ref_fn(fmts, &cfg_out[i]->fmts); \
946 if (ret < 0) { \
947 return ret; \
948 } \
949 } \
950 } \
951 \
952 if (!fmts->refcount) \
953 unref_fn(&fmts); \
954 \
955 return 0;
956
957 1481 int ff_set_common_channel_layouts2(const AVFilterContext *ctx,
958 AVFilterFormatsConfig **cfg_in,
959 AVFilterFormatsConfig **cfg_out,
960 AVFilterChannelLayouts *channel_layouts)
961 {
962
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1481 times.
✓ Branch 2 taken 114 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 114 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 114 times.
✓ Branch 9 taken 114 times.
✓ Branch 10 taken 1481 times.
✓ Branch 11 taken 1481 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1481 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1481 times.
✓ Branch 18 taken 1481 times.
✓ Branch 19 taken 1481 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1481 times.
3076 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, channel_layouts, AVMEDIA_TYPE_AUDIO,
963 ff_channel_layouts_ref, ff_channel_layouts_unref);
964 }
965
966 211 int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx,
967 AVFilterFormatsConfig **cfg_in,
968 AVFilterFormatsConfig **cfg_out,
969 const AVChannelLayout *fmts)
970 {
971 211 return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_make_channel_layout_list(fmts));
972 }
973
974 int ff_set_common_all_channel_counts2(const AVFilterContext *ctx,
975 AVFilterFormatsConfig **cfg_in,
976 AVFilterFormatsConfig **cfg_out)
977 {
978 return ff_set_common_channel_layouts2(ctx, cfg_in, cfg_out, ff_all_channel_counts());
979 }
980
981 1453 int ff_set_common_samplerates2(const AVFilterContext *ctx,
982 AVFilterFormatsConfig **cfg_in,
983 AVFilterFormatsConfig **cfg_out,
984 AVFilterFormats *samplerates)
985 {
986
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 1453 times.
✓ Branch 2 taken 86 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 86 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 86 times.
✓ Branch 9 taken 86 times.
✓ Branch 10 taken 1453 times.
✓ Branch 11 taken 1453 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1453 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1453 times.
✓ Branch 18 taken 1453 times.
✓ Branch 19 taken 1453 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1453 times.
2992 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, samplerates, AVMEDIA_TYPE_AUDIO,
987 ff_formats_ref, ff_formats_unref);
988 }
989
990 183 int ff_set_common_samplerates_from_list2(const AVFilterContext *ctx,
991 AVFilterFormatsConfig **cfg_in,
992 AVFilterFormatsConfig **cfg_out,
993 const int *samplerates)
994 {
995 183 return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_make_format_list(samplerates));
996 }
997
998 int ff_set_common_all_samplerates2(const AVFilterContext *ctx,
999 AVFilterFormatsConfig **cfg_in,
1000 AVFilterFormatsConfig **cfg_out)
1001 {
1002 return ff_set_common_samplerates2(ctx, cfg_in, cfg_out, ff_all_samplerates());
1003 }
1004
1005 5044 int ff_set_common_color_spaces2(const AVFilterContext *ctx,
1006 AVFilterFormatsConfig **cfg_in,
1007 AVFilterFormatsConfig **cfg_out,
1008 AVFilterFormats *color_spaces)
1009 {
1010
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 5044 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 5044 times.
✓ Branch 11 taken 5044 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 5044 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 5044 times.
✓ Branch 18 taken 5044 times.
✓ Branch 19 taken 5044 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 5044 times.
10108 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_spaces, AVMEDIA_TYPE_VIDEO,
1011 ff_formats_ref, ff_formats_unref);
1012 }
1013
1014 int ff_set_common_color_spaces_from_list2(const AVFilterContext *ctx,
1015 AVFilterFormatsConfig **cfg_in,
1016 AVFilterFormatsConfig **cfg_out,
1017 const int *color_spaces)
1018 {
1019 return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_make_format_list(color_spaces));
1020 }
1021
1022 int ff_set_common_all_color_spaces2(const AVFilterContext *ctx,
1023 AVFilterFormatsConfig **cfg_in,
1024 AVFilterFormatsConfig **cfg_out)
1025 {
1026 return ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, ff_all_color_spaces());
1027 }
1028
1029 7162 int ff_set_common_color_ranges2(const AVFilterContext *ctx,
1030 AVFilterFormatsConfig **cfg_in,
1031 AVFilterFormatsConfig **cfg_out,
1032 AVFilterFormats *color_ranges)
1033 {
1034
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 7162 times.
✓ Branch 2 taken 2138 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2138 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2138 times.
✓ Branch 9 taken 2138 times.
✓ Branch 10 taken 7162 times.
✓ Branch 11 taken 7162 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 7162 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 7162 times.
✓ Branch 18 taken 7162 times.
✓ Branch 19 taken 7162 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 7162 times.
16462 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, color_ranges, AVMEDIA_TYPE_VIDEO,
1035 ff_formats_ref, ff_formats_unref);
1036 }
1037
1038 int ff_set_common_color_ranges_from_list2(const AVFilterContext *ctx,
1039 AVFilterFormatsConfig **cfg_in,
1040 AVFilterFormatsConfig **cfg_out,
1041 const int *color_ranges)
1042 {
1043 return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_make_format_list(color_ranges));
1044 }
1045
1046 int ff_set_common_all_color_ranges2(const AVFilterContext *ctx,
1047 AVFilterFormatsConfig **cfg_in,
1048 AVFilterFormatsConfig **cfg_out)
1049 {
1050 return ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, ff_all_color_ranges());
1051 }
1052
1053 350 int ff_set_common_alpha_modes2(const AVFilterContext *ctx,
1054 AVFilterFormatsConfig **cfg_in,
1055 AVFilterFormatsConfig **cfg_out,
1056 AVFilterFormats *alpha_modes)
1057 {
1058
12/20
✗ Branch 0 not taken.
✓ Branch 1 taken 350 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 37 times.
✓ Branch 9 taken 37 times.
✓ Branch 10 taken 350 times.
✓ Branch 11 taken 350 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 350 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 350 times.
✓ Branch 18 taken 350 times.
✓ Branch 19 taken 350 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 350 times.
737 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, alpha_modes, AVMEDIA_TYPE_VIDEO,
1059 ff_formats_ref, ff_formats_unref);
1060 }
1061
1062 int ff_set_common_alpha_modes_from_list2(const AVFilterContext *ctx,
1063 AVFilterFormatsConfig **cfg_in,
1064 AVFilterFormatsConfig **cfg_out,
1065 const int *alpha_modes)
1066 {
1067 return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_make_format_list(alpha_modes));
1068 }
1069
1070 int ff_set_common_all_alpha_modes2(const AVFilterContext *ctx,
1071 AVFilterFormatsConfig **cfg_in,
1072 AVFilterFormatsConfig **cfg_out)
1073 {
1074 return ff_set_common_alpha_modes2(ctx, cfg_in, cfg_out, ff_all_alpha_modes());
1075 }
1076
1077 21022 int ff_set_common_formats2(const AVFilterContext *ctx,
1078 AVFilterFormatsConfig **cfg_in,
1079 AVFilterFormatsConfig **cfg_out,
1080 AVFilterFormats *formats)
1081 {
1082
11/16
✗ Branch 0 not taken.
✓ Branch 1 taken 21022 times.
✓ Branch 2 taken 13938 times.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13938 times.
✓ Branch 7 taken 13942 times.
✓ Branch 8 taken 21022 times.
✓ Branch 9 taken 21062 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 21062 times.
✓ Branch 14 taken 21062 times.
✓ Branch 15 taken 21022 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 21022 times.
56026 SET_COMMON_FORMATS2(ctx, cfg_in, cfg_out, formats, AVMEDIA_TYPE_UNKNOWN,
1083 ff_formats_ref, ff_formats_unref);
1084 }
1085
1086 1857 int ff_set_common_formats_from_list2(const AVFilterContext *ctx,
1087 AVFilterFormatsConfig **cfg_in,
1088 AVFilterFormatsConfig **cfg_out,
1089 const int *fmts)
1090 {
1091 1857 return ff_set_common_formats2(ctx, cfg_in, cfg_out, ff_make_format_list(fmts));
1092 }
1093
1094
1095 44595 int ff_default_query_formats(AVFilterContext *ctx)
1096 {
1097 44595 const FFFilter *const f = fffilter(ctx->filter);
1098 AVFilterFormats *formats;
1099 enum AVMediaType type;
1100 int ret;
1101
1102
5/5
✓ Branch 0 taken 1412 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 43119 times.
44595 switch (f->formats_state) {
1103 1412 case FF_FILTER_FORMATS_PIXFMT_LIST:
1104 1412 type = AVMEDIA_TYPE_VIDEO;
1105 1412 formats = ff_make_format_list(f->formats.pixels_list);
1106 1412 break;
1107 20 case FF_FILTER_FORMATS_SAMPLEFMTS_LIST:
1108 20 type = AVMEDIA_TYPE_AUDIO;
1109 20 formats = ff_make_format_list(f->formats.samples_list);
1110 20 break;
1111 31 case FF_FILTER_FORMATS_SINGLE_PIXFMT:
1112 31 type = AVMEDIA_TYPE_VIDEO;
1113 31 formats = ff_make_formats_list_singleton(f->formats.pix_fmt);
1114 31 break;
1115 13 case FF_FILTER_FORMATS_SINGLE_SAMPLEFMT:
1116 13 type = AVMEDIA_TYPE_AUDIO;
1117 13 formats = ff_make_formats_list_singleton(f->formats.sample_fmt);
1118 13 break;
1119 43119 default:
1120 av_assert2(!"Unreachable");
1121 /* Intended fallthrough */
1122 case FF_FILTER_FORMATS_PASSTHROUGH:
1123 case FF_FILTER_FORMATS_QUERY_FUNC:
1124 case FF_FILTER_FORMATS_QUERY_FUNC2:
1125 43119 type = AVMEDIA_TYPE_UNKNOWN;
1126
2/2
✓ Branch 0 taken 35949 times.
✓ Branch 1 taken 7170 times.
50289 formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type :
1127
1/2
✓ Branch 0 taken 7170 times.
✗ Branch 1 not taken.
7170 ctx->nb_outputs ? ctx->outputs[0]->type :
1128 AVMEDIA_TYPE_VIDEO);
1129 43119 break;
1130 }
1131
1132 44595 ret = ff_set_common_formats(ctx, formats);
1133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44595 times.
44595 if (ret < 0)
1134 return ret;
1135
2/2
✓ Branch 0 taken 44562 times.
✓ Branch 1 taken 33 times.
44595 if (type != AVMEDIA_TYPE_AUDIO) {
1136 44562 ret = ff_set_common_all_color_spaces(ctx);
1137
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
44562 if (ret < 0)
1138 return ret;
1139 44562 ret = ff_set_common_all_color_ranges(ctx);
1140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
44562 if (ret < 0)
1141 return ret;
1142 44562 ret = ff_set_common_all_alpha_modes(ctx);
1143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 44562 times.
44562 if (ret < 0)
1144 return ret;
1145 }
1146
2/2
✓ Branch 0 taken 43152 times.
✓ Branch 1 taken 1443 times.
44595 if (type != AVMEDIA_TYPE_VIDEO) {
1147 43152 ret = ff_set_common_all_channel_counts(ctx);
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43152 times.
43152 if (ret < 0)
1149 return ret;
1150 43152 ret = ff_set_common_all_samplerates(ctx);
1151
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43152 times.
43152 if (ret < 0)
1152 return ret;
1153 }
1154
1155 44595 return 0;
1156 }
1157
1158 211860 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
1159 {
1160 unsigned i, j;
1161
1162
2/2
✓ Branch 0 taken 117620 times.
✓ Branch 1 taken 94240 times.
211860 if (!fmts)
1163 117620 return 0;
1164
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 94240 times.
94240 if (!fmts->nb_formats) {
1165 av_log(log, AV_LOG_ERROR, "Empty %s list\n", name);
1166 return AVERROR(EINVAL);
1167 }
1168
2/2
✓ Branch 0 taken 3682884 times.
✓ Branch 1 taken 94240 times.
3777124 for (i = 0; i < fmts->nb_formats; i++) {
1169
2/2
✓ Branch 0 taken 378591265 times.
✓ Branch 1 taken 3682884 times.
382274149 for (j = i + 1; j < fmts->nb_formats; j++) {
1170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 378591265 times.
378591265 if (fmts->formats[i] == fmts->formats[j]) {
1171 av_log(log, AV_LOG_ERROR, "Duplicated %s\n", name);
1172 return AVERROR(EINVAL);
1173 }
1174 }
1175 }
1176 94240 return 0;
1177 }
1178
1179 50070 int ff_formats_check_pixel_formats(void *log, const AVFilterFormats *fmts)
1180 {
1181 50070 return check_list(log, "pixel format", fmts);
1182 }
1183
1184 9397 int ff_formats_check_sample_formats(void *log, const AVFilterFormats *fmts)
1185 {
1186 9397 return check_list(log, "sample format", fmts);
1187 }
1188
1189 9397 int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts)
1190 {
1191
4/4
✓ Branch 0 taken 4535 times.
✓ Branch 1 taken 4862 times.
✓ Branch 2 taken 2352 times.
✓ Branch 3 taken 2183 times.
9397 if (!fmts || !fmts->nb_formats)
1192 7214 return 0;
1193 2183 return check_list(log, "sample rate", fmts);
1194 }
1195
1196 50070 int ff_formats_check_color_spaces(void *log, const AVFilterFormats *fmts)
1197 {
1198
4/4
✓ Branch 0 taken 127482 times.
✓ Branch 1 taken 31955 times.
✓ Branch 2 taken 109367 times.
✓ Branch 3 taken 18115 times.
159437 for (int i = 0; fmts && i < fmts->nb_formats; i++) {
1199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109367 times.
109367 if (fmts->formats[i] == AVCOL_SPC_RESERVED) {
1200 av_log(log, AV_LOG_ERROR, "Invalid color space\n");
1201 return AVERROR(EINVAL);
1202 }
1203 }
1204 50070 return check_list(log, "color space", fmts);
1205 }
1206
1207 50070 int ff_formats_check_color_ranges(void *log, const AVFilterFormats *fmts)
1208 {
1209 50070 return check_list(log, "color range", fmts);
1210 }
1211
1212 50070 int ff_formats_check_alpha_modes(void *log, const AVFilterFormats *fmts)
1213 {
1214 50070 return check_list(log, "alpha mode", fmts);
1215 }
1216
1217 3420 static int layouts_compatible(const AVChannelLayout *a, const AVChannelLayout *b)
1218 {
1219 3420 return !av_channel_layout_compare(a, b) ||
1220
3/12
✓ Branch 0 taken 3420 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3420 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3420 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
6840 (KNOWN(a) && !KNOWN(b) && a->nb_channels == b->nb_channels) ||
1221
2/10
✗ Branch 0 not taken.
✓ Branch 1 taken 3420 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3420 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
3420 (KNOWN(b) && !KNOWN(a) && b->nb_channels == a->nb_channels);
1222 }
1223
1224 9397 int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts)
1225 {
1226 unsigned i, j;
1227
1228
2/2
✓ Branch 0 taken 4561 times.
✓ Branch 1 taken 4836 times.
9397 if (!fmts)
1229 4561 return 0;
1230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4836 times.
4836 if (fmts->all_layouts < fmts->all_counts) {
1231 av_log(log, AV_LOG_ERROR, "Inconsistent generic list\n");
1232 return AVERROR(EINVAL);
1233 }
1234
3/4
✓ Branch 0 taken 1755 times.
✓ Branch 1 taken 3081 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1755 times.
4836 if (!fmts->all_layouts && !fmts->nb_channel_layouts) {
1235 av_log(log, AV_LOG_ERROR, "Empty channel layout list\n");
1236 return AVERROR(EINVAL);
1237 }
1238
2/2
✓ Branch 0 taken 2403 times.
✓ Branch 1 taken 4836 times.
7239 for (i = 0; i < fmts->nb_channel_layouts; i++) {
1239
2/2
✓ Branch 0 taken 3420 times.
✓ Branch 1 taken 2403 times.
5823 for (j = i + 1; j < fmts->nb_channel_layouts; j++) {
1240
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3420 times.
3420 if (layouts_compatible(&fmts->channel_layouts[i], &fmts->channel_layouts[j])) {
1241 av_log(log, AV_LOG_ERROR, "Duplicated or redundant channel layout\n");
1242 return AVERROR(EINVAL);
1243 }
1244 }
1245 }
1246 4836 return 0;
1247 }
1248