FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/graphparser.c
Date: 2022-12-09 07:38:14
Exec Total Coverage
Lines: 194 332 58.4%
Functions: 14 16 87.5%
Branches: 106 194 54.6%

Line Branch Exec Source
1 /*
2 * filter graph parser
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 <string.h>
24 #include <stdio.h>
25
26 #include "libavutil/avstring.h"
27 #include "libavutil/mem.h"
28 #include "avfilter.h"
29
30 #define WHITESPACES " \n\t\r"
31
32 /**
33 * Link two filters together.
34 *
35 * @see avfilter_link()
36 */
37 6256 static int link_filter(AVFilterContext *src, int srcpad,
38 AVFilterContext *dst, int dstpad,
39 void *log_ctx)
40 {
41 int ret;
42
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6256 times.
6256 if ((ret = avfilter_link(src, srcpad, dst, dstpad))) {
43 av_log(log_ctx, AV_LOG_ERROR,
44 "Cannot create the link %s:%d -> %s:%d\n",
45 src->filter->name, srcpad, dst->filter->name, dstpad);
46 return ret;
47 }
48
49 6256 return 0;
50 }
51
52 /**
53 * Parse the name of a link, which has the format "[linkname]".
54 *
55 * @return a pointer (that need to be freed after use) to the name
56 * between parenthesis
57 */
58 471 static char *parse_link_name(const char **buf, void *log_ctx)
59 {
60 471 const char *start = *buf;
61 char *name;
62 471 (*buf)++;
63
64 471 name = av_get_token(buf, "]");
65
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 471 times.
471 if (!name)
66 return NULL;
67
68
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 471 times.
471 if (!name[0]) {
69 av_log(log_ctx, AV_LOG_ERROR,
70 "Bad (empty?) label found in the following: \"%s\".\n", start);
71 goto fail;
72 }
73
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 471 times.
471 if (**buf != ']') {
75 av_log(log_ctx, AV_LOG_ERROR,
76 "Mismatched '[' found in the following: \"%s\".\n", start);
77 fail:
78 av_freep(&name);
79 return NULL;
80 }
81 471 (*buf)++;
82
83 471 return name;
84 }
85
86 /**
87 * Create an instance of a filter, initialize and insert it in the
88 * filtergraph in *ctx.
89 *
90 * @param filt_ctx put here a filter context in case of successful creation and configuration, NULL otherwise.
91 * @param ctx the filtergraph context
92 * @param index an index which is supposed to be unique for each filter instance added to the filtergraph
93 * @param name the name of the filter to create, can be filter name or filter_name\@id as instance name
94 * @param args the arguments provided to the filter during its initialization
95 * @param log_ctx the log context to use
96 * @return >= 0 in case of success, a negative AVERROR code otherwise
97 */
98 12592 static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index,
99 const char *name, const char *args, void *log_ctx)
100 {
101 const AVFilter *filt;
102 char name2[30];
103 12592 const char *inst_name = NULL, *filt_name = NULL;
104 12592 char *tmp_args = NULL;
105 int ret, k;
106
107 12592 av_strlcpy(name2, name, sizeof(name2));
108
109
2/2
✓ Branch 0 taken 70748 times.
✓ Branch 1 taken 12592 times.
83340 for (k = 0; name2[k]; k++) {
110
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 70748 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
70748 if (name2[k] == '@' && name[k+1]) {
111 name2[k] = 0;
112 inst_name = name;
113 filt_name = name2;
114 break;
115 }
116 }
117
118
1/2
✓ Branch 0 taken 12592 times.
✗ Branch 1 not taken.
12592 if (!inst_name) {
119 12592 snprintf(name2, sizeof(name2), "Parsed_%s_%d", name, index);
120 12592 inst_name = name2;
121 12592 filt_name = name;
122 }
123
124 12592 filt = avfilter_get_by_name(filt_name);
125
126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12592 times.
12592 if (!filt) {
127 av_log(log_ctx, AV_LOG_ERROR,
128 "No such filter: '%s'\n", filt_name);
129 return AVERROR(EINVAL);
130 }
131
132 12592 *filt_ctx = avfilter_graph_alloc_filter(ctx, filt, inst_name);
133
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12592 times.
12592 if (!*filt_ctx) {
134 av_log(log_ctx, AV_LOG_ERROR,
135 "Error creating filter '%s'\n", filt_name);
136 return AVERROR(ENOMEM);
137 }
138
139
6/6
✓ Branch 0 taken 2864 times.
✓ Branch 1 taken 9728 times.
✓ Branch 2 taken 223 times.
✓ Branch 3 taken 2641 times.
✓ Branch 4 taken 220 times.
✓ Branch 5 taken 3 times.
12592 if (!strcmp(filt_name, "scale") && (!args || !strstr(args, "flags")) &&
140
2/2
✓ Branch 0 taken 2599 times.
✓ Branch 1 taken 262 times.
2861 ctx->scale_sws_opts) {
141
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 2387 times.
2599 if (args) {
142 212 tmp_args = av_asprintf("%s:%s",
143 args, ctx->scale_sws_opts);
144
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 212 times.
212 if (!tmp_args)
145 return AVERROR(ENOMEM);
146 212 args = tmp_args;
147 } else
148 2387 args = ctx->scale_sws_opts;
149 }
150
151 12592 ret = avfilter_init_str(*filt_ctx, args);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12592 times.
12592 if (ret < 0) {
153 av_log(log_ctx, AV_LOG_ERROR,
154 "Error initializing filter '%s'", filt_name);
155 if (args)
156 av_log(log_ctx, AV_LOG_ERROR, " with args '%s'", args);
157 av_log(log_ctx, AV_LOG_ERROR, "\n");
158 avfilter_free(*filt_ctx);
159 *filt_ctx = NULL;
160 }
161
162 12592 av_free(tmp_args);
163 12592 return ret;
164 }
165
166 /**
167 * Parse a string of the form FILTER_NAME[=PARAMS], and create a
168 * corresponding filter instance which is added to graph with
169 * create_filter().
170 *
171 * @param filt_ctx Pointer that is set to the created and configured filter
172 * context on success, set to NULL on failure.
173 * @param filt_ctx put here a pointer to the created filter context on
174 * success, NULL otherwise
175 * @param buf pointer to the buffer to parse, *buf will be updated to
176 * point to the char next after the parsed string
177 * @param index an index which is assigned to the created filter
178 * instance, and which is supposed to be unique for each filter
179 * instance added to the filtergraph
180 * @return >= 0 in case of success, a negative AVERROR code otherwise
181 */
182 12592 static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph,
183 int index, void *log_ctx)
184 {
185 12592 char *opts = NULL;
186 12592 char *name = av_get_token(buf, "=,;[");
187 int ret;
188
189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12592 times.
12592 if (!name)
190 return AVERROR(ENOMEM);
191
192
2/2
✓ Branch 0 taken 6601 times.
✓ Branch 1 taken 5991 times.
12592 if (**buf == '=') {
193 6601 (*buf)++;
194 6601 opts = av_get_token(buf, "[],;");
195
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6601 times.
6601 if (!opts) {
196 av_free(name);
197 return AVERROR(ENOMEM);
198 }
199 }
200
201 12592 ret = create_filter(filt_ctx, graph, index, name, opts, log_ctx);
202 12592 av_free(name);
203 12592 av_free(opts);
204 12592 return ret;
205 }
206
207 AVFilterInOut *avfilter_inout_alloc(void)
208 {
209 return av_mallocz(sizeof(AVFilterInOut));
210 }
211
212 18938 void avfilter_inout_free(AVFilterInOut **inout)
213 {
214
2/2
✓ Branch 0 taken 12657 times.
✓ Branch 1 taken 18938 times.
31595 while (*inout) {
215 12657 AVFilterInOut *next = (*inout)->next;
216 12657 av_freep(&(*inout)->name);
217 12657 av_freep(inout);
218 12657 *inout = next;
219 }
220 18938 }
221
222 471 static AVFilterInOut *extract_inout(const char *label, AVFilterInOut **links)
223 {
224 AVFilterInOut *ret;
225
226
6/6
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 305 times.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 447 times.
✓ Branch 4 taken 281 times.
✓ Branch 5 taken 166 times.
840 while (*links && (!(*links)->name || strcmp((*links)->name, label)))
227 369 links = &((*links)->next);
228
229 471 ret = *links;
230
231
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 305 times.
471 if (ret) {
232 166 *links = ret->next;
233 166 ret->next = NULL;
234 }
235
236 471 return ret;
237 }
238
239 12867 static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element)
240 {
241 12867 element->next = *inouts;
242 12867 *inouts = element;
243 12867 }
244
245 25420 static void append_inout(AVFilterInOut **inouts, AVFilterInOut **element)
246 {
247
4/4
✓ Branch 0 taken 503 times.
✓ Branch 1 taken 25100 times.
✓ Branch 2 taken 183 times.
✓ Branch 3 taken 320 times.
25603 while (*inouts && (*inouts)->next)
248 183 inouts = &((*inouts)->next);
249
250
2/2
✓ Branch 0 taken 25100 times.
✓ Branch 1 taken 320 times.
25420 if (!*inouts)
251 25100 *inouts = *element;
252 else
253 320 (*inouts)->next = *element;
254 25420 *element = NULL;
255 25420 }
256
257 12592 static int link_filter_inouts(AVFilterContext *filt_ctx,
258 AVFilterInOut **curr_inputs,
259 AVFilterInOut **open_inputs, void *log_ctx)
260 {
261 int pad, ret;
262
263
2/2
✓ Branch 0 taken 12539 times.
✓ Branch 1 taken 12592 times.
25131 for (pad = 0; pad < filt_ctx->nb_inputs; pad++) {
264 12539 AVFilterInOut *p = *curr_inputs;
265
266
2/2
✓ Branch 0 taken 6324 times.
✓ Branch 1 taken 6215 times.
12539 if (p) {
267 6324 *curr_inputs = (*curr_inputs)->next;
268 6324 p->next = NULL;
269
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6215 times.
6215 } else if (!(p = av_mallocz(sizeof(*p))))
270 return AVERROR(ENOMEM);
271
272
2/2
✓ Branch 0 taken 6256 times.
✓ Branch 1 taken 6283 times.
12539 if (p->filter_ctx) {
273 6256 ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx);
274 6256 av_freep(&p->name);
275 6256 av_freep(&p);
276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6256 times.
6256 if (ret < 0)
277 return ret;
278 } else {
279 6283 p->filter_ctx = filt_ctx;
280 6283 p->pad_idx = pad;
281 6283 append_inout(open_inputs, &p);
282 }
283 }
284
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12592 times.
12592 if (*curr_inputs) {
286 av_log(log_ctx, AV_LOG_ERROR,
287 "Too many inputs specified for the \"%s\" filter.\n",
288 filt_ctx->filter->name);
289 return AVERROR(EINVAL);
290 }
291
292 12592 pad = filt_ctx->nb_outputs;
293
2/2
✓ Branch 0 taken 12630 times.
✓ Branch 1 taken 12592 times.
25222 while (pad--) {
294 12630 AVFilterInOut *currlinkn = av_mallocz(sizeof(AVFilterInOut));
295
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12630 times.
12630 if (!currlinkn)
296 return AVERROR(ENOMEM);
297 12630 currlinkn->filter_ctx = filt_ctx;
298 12630 currlinkn->pad_idx = pad;
299 12630 insert_inout(curr_inputs, currlinkn);
300 }
301
302 12592 return 0;
303 }
304
305 12592 static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
306 AVFilterInOut **open_outputs, void *log_ctx)
307 {
308 12592 AVFilterInOut *parsed_inputs = NULL;
309 12592 int pad = 0;
310
311
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 12592 times.
12826 while (**buf == '[') {
312 234 char *name = parse_link_name(buf, log_ctx);
313 AVFilterInOut *match;
314
315
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
234 if (!name) {
316 avfilter_inout_free(&parsed_inputs);
317 return AVERROR(EINVAL);
318 }
319
320 /* First check if the label is not in the open_outputs list */
321 234 match = extract_inout(name, open_outputs);
322
323
2/2
✓ Branch 0 taken 166 times.
✓ Branch 1 taken 68 times.
234 if (match) {
324 166 av_free(name);
325 } else {
326 /* Not in the list, so add it as an input */
327
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 68 times.
68 if (!(match = av_mallocz(sizeof(AVFilterInOut)))) {
328 avfilter_inout_free(&parsed_inputs);
329 av_free(name);
330 return AVERROR(ENOMEM);
331 }
332 68 match->name = name;
333 68 match->pad_idx = pad;
334 }
335
336 234 append_inout(&parsed_inputs, &match);
337
338 234 *buf += strspn(*buf, WHITESPACES);
339 234 pad++;
340 }
341
342 12592 append_inout(&parsed_inputs, curr_inputs);
343 12592 *curr_inputs = parsed_inputs;
344
345 12592 return pad;
346 }
347
348 12628 static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
349 AVFilterInOut **open_inputs,
350 AVFilterInOut **open_outputs, void *log_ctx)
351 {
352 12628 int ret, pad = 0;
353
354
2/2
✓ Branch 0 taken 237 times.
✓ Branch 1 taken 12628 times.
12865 while (**buf == '[') {
355 237 char *name = parse_link_name(buf, log_ctx);
356 AVFilterInOut *match;
357
358 237 AVFilterInOut *input = *curr_inputs;
359
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 237 times.
237 if (!name)
361 return AVERROR(EINVAL);
362
363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 237 times.
237 if (!input) {
364 av_log(log_ctx, AV_LOG_ERROR,
365 "No output pad can be associated to link label '%s'.\n", name);
366 av_free(name);
367 return AVERROR(EINVAL);
368 }
369 237 *curr_inputs = (*curr_inputs)->next;
370
371 /* First check if the label is not in the open_inputs list */
372 237 match = extract_inout(name, open_inputs);
373
374
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 237 times.
237 if (match) {
375 ret = link_filter(input->filter_ctx, input->pad_idx,
376 match->filter_ctx, match->pad_idx, log_ctx);
377 av_freep(&match->name);
378 av_freep(&name);
379 av_freep(&match);
380 av_freep(&input);
381 if (ret < 0)
382 return ret;
383 } else {
384 /* Not in the list, so add the first input as an open_output */
385 237 input->name = name;
386 237 insert_inout(open_outputs, input);
387 }
388 237 *buf += strspn(*buf, WHITESPACES);
389 237 pad++;
390 }
391
392 12628 return pad;
393 }
394
395 6352 static int parse_sws_flags(const char **buf, AVFilterGraph *graph)
396 {
397 6352 char *p = strchr(*buf, ';');
398
399
2/2
✓ Branch 0 taken 6306 times.
✓ Branch 1 taken 46 times.
6352 if (strncmp(*buf, "sws_flags=", 10))
400 6306 return 0;
401
402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (!p) {
403 av_log(graph, AV_LOG_ERROR, "sws_flags not terminated with ';'.\n");
404 return AVERROR(EINVAL);
405 }
406
407 46 *buf += 4; // keep the 'flags=' part
408
409 46 av_freep(&graph->scale_sws_opts);
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
46 if (!(graph->scale_sws_opts = av_mallocz(p - *buf + 1)))
411 return AVERROR(ENOMEM);
412 46 av_strlcpy(graph->scale_sws_opts, *buf, p - *buf + 1);
413
414 46 *buf = p + 1;
415 46 return 0;
416 }
417
418 6311 int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
419 AVFilterInOut **inputs,
420 AVFilterInOut **outputs)
421 {
422 6311 int index = 0, ret = 0;
423 6311 char chr = 0;
424
425 6311 AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
426
427 6311 filters += strspn(filters, WHITESPACES);
428
429
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6311 times.
6311 if ((ret = parse_sws_flags(&filters, graph)) < 0)
430 goto fail;
431
432 do {
433 AVFilterContext *filter;
434 12525 filters += strspn(filters, WHITESPACES);
435
436
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12525 times.
12525 if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, graph)) < 0)
437 goto end;
438
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12525 times.
12525 if ((ret = parse_filter(&filter, &filters, graph, index, graph)) < 0)
439 goto end;
440
441
442
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12525 times.
12525 if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, graph)) < 0)
443 goto end;
444
445
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12525 times.
12525 if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
446 graph)) < 0)
447 goto end;
448
449 12525 filters += strspn(filters, WHITESPACES);
450 12525 chr = *filters++;
451
452
3/4
✓ Branch 0 taken 148 times.
✓ Branch 1 taken 12377 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 148 times.
12525 if (chr == ';' && curr_inputs)
453 append_inout(&open_outputs, &curr_inputs);
454 12525 index++;
455
4/4
✓ Branch 0 taken 6066 times.
✓ Branch 1 taken 6459 times.
✓ Branch 2 taken 148 times.
✓ Branch 3 taken 6311 times.
12525 } while (chr == ',' || chr == ';');
456
457
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6311 times.
6311 if (chr) {
458 av_log(graph, AV_LOG_ERROR,
459 "Unable to parse graph description substring: \"%s\"\n",
460 filters - 1);
461 ret = AVERROR(EINVAL);
462 goto end;
463 }
464
465 6311 append_inout(&open_outputs, &curr_inputs);
466
467
468 6311 *inputs = open_inputs;
469 6311 *outputs = open_outputs;
470 6311 return 0;
471
472 fail:end:
473 while (graph->nb_filters)
474 avfilter_free(graph->filters[0]);
475 av_freep(&graph->filters);
476 avfilter_inout_free(&open_inputs);
477 avfilter_inout_free(&open_outputs);
478 avfilter_inout_free(&curr_inputs);
479
480 *inputs = NULL;
481 *outputs = NULL;
482
483 return ret;
484 }
485
486 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
487 AVFilterInOut *open_inputs,
488 AVFilterInOut *open_outputs, void *log_ctx)
489 {
490 int ret;
491 AVFilterInOut *cur, *match, *inputs = NULL, *outputs = NULL;
492
493 if ((ret = avfilter_graph_parse2(graph, filters, &inputs, &outputs)) < 0)
494 goto fail;
495
496 /* First input can be omitted if it is "[in]" */
497 if (inputs && !inputs->name)
498 inputs->name = av_strdup("in");
499 for (cur = inputs; cur; cur = cur->next) {
500 if (!cur->name) {
501 av_log(log_ctx, AV_LOG_ERROR,
502 "Not enough inputs specified for the \"%s\" filter.\n",
503 cur->filter_ctx->filter->name);
504 ret = AVERROR(EINVAL);
505 goto fail;
506 }
507 if (!(match = extract_inout(cur->name, &open_outputs)))
508 continue;
509 ret = avfilter_link(match->filter_ctx, match->pad_idx,
510 cur->filter_ctx, cur->pad_idx);
511 avfilter_inout_free(&match);
512 if (ret < 0)
513 goto fail;
514 }
515
516 /* Last output can be omitted if it is "[out]" */
517 if (outputs && !outputs->name)
518 outputs->name = av_strdup("out");
519 for (cur = outputs; cur; cur = cur->next) {
520 if (!cur->name) {
521 av_log(log_ctx, AV_LOG_ERROR,
522 "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
523 filters);
524 ret = AVERROR(EINVAL);
525 goto fail;
526 }
527 if (!(match = extract_inout(cur->name, &open_inputs)))
528 continue;
529 ret = avfilter_link(cur->filter_ctx, cur->pad_idx,
530 match->filter_ctx, match->pad_idx);
531 avfilter_inout_free(&match);
532 if (ret < 0)
533 goto fail;
534 }
535
536 fail:
537 if (ret < 0) {
538 while (graph->nb_filters)
539 avfilter_free(graph->filters[0]);
540 av_freep(&graph->filters);
541 }
542 avfilter_inout_free(&inputs);
543 avfilter_inout_free(&outputs);
544 avfilter_inout_free(&open_inputs);
545 avfilter_inout_free(&open_outputs);
546 return ret;
547 }
548
549 41 int avfilter_graph_parse_ptr(AVFilterGraph *graph, const char *filters,
550 AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
551 void *log_ctx)
552 {
553 41 int index = 0, ret = 0;
554 41 char chr = 0;
555
556 41 AVFilterInOut *curr_inputs = NULL;
557
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL;
558
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
559
560
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
41 if ((ret = parse_sws_flags(&filters, graph)) < 0)
561 goto end;
562
563 do {
564 AVFilterContext *filter;
565 67 const char *filterchain = filters;
566 67 filters += strspn(filters, WHITESPACES);
567
568
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
569 goto end;
570
571
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
572 goto end;
573
574
3/6
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
67 if (filter->nb_inputs == 1 && !curr_inputs && !index) {
575 /* First input pad, assume it is "[in]" if not specified */
576 const char *tmp = "[in]";
577 if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0)
578 goto end;
579 }
580
581
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
582 goto end;
583
584
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 67 times.
67 if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
585 log_ctx)) < 0)
586 goto end;
587
588 67 filters += strspn(filters, WHITESPACES);
589 67 chr = *filters++;
590
591
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
67 if (chr == ';' && curr_inputs) {
592 av_log(log_ctx, AV_LOG_ERROR,
593 "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
594 filterchain);
595 ret = AVERROR(EINVAL);
596 goto end;
597 }
598 67 index++;
599
4/4
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 45 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 41 times.
67 } while (chr == ',' || chr == ';');
600
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (chr) {
602 av_log(log_ctx, AV_LOG_ERROR,
603 "Unable to parse graph description substring: \"%s\"\n",
604 filters - 1);
605 ret = AVERROR(EINVAL);
606 goto end;
607 }
608
609
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 36 times.
41 if (curr_inputs) {
610 /* Last output pad, assume it is "[out]" if not specified */
611 36 const char *tmp = "[out]";
612
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
36 if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs,
613 log_ctx)) < 0)
614 goto end;
615 }
616
617 5 end:
618 /* clear open_in/outputs only if not passed as parameters */
619
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
620 else avfilter_inout_free(&open_inputs);
621
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
622 else avfilter_inout_free(&open_outputs);
623 41 avfilter_inout_free(&curr_inputs);
624
625
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
41 if (ret < 0) {
626 while (graph->nb_filters)
627 avfilter_free(graph->filters[0]);
628 av_freep(&graph->filters);
629 }
630 41 return ret;
631 }
632