../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
709 / 915
77.5%
Branches:
621 / 881
70.5%
Functions:
39 / 42
92.9%

libavfilter/avfiltergraph.c
Line Branch Exec Source
1 /*
2 * filter graphs
3 * Copyright (c) 2008 Vitor Sessak
4 * Copyright (c) 2007 Bobby Bingham
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #include <string.h>
26
27 #include "libavutil/avassert.h"
28 #include "libavutil/bprint.h"
29 #include "libavutil/channel_layout.h"
30 #include "libavutil/imgutils.h"
31 #include "libavutil/mem.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34
35
36 #include "avfilter.h"
37 #include "avfilter_internal.h"
38 #include "buffersink.h"
39 #include "filters.h"
40 #include "formats.h"
41 #include "framequeue.h"
42 #include "video.h"
43
44 #define OFFSET(x) offsetof(AVFilterGraph, x)
45 #define F AV_OPT_FLAG_FILTERING_PARAM
46 #define V AV_OPT_FLAG_VIDEO_PARAM
47 #define A AV_OPT_FLAG_AUDIO_PARAM
48 FF_DISABLE_DEPRECATION_WARNINGS
49 static const AVOption filtergraph_options[] = {
50 { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
51 { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, F|V|A, .unit = "thread_type" },
52 { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .flags = F|V|A, .unit = "thread_type" },
53 { "threads", "Maximum number of threads", OFFSET(nb_threads), AV_OPT_TYPE_INT,
54 { .i64 = 0 }, 0, INT_MAX, F|V|A, .unit = "threads"},
55 {"auto", "autodetect a suitable number of threads to use", 0, AV_OPT_TYPE_CONST, {.i64 = 0 }, .flags = F|V|A, .unit = "threads"},
56 {"scale_sws_opts" , "default scale filter options" , OFFSET(scale_sws_opts) ,
57 AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|V },
58 {"aresample_swr_opts" , "default aresample filter options" , OFFSET(aresample_swr_opts) ,
59 AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, F|A },
60 #if FF_API_MAX_BUFFERED_FRAMES
61 {"max_buffered_frames" , "maximum number of buffered frames allowed", OFFSET(max_buffered_frames),
62 AV_OPT_TYPE_UINT, {.i64 = 0}, 0, UINT_MAX, F|V|A|AV_OPT_FLAG_DEPRECATED },
63 #endif
64 { NULL },
65 };
66 FF_ENABLE_DEPRECATION_WARNINGS
67
68 static const AVClass filtergraph_class = {
69 .class_name = "AVFilterGraph",
70 .item_name = av_default_item_name,
71 .version = LIBAVUTIL_VERSION_INT,
72 .option = filtergraph_options,
73 .category = AV_CLASS_CATEGORY_FILTER,
74 };
75
76 #if !HAVE_THREADS
77 void ff_graph_thread_free(FFFilterGraph *graph)
78 {
79 }
80
81 int ff_graph_thread_init(FFFilterGraph *graph)
82 {
83 graph->p.thread_type = 0;
84 graph->p.nb_threads = 1;
85 return 0;
86 }
87 #endif
88
89 17655 AVFilterGraph *avfilter_graph_alloc(void)
90 {
91 17655 FFFilterGraph *graph = av_mallocz(sizeof(*graph));
92 AVFilterGraph *ret;
93
94
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 17655 times.
17655 if (!graph)
95 ✗ return NULL;
96
97 17655 ret = &graph->p;
98 17655 ret->av_class = &filtergraph_class;
99 17655 av_opt_set_defaults(ret);
100
2/2
✓ Branch 9 → 7 taken 88275 times.
✓ Branch 9 → 10 taken 17655 times.
105930 for (int i = 0; i < FF_ARRAY_ELEMS(graph->frame_queues); i++)
101 88275 ff_framequeue_global_init(&graph->frame_queues[i]);
102
103 17655 return ret;
104 }
105
106 69023 void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter)
107 {
108 int i, j;
109
1/2
✓ Branch 12 → 3 taken 69023 times.
✗ Branch 12 → 13 not taken.
69023 for (i = 0; i < graph->nb_filters; i++) {
110
1/2
✓ Branch 3 → 4 taken 69023 times.
✗ Branch 3 → 11 not taken.
69023 if (graph->filters[i] == filter) {
111 69023 FFSWAP(AVFilterContext*, graph->filters[i],
112 graph->filters[graph->nb_filters - 1]);
113 69023 graph->nb_filters--;
114 69023 filter->graph = NULL;
115
2/2
✓ Branch 9 → 5 taken 60193 times.
✓ Branch 9 → 10 taken 69023 times.
129216 for (j = 0; j<filter->nb_outputs; j++)
116
2/2
✓ Branch 5 → 6 taken 23152 times.
✓ Branch 5 → 8 taken 37041 times.
60193 if (filter->outputs[j])
117 23152 ff_filter_link(filter->outputs[j])->graph = NULL;
118
119 69023 return;
120 }
121 }
122 }
123
124 26227 void avfilter_graph_free(AVFilterGraph **graphp)
125 {
126 26227 AVFilterGraph *graph = *graphp;
127 26227 FFFilterGraph *graphi = fffiltergraph(graph);
128
129
2/2
✓ Branch 3 → 4 taken 8572 times.
✓ Branch 3 → 5 taken 17655 times.
26227 if (!graph)
130 8572 return;
131
132
2/2
✓ Branch 7 → 6 taken 68957 times.
✓ Branch 7 → 8 taken 17655 times.
86612 while (graph->nb_filters)
133 68957 avfilter_free(graph->filters[0]);
134
135 17655 ff_graph_thread_free(graphi);
136
137 17655 av_freep(&graphi->sink_links);
138
139 17655 av_opt_free(graph);
140
141 17655 av_freep(&graph->filters);
142 17655 av_freep(graphp);
143 }
144
145 21889 int avfilter_graph_create_filter(AVFilterContext **filt_ctx, const AVFilter *filt,
146 const char *name, const char *args, void *opaque,
147 AVFilterGraph *graph_ctx)
148 {
149 int ret;
150
151 21889 *filt_ctx = avfilter_graph_alloc_filter(graph_ctx, filt, name);
152
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 21889 times.
21889 if (!*filt_ctx)
153 ✗ return AVERROR(ENOMEM);
154
155 21889 ret = avfilter_init_str(*filt_ctx, args);
156
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 21889 times.
21889 if (ret < 0)
157 ✗ goto fail;
158
159 21889 return 0;
160
161 ✗ fail:
162 ✗ avfilter_free(*filt_ctx);
163 ✗ *filt_ctx = NULL;
164 ✗ return ret;
165 }
166
167 6883 void avfilter_graph_set_auto_convert(AVFilterGraph *graph, unsigned flags)
168 {
169 6883 fffiltergraph(graph)->disable_auto_convert = flags;
170 6883 }
171
172 5 int avfilter_graph_set_max_buffered_frames(AVFilterGraph *graph,
173 enum AVMediaType type,
174 unsigned frames)
175 {
176 5 FFFilterGraph *graphi = fffiltergraph(graph);
177
2/4
✓ Branch 3 → 4 taken 5 times.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 5 times.
5 if (type < 0 || type >= FF_ARRAY_ELEMS(graphi->frame_queues))
178 ✗ return AVERROR(EINVAL);
179
180 5 FFFrameQueueGlobal *fqg = &graphi->frame_queues[type];
181
1/2
✓ Branch 6 → 7 taken 5 times.
✗ Branch 6 → 8 not taken.
5 size_t max_queued = frames ? frames : SIZE_MAX;
182
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 5 times.
5 if (fqg->queued > max_queued)
183 ✗ return AVERROR(EINVAL);
184 5 fqg->max_queued = max_queued;
185 5 graphi->max_queued_set[type] = 1;
186 5 return 0;
187 }
188
189 69023 AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph,
190 const AVFilter *filter,
191 const char *name)
192 {
193 AVFilterContext **filters, *s;
194 69023 FFFilterGraph *graphi = fffiltergraph(graph);
195
196
4/4
✓ Branch 3 → 4 taken 37747 times.
✓ Branch 3 → 12 taken 31276 times.
✓ Branch 4 → 5 taken 17655 times.
✓ Branch 4 → 12 taken 20092 times.
69023 if (graph->thread_type && !graphi->thread_execute) {
197
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 17655 times.
17655 if (graph->execute) {
198 ✗ graphi->thread_execute = graph->execute;
199 } else {
200 17655 int ret = ff_graph_thread_init(graphi);
201
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 12 taken 17655 times.
17655 if (ret < 0) {
202 ✗ av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret));
203 ✗ return NULL;
204 }
205 }
206 }
207
208 69023 filters = av_realloc_array(graph->filters, graph->nb_filters + 1, sizeof(*filters));
209
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 69023 times.
69023 if (!filters)
210 ✗ return NULL;
211 69023 graph->filters = filters;
212
213 69023 s = ff_filter_alloc(filter, name);
214
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 69023 times.
69023 if (!s)
215 ✗ return NULL;
216
217 69023 graph->filters[graph->nb_filters++] = s;
218
219 69023 s->graph = graph;
220
221 69023 return s;
222 }
223
224 /**
225 * Check for the validity of graph.
226 *
227 * A graph is considered valid if all its input and output pads are
228 * connected.
229 *
230 * @return >= 0 in case of success, a negative value otherwise
231 */
232 9010 static int graph_check_validity(AVFilterGraph *graph, void *log_ctx)
233 {
234 AVFilterContext *filt;
235 int i, j;
236
237
2/2
✓ Branch 20 → 3 taken 47904 times.
✓ Branch 20 → 21 taken 9010 times.
56914 for (i = 0; i < graph->nb_filters; i++) {
238 const AVFilterPad *pad;
239 47904 filt = graph->filters[i];
240
241
2/2
✓ Branch 10 → 4 taken 38865 times.
✓ Branch 10 → 11 taken 47904 times.
86769 for (j = 0; j < filt->nb_inputs; j++) {
242
2/4
✓ Branch 4 → 5 taken 38865 times.
✗ Branch 4 → 6 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 38865 times.
38865 if (!filt->inputs[j] || !filt->inputs[j]->src) {
243 ✗ pad = &filt->input_pads[j];
244 ✗ av_log(log_ctx, AV_LOG_ERROR,
245 "Input pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any source\n",
246 ✗ pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
247 ✗ return AVERROR(EINVAL);
248 }
249 }
250
251
2/2
✓ Branch 18 → 12 taken 38865 times.
✓ Branch 18 → 19 taken 47904 times.
86769 for (j = 0; j < filt->nb_outputs; j++) {
252
2/4
✓ Branch 12 → 13 taken 38865 times.
✗ Branch 12 → 14 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 17 taken 38865 times.
38865 if (!filt->outputs[j] || !filt->outputs[j]->dst) {
253 ✗ pad = &filt->output_pads[j];
254 ✗ av_log(log_ctx, AV_LOG_ERROR,
255 "Output pad \"%s\" with type %s of the filter instance \"%s\" of %s not connected to any destination\n",
256 ✗ pad->name, av_get_media_type_string(pad->type), filt->name, filt->filter->name);
257 ✗ return AVERROR(EINVAL);
258 }
259 }
260 }
261
262 9010 return 0;
263 }
264
265 /**
266 * Configure all the links of graphctx.
267 *
268 * @return >= 0 in case of success, a negative value otherwise
269 */
270 9010 static int graph_config_links(AVFilterGraph *graph, void *log_ctx)
271 {
272 AVFilterContext *filt;
273 int i, ret;
274
275
2/2
✓ Branch 8 → 3 taken 49543 times.
✓ Branch 8 → 9 taken 9008 times.
58551 for (i = 0; i < graph->nb_filters; i++) {
276 49543 filt = graph->filters[i];
277
278
2/2
✓ Branch 3 → 4 taken 9250 times.
✓ Branch 3 → 7 taken 40293 times.
49543 if (!filt->nb_outputs) {
279
2/2
✓ Branch 5 → 6 taken 2 times.
✓ Branch 5 → 7 taken 9248 times.
9250 if ((ret = ff_filter_config_links(filt)))
280 2 return ret;
281 }
282 }
283
284 9008 return 0;
285 }
286
287 9008 static int graph_check_links(AVFilterGraph *graph, void *log_ctx)
288 {
289 AVFilterContext *f;
290 AVFilterLink *l;
291 unsigned i, j;
292 int ret;
293
294
2/2
✓ Branch 11 → 3 taken 49535 times.
✓ Branch 11 → 12 taken 9008 times.
58543 for (i = 0; i < graph->nb_filters; i++) {
295 49535 f = graph->filters[i];
296
2/2
✓ Branch 9 → 4 taken 40498 times.
✓ Branch 9 → 10 taken 49535 times.
90033 for (j = 0; j < f->nb_outputs; j++) {
297 40498 l = f->outputs[j];
298
2/2
✓ Branch 4 → 5 taken 33168 times.
✓ Branch 4 → 8 taken 7330 times.
40498 if (l->type == AVMEDIA_TYPE_VIDEO) {
299 33168 ret = av_image_check_size2(l->w, l->h, INT64_MAX, l->format, 0, f);
300
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 33168 times.
33168 if (ret < 0)
301 ✗ return ret;
302 }
303 }
304 }
305 9008 return 0;
306 }
307
308 ✗ AVFilterContext *avfilter_graph_get_filter(AVFilterGraph *graph, const char *name)
309 {
310 int i;
311
312
0/2
✗ Branch 7 → 3 not taken.
✗ Branch 7 → 8 not taken.
✗ for (i = 0; i < graph->nb_filters; i++)
313
0/4
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ if (graph->filters[i]->name && !strcmp(name, graph->filters[i]->name))
314 ✗ return graph->filters[i];
315
316 ✗ return NULL;
317 }
318
319 66362 static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
320 {
321 int ret;
322
323
2/3
✓ Branch 2 → 3 taken 54799 times.
✓ Branch 2 → 15 taken 11563 times.
✗ Branch 2 → 23 not taken.
66362 switch (link->type) {
324
325 54799 case AVMEDIA_TYPE_VIDEO:
326
2/4
✓ Branch 4 → 5 taken 54799 times.
✗ Branch 4 → 13 not taken.
✓ Branch 6 → 7 taken 54799 times.
✗ Branch 6 → 13 not taken.
109598 if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0 ||
327
1/2
✓ Branch 8 → 9 taken 54799 times.
✗ Branch 8 → 13 not taken.
109598 (ret = ff_formats_check_color_spaces(log, cfg->color_spaces)) < 0 ||
328
1/2
✓ Branch 10 → 11 taken 54799 times.
✗ Branch 10 → 13 not taken.
109598 (ret = ff_formats_check_color_ranges(log, cfg->color_ranges)) < 0 ||
329
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 54799 times.
109598 (ret = ff_formats_check_alpha_modes(log, cfg->alpha_modes)) < 0 ||
330 54799 (ret = ff_formats_check_chroma_locations(log, cfg->chroma_locations)) < 0)
331 ✗ return ret;
332 54799 break;
333
334 11563 case AVMEDIA_TYPE_AUDIO:
335
2/4
✓ Branch 16 → 17 taken 11563 times.
✗ Branch 16 → 21 not taken.
✓ Branch 18 → 19 taken 11563 times.
✗ Branch 18 → 21 not taken.
23126 if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
336
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 11563 times.
23126 (ret = ff_formats_check_sample_rates(log, cfg->samplerates)) < 0 ||
337 11563 (ret = ff_formats_check_channel_layouts(log, cfg->channel_layouts)) < 0)
338 ✗ return ret;
339 11563 break;
340
341 ✗ default:
342 ✗ av_assert0(!"reached");
343 }
344 66362 return 0;
345 }
346
347 /**
348 * Check the validity of the formats / etc. lists set by query_formats().
349 *
350 * In particular, check they do not contain any redundant element.
351 */
352 41730 static int filter_check_formats(AVFilterContext *ctx)
353 {
354 unsigned i;
355 int ret;
356
357
2/2
✓ Branch 7 → 3 taken 33806 times.
✓ Branch 7 → 8 taken 41730 times.
75536 for (i = 0; i < ctx->nb_inputs; i++) {
358 33806 ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
359
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 33806 times.
33806 if (ret < 0)
360 ✗ return ret;
361 }
362
2/2
✓ Branch 13 → 9 taken 32556 times.
✓ Branch 13 → 14 taken 41730 times.
74286 for (i = 0; i < ctx->nb_outputs; i++) {
363 32556 ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
364
1/2
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 32556 times.
32556 if (ret < 0)
365 ✗ return ret;
366 }
367 41730 return 0;
368 }
369
370 49564 static int filter_query_formats(AVFilterContext *ctx)
371 {
372 49564 const FFFilter *const filter = fffilter(ctx->filter);
373 int ret;
374
375
2/2
✓ Branch 3 → 4 taken 35 times.
✓ Branch 3 → 11 taken 49529 times.
49564 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC) {
376
2/2
✓ Branch 5 → 6 taken 17 times.
✓ Branch 5 → 46 taken 18 times.
35 if ((ret = filter->formats.query_func(ctx)) < 0) {
377
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 10 taken 17 times.
17 if (ret != AVERROR(EAGAIN))
378 ✗ av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
379 ✗ ctx->name, av_err2str(ret));
380 17 return ret;
381 }
382
2/2
✓ Branch 11 → 12 taken 41712 times.
✓ Branch 11 → 46 taken 7817 times.
49529 } else if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
383 AVFilterFormatsConfig *cfg_in_stack[64], *cfg_out_stack[64];
384 41712 AVFilterFormatsConfig **cfg_in_dyn = NULL, **cfg_out_dyn = NULL;
385 AVFilterFormatsConfig **cfg_in, **cfg_out;
386
387
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 17 taken 41711 times.
41712 if (ctx->nb_inputs > FF_ARRAY_ELEMS(cfg_in_stack)) {
388 1 cfg_in_dyn = av_malloc_array(ctx->nb_inputs, sizeof(*cfg_in_dyn));
389
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 1 time.
1 if (!cfg_in_dyn)
390 ✗ return AVERROR(ENOMEM);
391 1 cfg_in = cfg_in_dyn;
392 } else
393
2/2
✓ Branch 17 → 18 taken 33641 times.
✓ Branch 17 → 19 taken 8070 times.
41711 cfg_in = ctx->nb_inputs ? cfg_in_stack : NULL;
394
395
2/2
✓ Branch 22 → 21 taken 33782 times.
✓ Branch 22 → 23 taken 41712 times.
75494 for (unsigned i = 0; i < ctx->nb_inputs; i++) {
396 33782 AVFilterLink *l = ctx->inputs[i];
397 33782 cfg_in[i] = &l->outcfg;
398 }
399
400
2/2
✓ Branch 23 → 24 taken 1 time.
✓ Branch 23 → 29 taken 41711 times.
41712 if (ctx->nb_outputs > FF_ARRAY_ELEMS(cfg_out_stack)) {
401 1 cfg_out_dyn = av_malloc_array(ctx->nb_outputs, sizeof(*cfg_out_dyn));
402
1/2
✗ Branch 25 → 26 not taken.
✓ Branch 25 → 28 taken 1 time.
1 if (!cfg_out_dyn) {
403 ✗ av_freep(&cfg_in_dyn);
404 ✗ return AVERROR(ENOMEM);
405 }
406 1 cfg_out = cfg_out_dyn;
407 } else
408
2/2
✓ Branch 29 → 30 taken 32462 times.
✓ Branch 29 → 31 taken 9249 times.
41711 cfg_out = ctx->nb_outputs ? cfg_out_stack : NULL;
409
410
2/2
✓ Branch 34 → 33 taken 32538 times.
✓ Branch 34 → 35 taken 41712 times.
74250 for (unsigned i = 0; i < ctx->nb_outputs; i++) {
411 32538 AVFilterLink *l = ctx->outputs[i];
412 32538 cfg_out[i] = &l->incfg;
413 }
414
415 41712 ret = filter->formats.query_func2(ctx, cfg_in, cfg_out);
416 41712 av_freep(&cfg_in_dyn);
417 41712 av_freep(&cfg_out_dyn);
418
1/2
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 44 taken 41712 times.
41712 if (ret < 0) {
419
0/2
✗ Branch 39 → 40 not taken.
✗ Branch 39 → 43 not taken.
✗ if (ret != AVERROR(EAGAIN))
420 ✗ av_log(ctx, AV_LOG_ERROR, "Query format failed for '%s': %s\n",
421 ✗ ctx->name, av_err2str(ret));
422 ✗ return ret;
423 }
424 }
425
426
2/2
✓ Branch 46 → 47 taken 49529 times.
✓ Branch 46 → 48 taken 18 times.
49547 if (filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC ||
427
2/2
✓ Branch 47 → 48 taken 41712 times.
✓ Branch 47 → 51 taken 7817 times.
49529 filter->formats_state == FF_FILTER_FORMATS_QUERY_FUNC2) {
428 41730 ret = filter_check_formats(ctx);
429
1/2
✗ Branch 49 → 50 not taken.
✓ Branch 49 → 51 taken 41730 times.
41730 if (ret < 0)
430 ✗ return ret;
431 }
432
433 49547 return ff_default_query_formats(ctx);
434 }
435
436 47978 static int formats_declared(AVFilterContext *f)
437 {
438 int i;
439
440
2/2
✓ Branch 16 → 3 taken 38740 times.
✓ Branch 16 → 17 taken 9278 times.
48018 for (i = 0; i < f->nb_inputs; i++) {
441
2/2
✓ Branch 3 → 4 taken 38698 times.
✓ Branch 3 → 5 taken 42 times.
38740 if (!f->inputs[i]->outcfg.formats)
442 38698 return 0;
443
2/2
✓ Branch 5 → 6 taken 33 times.
✓ Branch 5 → 11 taken 9 times.
42 if (f->inputs[i]->type == AVMEDIA_TYPE_VIDEO &&
444
2/2
✓ Branch 6 → 7 taken 31 times.
✓ Branch 6 → 10 taken 2 times.
33 !(f->inputs[i]->outcfg.color_ranges &&
445
1/2
✓ Branch 7 → 8 taken 31 times.
✗ Branch 7 → 10 not taken.
31 f->inputs[i]->outcfg.color_spaces &&
446
1/2
✓ Branch 8 → 9 taken 31 times.
✗ Branch 8 → 10 not taken.
31 f->inputs[i]->outcfg.alpha_modes &&
447
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 31 times.
31 f->inputs[i]->outcfg.chroma_locations))
448 2 return 0;
449
2/2
✓ Branch 11 → 12 taken 9 times.
✓ Branch 11 → 15 taken 31 times.
40 if (f->inputs[i]->type == AVMEDIA_TYPE_AUDIO &&
450
1/2
✓ Branch 12 → 13 taken 9 times.
✗ Branch 12 → 14 not taken.
9 !(f->inputs[i]->outcfg.samplerates &&
451
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 9 times.
9 f->inputs[i]->outcfg.channel_layouts))
452 ✗ return 0;
453 }
454
2/2
✓ Branch 31 → 18 taken 9267 times.
✓ Branch 31 → 32 taken 57 times.
9324 for (i = 0; i < f->nb_outputs; i++) {
455
2/2
✓ Branch 18 → 19 taken 9221 times.
✓ Branch 18 → 20 taken 46 times.
9267 if (!f->outputs[i]->incfg.formats)
456 9221 return 0;
457
2/2
✓ Branch 20 → 21 taken 31 times.
✓ Branch 20 → 26 taken 15 times.
46 if (f->outputs[i]->type == AVMEDIA_TYPE_VIDEO &&
458
1/2
✓ Branch 21 → 22 taken 31 times.
✗ Branch 21 → 25 not taken.
31 !(f->outputs[i]->incfg.color_ranges &&
459
1/2
✓ Branch 22 → 23 taken 31 times.
✗ Branch 22 → 25 not taken.
31 f->outputs[i]->incfg.color_spaces &&
460
1/2
✓ Branch 23 → 24 taken 31 times.
✗ Branch 23 → 25 not taken.
31 f->outputs[i]->incfg.alpha_modes &&
461
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 31 times.
31 f->outputs[i]->incfg.chroma_locations))
462 ✗ return 0;
463
2/2
✓ Branch 26 → 27 taken 15 times.
✓ Branch 26 → 30 taken 31 times.
46 if (f->outputs[i]->type == AVMEDIA_TYPE_AUDIO &&
464
1/2
✓ Branch 27 → 28 taken 15 times.
✗ Branch 27 → 29 not taken.
15 !(f->outputs[i]->incfg.samplerates &&
465
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 30 taken 15 times.
15 f->outputs[i]->incfg.channel_layouts))
466 ✗ return 0;
467 }
468 57 return 1;
469 }
470
471 ✗ static void print_link_formats(void *log_ctx, int level, const AVFilterLink *l,
472 const AVFilterFormatsMerger *mergers[],
473 int nb_mergers)
474 {
475
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (av_log_get_level() < level)
476 ✗ return;
477
478 AVBPrint bp;
479 ✗ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
480
481 ✗ av_log(log_ctx, level, "Link '%s.%s' -> '%s.%s':\n",
482 ✗ l->src->name, l->srcpad->name, l->dst->name, l->dstpad->name);
483
484
0/2
✗ Branch 20 → 8 not taken.
✗ Branch 20 → 21 not taken.
✗ for (unsigned i = 0; i < nb_mergers; i++) {
485 ✗ const AVFilterFormatsMerger *m = mergers[i];
486 ✗ av_log(log_ctx, level, " %s:\n", m->name);
487 ✗ m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->incfg));
488
0/2
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
✗ if (av_bprint_is_complete(&bp))
489 ✗ av_log(log_ctx, level, " src: %s\n", bp.str);
490 ✗ av_bprint_clear(&bp);
491
492 ✗ m->print_list(&bp, FF_FIELD_AT(void *, m->offset, l->outcfg));
493
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ if (av_bprint_is_complete(&bp))
494 ✗ av_log(log_ctx, level, " dst: %s\n", bp.str);
495 ✗ av_bprint_clear(&bp);
496 }
497
498 ✗ av_bprint_finalize(&bp, NULL);
499 }
500
501 47904 static void print_filter_formats(void *log_ctx, int level, const AVFilterContext *f)
502 {
503
1/2
✓ Branch 3 → 4 taken 47904 times.
✗ Branch 3 → 5 not taken.
47904 if (av_log_get_level() < level)
504 47904 return;
505
506 AVBPrint bp;
507 ✗ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
508
509 ✗ av_log(log_ctx, level, "Filter '%s' formats:\n", f->name);
510
0/2
✗ Branch 19 → 8 not taken.
✗ Branch 19 → 20 not taken.
✗ for (int i = 0; i < f->nb_inputs; i++) {
511 ✗ const AVFilterLink *in = f->inputs[i];
512 ✗ const AVFilterNegotiation *neg = ff_filter_get_negotiation(in);
513 ✗ av_log(log_ctx, level, " in[%d] '%s':\n", i, f->input_pads[i].name);
514
515
0/2
✗ Branch 17 → 11 not taken.
✗ Branch 17 → 18 not taken.
✗ for (unsigned i = 0; i < neg->nb_mergers; i++) {
516 ✗ const AVFilterFormatsMerger *m = &neg->mergers[i];
517 ✗ m->print_list(&bp, FF_FIELD_AT(void *, m->offset, in->outcfg));
518
0/2
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 15 not taken.
✗ if (av_bprint_is_complete(&bp))
519 ✗ av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
520 ✗ av_bprint_clear(&bp);
521 }
522 }
523
524
0/2
✗ Branch 32 → 21 not taken.
✗ Branch 32 → 33 not taken.
✗ for (int i = 0; i < f->nb_outputs; i++) {
525 ✗ const AVFilterLink *out = f->outputs[i];
526 ✗ const AVFilterNegotiation *neg = ff_filter_get_negotiation(out);
527 ✗ av_log(log_ctx, level, " out[%d] '%s':\n", i, f->output_pads[i].name);
528
529
0/2
✗ Branch 30 → 24 not taken.
✗ Branch 30 → 31 not taken.
✗ for (unsigned i = 0; i < neg->nb_mergers; i++) {
530 ✗ const AVFilterFormatsMerger *m = &neg->mergers[i];
531 ✗ m->print_list(&bp, FF_FIELD_AT(void *, m->offset, out->incfg));
532
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ if (av_bprint_is_complete(&bp))
533 ✗ av_log(log_ctx, level, " %s: %s\n", m->name, bp.str);
534 ✗ av_bprint_clear(&bp);
535 }
536 }
537
538 ✗ av_bprint_finalize(&bp, NULL);
539 }
540
541 /**
542 * Perform one round of query_formats() and merging formats lists on the
543 * filter graph.
544 * @return >=0 if all links formats lists could be queried and merged;
545 * AVERROR(EAGAIN) some progress was made in the queries or merging
546 * and a later call may succeed;
547 * AVERROR(EIO) (may be changed) plus a log message if no progress
548 * was made and the negotiation is stuck;
549 * a negative error code if some other error happened
550 */
551 9025 static int query_formats(AVFilterGraph *graph, void *log_ctx)
552 {
553 int i, j, k, ret;
554 9025 int converter_count = 0;
555 9025 int count_queried = 0; /* successful calls to query_formats() */
556 9025 int count_merged = 0; /* successful merge of formats lists */
557 9025 int count_already_merged = 0; /* lists already merged */
558 9025 int count_delayed = 0; /* lists that need to be merged later */
559
560
2/2
✓ Branch 14 → 3 taken 47978 times.
✓ Branch 14 → 15 taken 9025 times.
57003 for (i = 0; i < graph->nb_filters; i++) {
561 47978 AVFilterContext *f = graph->filters[i];
562
2/2
✓ Branch 4 → 5 taken 57 times.
✓ Branch 4 → 6 taken 47921 times.
47978 if (formats_declared(f))
563 57 continue;
564 47921 ret = filter_query_formats(f);
565
3/4
✓ Branch 7 → 8 taken 17 times.
✓ Branch 7 → 10 taken 47904 times.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 17 times.
47921 if (ret < 0 && ret != AVERROR(EAGAIN))
566 ✗ return ret;
567 /* note: EAGAIN could indicate a partial success, not counted yet */
568
2/2
✓ Branch 10 → 11 taken 47904 times.
✓ Branch 10 → 13 taken 17 times.
47921 if (ret >= 0) {
569 47904 print_filter_formats(log_ctx, AV_LOG_TRACE, f);
570 47904 count_queried++;
571 }
572 }
573
574 /* go through and merge as many format lists as possible */
575 9025 retry:
576
2/2
✓ Branch 197 → 18 taken 79978 times.
✓ Branch 197 → 198 taken 9025 times.
89003 for (i = 0; i < graph->nb_filters; i++) {
577 79978 AVFilterContext *filter = graph->filters[i];
578
579
2/2
✓ Branch 195 → 19 taken 66977 times.
✓ Branch 195 → 196 taken 78335 times.
145312 for (j = 0; j < filter->nb_inputs; j++) {
580 66977 AVFilterLink *link = filter->inputs[j];
581 const AVFilterNegotiation *neg;
582 AVFilterContext *conv[4];
583 const AVFilterFormatsMerger *mergers[4]; /* triggered mergers */
584 66977 const char *conv_filters[4], *conv_opts[4] = {0};
585 66977 unsigned neg_step, num_conv = 0, num_mergers = 0;
586
587
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 66977 times.
66977 if (!link)
588 ✗ continue;
589
590 66977 neg = ff_filter_get_negotiation(link);
591
1/2
✗ Branch 22 → 23 not taken.
✓ Branch 22 → 25 taken 66977 times.
66977 av_assert0(neg);
592
2/2
✓ Branch 42 → 26 taken 272097 times.
✓ Branch 42 → 43 taken 66977 times.
339074 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
593 272097 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
594 272097 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
595 272097 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
596
8/8
✓ Branch 26 → 27 taken 272020 times.
✓ Branch 26 → 41 taken 77 times.
✓ Branch 27 → 28 taken 271933 times.
✓ Branch 27 → 41 taken 87 times.
✓ Branch 28 → 29 taken 182853 times.
✓ Branch 28 → 41 taken 89080 times.
✓ Branch 30 → 31 taken 1744 times.
✓ Branch 30 → 41 taken 181109 times.
272097 if (a && b && a != b && !m->can_merge(a, b)) {
597
2/2
✓ Branch 35 → 32 taken 101 times.
✓ Branch 35 → 36 taken 1643 times.
1744 for (k = 0; k < num_conv; k++) {
598
1/2
✓ Branch 32 → 33 taken 101 times.
✗ Branch 32 → 34 not taken.
101 if (!strcmp(conv_filters[k], m->conversion_filter))
599 101 break;
600 }
601
2/2
✓ Branch 36 → 37 taken 1643 times.
✓ Branch 36 → 40 taken 101 times.
1744 if (k == num_conv) {
602 av_assert1(num_conv < FF_ARRAY_ELEMS(conv_filters));
603 1643 conv_filters[num_conv] = m->conversion_filter;
604
2/2
✓ Branch 37 → 38 taken 1642 times.
✓ Branch 37 → 39 taken 1 time.
1643 if (m->conversion_opts_offset)
605 1642 conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
606 1643 num_conv++;
607 }
608 av_assert1(num_mergers < FF_ARRAY_ELEMS(mergers));
609 1744 mergers[num_mergers++] = m;
610 }
611 }
612
2/2
✓ Branch 58 → 44 taken 272097 times.
✓ Branch 58 → 59 taken 66977 times.
339074 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
613 272097 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
614 272097 void *a = FF_FIELD_AT(void *, m->offset, link->incfg);
615 272097 void *b = FF_FIELD_AT(void *, m->offset, link->outcfg);
616
4/4
✓ Branch 44 → 45 taken 272020 times.
✓ Branch 44 → 46 taken 77 times.
✓ Branch 45 → 46 taken 87 times.
✓ Branch 45 → 47 taken 271933 times.
272097 if (!(a && b)) {
617 164 count_delayed++;
618
2/2
✓ Branch 47 → 48 taken 95277 times.
✓ Branch 47 → 49 taken 176656 times.
271933 } else if (a == b) {
619 95277 count_already_merged++;
620
2/2
✓ Branch 49 → 50 taken 170862 times.
✓ Branch 49 → 57 taken 5794 times.
176656 } else if (!num_conv) {
621 170862 count_merged++;
622 170862 ret = m->merge(a, b);
623
1/2
✗ Branch 51 → 52 not taken.
✓ Branch 51 → 53 taken 170862 times.
170862 if (ret < 0)
624 ✗ return ret;
625
1/2
✗ Branch 53 → 54 not taken.
✓ Branch 53 → 57 taken 170862 times.
170862 if (!ret) {
626 ✗ mergers[num_mergers++] = m;
627 ✗ conv_filters[num_conv] = m->conversion_filter;
628
0/2
✗ Branch 54 → 55 not taken.
✗ Branch 54 → 56 not taken.
✗ if (m->conversion_opts_offset)
629 ✗ conv_opts[num_conv] = FF_FIELD_AT(char *, m->conversion_opts_offset, *graph);
630 ✗ num_conv++;
631 }
632 }
633 }
634
635 /**
636 * Couldn't merge format lists; auto-insert conversion filters
637 * in reverse order to keep the order consistent with the list
638 * of mergers, since they are prepended onto the existing link
639 */
640
2/2
✓ Branch 81 → 60 taken 1643 times.
✓ Branch 81 → 82 taken 66977 times.
68620 for (k = num_conv - 1; k >= 0; k--) {
641 const AVFilter *filter;
642 char inst_name[30];
643
644
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 65 taken 1643 times.
1643 if (fffiltergraph(graph)->disable_auto_convert) {
645 ✗ av_log(log_ctx, AV_LOG_ERROR,
646 "The filters '%s' and '%s' do not have a common format "
647 "and automatic conversion is disabled.\n",
648 ✗ link->src->name, link->dst->name);
649 ✗ print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
650 ✗ return AVERROR(EINVAL);
651 }
652
653
1/2
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 70 taken 1643 times.
1643 if (!(filter = avfilter_get_by_name(conv_filters[k]))) {
654 ✗ av_log(log_ctx, AV_LOG_ERROR,
655 "'%s' filter not present, cannot convert formats.\n",
656 conv_filters[k]);
657 ✗ print_link_formats(log_ctx, AV_LOG_ERROR, link, mergers, num_mergers);
658 ✗ return AVERROR(EINVAL);
659 }
660 1643 snprintf(inst_name, sizeof(inst_name), "auto_%s_%d",
661 conv_filters[k], converter_count++);
662 1643 ret = avfilter_graph_create_filter(&conv[k], filter, inst_name,
663 conv_opts[k], NULL, graph);
664
1/2
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 1643 times.
1643 if (ret < 0)
665 ✗ return ret;
666
1/2
✗ Branch 74 → 75 not taken.
✓ Branch 74 → 76 taken 1643 times.
1643 if ((ret = avfilter_insert_filter(link, conv[k], 0, 0)) < 0)
667 ✗ return ret;
668
669
1/2
✗ Branch 77 → 78 not taken.
✓ Branch 77 → 79 taken 1643 times.
1643 if ((ret = filter_query_formats(conv[k])) < 0)
670 ✗ return ret;
671 }
672
673 /* preemptively settle formats of auto filters */
674
2/2
✓ Branch 188 → 83 taken 1643 times.
✓ Branch 188 → 189 taken 66977 times.
68620 for (k = 0; k < num_conv; k++) {
675 1643 AVFilterLink *inlink = conv[k]->inputs[0];
676 1643 AVFilterLink *outlink = conv[k]->outputs[0];
677
1/2
✗ Branch 83 → 84 not taken.
✓ Branch 83 → 86 taken 1643 times.
1643 av_assert0( inlink->incfg.formats->refcount > 0);
678
1/2
✗ Branch 86 → 87 not taken.
✓ Branch 86 → 89 taken 1643 times.
1643 av_assert0( inlink->outcfg.formats->refcount > 0);
679
1/2
✗ Branch 89 → 90 not taken.
✓ Branch 89 → 92 taken 1643 times.
1643 av_assert0(outlink->incfg.formats->refcount > 0);
680
1/2
✗ Branch 92 → 93 not taken.
✓ Branch 92 → 95 taken 1643 times.
1643 av_assert0(outlink->outcfg.formats->refcount > 0);
681
2/2
✓ Branch 95 → 96 taken 778 times.
✓ Branch 95 → 144 taken 865 times.
1643 if (outlink->type == AVMEDIA_TYPE_VIDEO) {
682
1/2
✗ Branch 96 → 97 not taken.
✓ Branch 96 → 99 taken 778 times.
778 av_assert0( inlink-> incfg.color_spaces->refcount > 0);
683
1/2
✗ Branch 99 → 100 not taken.
✓ Branch 99 → 102 taken 778 times.
778 av_assert0( inlink->outcfg.color_spaces->refcount > 0);
684
1/2
✗ Branch 102 → 103 not taken.
✓ Branch 102 → 105 taken 778 times.
778 av_assert0(outlink-> incfg.color_spaces->refcount > 0);
685
1/2
✗ Branch 105 → 106 not taken.
✓ Branch 105 → 108 taken 778 times.
778 av_assert0(outlink->outcfg.color_spaces->refcount > 0);
686
1/2
✗ Branch 108 → 109 not taken.
✓ Branch 108 → 111 taken 778 times.
778 av_assert0( inlink-> incfg.color_ranges->refcount > 0);
687
1/2
✗ Branch 111 → 112 not taken.
✓ Branch 111 → 114 taken 778 times.
778 av_assert0( inlink->outcfg.color_ranges->refcount > 0);
688
1/2
✗ Branch 114 → 115 not taken.
✓ Branch 114 → 117 taken 778 times.
778 av_assert0(outlink-> incfg.color_ranges->refcount > 0);
689
1/2
✗ Branch 117 → 118 not taken.
✓ Branch 117 → 120 taken 778 times.
778 av_assert0(outlink->outcfg.color_ranges->refcount > 0);
690
1/2
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 123 taken 778 times.
778 av_assert0( inlink-> incfg.alpha_modes->refcount > 0);
691
1/2
✗ Branch 123 → 124 not taken.
✓ Branch 123 → 126 taken 778 times.
778 av_assert0( inlink->outcfg.alpha_modes->refcount > 0);
692
1/2
✗ Branch 126 → 127 not taken.
✓ Branch 126 → 129 taken 778 times.
778 av_assert0(outlink-> incfg.alpha_modes->refcount > 0);
693
1/2
✗ Branch 129 → 130 not taken.
✓ Branch 129 → 132 taken 778 times.
778 av_assert0(outlink->outcfg.alpha_modes->refcount > 0);
694
1/2
✗ Branch 132 → 133 not taken.
✓ Branch 132 → 135 taken 778 times.
778 av_assert0( inlink-> incfg.chroma_locations->refcount > 0);
695
1/2
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 138 taken 778 times.
778 av_assert0( inlink->outcfg.chroma_locations->refcount > 0);
696
1/2
✗ Branch 138 → 139 not taken.
✓ Branch 138 → 141 taken 778 times.
778 av_assert0(outlink-> incfg.chroma_locations->refcount > 0);
697
1/2
✗ Branch 141 → 142 not taken.
✓ Branch 141 → 169 taken 778 times.
778 av_assert0(outlink->outcfg.chroma_locations->refcount > 0);
698
1/2
✓ Branch 144 → 145 taken 865 times.
✗ Branch 144 → 169 not taken.
865 } else if (outlink->type == AVMEDIA_TYPE_AUDIO) {
699
1/2
✗ Branch 145 → 146 not taken.
✓ Branch 145 → 148 taken 865 times.
865 av_assert0( inlink-> incfg.samplerates->refcount > 0);
700
1/2
✗ Branch 148 → 149 not taken.
✓ Branch 148 → 151 taken 865 times.
865 av_assert0( inlink->outcfg.samplerates->refcount > 0);
701
1/2
✗ Branch 151 → 152 not taken.
✓ Branch 151 → 154 taken 865 times.
865 av_assert0(outlink-> incfg.samplerates->refcount > 0);
702
1/2
✗ Branch 154 → 155 not taken.
✓ Branch 154 → 157 taken 865 times.
865 av_assert0(outlink->outcfg.samplerates->refcount > 0);
703
1/2
✗ Branch 157 → 158 not taken.
✓ Branch 157 → 160 taken 865 times.
865 av_assert0( inlink-> incfg.channel_layouts->refcount > 0);
704
1/2
✗ Branch 160 → 161 not taken.
✓ Branch 160 → 163 taken 865 times.
865 av_assert0( inlink->outcfg.channel_layouts->refcount > 0);
705
1/2
✗ Branch 163 → 164 not taken.
✓ Branch 163 → 166 taken 865 times.
865 av_assert0(outlink-> incfg.channel_layouts->refcount > 0);
706
1/2
✗ Branch 166 → 167 not taken.
✓ Branch 166 → 169 taken 865 times.
865 av_assert0(outlink->outcfg.channel_layouts->refcount > 0);
707 }
708
709 #define MERGE(merger, link) \
710 ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \
711 FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg)))
712
713
2/2
✓ Branch 186 → 170 taken 6485 times.
✓ Branch 186 → 187 taken 1643 times.
8128 for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) {
714 6485 const AVFilterFormatsMerger *m = &neg->mergers[neg_step];
715
2/2
✓ Branch 170 → 171 taken 781 times.
✓ Branch 170 → 172 taken 5704 times.
6485 if (strcmp(m->conversion_filter, conv_filters[k]))
716 781 continue;
717
2/4
✓ Branch 173 → 174 taken 5704 times.
✗ Branch 173 → 176 not taken.
✗ Branch 175 → 176 not taken.
✓ Branch 175 → 182 taken 5704 times.
11408 if ((ret = MERGE(m, inlink)) <= 0 ||
718 5704 (ret = MERGE(m, outlink)) <= 0) {
719
0/2
✗ Branch 176 → 177 not taken.
✗ Branch 176 → 178 not taken.
✗ if (ret < 0)
720 ✗ return ret;
721 ✗ av_log(log_ctx, AV_LOG_ERROR,
722 "Impossible to convert between the formats supported by the filter "
723 ✗ "'%s' and the filter '%s'\n", link->src->name, link->dst->name);
724 ✗ print_link_formats(log_ctx, AV_LOG_ERROR, inlink, &m, 1);
725 ✗ print_link_formats(log_ctx, AV_LOG_ERROR, outlink, &m, 1);
726 ✗ return AVERROR(ENOSYS);
727 } else {
728 5704 count_merged += 2;
729 }
730 }
731 }
732
733 /* if there is an auto filter, we may need another round to fully
734 * settle formats due to possible cross-incompatibilities between
735 * the auto filters themselves, or between the auto filters and
736 * a different attribute of the filter they are modifying */
737
2/2
✓ Branch 189 → 190 taken 1643 times.
✓ Branch 189 → 191 taken 65334 times.
66977 if (num_conv)
738 1643 goto retry;
739 }
740 }
741
742 9025 av_log(graph, AV_LOG_DEBUG, "query_formats: "
743 "%d queried, %d merged, %d already done, %d delayed\n",
744 count_queried, count_merged, count_already_merged, count_delayed);
745
2/2
✓ Branch 199 → 200 taken 15 times.
✓ Branch 199 → 216 taken 9010 times.
9025 if (count_delayed) {
746 AVBPrint bp;
747
748 /* if count_queried > 0, one filter at least did set its formats,
749 that will give additional information to its neighbour;
750 if count_merged > 0, one pair of formats lists at least was merged,
751 that will give additional information to all connected filters;
752 in both cases, progress was made and a new round must be done */
753
1/4
✗ Branch 200 → 201 not taken.
✓ Branch 200 → 202 taken 15 times.
✗ Branch 201 → 202 not taken.
✗ Branch 201 → 203 not taken.
15 if (count_queried || count_merged)
754 15 return AVERROR(EAGAIN);
755 ✗ av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
756
0/2
✗ Branch 212 → 205 not taken.
✗ Branch 212 → 213 not taken.
✗ for (i = 0; i < graph->nb_filters; i++)
757
0/2
✗ Branch 206 → 207 not taken.
✗ Branch 206 → 211 not taken.
✗ if (!formats_declared(graph->filters[i]))
758 ✗ av_bprintf(&bp, "%s%s", bp.len ? ", " : "",
759
0/2
✗ Branch 207 → 208 not taken.
✗ Branch 207 → 209 not taken.
✗ graph->filters[i]->name);
760 ✗ av_log(graph, AV_LOG_ERROR,
761 "The following filters could not choose their formats: %s\n"
762 "Consider inserting the (a)format filter near their input or "
763 "output.\n", bp.str);
764 ✗ return AVERROR(EIO);
765 }
766 9010 return 0;
767 }
768
769 1342 static int get_fmt_score(enum AVSampleFormat dst_fmt, enum AVSampleFormat src_fmt)
770 {
771 1342 int score = 0;
772
773
2/2
✓ Branch 4 → 5 taken 1242 times.
✓ Branch 4 → 6 taken 100 times.
1342 if (av_sample_fmt_is_planar(dst_fmt) != av_sample_fmt_is_planar(src_fmt))
774 1242 score ++;
775
776
2/2
✓ Branch 8 → 9 taken 339 times.
✓ Branch 8 → 12 taken 1003 times.
1342 if (av_get_bytes_per_sample(dst_fmt) < av_get_bytes_per_sample(src_fmt)) {
777 339 score += 100 * (av_get_bytes_per_sample(src_fmt) - av_get_bytes_per_sample(dst_fmt));
778 }else
779 1003 score += 10 * (av_get_bytes_per_sample(dst_fmt) - av_get_bytes_per_sample(src_fmt));
780
781
4/4
✓ Branch 16 → 17 taken 163 times.
✓ Branch 16 → 20 taken 1179 times.
✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 20 taken 161 times.
1505 if (av_get_packed_sample_fmt(dst_fmt) == AV_SAMPLE_FMT_S32 &&
782 163 av_get_packed_sample_fmt(src_fmt) == AV_SAMPLE_FMT_FLT)
783 2 score += 20;
784
785
3/4
✓ Branch 21 → 22 taken 115 times.
✓ Branch 21 → 25 taken 1227 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 115 times.
1457 if (av_get_packed_sample_fmt(dst_fmt) == AV_SAMPLE_FMT_FLT &&
786 115 av_get_packed_sample_fmt(src_fmt) == AV_SAMPLE_FMT_S32)
787 ✗ score += 2;
788
789 1342 return score;
790 }
791
792 671 static enum AVSampleFormat find_best_sample_fmt_of_2(enum AVSampleFormat dst_fmt1, enum AVSampleFormat dst_fmt2,
793 enum AVSampleFormat src_fmt)
794 {
795 int score1, score2;
796
797 671 score1 = get_fmt_score(dst_fmt1, src_fmt);
798 671 score2 = get_fmt_score(dst_fmt2, src_fmt);
799
800
2/2
✓ Branch 4 → 5 taken 507 times.
✓ Branch 4 → 6 taken 164 times.
671 return score1 < score2 ? dst_fmt1 : dst_fmt2;
801 }
802
803 39371 int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt)
804 {
805 39371 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
806
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 39371 times.
39371 if (!desc)
807 ✗ return 0;
808
2/2
✓ Branch 5 → 6 taken 1940 times.
✓ Branch 5 → 7 taken 37431 times.
39371 if (desc->nb_components < 3)
809 1940 return 0; /* Grayscale is explicitly full-range in swscale */
810 av_assert1(!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL));
811 37431 return !(desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_PAL |
812 AV_PIX_FMT_FLAG_XYZ | AV_PIX_FMT_FLAG_FLOAT));
813 }
814
815
816 28355 int ff_fmt_is_forced_full_range(enum AVPixelFormat fmt)
817 {
818
2/2
✓ Branch 2 → 3 taken 787 times.
✓ Branch 2 → 4 taken 27568 times.
28355 switch (fmt) {
819 787 case AV_PIX_FMT_YUVJ420P:
820 case AV_PIX_FMT_YUVJ422P:
821 case AV_PIX_FMT_YUVJ444P:
822 case AV_PIX_FMT_YUVJ440P:
823 case AV_PIX_FMT_YUVJ411P:
824 787 return 1;
825 27568 default:
826 27568 return 0;
827 }
828 }
829
830 121416 static int pick_format(AVFilterLink *link, AVFilterLink *ref)
831 {
832
3/4
✓ Branch 2 → 3 taken 121416 times.
✗ Branch 2 → 4 not taken.
✓ Branch 3 → 4 taken 80908 times.
✓ Branch 3 → 5 taken 40508 times.
121416 if (!link || !link->incfg.formats)
833 80908 return 0;
834
835
2/2
✓ Branch 5 → 6 taken 33172 times.
✓ Branch 5 → 17 taken 7336 times.
40508 if (link->type == AVMEDIA_TYPE_VIDEO) {
836
3/4
✓ Branch 6 → 7 taken 116 times.
✓ Branch 6 → 28 taken 33056 times.
✓ Branch 7 → 8 taken 116 times.
✗ Branch 7 → 28 not taken.
33172 if(ref && ref->type == AVMEDIA_TYPE_VIDEO){
837 //FIXME: This should check for AV_PIX_FMT_FLAG_ALPHA after PAL8 pixel format without alpha is implemented
838 116 int has_alpha= av_pix_fmt_desc_get(ref->format)->nb_components % 2 == 0;
839 116 enum AVPixelFormat best= AV_PIX_FMT_NONE;
840 int i;
841
2/2
✓ Branch 12 → 10 taken 1133 times.
✓ Branch 12 → 13 taken 116 times.
1249 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
842 1133 enum AVPixelFormat p = link->incfg.formats->formats[i];
843 1133 best= av_find_best_pix_fmt_of_2(best, p, ref->format, has_alpha, NULL);
844 }
845 116 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s alpha:%d\n",
846 116 av_get_pix_fmt_name(best), link->incfg.formats->nb_formats,
847 116 av_get_pix_fmt_name(ref->format), has_alpha);
848 116 link->incfg.formats->formats[0] = best;
849 }
850
1/2
✓ Branch 17 → 18 taken 7336 times.
✗ Branch 17 → 28 not taken.
7336 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
851
3/4
✓ Branch 18 → 19 taken 164 times.
✓ Branch 18 → 28 taken 7172 times.
✓ Branch 19 → 20 taken 164 times.
✗ Branch 19 → 28 not taken.
7336 if(ref && ref->type == AVMEDIA_TYPE_AUDIO){
852 164 enum AVSampleFormat best= AV_SAMPLE_FMT_NONE;
853 int i;
854
2/2
✓ Branch 23 → 21 taken 671 times.
✓ Branch 23 → 24 taken 164 times.
835 for (i = 0; i < link->incfg.formats->nb_formats; i++) {
855 671 enum AVSampleFormat p = link->incfg.formats->formats[i];
856 671 best = find_best_sample_fmt_of_2(best, p, ref->format);
857 }
858 164 av_log(link->src,AV_LOG_DEBUG, "picking %s out of %d ref:%s\n",
859 164 av_get_sample_fmt_name(best), link->incfg.formats->nb_formats,
860 164 av_get_sample_fmt_name(ref->format));
861 164 link->incfg.formats->formats[0] = best;
862 }
863 }
864
865 40508 link->incfg.formats->nb_formats = 1;
866 40508 link->format = link->incfg.formats->formats[0];
867
868
2/2
✓ Branch 28 → 29 taken 33172 times.
✓ Branch 28 → 65 taken 7336 times.
40508 if (link->type == AVMEDIA_TYPE_VIDEO) {
869 33172 enum AVPixelFormat swfmt = link->format;
870
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 33172 times.
33172 if (av_pix_fmt_desc_get(swfmt)->flags & AV_PIX_FMT_FLAG_HWACCEL) {
871 // FIXME: this is a hack - we'd like to use the sw_format of
872 // link->hw_frames_ctx here, but it is not yet available.
873 // To make this work properly we will need to either reorder
874 // things so that it is available here or somehow negotiate
875 // sw_format separately.
876 ✗ swfmt = AV_PIX_FMT_YUV420P;
877 }
878
879 33172 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(swfmt);
880
2/2
✓ Branch 34 → 35 taken 10285 times.
✓ Branch 34 → 41 taken 22887 times.
33172 if (!ff_fmt_is_regular_yuv(swfmt)) {
881 /* These fields are explicitly documented as affecting YUV only,
882 * so set them to sane values for other formats. */
883
2/2
✓ Branch 35 → 36 taken 914 times.
✓ Branch 35 → 37 taken 9371 times.
10285 if (desc->flags & AV_PIX_FMT_FLAG_FLOAT)
884 914 link->color_range = AVCOL_RANGE_UNSPECIFIED;
885 else
886 9371 link->color_range = AVCOL_RANGE_JPEG;
887
2/2
✓ Branch 38 → 39 taken 8547 times.
✓ Branch 38 → 40 taken 1738 times.
10285 if (desc->flags & (AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_XYZ)) {
888 8547 link->colorspace = AVCOL_SPC_RGB;
889 } else {
890 1738 link->colorspace = AVCOL_SPC_UNSPECIFIED;
891 }
892 } else {
893
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 44 taken 22887 times.
22887 if (!link->incfg.color_spaces->nb_formats) {
894 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select color space for"
895 ✗ " the link between filters %s and %s.\n", link->src->name,
896 ✗ link->dst->name);
897 ✗ return AVERROR(EINVAL);
898 }
899 22887 link->incfg.color_spaces->nb_formats = 1;
900 22887 link->colorspace = link->incfg.color_spaces->formats[0];
901
902
2/2
✓ Branch 45 → 46 taken 706 times.
✓ Branch 45 → 47 taken 22181 times.
22887 if (ff_fmt_is_forced_full_range(swfmt)) {
903 706 link->color_range = AVCOL_RANGE_JPEG;
904 } else {
905
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 50 taken 22181 times.
22181 if (!link->incfg.color_ranges->nb_formats) {
906 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select color range for"
907 ✗ " the link between filters %s and %s.\n", link->src->name,
908 ✗ link->dst->name);
909 ✗ return AVERROR(EINVAL);
910 }
911 22181 link->incfg.color_ranges->nb_formats = 1;
912 22181 link->color_range = link->incfg.color_ranges->formats[0];
913 }
914 }
915
916
2/2
✓ Branch 51 → 52 taken 3999 times.
✓ Branch 51 → 56 taken 29173 times.
33172 if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) {
917
1/2
✗ Branch 52 → 53 not taken.
✓ Branch 52 → 55 taken 3999 times.
3999 if (!link->incfg.alpha_modes->nb_formats) {
918 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select alpha mode for"
919 ✗ " the link between filters %s and %s.\n", link->src->name,
920 ✗ link->dst->name);
921 ✗ return AVERROR(EINVAL);
922 }
923 3999 link->incfg.alpha_modes->nb_formats = 1;
924 3999 link->alpha_mode = link->incfg.alpha_modes->formats[0];
925 } else {
926 29173 link->alpha_mode = AVALPHA_MODE_UNSPECIFIED;
927 }
928
929
4/4
✓ Branch 57 → 58 taken 17619 times.
✓ Branch 57 → 59 taken 15553 times.
✓ Branch 58 → 59 taken 512 times.
✓ Branch 58 → 63 taken 17107 times.
33172 if (desc->log2_chroma_w || desc->log2_chroma_h) {
930
1/2
✗ Branch 59 → 60 not taken.
✓ Branch 59 → 62 taken 16065 times.
16065 if (!link->incfg.chroma_locations->nb_formats) {
931 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select chroma location"
932 ✗ " for the link between filters %s and %s.\n", link->src->name,
933 ✗ link->dst->name);
934 ✗ return AVERROR(EINVAL);
935 }
936 16065 link->incfg.chroma_locations->nb_formats = 1;
937 16065 link->chroma_location = link->incfg.chroma_locations->formats[0];
938 } else {
939 /* Chroma location is meaningless without subsampled chroma. */
940 17107 link->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
941 }
942
1/2
✓ Branch 65 → 66 taken 7336 times.
✗ Branch 65 → 77 not taken.
7336 } else if (link->type == AVMEDIA_TYPE_AUDIO) {
943 int ret;
944
945
1/2
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 69 taken 7336 times.
7336 if (!link->incfg.samplerates->nb_formats) {
946 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select sample rate for"
947 ✗ " the link between filters %s and %s.\n", link->src->name,
948 ✗ link->dst->name);
949 ✗ return AVERROR(EINVAL);
950 }
951 7336 link->incfg.samplerates->nb_formats = 1;
952 7336 link->sample_rate = link->incfg.samplerates->formats[0];
953
954
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 74 taken 7336 times.
7336 if (link->incfg.channel_layouts->all_layouts) {
955 ✗ av_log(link->src, AV_LOG_ERROR, "Cannot select channel layout for"
956 ✗ " the link between filters %s and %s.\n", link->src->name,
957 ✗ link->dst->name);
958
0/2
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ if (!link->incfg.channel_layouts->all_counts)
959 ✗ av_log(link->src, AV_LOG_ERROR, "Unknown channel layouts not "
960 "supported, try specifying a channel layout using "
961 "'aformat=channel_layouts=something'.\n");
962 ✗ return AVERROR(EINVAL);
963 }
964 7336 link->incfg.channel_layouts->nb_channel_layouts = 1;
965 7336 ret = av_channel_layout_copy(&link->ch_layout, &link->incfg.channel_layouts->channel_layouts[0]);
966
1/2
✗ Branch 75 → 76 not taken.
✓ Branch 75 → 77 taken 7336 times.
7336 if (ret < 0)
967 ✗ return ret;
968 }
969
970 40508 ff_formats_unref(&link->incfg.formats);
971 40508 ff_formats_unref(&link->outcfg.formats);
972 40508 ff_formats_unref(&link->incfg.samplerates);
973 40508 ff_formats_unref(&link->outcfg.samplerates);
974 40508 ff_channel_layouts_unref(&link->incfg.channel_layouts);
975 40508 ff_channel_layouts_unref(&link->outcfg.channel_layouts);
976 40508 ff_formats_unref(&link->incfg.color_spaces);
977 40508 ff_formats_unref(&link->outcfg.color_spaces);
978 40508 ff_formats_unref(&link->incfg.color_ranges);
979 40508 ff_formats_unref(&link->outcfg.color_ranges);
980 40508 ff_formats_unref(&link->incfg.alpha_modes);
981 40508 ff_formats_unref(&link->outcfg.alpha_modes);
982 40508 ff_formats_unref(&link->incfg.chroma_locations);
983 40508 ff_formats_unref(&link->outcfg.chroma_locations);
984
985 40508 return 0;
986 }
987
988 #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
989 do { \
990 for (i = 0; i < filter->nb_inputs; i++) { \
991 AVFilterLink *link = filter->inputs[i]; \
992 fmt_type fmt; \
993 \
994 if (!link->outcfg.list || link->outcfg.list->nb != 1) \
995 continue; \
996 fmt = link->outcfg.list->var[0]; \
997 \
998 for (j = 0; j < filter->nb_outputs; j++) { \
999 AVFilterLink *out_link = filter->outputs[j]; \
1000 list_type *fmts; \
1001 \
1002 if (link->type != out_link->type || \
1003 out_link->incfg.list->nb == 1) \
1004 continue; \
1005 fmts = out_link->incfg.list; \
1006 \
1007 if (!out_link->incfg.list->nb) { \
1008 if ((ret = add_format(&out_link->incfg.list, fmt)) < 0)\
1009 return ret; \
1010 ret = 1; \
1011 break; \
1012 } \
1013 \
1014 for (k = 0; k < out_link->incfg.list->nb; k++) \
1015 if (fmts->var[k] == fmt) { \
1016 fmts->var[0] = fmt; \
1017 fmts->nb = 1; \
1018 ret = 1; \
1019 break; \
1020 } \
1021 } \
1022 } \
1023 } while (0)
1024
1025 80351 static int reduce_formats_on_filter(AVFilterContext *filter)
1026 {
1027 80351 int i, j, k, ret = 0;
1028
1029
16/20
✓ Branch 3 → 4 taken 65986 times.
✗ Branch 3 → 5 not taken.
✓ Branch 4 → 5 taken 1616 times.
✓ Branch 4 → 6 taken 64370 times.
✓ Branch 7 → 8 taken 50356 times.
✓ Branch 7 → 9 taken 12 times.
✓ Branch 8 → 9 taken 49439 times.
✓ Branch 8 → 10 taken 917 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 15 taken 917 times.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✓ Branch 16 → 17 taken 344 times.
✓ Branch 16 → 18 taken 19719 times.
✓ Branch 19 → 16 taken 20063 times.
✓ Branch 19 → 20 taken 573 times.
✓ Branch 21 → 7 taken 50368 times.
✓ Branch 21 → 22 taken 64370 times.
✓ Branch 23 → 3 taken 65986 times.
✓ Branch 23 → 24 taken 80351 times.
216424 REDUCE_FORMATS(int, AVFilterFormats, formats, formats,
1030 nb_formats, ff_add_format);
1031
18/20
✓ Branch 25 → 26 taken 13215 times.
✓ Branch 25 → 27 taken 52771 times.
✓ Branch 26 → 27 taken 1610 times.
✓ Branch 26 → 28 taken 11605 times.
✓ Branch 29 → 30 taken 9500 times.
✓ Branch 29 → 31 taken 6 times.
✓ Branch 30 → 31 taken 8442 times.
✓ Branch 30 → 32 taken 1058 times.
✓ Branch 32 → 33 taken 886 times.
✓ Branch 32 → 37 taken 172 times.
✗ Branch 34 → 35 not taken.
✓ Branch 34 → 36 taken 886 times.
✓ Branch 38 → 39 taken 172 times.
✓ Branch 38 → 40 taken 652 times.
✓ Branch 41 → 38 taken 824 times.
✗ Branch 41 → 42 not taken.
✓ Branch 43 → 29 taken 9506 times.
✓ Branch 43 → 44 taken 10719 times.
✓ Branch 45 → 25 taken 65986 times.
✓ Branch 45 → 46 taken 80351 times.
155609 REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
1032 nb_formats, ff_add_format);
1033
15/20
✓ Branch 47 → 48 taken 52771 times.
✓ Branch 47 → 49 taken 13215 times.
✓ Branch 48 → 49 taken 12336 times.
✓ Branch 48 → 50 taken 40435 times.
✓ Branch 51 → 52 taken 31914 times.
✗ Branch 51 → 53 not taken.
✓ Branch 52 → 53 taken 27225 times.
✓ Branch 52 → 54 taken 4689 times.
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 59 taken 4689 times.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✓ Branch 60 → 61 taken 4689 times.
✓ Branch 60 → 62 taken 527 times.
✓ Branch 63 → 60 taken 5216 times.
✗ Branch 63 → 64 not taken.
✓ Branch 65 → 51 taken 31914 times.
✓ Branch 65 → 66 taken 40435 times.
✓ Branch 67 → 47 taken 65986 times.
✓ Branch 67 → 68 taken 80351 times.
178778 REDUCE_FORMATS(int, AVFilterFormats, color_spaces, formats,
1034 nb_formats, ff_add_format);
1035
15/20
✓ Branch 69 → 70 taken 52771 times.
✓ Branch 69 → 71 taken 13215 times.
✓ Branch 70 → 71 taken 9371 times.
✓ Branch 70 → 72 taken 43400 times.
✓ Branch 73 → 74 taken 33189 times.
✗ Branch 73 → 75 not taken.
✓ Branch 74 → 75 taken 29521 times.
✓ Branch 74 → 76 taken 3668 times.
✗ Branch 76 → 77 not taken.
✓ Branch 76 → 81 taken 3668 times.
✗ Branch 78 → 79 not taken.
✗ Branch 78 → 80 not taken.
✓ Branch 82 → 83 taken 3668 times.
✓ Branch 82 → 84 taken 3655 times.
✓ Branch 85 → 82 taken 7323 times.
✗ Branch 85 → 86 not taken.
✓ Branch 87 → 73 taken 33189 times.
✓ Branch 87 → 88 taken 43400 times.
✓ Branch 89 → 69 taken 65986 times.
✓ Branch 89 → 90 taken 80351 times.
183181 REDUCE_FORMATS(int, AVFilterFormats, color_ranges, formats,
1036 nb_formats, ff_add_format);
1037
15/20
✓ Branch 91 → 92 taken 52771 times.
✓ Branch 91 → 93 taken 13215 times.
✓ Branch 92 → 93 taken 52120 times.
✓ Branch 92 → 94 taken 651 times.
✓ Branch 95 → 96 taken 505 times.
✗ Branch 95 → 97 not taken.
✓ Branch 96 → 97 taken 503 times.
✓ Branch 96 → 98 taken 2 times.
✗ Branch 98 → 99 not taken.
✓ Branch 98 → 103 taken 2 times.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 102 not taken.
✓ Branch 104 → 105 taken 2 times.
✓ Branch 104 → 106 taken 4 times.
✓ Branch 107 → 104 taken 6 times.
✗ Branch 107 → 108 not taken.
✓ Branch 109 → 95 taken 505 times.
✓ Branch 109 → 110 taken 651 times.
✓ Branch 111 → 91 taken 65986 times.
✓ Branch 111 → 112 taken 80351 times.
146846 REDUCE_FORMATS(int, AVFilterFormats, alpha_modes, formats,
1038 nb_formats, ff_add_format);
1039
16/20
✓ Branch 113 → 114 taken 52771 times.
✓ Branch 113 → 115 taken 13215 times.
✓ Branch 114 → 115 taken 45643 times.
✓ Branch 114 → 116 taken 7128 times.
✓ Branch 117 → 118 taken 5094 times.
✗ Branch 117 → 119 not taken.
✓ Branch 118 → 119 taken 4694 times.
✓ Branch 118 → 120 taken 400 times.
✗ Branch 120 → 121 not taken.
✓ Branch 120 → 125 taken 400 times.
✗ Branch 122 → 123 not taken.
✗ Branch 122 → 124 not taken.
✓ Branch 126 → 127 taken 398 times.
✓ Branch 126 → 128 taken 762 times.
✓ Branch 129 → 126 taken 1160 times.
✓ Branch 129 → 130 taken 2 times.
✓ Branch 131 → 117 taken 5094 times.
✓ Branch 131 → 132 taken 7128 times.
✓ Branch 133 → 113 taken 65986 times.
✓ Branch 133 → 134 taken 80351 times.
152193 REDUCE_FORMATS(int, AVFilterFormats, chroma_locations, formats,
1040 nb_formats, ff_add_format);
1041
1042 /* reduce channel layouts */
1043
2/2
✓ Branch 162 → 135 taken 65986 times.
✓ Branch 162 → 163 taken 80351 times.
146337 for (i = 0; i < filter->nb_inputs; i++) {
1044 65986 AVFilterLink *inlink = filter->inputs[i];
1045 const AVChannelLayout *fmt;
1046
1047
2/2
✓ Branch 135 → 136 taken 13215 times.
✓ Branch 135 → 137 taken 52771 times.
65986 if (!inlink->outcfg.channel_layouts ||
1048
2/2
✓ Branch 136 → 137 taken 336 times.
✓ Branch 136 → 138 taken 12879 times.
13215 inlink->outcfg.channel_layouts->nb_channel_layouts != 1)
1049 53107 continue;
1050 12879 fmt = &inlink->outcfg.channel_layouts->channel_layouts[0];
1051
1052
2/2
✓ Branch 160 → 139 taken 10307 times.
✓ Branch 160 → 161 taken 11976 times.
22283 for (j = 0; j < filter->nb_outputs; j++) {
1053 10307 AVFilterLink *outlink = filter->outputs[j];
1054 AVFilterChannelLayouts *fmts;
1055
1056 10307 fmts = outlink->incfg.channel_layouts;
1057
4/4
✓ Branch 139 → 140 taken 10301 times.
✓ Branch 139 → 141 taken 6 times.
✓ Branch 140 → 141 taken 9227 times.
✓ Branch 140 → 142 taken 1074 times.
10307 if (inlink->type != outlink->type || fmts->nb_channel_layouts == 1)
1058 9233 continue;
1059
1060
2/2
✓ Branch 142 → 143 taken 903 times.
✓ Branch 142 → 150 taken 171 times.
1074 if (fmts->all_layouts &&
1061
4/6
✓ Branch 143 → 144 taken 7 times.
✓ Branch 143 → 146 taken 896 times.
✓ Branch 144 → 145 taken 7 times.
✗ Branch 144 → 146 not taken.
✓ Branch 145 → 146 taken 7 times.
✗ Branch 145 → 150 not taken.
903 (KNOWN(fmt) || fmts->all_counts)) {
1062 /* Turn the infinite list into a singleton */
1063 903 fmts->all_layouts = fmts->all_counts = 0;
1064 903 ret = ff_add_channel_layout(&outlink->incfg.channel_layouts, fmt);
1065
1/2
✗ Branch 147 → 148 not taken.
✓ Branch 147 → 149 taken 903 times.
903 if (ret < 0)
1066 ✗ return ret;
1067 903 ret = 1;
1068 903 break;
1069 }
1070
1071
2/2
✓ Branch 158 → 151 taken 281 times.
✓ Branch 158 → 159 taken 8 times.
289 for (k = 0; k < outlink->incfg.channel_layouts->nb_channel_layouts; k++) {
1072
2/2
✓ Branch 152 → 153 taken 163 times.
✓ Branch 152 → 157 taken 118 times.
281 if (!av_channel_layout_compare(&fmts->channel_layouts[k], fmt)) {
1073 163 ret = av_channel_layout_copy(&fmts->channel_layouts[0], fmt);
1074
1/2
✗ Branch 154 → 155 not taken.
✓ Branch 154 → 156 taken 163 times.
163 if (ret < 0)
1075 ✗ return ret;
1076 163 fmts->nb_channel_layouts = 1;
1077 163 ret = 1;
1078 163 break;
1079 }
1080 }
1081 }
1082 }
1083
1084 80351 return ret;
1085 }
1086
1087 9010 static int reduce_formats(AVFilterGraph *graph)
1088 {
1089 int i, reduced, ret;
1090
1091 do {
1092 14301 reduced = 0;
1093
1094
2/2
✓ Branch 8 → 4 taken 80351 times.
✓ Branch 8 → 9 taken 14301 times.
94652 for (i = 0; i < graph->nb_filters; i++) {
1095
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 80351 times.
80351 if ((ret = reduce_formats_on_filter(graph->filters[i])) < 0)
1096 ✗ return ret;
1097 80351 reduced |= ret;
1098 }
1099
2/2
✓ Branch 9 → 10 taken 5291 times.
✓ Branch 9 → 11 taken 9010 times.
14301 } while (reduced);
1100
1101 9010 return 0;
1102 }
1103
1104 49547 static void swap_samplerates_on_filter(AVFilterContext *filter)
1105 {
1106 49547 AVFilterLink *link = NULL;
1107 int sample_rate;
1108 int i, j;
1109
1110
2/2
✓ Branch 7 → 3 taken 40417 times.
✓ Branch 7 → 8 taken 42298 times.
82715 for (i = 0; i < filter->nb_inputs; i++) {
1111 40417 link = filter->inputs[i];
1112
1113
2/2
✓ Branch 3 → 4 taken 7249 times.
✓ Branch 3 → 6 taken 33168 times.
40417 if (link->type == AVMEDIA_TYPE_AUDIO &&
1114
1/2
✓ Branch 4 → 5 taken 7249 times.
✗ Branch 4 → 6 not taken.
7249 link->outcfg.samplerates->nb_formats== 1)
1115 7249 break;
1116 }
1117
2/2
✓ Branch 8 → 9 taken 42298 times.
✓ Branch 8 → 10 taken 7249 times.
49547 if (i == filter->nb_inputs)
1118 42298 return;
1119
1120 7249 sample_rate = link->outcfg.samplerates->formats[0];
1121
1122
2/2
✓ Branch 24 → 11 taken 5642 times.
✓ Branch 24 → 25 taken 7249 times.
12891 for (i = 0; i < filter->nb_outputs; i++) {
1123 5642 AVFilterLink *outlink = filter->outputs[i];
1124 5642 int best_idx, best_diff = INT_MAX;
1125
1126
2/2
✓ Branch 11 → 12 taken 5640 times.
✓ Branch 11 → 13 taken 2 times.
5642 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1127
1/2
✓ Branch 12 → 13 taken 5640 times.
✗ Branch 12 → 14 not taken.
5640 outlink->incfg.samplerates->nb_formats < 2)
1128 5642 continue;
1129
1130
0/2
✗ Branch 21 → 15 not taken.
✗ Branch 21 → 22 not taken.
✗ for (j = 0; j < outlink->incfg.samplerates->nb_formats; j++) {
1131 ✗ int diff = abs(sample_rate - outlink->incfg.samplerates->formats[j]);
1132
1133
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 18 not taken.
✗ av_assert0(diff < INT_MAX); // This would lead to the use of uninitialized best_diff but is only possible with invalid sample rates
1134
1135
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ if (diff < best_diff) {
1136 ✗ best_diff = diff;
1137 ✗ best_idx = j;
1138 }
1139 }
1140 ✗ FFSWAP(int, outlink->incfg.samplerates->formats[0],
1141 outlink->incfg.samplerates->formats[best_idx]);
1142 }
1143 }
1144
1145 9010 static void swap_samplerates(AVFilterGraph *graph)
1146 {
1147 int i;
1148
1149
2/2
✓ Branch 5 → 3 taken 49547 times.
✓ Branch 5 → 6 taken 9010 times.
58557 for (i = 0; i < graph->nb_filters; i++)
1150 49547 swap_samplerates_on_filter(graph->filters[i]);
1151 9010 }
1152
1153 #define CH_CENTER_PAIR (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER)
1154 #define CH_FRONT_PAIR (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT)
1155 #define CH_STEREO_PAIR (AV_CH_STEREO_LEFT | AV_CH_STEREO_RIGHT)
1156 #define CH_WIDE_PAIR (AV_CH_WIDE_LEFT | AV_CH_WIDE_RIGHT)
1157 #define CH_SIDE_PAIR (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT)
1158 #define CH_DIRECT_PAIR (AV_CH_SURROUND_DIRECT_LEFT | AV_CH_SURROUND_DIRECT_RIGHT)
1159 #define CH_BACK_PAIR (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT)
1160
1161 /* allowable substitutions for channel pairs when comparing layouts,
1162 * ordered by priority for both values */
1163 static const uint64_t ch_subst[][2] = {
1164 { CH_FRONT_PAIR, CH_CENTER_PAIR },
1165 { CH_FRONT_PAIR, CH_WIDE_PAIR },
1166 { CH_FRONT_PAIR, AV_CH_FRONT_CENTER },
1167 { CH_CENTER_PAIR, CH_FRONT_PAIR },
1168 { CH_CENTER_PAIR, CH_WIDE_PAIR },
1169 { CH_CENTER_PAIR, AV_CH_FRONT_CENTER },
1170 { CH_WIDE_PAIR, CH_FRONT_PAIR },
1171 { CH_WIDE_PAIR, CH_CENTER_PAIR },
1172 { CH_WIDE_PAIR, AV_CH_FRONT_CENTER },
1173 { AV_CH_FRONT_CENTER, CH_FRONT_PAIR },
1174 { AV_CH_FRONT_CENTER, CH_CENTER_PAIR },
1175 { AV_CH_FRONT_CENTER, CH_WIDE_PAIR },
1176 { CH_SIDE_PAIR, CH_DIRECT_PAIR },
1177 { CH_SIDE_PAIR, CH_BACK_PAIR },
1178 { CH_SIDE_PAIR, AV_CH_BACK_CENTER },
1179 { CH_BACK_PAIR, CH_DIRECT_PAIR },
1180 { CH_BACK_PAIR, CH_SIDE_PAIR },
1181 { CH_BACK_PAIR, AV_CH_BACK_CENTER },
1182 { AV_CH_BACK_CENTER, CH_BACK_PAIR },
1183 { AV_CH_BACK_CENTER, CH_DIRECT_PAIR },
1184 { AV_CH_BACK_CENTER, CH_SIDE_PAIR },
1185 };
1186
1187 49547 static void swap_channel_layouts_on_filter(AVFilterContext *filter)
1188 {
1189 49547 AVFilterLink *link = NULL;
1190 int i, j, k;
1191
1192
2/2
✓ Branch 7 → 3 taken 40417 times.
✓ Branch 7 → 8 taken 42306 times.
82723 for (i = 0; i < filter->nb_inputs; i++) {
1193 40417 link = filter->inputs[i];
1194
1195
2/2
✓ Branch 3 → 4 taken 7249 times.
✓ Branch 3 → 6 taken 33168 times.
40417 if (link->type == AVMEDIA_TYPE_AUDIO &&
1196
2/2
✓ Branch 4 → 5 taken 7241 times.
✓ Branch 4 → 6 taken 8 times.
7249 link->outcfg.channel_layouts->nb_channel_layouts == 1)
1197 7241 break;
1198 }
1199
2/2
✓ Branch 8 → 9 taken 42306 times.
✓ Branch 8 → 10 taken 7241 times.
49547 if (i == filter->nb_inputs)
1200 42306 return;
1201
1202
2/2
✓ Branch 69 → 11 taken 5638 times.
✓ Branch 69 → 70 taken 7241 times.
12879 for (i = 0; i < filter->nb_outputs; i++) {
1203 5638 AVFilterLink *outlink = filter->outputs[i];
1204 5638 int best_idx = -1, best_score = INT_MIN, best_count_diff = INT_MAX;
1205
1206
2/2
✓ Branch 11 → 12 taken 5636 times.
✓ Branch 11 → 13 taken 2 times.
5638 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1207
2/2
✓ Branch 12 → 13 taken 5632 times.
✓ Branch 12 → 14 taken 4 times.
5636 outlink->incfg.channel_layouts->nb_channel_layouts < 2)
1208 5634 continue;
1209
1210
2/2
✓ Branch 63 → 15 taken 39 times.
✓ Branch 63 → 64 taken 4 times.
43 for (j = 0; j < outlink->incfg.channel_layouts->nb_channel_layouts; j++) {
1211 39 AVChannelLayout in_chlayout = link->outcfg.channel_layouts->channel_layouts[0];
1212 39 AVChannelLayout out_chlayout = outlink->incfg.channel_layouts->channel_layouts[j];
1213 int in_channels;
1214 int out_channels;
1215 int count_diff;
1216 int matched_channels, extra_channels;
1217 39 int score = 100000;
1218
1219 39 in_channels = in_chlayout.nb_channels;
1220 39 out_channels = out_chlayout.nb_channels;
1221 39 count_diff = out_channels - in_channels;
1222
4/8
✓ Branch 15 → 16 taken 16 times.
✓ Branch 15 → 17 taken 23 times.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 19 taken 16 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 33 taken 23 times.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 33 not taken.
39 if (!KNOWN(&in_chlayout) || !KNOWN(&out_chlayout)) {
1223 /* Compute score in case the input or output layout encodes
1224 a channel count; in this case the score is not altered by
1225 the computation afterwards, as in_chlayout and
1226 out_chlayout have both been set to 0 */
1227
2/4
✓ Branch 19 → 20 taken 16 times.
✗ Branch 19 → 24 not taken.
✓ Branch 20 → 21 taken 16 times.
✗ Branch 20 → 24 not taken.
16 if (!KNOWN(&in_chlayout))
1228
1/2
✓ Branch 21 → 22 taken 16 times.
✗ Branch 21 → 23 not taken.
16 in_channels = FF_LAYOUT2COUNT(&in_chlayout);
1229
1/4
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 29 taken 16 times.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 29 not taken.
16 if (!KNOWN(&out_chlayout))
1230
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ out_channels = FF_LAYOUT2COUNT(&out_chlayout);
1231 32 score -= 10000 + FFABS(out_channels - in_channels) +
1232
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 16 times.
16 (in_channels > out_channels ? 10000 : 0);
1233 16 in_chlayout = (AVChannelLayout){ 0 };
1234 16 out_chlayout = (AVChannelLayout){ 0 };
1235 /* Let the remaining computation run, even if the score
1236 value is not altered */
1237 }
1238
1239 /* channel substitution */
1240
2/2
✓ Branch 48 → 34 taken 819 times.
✓ Branch 48 → 49 taken 39 times.
858 for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
1241 819 uint64_t cmp0 = ch_subst[k][0];
1242 819 uint64_t cmp1 = ch_subst[k][1];
1243
4/4
✓ Branch 35 → 36 taken 258 times.
✓ Branch 35 → 47 taken 561 times.
✓ Branch 37 → 38 taken 141 times.
✓ Branch 37 → 47 taken 117 times.
1077 if ( av_channel_layout_subset(& in_chlayout, cmp0) &&
1244
2/2
✓ Branch 39 → 40 taken 26 times.
✓ Branch 39 → 47 taken 115 times.
399 !av_channel_layout_subset(&out_chlayout, cmp0) &&
1245
2/2
✓ Branch 41 → 42 taken 7 times.
✓ Branch 41 → 47 taken 19 times.
167 av_channel_layout_subset(&out_chlayout, cmp1) &&
1246 26 !av_channel_layout_subset(& in_chlayout, cmp1)) {
1247 7 av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(& in_chlayout, ~cmp0));
1248 7 av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~cmp1));
1249 /* add score for channel match, minus a deduction for
1250 having to do the substitution */
1251 7 score += 10 * av_popcount64(cmp1) - 2;
1252 }
1253 }
1254
1255 /* no penalty for LFE channel mismatch */
1256
4/4
✓ Branch 50 → 51 taken 23 times.
✓ Branch 50 → 54 taken 16 times.
✓ Branch 52 → 53 taken 8 times.
✓ Branch 52 → 54 taken 15 times.
62 if (av_channel_layout_index_from_channel(&in_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0 &&
1257 23 av_channel_layout_index_from_channel(&out_chlayout, AV_CHAN_LOW_FREQUENCY) >= 0)
1258 8 score += 10;
1259 39 av_channel_layout_from_mask(&in_chlayout, av_channel_layout_subset(&in_chlayout, ~AV_CH_LOW_FREQUENCY));
1260 39 av_channel_layout_from_mask(&out_chlayout, av_channel_layout_subset(&out_chlayout, ~AV_CH_LOW_FREQUENCY));
1261
1262 39 matched_channels = av_popcount64(in_chlayout.u.mask & out_chlayout.u.mask);
1263 39 extra_channels = av_popcount64(out_chlayout.u.mask & (~in_chlayout.u.mask));
1264 39 score += 10 * matched_channels - 5 * extra_channels;
1265
1266
4/4
✓ Branch 58 → 59 taken 24 times.
✓ Branch 58 → 61 taken 15 times.
✓ Branch 59 → 60 taken 4 times.
✓ Branch 59 → 62 taken 20 times.
39 if (score > best_score ||
1267
1/2
✗ Branch 60 → 61 not taken.
✓ Branch 60 → 62 taken 4 times.
4 (count_diff < best_count_diff && score == best_score)) {
1268 15 best_score = score;
1269 15 best_idx = j;
1270 15 best_count_diff = count_diff;
1271 }
1272 }
1273
1/2
✗ Branch 64 → 65 not taken.
✓ Branch 64 → 67 taken 4 times.
4 av_assert0(best_idx >= 0);
1274 4 FFSWAP(AVChannelLayout, outlink->incfg.channel_layouts->channel_layouts[0],
1275 outlink->incfg.channel_layouts->channel_layouts[best_idx]);
1276 }
1277
1278 }
1279
1280 9010 static void swap_channel_layouts(AVFilterGraph *graph)
1281 {
1282 int i;
1283
1284
2/2
✓ Branch 5 → 3 taken 49547 times.
✓ Branch 5 → 6 taken 9010 times.
58557 for (i = 0; i < graph->nb_filters; i++)
1285 49547 swap_channel_layouts_on_filter(graph->filters[i]);
1286 9010 }
1287
1288 49547 static void swap_sample_fmts_on_filter(AVFilterContext *filter)
1289 {
1290 49547 AVFilterLink *link = NULL;
1291 int format, bps;
1292 int i, j;
1293
1294
2/2
✓ Branch 7 → 3 taken 40487 times.
✓ Branch 7 → 8 taken 42733 times.
83220 for (i = 0; i < filter->nb_inputs; i++) {
1295 40487 link = filter->inputs[i];
1296
1297
2/2
✓ Branch 3 → 4 taken 7319 times.
✓ Branch 3 → 6 taken 33168 times.
40487 if (link->type == AVMEDIA_TYPE_AUDIO &&
1298
2/2
✓ Branch 4 → 5 taken 6814 times.
✓ Branch 4 → 6 taken 505 times.
7319 link->outcfg.formats->nb_formats == 1)
1299 6814 break;
1300 }
1301
2/2
✓ Branch 8 → 9 taken 42733 times.
✓ Branch 8 → 10 taken 6814 times.
49547 if (i == filter->nb_inputs)
1302 42733 return;
1303
1304 6814 format = link->outcfg.formats->formats[0];
1305 6814 bps = av_get_bytes_per_sample(format);
1306
1307
2/2
✓ Branch 36 → 12 taken 5241 times.
✓ Branch 36 → 37 taken 6814 times.
12055 for (i = 0; i < filter->nb_outputs; i++) {
1308 5241 AVFilterLink *outlink = filter->outputs[i];
1309 5241 int best_idx = -1, best_score = INT_MIN;
1310
1311
2/2
✓ Branch 12 → 13 taken 5239 times.
✓ Branch 12 → 14 taken 2 times.
5241 if (outlink->type != AVMEDIA_TYPE_AUDIO ||
1312
2/2
✓ Branch 13 → 14 taken 5060 times.
✓ Branch 13 → 15 taken 179 times.
5239 outlink->incfg.formats->nb_formats < 2)
1313 5062 continue;
1314
1315
2/2
✓ Branch 30 → 16 taken 377 times.
✓ Branch 30 → 31 taken 10 times.
387 for (j = 0; j < outlink->incfg.formats->nb_formats; j++) {
1316 377 int out_format = outlink->incfg.formats->formats[j];
1317 377 int out_bps = av_get_bytes_per_sample(out_format);
1318 int score;
1319
1320
4/4
✓ Branch 18 → 19 taken 236 times.
✓ Branch 18 → 21 taken 141 times.
✓ Branch 20 → 21 taken 28 times.
✓ Branch 20 → 22 taken 208 times.
613 if (av_get_packed_sample_fmt(out_format) == format ||
1321 236 av_get_planar_sample_fmt(out_format) == format) {
1322 169 best_idx = j;
1323 169 break;
1324 }
1325
1326 /* for s32 and float prefer double to prevent loss of information */
1327
3/4
✓ Branch 22 → 23 taken 6 times.
✓ Branch 22 → 25 taken 202 times.
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 6 times.
208 if (bps == 4 && out_bps == 8) {
1328 ✗ best_idx = j;
1329 ✗ break;
1330 }
1331
1332 /* prefer closest higher or equal bps */
1333 208 score = -abs(out_bps - bps);
1334
2/2
✓ Branch 25 → 26 taken 33 times.
✓ Branch 25 → 27 taken 175 times.
208 if (out_bps >= bps)
1335 33 score += INT_MAX/2;
1336
1337
2/2
✓ Branch 27 → 28 taken 159 times.
✓ Branch 27 → 29 taken 49 times.
208 if (score > best_score) {
1338 159 best_score = score;
1339 159 best_idx = j;
1340 }
1341 }
1342
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 34 taken 179 times.
179 av_assert0(best_idx >= 0);
1343 179 FFSWAP(int, outlink->incfg.formats->formats[0],
1344 outlink->incfg.formats->formats[best_idx]);
1345 }
1346 }
1347
1348 9010 static void swap_sample_fmts(AVFilterGraph *graph)
1349 {
1350 int i;
1351
1352
2/2
✓ Branch 5 → 3 taken 49547 times.
✓ Branch 5 → 6 taken 9010 times.
58557 for (i = 0; i < graph->nb_filters; i++)
1353 49547 swap_sample_fmts_on_filter(graph->filters[i]);
1354
1355 9010 }
1356
1357 9010 static int pick_formats(AVFilterGraph *graph)
1358 {
1359 int i, j, ret;
1360 int change;
1361
1362 do{
1363 18039 change = 0;
1364
2/2
✓ Branch 36 → 4 taken 100015 times.
✓ Branch 36 → 37 taken 18039 times.
118054 for (i = 0; i < graph->nb_filters; i++) {
1365 100015 AVFilterContext *filter = graph->filters[i];
1366
2/2
✓ Branch 4 → 5 taken 81440 times.
✓ Branch 4 → 14 taken 18575 times.
100015 if (filter->nb_inputs){
1367
2/2
✓ Branch 13 → 6 taken 81879 times.
✓ Branch 13 → 14 taken 81440 times.
163319 for (j = 0; j < filter->nb_inputs; j++){
1368
4/4
✓ Branch 6 → 7 taken 17621 times.
✓ Branch 6 → 12 taken 64258 times.
✓ Branch 7 → 8 taken 17017 times.
✓ Branch 7 → 12 taken 604 times.
81879 if (filter->inputs[j]->incfg.formats && filter->inputs[j]->incfg.formats->nb_formats == 1) {
1369
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 17017 times.
17017 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1370 ✗ return ret;
1371 17017 change = 1;
1372 }
1373 }
1374 }
1375
2/2
✓ Branch 14 → 15 taken 81387 times.
✓ Branch 14 → 24 taken 18628 times.
100015 if (filter->nb_outputs){
1376
2/2
✓ Branch 23 → 16 taken 81879 times.
✓ Branch 23 → 24 taken 81387 times.
163266 for (j = 0; j < filter->nb_outputs; j++){
1377
4/4
✓ Branch 16 → 17 taken 23831 times.
✓ Branch 16 → 22 taken 58048 times.
✓ Branch 17 → 18 taken 23103 times.
✓ Branch 17 → 22 taken 728 times.
81879 if (filter->outputs[j]->incfg.formats && filter->outputs[j]->incfg.formats->nb_formats == 1) {
1378
1/2
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 23103 times.
23103 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1379 ✗ return ret;
1380 23103 change = 1;
1381 }
1382 }
1383 }
1384
6/6
✓ Branch 24 → 25 taken 81440 times.
✓ Branch 24 → 35 taken 18575 times.
✓ Branch 25 → 26 taken 62812 times.
✓ Branch 25 → 35 taken 18628 times.
✓ Branch 26 → 27 taken 62484 times.
✓ Branch 26 → 35 taken 328 times.
100015 if (filter->nb_inputs && filter->nb_outputs && filter->inputs[0]->format>=0) {
1385
2/2
✓ Branch 34 → 28 taken 62908 times.
✓ Branch 34 → 35 taken 62484 times.
125392 for (j = 0; j < filter->nb_outputs; j++) {
1386
2/2
✓ Branch 28 → 29 taken 280 times.
✓ Branch 28 → 33 taken 62628 times.
62908 if (filter->outputs[j]->format<0) {
1387
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 32 taken 280 times.
280 if ((ret = pick_format(filter->outputs[j], filter->inputs[0])) < 0)
1388 ✗ return ret;
1389 280 change = 1;
1390 }
1391 }
1392 }
1393 }
1394
2/2
✓ Branch 37 → 38 taken 9029 times.
✓ Branch 37 → 39 taken 9010 times.
18039 }while(change);
1395
1396
2/2
✓ Branch 53 → 40 taken 49547 times.
✓ Branch 53 → 54 taken 9010 times.
58557 for (i = 0; i < graph->nb_filters; i++) {
1397 49547 AVFilterContext *filter = graph->filters[i];
1398
1399
2/2
✓ Branch 45 → 41 taken 40508 times.
✓ Branch 45 → 46 taken 49547 times.
90055 for (j = 0; j < filter->nb_inputs; j++)
1400
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 40508 times.
40508 if ((ret = pick_format(filter->inputs[j], NULL)) < 0)
1401 ✗ return ret;
1402
2/2
✓ Branch 51 → 47 taken 40508 times.
✓ Branch 51 → 52 taken 49547 times.
90055 for (j = 0; j < filter->nb_outputs; j++)
1403
1/2
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 50 taken 40508 times.
40508 if ((ret = pick_format(filter->outputs[j], NULL)) < 0)
1404 ✗ return ret;
1405 }
1406 9010 return 0;
1407 }
1408
1409 /**
1410 * Configure the formats of all the links in the graph.
1411 */
1412 9010 static int graph_config_formats(AVFilterGraph *graph, void *log_ctx)
1413 {
1414 int ret;
1415
1416 /* find supported formats from sub-filters, and merge along links */
1417
2/2
✓ Branch 5 → 3 taken 15 times.
✓ Branch 5 → 6 taken 9010 times.
9025 while ((ret = query_formats(graph, log_ctx)) == AVERROR(EAGAIN))
1418 15 av_log(graph, AV_LOG_DEBUG, "query_formats not finished\n");
1419
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 9010 times.
9010 if (ret < 0)
1420 ✗ return ret;
1421
1422 /* Once everything is merged, it's possible that we'll still have
1423 * multiple valid media format choices. We try to minimize the amount
1424 * of format conversion inside filters */
1425
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 9010 times.
9010 if ((ret = reduce_formats(graph)) < 0)
1426 ✗ return ret;
1427
1428 /* for audio filters, ensure the best format, sample rate and channel layout
1429 * is selected */
1430 9010 swap_sample_fmts(graph);
1431 9010 swap_samplerates(graph);
1432 9010 swap_channel_layouts(graph);
1433
1434
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 9010 times.
9010 if ((ret = pick_formats(graph)) < 0)
1435 ✗ return ret;
1436
1437 9010 return 0;
1438 }
1439
1440 9008 static int graph_config_pointers(AVFilterGraph *graph, void *log_ctx)
1441 {
1442 unsigned i, j;
1443 9008 int sink_links_count = 0, n = 0;
1444 AVFilterContext *f;
1445 FilterLinkInternal **sinks;
1446
1447
2/2
✓ Branch 16 → 3 taken 49535 times.
✓ Branch 16 → 17 taken 9008 times.
58543 for (i = 0; i < graph->nb_filters; i++) {
1448 49535 f = graph->filters[i];
1449
2/2
✓ Branch 6 → 4 taken 40498 times.
✓ Branch 6 → 7 taken 49535 times.
90033 for (j = 0; j < f->nb_inputs; j++) {
1450 40498 ff_link_internal(f->inputs[j])->age_index = -1;
1451 }
1452
2/2
✓ Branch 10 → 8 taken 40498 times.
✓ Branch 10 → 11 taken 49535 times.
90033 for (j = 0; j < f->nb_outputs; j++) {
1453 40498 ff_link_internal(f->outputs[j])->age_index = -1;
1454 }
1455
2/2
✓ Branch 11 → 12 taken 9248 times.
✓ Branch 11 → 15 taken 40287 times.
49535 if (!f->nb_outputs) {
1456
1/2
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 9248 times.
9248 if (f->nb_inputs > INT_MAX - sink_links_count)
1457 ✗ return AVERROR(EINVAL);
1458 9248 sink_links_count += f->nb_inputs;
1459 }
1460 }
1461 9008 sinks = av_calloc(sink_links_count, sizeof(*sinks));
1462
1/2
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 9008 times.
9008 if (!sinks)
1463 ✗ return AVERROR(ENOMEM);
1464
2/2
✓ Branch 27 → 21 taken 49535 times.
✓ Branch 27 → 28 taken 9008 times.
58543 for (i = 0; i < graph->nb_filters; i++) {
1465 49535 f = graph->filters[i];
1466
2/2
✓ Branch 21 → 22 taken 9248 times.
✓ Branch 21 → 26 taken 40287 times.
49535 if (!f->nb_outputs) {
1467
2/2
✓ Branch 25 → 23 taken 9248 times.
✓ Branch 25 → 26 taken 9248 times.
18496 for (j = 0; j < f->nb_inputs; j++) {
1468 9248 sinks[n] = ff_link_internal(f->inputs[j]);
1469 9248 sinks[n]->age_index = n;
1470 9248 n++;
1471 }
1472 }
1473 }
1474
1/2
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 31 taken 9008 times.
9008 av_assert0(n == sink_links_count);
1475 9008 fffiltergraph(graph)->sink_links = sinks;
1476 9008 fffiltergraph(graph)->sink_links_count = sink_links_count;
1477 9008 return 0;
1478 }
1479
1480 9010 int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)
1481 {
1482 9010 FFFilterGraph *graphi = fffiltergraph(graphctx);
1483 int ret;
1484
1485 9010 size_t max_queued = SIZE_MAX;
1486 #if FF_API_MAX_BUFFERED_FRAMES
1487 FF_DISABLE_DEPRECATION_WARNINGS
1488
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 9010 times.
9010 if (graphctx->max_buffered_frames)
1489 ✗ max_queued = graphctx->max_buffered_frames;
1490 FF_ENABLE_DEPRECATION_WARNINGS
1491 #endif
1492
1493
2/2
✓ Branch 9 → 6 taken 45050 times.
✓ Branch 9 → 10 taken 9010 times.
54060 for (int i = 0; i < FF_ARRAY_ELEMS(graphi->frame_queues); i++) {
1494 /* only infer the value from graphctx->max_buffered_frames if it was
1495 * not already set by avfilter_graph_set_max_buffered_frames() */
1496
2/2
✓ Branch 6 → 7 taken 45045 times.
✓ Branch 6 → 8 taken 5 times.
45050 if (!graphi->max_queued_set[i])
1497 45045 graphi->frame_queues[i].max_queued = max_queued;
1498 }
1499
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 9010 times.
9010 if ((ret = graph_check_validity(graphctx, log_ctx)))
1500 ✗ return ret;
1501
1/2
✗ Branch 14 → 15 not taken.
✓ Branch 14 → 16 taken 9010 times.
9010 if ((ret = graph_config_formats(graphctx, log_ctx)))
1502 ✗ return ret;
1503
2/2
✓ Branch 17 → 18 taken 2 times.
✓ Branch 17 → 19 taken 9008 times.
9010 if ((ret = graph_config_links(graphctx, log_ctx)))
1504 2 return ret;
1505
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 9008 times.
9008 if ((ret = graph_check_links(graphctx, log_ctx)))
1506 ✗ return ret;
1507
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 9008 times.
9008 if ((ret = graph_config_pointers(graphctx, log_ctx)))
1508 ✗ return ret;
1509
1510 9008 return 0;
1511 }
1512
1513 2 int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags)
1514 {
1515 2 int i, r = AVERROR(ENOSYS);
1516
1517
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 2 times.
2 if (!graph)
1518 ✗ return r;
1519
1520
3/4
✓ Branch 4 → 5 taken 2 times.
✗ Branch 4 → 9 not taken.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 9 taken 1 time.
2 if ((flags & AVFILTER_CMD_FLAG_ONE) && !(flags & AVFILTER_CMD_FLAG_FAST)) {
1521 1 r = avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST);
1522
1/2
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 9 not taken.
1 if (r != AVERROR(ENOSYS))
1523 1 return r;
1524 }
1525
1526
2/4
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 12 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 12 not taken.
1 if (res_len && res)
1527 1 res[0] = 0;
1528
1529
1/2
✓ Branch 23 → 13 taken 3 times.
✗ Branch 23 → 24 not taken.
3 for (i = 0; i < graph->nb_filters; i++) {
1530 3 AVFilterContext *filter = graph->filters[i];
1531
5/8
✓ Branch 13 → 14 taken 3 times.
✗ Branch 13 → 17 not taken.
✓ Branch 14 → 15 taken 3 times.
✗ Branch 14 → 16 not taken.
✓ Branch 15 → 16 taken 3 times.
✗ Branch 15 → 17 not taken.
✓ Branch 16 → 17 taken 1 time.
✓ Branch 16 → 22 taken 2 times.
3 if (!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)) {
1532 1 r = avfilter_process_command(filter, cmd, arg, res, res_len, flags);
1533
1/2
✓ Branch 18 → 19 taken 1 time.
✗ Branch 18 → 22 not taken.
1 if (r != AVERROR(ENOSYS)) {
1534
1/4
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 1 time.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
1 if ((flags & AVFILTER_CMD_FLAG_ONE) || r < 0)
1535 1 return r;
1536 }
1537 }
1538 }
1539
1540 ✗ return r;
1541 }
1542
1543 ✗ int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts)
1544 {
1545 int i;
1546
1547
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if(!graph)
1548 ✗ return 0;
1549
1550
0/2
✗ Branch 22 → 5 not taken.
✗ Branch 22 → 23 not taken.
✗ for (i = 0; i < graph->nb_filters; i++) {
1551 ✗ AVFilterContext *filter = graph->filters[i];
1552 ✗ FFFilterContext *ctxi = fffilterctx(filter);
1553
0/8
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 21 not taken.
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 21 not taken.
✗ if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){
1554 ✗ AVFilterCommand **queue = &ctxi->command_queue, *next;
1555
0/4
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ Branch 13 → 11 not taken.
✗ Branch 13 → 14 not taken.
✗ while (*queue && (*queue)->time <= ts)
1556 ✗ queue = &(*queue)->next;
1557 ✗ next = *queue;
1558 ✗ *queue = av_mallocz(sizeof(AVFilterCommand));
1559
0/2
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 17 not taken.
✗ if (!*queue)
1560 ✗ return AVERROR(ENOMEM);
1561
1562 ✗ (*queue)->command = av_strdup(command);
1563 ✗ (*queue)->arg = av_strdup(arg);
1564 ✗ (*queue)->time = ts;
1565 ✗ (*queue)->flags = flags;
1566 ✗ (*queue)->next = next;
1567
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ if(flags & AVFILTER_CMD_FLAG_ONE)
1568 ✗ return 0;
1569 }
1570 }
1571
1572 ✗ return 0;
1573 }
1574
1575 1235418 static void heap_bubble_up(FFFilterGraph *graph,
1576 FilterLinkInternal *li, int index)
1577 {
1578 1235418 FilterLinkInternal **links = graph->sink_links;
1579
1580
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 1235418 times.
1235418 av_assert0(index >= 0);
1581
1582
2/2
✓ Branch 9 → 6 taken 358030 times.
✓ Branch 9 → 10 taken 1235418 times.
1593448 while (index) {
1583 358030 int parent = (index - 1) >> 1;
1584
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 358030 times.
358030 if (links[parent]->l.current_pts_us >= li->l.current_pts_us)
1585 ✗ break;
1586 358030 links[index] = links[parent];
1587 358030 links[index]->age_index = index;
1588 358030 index = parent;
1589 }
1590 1235418 links[index] = li;
1591 1235418 li->age_index = index;
1592 1235418 }
1593
1594 1235639 static void heap_bubble_down(FFFilterGraph *graph,
1595 FilterLinkInternal *li, int index)
1596 {
1597 1235639 FilterLinkInternal **links = graph->sink_links;
1598
1599
1/2
✓ Branch 2 → 3 taken 1235639 times.
✗ Branch 2 → 4 not taken.
1235639 av_assert0(index >= 0);
1600
1601 368216 while (1) {
1602 1603855 int child = 2 * index + 1;
1603
2/2
✓ Branch 6 → 7 taken 1219280 times.
✓ Branch 6 → 8 taken 384575 times.
1603855 if (child >= graph->sink_links_count)
1604 1219280 break;
1605
2/2
✓ Branch 8 → 9 taken 23035 times.
✓ Branch 8 → 11 taken 361540 times.
384575 if (child + 1 < graph->sink_links_count &&
1606
2/2
✓ Branch 9 → 10 taken 8297 times.
✓ Branch 9 → 11 taken 14738 times.
23035 links[child + 1]->l.current_pts_us < links[child]->l.current_pts_us)
1607 8297 child++;
1608
2/2
✓ Branch 11 → 12 taken 16359 times.
✓ Branch 11 → 13 taken 368216 times.
384575 if (li->l.current_pts_us < links[child]->l.current_pts_us)
1609 16359 break;
1610 368216 links[index] = links[child];
1611 368216 links[index]->age_index = index;
1612 368216 index = child;
1613 }
1614 1235639 links[index] = li;
1615 1235639 li->age_index = index;
1616 1235639 }
1617
1618 1235418 void ff_avfilter_graph_update_heap(AVFilterGraph *graph, FilterLinkInternal *li)
1619 {
1620 1235418 FFFilterGraph *graphi = fffiltergraph(graph);
1621
1622 1235418 heap_bubble_up (graphi, li, li->age_index);
1623 1235418 heap_bubble_down(graphi, li, li->age_index);
1624 1235418 }
1625
1626 847571 int avfilter_graph_request_oldest(AVFilterGraph *graph)
1627 {
1628 847571 FFFilterGraph *graphi = fffiltergraph(graph);
1629 847571 FilterLinkInternal *oldesti = graphi->sink_links[0];
1630 847571 AVFilterLink *oldest = &oldesti->l.pub;
1631 int64_t frame_count;
1632 int r;
1633
1634
2/2
✓ Branch 16 → 4 taken 847804 times.
✓ Branch 16 → 17 taken 5377 times.
853181 while (graphi->sink_links_count) {
1635 847804 oldesti = graphi->sink_links[0];
1636 847804 oldest = &oldesti->l.pub;
1637
2/2
✓ Branch 5 → 6 taken 847795 times.
✓ Branch 5 → 9 taken 9 times.
847804 if (fffilter(oldest->dst->filter)->activate) {
1638 847795 r = av_buffersink_get_frame_flags(oldest->dst, NULL,
1639 AV_BUFFERSINK_FLAG_PEEK);
1640
2/2
✓ Branch 7 → 8 taken 842186 times.
✓ Branch 7 → 10 taken 5609 times.
847795 if (r != AVERROR_EOF)
1641 842186 return r;
1642 } else {
1643 9 r = ff_request_frame(oldest);
1644 }
1645
2/2
✓ Branch 10 → 11 taken 8 times.
✓ Branch 10 → 12 taken 5610 times.
5618 if (r != AVERROR_EOF)
1646 8 break;
1647 5610 av_log(oldest->dst, AV_LOG_DEBUG, "EOF on sink link %s:%s.\n",
1648 5610 oldest->dst->name,
1649 5610 oldest->dstpad->name);
1650 /* EOF: remove the link from the heap */
1651
2/2
✓ Branch 13 → 14 taken 221 times.
✓ Branch 13 → 15 taken 5389 times.
5610 if (oldesti->age_index < --graphi->sink_links_count)
1652 221 heap_bubble_down(graphi, graphi->sink_links[graphi->sink_links_count],
1653 oldesti->age_index);
1654 5610 oldesti->age_index = -1;
1655 }
1656
2/2
✓ Branch 17 → 18 taken 5377 times.
✓ Branch 17 → 19 taken 8 times.
5385 if (!graphi->sink_links_count)
1657 5377 return AVERROR_EOF;
1658 av_assert1(!fffilter(oldest->dst->filter)->activate);
1659 av_assert1(oldesti->age_index >= 0);
1660 8 frame_count = oldesti->l.frame_count_out;
1661
1/2
✓ Branch 31 → 20 taken 32 times.
✗ Branch 31 → 32 not taken.
32 while (frame_count == oldesti->l.frame_count_out) {
1662 32 r = ff_filter_graph_run_once(graph);
1663
2/2
✓ Branch 21 → 22 taken 8 times.
✓ Branch 21 → 23 taken 24 times.
32 if (r == FFERROR_BUFFERSRC_EMPTY)
1664 8 r = 0;
1665
2/2
✓ Branch 23 → 24 taken 8 times.
✓ Branch 23 → 28 taken 24 times.
32 if (r == AVERROR(EAGAIN) &&
1666
1/4
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 28 taken 8 times.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 28 not taken.
8 !oldesti->frame_wanted_out && !oldesti->frame_blocked_in &&
1667
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 28 not taken.
✗ !oldesti->status_in)
1668 ✗ (void)ff_request_frame(oldest);
1669
2/2
✓ Branch 28 → 29 taken 8 times.
✓ Branch 28 → 30 taken 24 times.
32 else if (r < 0)
1670 8 return r;
1671 }
1672 ✗ return 0;
1673 }
1674
1675 10603139 int ff_filter_graph_run_once(AVFilterGraph *graph)
1676 {
1677 FFFilterContext *ctxi;
1678 unsigned i;
1679
1680
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 10603139 times.
10603139 av_assert0(graph->nb_filters);
1681 10603139 ctxi = fffilterctx(graph->filters[0]);
1682
2/2
✓ Branch 11 → 7 taken 46689262 times.
✓ Branch 11 → 12 taken 10603139 times.
57292401 for (i = 1; i < graph->nb_filters; i++) {
1683 46689262 FFFilterContext *ctxi_other = fffilterctx(graph->filters[i]);
1684
1685
2/2
✓ Branch 8 → 9 taken 6938423 times.
✓ Branch 8 → 10 taken 39750839 times.
46689262 if (ctxi_other->ready > ctxi->ready)
1686 6938423 ctxi = ctxi_other;
1687 }
1688
1689
2/2
✓ Branch 12 → 13 taken 1631045 times.
✓ Branch 12 → 14 taken 8972094 times.
10603139 if (!ctxi->ready)
1690 1631045 return AVERROR(EAGAIN);
1691 8972094 return ff_filter_activate(&ctxi->p);
1692 }
1693