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 "compat/va_copy.h" | ||
34 | #include "libavformat/avformat.h" | ||
35 | #include "libswscale/swscale.h" | ||
36 | #include "libswresample/swresample.h" | ||
37 | #include "libavutil/avassert.h" | ||
38 | #include "libavutil/avstring.h" | ||
39 | #include "libavutil/bprint.h" | ||
40 | #include "libavutil/display.h" | ||
41 | #include "libavutil/getenv_utf8.h" | ||
42 | #include "libavutil/libm.h" | ||
43 | #include "libavutil/mem.h" | ||
44 | #include "libavutil/parseutils.h" | ||
45 | #include "libavutil/eval.h" | ||
46 | #include "libavutil/dict.h" | ||
47 | #include "libavutil/opt.h" | ||
48 | #include "cmdutils.h" | ||
49 | #include "fopen_utf8.h" | ||
50 | #include "opt_common.h" | ||
51 | #ifdef _WIN32 | ||
52 | #include <windows.h> | ||
53 | #include "compat/w32dlfcn.h" | ||
54 | #endif | ||
55 | |||
56 | AVDictionary *sws_dict; | ||
57 | AVDictionary *swr_opts; | ||
58 | AVDictionary *format_opts, *codec_opts; | ||
59 | |||
60 | int hide_banner = 0; | ||
61 | |||
62 | 15983 | void uninit_opts(void) | |
63 | { | ||
64 | 15983 | av_dict_free(&swr_opts); | |
65 | 15983 | av_dict_free(&sws_dict); | |
66 | 15983 | av_dict_free(&format_opts); | |
67 | 15983 | av_dict_free(&codec_opts); | |
68 | 15983 | } | |
69 | |||
70 | ✗ | void log_callback_help(void *ptr, int level, const char *fmt, va_list vl) | |
71 | { | ||
72 | ✗ | vfprintf(stdout, fmt, vl); | |
73 | ✗ | } | |
74 | |||
75 | 8068 | void init_dynload(void) | |
76 | { | ||
77 | #if HAVE_SETDLLDIRECTORY && defined(_WIN32) | ||
78 | /* Calling SetDllDirectory with the empty string (but not NULL) removes the | ||
79 | * current working directory from the DLL search path as a security pre-caution. */ | ||
80 | SetDllDirectory(""); | ||
81 | #endif | ||
82 | 8068 | } | |
83 | |||
84 | 36329 | int parse_number(const char *context, const char *numstr, enum OptionType type, | |
85 | double min, double max, double *dst) | ||
86 | { | ||
87 | char *tail; | ||
88 | const char *error; | ||
89 | 36329 | double d = av_strtod(numstr, &tail); | |
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36329 times.
|
36329 | if (*tail) |
91 | ✗ | error = "Expected number for %s but found: %s\n"; | |
92 |
2/4✓ Branch 0 taken 36329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36329 times.
|
36329 | else if (d < min || d > max) |
93 | ✗ | error = "The value for %s was %s which is not within %f - %f\n"; | |
94 |
3/4✓ Branch 0 taken 36036 times.
✓ Branch 1 taken 293 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36036 times.
|
36329 | else if (type == OPT_TYPE_INT64 && (int64_t)d != d) |
95 | ✗ | error = "Expected int64 for %s but found %s\n"; | |
96 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 36329 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
36329 | else if (type == OPT_TYPE_INT && (int)d != d) |
97 | ✗ | error = "Expected int for %s but found %s\n"; | |
98 | else { | ||
99 | 36329 | *dst = d; | |
100 | 36329 | return 0; | |
101 | } | ||
102 | |||
103 | ✗ | av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max); | |
104 | ✗ | return AVERROR(EINVAL); | |
105 | } | ||
106 | |||
107 | ✗ | void show_help_options(const OptionDef *options, const char *msg, int req_flags, | |
108 | int rej_flags) | ||
109 | { | ||
110 | const OptionDef *po; | ||
111 | int first; | ||
112 | |||
113 | ✗ | first = 1; | |
114 | ✗ | for (po = options; po->name; po++) { | |
115 | char buf[128]; | ||
116 | |||
117 | ✗ | if (((po->flags & req_flags) != req_flags) || | |
118 | ✗ | (po->flags & rej_flags)) | |
119 | ✗ | continue; | |
120 | |||
121 | ✗ | if (first) { | |
122 | ✗ | printf("%s\n", msg); | |
123 | ✗ | first = 0; | |
124 | } | ||
125 | ✗ | av_strlcpy(buf, po->name, sizeof(buf)); | |
126 | |||
127 | ✗ | if (po->flags & OPT_FLAG_PERSTREAM) | |
128 | ✗ | av_strlcat(buf, "[:<stream_spec>]", sizeof(buf)); | |
129 | ✗ | else if (po->flags & OPT_FLAG_SPEC) | |
130 | ✗ | av_strlcat(buf, "[:<spec>]", sizeof(buf)); | |
131 | |||
132 | ✗ | if (po->argname) | |
133 | ✗ | av_strlcatf(buf, sizeof(buf), " <%s>", po->argname); | |
134 | |||
135 | ✗ | printf("-%-17s %s\n", buf, po->help); | |
136 | } | ||
137 | ✗ | printf("\n"); | |
138 | ✗ | } | |
139 | |||
140 | ✗ | void show_help_children(const AVClass *class, int flags) | |
141 | { | ||
142 | ✗ | void *iter = NULL; | |
143 | const AVClass *child; | ||
144 | ✗ | if (class->option) { | |
145 | ✗ | av_opt_show2(&class, NULL, flags, 0); | |
146 | ✗ | printf("\n"); | |
147 | } | ||
148 | |||
149 | ✗ | while (child = av_opt_child_class_iterate(class, &iter)) | |
150 | ✗ | show_help_children(child, flags); | |
151 | ✗ | } | |
152 | |||
153 | 1216834 | static const OptionDef *find_option(const OptionDef *po, const char *name) | |
154 | { | ||
155 |
2/2✓ Branch 0 taken 342 times.
✓ Branch 1 taken 1216492 times.
|
1216834 | if (*name == '/') |
156 | 342 | name++; | |
157 | |||
158 |
2/2✓ Branch 0 taken 174152415 times.
✓ Branch 1 taken 691423 times.
|
174843838 | while (po->name) { |
159 | const char *end; | ||
160 |
6/6✓ Branch 1 taken 1242417 times.
✓ Branch 2 taken 172909998 times.
✓ Branch 3 taken 766931 times.
✓ Branch 4 taken 475486 times.
✓ Branch 5 taken 717006 times.
✓ Branch 6 taken 49925 times.
|
174152415 | if (av_strstart(name, po->name, &end) && (!*end || *end == ':')) |
161 | break; | ||
162 | 173627004 | po++; | |
163 | } | ||
164 | 1216834 | return po; | |
165 | } | ||
166 | |||
167 | /* _WIN32 means using the windows libc - cygwin doesn't define that | ||
168 | * by default. HAVE_COMMANDLINETOARGVW is true on cygwin, while | ||
169 | * it doesn't provide the actual command line via GetCommandLineW(). */ | ||
170 | #if HAVE_COMMANDLINETOARGVW && defined(_WIN32) | ||
171 | #include <shellapi.h> | ||
172 | /* Will be leaked on exit */ | ||
173 | static char** win32_argv_utf8 = NULL; | ||
174 | static int win32_argc = 0; | ||
175 | |||
176 | /** | ||
177 | * Prepare command line arguments for executable. | ||
178 | * For Windows - perform wide-char to UTF-8 conversion. | ||
179 | * Input arguments should be main() function arguments. | ||
180 | * @param argc_ptr Arguments number (including executable) | ||
181 | * @param argv_ptr Arguments list. | ||
182 | */ | ||
183 | static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) | ||
184 | { | ||
185 | char *argstr_flat; | ||
186 | wchar_t **argv_w; | ||
187 | int i, buffsize = 0, offset = 0; | ||
188 | |||
189 | if (win32_argv_utf8) { | ||
190 | *argc_ptr = win32_argc; | ||
191 | *argv_ptr = win32_argv_utf8; | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | win32_argc = 0; | ||
196 | argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc); | ||
197 | if (win32_argc <= 0 || !argv_w) | ||
198 | return; | ||
199 | |||
200 | /* determine the UTF-8 buffer size (including NULL-termination symbols) */ | ||
201 | for (i = 0; i < win32_argc; i++) | ||
202 | buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, | ||
203 | NULL, 0, NULL, NULL); | ||
204 | |||
205 | win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize); | ||
206 | argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1); | ||
207 | if (!win32_argv_utf8) { | ||
208 | LocalFree(argv_w); | ||
209 | return; | ||
210 | } | ||
211 | |||
212 | for (i = 0; i < win32_argc; i++) { | ||
213 | win32_argv_utf8[i] = &argstr_flat[offset]; | ||
214 | offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, | ||
215 | &argstr_flat[offset], | ||
216 | buffsize - offset, NULL, NULL); | ||
217 | } | ||
218 | win32_argv_utf8[i] = NULL; | ||
219 | LocalFree(argv_w); | ||
220 | |||
221 | *argc_ptr = win32_argc; | ||
222 | *argv_ptr = win32_argv_utf8; | ||
223 | } | ||
224 | #else | ||
225 | 8068 | static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) | |
226 | { | ||
227 | /* nothing to do */ | ||
228 | 8068 | } | |
229 | #endif /* HAVE_COMMANDLINETOARGVW */ | ||
230 | |||
231 | 509191 | static int opt_has_arg(const OptionDef *o) | |
232 | { | ||
233 |
2/2✓ Branch 0 taken 160737 times.
✓ Branch 1 taken 348454 times.
|
509191 | if (o->type == OPT_TYPE_BOOL) |
234 | 160737 | return 0; | |
235 |
2/2✓ Branch 0 taken 120822 times.
✓ Branch 1 taken 227632 times.
|
348454 | if (o->type == OPT_TYPE_FUNC) |
236 | 120822 | return !!(o->flags & OPT_FUNC_ARG); | |
237 | 227632 | return 1; | |
238 | } | ||
239 | |||
240 | 94998 | static int write_option(void *optctx, const OptionDef *po, const char *opt, | |
241 | const char *arg, const OptionDef *defs) | ||
242 | { | ||
243 | /* new-style options contain an offset into optctx, old-style address of | ||
244 | * a global var*/ | ||
245 | 189996 | void *dst = po->flags & OPT_FLAG_OFFSET ? | |
246 |
2/2✓ Branch 0 taken 46309 times.
✓ Branch 1 taken 48689 times.
|
94998 | (uint8_t *)optctx + po->u.off : po->u.dst_ptr; |
247 | 94998 | char *arg_allocated = NULL; | |
248 | |||
249 | 94998 | enum OptionType so_type = po->type; | |
250 | |||
251 | 94998 | SpecifierOptList *sol = NULL; | |
252 | double num; | ||
253 | 94998 | int ret = 0; | |
254 | |||
255 |
2/2✓ Branch 0 taken 57 times.
✓ Branch 1 taken 94941 times.
|
94998 | if (*opt == '/') { |
256 | 57 | opt++; | |
257 | |||
258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (po->type == OPT_TYPE_BOOL) { |
259 | ✗ | av_log(NULL, AV_LOG_FATAL, | |
260 | "Requested to load an argument from file for a bool option '%s'\n", | ||
261 | ✗ | po->name); | |
262 | ✗ | return AVERROR(EINVAL); | |
263 | } | ||
264 | |||
265 | 57 | arg_allocated = file_read(arg); | |
266 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
|
57 | if (!arg_allocated) { |
267 | ✗ | av_log(NULL, AV_LOG_FATAL, | |
268 | "Error reading the value for option '%s' from file: %s\n", | ||
269 | opt, arg); | ||
270 | ✗ | return AVERROR(EINVAL); | |
271 | } | ||
272 | |||
273 | 57 | arg = arg_allocated; | |
274 | } | ||
275 | |||
276 |
2/2✓ Branch 0 taken 31666 times.
✓ Branch 1 taken 63332 times.
|
94998 | if (po->flags & OPT_FLAG_SPEC) { |
277 | 31666 | char *p = strchr(opt, ':'); | |
278 | char *str; | ||
279 | |||
280 | 31666 | sol = dst; | |
281 | 31666 | ret = GROW_ARRAY(sol->opt, sol->nb_opt); | |
282 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31666 times.
|
31666 | if (ret < 0) |
283 | ✗ | goto finish; | |
284 | |||
285 |
2/2✓ Branch 0 taken 15941 times.
✓ Branch 1 taken 15725 times.
|
31666 | str = av_strdup(p ? p + 1 : ""); |
286 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31666 times.
|
31666 | if (!str) { |
287 | ✗ | ret = AVERROR(ENOMEM); | |
288 | ✗ | goto finish; | |
289 | } | ||
290 | 31666 | sol->opt[sol->nb_opt - 1].specifier = str; | |
291 | |||
292 |
2/2✓ Branch 0 taken 31419 times.
✓ Branch 1 taken 247 times.
|
31666 | if (po->flags & OPT_FLAG_PERSTREAM) { |
293 | 31419 | ret = stream_specifier_parse(&sol->opt[sol->nb_opt - 1].stream_spec, | |
294 | str, 0, NULL); | ||
295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31419 times.
|
31419 | if (ret < 0) |
296 | ✗ | goto finish; | |
297 | } | ||
298 | |||
299 | 31666 | dst = &sol->opt[sol->nb_opt - 1].u; | |
300 | } | ||
301 | |||
302 |
2/2✓ Branch 0 taken 37576 times.
✓ Branch 1 taken 57422 times.
|
94998 | if (po->type == OPT_TYPE_STRING) { |
303 | char *str; | ||
304 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 37554 times.
|
37576 | if (arg_allocated) { |
305 | 22 | str = arg_allocated; | |
306 | 22 | arg_allocated = NULL; | |
307 | } else | ||
308 | 37554 | str = av_strdup(arg); | |
309 | 37576 | av_freep(dst); | |
310 | |||
311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37576 times.
|
37576 | if (!str) { |
312 | ✗ | ret = AVERROR(ENOMEM); | |
313 | ✗ | goto finish; | |
314 | } | ||
315 | |||
316 | 37576 | *(char **)dst = str; | |
317 |
4/4✓ Branch 0 taken 26708 times.
✓ Branch 1 taken 30714 times.
✓ Branch 2 taken 137 times.
✓ Branch 3 taken 26571 times.
|
57422 | } else if (po->type == OPT_TYPE_BOOL || po->type == OPT_TYPE_INT) { |
318 | 30851 | ret = parse_number(opt, arg, OPT_TYPE_INT64, INT_MIN, INT_MAX, &num); | |
319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30851 times.
|
30851 | if (ret < 0) |
320 | ✗ | goto finish; | |
321 | |||
322 | 30851 | *(int *)dst = num; | |
323 | 30851 | so_type = OPT_TYPE_INT; | |
324 |
2/2✓ Branch 0 taken 5185 times.
✓ Branch 1 taken 21386 times.
|
26571 | } else if (po->type == OPT_TYPE_INT64) { |
325 | 5185 | ret = parse_number(opt, arg, OPT_TYPE_INT64, INT64_MIN, (double)INT64_MAX, &num); | |
326 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5185 times.
|
5185 | if (ret < 0) |
327 | ✗ | goto finish; | |
328 | |||
329 | 5185 | *(int64_t *)dst = num; | |
330 |
2/2✓ Branch 0 taken 992 times.
✓ Branch 1 taken 20394 times.
|
21386 | } else if (po->type == OPT_TYPE_TIME) { |
331 | 992 | ret = av_parse_time(dst, arg, 1); | |
332 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 992 times.
|
992 | if (ret < 0) { |
333 | ✗ | av_log(NULL, AV_LOG_ERROR, "Invalid duration for option %s: %s\n", | |
334 | opt, arg); | ||
335 | ✗ | goto finish; | |
336 | } | ||
337 | 992 | so_type = OPT_TYPE_INT64; | |
338 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 20391 times.
|
20394 | } else if (po->type == OPT_TYPE_FLOAT) { |
339 | 3 | ret = parse_number(opt, arg, OPT_TYPE_FLOAT, -INFINITY, INFINITY, &num); | |
340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
341 | ✗ | goto finish; | |
342 | |||
343 | 3 | *(float *)dst = num; | |
344 |
2/2✓ Branch 0 taken 290 times.
✓ Branch 1 taken 20101 times.
|
20391 | } else if (po->type == OPT_TYPE_DOUBLE) { |
345 | 290 | ret = parse_number(opt, arg, OPT_TYPE_DOUBLE, -INFINITY, INFINITY, &num); | |
346 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 290 times.
|
290 | if (ret < 0) |
347 | ✗ | goto finish; | |
348 | |||
349 | 290 | *(double *)dst = num; | |
350 | } else { | ||
351 |
2/4✓ Branch 0 taken 20101 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20101 times.
|
20101 | av_assert0(po->type == OPT_TYPE_FUNC && po->u.func_arg); |
352 | |||
353 | 20101 | ret = po->u.func_arg(optctx, opt, arg); | |
354 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20101 times.
|
20101 | if (ret < 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 | ✗ | goto finish; | |
359 | } | ||
360 | } | ||
361 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 94997 times.
|
94998 | if (po->flags & OPT_EXIT) { |
362 | 1 | ret = AVERROR_EXIT; | |
363 | 1 | goto finish; | |
364 | } | ||
365 | |||
366 |
2/2✓ Branch 0 taken 63331 times.
✓ Branch 1 taken 31666 times.
|
94997 | if (sol) { |
367 | 31666 | sol->type = so_type; | |
368 |
2/2✓ Branch 0 taken 2441 times.
✓ Branch 1 taken 29225 times.
|
34107 | sol->opt_canon = (po->flags & OPT_HAS_CANON) ? |
369 | 2441 | find_option(defs, po->u1.name_canon) : po; | |
370 | } | ||
371 | |||
372 | 63331 | finish: | |
373 | 94998 | av_freep(&arg_allocated); | |
374 | 94998 | return ret; | |
375 | } | ||
376 | |||
377 | 9923 | int parse_option(void *optctx, const char *opt, const char *arg, | |
378 | const OptionDef *options) | ||
379 | { | ||
380 | static const OptionDef opt_avoptions = { | ||
381 | .name = "AVOption passthrough", | ||
382 | .type = OPT_TYPE_FUNC, | ||
383 | .flags = OPT_FUNC_ARG, | ||
384 | .u.func_arg = opt_default, | ||
385 | }; | ||
386 | |||
387 | const OptionDef *po; | ||
388 | int ret; | ||
389 | |||
390 | 9923 | po = find_option(options, opt); | |
391 |
5/6✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9914 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
9923 | if (!po->name && opt[0] == 'n' && opt[1] == 'o') { |
392 | /* handle 'no' bool option */ | ||
393 | 1 | po = find_option(options, opt + 2); | |
394 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if ((po->name && po->type == OPT_TYPE_BOOL)) |
395 | 1 | arg = "0"; | |
396 |
2/2✓ Branch 0 taken 145 times.
✓ Branch 1 taken 9777 times.
|
9922 | } else if (po->type == OPT_TYPE_BOOL) |
397 | 145 | arg = "1"; | |
398 | |||
399 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 9915 times.
|
9923 | if (!po->name) |
400 | 8 | po = &opt_avoptions; | |
401 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9923 times.
|
9923 | if (!po->name) { |
402 | ✗ | av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); | |
403 | ✗ | return AVERROR(EINVAL); | |
404 | } | ||
405 |
3/4✓ Branch 1 taken 9671 times.
✓ Branch 2 taken 252 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9671 times.
|
9923 | if (opt_has_arg(po) && !arg) { |
406 | ✗ | av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt); | |
407 | ✗ | return AVERROR(EINVAL); | |
408 | } | ||
409 | |||
410 | 9923 | ret = write_option(optctx, po, opt, arg, options); | |
411 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9923 times.
|
9923 | if (ret < 0) |
412 | ✗ | return ret; | |
413 | |||
414 | 9923 | return opt_has_arg(po); | |
415 | } | ||
416 | |||
417 | 153 | int parse_options(void *optctx, int argc, char **argv, const OptionDef *options, | |
418 | int (*parse_arg_function)(void *, const char*)) | ||
419 | { | ||
420 | const char *opt; | ||
421 | 153 | int optindex, handleoptions = 1, ret; | |
422 | |||
423 | /* perform system-dependent conversions for arguments list */ | ||
424 | 153 | prepare_app_arguments(&argc, &argv); | |
425 | |||
426 | /* parse options */ | ||
427 | 153 | optindex = 1; | |
428 |
2/2✓ Branch 0 taken 675 times.
✓ Branch 1 taken 153 times.
|
828 | while (optindex < argc) { |
429 | 675 | opt = argv[optindex++]; | |
430 | |||
431 |
4/6✓ Branch 0 taken 675 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 532 times.
✓ Branch 3 taken 143 times.
✓ Branch 4 taken 532 times.
✗ Branch 5 not taken.
|
675 | if (handleoptions && opt[0] == '-' && opt[1] != '\0') { |
432 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 532 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
532 | if (opt[1] == '-' && opt[2] == '\0') { |
433 | ✗ | handleoptions = 0; | |
434 | ✗ | continue; | |
435 | } | ||
436 | 532 | opt++; | |
437 | |||
438 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 532 times.
|
532 | if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) |
439 | ✗ | return ret; | |
440 | 532 | optindex += ret; | |
441 | } else { | ||
442 |
1/2✓ Branch 0 taken 143 times.
✗ Branch 1 not taken.
|
143 | if (parse_arg_function) { |
443 | 143 | ret = parse_arg_function(optctx, opt); | |
444 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 143 times.
|
143 | if (ret < 0) |
445 | ✗ | return ret; | |
446 | } | ||
447 | } | ||
448 | } | ||
449 | |||
450 | 153 | return 0; | |
451 | } | ||
452 | |||
453 | 22996 | int parse_optgroup(void *optctx, OptionGroup *g, const OptionDef *defs) | |
454 | { | ||
455 | int i, ret; | ||
456 | |||
457 | 22996 | av_log(NULL, AV_LOG_DEBUG, "Parsing a group of options: %s %s.\n", | |
458 | 22996 | g->group_def->name, g->arg); | |
459 | |||
460 |
2/2✓ Branch 0 taken 85075 times.
✓ Branch 1 taken 22995 times.
|
108070 | for (i = 0; i < g->nb_opts; i++) { |
461 | 85075 | Option *o = &g->opts[i]; | |
462 | |||
463 |
2/2✓ Branch 0 taken 46835 times.
✓ Branch 1 taken 38240 times.
|
85075 | if (g->group_def->flags && |
464 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 46835 times.
|
46835 | !(g->group_def->flags & o->opt->flags)) { |
465 | ✗ | av_log(NULL, AV_LOG_ERROR, "Option %s (%s) cannot be applied to " | |
466 | "%s %s -- you are trying to apply an input option to an " | ||
467 | "output file or vice versa. Move this option before the " | ||
468 | ✗ | "file it belongs to.\n", o->key, o->opt->help, | |
469 | ✗ | g->group_def->name, g->arg); | |
470 | ✗ | return AVERROR(EINVAL); | |
471 | } | ||
472 | |||
473 | 85075 | av_log(NULL, AV_LOG_DEBUG, "Applying option %s (%s) with argument %s.\n", | |
474 | 85075 | o->key, o->opt->help, o->val); | |
475 | |||
476 | 85075 | ret = write_option(optctx, o->opt, o->key, o->val, defs); | |
477 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 85074 times.
|
85075 | if (ret < 0) |
478 | 1 | return ret; | |
479 | } | ||
480 | |||
481 | 22995 | av_log(NULL, AV_LOG_DEBUG, "Successfully parsed a group of options.\n"); | |
482 | |||
483 | 22995 | return 0; | |
484 | } | ||
485 | |||
486 | 40340 | int locate_option(int argc, char **argv, const OptionDef *options, | |
487 | const char *optname) | ||
488 | { | ||
489 | const OptionDef *po; | ||
490 | int i; | ||
491 | |||
492 |
2/2✓ Branch 0 taken 931924 times.
✓ Branch 1 taken 40324 times.
|
972248 | for (i = 1; i < argc; i++) { |
493 | 931924 | const char *cur_opt = argv[i]; | |
494 | |||
495 |
4/4✓ Branch 0 taken 904812 times.
✓ Branch 1 taken 27112 times.
✓ Branch 2 taken 13180 times.
✓ Branch 3 taken 891632 times.
|
931924 | if (!(cur_opt[0] == '-' && cur_opt[1])) |
496 | 40292 | continue; | |
497 | 891632 | cur_opt++; | |
498 | |||
499 | 891632 | po = find_option(options, cur_opt); | |
500 |
5/6✓ Branch 0 taken 582122 times.
✓ Branch 1 taken 309510 times.
✓ Branch 2 taken 118510 times.
✓ Branch 3 taken 463612 times.
✓ Branch 4 taken 118510 times.
✗ Branch 5 not taken.
|
891632 | if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o') |
501 | 118510 | po = find_option(options, cur_opt + 2); | |
502 | |||
503 |
3/4✓ Branch 0 taken 463652 times.
✓ Branch 1 taken 427980 times.
✓ Branch 2 taken 463652 times.
✗ Branch 3 not taken.
|
891632 | if ((!po->name && !strcmp(cur_opt, optname)) || |
504 |
4/4✓ Branch 0 taken 427980 times.
✓ Branch 1 taken 463652 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 427964 times.
|
891632 | (po->name && !strcmp(optname, po->name))) |
505 | 16 | return i; | |
506 | |||
507 |
4/4✓ Branch 0 taken 427964 times.
✓ Branch 1 taken 463652 times.
✓ Branch 3 taken 273859 times.
✓ Branch 4 taken 154105 times.
|
891616 | if (!po->name || opt_has_arg(po)) |
508 | 737511 | i++; | |
509 | } | ||
510 | 40324 | return 0; | |
511 | } | ||
512 | |||
513 | ✗ | static void dump_argument(FILE *report_file, const char *a) | |
514 | { | ||
515 | const unsigned char *p; | ||
516 | |||
517 | ✗ | for (p = a; *p; p++) | |
518 | ✗ | if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') || | |
519 | ✗ | *p == '_' || (*p >= 'a' && *p <= 'z'))) | |
520 | break; | ||
521 | ✗ | if (!*p) { | |
522 | ✗ | fputs(a, report_file); | |
523 | ✗ | return; | |
524 | } | ||
525 | ✗ | fputc('"', report_file); | |
526 | ✗ | for (p = a; *p; p++) { | |
527 | ✗ | if (*p == '\\' || *p == '"' || *p == '$' || *p == '`') | |
528 | ✗ | fprintf(report_file, "\\%c", *p); | |
529 | ✗ | else if (*p < ' ' || *p > '~') | |
530 | ✗ | fprintf(report_file, "\\x%02x", *p); | |
531 | else | ||
532 | ✗ | fputc(*p, report_file); | |
533 | } | ||
534 | ✗ | fputc('"', report_file); | |
535 | } | ||
536 | |||
537 | 8068 | static void check_options(const OptionDef *po) | |
538 | { | ||
539 |
2/2✓ Branch 0 taken 1514407 times.
✓ Branch 1 taken 8068 times.
|
1522475 | while (po->name) { |
540 |
2/2✓ Branch 0 taken 933970 times.
✓ Branch 1 taken 580437 times.
|
1514407 | if (po->flags & OPT_PERFILE) |
541 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 933970 times.
|
933970 | av_assert0(po->flags & (OPT_INPUT | OPT_OUTPUT | OPT_DECODER)); |
542 | |||
543 |
2/2✓ Branch 0 taken 601428 times.
✓ Branch 1 taken 912979 times.
|
1514407 | if (po->type == OPT_TYPE_FUNC) |
544 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601428 times.
|
601428 | av_assert0(!(po->flags & (OPT_FLAG_OFFSET | OPT_FLAG_SPEC))); |
545 | |||
546 | // OPT_FUNC_ARG can only be ser for OPT_TYPE_FUNC | ||
547 |
3/4✓ Branch 0 taken 912979 times.
✓ Branch 1 taken 601428 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 912979 times.
|
1514407 | av_assert0((po->type == OPT_TYPE_FUNC) || !(po->flags & OPT_FUNC_ARG)); |
548 | |||
549 | 1514407 | po++; | |
550 | } | ||
551 | 8068 | } | |
552 | |||
553 | 8068 | void parse_loglevel(int argc, char **argv, const OptionDef *options) | |
554 | { | ||
555 | int idx; | ||
556 | char *env; | ||
557 | |||
558 | 8068 | check_options(options); | |
559 | |||
560 | 8068 | idx = locate_option(argc, argv, options, "loglevel"); | |
561 |
1/2✓ Branch 0 taken 8068 times.
✗ Branch 1 not taken.
|
8068 | if (!idx) |
562 | 8068 | idx = locate_option(argc, argv, options, "v"); | |
563 |
3/4✓ Branch 0 taken 16 times.
✓ Branch 1 taken 8052 times.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
8068 | if (idx && argv[idx + 1]) |
564 | 16 | opt_loglevel(NULL, "loglevel", argv[idx + 1]); | |
565 | 8068 | idx = locate_option(argc, argv, options, "report"); | |
566 | 8068 | env = getenv_utf8("FFREPORT"); | |
567 |
2/4✓ Branch 0 taken 8068 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8068 times.
|
8068 | if (env || idx) { |
568 | ✗ | FILE *report_file = NULL; | |
569 | ✗ | init_report(env, &report_file); | |
570 | ✗ | if (report_file) { | |
571 | int i; | ||
572 | ✗ | fprintf(report_file, "Command line:\n"); | |
573 | ✗ | for (i = 0; i < argc; i++) { | |
574 | ✗ | dump_argument(report_file, argv[i]); | |
575 | ✗ | fputc(i < argc - 1 ? ' ' : '\n', report_file); | |
576 | } | ||
577 | ✗ | fflush(report_file); | |
578 | } | ||
579 | } | ||
580 | 8068 | freeenv_utf8(env); | |
581 | 8068 | idx = locate_option(argc, argv, options, "hide_banner"); | |
582 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8068 times.
|
8068 | if (idx) |
583 | ✗ | hide_banner = 1; | |
584 | 8068 | } | |
585 | |||
586 | 295225 | static const AVOption *opt_find(void *obj, const char *name, const char *unit, | |
587 | int opt_flags, int search_flags) | ||
588 | { | ||
589 | 295225 | const AVOption *o = av_opt_find(obj, name, unit, opt_flags, search_flags); | |
590 |
4/4✓ Branch 0 taken 85645 times.
✓ Branch 1 taken 209580 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 85643 times.
|
295225 | if(o && !o->flags) |
591 | 2 | return NULL; | |
592 | 295223 | return o; | |
593 | } | ||
594 | |||
595 | #define FLAGS ((o->type == AV_OPT_TYPE_FLAGS && (arg[0]=='-' || arg[0]=='+')) ? AV_DICT_APPEND : 0) | ||
596 | 109260 | int opt_default(void *optctx, const char *opt, const char *arg) | |
597 | { | ||
598 | const AVOption *o; | ||
599 | 109260 | int consumed = 0; | |
600 | char opt_stripped[128]; | ||
601 | const char *p; | ||
602 | 109260 | const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(); | |
603 | #if CONFIG_SWSCALE | ||
604 | 109260 | const AVClass *sc = sws_get_class(); | |
605 | #endif | ||
606 | #if CONFIG_SWRESAMPLE | ||
607 | 109260 | const AVClass *swr_class = swr_get_class(); | |
608 | #endif | ||
609 | |||
610 |
2/4✓ Branch 0 taken 109260 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 109260 times.
|
109260 | if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug")) |
611 | ✗ | av_log_set_level(AV_LOG_DEBUG); | |
612 | |||
613 |
2/2✓ Branch 0 taken 109248 times.
✓ Branch 1 taken 12 times.
|
109260 | if (!(p = strchr(opt, ':'))) |
614 | 109248 | p = opt + strlen(opt); | |
615 | 109260 | av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1)); | |
616 | |||
617 |
2/2✓ Branch 1 taken 52913 times.
✓ Branch 2 taken 56347 times.
|
109260 | if ((o = opt_find(&cc, opt_stripped, NULL, 0, |
618 | 52913 | AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) || | |
619 |
8/8✓ Branch 0 taken 52910 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 52898 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 14664 times.
✓ Branch 5 taken 38234 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 14678 times.
|
67592 | ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && |
620 | 14679 | (o = opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) { | |
621 |
5/6✓ Branch 0 taken 21371 times.
✓ Branch 1 taken 34977 times.
✓ Branch 2 taken 21371 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14592 times.
✓ Branch 5 taken 6779 times.
|
56348 | av_dict_set(&codec_opts, opt, arg, FLAGS); |
622 | 56348 | consumed = 1; | |
623 | } | ||
624 |
2/2✓ Branch 1 taken 14655 times.
✓ Branch 2 taken 94605 times.
|
109260 | if ((o = opt_find(&fc, opt, NULL, 0, |
625 | AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { | ||
626 |
5/6✓ Branch 0 taken 14436 times.
✓ Branch 1 taken 219 times.
✓ Branch 2 taken 14436 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14428 times.
✓ Branch 5 taken 8 times.
|
14655 | av_dict_set(&format_opts, opt, arg, FLAGS); |
627 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 14579 times.
|
14655 | if (consumed) |
628 | 76 | av_log(NULL, AV_LOG_VERBOSE, "Routing option %s to both codec and muxer layer\n", opt); | |
629 | 14655 | consumed = 1; | |
630 | } | ||
631 | #if CONFIG_SWSCALE | ||
632 |
4/4✓ Branch 0 taken 38333 times.
✓ Branch 1 taken 70927 times.
✓ Branch 3 taken 14640 times.
✓ Branch 4 taken 23693 times.
|
109260 | if (!consumed && (o = opt_find(&sc, opt, NULL, 0, |
633 | AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { | ||
634 |
2/4✓ Branch 0 taken 14640 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14640 times.
✗ Branch 3 not taken.
|
14640 | if (!strcmp(opt, "srcw") || !strcmp(opt, "srch") || |
635 |
2/4✓ Branch 0 taken 14640 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14640 times.
✗ Branch 3 not taken.
|
14640 | !strcmp(opt, "dstw") || !strcmp(opt, "dsth") || |
636 |
2/4✓ Branch 0 taken 14640 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14640 times.
|
14640 | !strcmp(opt, "src_format") || !strcmp(opt, "dst_format")) { |
637 | ✗ | av_log(NULL, AV_LOG_ERROR, "Directly using swscale dimensions/format options is not supported, please use the -s or -pix_fmt options\n"); | |
638 | ✗ | return AVERROR(EINVAL); | |
639 | } | ||
640 |
4/6✓ Branch 0 taken 14640 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14640 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14431 times.
✓ Branch 5 taken 209 times.
|
14640 | av_dict_set(&sws_dict, opt, arg, FLAGS); |
641 | |||
642 | 14640 | consumed = 1; | |
643 | } | ||
644 | #else | ||
645 | if (!consumed && !strcmp(opt, "sws_flags")) { | ||
646 | av_log(NULL, AV_LOG_WARNING, "Ignoring %s %s, due to disabled swscale\n", opt, arg); | ||
647 | consumed = 1; | ||
648 | } | ||
649 | #endif | ||
650 | #if CONFIG_SWRESAMPLE | ||
651 |
3/4✓ Branch 0 taken 23693 times.
✓ Branch 1 taken 85567 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23693 times.
|
109260 | if (!consumed && (o=opt_find(&swr_class, opt, NULL, 0, |
652 | AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { | ||
653 | ✗ | av_dict_set(&swr_opts, opt, arg, FLAGS); | |
654 | ✗ | consumed = 1; | |
655 | } | ||
656 | #endif | ||
657 | |||
658 |
2/2✓ Branch 0 taken 85567 times.
✓ Branch 1 taken 23693 times.
|
109260 | if (consumed) |
659 | 85567 | return 0; | |
660 | 23693 | return AVERROR_OPTION_NOT_FOUND; | |
661 | } | ||
662 | |||
663 | /* | ||
664 | * Check whether given option is a group separator. | ||
665 | * | ||
666 | * @return index of the group definition that matched or -1 if none | ||
667 | */ | ||
668 | 177799 | static int match_group_separator(const OptionGroupDef *groups, int nb_groups, | |
669 | const char *opt) | ||
670 | { | ||
671 | int i; | ||
672 | |||
673 |
2/2✓ Branch 0 taken 526233 times.
✓ Branch 1 taken 170634 times.
|
696867 | for (i = 0; i < nb_groups; i++) { |
674 | 526233 | const OptionGroupDef *p = &groups[i]; | |
675 |
4/4✓ Branch 0 taken 348434 times.
✓ Branch 1 taken 177799 times.
✓ Branch 2 taken 7165 times.
✓ Branch 3 taken 341269 times.
|
526233 | if (p->sep && !strcmp(p->sep, opt)) |
676 | 7165 | return i; | |
677 | } | ||
678 | |||
679 | 170634 | return -1; | |
680 | } | ||
681 | |||
682 | /* | ||
683 | * Finish parsing an option group. | ||
684 | * | ||
685 | * @param group_idx which group definition should this group belong to | ||
686 | * @param arg argument of the group delimiting option | ||
687 | */ | ||
688 | 15081 | static int finish_group(OptionParseContext *octx, int group_idx, | |
689 | const char *arg) | ||
690 | { | ||
691 | 15081 | OptionGroupList *l = &octx->groups[group_idx]; | |
692 | OptionGroup *g; | ||
693 | int ret; | ||
694 | |||
695 | 15081 | ret = GROW_ARRAY(l->groups, l->nb_groups); | |
696 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15081 times.
|
15081 | if (ret < 0) |
697 | ✗ | return ret; | |
698 | |||
699 | 15081 | g = &l->groups[l->nb_groups - 1]; | |
700 | |||
701 | 15081 | *g = octx->cur_group; | |
702 | 15081 | g->arg = arg; | |
703 | 15081 | g->group_def = l->group_def; | |
704 | 15081 | g->sws_dict = sws_dict; | |
705 | 15081 | g->swr_opts = swr_opts; | |
706 | 15081 | g->codec_opts = codec_opts; | |
707 | 15081 | g->format_opts = format_opts; | |
708 | |||
709 | 15081 | codec_opts = NULL; | |
710 | 15081 | format_opts = NULL; | |
711 | 15081 | sws_dict = NULL; | |
712 | 15081 | swr_opts = NULL; | |
713 | |||
714 | 15081 | memset(&octx->cur_group, 0, sizeof(octx->cur_group)); | |
715 | |||
716 | 15081 | return ret; | |
717 | } | ||
718 | |||
719 | /* | ||
720 | * Add an option instance to currently parsed group. | ||
721 | */ | ||
722 | 85075 | static int add_opt(OptionParseContext *octx, const OptionDef *opt, | |
723 | const char *key, const char *val) | ||
724 | { | ||
725 | 85075 | int global = !(opt->flags & OPT_PERFILE); | |
726 |
2/2✓ Branch 0 taken 38240 times.
✓ Branch 1 taken 46835 times.
|
85075 | OptionGroup *g = global ? &octx->global_opts : &octx->cur_group; |
727 | int ret; | ||
728 | |||
729 | 85075 | ret = GROW_ARRAY(g->opts, g->nb_opts); | |
730 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 85075 times.
|
85075 | if (ret < 0) |
731 | ✗ | return ret; | |
732 | |||
733 | 85075 | g->opts[g->nb_opts - 1].opt = opt; | |
734 | 85075 | g->opts[g->nb_opts - 1].key = key; | |
735 | 85075 | g->opts[g->nb_opts - 1].val = val; | |
736 | |||
737 | 85075 | return 0; | |
738 | } | ||
739 | |||
740 | 7915 | static int init_parse_context(OptionParseContext *octx, | |
741 | const OptionGroupDef *groups, int nb_groups) | ||
742 | { | ||
743 | static const OptionGroupDef global_group = { "global" }; | ||
744 | int i; | ||
745 | |||
746 | 7915 | memset(octx, 0, sizeof(*octx)); | |
747 | |||
748 | 7915 | octx->groups = av_calloc(nb_groups, sizeof(*octx->groups)); | |
749 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7915 times.
|
7915 | if (!octx->groups) |
750 | ✗ | return AVERROR(ENOMEM); | |
751 | 7915 | octx->nb_groups = nb_groups; | |
752 | |||
753 |
2/2✓ Branch 0 taken 23745 times.
✓ Branch 1 taken 7915 times.
|
31660 | for (i = 0; i < octx->nb_groups; i++) |
754 | 23745 | octx->groups[i].group_def = &groups[i]; | |
755 | |||
756 | 7915 | octx->global_opts.group_def = &global_group; | |
757 | 7915 | octx->global_opts.arg = ""; | |
758 | |||
759 | 7915 | return 0; | |
760 | } | ||
761 | |||
762 | 7915 | void uninit_parse_context(OptionParseContext *octx) | |
763 | { | ||
764 | int i, j; | ||
765 | |||
766 |
2/2✓ Branch 0 taken 23745 times.
✓ Branch 1 taken 7915 times.
|
31660 | for (i = 0; i < octx->nb_groups; i++) { |
767 | 23745 | OptionGroupList *l = &octx->groups[i]; | |
768 | |||
769 |
2/2✓ Branch 0 taken 15081 times.
✓ Branch 1 taken 23745 times.
|
38826 | for (j = 0; j < l->nb_groups; j++) { |
770 | 15081 | av_freep(&l->groups[j].opts); | |
771 | 15081 | av_dict_free(&l->groups[j].codec_opts); | |
772 | 15081 | av_dict_free(&l->groups[j].format_opts); | |
773 | |||
774 | 15081 | av_dict_free(&l->groups[j].sws_dict); | |
775 | 15081 | av_dict_free(&l->groups[j].swr_opts); | |
776 | } | ||
777 | 23745 | av_freep(&l->groups); | |
778 | } | ||
779 | 7915 | av_freep(&octx->groups); | |
780 | |||
781 | 7915 | av_freep(&octx->cur_group.opts); | |
782 | 7915 | av_freep(&octx->global_opts.opts); | |
783 | |||
784 | 7915 | uninit_opts(); | |
785 | 7915 | } | |
786 | |||
787 | 7915 | int split_commandline(OptionParseContext *octx, int argc, char *argv[], | |
788 | const OptionDef *options, | ||
789 | const OptionGroupDef *groups, int nb_groups) | ||
790 | { | ||
791 | int ret; | ||
792 | 7915 | int optindex = 1; | |
793 | 7915 | int dashdash = -2; | |
794 | |||
795 | /* perform system-dependent conversions for arguments list */ | ||
796 | 7915 | prepare_app_arguments(&argc, &argv); | |
797 | |||
798 | 7915 | ret = init_parse_context(octx, groups, nb_groups); | |
799 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7915 times.
|
7915 | if (ret < 0) |
800 | ✗ | return ret; | |
801 | |||
802 | 7915 | av_log(NULL, AV_LOG_DEBUG, "Splitting the commandline.\n"); | |
803 | |||
804 |
2/2✓ Branch 0 taken 185715 times.
✓ Branch 1 taken 7915 times.
|
193630 | while (optindex < argc) { |
805 | 185715 | const char *opt = argv[optindex++], *arg; | |
806 | const OptionDef *po; | ||
807 | int group_idx; | ||
808 | |||
809 | 185715 | av_log(NULL, AV_LOG_DEBUG, "Reading option '%s' ...", opt); | |
810 | |||
811 |
3/6✓ Branch 0 taken 180435 times.
✓ Branch 1 taken 5280 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 180435 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
185715 | if (opt[0] == '-' && opt[1] == '-' && !opt[2]) { |
812 | ✗ | dashdash = optindex; | |
813 | ✗ | continue; | |
814 | } | ||
815 | /* unnamed group separators, e.g. output filename */ | ||
816 |
5/6✓ Branch 0 taken 180435 times.
✓ Branch 1 taken 5280 times.
✓ Branch 2 taken 177799 times.
✓ Branch 3 taken 2636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 177799 times.
|
185715 | if (opt[0] != '-' || !opt[1] || dashdash+1 == optindex) { |
817 | 7916 | ret = finish_group(octx, 0, opt); | |
818 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7916 times.
|
7916 | if (ret < 0) |
819 | ✗ | return ret; | |
820 | |||
821 | 7916 | av_log(NULL, AV_LOG_DEBUG, " matched as %s.\n", groups[0].name); | |
822 | 7916 | continue; | |
823 | } | ||
824 | 177799 | opt++; | |
825 | |||
826 | #define GET_ARG(arg) \ | ||
827 | do { \ | ||
828 | arg = argv[optindex++]; \ | ||
829 | if (!arg) { \ | ||
830 | av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'.\n", opt);\ | ||
831 | return AVERROR(EINVAL); \ | ||
832 | } \ | ||
833 | } while (0) | ||
834 | |||
835 | /* named group separators, e.g. -i */ | ||
836 | 177799 | group_idx = match_group_separator(groups, nb_groups, opt); | |
837 |
2/2✓ Branch 0 taken 7165 times.
✓ Branch 1 taken 170634 times.
|
177799 | if (group_idx >= 0) { |
838 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7165 times.
|
7165 | GET_ARG(arg); |
839 | 7165 | ret = finish_group(octx, group_idx, arg); | |
840 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7165 times.
|
7165 | if (ret < 0) |
841 | ✗ | return ret; | |
842 | |||
843 | 7165 | av_log(NULL, AV_LOG_DEBUG, " matched as %s with argument '%s'.\n", | |
844 | 7165 | groups[group_idx].name, arg); | |
845 | 7165 | continue; | |
846 | } | ||
847 | |||
848 | /* normal options */ | ||
849 | 170634 | po = find_option(options, opt); | |
850 |
2/2✓ Branch 0 taken 61382 times.
✓ Branch 1 taken 109252 times.
|
170634 | if (po->name) { |
851 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 61381 times.
|
61382 | if (po->flags & OPT_EXIT) { |
852 | /* optional argument, e.g. -h */ | ||
853 | 1 | arg = argv[optindex++]; | |
854 |
2/2✓ Branch 1 taken 54506 times.
✓ Branch 2 taken 6875 times.
|
61381 | } else if (opt_has_arg(po)) { |
855 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54506 times.
|
54506 | GET_ARG(arg); |
856 | } else { | ||
857 | 6875 | arg = "1"; | |
858 | } | ||
859 | |||
860 | 61382 | ret = add_opt(octx, po, opt, arg); | |
861 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 61382 times.
|
61382 | if (ret < 0) |
862 | ✗ | return ret; | |
863 | |||
864 | 61382 | av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with " | |
865 | 61382 | "argument '%s'.\n", po->name, po->help, arg); | |
866 | 61382 | continue; | |
867 | } | ||
868 | |||
869 | /* AVOptions */ | ||
870 |
1/2✓ Branch 0 taken 109252 times.
✗ Branch 1 not taken.
|
109252 | if (argv[optindex]) { |
871 | 109252 | ret = opt_default(NULL, opt, argv[optindex]); | |
872 |
2/2✓ Branch 0 taken 85559 times.
✓ Branch 1 taken 23693 times.
|
109252 | if (ret >= 0) { |
873 | 85559 | av_log(NULL, AV_LOG_DEBUG, " matched as AVOption '%s' with " | |
874 | 85559 | "argument '%s'.\n", opt, argv[optindex]); | |
875 | 85559 | optindex++; | |
876 | 85559 | continue; | |
877 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23693 times.
|
23693 | } else if (ret != AVERROR_OPTION_NOT_FOUND) { |
878 | ✗ | av_log(NULL, AV_LOG_ERROR, "Error parsing option '%s' " | |
879 | ✗ | "with argument '%s'.\n", opt, argv[optindex]); | |
880 | ✗ | return ret; | |
881 | } | ||
882 | } | ||
883 | |||
884 | /* boolean -nofoo options */ | ||
885 |
3/6✓ Branch 0 taken 23693 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23693 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 23693 times.
✗ Branch 5 not taken.
|
47386 | if (opt[0] == 'n' && opt[1] == 'o' && |
886 | 23693 | (po = find_option(options, opt + 2)) && | |
887 |
2/4✓ Branch 0 taken 23693 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23693 times.
✗ Branch 3 not taken.
|
23693 | po->name && po->type == OPT_TYPE_BOOL) { |
888 | 23693 | ret = add_opt(octx, po, opt, "0"); | |
889 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23693 times.
|
23693 | if (ret < 0) |
890 | ✗ | return ret; | |
891 | |||
892 | 23693 | av_log(NULL, AV_LOG_DEBUG, " matched as option '%s' (%s) with " | |
893 | 23693 | "argument 0.\n", po->name, po->help); | |
894 | 23693 | continue; | |
895 | } | ||
896 | |||
897 | ✗ | av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'.\n", opt); | |
898 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
899 | } | ||
900 | |||
901 |
3/6✓ Branch 0 taken 7915 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7915 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7915 times.
|
7915 | if (octx->cur_group.nb_opts || codec_opts || format_opts) |
902 | ✗ | av_log(NULL, AV_LOG_WARNING, "Trailing option(s) found in the " | |
903 | "command: may be ignored.\n"); | ||
904 | |||
905 | 7915 | av_log(NULL, AV_LOG_DEBUG, "Finished splitting the commandline.\n"); | |
906 | |||
907 | 7915 | return 0; | |
908 | } | ||
909 | |||
910 | ✗ | int read_yesno(void) | |
911 | { | ||
912 | ✗ | int c = getchar(); | |
913 | ✗ | int yesno = (av_toupper(c) == 'Y'); | |
914 | |||
915 | ✗ | while (c != '\n' && c != EOF) | |
916 | ✗ | c = getchar(); | |
917 | |||
918 | ✗ | return yesno; | |
919 | } | ||
920 | |||
921 | ✗ | FILE *get_preset_file(char *filename, size_t filename_size, | |
922 | const char *preset_name, int is_path, | ||
923 | const char *codec_name) | ||
924 | { | ||
925 | ✗ | FILE *f = NULL; | |
926 | int i; | ||
927 | #if HAVE_GETMODULEHANDLE && defined(_WIN32) | ||
928 | char *datadir = NULL; | ||
929 | #endif | ||
930 | ✗ | char *env_home = getenv_utf8("HOME"); | |
931 | ✗ | char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR"); | |
932 | ✗ | const char *base[3] = { env_ffmpeg_datadir, | |
933 | env_home, /* index=1(HOME) is special: search in a .ffmpeg subfolder */ | ||
934 | FFMPEG_DATADIR, }; | ||
935 | |||
936 | ✗ | if (is_path) { | |
937 | ✗ | av_strlcpy(filename, preset_name, filename_size); | |
938 | ✗ | f = fopen_utf8(filename, "r"); | |
939 | } else { | ||
940 | #if HAVE_GETMODULEHANDLE && defined(_WIN32) | ||
941 | wchar_t *datadir_w = get_module_filename(NULL); | ||
942 | base[2] = NULL; | ||
943 | |||
944 | if (wchartoutf8(datadir_w, &datadir)) | ||
945 | datadir = NULL; | ||
946 | av_free(datadir_w); | ||
947 | |||
948 | if (datadir) | ||
949 | { | ||
950 | char *ls; | ||
951 | for (ls = datadir; *ls; ls++) | ||
952 | if (*ls == '\\') *ls = '/'; | ||
953 | |||
954 | if (ls = strrchr(datadir, '/')) | ||
955 | { | ||
956 | ptrdiff_t datadir_len = ls - datadir; | ||
957 | size_t desired_size = datadir_len + strlen("/ffpresets") + 1; | ||
958 | char *new_datadir = av_realloc_array( | ||
959 | datadir, desired_size, sizeof *datadir); | ||
960 | if (new_datadir) { | ||
961 | datadir = new_datadir; | ||
962 | datadir[datadir_len] = 0; | ||
963 | strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len); | ||
964 | base[2] = datadir; | ||
965 | } | ||
966 | } | ||
967 | } | ||
968 | #endif | ||
969 | ✗ | for (i = 0; i < 3 && !f; i++) { | |
970 | ✗ | if (!base[i]) | |
971 | ✗ | continue; | |
972 | ✗ | snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], | |
973 | i != 1 ? "" : "/.ffmpeg", preset_name); | ||
974 | ✗ | f = fopen_utf8(filename, "r"); | |
975 | ✗ | if (!f && codec_name) { | |
976 | ✗ | 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 | 16378 | int cmdutils_isalnum(char c) | |
994 | { | ||
995 |
3/4✓ Branch 0 taken 214 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 16337 times.
|
16378 | return (c >= '0' && c <= '9') || |
996 |
5/6✓ Branch 0 taken 214 times.
✓ Branch 1 taken 16164 times.
✓ Branch 2 taken 41 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 16338 times.
|
32796 | (c >= 'A' && c <= 'Z') || |
997 |
1/2✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
|
40 | (c >= 'a' && c <= 'z'); |
998 | } | ||
999 | |||
1000 | 32284 | void stream_specifier_uninit(StreamSpecifier *ss) | |
1001 | { | ||
1002 | 32284 | av_freep(&ss->meta_key); | |
1003 | 32284 | av_freep(&ss->meta_val); | |
1004 | 32284 | av_freep(&ss->remainder); | |
1005 | |||
1006 | 32284 | memset(ss, 0, sizeof(*ss)); | |
1007 | 32284 | } | |
1008 | |||
1009 | 32223 | int stream_specifier_parse(StreamSpecifier *ss, const char *spec, | |
1010 | int allow_remainder, void *logctx) | ||
1011 | { | ||
1012 | char *endptr; | ||
1013 | int ret; | ||
1014 | |||
1015 | 32223 | memset(ss, 0, sizeof(*ss)); | |
1016 | |||
1017 | 32223 | ss->idx = -1; | |
1018 | 32223 | ss->media_type = AVMEDIA_TYPE_UNKNOWN; | |
1019 | 32223 | ss->stream_list = STREAM_LIST_ALL; | |
1020 | |||
1021 | 32223 | av_log(logctx, AV_LOG_TRACE, "Parsing stream specifier: %s\n", spec); | |
1022 | |||
1023 |
2/2✓ Branch 0 taken 16738 times.
✓ Branch 1 taken 31825 times.
|
80786 | while (*spec) { |
1024 |
3/4✓ Branch 0 taken 385 times.
✓ Branch 1 taken 16353 times.
✓ Branch 2 taken 385 times.
✗ Branch 3 not taken.
|
16738 | if (*spec <= '9' && *spec >= '0') { /* opt:index */ |
1025 | 385 | ss->idx = strtol(spec, &endptr, 0); | |
1026 | |||
1027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 385 times.
|
385 | av_assert0(endptr > spec); |
1028 | 385 | spec = endptr; | |
1029 | |||
1030 | 385 | av_log(logctx, AV_LOG_TRACE, | |
1031 | "Parsed index: %d; remainder: %s\n", ss->idx, spec); | ||
1032 | |||
1033 | // this terminates the specifier | ||
1034 | 385 | break; | |
1035 |
6/6✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 14865 times.
✓ Branch 2 taken 46 times.
✓ Branch 3 taken 1442 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 36 times.
|
16353 | } else if ((*spec == 'v' || *spec == 'a' || *spec == 's' || |
1036 |
7/8✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 16333 times.
✓ Branch 7 taken 14 times.
|
16357 | *spec == 'd' || *spec == 't' || *spec == 'V') && |
1037 | 16347 | !cmdutils_isalnum(*(spec + 1))) { /* opt:[vasdtV] */ | |
1038 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16333 times.
|
16333 | 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 |
4/7✓ Branch 0 taken 14852 times.
✓ Branch 1 taken 1442 times.
✓ Branch 2 taken 36 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
16333 | switch (*spec++) { |
1045 | 14852 | case 'v': ss->media_type = AVMEDIA_TYPE_VIDEO; break; | |
1046 | 1442 | case 'a': ss->media_type = AVMEDIA_TYPE_AUDIO; break; | |
1047 | 36 | case 's': ss->media_type = AVMEDIA_TYPE_SUBTITLE; break; | |
1048 | ✗ | 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 | 16333 | av_log(logctx, AV_LOG_TRACE, "Parsed media type: %s; remainder: %s\n", | |
1056 | av_get_media_type_string(ss->media_type), spec); | ||
1057 |
3/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
20 | } else if (*spec == 'g' && *(spec + 1) == ':') { |
1058 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (ss->stream_list != STREAM_LIST_ALL) |
1059 | ✗ | goto multiple_stream_lists; | |
1060 | |||
1061 | 6 | spec += 2; | |
1062 |
5/6✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
6 | if (*spec == '#' || (*spec == 'i' && *(spec + 1) == ':')) { |
1063 | 3 | ss->stream_list = STREAM_LIST_GROUP_ID; | |
1064 | |||
1065 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | spec += 1 + (*spec == 'i'); |
1066 | } else | ||
1067 | 3 | ss->stream_list = STREAM_LIST_GROUP_IDX; | |
1068 | |||
1069 | 6 | ss->list_id = strtol(spec, &endptr, 0); | |
1070 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | 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 | 6 | spec = endptr; | |
1076 | |||
1077 | 6 | av_log(logctx, AV_LOG_TRACE, "Parsed stream group %s: %"PRId64"; remainder: %s\n", | |
1078 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
|
6 | ss->stream_list == STREAM_LIST_GROUP_ID ? "ID" : "index", ss->list_id, spec); |
1079 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
14 | } else if (*spec == 'p' && *(spec + 1) == ':') { |
1080 | ✗ | 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 | ✗ | 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 0 taken 1 times.
✓ Branch 1 taken 13 times.
|
14 | } 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 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | av_assert0(o); |
1103 | |||
1104 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
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 0 taken 26 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
|
57 | spec[len] == '_' || spec[len] == '+'; len++) |
1114 | 28 | continue; | |
1115 | |||
1116 | 1 | disp = av_strndup(spec, len); | |
1117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
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 0 not taken.
✓ Branch 1 taken 1 times.
|
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 0 taken 13 times.
✗ Branch 1 not taken.
|
13 | } else if (*spec == '#' || |
1134 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
13 | (*spec == 'i' && *(spec + 1) == ':')) { |
1135 | ✗ | if (ss->stream_list != STREAM_LIST_ALL) | |
1136 | ✗ | goto multiple_stream_lists; | |
1137 | |||
1138 | ✗ | ss->stream_list = STREAM_LIST_STREAM_ID; | |
1139 | |||
1140 | ✗ | spec += 1 + (*spec == 'i'); | |
1141 | ✗ | ss->list_id = strtol(spec, &endptr, 0); | |
1142 | ✗ | 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 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
13 | } else if (*spec == 'm' && *(spec + 1) == ':') { |
1155 | ✗ | av_assert0(!ss->meta_key && !ss->meta_val); | |
1156 | |||
1157 | ✗ | spec += 2; | |
1158 | ✗ | ss->meta_key = av_get_token(&spec, ":"); | |
1159 | ✗ | if (!ss->meta_key) { | |
1160 | ✗ | ret = AVERROR(ENOMEM); | |
1161 | ✗ | goto fail; | |
1162 | } | ||
1163 | ✗ | if (*spec == ':') { | |
1164 | ✗ | spec++; | |
1165 | ✗ | ss->meta_val = av_get_token(&spec, ":"); | |
1166 | ✗ | 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 | ✗ | ss->meta_val ? ss->meta_val : "<any value>", spec); | |
1175 | |||
1176 | // this terminates the specifier | ||
1177 | ✗ | break; | |
1178 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
13 | } 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 0 taken 173 times.
✓ Branch 1 taken 16167 times.
|
16340 | if (*spec == ':') |
1189 | 173 | spec++; | |
1190 | } | ||
1191 | |||
1192 |
2/2✓ Branch 0 taken 13 times.
✓ Branch 1 taken 32210 times.
|
32223 | if (*spec) { |
1193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!allow_remainder) { |
1194 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
1195 | "Trailing garbage at the end of a stream specifier: %s\n", | ||
1196 | spec); | ||
1197 | ✗ | ret = AVERROR(EINVAL); | |
1198 | ✗ | goto fail; | |
1199 | } | ||
1200 | |||
1201 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (*spec == ':') |
1202 | ✗ | spec++; | |
1203 | |||
1204 | 13 | ss->remainder = av_strdup(spec); | |
1205 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!ss->remainder) { |
1206 | ✗ | ret = AVERROR(EINVAL); | |
1207 | ✗ | goto fail; | |
1208 | } | ||
1209 | } | ||
1210 | |||
1211 | 32223 | 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 | ✗ | fail: | |
1220 | ✗ | stream_specifier_uninit(ss); | |
1221 | ✗ | return ret; | |
1222 | } | ||
1223 | |||
1224 | 33810 | unsigned stream_specifier_match(const StreamSpecifier *ss, | |
1225 | const AVFormatContext *s, const AVStream *st, | ||
1226 | void *logctx) | ||
1227 | { | ||
1228 | 33810 | const AVStreamGroup *g = NULL; | |
1229 | 33810 | const AVProgram *p = NULL; | |
1230 | 33810 | int start_stream = 0, nb_streams; | |
1231 | 33810 | int nb_matched = 0; | |
1232 | |||
1233 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 33794 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
33810 | 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 | ✗ | av_assert0(ss->idx < 0); | |
1237 | // return early if we know for sure the stream does not match | ||
1238 | ✗ | if (st->id != ss->list_id) | |
1239 | ✗ | return 0; | |
1240 | ✗ | start_stream = st->index; | |
1241 | ✗ | nb_streams = st->index + 1; | |
1242 | ✗ | break; | |
1243 | 33794 | case STREAM_LIST_ALL: | |
1244 |
2/2✓ Branch 0 taken 33136 times.
✓ Branch 1 taken 658 times.
|
33794 | start_stream = ss->idx >= 0 ? 0 : st->index; |
1245 | 33794 | nb_streams = st->index + 1; | |
1246 | 33794 | break; | |
1247 | ✗ | case STREAM_LIST_PROGRAM: | |
1248 | ✗ | for (unsigned i = 0; i < s->nb_programs; i++) { | |
1249 | ✗ | if (s->programs[i]->id == ss->list_id) { | |
1250 | ✗ | p = s->programs[i]; | |
1251 | ✗ | break; | |
1252 | } | ||
1253 | } | ||
1254 | ✗ | 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 | 9 | case STREAM_LIST_GROUP_ID: | |
1262 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | for (unsigned i = 0; i < s->nb_stream_groups; i++) { |
1263 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
|
18 | if (ss->list_id == s->stream_groups[i]->id) { |
1264 | 9 | g = s->stream_groups[i]; | |
1265 | 9 | break; | |
1266 | } | ||
1267 | } | ||
1268 | // fall-through | ||
1269 | case STREAM_LIST_GROUP_IDX: | ||
1270 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 9 times.
|
16 | if (ss->stream_list == STREAM_LIST_GROUP_IDX && |
1271 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
7 | ss->list_id >= 0 && ss->list_id < s->nb_stream_groups) |
1272 | 7 | g = s->stream_groups[ss->list_id]; | |
1273 | |||
1274 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | 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 | ✗ | ss->list_id); | |
1279 | ✗ | return 0; | |
1280 | } | ||
1281 | 16 | nb_streams = g->nb_streams; | |
1282 | 16 | break; | |
1283 | ✗ | default: av_assert0(0); | |
1284 | } | ||
1285 | |||
1286 |
2/2✓ Branch 0 taken 35256 times.
✓ Branch 1 taken 455 times.
|
35711 | for (int i = start_stream; i < nb_streams; i++) { |
1287 |
3/4✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35221 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 35221 times.
|
35256 | const AVStream *candidate = s->streams[g ? g->streams[i]->index : |
1288 | ✗ | p ? p->stream_index[i] : i]; | |
1289 | |||
1290 |
2/2✓ Branch 0 taken 20492 times.
✓ Branch 1 taken 14764 times.
|
35256 | if (ss->media_type != AVMEDIA_TYPE_UNKNOWN && |
1291 |
2/2✓ Branch 0 taken 19803 times.
✓ Branch 1 taken 689 times.
|
20492 | (ss->media_type != candidate->codecpar->codec_type || |
1292 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 19803 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
19803 | (ss->no_apic && (candidate->disposition & AV_DISPOSITION_ATTACHED_PIC)))) |
1293 | 689 | continue; | |
1294 | |||
1295 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34567 times.
|
34567 | if (ss->meta_key) { |
1296 | ✗ | const AVDictionaryEntry *tag = av_dict_get(candidate->metadata, | |
1297 | ✗ | ss->meta_key, NULL, 0); | |
1298 | |||
1299 | ✗ | if (!tag) | |
1300 | ✗ | continue; | |
1301 | ✗ | if (ss->meta_val && strcmp(tag->value, ss->meta_val)) | |
1302 | ✗ | continue; | |
1303 | } | ||
1304 | |||
1305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 34567 times.
|
34567 | if (ss->usable_only) { |
1306 | ✗ | const AVCodecParameters *par = candidate->codecpar; | |
1307 | |||
1308 | ✗ | switch (par->codec_type) { | |
1309 | ✗ | case AVMEDIA_TYPE_AUDIO: | |
1310 | ✗ | if (!par->sample_rate || !par->ch_layout.nb_channels || | |
1311 | ✗ | par->format == AV_SAMPLE_FMT_NONE) | |
1312 | ✗ | continue; | |
1313 | ✗ | break; | |
1314 | ✗ | case AVMEDIA_TYPE_VIDEO: | |
1315 | ✗ | if (!par->width || !par->height || par->format == AV_PIX_FMT_NONE) | |
1316 | ✗ | continue; | |
1317 | ✗ | break; | |
1318 | ✗ | case AVMEDIA_TYPE_UNKNOWN: | |
1319 | ✗ | continue; | |
1320 | } | ||
1321 | } | ||
1322 | |||
1323 |
2/2✓ Branch 0 taken 55 times.
✓ Branch 1 taken 34512 times.
|
34567 | if (ss->disposition && |
1324 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
|
55 | (candidate->disposition & ss->disposition) != ss->disposition) |
1325 | 44 | continue; | |
1326 | |||
1327 |
2/2✓ Branch 0 taken 33355 times.
✓ Branch 1 taken 1168 times.
|
34523 | if (st == candidate) |
1328 |
4/4✓ Branch 0 taken 567 times.
✓ Branch 1 taken 32788 times.
✓ Branch 2 taken 172 times.
✓ Branch 3 taken 395 times.
|
33355 | return ss->idx < 0 || ss->idx == nb_matched; |
1329 | |||
1330 | 1168 | nb_matched++; | |
1331 | } | ||
1332 | |||
1333 | 455 | return 0; | |
1334 | } | ||
1335 | |||
1336 | 518 | int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) | |
1337 | { | ||
1338 | StreamSpecifier ss; | ||
1339 | int ret; | ||
1340 | |||
1341 | 518 | ret = stream_specifier_parse(&ss, spec, 0, NULL); | |
1342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 518 times.
|
518 | if (ret < 0) |
1343 | ✗ | return ret; | |
1344 | |||
1345 | 518 | ret = stream_specifier_match(&ss, s, st, NULL); | |
1346 | 518 | stream_specifier_uninit(&ss); | |
1347 | 518 | return ret; | |
1348 | } | ||
1349 | |||
1350 | 24109 | int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id, | |
1351 | AVFormatContext *s, AVStream *st, const AVCodec *codec, | ||
1352 | AVDictionary **dst, AVDictionary **opts_used) | ||
1353 | { | ||
1354 | 24109 | AVDictionary *ret = NULL; | |
1355 | 24109 | const AVDictionaryEntry *t = NULL; | |
1356 | 48218 | int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM | |
1357 |
2/2✓ Branch 0 taken 8357 times.
✓ Branch 1 taken 15752 times.
|
24109 | : AV_OPT_FLAG_DECODING_PARAM; |
1358 | 24109 | char prefix = 0; | |
1359 | 24109 | const AVClass *cc = avcodec_get_class(); | |
1360 | |||
1361 |
4/4✓ Branch 0 taken 18674 times.
✓ Branch 1 taken 5110 times.
✓ Branch 2 taken 240 times.
✓ Branch 3 taken 85 times.
|
24109 | switch (st->codecpar->codec_type) { |
1362 | 18674 | case AVMEDIA_TYPE_VIDEO: | |
1363 | 18674 | prefix = 'v'; | |
1364 | 18674 | flags |= AV_OPT_FLAG_VIDEO_PARAM; | |
1365 | 18674 | break; | |
1366 | 5110 | case AVMEDIA_TYPE_AUDIO: | |
1367 | 5110 | prefix = 'a'; | |
1368 | 5110 | flags |= AV_OPT_FLAG_AUDIO_PARAM; | |
1369 | 5110 | break; | |
1370 | 240 | case AVMEDIA_TYPE_SUBTITLE: | |
1371 | 240 | prefix = 's'; | |
1372 | 240 | flags |= AV_OPT_FLAG_SUBTITLE_PARAM; | |
1373 | 240 | break; | |
1374 | } | ||
1375 | |||
1376 |
2/2✓ Branch 1 taken 73219 times.
✓ Branch 2 taken 24109 times.
|
97328 | while (t = av_dict_iterate(opts, t)) { |
1377 | const AVClass *priv_class; | ||
1378 | 73219 | char *p = strchr(t->key, ':'); | |
1379 | 73219 | int used = 0; | |
1380 | |||
1381 | /* check stream specification in opt name */ | ||
1382 |
2/2✓ Branch 0 taken 288 times.
✓ Branch 1 taken 72931 times.
|
73219 | if (p) { |
1383 | 288 | int err = check_stream_specifier(s, st, p + 1); | |
1384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 288 times.
|
288 | if (err < 0) { |
1385 | ✗ | av_dict_free(&ret); | |
1386 | ✗ | return err; | |
1387 |
2/2✓ Branch 0 taken 78 times.
✓ Branch 1 taken 210 times.
|
288 | } else if (!err) |
1388 | 78 | continue; | |
1389 | |||
1390 | 210 | *p = 0; | |
1391 | } | ||
1392 | |||
1393 |
4/4✓ Branch 1 taken 2725 times.
✓ Branch 2 taken 70416 times.
✓ Branch 3 taken 1574 times.
✓ Branch 4 taken 1151 times.
|
73141 | if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || |
1394 | 1574 | !codec || | |
1395 |
4/4✓ Branch 0 taken 707 times.
✓ Branch 1 taken 867 times.
✓ Branch 2 taken 323 times.
✓ Branch 3 taken 384 times.
|
2281 | ((priv_class = codec->priv_class) && |
1396 | 707 | av_opt_find(&priv_class, t->key, NULL, flags, | |
1397 | AV_OPT_SEARCH_FAKE_OBJ))) { | ||
1398 | 71890 | av_dict_set(&ret, t->key, t->value, 0); | |
1399 | 71890 | used = 1; | |
1400 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1248 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
1254 | } else if (t->key[0] == prefix && |
1401 | 3 | av_opt_find(&cc, t->key + 1, NULL, flags, | |
1402 | AV_OPT_SEARCH_FAKE_OBJ)) { | ||
1403 | 1 | av_dict_set(&ret, t->key + 1, t->value, 0); | |
1404 | 1 | used = 1; | |
1405 | } | ||
1406 | |||
1407 |
2/2✓ Branch 0 taken 210 times.
✓ Branch 1 taken 72931 times.
|
73141 | if (p) |
1408 | 210 | *p = ':'; | |
1409 | |||
1410 |
4/4✓ Branch 0 taken 71891 times.
✓ Branch 1 taken 1250 times.
✓ Branch 2 taken 47145 times.
✓ Branch 3 taken 24746 times.
|
73141 | if (used && opts_used) |
1411 | 47145 | av_dict_set(opts_used, t->key, "", 0); | |
1412 | } | ||
1413 | |||
1414 | 24109 | *dst = ret; | |
1415 | 24109 | return 0; | |
1416 | } | ||
1417 | |||
1418 | 7315 | int setup_find_stream_info_opts(AVFormatContext *s, | |
1419 | AVDictionary *local_codec_opts, | ||
1420 | AVDictionary ***dst) | ||
1421 | { | ||
1422 | int ret; | ||
1423 | AVDictionary **opts; | ||
1424 | |||
1425 | 7315 | *dst = NULL; | |
1426 | |||
1427 |
2/2✓ Branch 0 taken 85 times.
✓ Branch 1 taken 7230 times.
|
7315 | if (!s->nb_streams) |
1428 | 85 | return 0; | |
1429 | |||
1430 | 7230 | opts = av_calloc(s->nb_streams, sizeof(*opts)); | |
1431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7230 times.
|
7230 | if (!opts) |
1432 | ✗ | return AVERROR(ENOMEM); | |
1433 | |||
1434 |
2/2✓ Branch 0 taken 7851 times.
✓ Branch 1 taken 7230 times.
|
15081 | for (int i = 0; i < s->nb_streams; i++) { |
1435 | 7851 | ret = filter_codec_opts(local_codec_opts, s->streams[i]->codecpar->codec_id, | |
1436 | 7851 | s, s->streams[i], NULL, &opts[i], NULL); | |
1437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7851 times.
|
7851 | if (ret < 0) |
1438 | ✗ | goto fail; | |
1439 | } | ||
1440 | 7230 | *dst = opts; | |
1441 | 7230 | return 0; | |
1442 | ✗ | fail: | |
1443 | ✗ | for (int i = 0; i < s->nb_streams; i++) | |
1444 | ✗ | av_dict_free(&opts[i]); | |
1445 | ✗ | av_freep(&opts); | |
1446 | ✗ | return ret; | |
1447 | } | ||
1448 | |||
1449 | 241440 | int grow_array(void **array, int elem_size, int *size, int new_size) | |
1450 | { | ||
1451 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241440 times.
|
241440 | if (new_size >= INT_MAX / elem_size) { |
1452 | ✗ | av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); | |
1453 | ✗ | return AVERROR(ERANGE); | |
1454 | } | ||
1455 |
1/2✓ Branch 0 taken 241440 times.
✗ Branch 1 not taken.
|
241440 | if (*size < new_size) { |
1456 | 241440 | uint8_t *tmp = av_realloc_array(*array, new_size, elem_size); | |
1457 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 241440 times.
|
241440 | if (!tmp) |
1458 | ✗ | return AVERROR(ENOMEM); | |
1459 | 241440 | memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); | |
1460 | 241440 | *size = new_size; | |
1461 | 241440 | *array = tmp; | |
1462 | 241440 | return 0; | |
1463 | } | ||
1464 | ✗ | return 0; | |
1465 | } | ||
1466 | |||
1467 | 45565 | void *allocate_array_elem(void *ptr, size_t elem_size, int *nb_elems) | |
1468 | { | ||
1469 | void *new_elem; | ||
1470 | |||
1471 |
2/4✓ Branch 1 taken 45565 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 45565 times.
|
91130 | if (!(new_elem = av_mallocz(elem_size)) || |
1472 | 45565 | av_dynarray_add_nofree(ptr, nb_elems, new_elem) < 0) | |
1473 | ✗ | return NULL; | |
1474 | 45565 | return new_elem; | |
1475 | } | ||
1476 | |||
1477 | 5566 | double get_rotation(const int32_t *displaymatrix) | |
1478 | { | ||
1479 | 5566 | double theta = 0; | |
1480 |
1/2✓ Branch 0 taken 5566 times.
✗ Branch 1 not taken.
|
5566 | if (displaymatrix) |
1481 | 5566 | theta = -round(av_display_rotation_get(displaymatrix)); | |
1482 | |||
1483 | 5566 | theta -= 360*floor(theta/360 + 0.9/360); | |
1484 | |||
1485 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5566 times.
|
5566 | if (fabs(theta - 90*round(theta/90)) > 2) |
1486 | ✗ | av_log(NULL, AV_LOG_WARNING, "Odd rotation angle.\n" | |
1487 | "If you want to help, upload a sample " | ||
1488 | "of this file to https://streams.videolan.org/upload/ " | ||
1489 | "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)"); | ||
1490 | |||
1491 | 5566 | return theta; | |
1492 | } | ||
1493 | |||
1494 | /* read file contents into a string */ | ||
1495 | 65 | char *file_read(const char *filename) | |
1496 | { | ||
1497 | 65 | AVIOContext *pb = NULL; | |
1498 | 65 | int ret = avio_open(&pb, filename, AVIO_FLAG_READ); | |
1499 | AVBPrint bprint; | ||
1500 | char *str; | ||
1501 | |||
1502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
|
65 | if (ret < 0) { |
1503 | ✗ | av_log(NULL, AV_LOG_ERROR, "Error opening file %s.\n", filename); | |
1504 | ✗ | return NULL; | |
1505 | } | ||
1506 | |||
1507 | 65 | av_bprint_init(&bprint, 0, AV_BPRINT_SIZE_UNLIMITED); | |
1508 | 65 | ret = avio_read_to_bprint(pb, &bprint, SIZE_MAX); | |
1509 | 65 | avio_closep(&pb); | |
1510 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
|
65 | if (ret < 0) { |
1511 | ✗ | av_bprint_finalize(&bprint, NULL); | |
1512 | ✗ | return NULL; | |
1513 | } | ||
1514 | 65 | ret = av_bprint_finalize(&bprint, &str); | |
1515 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 65 times.
|
65 | if (ret < 0) |
1516 | ✗ | return NULL; | |
1517 | 65 | return str; | |
1518 | } | ||
1519 | |||
1520 | 7164 | void remove_avoptions(AVDictionary **a, AVDictionary *b) | |
1521 | { | ||
1522 | 7164 | const AVDictionaryEntry *t = NULL; | |
1523 | |||
1524 |
2/2✓ Branch 1 taken 23570 times.
✓ Branch 2 taken 7164 times.
|
30734 | while ((t = av_dict_iterate(b, t))) { |
1525 | 23570 | av_dict_set(a, t->key, NULL, AV_DICT_MATCH_CASE); | |
1526 | } | ||
1527 | 7164 | } | |
1528 | |||
1529 | 21614 | int check_avoptions(AVDictionary *m) | |
1530 | { | ||
1531 | 21614 | const AVDictionaryEntry *t = av_dict_iterate(m, NULL); | |
1532 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21614 times.
|
21614 | if (t) { |
1533 | ✗ | av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); | |
1534 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1535 | } | ||
1536 | |||
1537 | 21614 | return 0; | |
1538 | } | ||
1539 |