FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/opt.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 1047 1412 74.2%
Functions: 62 82 75.6%
Branches: 653 1061 61.5%

Line Branch Exec Source
1 /*
2 * AVOptions
3 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
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 /**
23 * @file
24 * AVOptions
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #include "avutil.h"
29 #include "avassert.h"
30 #include "avstring.h"
31 #include "channel_layout.h"
32 #include "common.h"
33 #include "dict.h"
34 #include "eval.h"
35 #include "log.h"
36 #include "parseutils.h"
37 #include "pixdesc.h"
38 #include "mathematics.h"
39 #include "opt.h"
40 #include "samplefmt.h"
41 #include "bprint.h"
42 #include "version.h"
43
44 #include <float.h>
45
46 479538146 const AVOption *av_opt_next(const void *obj, const AVOption *last)
47 {
48 const AVClass *class;
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 479538146 times.
479538146 if (!obj)
50 return NULL;
51 479538146 class = *(const AVClass**)obj;
52
7/8
✓ Branch 0 taken 38145241 times.
✓ Branch 1 taken 441392905 times.
✓ Branch 2 taken 38145241 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37872061 times.
✓ Branch 5 taken 273180 times.
✓ Branch 6 taken 37779097 times.
✓ Branch 7 taken 92964 times.
479538146 if (!last && class && class->option && class->option[0].name)
53 37779097 return class->option;
54
4/4
✓ Branch 0 taken 441392905 times.
✓ Branch 1 taken 366144 times.
✓ Branch 2 taken 404194152 times.
✓ Branch 3 taken 37198753 times.
441759049 if (last && last[1].name)
55 404194152 return ++last;
56 37564897 return NULL;
57 }
58
59 127506 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
60 {
61
7/10
✓ Branch 0 taken 109058 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 18436 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
127506 switch (o->type) {
62 109058 case AV_OPT_TYPE_FLAGS:
63 109058 *intnum = *(unsigned int*)dst;
64 109058 return 0;
65 2 case AV_OPT_TYPE_PIXEL_FMT:
66 2 *intnum = *(enum AVPixelFormat *)dst;
67 2 return 0;
68 2 case AV_OPT_TYPE_SAMPLE_FMT:
69 2 *intnum = *(enum AVSampleFormat *)dst;
70 2 return 0;
71 18436 case AV_OPT_TYPE_BOOL:
72 case AV_OPT_TYPE_INT:
73 18436 *intnum = *(int *)dst;
74 18436 return 0;
75 #if FF_API_OLD_CHANNEL_LAYOUT
76 FF_DISABLE_DEPRECATION_WARNINGS
77 4 case AV_OPT_TYPE_CHANNEL_LAYOUT:
78 FF_ENABLE_DEPRECATION_WARNINGS
79 #endif
80 case AV_OPT_TYPE_DURATION:
81 case AV_OPT_TYPE_INT64:
82 case AV_OPT_TYPE_UINT64:
83 4 *intnum = *(int64_t *)dst;
84 4 return 0;
85 2 case AV_OPT_TYPE_FLOAT:
86 2 *num = *(float *)dst;
87 2 return 0;
88 2 case AV_OPT_TYPE_DOUBLE:
89 2 *num = *(double *)dst;
90 2 return 0;
91 case AV_OPT_TYPE_RATIONAL:
92 *intnum = ((AVRational *)dst)->num;
93 *den = ((AVRational *)dst)->den;
94 return 0;
95 case AV_OPT_TYPE_CONST:
96 *intnum = o->default_val.i64;
97 return 0;
98 }
99 return AVERROR(EINVAL);
100 }
101
102 7043555 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
103 {
104
4/4
✓ Branch 0 taken 6265619 times.
✓ Branch 1 taken 777936 times.
✓ Branch 2 taken 6265618 times.
✓ Branch 3 taken 1 times.
7043555 if (o->type != AV_OPT_TYPE_FLAGS &&
105
4/4
✓ Branch 0 taken 6265613 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 6265608 times.
6265618 (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
106
4/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
11 num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
107 11 av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
108 11 num, o->name, o->min, o->max);
109 11 return AVERROR(ERANGE);
110 }
111
2/2
✓ Branch 0 taken 777936 times.
✓ Branch 1 taken 6265608 times.
7043544 if (o->type == AV_OPT_TYPE_FLAGS) {
112 777936 double d = num*intnum/den;
113
3/6
✓ Branch 0 taken 777936 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 777936 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 777936 times.
777936 if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) {
114 av_log(obj, AV_LOG_ERROR,
115 "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
116 num*intnum/den, o->name);
117 return AVERROR(ERANGE);
118 }
119 }
120
121
7/9
✓ Branch 0 taken 63839 times.
✓ Branch 1 taken 44749 times.
✓ Branch 2 taken 5515168 times.
✓ Branch 3 taken 467457 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 711287 times.
✓ Branch 6 taken 51060 times.
✓ Branch 7 taken 189984 times.
✗ Branch 8 not taken.
7043544 switch (o->type) {
122 63839 case AV_OPT_TYPE_PIXEL_FMT:
123 63839 *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
124 63839 break;
125 44749 case AV_OPT_TYPE_SAMPLE_FMT:
126 44749 *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
127 44749 break;
128 5515168 case AV_OPT_TYPE_BOOL:
129 case AV_OPT_TYPE_FLAGS:
130 case AV_OPT_TYPE_INT:
131 5515168 *(int *)dst = llrint(num / den) * intnum;
132 5515168 break;
133 467457 case AV_OPT_TYPE_DURATION:
134 #if FF_API_OLD_CHANNEL_LAYOUT
135 FF_DISABLE_DEPRECATION_WARNINGS
136 case AV_OPT_TYPE_CHANNEL_LAYOUT:
137 FF_ENABLE_DEPRECATION_WARNINGS
138 #endif
139 case AV_OPT_TYPE_INT64:{
140 467457 double d = num / den;
141
3/4
✓ Branch 0 taken 1143 times.
✓ Branch 1 taken 466314 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1143 times.
467457 if (intnum == 1 && d == (double)INT64_MAX) {
142 *(int64_t *)dst = INT64_MAX;
143 } else
144 467457 *(int64_t *)dst = llrint(d) * intnum;
145 467457 break;}
146 case AV_OPT_TYPE_UINT64:{
147 double d = num / den;
148 // We must special case uint64_t here as llrint() does not support values
149 // outside the int64_t range and there is no portable function which does
150 // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double
151 // while INT64_MAX is not
152 if (intnum == 1 && d == (double)UINT64_MAX) {
153 *(uint64_t *)dst = UINT64_MAX;
154 } else if (d > INT64_MAX + 1ULL) {
155 *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum;
156 } else {
157 *(uint64_t *)dst = llrint(d) * intnum;
158 }
159 break;}
160 711287 case AV_OPT_TYPE_FLOAT:
161 711287 *(float *)dst = num * intnum / den;
162 711287 break;
163 51060 case AV_OPT_TYPE_DOUBLE:
164 51060 *(double *)dst = num * intnum / den;
165 51060 break;
166 189984 case AV_OPT_TYPE_RATIONAL:
167 case AV_OPT_TYPE_VIDEO_RATE:
168
1/2
✓ Branch 0 taken 189984 times.
✗ Branch 1 not taken.
189984 if ((int) num == num)
169 189984 *(AVRational *)dst = (AVRational) { num *intnum, den };
170 else
171 *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
172 189984 break;
173 default:
174 return AVERROR(EINVAL);
175 }
176 7043544 return 0;
177 }
178
179 15038 static int hexchar2int(char c) {
180
3/4
✓ Branch 0 taken 15038 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10849 times.
✓ Branch 3 taken 4189 times.
15038 if (c >= '0' && c <= '9')
181 10849 return c - '0';
182
4/4
✓ Branch 0 taken 4187 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4186 times.
✓ Branch 3 taken 1 times.
4189 if (c >= 'a' && c <= 'f')
183 4186 return c - 'a' + 10;
184
3/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
3 if (c >= 'A' && c <= 'F')
185 2 return c - 'A' + 10;
186 1 return -1;
187 }
188
189 37427 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
190 {
191 37427 int *lendst = (int *)(dst + 1);
192 uint8_t *bin, *ptr;
193 int len;
194
195 37427 av_freep(dst);
196 37427 *lendst = 0;
197
198
4/4
✓ Branch 0 taken 489 times.
✓ Branch 1 taken 36938 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 479 times.
37427 if (!val || !(len = strlen(val)))
199 36948 return 0;
200
201
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 478 times.
479 if (len & 1)
202 1 return AVERROR(EINVAL);
203 478 len /= 2;
204
205 478 ptr = bin = av_malloc(len);
206
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if (!ptr)
207 return AVERROR(ENOMEM);
208
2/2
✓ Branch 0 taken 7519 times.
✓ Branch 1 taken 477 times.
7996 while (*val) {
209 7519 int a = hexchar2int(*val++);
210 7519 int b = hexchar2int(*val++);
211
3/4
✓ Branch 0 taken 7519 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7518 times.
7519 if (a < 0 || b < 0) {
212 1 av_free(bin);
213 1 return AVERROR(EINVAL);
214 }
215 7518 *ptr++ = (a << 4) | b;
216 }
217 477 *dst = bin;
218 477 *lendst = len;
219
220 477 return 0;
221 }
222
223 421768 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
224 {
225 421768 av_freep(dst);
226 421768 *dst = av_strdup(val);
227
2/2
✓ Branch 0 taken 72802 times.
✓ Branch 1 taken 348966 times.
421768 return *dst ? 0 : AVERROR(ENOMEM);
228 }
229
230 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
231 opt->type == AV_OPT_TYPE_UINT64 || \
232 opt->type == AV_OPT_TYPE_CONST || \
233 opt->type == AV_OPT_TYPE_FLAGS || \
234 opt->type == AV_OPT_TYPE_INT) \
235 ? opt->default_val.i64 \
236 : opt->default_val.dbl)
237
238 154853 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
239 {
240 154853 int ret = 0;
241
242
3/4
✓ Branch 0 taken 138014 times.
✓ Branch 1 taken 16839 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138014 times.
154853 if (o->type == AV_OPT_TYPE_RATIONAL || o->type == AV_OPT_TYPE_VIDEO_RATE) {
243 int num, den;
244 char c;
245
2/2
✓ Branch 0 taken 16830 times.
✓ Branch 1 taken 9 times.
16839 if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
246
2/2
✓ Branch 1 taken 16828 times.
✓ Branch 2 taken 2 times.
16830 if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
247 16828 return ret;
248 2 ret = 0;
249 }
250 }
251
252 37651 for (;;) {
253 175676 int i = 0;
254 char buf[256];
255 175676 int cmd = 0;
256 double d;
257 175676 int64_t intnum = 1;
258
259
2/2
✓ Branch 0 taken 109056 times.
✓ Branch 1 taken 66620 times.
175676 if (o->type == AV_OPT_TYPE_FLAGS) {
260
4/4
✓ Branch 0 taken 20119 times.
✓ Branch 1 taken 88937 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 20096 times.
109056 if (*val == '+' || *val == '-')
261 88960 cmd = *(val++);
262
7/8
✓ Branch 0 taken 982466 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 911061 times.
✓ Branch 3 taken 71405 times.
✓ Branch 4 taken 873411 times.
✓ Branch 5 taken 37650 times.
✓ Branch 6 taken 873410 times.
✓ Branch 7 taken 1 times.
982466 for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
263 873410 buf[i] = val[i];
264 109056 buf[i] = 0;
265 }
266
267 {
268 int res;
269 175676 int ci = 0;
270 double const_values[64];
271 const char * const_names[64];
272 175676 int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0;
273
2/2
✓ Branch 0 taken 109056 times.
✓ Branch 1 taken 66620 times.
175676 const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags);
274
3/4
✓ Branch 0 taken 123558 times.
✓ Branch 1 taken 52118 times.
✓ Branch 2 taken 123558 times.
✗ Branch 3 not taken.
175676 if (o_named && o_named->type == AV_OPT_TYPE_CONST) {
275
3/10
✓ Branch 0 taken 123558 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 123558 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 123558 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
123558 d = DEFAULT_NUMVAL(o_named);
276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 123558 times.
123558 if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
277 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n",
278 o_named->name, o_named->help);
279 } else {
280
2/2
✓ Branch 0 taken 39385 times.
✓ Branch 1 taken 12733 times.
52118 if (o->unit) {
281
2/2
✓ Branch 1 taken 6848698 times.
✓ Branch 2 taken 39385 times.
6888083 for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
282
2/2
✓ Branch 0 taken 4674403 times.
✓ Branch 1 taken 2174295 times.
6848698 if (o_named->type == AV_OPT_TYPE_CONST &&
283
1/2
✓ Branch 0 taken 4674403 times.
✗ Branch 1 not taken.
4674403 o_named->unit &&
284
2/2
✓ Branch 0 taken 372801 times.
✓ Branch 1 taken 4301602 times.
4674403 !strcmp(o_named->unit, o->unit)) {
285
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372801 times.
372801 if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
286 av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
287 6 return AVERROR_PATCHWELCOME;
288 }
289 372801 const_names [ci ] = o_named->name;
290
3/10
✓ Branch 0 taken 372801 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 372801 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 372801 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
372801 const_values[ci++] = DEFAULT_NUMVAL(o_named);
291 }
292 }
293 }
294 52118 const_names [ci ] = "default";
295
8/10
✓ Branch 0 taken 50978 times.
✓ Branch 1 taken 1140 times.
✓ Branch 2 taken 50978 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 50978 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 44243 times.
✓ Branch 7 taken 6735 times.
✓ Branch 8 taken 43849 times.
✓ Branch 9 taken 394 times.
52118 const_values[ci++] = DEFAULT_NUMVAL(o);
296 52118 const_names [ci ] = "max";
297 52118 const_values[ci++] = o->max;
298 52118 const_names [ci ] = "min";
299 52118 const_values[ci++] = o->min;
300 52118 const_names [ci ] = "none";
301 52118 const_values[ci++] = 0;
302 52118 const_names [ci ] = "all";
303 52118 const_values[ci++] = ~0;
304 52118 const_names [ci] = NULL;
305 52118 const_values[ci] = 0;
306
307
2/2
✓ Branch 0 taken 6735 times.
✓ Branch 1 taken 45383 times.
52118 res = av_expr_parse_and_eval(&d, i ? buf : val, const_names,
308 const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
309
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 52112 times.
52118 if (res < 0) {
310 6 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
311 6 return res;
312 }
313 }
314 }
315
2/2
✓ Branch 0 taken 109056 times.
✓ Branch 1 taken 66614 times.
175670 if (o->type == AV_OPT_TYPE_FLAGS) {
316 109056 read_number(o, dst, NULL, NULL, &intnum);
317
2/2
✓ Branch 0 taken 88937 times.
✓ Branch 1 taken 20119 times.
109056 if (cmd == '+')
318 88937 d = intnum | (int64_t)d;
319
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 20096 times.
20119 else if (cmd == '-')
320 23 d = intnum &~(int64_t)d;
321 }
322
323
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 175661 times.
175670 if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
324 9 return ret;
325 175661 val += i;
326
4/4
✓ Branch 0 taken 109056 times.
✓ Branch 1 taken 66605 times.
✓ Branch 2 taken 71405 times.
✓ Branch 3 taken 37651 times.
175661 if (!i || !*val)
327 138010 return 0;
328 }
329 }
330
331 37898 static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
332 {
333 int ret;
334
335
3/4
✓ Branch 0 taken 6096 times.
✓ Branch 1 taken 31802 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6096 times.
37898 if (!val || !strcmp(val, "none")) {
336 31802 dst[0] =
337 31802 dst[1] = 0;
338 31802 return 0;
339 }
340 6096 ret = av_parse_video_size(dst, dst + 1, val);
341
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6095 times.
6096 if (ret < 0)
342 1 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
343 6096 return ret;
344 }
345
346 4641 static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
347 {
348 4641 int ret = av_parse_video_rate(dst, val);
349
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4640 times.
4641 if (ret < 0)
350 1 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
351 4641 return ret;
352 }
353
354 333 static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
355 {
356 int ret;
357
358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
333 if (!val) {
359 return 0;
360 } else {
361 333 ret = av_parse_color(dst, val, -1, obj);
362
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 333 times.
333 if (ret < 0)
363 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val);
364 333 return ret;
365 }
366 return 0;
367 }
368
369 33 static const char *get_bool_name(int val)
370 {
371
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 28 times.
33 if (val < 0)
372 5 return "auto";
373
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
28 return val ? "true" : "false";
374 }
375
376 2814 static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
377 {
378 int n;
379
380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2814 times.
2814 if (!val)
381 return 0;
382
383
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2811 times.
2814 if (!strcmp(val, "auto")) {
384 3 n = -1;
385
2/2
✓ Branch 1 taken 1268 times.
✓ Branch 2 taken 1543 times.
2811 } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
386 1268 n = 1;
387
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1531 times.
1543 } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
388 12 n = 0;
389 } else {
390 1531 char *end = NULL;
391 1531 n = strtol(val, &end, 10);
392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1531 times.
1531 if (val + strlen(val) != end)
393 goto fail;
394 }
395
396
2/4
✓ Branch 0 taken 2814 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2814 times.
2814 if (n < o->min || n > o->max)
397 goto fail;
398
399 2814 *dst = n;
400 2814 return 0;
401
402 fail:
403 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val);
404 return AVERROR(EINVAL);
405 }
406
407 7712 static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
408 int fmt_nb, int ((*get_fmt)(const char *)), const char *desc)
409 {
410 int fmt, min, max;
411
412
2/4
✓ Branch 0 taken 7712 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7712 times.
7712 if (!val || !strcmp(val, "none")) {
413 fmt = -1;
414 } else {
415 7712 fmt = get_fmt(val);
416
2/2
✓ Branch 0 taken 5198 times.
✓ Branch 1 taken 2514 times.
7712 if (fmt == -1) {
417 char *tail;
418 5198 fmt = strtol(val, &tail, 0);
419
3/4
✓ Branch 0 taken 5196 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5196 times.
5198 if (*tail || (unsigned)fmt >= fmt_nb) {
420 2 av_log(obj, AV_LOG_ERROR,
421 "Unable to parse option value \"%s\" as %s\n", val, desc);
422 2 return AVERROR(EINVAL);
423 }
424 }
425 }
426
427
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7708 times.
7710 min = FFMAX(o->min, -1);
428
1/2
✓ Branch 0 taken 7710 times.
✗ Branch 1 not taken.
7710 max = FFMIN(o->max, fmt_nb-1);
429
430 // hack for compatibility with old ffmpeg
431
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7708 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
7710 if(min == 0 && max == 0) {
432 min = -1;
433 max = fmt_nb-1;
434 }
435
436
2/4
✓ Branch 0 taken 7710 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7710 times.
7710 if (fmt < min || fmt > max) {
437 av_log(obj, AV_LOG_ERROR,
438 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
439 fmt, o->name, desc, min, max);
440 return AVERROR(ERANGE);
441 }
442
443 7710 *(int *)dst = fmt;
444 7710 return 0;
445 }
446
447 5201 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
448 {
449 5201 return set_string_fmt(obj, o, val, dst,
450 AV_PIX_FMT_NB, av_get_pix_fmt, "pixel format");
451 }
452
453 2511 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
454 {
455 2511 return set_string_fmt(obj, o, val, dst,
456 AV_SAMPLE_FMT_NB, av_get_sample_fmt, "sample format");
457 }
458
459 160 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
460 {
461 160 AVDictionary *options = NULL;
462
463
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 134 times.
160 if (val) {
464 26 int ret = av_dict_parse_string(&options, val, "=", ":", 0);
465
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
26 if (ret < 0) {
466 av_dict_free(&options);
467 return ret;
468 }
469 }
470
471 160 av_dict_free((AVDictionary **)dst);
472 160 *dst = (uint8_t *)options;
473
474 160 return 0;
475 }
476
477 41404 static int set_string_channel_layout(void *obj, const AVOption *o,
478 const char *val, void *dst)
479 {
480 41404 AVChannelLayout *channel_layout = dst;
481 41404 av_channel_layout_uninit(channel_layout);
482
2/2
✓ Branch 0 taken 41254 times.
✓ Branch 1 taken 150 times.
41404 if (!val)
483 41254 return 0;
484 150 return av_channel_layout_from_string(channel_layout, val);
485 }
486
487 261420 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
488 {
489 261420 int ret = 0;
490 void *dst, *target_obj;
491 261420 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
492
3/4
✓ Branch 0 taken 201834 times.
✓ Branch 1 taken 59586 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 201834 times.
261420 if (!o || !target_obj)
493 59586 return AVERROR_OPTION_NOT_FOUND;
494 FF_DISABLE_DEPRECATION_WARNINGS
495
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 201834 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
201834 if (!val && (o->type != AV_OPT_TYPE_STRING &&
496 o->type != AV_OPT_TYPE_PIXEL_FMT && o->type != AV_OPT_TYPE_SAMPLE_FMT &&
497 o->type != AV_OPT_TYPE_IMAGE_SIZE &&
498 o->type != AV_OPT_TYPE_DURATION && o->type != AV_OPT_TYPE_COLOR &&
499 #if FF_API_OLD_CHANNEL_LAYOUT
500 o->type != AV_OPT_TYPE_CHANNEL_LAYOUT &&
501 #endif
502 o->type != AV_OPT_TYPE_BOOL))
503 return AVERROR(EINVAL);
504 FF_ENABLE_DEPRECATION_WARNINGS
505
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 201834 times.
201834 if (o->flags & AV_OPT_FLAG_READONLY)
507 return AVERROR(EINVAL);
508
509
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 201832 times.
201834 if (o->flags & AV_OPT_FLAG_DEPRECATED)
510 2 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
511
512 201834 dst = ((uint8_t *)target_obj) + o->offset;
513
12/14
✓ Branch 0 taken 2814 times.
✓ Branch 1 taken 44596 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 140293 times.
✓ Branch 4 taken 5793 times.
✓ Branch 5 taken 167 times.
✓ Branch 6 taken 5201 times.
✓ Branch 7 taken 2511 times.
✓ Branch 8 taken 247 times.
✓ Branch 9 taken 38 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 140 times.
✓ Branch 12 taken 20 times.
✗ Branch 13 not taken.
201834 switch (o->type) {
514 2814 case AV_OPT_TYPE_BOOL:
515 2814 return set_string_bool(obj, o, val, dst);
516 44596 case AV_OPT_TYPE_STRING:
517 44596 return set_string(obj, o, val, dst);
518 14 case AV_OPT_TYPE_BINARY:
519 14 return set_string_binary(obj, o, val, dst);
520 140293 case AV_OPT_TYPE_FLAGS:
521 case AV_OPT_TYPE_INT:
522 case AV_OPT_TYPE_INT64:
523 case AV_OPT_TYPE_UINT64:
524 case AV_OPT_TYPE_FLOAT:
525 case AV_OPT_TYPE_DOUBLE:
526 case AV_OPT_TYPE_RATIONAL:
527 140293 return set_string_number(obj, target_obj, o, val, dst);
528 5793 case AV_OPT_TYPE_IMAGE_SIZE:
529 5793 return set_string_image_size(obj, o, val, dst);
530 167 case AV_OPT_TYPE_VIDEO_RATE: {
531 AVRational tmp;
532 167 ret = set_string_video_rate(obj, o, val, &tmp);
533
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 166 times.
167 if (ret < 0)
534 1 return ret;
535 166 return write_number(obj, o, dst, 1, tmp.den, tmp.num);
536 }
537 5201 case AV_OPT_TYPE_PIXEL_FMT:
538 5201 return set_string_pixel_fmt(obj, o, val, dst);
539 2511 case AV_OPT_TYPE_SAMPLE_FMT:
540 2511 return set_string_sample_fmt(obj, o, val, dst);
541 247 case AV_OPT_TYPE_DURATION:
542 {
543 247 int64_t usecs = 0;
544
1/2
✓ Branch 0 taken 247 times.
✗ Branch 1 not taken.
247 if (val) {
545
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 246 times.
247 if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
546 1 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
547 1 return ret;
548 }
549 }
550
2/4
✓ Branch 0 taken 246 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 246 times.
246 if (usecs < o->min || usecs > o->max) {
551 av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
552 usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
553 return AVERROR(ERANGE);
554 }
555 246 *(int64_t *)dst = usecs;
556 246 return 0;
557 }
558 38 case AV_OPT_TYPE_COLOR:
559 38 return set_string_color(obj, o, val, dst);
560 #if FF_API_OLD_CHANNEL_LAYOUT
561 FF_DISABLE_DEPRECATION_WARNINGS
562 case AV_OPT_TYPE_CHANNEL_LAYOUT:
563 if (!val || !strcmp(val, "none")) {
564 *(int64_t *)dst = 0;
565 } else {
566 int64_t cl = av_get_channel_layout(val);
567 if (!cl) {
568 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
569 ret = AVERROR(EINVAL);
570 }
571 *(int64_t *)dst = cl;
572 return ret;
573 }
574 break;
575 FF_ENABLE_DEPRECATION_WARNINGS
576 #endif
577 140 case AV_OPT_TYPE_CHLAYOUT:
578 140 ret = set_string_channel_layout(obj, o, val, dst);
579
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 139 times.
140 if (ret < 0) {
580 1 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
581 1 ret = AVERROR(EINVAL);
582 }
583 140 return ret;
584 20 case AV_OPT_TYPE_DICT:
585 20 return set_string_dict(obj, o, val, dst);
586 }
587
588 av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
589 return AVERROR(EINVAL);
590 }
591
592 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
593 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
594 const char *val, vartype *name ## _out) \
595 { \
596 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
597 return AVERROR(EINVAL); \
598 return set_string_number(obj, obj, o, val, name ## _out); \
599 }
600
601
3/6
✓ Branch 0 taken 14552 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14552 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14552 times.
14552 OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int)
602
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 8 times.
8 OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int)
603 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
604 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
605 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
606 OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational)
607
608 86279 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
609 int search_flags)
610 {
611 void *dst, *target_obj;
612 86279 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
613
614
3/4
✓ Branch 0 taken 72091 times.
✓ Branch 1 taken 14188 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 72091 times.
86279 if (!o || !target_obj)
615 14188 return AVERROR_OPTION_NOT_FOUND;
616
617
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72091 times.
72091 if (o->flags & AV_OPT_FLAG_READONLY)
618 return AVERROR(EINVAL);
619
620 72091 dst = ((uint8_t *)target_obj) + o->offset;
621 72091 return write_number(obj, o, dst, num, den, intnum);
622 }
623
624 86279 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
625 {
626 86279 return set_number(obj, name, 1, 1, val, search_flags);
627 }
628
629 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
630 {
631 return set_number(obj, name, val, 1, 1, search_flags);
632 }
633
634 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
635 {
636 return set_number(obj, name, val.num, val.den, 1, search_flags);
637 }
638
639 24 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
640 {
641 void *target_obj;
642 24 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
643 uint8_t *ptr;
644 uint8_t **dst;
645 int *lendst;
646
647
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (!o || !target_obj)
648 return AVERROR_OPTION_NOT_FOUND;
649
650
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
651 return AVERROR(EINVAL);
652
653
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ptr = len ? av_malloc(len) : NULL;
654
2/4
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
24 if (len && !ptr)
655 return AVERROR(ENOMEM);
656
657 24 dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
658 24 lendst = (int *)(dst + 1);
659
660 24 av_free(*dst);
661 24 *dst = ptr;
662 24 *lendst = len;
663
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if (len)
664 24 memcpy(ptr, val, len);
665
666 24 return 0;
667 }
668
669 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
670 {
671 void *target_obj;
672 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
673
674 if (!o || !target_obj)
675 return AVERROR_OPTION_NOT_FOUND;
676 if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
677 av_log(obj, AV_LOG_ERROR,
678 "The value set by option '%s' is not an image size.\n", o->name);
679 return AVERROR(EINVAL);
680 }
681 if (w<0 || h<0) {
682 av_log(obj, AV_LOG_ERROR,
683 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
684 return AVERROR(EINVAL);
685 }
686 *(int *)(((uint8_t *)target_obj) + o->offset) = w;
687 *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
688 return 0;
689 }
690
691 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
692 {
693 void *target_obj;
694 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
695
696 if (!o || !target_obj)
697 return AVERROR_OPTION_NOT_FOUND;
698 if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
699 av_log(obj, AV_LOG_ERROR,
700 "The value set by option '%s' is not a video rate.\n", o->name);
701 return AVERROR(EINVAL);
702 }
703 if (val.num <= 0 || val.den <= 0)
704 return AVERROR(EINVAL);
705 return set_number(obj, name, val.num, val.den, 1, search_flags);
706 }
707
708 static int set_format(void *obj, const char *name, int fmt, int search_flags,
709 enum AVOptionType type, const char *desc, int nb_fmts)
710 {
711 void *target_obj;
712 const AVOption *o = av_opt_find2(obj, name, NULL, 0,
713 search_flags, &target_obj);
714 int min, max;
715
716 if (!o || !target_obj)
717 return AVERROR_OPTION_NOT_FOUND;
718 if (o->type != type) {
719 av_log(obj, AV_LOG_ERROR,
720 "The value set by option '%s' is not a %s format", name, desc);
721 return AVERROR(EINVAL);
722 }
723
724 min = FFMAX(o->min, -1);
725 max = FFMIN(o->max, nb_fmts-1);
726
727 if (fmt < min || fmt > max) {
728 av_log(obj, AV_LOG_ERROR,
729 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
730 fmt, name, desc, min, max);
731 return AVERROR(ERANGE);
732 }
733 *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
734 return 0;
735 }
736
737 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
738 {
739 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
740 }
741
742 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
743 {
744 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
745 }
746
747 #if FF_API_OLD_CHANNEL_LAYOUT
748 FF_DISABLE_DEPRECATION_WARNINGS
749 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
750 {
751 void *target_obj;
752 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
753
754 if (!o || !target_obj)
755 return AVERROR_OPTION_NOT_FOUND;
756 if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
757 av_log(obj, AV_LOG_ERROR,
758 "The value set by option '%s' is not a channel layout.\n", o->name);
759 return AVERROR(EINVAL);
760 }
761 *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
762 return 0;
763 }
764 FF_ENABLE_DEPRECATION_WARNINGS
765 #endif
766
767 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
768 int search_flags)
769 {
770 void *target_obj;
771 AVDictionary **dst;
772 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
773
774 if (!o || !target_obj)
775 return AVERROR_OPTION_NOT_FOUND;
776 if (o->flags & AV_OPT_FLAG_READONLY)
777 return AVERROR(EINVAL);
778
779 dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
780 av_dict_free(dst);
781 av_dict_copy(dst, val, 0);
782
783 return 0;
784 }
785
786 2762 int av_opt_set_chlayout(void *obj, const char *name,
787 const AVChannelLayout *channel_layout,
788 int search_flags)
789 {
790 void *target_obj;
791 2762 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
792 AVChannelLayout *dst;
793
794
2/4
✓ Branch 0 taken 2762 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2762 times.
2762 if (!o || !target_obj)
795 return AVERROR_OPTION_NOT_FOUND;
796
797 2762 dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
798
799 2762 return av_channel_layout_copy(dst, channel_layout);
800 }
801
802 5 static void format_duration(char *buf, size_t size, int64_t d)
803 {
804 char *e;
805
806
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 av_assert0(size >= 25);
807
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
5 if (d < 0 && d != INT64_MIN) {
808 *(buf++) = '-';
809 size--;
810 d = -d;
811 }
812
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (d == INT64_MAX)
813 snprintf(buf, size, "INT64_MAX");
814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 else if (d == INT64_MIN)
815 snprintf(buf, size, "INT64_MIN");
816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 else if (d > (int64_t)3600*1000000)
817 snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
818 (int)((d / 60000000) % 60),
819 (int)((d / 1000000) % 60),
820 (int)(d % 1000000));
821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 else if (d > 60*1000000)
822 snprintf(buf, size, "%d:%02d.%06d",
823 (int)(d / 60000000),
824 (int)((d / 1000000) % 60),
825 (int)(d % 1000000));
826 else
827 5 snprintf(buf, size, "%d.%06d",
828 5 (int)(d / 1000000),
829 5 (int)(d % 1000000));
830 5 e = buf + strlen(buf);
831
3/4
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 5 times.
20 while (e > buf && e[-1] == '0')
832 15 *(--e) = 0;
833
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
5 if (e > buf && e[-1] == '.')
834 *(--e) = 0;
835 5 }
836
837 8127 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
838 {
839 void *dst, *target_obj;
840 8127 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
841 uint8_t *bin, buf[128];
842 int len, i, ret;
843 int64_t i64;
844
845
4/8
✓ Branch 0 taken 3964 times.
✓ Branch 1 taken 4163 times.
✓ Branch 2 taken 3964 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3964 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8127 if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
846 4163 return AVERROR_OPTION_NOT_FOUND;
847
848
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3964 times.
3964 if (o->flags & AV_OPT_FLAG_DEPRECATED)
849 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
850
851 3964 dst = (uint8_t *)target_obj + o->offset;
852
853 3964 buf[0] = 0;
854
16/20
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3799 times.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 16 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 8 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 8 times.
✓ Branch 10 taken 12 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4 times.
✓ Branch 18 taken 8 times.
✗ Branch 19 not taken.
3964 switch (o->type) {
855 30 case AV_OPT_TYPE_BOOL:
856 30 ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
857 30 break;
858 3799 case AV_OPT_TYPE_FLAGS:
859 3799 ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
860 3799 break;
861 51 case AV_OPT_TYPE_INT:
862 51 ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
863 51 break;
864 16 case AV_OPT_TYPE_INT64:
865 16 ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
866 16 break;
867 case AV_OPT_TYPE_UINT64:
868 ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
869 break;
870 4 case AV_OPT_TYPE_FLOAT:
871 4 ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
872 4 break;
873 4 case AV_OPT_TYPE_DOUBLE:
874 4 ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
875 4 break;
876 8 case AV_OPT_TYPE_VIDEO_RATE:
877 case AV_OPT_TYPE_RATIONAL:
878 8 ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
879 8 break;
880 case AV_OPT_TYPE_CONST:
881 ret = snprintf(buf, sizeof(buf), "%"PRId64, o->default_val.i64);
882 break;
883 8 case AV_OPT_TYPE_STRING:
884
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (*(uint8_t **)dst) {
885 8 *out_val = av_strdup(*(uint8_t **)dst);
886 } else if (search_flags & AV_OPT_ALLOW_NULL) {
887 *out_val = NULL;
888 return 0;
889 } else {
890 *out_val = av_strdup("");
891 }
892
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 return *out_val ? 0 : AVERROR(ENOMEM);
893 12 case AV_OPT_TYPE_BINARY:
894
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
12 if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
895 *out_val = NULL;
896 return 0;
897 }
898 12 len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if ((uint64_t)len * 2 + 1 > INT_MAX)
900 return AVERROR(EINVAL);
901
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (!(*out_val = av_malloc(len * 2 + 1)))
902 return AVERROR(ENOMEM);
903
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if (!len) {
904 8 *out_val[0] = '\0';
905 8 return 0;
906 }
907 4 bin = *(uint8_t **)dst;
908
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for (i = 0; i < len; i++)
909 16 snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
910 4 return 0;
911 4 case AV_OPT_TYPE_IMAGE_SIZE:
912 4 ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
913 4 break;
914 4 case AV_OPT_TYPE_PIXEL_FMT:
915 4 ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
916 4 break;
917 4 case AV_OPT_TYPE_SAMPLE_FMT:
918 4 ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
919 4 break;
920 4 case AV_OPT_TYPE_DURATION:
921 4 i64 = *(int64_t *)dst;
922 4 format_duration(buf, sizeof(buf), i64);
923 4 ret = strlen(buf); // no overflow possible, checked by an assert
924 4 break;
925 4 case AV_OPT_TYPE_COLOR:
926 4 ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
927 4 (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
928 4 (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
929 4 break;
930 #if FF_API_OLD_CHANNEL_LAYOUT
931 FF_DISABLE_DEPRECATION_WARNINGS
932 case AV_OPT_TYPE_CHANNEL_LAYOUT:
933
934 i64 = *(int64_t *)dst;
935 ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
936 break;
937 FF_ENABLE_DEPRECATION_WARNINGS
938 #endif
939 4 case AV_OPT_TYPE_CHLAYOUT:
940 4 ret = av_channel_layout_describe(dst, buf, sizeof(buf));
941 4 break;
942 8 case AV_OPT_TYPE_DICT:
943
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
8 if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
944 *out_val = NULL;
945 return 0;
946 }
947 8 return av_dict_get_string(*(AVDictionary **)dst, (char **)out_val, '=', ':');
948 default:
949 return AVERROR(EINVAL);
950 }
951
952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3936 times.
3936 if (ret >= sizeof(buf))
953 return AVERROR(EINVAL);
954 3936 *out_val = av_strdup(buf);
955
1/2
✓ Branch 0 taken 3936 times.
✗ Branch 1 not taken.
3936 return *out_val ? 0 : AVERROR(ENOMEM);
956 }
957
958 18440 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
959 int search_flags)
960 {
961 void *dst, *target_obj;
962 18440 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
963
3/4
✓ Branch 0 taken 18426 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18426 times.
18440 if (!o || !target_obj)
964 14 goto error;
965
966 18426 dst = ((uint8_t *)target_obj) + o->offset;
967
968
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18426 times.
18426 if (o_out) *o_out= o;
969
970 18426 return read_number(o, dst, num, den, intnum);
971
972 14 error:
973 14 *den =
974 14 *intnum = 0;
975 14 return -1;
976 }
977
978 18440 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
979 {
980 18440 int64_t intnum = 1;
981 18440 double num = 1;
982 18440 int ret, den = 1;
983
984
2/2
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 18426 times.
18440 if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
985 14 return ret;
986
1/2
✓ Branch 0 taken 18426 times.
✗ Branch 1 not taken.
18426 if (num == den)
987 18426 *out_val = intnum;
988 else
989 *out_val = num * intnum / den;
990 18426 return 0;
991 }
992
993 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
994 {
995 int64_t intnum = 1;
996 double num = 1;
997 int ret, den = 1;
998
999 if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1000 return ret;
1001 *out_val = num * intnum / den;
1002 return 0;
1003 }
1004
1005 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1006 {
1007 int64_t intnum = 1;
1008 double num = 1;
1009 int ret, den = 1;
1010
1011 if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1012 return ret;
1013
1014 if (num == 1.0 && (int)intnum == intnum)
1015 *out_val = (AVRational){intnum, den};
1016 else
1017 *out_val = av_d2q(num*intnum/den, 1<<24);
1018 return 0;
1019 }
1020
1021 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1022 {
1023 void *dst, *target_obj;
1024 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1025 if (!o || !target_obj)
1026 return AVERROR_OPTION_NOT_FOUND;
1027 if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1028 av_log(obj, AV_LOG_ERROR,
1029 "The value for option '%s' is not an image size.\n", name);
1030 return AVERROR(EINVAL);
1031 }
1032
1033 dst = ((uint8_t*)target_obj) + o->offset;
1034 if (w_out) *w_out = *(int *)dst;
1035 if (h_out) *h_out = *((int *)dst+1);
1036 return 0;
1037 }
1038
1039 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1040 {
1041 int64_t intnum = 1;
1042 double num = 1;
1043 int ret, den = 1;
1044
1045 if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1046 return ret;
1047
1048 if (num == 1.0 && (int)intnum == intnum)
1049 *out_val = (AVRational) { intnum, den };
1050 else
1051 *out_val = av_d2q(num * intnum / den, 1 << 24);
1052 return 0;
1053 }
1054
1055 2564 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
1056 enum AVOptionType type, const char *desc)
1057 {
1058 void *dst, *target_obj;
1059 2564 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1060
2/4
✓ Branch 0 taken 2564 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2564 times.
2564 if (!o || !target_obj)
1061 return AVERROR_OPTION_NOT_FOUND;
1062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2564 times.
2564 if (o->type != type) {
1063 av_log(obj, AV_LOG_ERROR,
1064 "The value for option '%s' is not a %s format.\n", desc, name);
1065 return AVERROR(EINVAL);
1066 }
1067
1068 2564 dst = ((uint8_t*)target_obj) + o->offset;
1069 2564 *out_fmt = *(int *)dst;
1070 2564 return 0;
1071 }
1072
1073 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1074 {
1075 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1076 }
1077
1078 2564 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1079 {
1080 2564 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1081 }
1082
1083 #if FF_API_OLD_CHANNEL_LAYOUT
1084 FF_DISABLE_DEPRECATION_WARNINGS
1085 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
1086 {
1087 void *dst, *target_obj;
1088 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1089 if (!o || !target_obj)
1090 return AVERROR_OPTION_NOT_FOUND;
1091 if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
1092 av_log(obj, AV_LOG_ERROR,
1093 "The value for option '%s' is not a channel layout.\n", name);
1094 return AVERROR(EINVAL);
1095 }
1096
1097 dst = ((uint8_t*)target_obj) + o->offset;
1098 *cl = *(int64_t *)dst;
1099 return 0;
1100 }
1101 FF_ENABLE_DEPRECATION_WARNINGS
1102 #endif
1103
1104 2564 int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1105 {
1106 void *dst, *target_obj;
1107 2564 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1108
2/4
✓ Branch 0 taken 2564 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2564 times.
2564 if (!o || !target_obj)
1109 return AVERROR_OPTION_NOT_FOUND;
1110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2564 times.
2564 if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1111 av_log(obj, AV_LOG_ERROR,
1112 "The value for option '%s' is not a channel layout.\n", name);
1113 return AVERROR(EINVAL);
1114 }
1115
1116 2564 dst = ((uint8_t*)target_obj) + o->offset;
1117 2564 return av_channel_layout_copy(cl, dst);
1118 }
1119
1120 7128 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1121 {
1122 void *target_obj;
1123 AVDictionary *src;
1124 7128 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1125
1126
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 7128 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
7128 if (!o || !target_obj)
1127 7128 return AVERROR_OPTION_NOT_FOUND;
1128 if (o->type != AV_OPT_TYPE_DICT)
1129 return AVERROR(EINVAL);
1130
1131 src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1132 av_dict_copy(out_val, src, 0);
1133
1134 return 0;
1135 }
1136
1137 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1138 {
1139 const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1140 const AVOption *flag = av_opt_find(obj, flag_name,
1141 field ? field->unit : NULL, 0, 0);
1142 int64_t res;
1143
1144 if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1145 av_opt_get_int(obj, field_name, 0, &res) < 0)
1146 return 0;
1147 return res & flag->default_val.i64;
1148 }
1149
1150 3 static void log_int_value(void *av_log_obj, int level, int64_t i)
1151 {
1152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (i == INT_MAX) {
1153 av_log(av_log_obj, level, "INT_MAX");
1154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if (i == INT_MIN) {
1155 av_log(av_log_obj, level, "INT_MIN");
1156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if (i == UINT32_MAX) {
1157 av_log(av_log_obj, level, "UINT32_MAX");
1158
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if (i == INT64_MAX) {
1159 av_log(av_log_obj, level, "I64_MAX");
1160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 } else if (i == INT64_MIN) {
1161 av_log(av_log_obj, level, "I64_MIN");
1162 } else {
1163 3 av_log(av_log_obj, level, "%"PRId64, i);
1164 }
1165 3 }
1166
1167 14 static void log_value(void *av_log_obj, int level, double d)
1168 {
1169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (d == INT_MAX) {
1170 av_log(av_log_obj, level, "INT_MAX");
1171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == INT_MIN) {
1172 av_log(av_log_obj, level, "INT_MIN");
1173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == UINT32_MAX) {
1174 av_log(av_log_obj, level, "UINT32_MAX");
1175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == (double)INT64_MAX) {
1176 av_log(av_log_obj, level, "I64_MAX");
1177
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == INT64_MIN) {
1178 av_log(av_log_obj, level, "I64_MIN");
1179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == FLT_MAX) {
1180 av_log(av_log_obj, level, "FLT_MAX");
1181
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == FLT_MIN) {
1182 av_log(av_log_obj, level, "FLT_MIN");
1183
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == -FLT_MAX) {
1184 av_log(av_log_obj, level, "-FLT_MAX");
1185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == -FLT_MIN) {
1186 av_log(av_log_obj, level, "-FLT_MIN");
1187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == DBL_MAX) {
1188 av_log(av_log_obj, level, "DBL_MAX");
1189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == DBL_MIN) {
1190 av_log(av_log_obj, level, "DBL_MIN");
1191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == -DBL_MAX) {
1192 av_log(av_log_obj, level, "-DBL_MAX");
1193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 } else if (d == -DBL_MIN) {
1194 av_log(av_log_obj, level, "-DBL_MIN");
1195 } else {
1196 14 av_log(av_log_obj, level, "%g", d);
1197 }
1198 14 }
1199
1200 3 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1201 {
1202 3 const AVOption *opt = NULL;
1203
1204
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (!unit)
1205 3 return NULL;
1206 while ((opt = av_opt_next(obj, opt)))
1207 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1208 opt->default_val.i64 == value)
1209 return opt->name;
1210 return NULL;
1211 }
1212
1213 1 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1214 {
1215 1 const AVOption *opt = NULL;
1216 char flags[512];
1217
1218 1 flags[0] = 0;
1219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!unit)
1220 return NULL;
1221
2/2
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1 times.
28 while ((opt = av_opt_next(obj, opt))) {
1222
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
27 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1223
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 opt->default_val.i64 & value) {
1224
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (flags[0])
1225 av_strlcatf(flags, sizeof(flags), "+");
1226 1 av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1227 }
1228 }
1229
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (flags[0])
1230 1 return av_strdup(flags);
1231 return NULL;
1232 }
1233
1234 2 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1235 int req_flags, int rej_flags, enum AVOptionType parent_type)
1236 {
1237 2 const AVOption *opt = NULL;
1238 AVOptionRanges *r;
1239 int i;
1240
1241
2/2
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
56 while ((opt = av_opt_next(obj, opt))) {
1242
2/4
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 54 times.
54 if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1243 continue;
1244
1245 /* Don't print CONST's on level one.
1246 * Don't print anything but CONST's on level two.
1247 * Only print items from the requested unit.
1248 */
1249
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 24 times.
54 if (!unit && opt->type == AV_OPT_TYPE_CONST)
1250 3 continue;
1251
4/4
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 3 times.
51 else if (unit && opt->type != AV_OPT_TYPE_CONST)
1252 24 continue;
1253
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
27 else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1254 continue;
1255
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
27 else if (unit && opt->type == AV_OPT_TYPE_CONST)
1256 3 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1257 else
1258 24 av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1259 24 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
24 opt->name);
1261
1262
18/20
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 3 times.
✓ Branch 18 taken 3 times.
✗ Branch 19 not taken.
27 switch (opt->type) {
1263 1 case AV_OPT_TYPE_FLAGS:
1264 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
1265 1 break;
1266 2 case AV_OPT_TYPE_INT:
1267 2 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
1268 2 break;
1269 1 case AV_OPT_TYPE_INT64:
1270 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
1271 1 break;
1272 case AV_OPT_TYPE_UINT64:
1273 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<uint64>");
1274 break;
1275 1 case AV_OPT_TYPE_DOUBLE:
1276 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
1277 1 break;
1278 1 case AV_OPT_TYPE_FLOAT:
1279 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
1280 1 break;
1281 2 case AV_OPT_TYPE_STRING:
1282 2 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
1283 2 break;
1284 1 case AV_OPT_TYPE_RATIONAL:
1285 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
1286 1 break;
1287 3 case AV_OPT_TYPE_BINARY:
1288 3 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
1289 3 break;
1290 2 case AV_OPT_TYPE_DICT:
1291 2 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<dictionary>");
1292 2 break;
1293 1 case AV_OPT_TYPE_IMAGE_SIZE:
1294 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
1295 1 break;
1296 1 case AV_OPT_TYPE_VIDEO_RATE:
1297 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
1298 1 break;
1299 1 case AV_OPT_TYPE_PIXEL_FMT:
1300 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
1301 1 break;
1302 1 case AV_OPT_TYPE_SAMPLE_FMT:
1303 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
1304 1 break;
1305 1 case AV_OPT_TYPE_DURATION:
1306 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
1307 1 break;
1308 1 case AV_OPT_TYPE_COLOR:
1309 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
1310 1 break;
1311 1 case AV_OPT_TYPE_CHLAYOUT:
1312 #if FF_API_OLD_CHANNEL_LAYOUT
1313 FF_DISABLE_DEPRECATION_WARNINGS
1314 case AV_OPT_TYPE_CHANNEL_LAYOUT:
1315 FF_ENABLE_DEPRECATION_WARNINGS
1316 #endif
1317 1 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
1318 1 break;
1319 3 case AV_OPT_TYPE_BOOL:
1320 3 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
1321 3 break;
1322 3 case AV_OPT_TYPE_CONST:
1323
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (parent_type == AV_OPT_TYPE_INT)
1324 av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", opt->default_val.i64);
1325 else
1326 3 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1327 3 break;
1328 default:
1329 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1330 break;
1331 }
1332 297 av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1333
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1334
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1335
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1337
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1338
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1340
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1342
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
27 (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1344
1345
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (opt->help)
1346 27 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1347
1348
2/2
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 10 times.
27 if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1349
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 11 times.
17 switch (opt->type) {
1350 6 case AV_OPT_TYPE_INT:
1351 case AV_OPT_TYPE_INT64:
1352 case AV_OPT_TYPE_UINT64:
1353 case AV_OPT_TYPE_DOUBLE:
1354 case AV_OPT_TYPE_FLOAT:
1355 case AV_OPT_TYPE_RATIONAL:
1356
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for (i = 0; i < r->nb_ranges; i++) {
1357 6 av_log(av_log_obj, AV_LOG_INFO, " (from ");
1358 6 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1359 6 av_log(av_log_obj, AV_LOG_INFO, " to ");
1360 6 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1361 6 av_log(av_log_obj, AV_LOG_INFO, ")");
1362 }
1363 6 break;
1364 }
1365 17 av_opt_freep_ranges(&r);
1366 }
1367
1368
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 3 times.
27 if (opt->type != AV_OPT_TYPE_CONST &&
1369
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 opt->type != AV_OPT_TYPE_BINARY &&
1370
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 times.
21 !((opt->type == AV_OPT_TYPE_COLOR ||
1371
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
20 opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1372
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 2 times.
19 opt->type == AV_OPT_TYPE_STRING ||
1373
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 2 times.
17 opt->type == AV_OPT_TYPE_DICT ||
1374
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
15 opt->type == AV_OPT_TYPE_CHLAYOUT ||
1375
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1376
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 !opt->default_val.str)) {
1377 20 av_log(av_log_obj, AV_LOG_INFO, " (default ");
1378
9/11
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
20 switch (opt->type) {
1379 3 case AV_OPT_TYPE_BOOL:
1380 3 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
1381 3 break;
1382 1 case AV_OPT_TYPE_FLAGS: {
1383 1 char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1384
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (def_flags) {
1385 1 av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1386 1 av_freep(&def_flags);
1387 } else {
1388 av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1389 }
1390 1 break;
1391 }
1392 1 case AV_OPT_TYPE_DURATION: {
1393 char buf[25];
1394 1 format_duration(buf, sizeof(buf), opt->default_val.i64);
1395 1 av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1396 1 break;
1397 }
1398 3 case AV_OPT_TYPE_INT:
1399 case AV_OPT_TYPE_UINT64:
1400 case AV_OPT_TYPE_INT64: {
1401 3 const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (def_const)
1403 av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1404 else
1405 3 log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1406 3 break;
1407 }
1408 2 case AV_OPT_TYPE_DOUBLE:
1409 case AV_OPT_TYPE_FLOAT:
1410 2 log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1411 2 break;
1412 1 case AV_OPT_TYPE_RATIONAL: {
1413 1 AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1414 1 av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1415 1 break;
1416 1 case AV_OPT_TYPE_PIXEL_FMT:
1417 1 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1418 1 break;
1419 1 case AV_OPT_TYPE_SAMPLE_FMT:
1420 1 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1421 1 break;
1422 7 case AV_OPT_TYPE_COLOR:
1423 case AV_OPT_TYPE_IMAGE_SIZE:
1424 case AV_OPT_TYPE_STRING:
1425 case AV_OPT_TYPE_DICT:
1426 case AV_OPT_TYPE_VIDEO_RATE:
1427 case AV_OPT_TYPE_CHLAYOUT:
1428 7 av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1429 7 break;
1430 #if FF_API_OLD_CHANNEL_LAYOUT
1431 FF_DISABLE_DEPRECATION_WARNINGS
1432 case AV_OPT_TYPE_CHANNEL_LAYOUT:
1433 av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
1434 break;
1435 FF_ENABLE_DEPRECATION_WARNINGS
1436 #endif
1437 }
1438 20 av_log(av_log_obj, AV_LOG_INFO, ")");
1439 }
1440
1441 27 av_log(av_log_obj, AV_LOG_INFO, "\n");
1442
4/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 23 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
27 if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1443 1 opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1444 }
1445 2 }
1446
1447 1 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1448 {
1449
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!obj)
1450 return -1;
1451
1452 1 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1453
1454 1 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1455
1456 1 return 0;
1457 }
1458
1459 288556 void av_opt_set_defaults(void *s)
1460 {
1461 288556 av_opt_set_defaults2(s, 0, 0);
1462 288556 }
1463
1464 345201 void av_opt_set_defaults2(void *s, int mask, int flags)
1465 {
1466 345201 const AVOption *opt = NULL;
1467
2/2
✓ Branch 1 taken 22728146 times.
✓ Branch 2 taken 345201 times.
23073347 while ((opt = av_opt_next(s, opt))) {
1468 22728146 void *dst = ((uint8_t*)s) + opt->offset;
1469
1470
2/2
✓ Branch 0 taken 2717748 times.
✓ Branch 1 taken 20010398 times.
22728146 if ((opt->flags & mask) != flags)
1471 2717748 continue;
1472
1473
2/2
✓ Branch 0 taken 631 times.
✓ Branch 1 taken 20009767 times.
20010398 if (opt->flags & AV_OPT_FLAG_READONLY)
1474 631 continue;
1475
1476
11/12
✓ Branch 0 taken 12738107 times.
✓ Branch 1 taken 5843847 times.
✓ Branch 2 taken 761970 times.
✓ Branch 3 taken 172981 times.
✓ Branch 4 taken 295 times.
✓ Branch 5 taken 377172 times.
✓ Branch 6 taken 32105 times.
✓ Branch 7 taken 4474 times.
✓ Branch 8 taken 37412 times.
✓ Branch 9 taken 41264 times.
✓ Branch 10 taken 140 times.
✗ Branch 11 not taken.
20009767 switch (opt->type) {
1477 12738107 case AV_OPT_TYPE_CONST:
1478 /* Nothing to be done here */
1479 12738107 break;
1480 5843847 case AV_OPT_TYPE_BOOL:
1481 case AV_OPT_TYPE_FLAGS:
1482 case AV_OPT_TYPE_INT:
1483 case AV_OPT_TYPE_INT64:
1484 case AV_OPT_TYPE_UINT64:
1485 case AV_OPT_TYPE_DURATION:
1486 #if FF_API_OLD_CHANNEL_LAYOUT
1487 FF_DISABLE_DEPRECATION_WARNINGS
1488 case AV_OPT_TYPE_CHANNEL_LAYOUT:
1489 FF_ENABLE_DEPRECATION_WARNINGS
1490 #endif
1491 case AV_OPT_TYPE_PIXEL_FMT:
1492 case AV_OPT_TYPE_SAMPLE_FMT:
1493 5843847 write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1494 5843847 break;
1495 761970 case AV_OPT_TYPE_DOUBLE:
1496 case AV_OPT_TYPE_FLOAT: {
1497 double val;
1498 761970 val = opt->default_val.dbl;
1499 761970 write_number(s, opt, dst, val, 1, 1);
1500 }
1501 761970 break;
1502 172981 case AV_OPT_TYPE_RATIONAL: {
1503 AVRational val;
1504 172981 val = av_d2q(opt->default_val.dbl, INT_MAX);
1505 172981 write_number(s, opt, dst, 1, val.den, val.num);
1506 }
1507 172981 break;
1508 295 case AV_OPT_TYPE_COLOR:
1509 295 set_string_color(s, opt, opt->default_val.str, dst);
1510 295 break;
1511 377172 case AV_OPT_TYPE_STRING:
1512 377172 set_string(s, opt, opt->default_val.str, dst);
1513 377172 break;
1514 32105 case AV_OPT_TYPE_IMAGE_SIZE:
1515 32105 set_string_image_size(s, opt, opt->default_val.str, dst);
1516 32105 break;
1517 4474 case AV_OPT_TYPE_VIDEO_RATE:
1518 4474 set_string_video_rate(s, opt, opt->default_val.str, dst);
1519 4474 break;
1520 37412 case AV_OPT_TYPE_BINARY:
1521 37412 set_string_binary(s, opt, opt->default_val.str, dst);
1522 37412 break;
1523 41264 case AV_OPT_TYPE_CHLAYOUT:
1524 41264 set_string_channel_layout(s, opt, opt->default_val.str, dst);
1525 41264 break;
1526 140 case AV_OPT_TYPE_DICT:
1527 140 set_string_dict(s, opt, opt->default_val.str, dst);
1528 140 break;
1529 default:
1530 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1531 opt->type, opt->name);
1532 }
1533 }
1534 345201 }
1535
1536 /**
1537 * Store the value in the field in ctx that is named like key.
1538 * ctx must be an AVClass context, storing is done using AVOptions.
1539 *
1540 * @param buf the string to parse, buf will be updated to point at the
1541 * separator just after the parsed key/value pair
1542 * @param key_val_sep a 0-terminated list of characters used to
1543 * separate key from value
1544 * @param pairs_sep a 0-terminated list of characters used to separate
1545 * two pairs from each other
1546 * @return 0 if the key/value pair has been successfully parsed and
1547 * set, or a negative value corresponding to an AVERROR code in case
1548 * of error:
1549 * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1550 * the error code issued by av_opt_set() if the key/value pair
1551 * cannot be set
1552 */
1553 2785 static int parse_key_value_pair(void *ctx, const char **buf,
1554 const char *key_val_sep, const char *pairs_sep)
1555 {
1556 2785 char *key = av_get_token(buf, key_val_sep);
1557 char *val;
1558 int ret;
1559
1560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2785 times.
2785 if (!key)
1561 return AVERROR(ENOMEM);
1562
1563
4/4
✓ Branch 0 taken 2783 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2780 times.
✓ Branch 3 taken 3 times.
2785 if (*key && strspn(*buf, key_val_sep)) {
1564 2780 (*buf)++;
1565 2780 val = av_get_token(buf, pairs_sep);
1566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2780 times.
2780 if (!val) {
1567 av_freep(&key);
1568 return AVERROR(ENOMEM);
1569 }
1570 } else {
1571 5 av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1572 5 av_free(key);
1573 5 return AVERROR(EINVAL);
1574 }
1575
1576 2780 av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1577
1578 2780 ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN);
1579
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2775 times.
2780 if (ret == AVERROR_OPTION_NOT_FOUND)
1580 5 av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1581
1582 2780 av_free(key);
1583 2780 av_free(val);
1584 2780 return ret;
1585 }
1586
1587 2757 int av_set_options_string(void *ctx, const char *opts,
1588 const char *key_val_sep, const char *pairs_sep)
1589 {
1590 2757 int ret, count = 0;
1591
1592
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2757 times.
2757 if (!opts)
1593 return 0;
1594
1595
2/2
✓ Branch 0 taken 2785 times.
✓ Branch 1 taken 2725 times.
5510 while (*opts) {
1596
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 2753 times.
2785 if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1597 32 return ret;
1598 2753 count++;
1599
1600
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 2723 times.
2753 if (*opts)
1601 30 opts++;
1602 }
1603
1604 2725 return count;
1605 }
1606
1607 #define WHITESPACES " \n\t\r"
1608
1609 658408 static int is_key_char(char c)
1610 {
1611 812496 return (unsigned)((c | 32) - 'a') < 26 ||
1612
4/4
✓ Branch 0 taken 109035 times.
✓ Branch 1 taken 45053 times.
✓ Branch 2 taken 108961 times.
✓ Branch 3 taken 74 times.
154088 (unsigned)(c - '0') < 10 ||
1613
8/8
✓ Branch 0 taken 154088 times.
✓ Branch 1 taken 504320 times.
✓ Branch 2 taken 68421 times.
✓ Branch 3 taken 40540 times.
✓ Branch 4 taken 68298 times.
✓ Branch 5 taken 123 times.
✓ Branch 6 taken 77 times.
✓ Branch 7 taken 68221 times.
812496 c == '-' || c == '_' || c == '/' || c == '.';
1614 }
1615
1616 /**
1617 * Read a key from a string.
1618 *
1619 * The key consists of is_key_char characters and must be terminated by a
1620 * character from the delim string; spaces are ignored.
1621 *
1622 * @return 0 for success (even with ellipsis), <0 for failure
1623 */
1624 68221 static int get_key(const char **ropts, const char *delim, char **rkey)
1625 {
1626 68221 const char *opts = *ropts;
1627 const char *key_start, *key_end;
1628
1629 68221 key_start = opts += strspn(opts, WHITESPACES);
1630
2/2
✓ Branch 1 taken 590187 times.
✓ Branch 2 taken 68221 times.
658408 while (is_key_char(*opts))
1631 590187 opts++;
1632 68221 key_end = opts;
1633 68221 opts += strspn(opts, WHITESPACES);
1634
4/4
✓ Branch 0 taken 56086 times.
✓ Branch 1 taken 12135 times.
✓ Branch 2 taken 5024 times.
✓ Branch 3 taken 51062 times.
68221 if (!*opts || !strchr(delim, *opts))
1635 17159 return AVERROR(EINVAL);
1636 51062 opts++;
1637
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 51062 times.
51062 if (!(*rkey = av_malloc(key_end - key_start + 1)))
1638 return AVERROR(ENOMEM);
1639 51062 memcpy(*rkey, key_start, key_end - key_start);
1640 51062 (*rkey)[key_end - key_start] = 0;
1641 51062 *ropts = opts;
1642 51062 return 0;
1643 }
1644
1645 68221 int av_opt_get_key_value(const char **ropts,
1646 const char *key_val_sep, const char *pairs_sep,
1647 unsigned flags,
1648 char **rkey, char **rval)
1649 {
1650 int ret;
1651 68221 char *key = NULL, *val;
1652 68221 const char *opts = *ropts;
1653
1654
2/2
✓ Branch 1 taken 17159 times.
✓ Branch 2 taken 51062 times.
68221 if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1655
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17158 times.
17159 !(flags & AV_OPT_FLAG_IMPLICIT_KEY))
1656 1 return AVERROR(EINVAL);
1657
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 68220 times.
68220 if (!(val = av_get_token(&opts, pairs_sep))) {
1658 av_free(key);
1659 return AVERROR(ENOMEM);
1660 }
1661 68220 *ropts = opts;
1662 68220 *rkey = key;
1663 68220 *rval = val;
1664 68220 return 0;
1665 }
1666
1667 36 int av_opt_set_from_string(void *ctx, const char *opts,
1668 const char *const *shorthand,
1669 const char *key_val_sep, const char *pairs_sep)
1670 {
1671 36 int ret, count = 0;
1672 36 const char *dummy_shorthand = NULL;
1673 36 char *av_uninit(parsed_key), *av_uninit(value);
1674 const char *key;
1675
1676
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (!opts)
1677 return 0;
1678
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
36 if (!shorthand)
1679 shorthand = &dummy_shorthand;
1680
1681
2/2
✓ Branch 0 taken 49 times.
✓ Branch 1 taken 32 times.
81 while (*opts) {
1682 49 ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1683 49 *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1684 &parsed_key, &value);
1685
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 48 times.
49 if (ret < 0) {
1686
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (ret == AVERROR(EINVAL))
1687 1 av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1688 else
1689 av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1690 av_err2str(ret));
1691 1 return ret;
1692 }
1693
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 33 times.
48 if (*opts)
1694 15 opts++;
1695
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 14 times.
48 if (parsed_key) {
1696 34 key = parsed_key;
1697
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 34 times.
61 while (*shorthand) /* discard all remaining shorthand */
1698 27 shorthand++;
1699 } else {
1700 14 key = *(shorthand++);
1701 }
1702
1703 48 av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1704
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 45 times.
48 if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1705
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if (ret == AVERROR_OPTION_NOT_FOUND)
1706 2 av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1707 3 av_free(value);
1708 3 av_free(parsed_key);
1709 3 return ret;
1710 }
1711
1712 45 av_free(value);
1713 45 av_free(parsed_key);
1714 45 count++;
1715 }
1716 32 return count;
1717 }
1718
1719 576122 void av_opt_free(void *obj)
1720 {
1721 576122 const AVOption *o = NULL;
1722
2/2
✓ Branch 1 taken 22471415 times.
✓ Branch 2 taken 576122 times.
23047537 while ((o = av_opt_next(obj, o))) {
1723
4/4
✓ Branch 0 taken 841586 times.
✓ Branch 1 taken 144 times.
✓ Branch 2 taken 57144 times.
✓ Branch 3 taken 21572541 times.
22471415 switch (o->type) {
1724 841586 case AV_OPT_TYPE_STRING:
1725 case AV_OPT_TYPE_BINARY:
1726 841586 av_freep((uint8_t *)obj + o->offset);
1727 841586 break;
1728
1729 144 case AV_OPT_TYPE_DICT:
1730 144 av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
1731 144 break;
1732
1733 57144 case AV_OPT_TYPE_CHLAYOUT:
1734 57144 av_channel_layout_uninit((AVChannelLayout *)(((uint8_t *)obj) + o->offset));
1735 57144 break;
1736
1737 21572541 default:
1738 21572541 break;
1739 }
1740 }
1741 576122 }
1742
1743 230367 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1744 {
1745 230367 const AVDictionaryEntry *t = NULL;
1746 230367 AVDictionary *tmp = NULL;
1747 int ret;
1748
1749
2/2
✓ Branch 0 taken 38347 times.
✓ Branch 1 taken 192020 times.
230367 if (!options)
1750 38347 return 0;
1751
1752
2/2
✓ Branch 1 taken 207761 times.
✓ Branch 2 taken 192020 times.
399781 while ((t = av_dict_iterate(*options, t))) {
1753 207761 ret = av_opt_set(obj, t->key, t->value, search_flags);
1754
2/2
✓ Branch 0 taken 59575 times.
✓ Branch 1 taken 148186 times.
207761 if (ret == AVERROR_OPTION_NOT_FOUND)
1755 59575 ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY);
1756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 207761 times.
207761 if (ret < 0) {
1757 av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1758 av_dict_free(&tmp);
1759 return ret;
1760 }
1761 }
1762 192020 av_dict_free(options);
1763 192020 *options = tmp;
1764 192020 return 0;
1765 }
1766
1767 181105 int av_opt_set_dict(void *obj, AVDictionary **options)
1768 {
1769 181105 return av_opt_set_dict2(obj, options, 0);
1770 }
1771
1772 494363 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1773 int opt_flags, int search_flags)
1774 {
1775 494363 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1776 }
1777
1778 37178153 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1779 int opt_flags, int search_flags, void **target_obj)
1780 {
1781 const AVClass *c;
1782 37178153 const AVOption *o = NULL;
1783
1784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 37178153 times.
37178153 if(!obj)
1785 return NULL;
1786
1787 37178153 c= *(AVClass**)obj;
1788
1789
2/2
✓ Branch 0 taken 953 times.
✓ Branch 1 taken 37177200 times.
37178153 if (!c)
1790 953 return NULL;
1791
1792
2/2
✓ Branch 0 taken 36620302 times.
✓ Branch 1 taken 556898 times.
37177200 if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1793
2/2
✓ Branch 0 taken 36373186 times.
✓ Branch 1 taken 247116 times.
36620302 if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1794 36373186 void *iter = NULL;
1795 const AVClass *child;
1796
2/2
✓ Branch 1 taken 36138490 times.
✓ Branch 2 taken 36372697 times.
72511187 while (child = av_opt_child_class_iterate(c, &iter))
1797
2/2
✓ Branch 1 taken 489 times.
✓ Branch 2 taken 36138001 times.
36138490 if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1798 489 return o;
1799 } else {
1800 247116 void *child = NULL;
1801
2/2
✓ Branch 1 taken 148826 times.
✓ Branch 2 taken 167250 times.
316076 while (child = av_opt_child_next(obj, child))
1802
2/2
✓ Branch 1 taken 79866 times.
✓ Branch 2 taken 68960 times.
148826 if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1803 79866 return o;
1804 }
1805 }
1806
1807
2/2
✓ Branch 1 taken 383934574 times.
✓ Branch 2 taken 36528908 times.
420463482 while (o = av_opt_next(obj, o)) {
1808
6/6
✓ Branch 0 taken 645243 times.
✓ Branch 1 taken 383289331 times.
✓ Branch 2 taken 642750 times.
✓ Branch 3 taken 2493 times.
✓ Branch 4 taken 512672 times.
✓ Branch 5 taken 130078 times.
383934574 if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1809
4/4
✓ Branch 0 taken 68293 times.
✓ Branch 1 taken 444379 times.
✓ Branch 2 taken 130078 times.
✓ Branch 3 taken 68293 times.
642750 ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1810
4/6
✓ Branch 0 taken 130078 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 130078 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 123558 times.
✓ Branch 5 taken 6520 times.
130078 (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1811
2/2
✓ Branch 0 taken 304277 times.
✓ Branch 1 taken 263660 times.
567937 if (target_obj) {
1812
1/2
✓ Branch 0 taken 304277 times.
✗ Branch 1 not taken.
304277 if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1813 304277 *target_obj = obj;
1814 else
1815 *target_obj = NULL;
1816 }
1817 567937 return o;
1818 }
1819 }
1820 36528908 return NULL;
1821 }
1822
1823 316076 void *av_opt_child_next(void *obj, void *prev)
1824 {
1825 316076 const AVClass *c = *(AVClass **)obj;
1826
2/2
✓ Branch 0 taken 207596 times.
✓ Branch 1 taken 108480 times.
316076 if (c->child_next)
1827 207596 return c->child_next(obj, prev);
1828 108480 return NULL;
1829 }
1830
1831 72511187 const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
1832 {
1833
2/2
✓ Branch 0 taken 36502729 times.
✓ Branch 1 taken 36008458 times.
72511187 if (parent->child_class_iterate)
1834 36502729 return parent->child_class_iterate(iter);
1835 36008458 return NULL;
1836 }
1837
1838 7112 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
1839 {
1840 7112 const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
1841
2/2
✓ Branch 0 taken 7079 times.
✓ Branch 1 taken 33 times.
7112 if(!opt)
1842 7079 return NULL;
1843 33 return (uint8_t*)obj + opt->offset;
1844 }
1845
1846 1509501 static int opt_size(enum AVOptionType type)
1847 {
1848
8/12
✓ Branch 0 taken 1111984 times.
✓ Branch 1 taken 114661 times.
✓ Branch 2 taken 14028 times.
✓ Branch 3 taken 165620 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 50960 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 12740 times.
✓ Branch 8 taken 26768 times.
✓ Branch 9 taken 12740 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
1509501 switch(type) {
1849 1111984 case AV_OPT_TYPE_BOOL:
1850 case AV_OPT_TYPE_INT:
1851 case AV_OPT_TYPE_FLAGS:
1852 1111984 return sizeof(int);
1853 114661 case AV_OPT_TYPE_DURATION:
1854 #if FF_API_OLD_CHANNEL_LAYOUT
1855 FF_DISABLE_DEPRECATION_WARNINGS
1856 case AV_OPT_TYPE_CHANNEL_LAYOUT:
1857 FF_ENABLE_DEPRECATION_WARNINGS
1858 #endif
1859 case AV_OPT_TYPE_INT64:
1860 case AV_OPT_TYPE_UINT64:
1861 114661 return sizeof(int64_t);
1862 14028 case AV_OPT_TYPE_DOUBLE:
1863 14028 return sizeof(double);
1864 165620 case AV_OPT_TYPE_FLOAT:
1865 165620 return sizeof(float);
1866 case AV_OPT_TYPE_STRING:
1867 return sizeof(uint8_t*);
1868 50960 case AV_OPT_TYPE_VIDEO_RATE:
1869 case AV_OPT_TYPE_RATIONAL:
1870 50960 return sizeof(AVRational);
1871 case AV_OPT_TYPE_BINARY:
1872 return sizeof(uint8_t*) + sizeof(int);
1873 12740 case AV_OPT_TYPE_IMAGE_SIZE:
1874 12740 return sizeof(int[2]);
1875 26768 case AV_OPT_TYPE_PIXEL_FMT:
1876 26768 return sizeof(enum AVPixelFormat);
1877 12740 case AV_OPT_TYPE_SAMPLE_FMT:
1878 12740 return sizeof(enum AVSampleFormat);
1879 case AV_OPT_TYPE_COLOR:
1880 return 4;
1881 }
1882 return AVERROR(EINVAL);
1883 }
1884
1885 19953 int av_opt_copy(void *dst, const void *src)
1886 {
1887 19953 const AVOption *o = NULL;
1888 const AVClass *c;
1889 19953 int ret = 0;
1890
1891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19953 times.
19953 if (!src)
1892 return AVERROR(EINVAL);
1893
1894 19953 c = *(AVClass **)src;
1895
2/4
✓ Branch 0 taken 19953 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 19953 times.
19953 if (!c || c != *(AVClass **)dst)
1896 return AVERROR(EINVAL);
1897
1898
2/2
✓ Branch 1 taken 4673596 times.
✓ Branch 2 taken 19953 times.
4693549 while ((o = av_opt_next(src, o))) {
1899 4673596 void *field_dst = (uint8_t *)dst + o->offset;
1900 4673596 void *field_src = (uint8_t *)src + o->offset;
1901 4673596 uint8_t **field_dst8 = (uint8_t **)field_dst;
1902 4673596 uint8_t **field_src8 = (uint8_t **)field_src;
1903
1904
2/2
✓ Branch 0 taken 38231 times.
✓ Branch 1 taken 4635365 times.
4673596 if (o->type == AV_OPT_TYPE_STRING) {
1905
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 38231 times.
38231 if (*field_dst8 != *field_src8)
1906 av_freep(field_dst8);
1907 38231 *field_dst8 = av_strdup(*field_src8);
1908
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 38231 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
38231 if (*field_src8 && !*field_dst8)
1909 ret = AVERROR(ENOMEM);
1910
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4635365 times.
4635365 } else if (o->type == AV_OPT_TYPE_BINARY) {
1911 int len = *(int *)(field_src8 + 1);
1912 if (*field_dst8 != *field_src8)
1913 av_freep(field_dst8);
1914 *field_dst8 = av_memdup(*field_src8, len);
1915 if (len && !*field_dst8) {
1916 ret = AVERROR(ENOMEM);
1917 len = 0;
1918 }
1919 *(int *)(field_dst8 + 1) = len;
1920
2/2
✓ Branch 0 taken 1522241 times.
✓ Branch 1 taken 3113124 times.
4635365 } else if (o->type == AV_OPT_TYPE_CONST) {
1921 // do nothing
1922
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1522241 times.
1522241 } else if (o->type == AV_OPT_TYPE_DICT) {
1923 AVDictionary **sdict = (AVDictionary **) field_src;
1924 AVDictionary **ddict = (AVDictionary **) field_dst;
1925 int ret2;
1926 if (*sdict != *ddict)
1927 av_dict_free(ddict);
1928 *ddict = NULL;
1929 ret2 = av_dict_copy(ddict, *sdict, 0);
1930 if (ret2 < 0)
1931 ret = ret2;
1932
2/2
✓ Branch 0 taken 12740 times.
✓ Branch 1 taken 1509501 times.
1522241 } else if (o->type == AV_OPT_TYPE_CHLAYOUT) {
1933
1/2
✓ Branch 0 taken 12740 times.
✗ Branch 1 not taken.
12740 if (field_dst != field_src)
1934 12740 ret = av_channel_layout_copy(field_dst, field_src);
1935 } else {
1936 1509501 int size = opt_size(o->type);
1937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1509501 times.
1509501 if (size < 0)
1938 ret = size;
1939 else
1940 1509501 memcpy(field_dst, field_src, size);
1941 }
1942 }
1943 19953 return ret;
1944 }
1945
1946 27 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1947 {
1948 int ret;
1949 27 const AVClass *c = *(AVClass**)obj;
1950 27 int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
1951
1952
1/2
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
27 if (!callback)
1953 27 callback = av_opt_query_ranges_default;
1954
1955 27 ret = callback(ranges_arg, obj, key, flags);
1956
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 10 times.
27 if (ret >= 0) {
1957
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE))
1958 17 ret = 1;
1959 17 (*ranges_arg)->nb_components = ret;
1960 }
1961 27 return ret;
1962 }
1963
1964 27 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1965 {
1966 27 AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
1967 27 AVOptionRange **range_array = av_mallocz(sizeof(void*));
1968 27 AVOptionRange *range = av_mallocz(sizeof(*range));
1969 27 const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
1970 int ret;
1971
1972 27 *ranges_arg = NULL;
1973
1974
5/8
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 27 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 24 times.
27 if (!ranges || !range || !range_array || !field) {
1975 3 ret = AVERROR(ENOMEM);
1976 3 goto fail;
1977 }
1978
1979 24 ranges->range = range_array;
1980 24 ranges->range[0] = range;
1981 24 ranges->nb_ranges = 1;
1982 24 ranges->nb_components = 1;
1983 24 range->is_range = 1;
1984 24 range->value_min = field->min;
1985 24 range->value_max = field->max;
1986
1987
6/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 7 times.
24 switch (field->type) {
1988 12 case AV_OPT_TYPE_BOOL:
1989 case AV_OPT_TYPE_INT:
1990 case AV_OPT_TYPE_INT64:
1991 case AV_OPT_TYPE_UINT64:
1992 case AV_OPT_TYPE_PIXEL_FMT:
1993 case AV_OPT_TYPE_SAMPLE_FMT:
1994 case AV_OPT_TYPE_FLOAT:
1995 case AV_OPT_TYPE_DOUBLE:
1996 case AV_OPT_TYPE_DURATION:
1997 case AV_OPT_TYPE_COLOR:
1998 #if FF_API_OLD_CHANNEL_LAYOUT
1999 FF_DISABLE_DEPRECATION_WARNINGS
2000 case AV_OPT_TYPE_CHANNEL_LAYOUT:
2001 FF_ENABLE_DEPRECATION_WARNINGS
2002