../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
554 / 887
62.5%
Branches:
416 / 759
54.8%
Functions:
34 / 42
81.0%

fftools/cmdutils.c
Line Branch Exec Source
1 /*
2 * Various utilities for command line tools
3 * Copyright (c) 2000-2003 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <string.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <math.h>
27
28 /* Include only the enabled headers since some compilers (namely, Sun
29 Studio) will not omit unused inline functions and create undefined
30 references to libraries that are not being built. */
31
32 #include "config.h"
33 #include "libavformat/avformat.h"
34 #include "libswscale/swscale.h"
35 #include "libswresample/swresample.h"
36 #include "libavutil/avassert.h"
37 #include "libavutil/avstring.h"
38 #include "libavutil/bprint.h"
39 #include "libavutil/display.h"
40 #include "libavutil/getenv_utf8.h"
41 #include "libavutil/mem.h"
42 #include "libavutil/parseutils.h"
43 #include "libavutil/eval.h"
44 #include "libavutil/dict.h"
45 #include "libavutil/opt.h"
46 #include "cmdutils.h"
47 #include "fopen_utf8.h"
48 #include "opt_common.h"
49 #ifdef _WIN32
50 #include <windows.h>
51 #include "compat/w32dlfcn.h"
52 #endif
53
54 AVDictionary *sws_dict;
55 AVDictionary *swr_opts;
56 AVDictionary *format_opts, *codec_opts;
57
58 int hide_banner = 0;
59
60 18838 void uninit_opts(void)
61 {
62 18838 av_dict_free(&swr_opts);
63 18838 av_dict_free(&sws_dict);
64 18838 av_dict_free(&format_opts);
65 18838 av_dict_free(&codec_opts);
66 18838 }
67
68 ✗ void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
69 {
70 ✗ vfprintf(stdout, fmt, vl);
71 ✗ }
72
73 9618 void init_dynload(void)
74 {
75 #if HAVE_SETDLLDIRECTORY && defined(_WIN32)
76 /* Calling SetDllDirectory with the empty string (but not NULL) removes the
77 * current working directory from the DLL search path as a security pre-caution. */
78 SetDllDirectory("");
79 #endif
80 9618 }
81
82 41982 int parse_number(const char *context, const char *numstr, enum OptionType type,
83 double min, double max, double *dst)
84 {
85 char *tail;
86 const char *error;
87 41982 double d = av_strtod(numstr, &tail);
88
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 41982 times.
41982 if (*tail)
89 ✗ error = "Expected number for %s but found: %s\n";
90
2/4
✓ Branch 5 → 6 taken 41982 times.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 41982 times.
41982 else if (d < min || d > max)
91 ✗ error = "The value for %s was %s which is not within %f - %f\n";
92
3/4
✓ Branch 8 → 9 taken 41655 times.
✓ Branch 8 → 11 taken 327 times.
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 41655 times.
41982 else if (type == OPT_TYPE_INT64 && (int64_t)d != d)
93 ✗ error = "Expected int64 for %s but found %s\n";
94
3/4
✓ Branch 11 → 12 taken 1 time.
✓ Branch 11 → 14 taken 41981 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 14 taken 1 time.
41982 else if (type == OPT_TYPE_INT && (int)d != d)
95 ✗ error = "Expected int for %s but found %s\n";
96 else {
97 41982 *dst = d;
98 41982 return 0;
99 }
100
101 ✗ av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max);
102 ✗ return AVERROR(EINVAL);
103 }
104
105 ✗ void show_help_options(const OptionDef *options, const char *msg, int req_flags,
106 int rej_flags)
107 {
108 const OptionDef *po;
109 int first;
110
111 ✗ first = 1;
112
0/2
✗ Branch 20 → 3 not taken.
✗ Branch 20 → 21 not taken.
✗ for (po = options; po->name; po++) {
113 char buf[128];
114
115
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ if (((po->flags & req_flags) != req_flags) ||
116
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ (po->flags & rej_flags))
117 ✗ continue;
118
119
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 9 not taken.
✗ if (first) {
120 ✗ printf("%s\n", msg);
121 ✗ first = 0;
122 }
123 ✗ av_strlcpy(buf, po->name, sizeof(buf));
124
125
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ if (po->flags & OPT_FLAG_PERSTREAM)
126 ✗ av_strlcat(buf, "[:<stream_spec>]", sizeof(buf));
127
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ else if (po->flags & OPT_FLAG_SPEC)
128 ✗ av_strlcat(buf, "[:<spec>]", sizeof(buf));
129
130
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (po->argname)
131 ✗ av_strlcatf(buf, sizeof(buf), " <%s>", po->argname);
132
133 ✗ printf("-%-17s %s\n", buf, po->help);
134 }
135 ✗ printf("\n");
136 ✗ }
137
138 ✗ void show_help_children(const AVClass *class, int flags)
139 {
140 ✗ void *iter = NULL;
141 const AVClass *child;
142
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 5 not taken.
✗ if (class->option) {
143 ✗ av_opt_show2(&class, NULL, flags, 0);
144 ✗ printf("\n");
145 }
146
147
0/2
✗ Branch 8 → 6 not taken.
✗ Branch 8 → 9 not taken.
✗ while (child = av_opt_child_class_iterate(class, &iter))
148 ✗ show_help_children(child, flags);
149 ✗ }
150
151 1410767 static const OptionDef *find_option(const OptionDef *po, const char *name)
152 {
153
2/2
✓ Branch 2 → 3 taken 432 times.
✓ Branch 2 → 4 taken 1410335 times.
1410767 if (*name == '/')
154 432 name++;
155
156
2/2
✓ Branch 11 → 5 taken 208461494 times.
✓ Branch 11 → 12 taken 800204 times.
209261698 while (po->name) {
157 const char *end;
158
6/6
✓ Branch 6 → 7 taken 1434496 times.
✓ Branch 6 → 9 taken 207026998 times.
✓ Branch 7 → 8 taken 880492 times.
✓ Branch 7 → 10 taken 554004 times.
✓ Branch 8 → 9 taken 823933 times.
✓ Branch 8 → 10 taken 56559 times.
208461494 if (av_strstart(name, po->name, &end) && (!*end || *end == ':'))
159 break;
160 207850931 po++;
161 }
162 1410767 return po;
163 }
164
165 /* _WIN32 means using the windows libc - cygwin doesn't define that
166 * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while
167 * it doesn't provide the actual command line via GetCommandLineW(). */
168 #if HAVE_COMMANDLINETOARGVW && defined(_WIN32)
169 #include <shellapi.h>
170 /* Will be leaked on exit */
171 static char** win32_argv_utf8 = NULL;
172 static int win32_argc = 0;
173
174 /**
175 * Prepare command line arguments for executable.
176 * For Windows - perform wide-char to UTF-8 conversion.
177 * Input arguments should be main() function arguments.
178 * @param argc_ptr Arguments number (including executable)
179 * @param argv_ptr Arguments list.
180 */
181 static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
182 {
183 char *argstr_flat;
184 wchar_t **argv_w;
185 int i, buffsize = 0, offset = 0;
186
187 if (win32_argv_utf8) {
188 *argc_ptr = win32_argc;
189 *argv_ptr = win32_argv_utf8;
190 return;
191 }
192
193 win32_argc = 0;
194 argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc);
195 if (win32_argc <= 0 || !argv_w)
196 return;
197
198 /* determine the UTF-8 buffer size (including NULL-termination symbols) */
199 for (i = 0; i < win32_argc; i++)
200 buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
201 NULL, 0, NULL, NULL);
202
203 win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize);
204 argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1);
205 if (!win32_argv_utf8) {
206 LocalFree(argv_w);
207 return;
208 }
209
210 for (i = 0; i < win32_argc; i++) {
211 win32_argv_utf8[i] = &argstr_flat[offset];
212 offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1,
213 &argstr_flat[offset],
214 buffsize - offset, NULL, NULL);
215 }
216 win32_argv_utf8[i] = NULL;
217 LocalFree(argv_w);
218
219 *argc_ptr = win32_argc;
220 *argv_ptr = win32_argv_utf8;
221 }
222 #else
223 9618 static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr)
224 {
225 /* nothing to do */
226 9618 }
227 #endif /* HAVE_COMMANDLINETOARGVW */
228
229 592167 static int opt_has_arg(const OptionDef *o)
230 {
231
2/2
✓ Branch 2 → 3 taken 187869 times.
✓ Branch 2 → 4 taken 404298 times.
592167 if (o->type == OPT_TYPE_BOOL)
232 187869 return 0;
233
2/2
✓ Branch 4 → 5 taken 142553 times.
✓ Branch 4 → 6 taken 261745 times.
404298 if (o->type == OPT_TYPE_FUNC)
234 142553 return !!(o->flags & OPT_FUNC_ARG);
235 261745 return 1;
236 }
237
238 110175 static int write_option(void *optctx, const OptionDef *po, const char *opt,
239 const char *arg, const OptionDef *defs)
240 {
241 /* new-style options contain an offset into optctx, old-style address of
242 * a global var*/
243 57490 void *dst = po->flags & OPT_FLAG_OFFSET ?
244
2/2
✓ Branch 2 → 3 taken 52685 times.
✓ Branch 2 → 4 taken 57490 times.
110175 (uint8_t *)optctx + po->u.off : po->u.dst_ptr;
245 110175 char *arg_allocated = NULL;
246
247 110175 enum OptionType so_type = po->type;
248
249 110175 SpecifierOptList *sol = NULL;
250 double num;
251 110175 int ret = 0;
252
253
2/2
✓ Branch 5 → 6 taken 72 times.
✓ Branch 5 → 15 taken 110103 times.
110175 if (*opt == '/') {
254 72 opt++;
255
256
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 72 times.
72 if (!opt_has_arg(po)) {
257 ✗ av_log(NULL, AV_LOG_FATAL,
258 "Requested to load an argument from file for an option '%s'"
259 " which does not take an argument\n",
260 ✗ po->name);
261 ✗ return AVERROR(EINVAL);
262 }
263
264 72 arg_allocated = read_file_to_string(arg);
265
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 14 taken 72 times.
72 if (!arg_allocated) {
266 ✗ av_log(NULL, AV_LOG_FATAL,
267 "Error reading the value for option '%s' from file: %s\n",
268 opt, arg);
269 ✗ return AVERROR(EINVAL);
270 }
271
272 72 arg = arg_allocated;
273 }
274
275
2/2
✓ Branch 15 → 16 taken 35447 times.
✓ Branch 15 → 30 taken 74728 times.
110175 if (po->flags & OPT_FLAG_SPEC) {
276 35447 const char *p = strchr(opt, ':');
277 char *str;
278
279 35447 sol = dst;
280 35447 ret = GROW_ARRAY(sol->opt, sol->nb_opt);
281
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 35447 times.
35447 if (ret < 0)
282 ✗ goto finish;
283
284
2/2
✓ Branch 19 → 20 taken 17644 times.
✓ Branch 19 → 21 taken 17803 times.
35447 str = av_strdup(p ? p + 1 : "");
285
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 25 taken 35447 times.
35447 if (!str) {
286 ✗ ret = AVERROR(ENOMEM);
287 ✗ goto finish;
288 }
289 35447 sol->opt[sol->nb_opt - 1].specifier = str;
290
291
2/2
✓ Branch 25 → 26 taken 35107 times.
✓ Branch 25 → 29 taken 340 times.
35447 if (po->flags & OPT_FLAG_PERSTREAM) {
292 35107 ret = stream_specifier_parse(&sol->opt[sol->nb_opt - 1].stream_spec,
293 str, 0, NULL);
294
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 35107 times.
35107 if (ret < 0)
295 ✗ goto finish;
296 }
297
298 35447 dst = &sol->opt[sol->nb_opt - 1].u;
299 }
300
301
2/2
✓ Branch 30 → 31 taken 42805 times.
✓ Branch 30 → 38 taken 67370 times.
110175 if (po->type == OPT_TYPE_STRING) {
302 char *str;
303
2/2
✓ Branch 31 → 32 taken 31 times.
✓ Branch 31 → 33 taken 42774 times.
42805 if (arg_allocated) {
304 31 str = arg_allocated;
305 31 arg_allocated = NULL;
306 } else
307 42774 str = av_strdup(arg);
308 42805 av_freep(dst);
309
310
1/2
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 42805 times.
42805 if (!str) {
311 ✗ ret = AVERROR(ENOMEM);
312 ✗ goto finish;
313 }
314
315 42805 *(char **)dst = str;
316
4/4
✓ Branch 38 → 39 taken 31499 times.
✓ Branch 38 → 40 taken 35871 times.
✓ Branch 39 → 40 taken 161 times.
✓ Branch 39 → 44 taken 31338 times.
67370 } else if (po->type == OPT_TYPE_BOOL || po->type == OPT_TYPE_INT) {
317 36032 ret = parse_number(opt, arg, OPT_TYPE_INT64, INT_MIN, INT_MAX, &num);
318
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 36032 times.
36032 if (ret < 0)
319 ✗ goto finish;
320
321 36032 *(int *)dst = num;
322 36032 so_type = OPT_TYPE_INT;
323
2/2
✓ Branch 44 → 45 taken 5623 times.
✓ Branch 44 → 49 taken 25715 times.
31338 } else if (po->type == OPT_TYPE_INT64) {
324 5623 ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, (double)INT64_MAX, &num);
325
1/2
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 5623 times.
5623 if (ret < 0)
326 ✗ goto finish;
327
328 5623 *(int64_t *)dst = num;
329
2/2
✓ Branch 49 → 50 taken 1468 times.
✓ Branch 49 → 55 taken 24247 times.
25715 } else if (po->type == OPT_TYPE_TIME) {
330 1468 ret = av_parse_time(dst, arg, 1);
331
1/2
✗ Branch 51 → 52 not taken.
✓ Branch 51 → 54 taken 1468 times.
1468 if (ret < 0) {
332 ✗ av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n",
333 opt, arg);
334 ✗ goto finish;
335 }
336 1468 so_type = OPT_TYPE_INT64;
337
2/2
✓ Branch 55 → 56 taken 18 times.
✓ Branch 55 → 60 taken 24229 times.
24247 } else if (po->type == OPT_TYPE_FLOAT) {
338 18 ret = parse_number(opt, arg, OPT_TYPE_FLOAT, -INFINITY, INFINITY, &num);
339
1/2
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 59 taken 18 times.
18 if (ret < 0)
340 ✗ goto finish;
341
342 18 *(float *)dst = num;
343
2/2
✓ Branch 60 → 61 taken 308 times.
✓ Branch 60 → 65 taken 23921 times.
24229 } else if (po->type == OPT_TYPE_DOUBLE) {
344 308 ret = parse_number(opt, arg, OPT_TYPE_DOUBLE, -INFINITY, INFINITY, &num);
345
1/2
✗ Branch 62 → 63 not taken.
✓ Branch 62 → 64 taken 308 times.
308 if (ret < 0)
346 ✗ goto finish;
347
348 308 *(double *)dst = num;
349 } else {
350
2/4
✓ Branch 65 → 66 taken 23921 times.
✗ Branch 65 → 67 not taken.
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 69 taken 23921 times.
23921 av_assert0(po->type == OPT_TYPE_FUNC && po->u.func_arg);
351
352 23921 ret = po->u.func_arg(optctx, opt, arg);
353
1/2
✗ Branch 70 → 71 not taken.
✓ Branch 70 → 77 taken 23921 times.
23921 if (ret < 0) {
354
0/4
✗ Branch 71 → 72 not taken.
✗ Branch 71 → 73 not taken.
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 76 not taken.
✗ if ((strcmp(opt, "init_hw_device") != 0) || (strcmp(arg, "list") != 0)) {
355 ✗ av_log(NULL, AV_LOG_ERROR,
356 "Failed to set value '%s' for option '%s': %s\n",
357 ✗ arg, opt, av_err2str(ret));
358 }
359 ✗ goto finish;
360 }
361 }
362
2/2
✓ Branch 77 → 78 taken 2 times.
✓ Branch 77 → 79 taken 110173 times.
110175 if (po->flags & OPT_EXIT) {
363 2 ret = AVERROR_EXIT;
364 2 goto finish;
365 }
366
367
2/2
✓ Branch 79 → 80 taken 74726 times.
✓ Branch 79 → 81 taken 35447 times.
110173 if (sol) {
368 35447 sol->type = so_type;
369
2/2
✓ Branch 81 → 82 taken 3029 times.
✓ Branch 81 → 83 taken 32418 times.
38476 sol->opt_canon = (po->flags & OPT_HAS_CANON) ?
370 3029 find_option(defs, po->u1.name_canon) : po;
371 }
372
373 74726 finish:
374 110175 av_freep(&arg_allocated);
375 110175 return ret;
376 }
377
378 11817 int parse_option(void *optctx, const char *opt, const char *arg,
379 const OptionDef *options)
380 {
381 static const OptionDef opt_avoptions = {
382 .name = "AVOption passthrough",
383 .type = OPT_TYPE_FUNC,
384 .flags = OPT_FUNC_ARG,
385 .u.func_arg = opt_default,
386 };
387
388 const OptionDef *po;
389 int ret;
390
391 11817 po = find_option(options, opt);
392
5/6
✓ Branch 3 → 4 taken 356 times.
✓ Branch 3 → 11 taken 11461 times.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 11 taken 355 times.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 11 not taken.
11817 if (!po->name && opt[0] == 'n' && opt[1] == 'o') {
393 /* handle 'no' bool option */
394 1 po = find_option(options, opt + 2);
395
2/4
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 10 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 10 not taken.
1 if ((po->name && po->type == OPT_TYPE_BOOL))
396 1 arg = "0";
397
2/2
✓ Branch 11 → 12 taken 346 times.
✓ Branch 11 → 13 taken 11470 times.
11816 } else if (po->type == OPT_TYPE_BOOL)
398 346 arg = "1";
399
400
2/2
✓ Branch 13 → 14 taken 355 times.
✓ Branch 13 → 15 taken 11462 times.
11817 if (!po->name)
401 355 po = &opt_avoptions;
402
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 18 taken 11817 times.
11817 if (!po->name) {
403 ✗ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt);
404 ✗ return AVERROR(EINVAL);
405 }
406
3/4
✓ Branch 19 → 20 taken 11291 times.
✓ Branch 19 → 23 taken 526 times.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 23 taken 11291 times.
11817 if (opt_has_arg(po) && !arg) {
407 ✗ av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt);
408 ✗ return AVERROR(EINVAL);
409 }
410
411 11817 ret = write_option(optctx, po, opt, arg, options);
412
1/2
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 11817 times.
11817 if (ret < 0)
413 ✗ return ret;
414
415 11817 return opt_has_arg(po);
416 }
417
418 398 int parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
419 int (*parse_arg_function)(void *, const char*))
420 {
421 const char *opt;
422 398 int optindex, handleoptions = 1, ret;
423
424 /* perform system-dependent conversions for arguments list */
425 398 prepare_app_arguments(&argc, &argv);
426
427 /* parse options */
428 398 optindex = 1;
429
2/2
✓ Branch 19 → 4 taken 2078 times.
✓ Branch 19 → 20 taken 398 times.
2476 while (optindex < argc) {
430 2078 opt = argv[optindex++];
431
432
4/6
✓ Branch 4 → 5 taken 2078 times.
✗ Branch 4 → 14 not taken.
✓ Branch 5 → 6 taken 1697 times.
✓ Branch 5 → 14 taken 381 times.
✓ Branch 6 → 7 taken 1697 times.
✗ Branch 6 → 14 not taken.
2078 if (handleoptions && opt[0] == '-' && opt[1] != '\0') {
433
1/4
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 1697 times.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
1697 if (opt[1] == '-' && opt[2] == '\0') {
434 ✗ handleoptions = 0;
435 ✗ continue;
436 }
437 1697 opt++;
438
439
1/2
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 13 taken 1697 times.
1697 if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0)
440 ✗ return ret;
441 1697 optindex += ret;
442 } else {
443
1/2
✓ Branch 14 → 15 taken 381 times.
✗ Branch 14 → 18 not taken.
381 if (parse_arg_function) {
444 381 ret = parse_arg_function(optctx, opt);
445
1/2
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 18 taken 381 times.
381 if (ret < 0)
446 ✗ return ret;
447 }
448 }
449 }
450
451 398 return 0;
452 }
453
454 26528 int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs)
455 {
456 int i, ret;
457
458 26528 av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n",
459 26528 g->group_def->name, g->arg);
460
461
2/2
✓ Branch 13 → 4 taken 98358 times.
✓ Branch 13 → 14 taken 26526 times.
124884 for (i = 0; i < g->nb_opts; i++) {
462 98358 Option *o = &g->opts[i];
463
464
2/2
✓ Branch 4 → 5 taken 53479 times.
✓ Branch 4 → 8 taken 44879 times.
98358 if (g->group_def->flags &&
465
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 8 taken 53479 times.
53479 !(g->group_def->flags & o->opt->flags)) {
466 ✗ av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to "
467 "%s %s -- you are trying to apply an input option to an "
468 "output file or vice versa. Move this option before the "
469 ✗ "file it belongs to.\n", o->key, o->opt->help,
470 ✗ g->group_def->name, g->arg);
471 ✗ return AVERROR(EINVAL);
472 }
473
474 98358 av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n",
475 98358 o->key, o->opt->help, o->val);
476
477 98358 ret = write_option(optctx, o->opt, o->key, o->val, defs);
478
2/2
✓ Branch 10 → 11 taken 2 times.
✓ Branch 10 → 12 taken 98356 times.
98358 if (ret < 0)
479 2 return ret;
480 }
481
482 26526 av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n");
483
484 26526 return 0;
485 }
486
487 48048 int locate_option(int argc, char **argv, const OptionDef *options,
488 const char *optname)
489 {
490 const OptionDef *po;
491 int i;
492
493
2/2
✓ Branch 21 → 3 taken 1081816 times.
✓ Branch 21 → 22 taken 47893 times.
1129709 for (i = 1; i < argc; i++) {
494 1081816 const char *cur_opt = argv[i];
495
496
4/4
✓ Branch 3 → 4 taken 1049676 times.
✓ Branch 3 → 5 taken 32140 times.
✓ Branch 4 → 5 taken 15721 times.
✓ Branch 4 → 6 taken 1033955 times.
1081816 if (!(cur_opt[0] == '-' && cur_opt[1]))
497 47861 continue;
498 1033955 cur_opt++;
499
500 1033955 po = find_option(options, cur_opt);
501
5/6
✓ Branch 7 → 8 taken 673478 times.
✓ Branch 7 → 11 taken 360477 times.
✓ Branch 8 → 9 taken 137274 times.
✓ Branch 8 → 11 taken 536204 times.
✓ Branch 9 → 10 taken 137274 times.
✗ Branch 9 → 11 not taken.
1033955 if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o')
502 137274 po = find_option(options, cur_opt + 2);
503
504
3/4
✓ Branch 11 → 12 taken 536244 times.
✓ Branch 11 → 13 taken 497711 times.
✓ Branch 12 → 13 taken 536244 times.
✗ Branch 12 → 15 not taken.
1033955 if ((!po->name && !strcmp(cur_opt, optname)) ||
505
4/4
✓ Branch 13 → 14 taken 497711 times.
✓ Branch 13 → 16 taken 536244 times.
✓ Branch 14 → 15 taken 155 times.
✓ Branch 14 → 16 taken 497556 times.
1033955 (po->name && !strcmp(optname, po->name)))
506 155 return i;
507
508
4/4
✓ Branch 16 → 17 taken 497556 times.
✓ Branch 16 → 19 taken 536244 times.
✓ Branch 18 → 19 taken 317550 times.
✓ Branch 18 → 20 taken 180006 times.
1033800 if (!po->name || opt_has_arg(po))
509 853794 i++;
510 }
511 47893 return 0;
512 }
513
514 ✗ static void dump_argument(FILE *report_file, const char *a)
515 {
516 const unsigned char *p;
517
518
0/2
✗ Branch 11 → 3 not taken.
✗ Branch 11 → 12 not taken.
✗ for (p = a; *p; p++)
519
0/8
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 10 not taken.
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 10 not taken.
✗ if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') ||
520
0/6
✗ Branch 7 → 8 not taken.
✗ Branch 7 → 10 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 12 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 12 not taken.
✗ *p == '_' || (*p >= 'a' && *p <= 'z')))
521 break;
522
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 15 not taken.
✗ if (!*p) {
523 ✗ fputs(a, report_file);
524 ✗ return;
525 }
526 ✗ fputc('"', report_file);
527
0/2
✗ Branch 27 → 17 not taken.
✗ Branch 27 → 28 not taken.
✗ for (p = a; *p; p++) {
528
0/8
✗ Branch 17 → 18 not taken.
✗ Branch 17 → 21 not taken.
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 21 not taken.
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 21 not taken.
✗ Branch 20 → 21 not taken.
✗ Branch 20 → 22 not taken.
✗ if (*p == '\\' || *p == '"' || *p == '$' || *p == '`')
529 ✗ fprintf(report_file, "\\%c", *p);
530
0/4
✗ Branch 22 → 23 not taken.
✗ Branch 22 → 24 not taken.
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 25 not taken.
✗ else if (*p < ' ' || *p > '~')
531 ✗ fprintf(report_file, "\\x%02x", *p);
532 else
533 ✗ fputc(*p, report_file);
534 }
535 ✗ fputc('"', report_file);
536 }
537
538 9618 static void check_options(const OptionDef *po)
539 {
540
2/2
✓ Branch 16 → 3 taken 1836572 times.
✓ Branch 16 → 17 taken 9618 times.
1846190 while (po->name) {
541
2/2
✓ Branch 3 → 4 taken 1134060 times.
✓ Branch 3 → 7 taken 702512 times.
1836572 if (po->flags & OPT_PERFILE)
542
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 7 taken 1134060 times.
1134060 av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT | OPT_DECODER));
543
544
2/2
✓ Branch 7 → 8 taken 694552 times.
✓ Branch 7 → 11 taken 1142020 times.
1836572 if (po->type == OPT_TYPE_FUNC)
545
1/2
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 694552 times.
694552 av_assert0(!(po->flags & (OPT_FLAG_OFFSET | OPT_FLAG_SPEC)));
546
547 // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC
548
3/4
✓ Branch 11 → 12 taken 1142020 times.
✓ Branch 11 → 15 taken 694552 times.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 15 taken 1142020 times.
1836572 av_assert0((po->type == OPT_TYPE_FUNC) || !(po->flags & OPT_FUNC_ARG));
549
550 1836572 po++;
551 }
552 9618 }
553
554 9618 void parse_loglevel(int argc, char **argv, const OptionDef *options)
555 {
556 int idx;
557 char *env;
558
559 9618 check_options(options);
560
561 9618 idx = locate_option(argc, argv, options, "loglevel");
562
2/2
✓ Branch 4 → 5 taken 9576 times.
✓ Branch 4 → 6 taken 42 times.
9618 if (!idx)
563 9576 idx = locate_option(argc, argv, options, "v");
564
3/4
✓ Branch 6 → 7 taken 118 times.
✓ Branch 6 → 9 taken 9500 times.
✓ Branch 7 → 8 taken 118 times.
✗ Branch 7 → 9 not taken.
9618 if (idx && argv[idx + 1])
565 118 opt_loglevel(NULL, "loglevel", argv[idx + 1]);
566 9618 idx = locate_option(argc, argv, options, "report");
567 9618 env = getenv_utf8("FFREPORT");
568
2/4
✓ Branch 11 → 12 taken 9618 times.
✗ Branch 11 → 13 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 26 taken 9618 times.
9618 if (env || idx) {
569 ✗ FILE *report_file = NULL;
570 ✗ init_report(env, &report_file);
571
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 25 not taken.
✗ if (report_file) {
572 int i;
573 ✗ fprintf(report_file, "Command line:\n");
574
0/2
✗ Branch 23 → 17 not taken.
✗ Branch 23 → 24 not taken.
✗ for (i = 0; i < argc; i++) {
575 ✗ dump_argument(report_file, argv[i]);
576
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 20 not taken.
✗ fputc(i < argc - 1 ? ' ' : '\n', report_file);
577 }
578 ✗ fflush(report_file);
579 }
580 }
581 9618 freeenv_utf8(env);
582 9618 idx = locate_option(argc, argv, options, "hide_banner");
583
2/2
✓ Branch 28 → 29 taken 37 times.
✓ Branch 28 → 30 taken 9581 times.
9618 if (idx)
584 37 hide_banner = 1;
585 9618 }
586
587 341593 static const AVOption *opt_find(void *obj, const char *name, const char *unit,
588 int opt_flags, int search_flags)
589 {
590 341593 const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags);
591
4/4
✓ Branch 3 → 4 taken 99347 times.
✓ Branch 3 → 6 taken 242246 times.
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 6 taken 99341 times.
341593 if(o && !o->flags)
592 6 return NULL;
593 341587 return o;
594 }
595
596 #define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0)
597 126685 int opt_default(void *optctx, const char *opt, const char *arg)
598 {
599 const AVOption *o;
600 126685 int consumed = 0;
601 char opt_stripped[128];
602 const char *p;
603 126685 const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class();
604 #if CONFIG_SWSCALE
605 126685 const AVClass *sc = sws_get_class();
606 #endif
607 #if CONFIG_SWRESAMPLE
608 126685 const AVClass *swr_class = swr_get_class();
609 #endif
610
611
2/4
✓ Branch 6 → 7 taken 126685 times.
✗ Branch 6 → 8 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 126685 times.
126685 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
612 ✗ av_log_set_level(AV_LOG_DEBUG);
613
614
2/2
✓ Branch 9 → 10 taken 126671 times.
✓ Branch 9 → 11 taken 14 times.
126685 if (!(p = strchr(opt, ':')))
615 126671 p = opt + strlen(opt);
616 126685 av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1));
617
618
2/2
✓ Branch 13 → 14 taken 60950 times.
✓ Branch 13 → 19 taken 65735 times.
126685 if ((o = opt_find(&cc, opt_stripped, NULL, 0,
619 60950 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) ||
620
8/8
✓ Branch 14 → 15 taken 60944 times.
✓ Branch 14 → 17 taken 6 times.
✓ Branch 15 → 16 taken 60921 times.
✓ Branch 15 → 17 taken 23 times.
✓ Branch 16 → 17 taken 16690 times.
✓ Branch 16 → 26 taken 44231 times.
✓ Branch 18 → 19 taken 1 time.
✓ Branch 18 → 26 taken 16718 times.
77669 ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') &&
621 16719 (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) {
622
5/6
✓ Branch 19 → 20 taken 24266 times.
✓ Branch 19 → 23 taken 41470 times.
✓ Branch 20 → 21 taken 24266 times.
✗ Branch 20 → 22 not taken.
✓ Branch 21 → 22 taken 16602 times.
✓ Branch 21 → 23 taken 7664 times.
65736 av_dict_set(&codec_opts, opt, arg, FLAGS);
623 65736 consumed = 1;
624 }
625
2/2
✓ Branch 27 → 28 taken 17009 times.
✓ Branch 27 → 37 taken 109676 times.
126685 if ((o = opt_find(&fc, opt, NULL, 0,
626 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
627
5/6
✓ Branch 28 → 29 taken 16555 times.
✓ Branch 28 → 32 taken 454 times.
✓ Branch 29 → 30 taken 16555 times.
✗ Branch 29 → 31 not taken.
✓ Branch 30 → 31 taken 16479 times.
✓ Branch 30 → 32 taken 76 times.
17009 av_dict_set(&format_opts, opt, arg, FLAGS);
628
2/2
✓ Branch 34 → 35 taken 110 times.
✓ Branch 34 → 36 taken 16899 times.
17009 if (consumed)
629 110 av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt);
630 17009 consumed = 1;
631 }
632 #if CONFIG_SWSCALE
633
4/4
✓ Branch 37 → 38 taken 44050 times.
✓ Branch 37 → 55 taken 82635 times.
✓ Branch 39 → 40 taken 16596 times.
✓ Branch 39 → 55 taken 27454 times.
126685 if (!consumed && (o = opt_find(&sc, opt, NULL, 0,
634 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
635
2/4
✓ Branch 40 → 41 taken 16596 times.
✗ Branch 40 → 46 not taken.
✓ Branch 41 → 42 taken 16596 times.
✗ Branch 41 → 46 not taken.
16596 if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") ||
636
2/4
✓ Branch 42 → 43 taken 16596 times.
✗ Branch 42 → 46 not taken.
✓ Branch 43 → 44 taken 16596 times.
✗ Branch 43 → 46 not taken.
16596 !strcmp(opt, "dstw") || !strcmp(opt, "dsth") ||
637
2/4
✓ Branch 44 → 45 taken 16596 times.
✗ Branch 44 → 46 not taken.
✗ Branch 45 → 46 not taken.
✓ Branch 45 → 48 taken 16596 times.
16596 !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) {
638 ✗ av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n");
639 ✗ return AVERROR(EINVAL);
640 }
641
4/6
✓ Branch 48 → 49 taken 16596 times.
✗ Branch 48 → 52 not taken.
✓ Branch 49 → 50 taken 16596 times.
✗ Branch 49 → 51 not taken.
✓ Branch 50 → 51 taken 16381 times.
✓ Branch 50 → 52 taken 215 times.
16596 av_dict_set(&sws_dict, opt, arg, FLAGS);
642
643 16596 consumed = 1;
644 }
645 #else
646 if (!consumed && !strcmp(opt, "sws_flags")) {
647 av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg);
648 consumed = 1;
649 }
650 #endif
651 #if CONFIG_SWRESAMPLE
652
3/4
✓ Branch 55 → 56 taken 27454 times.
✓ Branch 55 → 65 taken 99231 times.
✗ Branch 57 → 58 not taken.
✓ Branch 57 → 65 taken 27454 times.
126685 if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0,
653 AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) {
654
0/6
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 62 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✗ av_dict_set(&swr_opts, opt, arg, FLAGS);
655 ✗ consumed = 1;
656 }
657 #endif
658
659
2/2
✓ Branch 65 → 66 taken 99231 times.
✓ Branch 65 → 67 taken 27454 times.
126685 if (consumed)
660 99231 return 0;
661 27454 return AVERROR_OPTION_NOT_FOUND;
662 }
663
664 /*
665 * Check whether given option is a group separator.
666 *
667 * @return index of the group definition that matched or -1 if none
668 */
669 205321 static int match_group_separator(const OptionGroupDef *groups, int nb_groups,
670 const char *opt)
671 {
672 int i;
673
674
2/2
✓ Branch 7 → 3 taken 607880 times.
✓ Branch 7 → 8 taken 197237 times.
805117 for (i = 0; i < nb_groups; i++) {
675 607880 const OptionGroupDef *p = &groups[i];
676
4/4
✓ Branch 3 → 4 taken 402559 times.
✓ Branch 3 → 6 taken 205321 times.
✓ Branch 4 → 5 taken 8084 times.
✓ Branch 4 → 6 taken 394475 times.
607880 if (p->sep && !strcmp(p->sep, opt))
677 8084 return i;
678 }
679
680 197237 return -1;
681 }
682
683 /*
684 * Finish parsing an option group.
685 *
686 * @param group_idx which group definition should this group belong to
687 * @param arg argument of the group delimiting option
688 */
689 17310 static int finish_group(OptionParseContext *octx, int group_idx,
690 const char *arg)
691 {
692 17310 OptionGroupList *l = &octx->groups[group_idx];
693 OptionGroup *g;
694 int ret;
695
696 17310 ret = GROW_ARRAY(l->groups, l->nb_groups);
697
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 17310 times.
17310 if (ret < 0)
698 ✗ return ret;
699
700 17310 g = &l->groups[l->nb_groups - 1];
701
702 17310 *g = octx->cur_group;
703 17310 g->arg = arg;
704 17310 g->group_def = l->group_def;
705 17310 g->sws_dict = sws_dict;
706 17310 g->swr_opts = swr_opts;
707 17310 g->codec_opts = codec_opts;
708 17310 g->format_opts = format_opts;
709
710 17310 codec_opts = NULL;
711 17310 format_opts = NULL;
712 17310 sws_dict = NULL;
713 17310 swr_opts = NULL;
714
715 17310 memset(&octx->cur_group, 0, sizeof(octx->cur_group));
716
717 17310 return ret;
718 }
719
720 /*
721 * Add an option instance to currently parsed group.
722 */
723 98361 static int add_opt(OptionParseContext *octx, const OptionDef *opt,
724 const char *key, const char *val)
725 {
726 98361 int global = !(opt->flags & OPT_PERFILE);
727
2/2
✓ Branch 2 → 3 taken 44879 times.
✓ Branch 2 → 4 taken 53482 times.
98361 OptionGroup *g = global ? &octx->global_opts : &octx->cur_group;
728 int ret;
729
730 98361 ret = GROW_ARRAY(g->opts, g->nb_opts);
731
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 98361 times.
98361 if (ret < 0)
732 ✗ return ret;
733
734 98361 g->opts[g->nb_opts - 1].opt = opt;
735 98361 g->opts[g->nb_opts - 1].key = key;
736 98361 g->opts[g->nb_opts - 1].val = val;
737
738 98361 return 0;
739 }
740
741 9220 static int init_parse_context(OptionParseContext *octx,
742 const OptionGroupDef *groups, int nb_groups)
743 {
744 static const OptionGroupDef global_group = { "global" };
745 int i;
746
747 9220 memset(octx, 0, sizeof(*octx));
748
749 9220 octx->groups = av_calloc(nb_groups, sizeof(*octx->groups));
750
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 9220 times.
9220 if (!octx->groups)
751 ✗ return AVERROR(ENOMEM);
752 9220 octx->nb_groups = nb_groups;
753
754
2/2
✓ Branch 7 → 6 taken 27660 times.
✓ Branch 7 → 8 taken 9220 times.
36880 for (i = 0; i < octx->nb_groups; i++)
755 27660 octx->groups[i].group_def = &groups[i];
756
757 9220 octx->global_opts.group_def = &global_group;
758 9220 octx->global_opts.arg = "";
759
760 9220 return 0;
761 }
762
763 9220 void uninit_parse_context(OptionParseContext *octx)
764 {
765 int i, j;
766
767
2/2
✓ Branch 13 → 3 taken 27660 times.
✓ Branch 13 → 14 taken 9220 times.
36880 for (i = 0; i < octx->nb_groups; i++) {
768 27660 OptionGroupList *l = &octx->groups[i];
769
770
2/2
✓ Branch 10 → 4 taken 17310 times.
✓ Branch 10 → 11 taken 27660 times.
44970 for (j = 0; j < l->nb_groups; j++) {
771 17310 av_freep(&l->groups[j].opts);
772 17310 av_dict_free(&l->groups[j].codec_opts);
773 17310 av_dict_free(&l->groups[j].format_opts);
774
775 17310 av_dict_free(&l->groups[j].sws_dict);
776 17310 av_dict_free(&l->groups[j].swr_opts);
777 }
778 27660 av_freep(&l->groups);
779 }
780 9220 av_freep(&octx->groups);
781
782 9220 av_freep(&octx->cur_group.opts);
783 9220 av_freep(&octx->global_opts.opts);
784
785 9220 uninit_opts();
786 9220 }
787
788 9220 int split_commandline(OptionParseContext *octx, int argc, char *argv[],
789 const OptionDef *options,
790 const OptionGroupDef *groups, int nb_groups)
791 {
792 int ret;
793 9220 int optindex = 1;
794 9220 int dashdash = -2;
795
796 /* perform system-dependent conversions for arguments list */
797 9220 prepare_app_arguments(&argc, &argv);
798
799 9220 ret = init_parse_context(octx, groups, nb_groups);
800
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 9220 times.
9220 if (ret < 0)
801 ✗ return ret;
802
803 9220 av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n");
804
805
2/2
✓ Branch 68 → 8 taken 214547 times.
✓ Branch 68 → 69 taken 9220 times.
223767 while (optindex < argc) {
806 214547 const char *opt = argv[optindex++], *arg;
807 const OptionDef *po;
808 int group_idx;
809
810 214547 av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt);
811
812
3/6
✓ Branch 9 → 10 taken 208467 times.
✓ Branch 9 → 13 taken 6080 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 13 taken 208467 times.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 13 not taken.
214547 if (opt[0] == '-' && opt[1] == '-' && !opt[2]) {
813 ✗ dashdash = optindex;
814 ✗ continue;
815 }
816 /* unnamed group separators, e.g. output filename */
817
5/6
✓ Branch 13 → 14 taken 208467 times.
✓ Branch 13 → 16 taken 6080 times.
✓ Branch 14 → 15 taken 205321 times.
✓ Branch 14 → 16 taken 3146 times.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 21 taken 205321 times.
214547 if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) {
818 9226 ret = finish_group(octx, 0, opt);
819
1/2
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 19 taken 9226 times.
9226 if (ret < 0)
820 ✗ return ret;
821
822 9226 av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name);
823 9226 continue;
824 }
825 205321 opt++;
826
827 #define GET_ARG(arg) \
828 do { \
829 arg = argv[optindex++]; \
830 if (!arg) { \
831 av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\
832 return AVERROR(EINVAL); \
833 } \
834 } while (0)
835
836 /* named group separators, e.g. -i */
837 205321 group_idx = match_group_separator(groups, nb_groups, opt);
838
2/2
✓ Branch 22 → 23 taken 8084 times.
✓ Branch 22 → 31 taken 197237 times.
205321 if (group_idx >= 0) {
839
1/2
✗ Branch 23 → 24 not taken.
✓ Branch 23 → 26 taken 8084 times.
8084 GET_ARG(arg);
840 8084 ret = finish_group(octx, group_idx, arg);
841
1/2
✗ Branch 27 → 28 not taken.
✓ Branch 27 → 29 taken 8084 times.
8084 if (ret < 0)
842 ✗ return ret;
843
844 8084 av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n",
845 8084 groups[group_idx].name, arg);
846 8084 continue;
847 }
848
849 /* normal options */
850 197237 po = find_option(options, opt);
851
2/2
✓ Branch 32 → 33 taken 70907 times.
✓ Branch 32 → 46 taken 126330 times.
197237 if (po->name) {
852
2/2
✓ Branch 33 → 34 taken 2 times.
✓ Branch 33 → 35 taken 70905 times.
70907 if (po->flags & OPT_EXIT) {
853 /* optional argument, e.g. -h */
854 2 arg = argv[optindex++];
855
2/2
✓ Branch 36 → 37 taken 62835 times.
✓ Branch 36 → 40 taken 8070 times.
70905 } else if (opt_has_arg(po)) {
856
1/2
✗ Branch 37 → 38 not taken.
✓ Branch 37 → 41 taken 62835 times.
62835 GET_ARG(arg);
857 } else {
858 8070 arg = "1";
859 }
860
861 70907 ret = add_opt(octx, po, opt, arg);
862
1/2
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 70907 times.
70907 if (ret < 0)
863 ✗ return ret;
864
865 70907 av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
866 70907 "argument '%s'.\n", po->name, po->help, arg);
867 70907 continue;
868 }
869
870 /* AVOptions */
871
1/2
✓ Branch 46 → 47 taken 126330 times.
✗ Branch 46 → 54 not taken.
126330 if (argv[optindex]) {
872 126330 ret = opt_default(NULL, opt, argv[optindex]);
873
2/2
✓ Branch 48 → 49 taken 98876 times.
✓ Branch 48 → 51 taken 27454 times.
126330 if (ret >= 0) {
874 98876 av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with "
875 98876 "argument '%s'.\n", opt, argv[optindex]);
876 98876 optindex++;
877 98876 continue;
878
1/2
✗ Branch 51 → 52 not taken.
✓ Branch 51 → 54 taken 27454 times.
27454 } else if (ret != AVERROR_OPTION_NOT_FOUND) {
879 ✗ av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' "
880 ✗ "with argument '%s'.\n", opt, argv[optindex]);
881 ✗ return ret;
882 }
883 }
884
885 /* boolean -nofoo options */
886
3/6
✓ Branch 54 → 55 taken 27454 times.
✗ Branch 54 → 65 not taken.
✓ Branch 55 → 56 taken 27454 times.
✗ Branch 55 → 65 not taken.
✓ Branch 57 → 58 taken 27454 times.
✗ Branch 57 → 65 not taken.
54908 if (opt[0] == 'n' && opt[1] == 'o' &&
887 27454 (po = find_option(options, opt + 2)) &&
888
2/4
✓ Branch 58 → 59 taken 27454 times.
✗ Branch 58 → 65 not taken.
✓ Branch 59 → 60 taken 27454 times.
✗ Branch 59 → 65 not taken.
27454 po->name && po->type == OPT_TYPE_BOOL) {
889 27454 ret = add_opt(octx, po, opt, "0");
890
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 63 taken 27454 times.
27454 if (ret < 0)
891 ✗ return ret;
892
893 27454 av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with "
894 27454 "argument 0.\n", po->name, po->help);
895 27454 continue;
896 }
897
898 ✗ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt);
899 ✗ return AVERROR_OPTION_NOT_FOUND;
900 }
901
902
3/6
✓ Branch 69 → 70 taken 9220 times.
✗ Branch 69 → 72 not taken.
✓ Branch 70 → 71 taken 9220 times.
✗ Branch 70 → 72 not taken.
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 73 taken 9220 times.
9220 if (octx->cur_group.nb_opts || codec_opts || format_opts)
903 ✗ av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the "
904 "command: may be ignored.\n");
905
906 9220 av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n");
907
908 9220 return 0;
909 }
910
911 ✗ int read_yesno(void)
912 {
913 ✗ int c = getchar();
914 ✗ int yesno = (av_toupper(c) == 'Y');
915
916
0/4
✗ Branch 5 → 6 not taken.
✗ Branch 5 → 7 not taken.
✗ Branch 6 → 4 not taken.
✗ Branch 6 → 7 not taken.
✗ while (c != '\n' && c != EOF)
917 ✗ c = getchar();
918
919 ✗ return yesno;
920 }
921
922 ✗ FILE *get_preset_file(char *filename, size_t filename_size,
923 const char *preset_name, int is_path,
924 const char *codec_name)
925 {
926 ✗ FILE *f = NULL;
927 int i;
928 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
929 char *datadir = NULL;
930 #endif
931 ✗ char *env_home = getenv_utf8("HOME");
932 ✗ char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR");
933 ✗ const char *base[3] = { env_ffmpeg_datadir,
934 env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */
935 FFMPEG_DATADIR, };
936
937
0/2
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 7 not taken.
✗ if (is_path) {
938 ✗ av_strlcpy(filename, preset_name, filename_size);
939 ✗ f = fopen_utf8(filename, "r");
940 } else {
941 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
942 wchar_t *datadir_w = get_module_filename(NULL);
943 base[2] = NULL;
944
945 if (wchartoutf8(datadir_w, &datadir))
946 datadir = NULL;
947 av_free(datadir_w);
948
949 if (datadir)
950 {
951 char *ls;
952 for (ls = datadir; *ls; ls++)
953 if (*ls == '\\') *ls = '/';
954
955 if (ls = strrchr(datadir, '/'))
956 {
957 ptrdiff_t datadir_len = ls - datadir;
958 size_t desired_size = datadir_len + strlen("/ffpresets") + 1;
959 char *new_datadir = av_realloc_array(
960 datadir, desired_size, sizeof *datadir);
961 if (new_datadir) {
962 datadir = new_datadir;
963 strcpy(datadir + datadir_len, "/ffpresets");
964 base[2] = datadir;
965 }
966 }
967 }
968 #endif
969
0/4
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ Branch 22 → 8 not taken.
✗ Branch 22 → 23 not taken.
✗ for (i = 0; i < 3 && !f; i++) {
970
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ if (!base[i])
971 ✗ continue;
972
0/2
✗ Branch 10 → 11 not taken.
✗ Branch 10 → 12 not taken.
✗ snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i],
973 i != 1 ? "" : "/.ffmpeg", preset_name);
974 ✗ f = fopen_utf8(filename, "r");
975
0/4
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 20 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 20 not taken.
✗ if (!f && codec_name) {
976
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ snprintf(filename, filename_size,
977 "%s%s/%s-%s.ffpreset",
978 base[i], i != 1 ? "" : "/.ffmpeg", codec_name,
979 preset_name);
980 ✗ f = fopen_utf8(filename, "r");
981 }
982 }
983 }
984
985 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
986 av_free(datadir);
987 #endif
988 ✗ freeenv_utf8(env_ffmpeg_datadir);
989 ✗ freeenv_utf8(env_home);
990 ✗ return f;
991 }
992
993 18519 int cmdutils_isalnum(char c)
994 {
995
4/4
✓ Branch 3 → 4 taken 358 times.
✓ Branch 3 → 8 taken 1 time.
✓ Branch 4 → 5 taken 55 times.
✓ Branch 4 → 6 taken 18463 times.
18519 return (c >= '0' && c <= '9') ||
996
5/6
✓ Branch 2 → 3 taken 359 times.
✓ Branch 2 → 4 taken 18160 times.
✓ Branch 5 → 6 taken 55 times.
✗ Branch 5 → 8 not taken.
✓ Branch 6 → 7 taken 49 times.
✓ Branch 6 → 9 taken 18469 times.
37087 (c >= 'A' && c <= 'Z') ||
997
1/2
✓ Branch 7 → 8 taken 49 times.
✗ Branch 7 → 9 not taken.
49 (c >= 'a' && c <= 'z');
998 }
999
1000 36614 void stream_specifier_uninit(StreamSpecifier *ss)
1001 {
1002 36614 av_freep(&ss->meta_key);
1003 36614 av_freep(&ss->meta_val);
1004 36614 av_freep(&ss->remainder);
1005
1006 36614 memset(ss, 0, sizeof(*ss));
1007 36614 }
1008
1009 36609 int stream_specifier_parse(StreamSpecifier *ss, const char *spec,
1010 int allow_remainder, void *logctx)
1011 {
1012 char *endptr;
1013 int ret;
1014
1015 36609 memset(ss, 0, sizeof(*ss));
1016
1017 36609 ss->idx = -1;
1018 36609 ss->media_type = AVMEDIA_TYPE_UNKNOWN;
1019 36609 ss->stream_list = STREAM_LIST_ALL;
1020
1021 36609 av_log(logctx, AV_LOG_TRACE, "Parsing stream specifier: %s\n", spec);
1022
1023
2/2
✓ Branch 130 → 4 taken 19318 times.
✓ Branch 130 → 131 taken 35874 times.
91801 while (*spec) {
1024
3/4
✓ Branch 4 → 5 taken 634 times.
✓ Branch 4 → 12 taken 18684 times.
✓ Branch 5 → 6 taken 634 times.
✗ Branch 5 → 12 not taken.
19318 if (*spec <= '9' && *spec >= '0') { /* opt:index */
1025 634 ss->idx = strtol(spec, &endptr, 0);
1026
1027
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 10 taken 634 times.
634 av_assert0(endptr > spec);
1028 634 spec = endptr;
1029
1030 634 av_log(logctx, AV_LOG_TRACE,
1031 "Parsed index: %d; remainder: %s\n", ss->idx, spec);
1032
1033 // this terminates the specifier
1034 634 break;
1035
6/6
✓ Branch 12 → 13 taken 2407 times.
✓ Branch 12 → 18 taken 16277 times.
✓ Branch 13 → 14 taken 267 times.
✓ Branch 13 → 18 taken 2140 times.
✓ Branch 14 → 15 taken 202 times.
✓ Branch 14 → 18 taken 65 times.
18684 } else if ((*spec == 'v' || *spec == 'a' || *spec == 's' ||
1036
7/8
✓ Branch 15 → 16 taken 199 times.
✓ Branch 15 → 18 taken 3 times.
✓ Branch 16 → 17 taken 196 times.
✓ Branch 16 → 18 taken 3 times.
✗ Branch 17 → 18 not taken.
✓ Branch 17 → 34 taken 196 times.
✓ Branch 19 → 20 taken 18464 times.
✓ Branch 19 → 34 taken 24 times.
18690 *spec == 'd' || *spec == 't' || *spec == 'V') &&
1037 18488 !cmdutils_isalnum(*(spec + 1))) { /* opt:[vasdtV] */
1038
1/2
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 23 taken 18464 times.
18464 if (ss->media_type != AVMEDIA_TYPE_UNKNOWN) {
1039 ✗ av_log(logctx, AV_LOG_ERROR, "Stream type specified multiple times\n");
1040 ✗ ret = AVERROR(EINVAL);
1041 ✗ goto fail;
1042 }
1043
1044
5/7
✓ Branch 23 → 24 taken 16262 times.
✓ Branch 23 → 25 taken 2134 times.
✓ Branch 23 → 26 taken 63 times.
✓ Branch 23 → 27 taken 2 times.
✓ Branch 23 → 28 taken 3 times.
✗ Branch 23 → 29 not taken.
✗ Branch 23 → 30 not taken.
18464 switch (*spec++) {
1045 16262 case 'v': ss->media_type = AVMEDIA_TYPE_VIDEO; break;
1046 2134 case 'a': ss->media_type = AVMEDIA_TYPE_AUDIO; break;
1047 63 case 's': ss->media_type = AVMEDIA_TYPE_SUBTITLE; break;
1048 2 case 'd': ss->media_type = AVMEDIA_TYPE_DATA; break;
1049 3 case 't': ss->media_type = AVMEDIA_TYPE_ATTACHMENT; break;
1050 ✗ case 'V': ss->media_type = AVMEDIA_TYPE_VIDEO;
1051 ✗ ss->no_apic = 1; break;
1052 ✗ default: av_assert0(0);
1053 }
1054
1055 18464 av_log(logctx, AV_LOG_TRACE, "Parsed media type: %s; remainder: %s\n",
1056 av_get_media_type_string(ss->media_type), spec);
1057
4/4
✓ Branch 34 → 35 taken 119 times.
✓ Branch 34 → 54 taken 101 times.
✓ Branch 35 → 36 taken 118 times.
✓ Branch 35 → 54 taken 1 time.
220 } else if (*spec == 'g' && *(spec + 1) == ':') {
1058
1/2
✗ Branch 36 → 37 not taken.
✓ Branch 36 → 38 taken 118 times.
118 if (ss->stream_list != STREAM_LIST_ALL)
1059 ✗ goto multiple_stream_lists;
1060
1061 118 spec += 2;
1062
5/6
✓ Branch 38 → 39 taken 114 times.
✓ Branch 38 → 41 taken 4 times.
✓ Branch 39 → 40 taken 3 times.
✓ Branch 39 → 45 taken 111 times.
✓ Branch 40 → 41 taken 3 times.
✗ Branch 40 → 45 not taken.
118 if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) {
1063 7 ss->stream_list = STREAM_LIST_GROUP_ID;
1064
1065
2/2
✓ Branch 41 → 42 taken 3 times.
✓ Branch 41 → 43 taken 4 times.
7 spec += 1 + (*spec == 'i');
1066 } else
1067 111 ss->stream_list = STREAM_LIST_GROUP_IDX;
1068
1069 118 ss->list_id = strtol(spec, &endptr, 0);
1070
1/2
✗ Branch 47 → 48 not taken.
✓ Branch 47 → 50 taken 118 times.
118 if (spec == endptr) {
1071 ✗ av_log(logctx, AV_LOG_ERROR, "Expected stream group idx/ID, got: %s\n", spec);
1072 ✗ ret = AVERROR(EINVAL);
1073 ✗ goto fail;
1074 }
1075 118 spec = endptr;
1076
1077 118 av_log(logctx, AV_LOG_TRACE, "Parsed stream group %s: %"PRId64"; remainder: %s\n",
1078
2/2
✓ Branch 50 → 51 taken 7 times.
✓ Branch 50 → 52 taken 111 times.
118 ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index", ss->list_id, spec);
1079
1/4
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 63 taken 102 times.
✗ Branch 55 → 56 not taken.
✗ Branch 55 → 63 not taken.
102 } else if (*spec == 'p' && *(spec + 1) == ':') {
1080
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ if (ss->stream_list != STREAM_LIST_ALL)
1081 ✗ goto multiple_stream_lists;
1082
1083 ✗ ss->stream_list = STREAM_LIST_PROGRAM;
1084
1085 ✗ spec += 2;
1086 ✗ ss->list_id = strtol(spec, &endptr, 0);
1087
0/2
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 62 not taken.
✗ if (spec == endptr) {
1088 ✗ av_log(logctx, AV_LOG_ERROR, "Expected program ID, got: %s\n", spec);
1089 ✗ ret = AVERROR(EINVAL);
1090 ✗ goto fail;
1091 }
1092 ✗ spec = endptr;
1093
1094 ✗ av_log(logctx, AV_LOG_TRACE,
1095 "Parsed program ID: %"PRId64"; remainder: %s\n", ss->list_id, spec);
1096
2/2
✓ Branch 63 → 64 taken 1 time.
✓ Branch 63 → 90 taken 101 times.
102 } else if (!strncmp(spec, "disp:", 5)) {
1097 1 const AVClass *st_class = av_stream_get_class();
1098 1 const AVOption *o = av_opt_find(&st_class, "disposition", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
1099 1 char *disp = NULL;
1100 size_t len;
1101
1102
1/2
✗ Branch 66 → 67 not taken.
✓ Branch 66 → 69 taken 1 time.
1 av_assert0(o);
1103
1104
1/2
✗ Branch 69 → 70 not taken.
✓ Branch 69 → 72 taken 1 time.
1 if (ss->disposition) {
1105 ✗ av_log(logctx, AV_LOG_ERROR, "Multiple disposition specifiers\n");
1106 ✗ ret = AVERROR(EINVAL);
1107 ✗ goto fail;
1108 }
1109
1110 1 spec += 5;
1111
1112 29 for (len = 0; cmdutils_isalnum(spec[len]) ||
1113
6/6
✓ Branch 76 → 73 taken 26 times.
✓ Branch 76 → 77 taken 3 times.
✓ Branch 77 → 73 taken 1 time.
✓ Branch 77 → 78 taken 2 times.
✓ Branch 78 → 73 taken 1 time.
✓ Branch 78 → 79 taken 1 time.
57 spec[len] == '_' || spec[len] == '+'; len++)
1114 28 continue;
1115
1116 1 disp = av_strndup(spec, len);
1117
1/2
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 82 taken 1 time.
1 if (!disp) {
1118 ✗ ret = AVERROR(ENOMEM);
1119 ✗ goto fail;
1120 }
1121
1122 1 ret = av_opt_eval_flags(&st_class, o, disp, &ss->disposition);
1123 1 av_freep(&disp);
1124
1/2
✗ Branch 84 → 85 not taken.
✓ Branch 84 → 87 taken 1 time.
1 if (ret < 0) {
1125 ✗ av_log(logctx, AV_LOG_ERROR, "Invalid disposition specifier\n");
1126 ✗ goto fail;
1127 }
1128
1129 1 spec += len;
1130
1131 1 av_log(logctx, AV_LOG_TRACE,
1132 "Parsed disposition: 0x%x; remainder: %s\n", ss->disposition, spec);
1133
1/2
✓ Branch 90 → 91 taken 101 times.
✗ Branch 90 → 93 not taken.
101 } else if (*spec == '#' ||
1134
1/4
✗ Branch 91 → 92 not taken.
✓ Branch 91 → 104 taken 101 times.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 104 not taken.
101 (*spec == 'i' && *(spec + 1) == ':')) {
1135
0/2
✗ Branch 93 → 94 not taken.
✗ Branch 93 → 95 not taken.
✗ if (ss->stream_list != STREAM_LIST_ALL)
1136 ✗ goto multiple_stream_lists;
1137
1138 ✗ ss->stream_list = STREAM_LIST_STREAM_ID;
1139
1140
0/2
✗ Branch 95 → 96 not taken.
✗ Branch 95 → 97 not taken.
✗ spec += 1 + (*spec == 'i');
1141 ✗ ss->list_id = strtol(spec, &endptr, 0);
1142
0/2
✗ Branch 99 → 100 not taken.
✗ Branch 99 → 102 not taken.
✗ if (spec == endptr) {
1143 ✗ av_log(logctx, AV_LOG_ERROR, "Expected stream ID, got: %s\n", spec);
1144 ✗ ret = AVERROR(EINVAL);
1145 ✗ goto fail;
1146 }
1147 ✗ spec = endptr;
1148
1149 ✗ av_log(logctx, AV_LOG_TRACE,
1150 "Parsed stream ID: %"PRId64"; remainder: %s\n", ss->list_id, spec);
1151
1152 // this terminates the specifier
1153 ✗ break;
1154
3/4
✓ Branch 104 → 105 taken 1 time.
✓ Branch 104 → 122 taken 100 times.
✗ Branch 105 → 106 not taken.
✓ Branch 105 → 122 taken 1 time.
101 } else if (*spec == 'm' && *(spec + 1) == ':') {
1155
0/4
✗ Branch 106 → 107 not taken.
✗ Branch 106 → 108 not taken.
✗ Branch 107 → 108 not taken.
✗ Branch 107 → 110 not taken.
✗ av_assert0(!ss->meta_key && !ss->meta_val);
1156
1157 ✗ spec += 2;
1158 ✗ ss->meta_key = av_get_token(&spec, ":");
1159
0/2
✗ Branch 111 → 112 not taken.
✗ Branch 111 → 113 not taken.
✗ if (!ss->meta_key) {
1160 ✗ ret = AVERROR(ENOMEM);
1161 ✗ goto fail;
1162 }
1163
0/2
✗ Branch 113 → 114 not taken.
✗ Branch 113 → 117 not taken.
✗ if (*spec == ':') {
1164 ✗ spec++;
1165 ✗ ss->meta_val = av_get_token(&spec, ":");
1166
0/2
✗ Branch 115 → 116 not taken.
✗ Branch 115 → 117 not taken.
✗ if (!ss->meta_val) {
1167 ✗ ret = AVERROR(ENOMEM);
1168 ✗ goto fail;
1169 }
1170 }
1171
1172 ✗ av_log(logctx, AV_LOG_TRACE,
1173 "Parsed metadata: %s:%s; remainder: %s", ss->meta_key,
1174
0/2
✗ Branch 117 → 118 not taken.
✗ Branch 117 → 119 not taken.
✗ ss->meta_val ? ss->meta_val : "<any value>", spec);
1175
1176 // this terminates the specifier
1177 ✗ break;
1178
1/6
✗ Branch 122 → 123 not taken.
✓ Branch 122 → 131 taken 101 times.
✗ Branch 123 → 124 not taken.
✗ Branch 123 → 125 not taken.
✗ Branch 124 → 125 not taken.
✗ Branch 124 → 131 not taken.
101 } else if (*spec == 'u' && (*(spec + 1) == '\0' || *(spec + 1) == ':')) {
1179 ✗ ss->usable_only = 1;
1180 ✗ spec++;
1181 ✗ av_log(logctx, AV_LOG_ERROR, "Parsed 'usable only'\n");
1182
1183 // this terminates the specifier
1184 ✗ break;
1185 } else
1186 break;
1187
1188
2/2
✓ Branch 127 → 128 taken 407 times.
✓ Branch 127 → 130 taken 18176 times.
18583 if (*spec == ':')
1189 407 spec++;
1190 }
1191
1192
2/2
✓ Branch 131 → 132 taken 101 times.
✓ Branch 131 → 140 taken 36508 times.
36609 if (*spec) {
1193
2/2
✓ Branch 132 → 133 taken 1 time.
✓ Branch 132 → 135 taken 100 times.
101 if (!allow_remainder) {
1194 1 av_log(logctx, AV_LOG_ERROR,
1195 "Trailing garbage at the end of a stream specifier: %s\n",
1196 spec);
1197 1 ret = AVERROR(EINVAL);
1198 1 goto fail;
1199 }
1200
1201
1/2
✗ Branch 135 → 136 not taken.
✓ Branch 135 → 137 taken 100 times.
100 if (*spec == ':')
1202 ✗ spec++;
1203
1204 100 ss->remainder = av_strdup(spec);
1205
1/2
✗ Branch 138 → 139 not taken.
✓ Branch 138 → 140 taken 100 times.
100 if (!ss->remainder) {
1206 ✗ ret = AVERROR(EINVAL);
1207 ✗ goto fail;
1208 }
1209 }
1210
1211 36608 return 0;
1212
1213 ✗ multiple_stream_lists:
1214 ✗ av_log(logctx, AV_LOG_ERROR,
1215 "Cannot combine multiple program/group designators in a "
1216 "single stream specifier");
1217 ✗ ret = AVERROR(EINVAL);
1218
1219 1 fail:
1220 1 stream_specifier_uninit(ss);
1221 1 return ret;
1222 }
1223
1224 39386 unsigned stream_specifier_match(const StreamSpecifier *ss,
1225 const AVFormatContext *s, const AVStream *st,
1226 void *logctx)
1227 {
1228 39386 const AVStreamGroup *g = NULL;
1229 39386 const AVProgram *p = NULL;
1230 39386 int start_stream = 0, nb_streams;
1231 39386 int nb_matched = 0;
1232
1233
3/6
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 9 taken 38486 times.
✗ Branch 2 → 13 not taken.
✓ Branch 2 → 22 taken 49 times.
✓ Branch 2 → 27 taken 851 times.
✗ Branch 2 → 38 not taken.
39386 switch (ss->stream_list) {
1234 ✗ case STREAM_LIST_STREAM_ID:
1235 // <n-th> stream with given ID makes no sense and should be impossible to request
1236
0/2
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 6 not taken.
✗ av_assert0(ss->idx < 0);
1237 // return early if we know for sure the stream does not match
1238
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ if (st->id != ss->list_id)
1239 ✗ return 0;
1240 ✗ start_stream = st->index;
1241 ✗ nb_streams = st->index + 1;
1242 ✗ break;
1243 38486 case STREAM_LIST_ALL:
1244
2/2
✓ Branch 9 → 10 taken 37506 times.
✓ Branch 9 → 11 taken 980 times.
38486 start_stream = ss->idx >= 0 ? 0 : st->index;
1245 38486 nb_streams = st->index + 1;
1246 38486 break;
1247 ✗ case STREAM_LIST_PROGRAM:
1248
0/2
✗ Branch 17 → 14 not taken.
✗ Branch 17 → 18 not taken.
✗ for (unsigned i = 0; i < s->nb_programs; i++) {
1249
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (s->programs[i]->id == ss->list_id) {
1250 ✗ p = s->programs[i];
1251 ✗ break;
1252 }
1253 }
1254
0/2
✗ Branch 18 → 19 not taken.
✗ Branch 18 → 21 not taken.
✗ if (!p) {
1255 ✗ av_log(logctx, AV_LOG_WARNING, "No program with ID %"PRId64" exists,"
1256 ✗ " stream specifier can never match\n", ss->list_id);
1257 ✗ return 0;
1258 }
1259 ✗ nb_streams = p->nb_stream_indexes;
1260 ✗ break;
1261 49 case STREAM_LIST_GROUP_ID:
1262
1/2
✓ Branch 26 → 23 taken 58 times.
✗ Branch 26 → 27 not taken.
58 for (unsigned i = 0; i < s->nb_stream_groups; i++) {
1263
2/2
✓ Branch 23 → 24 taken 49 times.
✓ Branch 23 → 25 taken 9 times.
58 if (ss->list_id == s->stream_groups[i]->id) {
1264 49 g = s->stream_groups[i];
1265 49 break;
1266 }
1267 }
1268 av_fallthrough;
1269 case STREAM_LIST_GROUP_IDX:
1270
2/2
✓ Branch 27 → 28 taken 851 times.
✓ Branch 27 → 31 taken 49 times.
900 if (ss->stream_list == STREAM_LIST_GROUP_IDX &&
1271
2/4
✓ Branch 28 → 29 taken 851 times.
✗ Branch 28 → 31 not taken.
✓ Branch 29 → 30 taken 851 times.
✗ Branch 29 → 31 not taken.
851 ss->list_id >= 0 && ss->list_id < s->nb_stream_groups)
1272 851 g = s->stream_groups[ss->list_id];
1273
1274
1/2
✗ Branch 31 → 32 not taken.
✓ Branch 31 → 37 taken 900 times.
900 if (!g) {
1275 ✗ av_log(logctx, AV_LOG_WARNING, "No stream group with group %s %"
1276 PRId64" exists, stream specifier can never match\n",
1277 ✗ ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index",
1278
0/2
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✗ ss->list_id);
1279 ✗ return 0;
1280 }
1281 900 nb_streams = g->nb_entries;
1282 900 break;
1283 ✗ default: av_assert0(0);
1284 }
1285
1286
2/2
✓ Branch 85 → 41 taken 51326 times.
✓ Branch 85 → 86 taken 871 times.
52197 for (int i = start_stream; i < nb_streams; i++) {
1287
3/4
✓ Branch 41 → 42 taken 6335 times.
✓ Branch 41 → 44 taken 44991 times.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 6335 times.
51326 if (g && g->entries[i]->type != AV_STREAM_GROUP_ENTRY_STREAM)
1288 ✗ continue;
1289
1290
3/4
✓ Branch 44 → 45 taken 6335 times.
✓ Branch 44 → 46 taken 44991 times.
✗ Branch 46 → 47 not taken.
✓ Branch 46 → 48 taken 44991 times.
51326 const AVStream *candidate = s->streams[g ? g->entries[i]->stream->index :
1291 ✗ p ? p->stream_index[i] : i];
1292
1293
2/2
✓ Branch 49 → 50 taken 28314 times.
✓ Branch 49 → 54 taken 23012 times.
51326 if (ss->media_type != AVMEDIA_TYPE_UNKNOWN &&
1294
2/2
✓ Branch 50 → 51 taken 27489 times.
✓ Branch 50 → 53 taken 825 times.
28314 (ss->media_type != candidate->codecpar->codec_type ||
1295
1/4
✗ Branch 51 → 52 not taken.
✓ Branch 51 → 54 taken 27489 times.
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
27489 (ss->no_apic && (candidate->disposition & AV_DISPOSITION_ATTACHED_PIC))))
1296 825 continue;
1297
1298
1/2
✗ Branch 54 → 55 not taken.
✓ Branch 54 → 61 taken 50501 times.
50501 if (ss->meta_key) {
1299 ✗ const AVDictionaryEntry *tag = av_dict_get(candidate->metadata,
1300 ✗ ss->meta_key, NULL, 0);
1301
1302
0/2
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 58 not taken.
✗ if (!tag)
1303 ✗ continue;
1304
0/4
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 61 not taken.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
✗ if (ss->meta_val && strcmp(tag->value, ss->meta_val))
1305 ✗ continue;
1306 }
1307
1308
1/2
✗ Branch 61 → 62 not taken.
✓ Branch 61 → 74 taken 50501 times.
50501 if (ss->usable_only) {
1309 ✗ const AVCodecParameters *par = candidate->codecpar;
1310
1311
0/4
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 68 not taken.
✗ Branch 62 → 73 not taken.
✗ Branch 62 → 74 not taken.
✗ switch (par->codec_type) {
1312 ✗ case AVMEDIA_TYPE_AUDIO:
1313
0/4
✗ Branch 63 → 64 not taken.
✗ Branch 63 → 66 not taken.
✗ Branch 64 → 65 not taken.
✗ Branch 64 → 66 not taken.
✗ if (!par->sample_rate || !par->ch_layout.nb_channels ||
1314
0/2
✗ Branch 65 → 66 not taken.
✗ Branch 65 → 67 not taken.
✗ par->format == AV_SAMPLE_FMT_NONE)
1315 ✗ continue;
1316 ✗ break;
1317 ✗ case AVMEDIA_TYPE_VIDEO:
1318
0/6
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 71 not taken.
✗ Branch 69 → 70 not taken.
✗ Branch 69 → 71 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
✗ if (!par->width || !par->height || par->format == AV_PIX_FMT_NONE)
1319 ✗ continue;
1320 ✗ break;
1321 ✗ case AVMEDIA_TYPE_UNKNOWN:
1322 ✗ continue;
1323 }
1324 }
1325
1326
2/2
✓ Branch 74 → 75 taken 55 times.
✓ Branch 74 → 77 taken 50446 times.
50501 if (ss->disposition &&
1327
2/2
✓ Branch 75 → 76 taken 44 times.
✓ Branch 75 → 77 taken 11 times.
55 (candidate->disposition & ss->disposition) != ss->disposition)
1328 44 continue;
1329
1330
2/2
✓ Branch 77 → 78 taken 38515 times.
✓ Branch 77 → 83 taken 11942 times.
50457 if (st == candidate)
1331
4/4
✓ Branch 78 → 79 taken 1339 times.
✓ Branch 78 → 80 taken 37176 times.
✓ Branch 79 → 80 taken 404 times.
✓ Branch 79 → 81 taken 935 times.
38515 return ss->idx < 0 || ss->idx == nb_matched;
1332
1333 11942 nb_matched++;
1334 }
1335
1336 871 return 0;
1337 }
1338
1339 702 int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
1340 {
1341 StreamSpecifier ss;
1342 int ret;
1343
1344 702 ret = stream_specifier_parse(&ss, spec, 0, NULL);
1345
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 701 times.
702 if (ret < 0)
1346 1 return ret;
1347
1348 701 ret = stream_specifier_match(&ss, s, st, NULL);
1349 701 stream_specifier_uninit(&ss);
1350 701 return ret;
1351 }
1352
1353 ✗ unsigned stream_group_specifier_match(const StreamSpecifier *ss,
1354 const AVFormatContext *s, const AVStreamGroup *stg,
1355 void *logctx)
1356 {
1357 ✗ int start_stream_group = 0, nb_stream_groups;
1358 ✗ int nb_matched = 0;
1359
1360
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (ss->idx >= 0)
1361 ✗ return 0;
1362
1363
0/4
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✗ Branch 4 → 12 not taken.
✗ Branch 4 → 16 not taken.
✗ switch (ss->stream_list) {
1364 ✗ case STREAM_LIST_STREAM_ID:
1365 case STREAM_LIST_ALL:
1366 case STREAM_LIST_PROGRAM:
1367 ✗ return 0;
1368 ✗ case STREAM_LIST_GROUP_ID:
1369 // <n-th> stream with given ID makes no sense and should be impossible to request
1370
0/2
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 9 not taken.
✗ av_assert0(ss->idx < 0);
1371 // return early if we know for sure the stream does not match
1372
0/2
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
✗ if (stg->id != ss->list_id)
1373 ✗ return 0;
1374 ✗ start_stream_group = stg->index;
1375 ✗ nb_stream_groups = stg->index + 1;
1376 ✗ break;
1377 ✗ case STREAM_LIST_GROUP_IDX:
1378
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ start_stream_group = ss->list_id >= 0 ? 0 : stg->index;
1379 ✗ nb_stream_groups = stg->index + 1;
1380 ✗ break;
1381 ✗ default: av_assert0(0);
1382 }
1383
1384
0/2
✗ Branch 48 → 19 not taken.
✗ Branch 48 → 49 not taken.
✗ for (int i = start_stream_group; i < nb_stream_groups; i++) {
1385 ✗ const AVStreamGroup *candidate = s->stream_groups[i];
1386
1387
0/2
✗ Branch 19 → 20 not taken.
✗ Branch 19 → 26 not taken.
✗ if (ss->meta_key) {
1388 ✗ const AVDictionaryEntry *tag = av_dict_get(candidate->metadata,
1389 ✗ ss->meta_key, NULL, 0);
1390
1391
0/2
✗ Branch 21 → 22 not taken.
✗ Branch 21 → 23 not taken.
✗ if (!tag)
1392 ✗ continue;
1393
0/4
✗ Branch 23 → 24 not taken.
✗ Branch 23 → 26 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
✗ if (ss->meta_val && strcmp(tag->value, ss->meta_val))
1394 ✗ continue;
1395 }
1396
1397
0/2
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 37 not taken.
✗ if (ss->usable_only) {
1398
0/2
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 36 not taken.
✗ switch (candidate->type) {
1399 ✗ case AV_STREAM_GROUP_PARAMS_TILE_GRID: {
1400 ✗ const AVStreamGroupTileGrid *tg = candidate->params.tile_grid;
1401
0/6
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 34 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 34 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 34 not taken.
✗ if (!tg->coded_width || !tg->coded_height || !tg->nb_tiles ||
1402
0/6
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 34 not taken.
✗ Branch 32 → 33 not taken.
✗ Branch 32 → 34 not taken.
✗ Branch 33 → 34 not taken.
✗ Branch 33 → 35 not taken.
✗ !tg->width || !tg->height || !tg->offsets)
1403 ✗ continue;
1404 ✗ break;
1405 }
1406 ✗ default:
1407 ✗ continue;
1408 }
1409 }
1410
1411
0/2
✗ Branch 37 → 38 not taken.
✗ Branch 37 → 40 not taken.
✗ if (ss->disposition &&
1412
0/2
✗ Branch 38 → 39 not taken.
✗ Branch 38 → 40 not taken.
✗ (candidate->disposition & ss->disposition) != ss->disposition)
1413 ✗ continue;
1414
1415
0/2
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 46 not taken.
✗ if (stg == candidate)
1416
0/4
✗ Branch 41 → 42 not taken.
✗ Branch 41 → 43 not taken.
✗ Branch 42 → 43 not taken.
✗ Branch 42 → 44 not taken.
✗ return ss->list_id < 0 || ss->list_id == nb_matched;
1417
1418 ✗ nb_matched++;
1419 }
1420
1421 ✗ return 0;
1422 }
1423
1424 28777 int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
1425 AVFormatContext *s, AVStream *st, const AVCodec *codec,
1426 AVDictionary **dst, AVDictionary **opts_used)
1427 {
1428 28777 AVDictionary *ret = NULL;
1429 28777 const AVDictionaryEntry *t = NULL;
1430 28777 int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM
1431
2/2
✓ Branch 2 → 3 taken 9924 times.
✓ Branch 2 → 4 taken 18853 times.
28777 : AV_OPT_FLAG_DECODING_PARAM;
1432 28777 char prefix = 0;
1433 28777 const AVClass *cc = avcodec_get_class();
1434
1435
4/4
✓ Branch 6 → 7 taken 21001 times.
✓ Branch 6 → 8 taken 7333 times.
✓ Branch 6 → 9 taken 327 times.
✓ Branch 6 → 10 taken 116 times.
28777 switch (st->codecpar->codec_type) {
1436 21001 case AVMEDIA_TYPE_VIDEO:
1437 21001 prefix = 'v';
1438 21001 flags |= AV_OPT_FLAG_VIDEO_PARAM;
1439 21001 break;
1440 7333 case AVMEDIA_TYPE_AUDIO:
1441 7333 prefix = 'a';
1442 7333 flags |= AV_OPT_FLAG_AUDIO_PARAM;
1443 7333 break;
1444 327 case AVMEDIA_TYPE_SUBTITLE:
1445 327 prefix = 's';
1446 327 flags |= AV_OPT_FLAG_SUBTITLE_PARAM;
1447 327 break;
1448 }
1449
1450
2/2
✓ Branch 41 → 11 taken 86717 times.
✓ Branch 41 → 42 taken 28777 times.
115494 while (t = av_dict_iterate(opts, t)) {
1451 const AVClass *priv_class;
1452 86717 char *p = strchr(t->key, ':');
1453 86717 int used = 0;
1454
1455 /* check stream specification in opt name */
1456
2/2
✓ Branch 11 → 12 taken 414 times.
✓ Branch 11 → 19 taken 86303 times.
86717 if (p) {
1457 414 int err = check_stream_specifier(s, st, p + 1);
1458
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 16 taken 414 times.
414 if (err < 0) {
1459 ✗ av_dict_free(&ret);
1460 ✗ return err;
1461
2/2
✓ Branch 16 → 17 taken 83 times.
✓ Branch 16 → 18 taken 331 times.
414 } else if (!err)
1462 83 continue;
1463
1464 331 *p = 0;
1465 }
1466
1467
4/4
✓ Branch 20 → 21 taken 3636 times.
✓ Branch 20 → 25 taken 82998 times.
✓ Branch 21 → 22 taken 2049 times.
✓ Branch 21 → 25 taken 1587 times.
86634 if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) ||
1468 2049 !codec ||
1469
4/4
✓ Branch 22 → 23 taken 955 times.
✓ Branch 22 → 27 taken 1094 times.
✓ Branch 24 → 25 taken 406 times.
✓ Branch 24 → 27 taken 549 times.
3004 ((priv_class = codec->priv_class) &&
1470 955 av_opt_find(&priv_class, t->key, NULL, flags,
1471 AV_OPT_SEARCH_FAKE_OBJ))) {
1472 84991 av_dict_set(&ret, t->key, t->value, 0);
1473 84991 used = 1;
1474
4/4
✓ Branch 27 → 28 taken 5 times.
✓ Branch 27 → 32 taken 1638 times.
✓ Branch 29 → 30 taken 1 time.
✓ Branch 29 → 32 taken 4 times.
1648 } else if (t->key[0] == prefix &&
1475 5 av_opt_find(&cc, t->key + 1, NULL, flags,
1476 AV_OPT_SEARCH_FAKE_OBJ)) {
1477 1 av_dict_set(&ret, t->key + 1, t->value, 0);
1478 1 used = 1;
1479 }
1480
1481
2/2
✓ Branch 32 → 33 taken 331 times.
✓ Branch 32 → 34 taken 86303 times.
86634 if (p)
1482 331 *p = ':';
1483
1484
4/4
✓ Branch 34 → 35 taken 84992 times.
✓ Branch 34 → 37 taken 1642 times.
✓ Branch 35 → 36 taken 55405 times.
✓ Branch 35 → 37 taken 29587 times.
86634 if (used && opts_used)
1485 55405 av_dict_set(opts_used, t->key, "", 0);
1486 }
1487
1488 28777 *dst = ret;
1489 28777 return 0;
1490 }
1491
1492 8474 int setup_find_stream_info_opts(AVFormatContext *s,
1493 AVDictionary *local_codec_opts,
1494 AVDictionary ***dst)
1495 {
1496 int ret;
1497 AVDictionary **opts;
1498
1499 8474 *dst = NULL;
1500
1501
2/2
✓ Branch 2 → 3 taken 102 times.
✓ Branch 2 → 4 taken 8372 times.
8474 if (!s->nb_streams)
1502 102 return 0;
1503
1504 8372 opts = av_calloc(s->nb_streams, sizeof(*opts));
1505
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 8372 times.
8372 if (!opts)
1506 ✗ return AVERROR(ENOMEM);
1507
1508
2/2
✓ Branch 12 → 8 taken 9406 times.
✓ Branch 12 → 13 taken 8372 times.
17778 for (int i = 0; i < s->nb_streams; i++) {
1509 9406 ret = filter_codec_opts(local_codec_opts, s->streams[i]->codecpar->codec_id,
1510 9406 s, s->streams[i], NULL, &opts[i], NULL);
1511
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 11 taken 9406 times.
9406 if (ret < 0)
1512 ✗ goto fail;
1513 }
1514 8372 *dst = opts;
1515 8372 return 0;
1516 ✗ fail:
1517
0/2
✗ Branch 17 → 15 not taken.
✗ Branch 17 → 18 not taken.
✗ for (int i = 0; i < s->nb_streams; i++)
1518 ✗ av_dict_free(&opts[i]);
1519 ✗ av_freep(&opts);
1520 ✗ return ret;
1521 }
1522
1523 276090 int grow_array(void **array, int elem_size, int *size, int new_size)
1524 {
1525
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 5 taken 276090 times.
276090 if (new_size >= INT_MAX / elem_size) {
1526 ✗ av_log(NULL, AV_LOG_ERROR, "Array too big.\n");
1527 ✗ return AVERROR(ERANGE);
1528 }
1529
1/2
✓ Branch 5 → 6 taken 276090 times.
✗ Branch 5 → 10 not taken.
276090 if (*size < new_size) {
1530 276090 uint8_t *tmp = av_realloc_array(*array, new_size, elem_size);
1531
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 276090 times.
276090 if (!tmp)
1532 ✗ return AVERROR(ENOMEM);
1533 276090 memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size);
1534 276090 *size = new_size;
1535 276090 *array = tmp;
1536 276090 return 0;
1537 }
1538 ✗ return 0;
1539 }
1540
1541 52513 void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems)
1542 {
1543 void *new_elem;
1544
1545 52513 new_elem = av_mallocz(elem_size);
1546
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 52513 times.
52513 if (!new_elem)
1547 ✗ return NULL;
1548
1/2
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 52513 times.
52513 if (av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0)
1549 ✗ av_freep(&new_elem);
1550
1551 52513 return new_elem;
1552 }
1553
1554 6197 double get_rotation(const int32_t *displaymatrix)
1555 {
1556 6197 double theta = 0;
1557
1/2
✓ Branch 2 → 3 taken 6197 times.
✗ Branch 2 → 5 not taken.
6197 if (displaymatrix)
1558 6197 theta = -round(av_display_rotation_get(displaymatrix));
1559
1560 6197 theta -= 360*floor(theta/360 + 0.9/360);
1561
1562
1/2
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 6197 times.
6197 if (fabs(theta - 90*round(theta/90)) > 2)
1563 ✗ av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n"
1564 "If you want to help, upload a sample "
1565 "of this file to https://streams.videolan.org/upload/ "
1566 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)");
1567
1568 6197 return theta;
1569 }
1570
1571 /* read file contents into a string */
1572 80 char *read_file_to_string(const char *filename)
1573 {
1574 80 AVIOContext *pb = NULL;
1575 80 int ret = avio_open(&pb, filename, AVIO_FLAG_READ);
1576 AVBPrint bprint;
1577 char *str;
1578
1579
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 80 times.
80 if (ret < 0) {
1580 ✗ av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename);
1581 ✗ return NULL;
1582 }
1583
1584 80 av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED);
1585 80 ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX);
1586 80 avio_closep(&pb);
1587
1/2
✗ Branch 9 → 10 not taken.
✓ Branch 9 → 12 taken 80 times.
80 if (ret < 0) {
1588 ✗ av_bprint_finalize(&bprint, NULL);
1589 ✗ return NULL;
1590 }
1591 80 ret = av_bprint_finalize(&bprint, &str);
1592
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 80 times.
80 if (ret < 0)
1593 ✗ return NULL;
1594 80 return str;
1595 }
1596
1597 8081 void remove_avoptions(AVDictionary **a, AVDictionary *b)
1598 {
1599 8081 const AVDictionaryEntry *t = NULL;
1600
1601
2/2
✓ Branch 5 → 3 taken 26688 times.
✓ Branch 5 → 6 taken 8081 times.
34769 while ((t = av_dict_iterate(b, t))) {
1602 26688 av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE);
1603 }
1604 8081 }
1605
1606 33178 int check_avoptions(AVDictionary *m)
1607 {
1608 33178 const AVDictionaryEntry *t = av_dict_iterate(m, NULL);
1609
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 6 taken 33178 times.
33178 if (t) {
1610 ✗ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key);
1611 ✗ return AVERROR_OPTION_NOT_FOUND;
1612 }
1613
1614 33178 return 0;
1615 }
1616
1617 ✗ void dump_dictionary(void *ctx, const AVDictionary *m,
1618 const char *name, const char *indent,
1619 int log_level)
1620 {
1621 ✗ const AVDictionaryEntry *tag = NULL;
1622
1623
0/2
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 4 not taken.
✗ if (!m)
1624 ✗ return;
1625
1626 ✗ av_log(ctx, log_level, "%s%s:\n", indent, name);
1627
0/2
✗ Branch 22 → 6 not taken.
✗ Branch 22 → 23 not taken.
✗ while ((tag = av_dict_iterate(m, tag))) {
1628 ✗ const char *p = tag->value;
1629 ✗ av_log(ctx, log_level, "%s %-16s: ", indent, tag->key);
1630
0/2
✗ Branch 19 → 8 not taken.
✗ Branch 19 → 20 not taken.
✗ while (*p) {
1631 ✗ size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
1632
0/2
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 10 not taken.
✗ av_log(ctx, log_level, "%.*s", (int)(FFMIN(255, len)), p);
1633 ✗ p += len;
1634
0/2
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 14 not taken.
✗ if (*p == 0xd) av_log(ctx, log_level, " ");
1635
0/2
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 16 not taken.
✗ if (*p == 0xa) av_log(ctx, log_level, "\n%s %-16s: ", indent, "");
1636
0/2
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
✗ if (*p) p++;
1637 }
1638 ✗ av_log(ctx, log_level, "\n");
1639 }
1640 }
1641