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 "dict.h" | ||
33 | #include "eval.h" | ||
34 | #include "log.h" | ||
35 | #include "mem.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 | #define TYPE_BASE(type) ((type) & ~AV_OPT_TYPE_FLAG_ARRAY) | ||
47 | |||
48 | 482164534 | const AVOption *av_opt_next(const void *obj, const AVOption *last) | |
49 | { | ||
50 | const AVClass *class; | ||
51 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 482164534 times.
|
482164534 | if (!obj) |
52 | ✗ | return NULL; | |
53 | 482164534 | class = *(const AVClass**)obj; | |
54 |
7/8✓ Branch 0 taken 37975783 times.
✓ Branch 1 taken 444188751 times.
✓ Branch 2 taken 37975783 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37703344 times.
✓ Branch 5 taken 272439 times.
✓ Branch 6 taken 37612392 times.
✓ Branch 7 taken 90952 times.
|
482164534 | if (!last && class && class->option && class->option[0].name) |
55 | 37612392 | return class->option; | |
56 |
4/4✓ Branch 0 taken 444188751 times.
✓ Branch 1 taken 363391 times.
✓ Branch 2 taken 407120119 times.
✓ Branch 3 taken 37068632 times.
|
444552142 | if (last && last[1].name) |
57 | 407120119 | return ++last; | |
58 | 37432023 | return NULL; | |
59 | } | ||
60 | |||
61 | static const size_t opt_elem_size[] = { | ||
62 | [AV_OPT_TYPE_FLAGS] = sizeof(unsigned), | ||
63 | [AV_OPT_TYPE_INT] = sizeof(int), | ||
64 | [AV_OPT_TYPE_INT64] = sizeof(int64_t), | ||
65 | [AV_OPT_TYPE_UINT] = sizeof(unsigned), | ||
66 | [AV_OPT_TYPE_UINT64] = sizeof(uint64_t), | ||
67 | [AV_OPT_TYPE_DOUBLE] = sizeof(double), | ||
68 | [AV_OPT_TYPE_FLOAT] = sizeof(float), | ||
69 | [AV_OPT_TYPE_STRING] = sizeof(char *), | ||
70 | [AV_OPT_TYPE_RATIONAL] = sizeof(AVRational), | ||
71 | [AV_OPT_TYPE_BINARY] = sizeof(uint8_t *), | ||
72 | [AV_OPT_TYPE_DICT] = sizeof(AVDictionary *), | ||
73 | [AV_OPT_TYPE_IMAGE_SIZE] = sizeof(int[2]), | ||
74 | [AV_OPT_TYPE_VIDEO_RATE] = sizeof(AVRational), | ||
75 | [AV_OPT_TYPE_PIXEL_FMT] = sizeof(int), | ||
76 | [AV_OPT_TYPE_SAMPLE_FMT] = sizeof(int), | ||
77 | [AV_OPT_TYPE_DURATION] = sizeof(int64_t), | ||
78 | [AV_OPT_TYPE_COLOR] = sizeof(uint8_t[4]), | ||
79 | [AV_OPT_TYPE_CHLAYOUT] = sizeof(AVChannelLayout), | ||
80 | [AV_OPT_TYPE_BOOL] = sizeof(int), | ||
81 | }; | ||
82 | |||
83 | // option is plain old data | ||
84 | 1465463 | static int opt_is_pod(enum AVOptionType type) | |
85 | { | ||
86 |
1/2✓ Branch 0 taken 1465463 times.
✗ Branch 1 not taken.
|
1465463 | switch (type) { |
87 | 1465463 | case AV_OPT_TYPE_FLAGS: | |
88 | case AV_OPT_TYPE_INT: | ||
89 | case AV_OPT_TYPE_INT64: | ||
90 | case AV_OPT_TYPE_DOUBLE: | ||
91 | case AV_OPT_TYPE_FLOAT: | ||
92 | case AV_OPT_TYPE_RATIONAL: | ||
93 | case AV_OPT_TYPE_UINT64: | ||
94 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
95 | case AV_OPT_TYPE_PIXEL_FMT: | ||
96 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
97 | case AV_OPT_TYPE_VIDEO_RATE: | ||
98 | case AV_OPT_TYPE_DURATION: | ||
99 | case AV_OPT_TYPE_COLOR: | ||
100 | case AV_OPT_TYPE_BOOL: | ||
101 | 1465463 | return 1; | |
102 | } | ||
103 | ✗ | return 0; | |
104 | } | ||
105 | |||
106 | 57480 | static uint8_t opt_array_sep(const AVOption *o) | |
107 | { | ||
108 | 57480 | const AVOptionArrayDef *d = o->default_val.arr; | |
109 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
110 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 57436 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 23 times.
|
57480 | return (d && d->sep) ? d->sep : ','; |
111 | } | ||
112 | |||
113 | 125 | static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx) | |
114 | { | ||
115 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
116 | 125 | return (uint8_t *)array + idx * opt_elem_size[TYPE_BASE(o->type)]; | |
117 | } | ||
118 | |||
119 | 108787 | static unsigned *opt_array_pcount(const void *parray) | |
120 | { | ||
121 | 108787 | return (unsigned *)((const void * const *)parray + 1); | |
122 | } | ||
123 | |||
124 | 23312702 | static void opt_free_elem(const AVOption *o, void *ptr) | |
125 | { | ||
126 |
4/4✓ Branch 0 taken 845345 times.
✓ Branch 1 taken 225 times.
✓ Branch 2 taken 58114 times.
✓ Branch 3 taken 22409018 times.
|
23312702 | switch (TYPE_BASE(o->type)) { |
127 | 845345 | case AV_OPT_TYPE_STRING: | |
128 | case AV_OPT_TYPE_BINARY: | ||
129 | 845345 | av_freep(ptr); | |
130 | 845345 | break; | |
131 | |||
132 | 225 | case AV_OPT_TYPE_DICT: | |
133 | 225 | av_dict_free((AVDictionary **)ptr); | |
134 | 225 | break; | |
135 | |||
136 | 58114 | case AV_OPT_TYPE_CHLAYOUT: | |
137 | 58114 | av_channel_layout_uninit((AVChannelLayout *)ptr); | |
138 | 58114 | break; | |
139 | |||
140 | 22409018 | default: | |
141 | 22409018 | break; | |
142 | } | ||
143 | 23312702 | } | |
144 | |||
145 | 70331 | static void opt_free_array(const AVOption *o, void *parray, unsigned *count) | |
146 | { | ||
147 |
2/2✓ Branch 0 taken 47 times.
✓ Branch 1 taken 70331 times.
|
70378 | for (unsigned i = 0; i < *count; i++) |
148 | 47 | opt_free_elem(o, opt_array_pelem(o, *(void **)parray, i)); | |
149 | |||
150 | 70331 | av_freep(parray); | |
151 | 70331 | *count = 0; | |
152 | 70331 | } | |
153 | |||
154 | 18739 | static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum) | |
155 | { | ||
156 |
6/11✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 18692 times.
✓ Branch 4 taken 23 times.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
18739 | switch (o->type) { |
157 | 9 | case AV_OPT_TYPE_FLAGS: | |
158 | 9 | *intnum = *(unsigned int*)dst; | |
159 | 9 | return 0; | |
160 | 3 | case AV_OPT_TYPE_PIXEL_FMT: | |
161 | 3 | *intnum = *(enum AVPixelFormat *)dst; | |
162 | 3 | return 0; | |
163 | 3 | case AV_OPT_TYPE_SAMPLE_FMT: | |
164 | 3 | *intnum = *(enum AVSampleFormat *)dst; | |
165 | 3 | return 0; | |
166 | 18692 | case AV_OPT_TYPE_BOOL: | |
167 | case AV_OPT_TYPE_INT: | ||
168 | 18692 | *intnum = *(int *)dst; | |
169 | 18692 | return 0; | |
170 | 23 | case AV_OPT_TYPE_UINT: | |
171 | 23 | *intnum = *(unsigned int *)dst; | |
172 | 23 | return 0; | |
173 | 9 | case AV_OPT_TYPE_DURATION: | |
174 | case AV_OPT_TYPE_INT64: | ||
175 | case AV_OPT_TYPE_UINT64: | ||
176 | 9 | *intnum = *(int64_t *)dst; | |
177 | 9 | return 0; | |
178 | ✗ | case AV_OPT_TYPE_FLOAT: | |
179 | ✗ | *num = *(float *)dst; | |
180 | ✗ | return 0; | |
181 | ✗ | case AV_OPT_TYPE_DOUBLE: | |
182 | ✗ | *num = *(double *)dst; | |
183 | ✗ | return 0; | |
184 | ✗ | case AV_OPT_TYPE_RATIONAL: | |
185 | ✗ | *intnum = ((AVRational *)dst)->num; | |
186 | ✗ | *den = ((AVRational *)dst)->den; | |
187 | ✗ | return 0; | |
188 | ✗ | case AV_OPT_TYPE_CONST: | |
189 | ✗ | *intnum = o->default_val.i64; | |
190 | ✗ | return 0; | |
191 | } | ||
192 | ✗ | return AVERROR(EINVAL); | |
193 | } | ||
194 | |||
195 | 7038968 | static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum) | |
196 | { | ||
197 | 7038968 | const enum AVOptionType type = TYPE_BASE(o->type); | |
198 | |||
199 |
4/4✓ Branch 0 taken 6277576 times.
✓ Branch 1 taken 761392 times.
✓ Branch 2 taken 6277575 times.
✓ Branch 3 taken 1 times.
|
7038968 | if (type != AV_OPT_TYPE_FLAGS && |
200 |
4/4✓ Branch 0 taken 6277567 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 6277560 times.
|
6277575 | (!den || o->max * den < num * intnum || o->min * den > num * intnum)) { |
201 |
4/6✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
16 | num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN); |
202 | 16 | av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
203 | 16 | num, o->name, o->min, o->max); | |
204 | 16 | return AVERROR(ERANGE); | |
205 | } | ||
206 |
2/2✓ Branch 0 taken 761392 times.
✓ Branch 1 taken 6277560 times.
|
7038952 | if (type == AV_OPT_TYPE_FLAGS) { |
207 | 761392 | double d = num*intnum/den; | |
208 |
3/6✓ Branch 0 taken 761392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 761392 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 761392 times.
|
761392 | if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) { |
209 | ✗ | av_log(obj, AV_LOG_ERROR, | |
210 | "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n", | ||
211 | ✗ | num*intnum/den, o->name); | |
212 | ✗ | return AVERROR(ERANGE); | |
213 | } | ||
214 | } | ||
215 | |||
216 |
7/9✓ Branch 0 taken 67996 times.
✓ Branch 1 taken 45897 times.
✓ Branch 2 taken 5535737 times.
✓ Branch 3 taken 420941 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 720206 times.
✓ Branch 6 taken 55266 times.
✓ Branch 7 taken 192909 times.
✗ Branch 8 not taken.
|
7038952 | switch (type) { |
217 | 67996 | case AV_OPT_TYPE_PIXEL_FMT: | |
218 | 67996 | *(enum AVPixelFormat *)dst = llrint(num / den) * intnum; | |
219 | 67996 | break; | |
220 | 45897 | case AV_OPT_TYPE_SAMPLE_FMT: | |
221 | 45897 | *(enum AVSampleFormat *)dst = llrint(num / den) * intnum; | |
222 | 45897 | break; | |
223 | 5535737 | case AV_OPT_TYPE_BOOL: | |
224 | case AV_OPT_TYPE_FLAGS: | ||
225 | case AV_OPT_TYPE_INT: | ||
226 | case AV_OPT_TYPE_UINT: | ||
227 | 5535737 | *(int *)dst = llrint(num / den) * intnum; | |
228 | 5535737 | break; | |
229 | 420941 | case AV_OPT_TYPE_DURATION: | |
230 | case AV_OPT_TYPE_INT64:{ | ||
231 | 420941 | double d = num / den; | |
232 |
3/4✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 419789 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1152 times.
|
420941 | if (intnum == 1 && d == (double)INT64_MAX) { |
233 | ✗ | *(int64_t *)dst = INT64_MAX; | |
234 | } else | ||
235 | 420941 | *(int64_t *)dst = llrint(d) * intnum; | |
236 | 420941 | break;} | |
237 | ✗ | case AV_OPT_TYPE_UINT64:{ | |
238 | ✗ | double d = num / den; | |
239 | // We must special case uint64_t here as llrint() does not support values | ||
240 | // outside the int64_t range and there is no portable function which does | ||
241 | // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double | ||
242 | // while INT64_MAX is not | ||
243 | ✗ | if (intnum == 1 && d == (double)UINT64_MAX) { | |
244 | ✗ | *(uint64_t *)dst = UINT64_MAX; | |
245 | ✗ | } else if (d > INT64_MAX + 1ULL) { | |
246 | ✗ | *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum; | |
247 | } else { | ||
248 | ✗ | *(uint64_t *)dst = llrint(d) * intnum; | |
249 | } | ||
250 | ✗ | break;} | |
251 | 720206 | case AV_OPT_TYPE_FLOAT: | |
252 | 720206 | *(float *)dst = num * intnum / den; | |
253 | 720206 | break; | |
254 | 55266 | case AV_OPT_TYPE_DOUBLE: | |
255 | 55266 | *(double *)dst = num * intnum / den; | |
256 | 55266 | break; | |
257 | 192909 | case AV_OPT_TYPE_RATIONAL: | |
258 | case AV_OPT_TYPE_VIDEO_RATE: | ||
259 |
1/2✓ Branch 0 taken 192909 times.
✗ Branch 1 not taken.
|
192909 | if ((int) num == num) |
260 | 192909 | *(AVRational *)dst = (AVRational) { num *intnum, den }; | |
261 | else | ||
262 | ✗ | *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24); | |
263 | 192909 | break; | |
264 | ✗ | default: | |
265 | ✗ | return AVERROR(EINVAL); | |
266 | } | ||
267 | 7038952 | return 0; | |
268 | } | ||
269 | |||
270 | 15718 | static int hexchar2int(char c) { | |
271 |
3/4✓ Branch 0 taken 15718 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11339 times.
✓ Branch 3 taken 4379 times.
|
15718 | if (c >= '0' && c <= '9') |
272 | 11339 | return c - '0'; | |
273 |
4/4✓ Branch 0 taken 4377 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4376 times.
✓ Branch 3 taken 1 times.
|
4379 | if (c >= 'a' && c <= 'f') |
274 | 4376 | return c - 'a' + 10; | |
275 |
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') |
276 | 2 | return c - 'A' + 10; | |
277 | 1 | return -1; | |
278 | } | ||
279 | |||
280 | 35219 | static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
281 | { | ||
282 | 35219 | int *lendst = (int *)(dst + 1); | |
283 | uint8_t *bin, *ptr; | ||
284 | int len; | ||
285 | |||
286 | 35219 | av_freep(dst); | |
287 | 35219 | *lendst = 0; | |
288 | |||
289 |
4/4✓ Branch 0 taken 511 times.
✓ Branch 1 taken 34708 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 501 times.
|
35219 | if (!val || !(len = strlen(val))) |
290 | 34718 | return 0; | |
291 | |||
292 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 500 times.
|
501 | if (len & 1) |
293 | 1 | return AVERROR(EINVAL); | |
294 | 500 | len /= 2; | |
295 | |||
296 | 500 | ptr = bin = av_malloc(len); | |
297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 500 times.
|
500 | if (!ptr) |
298 | ✗ | return AVERROR(ENOMEM); | |
299 |
2/2✓ Branch 0 taken 7859 times.
✓ Branch 1 taken 499 times.
|
8358 | while (*val) { |
300 | 7859 | int a = hexchar2int(*val++); | |
301 | 7859 | int b = hexchar2int(*val++); | |
302 |
3/4✓ Branch 0 taken 7859 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7858 times.
|
7859 | if (a < 0 || b < 0) { |
303 | 1 | av_free(bin); | |
304 | 1 | return AVERROR(EINVAL); | |
305 | } | ||
306 | 7858 | *ptr++ = (a << 4) | b; | |
307 | } | ||
308 | 499 | *dst = bin; | |
309 | 499 | *lendst = len; | |
310 | |||
311 | 499 | return 0; | |
312 | } | ||
313 | |||
314 | 427023 | static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
315 | { | ||
316 | 427023 | av_freep(dst); | |
317 |
2/2✓ Branch 0 taken 353119 times.
✓ Branch 1 taken 73904 times.
|
427023 | if (!val) |
318 | 353119 | return 0; | |
319 | 73904 | *dst = av_strdup(val); | |
320 |
1/2✓ Branch 0 taken 73904 times.
✗ Branch 1 not taken.
|
73904 | return *dst ? 0 : AVERROR(ENOMEM); |
321 | } | ||
322 | |||
323 | #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \ | ||
324 | opt->type == AV_OPT_TYPE_UINT64 || \ | ||
325 | opt->type == AV_OPT_TYPE_CONST || \ | ||
326 | opt->type == AV_OPT_TYPE_FLAGS || \ | ||
327 | opt->type == AV_OPT_TYPE_UINT || \ | ||
328 | opt->type == AV_OPT_TYPE_INT) \ | ||
329 | ? opt->default_val.i64 \ | ||
330 | : opt->default_val.dbl) | ||
331 | |||
332 | 130574 | static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst) | |
333 | { | ||
334 | 130574 | const enum AVOptionType type = TYPE_BASE(o->type); | |
335 | 130574 | int ret = 0; | |
336 | |||
337 |
3/4✓ Branch 0 taken 113662 times.
✓ Branch 1 taken 16912 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 113662 times.
|
130574 | if (type == AV_OPT_TYPE_RATIONAL || type == AV_OPT_TYPE_VIDEO_RATE) { |
338 | int num, den; | ||
339 | char c; | ||
340 |
2/2✓ Branch 0 taken 16896 times.
✓ Branch 1 taken 16 times.
|
16912 | if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) { |
341 |
2/2✓ Branch 1 taken 16894 times.
✓ Branch 2 taken 2 times.
|
16896 | if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0) |
342 | 16894 | return ret; | |
343 | 2 | ret = 0; | |
344 | } | ||
345 | } | ||
346 | |||
347 | 34191 | for (;;) { | |
348 | 147871 | int i = 0; | |
349 | char buf[256]; | ||
350 | 147871 | int cmd = 0; | |
351 | double d; | ||
352 | 147871 | int64_t intnum = 1; | |
353 | |||
354 |
2/2✓ Branch 0 taken 82556 times.
✓ Branch 1 taken 65315 times.
|
147871 | if (type == AV_OPT_TYPE_FLAGS) { |
355 |
4/4✓ Branch 0 taken 19922 times.
✓ Branch 1 taken 62634 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 19899 times.
|
82556 | if (*val == '+' || *val == '-') |
356 | 62657 | cmd = *(val++); | |
357 |
7/8✓ Branch 0 taken 666237 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 617872 times.
✓ Branch 3 taken 48365 times.
✓ Branch 4 taken 583682 times.
✓ Branch 5 taken 34190 times.
✓ Branch 6 taken 583681 times.
✓ Branch 7 taken 1 times.
|
666237 | for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++) |
358 | 583681 | buf[i] = val[i]; | |
359 | 82556 | buf[i] = 0; | |
360 | } | ||
361 | |||
362 | { | ||
363 | int res; | ||
364 | 147871 | int ci = 0; | |
365 | double const_values[64]; | ||
366 | const char * const_names[64]; | ||
367 | 147871 | int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0; | |
368 |
2/2✓ Branch 0 taken 82556 times.
✓ Branch 1 taken 65315 times.
|
147871 | const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags); |
369 |
3/4✓ Branch 0 taken 95074 times.
✓ Branch 1 taken 52797 times.
✓ Branch 2 taken 95074 times.
✗ Branch 3 not taken.
|
147871 | if (o_named && o_named->type == AV_OPT_TYPE_CONST) { |
370 |
3/12✓ Branch 0 taken 95074 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 95074 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 95074 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
95074 | d = DEFAULT_NUMVAL(o_named); |
371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 95074 times.
|
95074 | if (o_named->flags & AV_OPT_FLAG_DEPRECATED) |
372 | ✗ | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", | |
373 | ✗ | o_named->name, o_named->help); | |
374 | } else { | ||
375 |
2/2✓ Branch 0 taken 39699 times.
✓ Branch 1 taken 13098 times.
|
52797 | if (o->unit) { |
376 |
2/2✓ Branch 1 taken 7128244 times.
✓ Branch 2 taken 39699 times.
|
7167943 | for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) { |
377 |
2/2✓ Branch 0 taken 4983006 times.
✓ Branch 1 taken 2145238 times.
|
7128244 | if (o_named->type == AV_OPT_TYPE_CONST && |
378 |
1/2✓ Branch 0 taken 4983006 times.
✗ Branch 1 not taken.
|
4983006 | o_named->unit && |
379 |
2/2✓ Branch 0 taken 390336 times.
✓ Branch 1 taken 4592670 times.
|
4983006 | !strcmp(o_named->unit, o->unit)) { |
380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 390336 times.
|
390336 | if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) { |
381 | ✗ | av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit); | |
382 | 8 | return AVERROR_PATCHWELCOME; | |
383 | } | ||
384 | 390336 | const_names [ci ] = o_named->name; | |
385 |
3/12✓ Branch 0 taken 390336 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 390336 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 390336 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
390336 | const_values[ci++] = DEFAULT_NUMVAL(o_named); |
386 | } | ||
387 | } | ||
388 | } | ||
389 | 52797 | const_names [ci ] = "default"; | |
390 |
10/12✓ Branch 0 taken 51642 times.
✓ Branch 1 taken 1155 times.
✓ Branch 2 taken 51642 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51642 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 44868 times.
✓ Branch 7 taken 6774 times.
✓ Branch 8 taken 44793 times.
✓ Branch 9 taken 75 times.
✓ Branch 10 taken 44386 times.
✓ Branch 11 taken 407 times.
|
52797 | const_values[ci++] = DEFAULT_NUMVAL(o); |
391 | 52797 | const_names [ci ] = "max"; | |
392 | 52797 | const_values[ci++] = o->max; | |
393 | 52797 | const_names [ci ] = "min"; | |
394 | 52797 | const_values[ci++] = o->min; | |
395 | 52797 | const_names [ci ] = "none"; | |
396 | 52797 | const_values[ci++] = 0; | |
397 | 52797 | const_names [ci ] = "all"; | |
398 | 52797 | const_values[ci++] = ~0; | |
399 | 52797 | const_names [ci] = NULL; | |
400 | 52797 | const_values[ci] = 0; | |
401 | |||
402 |
2/2✓ Branch 0 taken 6774 times.
✓ Branch 1 taken 46023 times.
|
52797 | res = av_expr_parse_and_eval(&d, i ? buf : val, const_names, |
403 | const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); | ||
404 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 52789 times.
|
52797 | if (res < 0) { |
405 | 8 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val); | |
406 | 8 | return res; | |
407 | } | ||
408 | } | ||
409 | } | ||
410 |
2/2✓ Branch 0 taken 82556 times.
✓ Branch 1 taken 65307 times.
|
147863 | if (type == AV_OPT_TYPE_FLAGS) { |
411 | 82556 | intnum = *(unsigned int*)dst; | |
412 |
2/2✓ Branch 0 taken 62634 times.
✓ Branch 1 taken 19922 times.
|
82556 | if (cmd == '+') |
413 | 62634 | d = intnum | (int64_t)d; | |
414 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 19899 times.
|
19922 | else if (cmd == '-') |
415 | 23 | d = intnum &~(int64_t)d; | |
416 | } | ||
417 | |||
418 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 147849 times.
|
147863 | if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0) |
419 | 14 | return ret; | |
420 | 147849 | val += i; | |
421 |
4/4✓ Branch 0 taken 82556 times.
✓ Branch 1 taken 65293 times.
✓ Branch 2 taken 48365 times.
✓ Branch 3 taken 34191 times.
|
147849 | if (!i || !*val) |
422 | 113658 | return 0; | |
423 | } | ||
424 | } | ||
425 | |||
426 | 38466 | static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst) | |
427 | { | ||
428 | int ret; | ||
429 | |||
430 |
3/4✓ Branch 0 taken 6118 times.
✓ Branch 1 taken 32348 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6118 times.
|
38466 | if (!val || !strcmp(val, "none")) { |
431 | 32348 | dst[0] = | |
432 | 32348 | dst[1] = 0; | |
433 | 32348 | return 0; | |
434 | } | ||
435 | 6118 | ret = av_parse_video_size(dst, dst + 1, val); | |
436 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 6117 times.
|
6118 | if (ret < 0) |
437 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val); | |
438 | 6118 | return ret; | |
439 | } | ||
440 | |||
441 | 4658 | static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst) | |
442 | { | ||
443 | 4658 | int ret = av_parse_video_rate(dst, val); | |
444 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 4657 times.
|
4658 | if (ret < 0) |
445 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val); | |
446 | 4658 | return ret; | |
447 | } | ||
448 | |||
449 | 339 | static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
450 | { | ||
451 | int ret; | ||
452 | |||
453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
|
339 | if (!val) { |
454 | ✗ | return 0; | |
455 | } else { | ||
456 | 339 | ret = av_parse_color(dst, val, -1, obj); | |
457 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 339 times.
|
339 | if (ret < 0) |
458 | ✗ | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val); | |
459 | 339 | return ret; | |
460 | } | ||
461 | return 0; | ||
462 | } | ||
463 | |||
464 | 33 | static const char *get_bool_name(int val) | |
465 | { | ||
466 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 28 times.
|
33 | if (val < 0) |
467 | 5 | return "auto"; | |
468 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 7 times.
|
28 | return val ? "true" : "false"; |
469 | } | ||
470 | |||
471 | 9222 | static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst) | |
472 | { | ||
473 | int n; | ||
474 | |||
475 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9222 times.
|
9222 | if (!val) |
476 | ✗ | return 0; | |
477 | |||
478 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9219 times.
|
9222 | if (!strcmp(val, "auto")) { |
479 | 3 | n = -1; | |
480 |
2/2✓ Branch 1 taken 1268 times.
✓ Branch 2 taken 7951 times.
|
9219 | } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) { |
481 | 1268 | n = 1; | |
482 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 7939 times.
|
7951 | } else if (av_match_name(val, "false,n,no,disable,disabled,off")) { |
483 | 12 | n = 0; | |
484 | } else { | ||
485 | 7939 | char *end = NULL; | |
486 | 7939 | n = strtol(val, &end, 10); | |
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7939 times.
|
7939 | if (val + strlen(val) != end) |
488 | ✗ | goto fail; | |
489 | } | ||
490 | |||
491 |
2/4✓ Branch 0 taken 9222 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9222 times.
|
9222 | if (n < o->min || n > o->max) |
492 | ✗ | goto fail; | |
493 | |||
494 | 9222 | *dst = n; | |
495 | 9222 | return 0; | |
496 | |||
497 | ✗ | fail: | |
498 | ✗ | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val); | |
499 | ✗ | return AVERROR(EINVAL); | |
500 | } | ||
501 | |||
502 | 7745 | static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst, | |
503 | int fmt_nb, int ((*get_fmt)(const char *)), const char *desc) | ||
504 | { | ||
505 | int fmt, min, max; | ||
506 | |||
507 |
2/4✓ Branch 0 taken 7745 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7745 times.
|
7745 | if (!val || !strcmp(val, "none")) { |
508 | ✗ | fmt = -1; | |
509 | } else { | ||
510 | 7745 | fmt = get_fmt(val); | |
511 |
2/2✓ Branch 0 taken 5213 times.
✓ Branch 1 taken 2532 times.
|
7745 | if (fmt == -1) { |
512 | char *tail; | ||
513 | 5213 | fmt = strtol(val, &tail, 0); | |
514 |
3/4✓ Branch 0 taken 5211 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5211 times.
|
5213 | if (*tail || (unsigned)fmt >= fmt_nb) { |
515 | 2 | av_log(obj, AV_LOG_ERROR, | |
516 | "Unable to parse option value \"%s\" as %s\n", val, desc); | ||
517 | 2 | return AVERROR(EINVAL); | |
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7741 times.
|
7743 | min = FFMAX(o->min, -1); |
523 |
1/2✓ Branch 0 taken 7743 times.
✗ Branch 1 not taken.
|
7743 | max = FFMIN(o->max, fmt_nb-1); |
524 | |||
525 | // hack for compatibility with old ffmpeg | ||
526 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7741 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
7743 | if(min == 0 && max == 0) { |
527 | ✗ | min = -1; | |
528 | ✗ | max = fmt_nb-1; | |
529 | } | ||
530 | |||
531 |
2/4✓ Branch 0 taken 7743 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7743 times.
|
7743 | if (fmt < min || fmt > max) { |
532 | ✗ | av_log(obj, AV_LOG_ERROR, | |
533 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
534 | ✗ | fmt, o->name, desc, min, max); | |
535 | ✗ | return AVERROR(ERANGE); | |
536 | } | ||
537 | |||
538 | 7743 | *(int *)dst = fmt; | |
539 | 7743 | return 0; | |
540 | } | ||
541 | |||
542 | 5216 | static int get_pix_fmt(const char *name) | |
543 | { | ||
544 | 5216 | return av_get_pix_fmt(name); | |
545 | } | ||
546 | |||
547 | 5216 | static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
548 | { | ||
549 | 5216 | return set_string_fmt(obj, o, val, dst, | |
550 | AV_PIX_FMT_NB, get_pix_fmt, "pixel format"); | ||
551 | } | ||
552 | |||
553 | 2529 | static int get_sample_fmt(const char *name) | |
554 | { | ||
555 | 2529 | return av_get_sample_fmt(name); | |
556 | } | ||
557 | |||
558 | 2529 | static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
559 | { | ||
560 | 2529 | return set_string_fmt(obj, o, val, dst, | |
561 | AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format"); | ||
562 | } | ||
563 | |||
564 | 252 | static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
565 | { | ||
566 | 252 | AVDictionary *options = NULL; | |
567 | |||
568 |
2/2✓ Branch 0 taken 53 times.
✓ Branch 1 taken 199 times.
|
252 | if (val) { |
569 | 53 | int ret = av_dict_parse_string(&options, val, "=", ":", 0); | |
570 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53 times.
|
53 | if (ret < 0) { |
571 | ✗ | av_dict_free(&options); | |
572 | ✗ | return ret; | |
573 | } | ||
574 | } | ||
575 | |||
576 | 252 | av_dict_free((AVDictionary **)dst); | |
577 | 252 | *dst = (uint8_t *)options; | |
578 | |||
579 | 252 | return 0; | |
580 | } | ||
581 | |||
582 | 42619 | static int set_string_channel_layout(void *obj, const AVOption *o, | |
583 | const char *val, void *dst) | ||
584 | { | ||
585 | 42619 | AVChannelLayout *channel_layout = dst; | |
586 | 42619 | av_channel_layout_uninit(channel_layout); | |
587 |
2/2✓ Branch 0 taken 42340 times.
✓ Branch 1 taken 279 times.
|
42619 | if (!val) |
588 | 42340 | return 0; | |
589 | 279 | return av_channel_layout_from_string(channel_layout, val); | |
590 | } | ||
591 | |||
592 | 188634 | static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, | |
593 | const char *val, void *dst) | ||
594 | { | ||
595 | 188634 | const enum AVOptionType type = TYPE_BASE(o->type); | |
596 | int ret; | ||
597 | |||
598 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 188634 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
188634 | if (!val && (type != AV_OPT_TYPE_STRING && |
599 | ✗ | type != AV_OPT_TYPE_PIXEL_FMT && type != AV_OPT_TYPE_SAMPLE_FMT && | |
600 | ✗ | type != AV_OPT_TYPE_IMAGE_SIZE && | |
601 | ✗ | type != AV_OPT_TYPE_DURATION && type != AV_OPT_TYPE_COLOR && | |
602 | type != AV_OPT_TYPE_BOOL)) | ||
603 | ✗ | return AVERROR(EINVAL); | |
604 | |||
605 |
12/13✓ Branch 0 taken 9222 times.
✓ Branch 1 taken 45375 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 119768 times.
✓ Branch 4 taken 5811 times.
✓ Branch 5 taken 167 times.
✓ Branch 6 taken 5216 times.
✓ Branch 7 taken 2529 times.
✓ Branch 8 taken 249 times.
✓ Branch 9 taken 38 times.
✓ Branch 10 taken 198 times.
✓ Branch 11 taken 47 times.
✗ Branch 12 not taken.
|
188634 | switch (type) { |
606 | 9222 | case AV_OPT_TYPE_BOOL: | |
607 | 9222 | return set_string_bool(obj, o, val, dst); | |
608 | 45375 | case AV_OPT_TYPE_STRING: | |
609 | 45375 | return set_string(obj, o, val, dst); | |
610 | 14 | case AV_OPT_TYPE_BINARY: | |
611 | 14 | return set_string_binary(obj, o, val, dst); | |
612 | 119768 | case AV_OPT_TYPE_FLAGS: | |
613 | case AV_OPT_TYPE_INT: | ||
614 | case AV_OPT_TYPE_UINT: | ||
615 | case AV_OPT_TYPE_INT64: | ||
616 | case AV_OPT_TYPE_UINT64: | ||
617 | case AV_OPT_TYPE_FLOAT: | ||
618 | case AV_OPT_TYPE_DOUBLE: | ||
619 | case AV_OPT_TYPE_RATIONAL: | ||
620 | 119768 | return set_string_number(obj, target_obj, o, val, dst); | |
621 | 5811 | case AV_OPT_TYPE_IMAGE_SIZE: | |
622 | 5811 | return set_string_image_size(obj, o, val, dst); | |
623 | 167 | case AV_OPT_TYPE_VIDEO_RATE: { | |
624 | AVRational tmp; | ||
625 | 167 | ret = set_string_video_rate(obj, o, val, &tmp); | |
626 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 166 times.
|
167 | if (ret < 0) |
627 | 1 | return ret; | |
628 | 166 | return write_number(obj, o, dst, 1, tmp.den, tmp.num); | |
629 | } | ||
630 | 5216 | case AV_OPT_TYPE_PIXEL_FMT: | |
631 | 5216 | return set_string_pixel_fmt(obj, o, val, dst); | |
632 | 2529 | case AV_OPT_TYPE_SAMPLE_FMT: | |
633 | 2529 | return set_string_sample_fmt(obj, o, val, dst); | |
634 | 249 | case AV_OPT_TYPE_DURATION: | |
635 | { | ||
636 | 249 | int64_t usecs = 0; | |
637 |
1/2✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
|
249 | if (val) { |
638 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 248 times.
|
249 | if ((ret = av_parse_time(&usecs, val, 1)) < 0) { |
639 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val); | |
640 | 1 | return ret; | |
641 | } | ||
642 | } | ||
643 |
2/4✓ Branch 0 taken 248 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 248 times.
|
248 | if (usecs < o->min || usecs > o->max) { |
644 | ✗ | av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
645 | ✗ | usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0); | |
646 | ✗ | return AVERROR(ERANGE); | |
647 | } | ||
648 | 248 | *(int64_t *)dst = usecs; | |
649 | 248 | return 0; | |
650 | } | ||
651 | 38 | case AV_OPT_TYPE_COLOR: | |
652 | 38 | return set_string_color(obj, o, val, dst); | |
653 | 198 | case AV_OPT_TYPE_CHLAYOUT: | |
654 | 198 | ret = set_string_channel_layout(obj, o, val, dst); | |
655 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 197 times.
|
198 | if (ret < 0) { |
656 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val); | |
657 | 1 | ret = AVERROR(EINVAL); | |
658 | } | ||
659 | 198 | return ret; | |
660 | 47 | case AV_OPT_TYPE_DICT: | |
661 | 47 | return set_string_dict(obj, o, val, dst); | |
662 | } | ||
663 | |||
664 | ✗ | av_log(obj, AV_LOG_ERROR, "Invalid option type.\n"); | |
665 | ✗ | return AVERROR(EINVAL); | |
666 | } | ||
667 | |||
668 | 23 | static int opt_set_array(void *obj, void *target_obj, const AVOption *o, | |
669 | const char *val, void *dst) | ||
670 | { | ||
671 | 23 | const AVOptionArrayDef *arr = o->default_val.arr; | |
672 | 23 | const size_t elem_size = opt_elem_size[TYPE_BASE(o->type)]; | |
673 | 23 | const uint8_t sep = opt_array_sep(o); | |
674 | 23 | uint8_t *str = NULL; | |
675 | |||
676 | 23 | void *elems = NULL; | |
677 | 23 | unsigned nb_elems = 0; | |
678 | int ret; | ||
679 | |||
680 |
4/4✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 2 times.
|
23 | if (val && *val) { |
681 | 20 | str = av_malloc(strlen(val) + 1); | |
682 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (!str) |
683 | ✗ | return AVERROR(ENOMEM); | |
684 | } | ||
685 | |||
686 | // split and unescape the string | ||
687 |
4/4✓ Branch 0 taken 69 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 48 times.
✓ Branch 3 taken 21 times.
|
70 | while (val && *val) { |
688 | 48 | uint8_t *p = str; | |
689 | void *tmp; | ||
690 | |||
691 |
3/6✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
48 | if (arr && arr->size_max && nb_elems >= arr->size_max) { |
692 | ✗ | av_log(obj, AV_LOG_ERROR, | |
693 | "Cannot assign more than %u elements to array option %s\n", | ||
694 | ✗ | arr->size_max, o->name); | |
695 | ✗ | ret = AVERROR(EINVAL); | |
696 | ✗ | goto fail; | |
697 | } | ||
698 | |||
699 |
2/2✓ Branch 0 taken 485 times.
✓ Branch 1 taken 20 times.
|
505 | for (; *val; val++, p++) { |
700 |
3/4✓ Branch 0 taken 56 times.
✓ Branch 1 taken 429 times.
✓ Branch 2 taken 56 times.
✗ Branch 3 not taken.
|
485 | if (*val == '\\' && val[1]) |
701 | 56 | val++; | |
702 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 401 times.
|
429 | else if (*val == sep) { |
703 | 28 | val++; | |
704 | 28 | break; | |
705 | } | ||
706 | 457 | *p = *val; | |
707 | } | ||
708 | 48 | *p = 0; | |
709 | |||
710 | 48 | tmp = av_realloc_array(elems, nb_elems + 1, elem_size); | |
711 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
|
48 | if (!tmp) { |
712 | ✗ | ret = AVERROR(ENOMEM); | |
713 | ✗ | goto fail; | |
714 | } | ||
715 | 48 | elems = tmp; | |
716 | |||
717 | 48 | tmp = opt_array_pelem(o, elems, nb_elems); | |
718 | 48 | memset(tmp, 0, elem_size); | |
719 | |||
720 | 48 | ret = opt_set_elem(obj, target_obj, o, str, tmp); | |
721 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 47 times.
|
48 | if (ret < 0) |
722 | 1 | goto fail; | |
723 | 47 | nb_elems++; | |
724 | } | ||
725 | 22 | av_freep(&str); | |
726 | |||
727 | 22 | opt_free_array(o, dst, opt_array_pcount(dst)); | |
728 | |||
729 |
3/4✓ Branch 0 taken 17 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
|
22 | if (arr && nb_elems < arr->size_min) { |
730 | ✗ | av_log(obj, AV_LOG_ERROR, | |
731 | "Cannot assign fewer than %u elements to array option %s\n", | ||
732 | ✗ | arr->size_min, o->name); | |
733 | ✗ | ret = AVERROR(EINVAL); | |
734 | ✗ | goto fail; | |
735 | } | ||
736 | |||
737 | 22 | *((void **)dst) = elems; | |
738 | 22 | *opt_array_pcount(dst) = nb_elems; | |
739 | |||
740 | 22 | return 0; | |
741 | 1 | fail: | |
742 | 1 | av_freep(&str); | |
743 | 1 | opt_free_array(o, &elems, &nb_elems); | |
744 | 1 | return ret; | |
745 | } | ||
746 | |||
747 | 239260 | int av_opt_set(void *obj, const char *name, const char *val, int search_flags) | |
748 | { | ||
749 | void *dst, *target_obj; | ||
750 | 239260 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
751 |
3/4✓ Branch 0 taken 188597 times.
✓ Branch 1 taken 50663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 188597 times.
|
239260 | if (!o || !target_obj) |
752 | 50663 | return AVERROR_OPTION_NOT_FOUND; | |
753 | |||
754 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 188597 times.
|
188597 | if (o->flags & AV_OPT_FLAG_READONLY) |
755 | ✗ | return AVERROR(EINVAL); | |
756 | |||
757 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 188595 times.
|
188597 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
758 | 2 | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
759 | |||
760 | 188597 | dst = ((uint8_t *)target_obj) + o->offset; | |
761 | |||
762 | 188597 | return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ? | |
763 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 188586 times.
|
188597 | opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst); |
764 | } | ||
765 | |||
766 | #define OPT_EVAL_NUMBER(name, opttype, vartype) \ | ||
767 | int av_opt_eval_ ## name(void *obj, const AVOption *o, \ | ||
768 | const char *val, vartype *name ## _out) \ | ||
769 | { \ | ||
770 | if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \ | ||
771 | return AVERROR(EINVAL); \ | ||
772 | return set_string_number(obj, obj, o, val, name ## _out); \ | ||
773 | } | ||
774 | |||
775 |
3/6✓ Branch 0 taken 10788 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10788 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10788 times.
|
10788 | OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int) |
776 |
3/6✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
|
18 | OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int) |
777 | ✗ | OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned) | |
778 | ✗ | OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t) | |
779 | ✗ | OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float) | |
780 | ✗ | OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double) | |
781 | ✗ | OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational) | |
782 | |||
783 | 81954 | static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, | |
784 | int search_flags) | ||
785 | { | ||
786 | void *dst, *target_obj; | ||
787 | 81954 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
788 | |||
789 |
3/4✓ Branch 0 taken 66316 times.
✓ Branch 1 taken 15638 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 66316 times.
|
81954 | if (!o || !target_obj) |
790 | 15638 | return AVERROR_OPTION_NOT_FOUND; | |
791 | |||
792 |
2/4✓ Branch 0 taken 66316 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 66316 times.
|
66316 | if ((o->flags & AV_OPT_FLAG_READONLY) || (o->type & AV_OPT_TYPE_FLAG_ARRAY)) |
793 | ✗ | return AVERROR(EINVAL); | |
794 | |||
795 | 66316 | dst = ((uint8_t *)target_obj) + o->offset; | |
796 | 66316 | return write_number(obj, o, dst, num, den, intnum); | |
797 | } | ||
798 | |||
799 | 81954 | int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags) | |
800 | { | ||
801 | 81954 | return set_number(obj, name, 1, 1, val, search_flags); | |
802 | } | ||
803 | |||
804 | ✗ | int av_opt_set_double(void *obj, const char *name, double val, int search_flags) | |
805 | { | ||
806 | ✗ | return set_number(obj, name, val, 1, 1, search_flags); | |
807 | } | ||
808 | |||
809 | ✗ | int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) | |
810 | { | ||
811 | ✗ | return set_number(obj, name, val.num, val.den, 1, search_flags); | |
812 | } | ||
813 | |||
814 | 24 | int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags) | |
815 | { | ||
816 | void *target_obj; | ||
817 | 24 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
818 | uint8_t *ptr; | ||
819 | uint8_t **dst; | ||
820 | int *lendst; | ||
821 | |||
822 |
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) |
823 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
824 | |||
825 |
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) |
826 | ✗ | return AVERROR(EINVAL); | |
827 | |||
828 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | ptr = len ? av_malloc(len) : NULL; |
829 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | if (len && !ptr) |
830 | ✗ | return AVERROR(ENOMEM); | |
831 | |||
832 | 24 | dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset); | |
833 | 24 | lendst = (int *)(dst + 1); | |
834 | |||
835 | 24 | av_free(*dst); | |
836 | 24 | *dst = ptr; | |
837 | 24 | *lendst = len; | |
838 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (len) |
839 | 24 | memcpy(ptr, val, len); | |
840 | |||
841 | 24 | return 0; | |
842 | } | ||
843 | |||
844 | ✗ | int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags) | |
845 | { | ||
846 | void *target_obj; | ||
847 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
848 | |||
849 | ✗ | if (!o || !target_obj) | |
850 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
851 | ✗ | if (o->type != AV_OPT_TYPE_IMAGE_SIZE) { | |
852 | ✗ | av_log(obj, AV_LOG_ERROR, | |
853 | ✗ | "The value set by option '%s' is not an image size.\n", o->name); | |
854 | ✗ | return AVERROR(EINVAL); | |
855 | } | ||
856 | ✗ | if (w<0 || h<0) { | |
857 | ✗ | av_log(obj, AV_LOG_ERROR, | |
858 | ✗ | "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name); | |
859 | ✗ | return AVERROR(EINVAL); | |
860 | } | ||
861 | ✗ | *(int *)(((uint8_t *)target_obj) + o->offset) = w; | |
862 | ✗ | *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h; | |
863 | ✗ | return 0; | |
864 | } | ||
865 | |||
866 | ✗ | int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags) | |
867 | { | ||
868 | void *target_obj; | ||
869 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
870 | |||
871 | ✗ | if (!o || !target_obj) | |
872 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
873 | ✗ | if (o->type != AV_OPT_TYPE_VIDEO_RATE) { | |
874 | ✗ | av_log(obj, AV_LOG_ERROR, | |
875 | "The value set by option '%s' is not a video rate.\n", | ||
876 | ✗ | o->name); | |
877 | ✗ | return AVERROR(EINVAL); | |
878 | } | ||
879 | ✗ | if (val.num <= 0 || val.den <= 0) | |
880 | ✗ | return AVERROR(EINVAL); | |
881 | ✗ | return set_number(obj, name, val.num, val.den, 1, search_flags); | |
882 | } | ||
883 | |||
884 | ✗ | static int set_format(void *obj, const char *name, int fmt, int search_flags, | |
885 | enum AVOptionType type, const char *desc, int nb_fmts) | ||
886 | { | ||
887 | void *target_obj; | ||
888 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, | |
889 | search_flags, &target_obj); | ||
890 | int min, max; | ||
891 | |||
892 | ✗ | if (!o || !target_obj) | |
893 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
894 | ✗ | if (o->type != type) { | |
895 | ✗ | av_log(obj, AV_LOG_ERROR, | |
896 | "The value set by option '%s' is not a %s format", name, desc); | ||
897 | ✗ | return AVERROR(EINVAL); | |
898 | } | ||
899 | |||
900 | ✗ | min = FFMAX(o->min, -1); | |
901 | ✗ | max = FFMIN(o->max, nb_fmts-1); | |
902 | |||
903 | ✗ | if (fmt < min || fmt > max) { | |
904 | ✗ | av_log(obj, AV_LOG_ERROR, | |
905 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
906 | fmt, name, desc, min, max); | ||
907 | ✗ | return AVERROR(ERANGE); | |
908 | } | ||
909 | ✗ | *(int *)(((uint8_t *)target_obj) + o->offset) = fmt; | |
910 | ✗ | return 0; | |
911 | } | ||
912 | |||
913 | ✗ | int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags) | |
914 | { | ||
915 | ✗ | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB); | |
916 | } | ||
917 | |||
918 | ✗ | int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags) | |
919 | { | ||
920 | ✗ | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB); | |
921 | } | ||
922 | |||
923 | ✗ | int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, | |
924 | int search_flags) | ||
925 | { | ||
926 | void *target_obj; | ||
927 | AVDictionary **dst; | ||
928 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
929 | |||
930 | ✗ | if (!o || !target_obj) | |
931 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
932 | ✗ | if (o->flags & AV_OPT_FLAG_READONLY) | |
933 | ✗ | return AVERROR(EINVAL); | |
934 | |||
935 | ✗ | dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset); | |
936 | ✗ | av_dict_free(dst); | |
937 | |||
938 | ✗ | return av_dict_copy(dst, val, 0); | |
939 | } | ||
940 | |||
941 | 2872 | int av_opt_set_chlayout(void *obj, const char *name, | |
942 | const AVChannelLayout *channel_layout, | ||
943 | int search_flags) | ||
944 | { | ||
945 | void *target_obj; | ||
946 | 2872 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
947 | AVChannelLayout *dst; | ||
948 | |||
949 |
2/4✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2872 times.
|
2872 | if (!o || !target_obj) |
950 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2872 times.
|
2872 | if (o->flags & AV_OPT_FLAG_READONLY) |
952 | ✗ | return AVERROR(EINVAL); | |
953 | |||
954 | 2872 | dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset); | |
955 | |||
956 | 2872 | return av_channel_layout_copy(dst, channel_layout); | |
957 | } | ||
958 | |||
959 | 5 | static void format_duration(char *buf, size_t size, int64_t d) | |
960 | { | ||
961 | char *e; | ||
962 | |||
963 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | av_assert0(size >= 25); |
964 |
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) { |
965 | ✗ | *(buf++) = '-'; | |
966 | ✗ | size--; | |
967 | ✗ | d = -d; | |
968 | } | ||
969 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (d == INT64_MAX) |
970 | ✗ | snprintf(buf, size, "INT64_MAX"); | |
971 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d == INT64_MIN) |
972 | ✗ | snprintf(buf, size, "INT64_MIN"); | |
973 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > (int64_t)3600*1000000) |
974 | ✗ | snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000, | |
975 | ✗ | (int)((d / 60000000) % 60), | |
976 | ✗ | (int)((d / 1000000) % 60), | |
977 | ✗ | (int)(d % 1000000)); | |
978 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > 60*1000000) |
979 | ✗ | snprintf(buf, size, "%d:%02d.%06d", | |
980 | ✗ | (int)(d / 60000000), | |
981 | ✗ | (int)((d / 1000000) % 60), | |
982 | ✗ | (int)(d % 1000000)); | |
983 | else | ||
984 | 5 | snprintf(buf, size, "%d.%06d", | |
985 | 5 | (int)(d / 1000000), | |
986 | 5 | (int)(d % 1000000)); | |
987 | 5 | e = buf + strlen(buf); | |
988 |
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') |
989 | 15 | *(--e) = 0; | |
990 |
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] == '.') |
991 | ✗ | *(--e) = 0; | |
992 | 5 | } | |
993 | |||
994 | 7893 | static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, | |
995 | void *dst, int search_flags) | ||
996 | { | ||
997 | int ret; | ||
998 | |||
999 |
17/20✓ Branch 0 taken 30 times.
✓ Branch 1 taken 3805 times.
✓ Branch 2 taken 3911 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 26 times.
✓ Branch 11 taken 12 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 8 times.
✓ Branch 18 taken 22 times.
✗ Branch 19 not taken.
|
7893 | switch (TYPE_BASE(o->type)) { |
1000 | 30 | case AV_OPT_TYPE_BOOL: | |
1001 | 30 | ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst)); | |
1002 | 30 | break; | |
1003 | 3805 | case AV_OPT_TYPE_FLAGS: | |
1004 | 3805 | ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst); | |
1005 | 3805 | break; | |
1006 | 3911 | case AV_OPT_TYPE_INT: | |
1007 | 3911 | ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst); | |
1008 | 3911 | break; | |
1009 | 19 | case AV_OPT_TYPE_UINT: | |
1010 | 19 | ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst); | |
1011 | 19 | break; | |
1012 | 18 | case AV_OPT_TYPE_INT64: | |
1013 | 18 | ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst); | |
1014 | 18 | break; | |
1015 | ✗ | case AV_OPT_TYPE_UINT64: | |
1016 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst); | |
1017 | ✗ | break; | |
1018 | 5 | case AV_OPT_TYPE_FLOAT: | |
1019 | 5 | ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst); | |
1020 | 5 | break; | |
1021 | 5 | case AV_OPT_TYPE_DOUBLE: | |
1022 | 5 | ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst); | |
1023 | 5 | break; | |
1024 | 12 | case AV_OPT_TYPE_VIDEO_RATE: | |
1025 | case AV_OPT_TYPE_RATIONAL: | ||
1026 | 12 | ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den); | |
1027 | 12 | break; | |
1028 | ✗ | case AV_OPT_TYPE_CONST: | |
1029 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64); | |
1030 | ✗ | break; | |
1031 | 26 | case AV_OPT_TYPE_STRING: | |
1032 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (*(uint8_t **)dst) { |
1033 | 26 | *pbuf = av_strdup(*(uint8_t **)dst); | |
1034 | ✗ | } else if (search_flags & AV_OPT_ALLOW_NULL) { | |
1035 | ✗ | *pbuf = NULL; | |
1036 | ✗ | return 0; | |
1037 | } else { | ||
1038 | ✗ | *pbuf = av_strdup(""); | |
1039 | } | ||
1040 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | return *pbuf ? 0 : AVERROR(ENOMEM); |
1041 | 12 | case AV_OPT_TYPE_BINARY: { | |
1042 | const uint8_t *bin; | ||
1043 | int len; | ||
1044 | |||
1045 |
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)) { |
1046 | ✗ | *pbuf = NULL; | |
1047 | ✗ | return 0; | |
1048 | } | ||
1049 | 12 | len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *)); | |
1050 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if ((uint64_t)len * 2 + 1 > INT_MAX) |
1051 | ✗ | return AVERROR(EINVAL); | |
1052 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if (!(*pbuf = av_malloc(len * 2 + 1))) |
1053 | ✗ | return AVERROR(ENOMEM); | |
1054 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
|
12 | if (!len) { |
1055 | 8 | *pbuf[0] = '\0'; | |
1056 | 8 | return 0; | |
1057 | } | ||
1058 | 4 | bin = *(uint8_t **)dst; | |
1059 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (int i = 0; i < len; i++) |
1060 | 16 | snprintf(*pbuf + i * 2, 3, "%02X", bin[i]); | |
1061 | 4 | return 0; | |
1062 | } | ||
1063 | 4 | case AV_OPT_TYPE_IMAGE_SIZE: | |
1064 | 4 | ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]); | |
1065 | 4 | break; | |
1066 | 4 | case AV_OPT_TYPE_PIXEL_FMT: | |
1067 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none")); | |
1068 | 4 | break; | |
1069 | 4 | case AV_OPT_TYPE_SAMPLE_FMT: | |
1070 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none")); | |
1071 | 4 | break; | |
1072 | 4 | case AV_OPT_TYPE_DURATION: { | |
1073 | 4 | int64_t i64 = *(int64_t *)dst; | |
1074 | 4 | format_duration(*pbuf, buf_len, i64); | |
1075 | 4 | ret = strlen(*pbuf); // no overflow possible, checked by an assert | |
1076 | 4 | break; | |
1077 | } | ||
1078 | 4 | case AV_OPT_TYPE_COLOR: | |
1079 | 4 | ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x", | |
1080 | 4 | (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1], | |
1081 | 4 | (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]); | |
1082 | 4 | break; | |
1083 | 8 | case AV_OPT_TYPE_CHLAYOUT: | |
1084 | 8 | ret = av_channel_layout_describe(dst, *pbuf, buf_len); | |
1085 | 8 | break; | |
1086 | 22 | case AV_OPT_TYPE_DICT: | |
1087 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
22 | if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) { |
1088 | ✗ | *pbuf = NULL; | |
1089 | ✗ | return 0; | |
1090 | } | ||
1091 | 22 | return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':'); | |
1092 | ✗ | default: | |
1093 | ✗ | return AVERROR(EINVAL); | |
1094 | } | ||
1095 | |||
1096 | 7833 | return ret; | |
1097 | } | ||
1098 | |||
1099 | 23 | static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val) | |
1100 | { | ||
1101 | 23 | const unsigned count = *opt_array_pcount(dst); | |
1102 | 23 | const uint8_t sep = opt_array_sep(o); | |
1103 | |||
1104 | 23 | uint8_t *str = NULL; | |
1105 | 23 | size_t str_len = 0; | |
1106 | int ret; | ||
1107 | |||
1108 | 23 | *out_val = NULL; | |
1109 | |||
1110 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 23 times.
|
53 | for (unsigned i = 0; i < count; i++) { |
1111 | 30 | uint8_t buf[128], *out = buf; | |
1112 | size_t out_len; | ||
1113 | |||
1114 | 30 | ret = opt_get_elem(o, &out, sizeof(buf), | |
1115 | opt_array_pelem(o, *(void **)dst, i), 0); | ||
1116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) |
1117 | ✗ | goto fail; | |
1118 | |||
1119 | 30 | out_len = strlen(out); | |
1120 |
3/4✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
|
30 | if (out_len > SIZE_MAX / 2 - !!i || |
1121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | !!i + out_len * 2 > SIZE_MAX - str_len - 1) { |
1122 | ✗ | ret = AVERROR(ERANGE); | |
1123 | ✗ | goto fail; | |
1124 | } | ||
1125 | |||
1126 | // terminator escaping separator | ||
1127 | // ↓ ↓ ↓ | ||
1128 | 30 | ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i); | |
1129 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) |
1130 | ✗ | goto fail; | |
1131 | |||
1132 | // add separator if needed | ||
1133 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
|
30 | if (i) |
1134 | 18 | str[str_len++] = sep; | |
1135 | |||
1136 | // escape the element | ||
1137 |
2/2✓ Branch 0 taken 258 times.
✓ Branch 1 taken 30 times.
|
288 | for (unsigned j = 0; j < out_len; j++) { |
1138 | 258 | uint8_t val = out[j]; | |
1139 |
4/4✓ Branch 0 taken 246 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 216 times.
|
258 | if (val == sep || val == '\\') |
1140 | 42 | str[str_len++] = '\\'; | |
1141 | 258 | str[str_len++] = val; | |
1142 | } | ||
1143 | 30 | str[str_len] = 0; | |
1144 | |||
1145 | 30 | fail: | |
1146 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | if (out != buf) |
1147 | 30 | av_freep(&out); | |
1148 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) { |
1149 | ✗ | av_freep(&str); | |
1150 | ✗ | return ret; | |
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | 23 | *out_val = str; | |
1155 | |||
1156 | 23 | return 0; | |
1157 | } | ||
1158 | |||
1159 | 12077 | int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) | |
1160 | { | ||
1161 | void *dst, *target_obj; | ||
1162 | 12077 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1163 | uint8_t *out, buf[128]; | ||
1164 | int ret; | ||
1165 | |||
1166 |
4/8✓ Branch 0 taken 7877 times.
✓ Branch 1 taken 4200 times.
✓ Branch 2 taken 7877 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7877 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
12077 | if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) |
1167 | 4200 | return AVERROR_OPTION_NOT_FOUND; | |
1168 | |||
1169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7877 times.
|
7877 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
1170 | ✗ | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
1171 | |||
1172 | 7877 | dst = (uint8_t *)target_obj + o->offset; | |
1173 | |||
1174 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 7863 times.
|
7877 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1175 | 14 | ret = opt_get_array(o, dst, out_val); | |
1176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (ret < 0) |
1177 | ✗ | return ret; | |
1178 |
4/4✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 times.
|
14 | if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) { |
1179 | 5 | *out_val = av_strdup(""); | |
1180 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!*out_val) |
1181 | ✗ | return AVERROR(ENOMEM); | |
1182 | } | ||
1183 | 14 | return 0; | |
1184 | } | ||
1185 | |||
1186 | 7863 | buf[0] = 0; | |
1187 | 7863 | out = buf; | |
1188 | 7863 | ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags); | |
1189 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7863 times.
|
7863 | if (ret < 0) |
1190 | ✗ | return ret; | |
1191 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 7833 times.
|
7863 | if (out != buf) { |
1192 | 30 | *out_val = out; | |
1193 | 30 | return 0; | |
1194 | } | ||
1195 | |||
1196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7833 times.
|
7833 | if (ret >= sizeof(buf)) |
1197 | ✗ | return AVERROR(EINVAL); | |
1198 | 7833 | *out_val = av_strdup(out); | |
1199 |
1/2✓ Branch 0 taken 7833 times.
✗ Branch 1 not taken.
|
7833 | return *out_val ? 0 : AVERROR(ENOMEM); |
1200 | } | ||
1201 | |||
1202 | 18684 | static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, | |
1203 | int search_flags) | ||
1204 | { | ||
1205 | void *dst, *target_obj; | ||
1206 | 18684 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1207 |
3/4✓ Branch 0 taken 18670 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18670 times.
|
18684 | if (!o || !target_obj) |
1208 | 14 | return AVERROR_OPTION_NOT_FOUND; | |
1209 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18670 times.
|
18670 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1210 | ✗ | return AVERROR(EINVAL); | |
1211 | |||
1212 | 18670 | dst = ((uint8_t *)target_obj) + o->offset; | |
1213 | |||
1214 | 18670 | return read_number(o, dst, num, den, intnum); | |
1215 | } | ||
1216 | |||
1217 | 18684 | int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val) | |
1218 | { | ||
1219 | 18684 | int64_t intnum = 1; | |
1220 | 18684 | double num = 1; | |
1221 | 18684 | int ret, den = 1; | |
1222 | |||
1223 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 18670 times.
|
18684 | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) |
1224 | 14 | return ret; | |
1225 |
1/2✓ Branch 0 taken 18670 times.
✗ Branch 1 not taken.
|
18670 | if (num == den) |
1226 | 18670 | *out_val = intnum; | |
1227 | else | ||
1228 | ✗ | *out_val = num * intnum / den; | |
1229 | 18670 | return 0; | |
1230 | } | ||
1231 | |||
1232 | ✗ | int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val) | |
1233 | { | ||
1234 | ✗ | int64_t intnum = 1; | |
1235 | ✗ | double num = 1; | |
1236 | ✗ | int ret, den = 1; | |
1237 | |||
1238 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
1239 | ✗ | return ret; | |
1240 | ✗ | *out_val = num * intnum / den; | |
1241 | ✗ | return 0; | |
1242 | } | ||
1243 | |||
1244 | ✗ | int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val) | |
1245 | { | ||
1246 | ✗ | int64_t intnum = 1; | |
1247 | ✗ | double num = 1; | |
1248 | ✗ | int ret, den = 1; | |
1249 | |||
1250 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
1251 | ✗ | return ret; | |
1252 | |||
1253 | ✗ | if (num == 1.0 && (int)intnum == intnum) | |
1254 | ✗ | *out_val = (AVRational){intnum, den}; | |
1255 | else | ||
1256 | ✗ | *out_val = av_d2q(num*intnum/den, 1<<24); | |
1257 | ✗ | return 0; | |
1258 | } | ||
1259 | |||
1260 | ✗ | int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out) | |
1261 | { | ||
1262 | void *dst, *target_obj; | ||
1263 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1264 | ✗ | if (!o || !target_obj) | |
1265 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1266 | ✗ | if (o->type != AV_OPT_TYPE_IMAGE_SIZE) { | |
1267 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1268 | "The value for option '%s' is not a image size.\n", name); | ||
1269 | ✗ | return AVERROR(EINVAL); | |
1270 | } | ||
1271 | |||
1272 | ✗ | dst = ((uint8_t*)target_obj) + o->offset; | |
1273 | ✗ | if (w_out) *w_out = *(int *)dst; | |
1274 | ✗ | if (h_out) *h_out = *((int *)dst+1); | |
1275 | ✗ | return 0; | |
1276 | } | ||
1277 | |||
1278 | ✗ | int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val) | |
1279 | { | ||
1280 | ✗ | int64_t intnum = 1; | |
1281 | ✗ | double num = 1; | |
1282 | ✗ | int ret, den = 1; | |
1283 | |||
1284 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
1285 | ✗ | return ret; | |
1286 | |||
1287 | ✗ | if (num == 1.0 && (int)intnum == intnum) | |
1288 | ✗ | *out_val = (AVRational) { intnum, den }; | |
1289 | else | ||
1290 | ✗ | *out_val = av_d2q(num * intnum / den, 1 << 24); | |
1291 | ✗ | return 0; | |
1292 | } | ||
1293 | |||
1294 | 2636 | static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, | |
1295 | enum AVOptionType type, const char *desc) | ||
1296 | { | ||
1297 | void *dst, *target_obj; | ||
1298 | 2636 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1299 |
2/4✓ Branch 0 taken 2636 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2636 times.
|
2636 | if (!o || !target_obj) |
1300 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2636 times.
|
2636 | if (o->type != type) { |
1302 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1303 | "The value for option '%s' is not a %s format.\n", desc, name); | ||
1304 | ✗ | return AVERROR(EINVAL); | |
1305 | } | ||
1306 | |||
1307 | 2636 | dst = ((uint8_t*)target_obj) + o->offset; | |
1308 | 2636 | *out_fmt = *(int *)dst; | |
1309 | 2636 | return 0; | |
1310 | } | ||
1311 | |||
1312 | ✗ | int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt) | |
1313 | { | ||
1314 | ✗ | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel"); | |
1315 | } | ||
1316 | |||
1317 | 2636 | int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt) | |
1318 | { | ||
1319 | 2636 | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample"); | |
1320 | } | ||
1321 | |||
1322 | 2636 | int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl) | |
1323 | { | ||
1324 | void *dst, *target_obj; | ||
1325 | 2636 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1326 |
2/4✓ Branch 0 taken 2636 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2636 times.
|
2636 | if (!o || !target_obj) |
1327 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2636 times.
|
2636 | if (o->type != AV_OPT_TYPE_CHLAYOUT) { |
1329 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1330 | "The value for option '%s' is not a channel layout.\n", name); | ||
1331 | ✗ | return AVERROR(EINVAL); | |
1332 | } | ||
1333 | |||
1334 | 2636 | dst = ((uint8_t*)target_obj) + o->offset; | |
1335 | 2636 | return av_channel_layout_copy(cl, dst); | |
1336 | } | ||
1337 | |||
1338 | 7176 | int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val) | |
1339 | { | ||
1340 | void *target_obj; | ||
1341 | AVDictionary *src; | ||
1342 | 7176 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1343 | |||
1344 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7176 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7176 | if (!o || !target_obj) |
1345 | 7176 | return AVERROR_OPTION_NOT_FOUND; | |
1346 | ✗ | if (o->type != AV_OPT_TYPE_DICT) | |
1347 | ✗ | return AVERROR(EINVAL); | |
1348 | |||
1349 | ✗ | src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset); | |
1350 | |||
1351 | ✗ | return av_dict_copy(out_val, src, 0); | |
1352 | } | ||
1353 | |||
1354 | ✗ | int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) | |
1355 | { | ||
1356 | ✗ | const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); | |
1357 | ✗ | const AVOption *flag = av_opt_find(obj, flag_name, | |
1358 | field ? field->unit : NULL, 0, 0); | ||
1359 | int64_t res; | ||
1360 | |||
1361 | ✗ | if (!field || !flag || flag->type != AV_OPT_TYPE_CONST || | |
1362 | ✗ | av_opt_get_int(obj, field_name, 0, &res) < 0) | |
1363 | ✗ | return 0; | |
1364 | ✗ | return res & flag->default_val.i64; | |
1365 | } | ||
1366 | |||
1367 | 4 | static void log_int_value(void *av_log_obj, int level, int64_t i) | |
1368 | { | ||
1369 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (i == INT_MAX) { |
1370 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
1371 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT_MIN) { |
1372 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
1373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == UINT32_MAX) { |
1374 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
1375 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MAX) { |
1376 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
1377 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MIN) { |
1378 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
1379 | } else { | ||
1380 | 4 | av_log(av_log_obj, level, "%"PRId64, i); | |
1381 | } | ||
1382 | 4 | } | |
1383 | |||
1384 | 16 | static void log_value(void *av_log_obj, int level, double d) | |
1385 | { | ||
1386 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (d == INT_MAX) { |
1387 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
1388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT_MIN) { |
1389 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
1390 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == UINT32_MAX) { |
1391 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
1392 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == (double)INT64_MAX) { |
1393 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT64_MIN) { |
1395 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
1396 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MAX) { |
1397 | ✗ | av_log(av_log_obj, level, "FLT_MAX"); | |
1398 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MIN) { |
1399 | ✗ | av_log(av_log_obj, level, "FLT_MIN"); | |
1400 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MAX) { |
1401 | ✗ | av_log(av_log_obj, level, "-FLT_MAX"); | |
1402 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MIN) { |
1403 | ✗ | av_log(av_log_obj, level, "-FLT_MIN"); | |
1404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MAX) { |
1405 | ✗ | av_log(av_log_obj, level, "DBL_MAX"); | |
1406 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MIN) { |
1407 | ✗ | av_log(av_log_obj, level, "DBL_MIN"); | |
1408 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MAX) { |
1409 | ✗ | av_log(av_log_obj, level, "-DBL_MAX"); | |
1410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MIN) { |
1411 | ✗ | av_log(av_log_obj, level, "-DBL_MIN"); | |
1412 | } else { | ||
1413 | 16 | av_log(av_log_obj, level, "%g", d); | |
1414 | } | ||
1415 | 16 | } | |
1416 | |||
1417 | 4 | static const char *get_opt_const_name(void *obj, const char *unit, int64_t value) | |
1418 | { | ||
1419 | 4 | const AVOption *opt = NULL; | |
1420 | |||
1421 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (!unit) |
1422 | 4 | return NULL; | |
1423 | ✗ | while ((opt = av_opt_next(obj, opt))) | |
1424 | ✗ | if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && | |
1425 | ✗ | opt->default_val.i64 == value) | |
1426 | ✗ | return opt->name; | |
1427 | ✗ | return NULL; | |
1428 | } | ||
1429 | |||
1430 | 1 | static char *get_opt_flags_string(void *obj, const char *unit, int64_t value) | |
1431 | { | ||
1432 | 1 | const AVOption *opt = NULL; | |
1433 | char flags[512]; | ||
1434 | |||
1435 | 1 | flags[0] = 0; | |
1436 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!unit) |
1437 | ✗ | return NULL; | |
1438 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 1 times.
|
32 | while ((opt = av_opt_next(obj, opt))) { |
1439 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
31 | if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && |
1440 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | opt->default_val.i64 & value) { |
1441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (flags[0]) |
1442 | ✗ | av_strlcatf(flags, sizeof(flags), "+"); | |
1443 | 1 | av_strlcatf(flags, sizeof(flags), "%s", opt->name); | |
1444 | } | ||
1445 | } | ||
1446 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (flags[0]) |
1447 | 1 | return av_strdup(flags); | |
1448 | ✗ | return NULL; | |
1449 | } | ||
1450 | |||
1451 | 31 | static void log_type(void *av_log_obj, const AVOption *o, | |
1452 | enum AVOptionType parent_type) | ||
1453 | { | ||
1454 | 31 | const char *desc[] = { | |
1455 | [AV_OPT_TYPE_FLAGS] = "<flags>", | ||
1456 | [AV_OPT_TYPE_INT] = "<int>", | ||
1457 | [AV_OPT_TYPE_INT64] = "<int64>", | ||
1458 | [AV_OPT_TYPE_UINT] = "<unsigned>", | ||
1459 | [AV_OPT_TYPE_UINT64] = "<uint64>", | ||
1460 | [AV_OPT_TYPE_DOUBLE] = "<double>", | ||
1461 | [AV_OPT_TYPE_FLOAT] = "<float>", | ||
1462 | [AV_OPT_TYPE_STRING] = "<string>", | ||
1463 | [AV_OPT_TYPE_RATIONAL] = "<rational>", | ||
1464 | [AV_OPT_TYPE_BINARY] = "<binary>", | ||
1465 | [AV_OPT_TYPE_DICT] = "<dictionary>", | ||
1466 | [AV_OPT_TYPE_IMAGE_SIZE] = "<image_size>", | ||
1467 | [AV_OPT_TYPE_VIDEO_RATE] = "<video_rate>", | ||
1468 | [AV_OPT_TYPE_PIXEL_FMT] = "<pix_fmt>", | ||
1469 | [AV_OPT_TYPE_SAMPLE_FMT] = "<sample_fmt>", | ||
1470 | [AV_OPT_TYPE_DURATION] = "<duration>", | ||
1471 | [AV_OPT_TYPE_COLOR] = "<color>", | ||
1472 | [AV_OPT_TYPE_CHLAYOUT] = "<channel_layout>", | ||
1473 | [AV_OPT_TYPE_BOOL] = "<boolean>", | ||
1474 | }; | ||
1475 | 31 | const enum AVOptionType type = TYPE_BASE(o->type); | |
1476 | |||
1477 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
31 | if (o->type == AV_OPT_TYPE_CONST && TYPE_BASE(parent_type) == AV_OPT_TYPE_INT) |
1478 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64); | |
1479 |
3/4✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 3 times.
|
31 | else if (type < FF_ARRAY_ELEMS(desc) && desc[type]) { |
1480 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 25 times.
|
28 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1481 | 3 | av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", desc[type]); | |
1482 | else | ||
1483 | 25 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[type]); | |
1484 | } | ||
1485 | else | ||
1486 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); | |
1487 | 31 | } | |
1488 | |||
1489 | 31 | static void log_default(void *obj, void *av_log_obj, const AVOption *opt) | |
1490 | { | ||
1491 |
4/4✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 25 times.
|
31 | if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY) |
1492 | 6 | return; | |
1493 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | if ((opt->type == AV_OPT_TYPE_COLOR || |
1494 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
|
24 | opt->type == AV_OPT_TYPE_IMAGE_SIZE || |
1495 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
|
23 | opt->type == AV_OPT_TYPE_STRING || |
1496 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 2 times.
|
21 | opt->type == AV_OPT_TYPE_DICT || |
1497 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
|
19 | opt->type == AV_OPT_TYPE_CHLAYOUT || |
1498 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
|
18 | opt->type == AV_OPT_TYPE_VIDEO_RATE) && |
1499 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | !opt->default_val.str) |
1500 | 1 | return; | |
1501 | |||
1502 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
|
24 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1503 | 3 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
1504 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
3 | if (arr && arr->def) |
1505 | 2 | av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def); | |
1506 | 3 | return; | |
1507 | } | ||
1508 | |||
1509 | 21 | av_log(av_log_obj, AV_LOG_INFO, " (default "); | |
1510 |
9/10✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 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.
|
21 | switch (opt->type) { |
1511 | 3 | case AV_OPT_TYPE_BOOL: | |
1512 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64)); | |
1513 | 3 | break; | |
1514 | 1 | case AV_OPT_TYPE_FLAGS: { | |
1515 | 1 | char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64); | |
1516 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (def_flags) { |
1517 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags); | |
1518 | 1 | av_freep(&def_flags); | |
1519 | } else { | ||
1520 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64); | |
1521 | } | ||
1522 | 1 | break; | |
1523 | } | ||
1524 | 1 | case AV_OPT_TYPE_DURATION: { | |
1525 | char buf[25]; | ||
1526 | 1 | format_duration(buf, sizeof(buf), opt->default_val.i64); | |
1527 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", buf); | |
1528 | 1 | break; | |
1529 | } | ||
1530 | 4 | case AV_OPT_TYPE_UINT: | |
1531 | case AV_OPT_TYPE_INT: | ||
1532 | case AV_OPT_TYPE_UINT64: | ||
1533 | case AV_OPT_TYPE_INT64: { | ||
1534 | 4 | const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64); | |
1535 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (def_const) |
1536 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%s", def_const); | |
1537 | else | ||
1538 | 4 | log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64); | |
1539 | 4 | break; | |
1540 | } | ||
1541 | 2 | case AV_OPT_TYPE_DOUBLE: | |
1542 | case AV_OPT_TYPE_FLOAT: | ||
1543 | 2 | log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl); | |
1544 | 2 | break; | |
1545 | 1 | case AV_OPT_TYPE_RATIONAL: { | |
1546 | 1 | AVRational q = av_d2q(opt->default_val.dbl, INT_MAX); | |
1547 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); } | |
1548 | 1 | break; | |
1549 | 1 | case AV_OPT_TYPE_PIXEL_FMT: | |
1550 | 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")); | |
1551 | 1 | break; | |
1552 | 1 | case AV_OPT_TYPE_SAMPLE_FMT: | |
1553 | 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")); | |
1554 | 1 | break; | |
1555 | 7 | case AV_OPT_TYPE_COLOR: | |
1556 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
1557 | case AV_OPT_TYPE_STRING: | ||
1558 | case AV_OPT_TYPE_DICT: | ||
1559 | case AV_OPT_TYPE_VIDEO_RATE: | ||
1560 | case AV_OPT_TYPE_CHLAYOUT: | ||
1561 | 7 | av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str); | |
1562 | 7 | break; | |
1563 | } | ||
1564 | 21 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
1565 | } | ||
1566 | |||
1567 | 2 | static void opt_list(void *obj, void *av_log_obj, const char *unit, | |
1568 | int req_flags, int rej_flags, enum AVOptionType parent_type) | ||
1569 | { | ||
1570 | 2 | const AVOption *opt = NULL; | |
1571 | AVOptionRanges *r; | ||
1572 | int i; | ||
1573 | |||
1574 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
|
64 | while ((opt = av_opt_next(obj, opt))) { |
1575 |
2/4✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
|
62 | if (!(opt->flags & req_flags) || (opt->flags & rej_flags)) |
1576 | ✗ | continue; | |
1577 | |||
1578 | /* Don't print CONST's on level one. | ||
1579 | * Don't print anything but CONST's on level two. | ||
1580 | * Only print items from the requested unit. | ||
1581 | */ | ||
1582 |
4/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 28 times.
|
62 | if (!unit && opt->type == AV_OPT_TYPE_CONST) |
1583 | 3 | continue; | |
1584 |
4/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 3 times.
|
59 | else if (unit && opt->type != AV_OPT_TYPE_CONST) |
1585 | 28 | continue; | |
1586 |
4/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
31 | else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit)) |
1587 | ✗ | continue; | |
1588 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
31 | else if (unit && opt->type == AV_OPT_TYPE_CONST) |
1589 | 3 | av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); | |
1590 | else | ||
1591 | 28 | av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ", | |
1592 | 28 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-", | |
1593 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | opt->name); |
1594 | |||
1595 | 31 | log_type(av_log_obj, opt, parent_type); | |
1596 | |||
1597 | 341 | av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c", | |
1598 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
|
31 | (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.', |
1599 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.', |
1600 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.', |
1601 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.', |
1602 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.', |
1603 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.', |
1604 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.', |
1605 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.', |
1606 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.', |
1607 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
|
31 | (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.', |
1608 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.'); |
1609 | |||
1610 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (opt->help) |
1611 | 31 | av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
1612 | |||
1613 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 2 taken 13 times.
|
31 | if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) { |
1614 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 11 times.
|
18 | switch (opt->type) { |
1615 | 7 | case AV_OPT_TYPE_INT: | |
1616 | case AV_OPT_TYPE_UINT: | ||
1617 | case AV_OPT_TYPE_INT64: | ||
1618 | case AV_OPT_TYPE_UINT64: | ||
1619 | case AV_OPT_TYPE_DOUBLE: | ||
1620 | case AV_OPT_TYPE_FLOAT: | ||
1621 | case AV_OPT_TYPE_RATIONAL: | ||
1622 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | for (i = 0; i < r->nb_ranges; i++) { |
1623 | 7 | av_log(av_log_obj, AV_LOG_INFO, " (from "); | |
1624 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min); | |
1625 | 7 | av_log(av_log_obj, AV_LOG_INFO, " to "); | |
1626 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max); | |
1627 | 7 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
1628 | } | ||
1629 | 7 | break; | |
1630 | } | ||
1631 | 18 | av_opt_freep_ranges(&r); | |
1632 | } | ||
1633 | |||
1634 | 31 | log_default(obj, av_log_obj, opt); | |
1635 | |||
1636 | 31 | av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
1637 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
31 | if (opt->unit && opt->type != AV_OPT_TYPE_CONST) |
1638 | 1 | opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type); | |
1639 | } | ||
1640 | 2 | } | |
1641 | |||
1642 | 1 | int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags) | |
1643 | { | ||
1644 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!obj) |
1645 | ✗ | return -1; | |
1646 | |||
1647 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name); | |
1648 | |||
1649 | 1 | opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1); | |
1650 | |||
1651 | 1 | return 0; | |
1652 | } | ||
1653 | |||
1654 | 299088 | void av_opt_set_defaults(void *s) | |
1655 | { | ||
1656 | 299088 | av_opt_set_defaults2(s, 0, 0); | |
1657 | 299088 | } | |
1658 | |||
1659 | 356504 | void av_opt_set_defaults2(void *s, int mask, int flags) | |
1660 | { | ||
1661 | 356504 | const AVOption *opt = NULL; | |
1662 |
2/2✓ Branch 1 taken 23733649 times.
✓ Branch 2 taken 356504 times.
|
24090153 | while ((opt = av_opt_next(s, opt))) { |
1663 | 23733649 | void *dst = ((uint8_t*)s) + opt->offset; | |
1664 | |||
1665 |
2/2✓ Branch 0 taken 2896338 times.
✓ Branch 1 taken 20837311 times.
|
23733649 | if ((opt->flags & mask) != flags) |
1666 | 2896338 | continue; | |
1667 | |||
1668 |
2/2✓ Branch 0 taken 692 times.
✓ Branch 1 taken 20836619 times.
|
20837311 | if (opt->flags & AV_OPT_FLAG_READONLY) |
1669 | 692 | continue; | |
1670 | |||
1671 |
2/2✓ Branch 0 taken 57434 times.
✓ Branch 1 taken 20779185 times.
|
20836619 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1672 | 57434 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
1673 | 57434 | const char sep = opt_array_sep(opt); | |
1674 | |||
1675 |
11/16✓ Branch 0 taken 57434 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 57434 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 57428 times.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✓ Branch 9 taken 57428 times.
✓ Branch 10 taken 6 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6 times.
✓ Branch 13 taken 57428 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 6 times.
|
57434 | av_assert0(sep && sep != '\\' && |
1676 | (sep < 'a' || sep > 'z') && | ||
1677 | (sep < 'A' || sep > 'Z') && | ||
1678 | (sep < '0' || sep > '9')); | ||
1679 | |||
1680 |
3/4✓ Branch 0 taken 12 times.
✓ Branch 1 taken 57422 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
57434 | if (arr && arr->def) |
1681 | 12 | opt_set_array(s, s, opt, arr->def, dst); | |
1682 | |||
1683 | 57434 | continue; | |
1684 | } | ||
1685 | |||
1686 |
11/12✓ Branch 0 taken 13474534 times.
✓ Branch 1 taken 5856801 times.
✓ Branch 2 taken 775093 times.
✓ Branch 3 taken 175833 times.
✓ Branch 4 taken 301 times.
✓ Branch 5 taken 381648 times.
✓ Branch 6 taken 32655 times.
✓ Branch 7 taken 4491 times.
✓ Branch 8 taken 35203 times.
✓ Branch 9 taken 42421 times.
✓ Branch 10 taken 205 times.
✗ Branch 11 not taken.
|
20779185 | switch (opt->type) { |
1687 | 13474534 | case AV_OPT_TYPE_CONST: | |
1688 | /* Nothing to be done here */ | ||
1689 | 13474534 | break; | |
1690 | 5856801 | case AV_OPT_TYPE_BOOL: | |
1691 | case AV_OPT_TYPE_FLAGS: | ||
1692 | case AV_OPT_TYPE_INT: | ||
1693 | case AV_OPT_TYPE_UINT: | ||
1694 | case AV_OPT_TYPE_INT64: | ||
1695 | case AV_OPT_TYPE_UINT64: | ||
1696 | case AV_OPT_TYPE_DURATION: | ||
1697 | case AV_OPT_TYPE_PIXEL_FMT: | ||
1698 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
1699 | 5856801 | write_number(s, opt, dst, 1, 1, opt->default_val.i64); | |
1700 | 5856801 | break; | |
1701 | 775093 | case AV_OPT_TYPE_DOUBLE: | |
1702 | case AV_OPT_TYPE_FLOAT: { | ||
1703 | double val; | ||
1704 | 775093 | val = opt->default_val.dbl; | |
1705 | 775093 | write_number(s, opt, dst, val, 1, 1); | |
1706 | } | ||
1707 | 775093 | break; | |
1708 | 175833 | case AV_OPT_TYPE_RATIONAL: { | |
1709 | AVRational val; | ||
1710 | 175833 | val = av_d2q(opt->default_val.dbl, INT_MAX); | |
1711 | 175833 | write_number(s, opt, dst, 1, val.den, val.num); | |
1712 | } | ||
1713 | 175833 | break; | |
1714 | 301 | case AV_OPT_TYPE_COLOR: | |
1715 | 301 | set_string_color(s, opt, opt->default_val.str, dst); | |
1716 | 301 | break; | |
1717 | 381648 | case AV_OPT_TYPE_STRING: | |
1718 | 381648 | set_string(s, opt, opt->default_val.str, dst); | |
1719 | 381648 | break; | |
1720 | 32655 | case AV_OPT_TYPE_IMAGE_SIZE: | |
1721 | 32655 | set_string_image_size(s, opt, opt->default_val.str, dst); | |
1722 | 32655 | break; | |
1723 | 4491 | case AV_OPT_TYPE_VIDEO_RATE: | |
1724 | 4491 | set_string_video_rate(s, opt, opt->default_val.str, dst); | |
1725 | 4491 | break; | |
1726 | 35203 | case AV_OPT_TYPE_BINARY: | |
1727 | 35203 | set_string_binary(s, opt, opt->default_val.str, dst); | |
1728 | 35203 | break; | |
1729 | 42421 | case AV_OPT_TYPE_CHLAYOUT: | |
1730 | 42421 | set_string_channel_layout(s, opt, opt->default_val.str, dst); | |
1731 | 42421 | break; | |
1732 | 205 | case AV_OPT_TYPE_DICT: | |
1733 | 205 | set_string_dict(s, opt, opt->default_val.str, dst); | |
1734 | 205 | break; | |
1735 | ✗ | default: | |
1736 | ✗ | av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", | |
1737 | ✗ | opt->type, opt->name); | |
1738 | } | ||
1739 | } | ||
1740 | 356504 | } | |
1741 | |||
1742 | /** | ||
1743 | * Store the value in the field in ctx that is named like key. | ||
1744 | * ctx must be an AVClass context, storing is done using AVOptions. | ||
1745 | * | ||
1746 | * @param buf the string to parse, buf will be updated to point at the | ||
1747 | * separator just after the parsed key/value pair | ||
1748 | * @param key_val_sep a 0-terminated list of characters used to | ||
1749 | * separate key from value | ||
1750 | * @param pairs_sep a 0-terminated list of characters used to separate | ||
1751 | * two pairs from each other | ||
1752 | * @return 0 if the key/value pair has been successfully parsed and | ||
1753 | * set, or a negative value corresponding to an AVERROR code in case | ||
1754 | * of error: | ||
1755 | * AVERROR(EINVAL) if the key/value pair cannot be parsed, | ||
1756 | * the error code issued by av_opt_set() if the key/value pair | ||
1757 | * cannot be set | ||
1758 | */ | ||
1759 | 2814 | static int parse_key_value_pair(void *ctx, const char **buf, | |
1760 | const char *key_val_sep, const char *pairs_sep) | ||
1761 | { | ||
1762 | 2814 | char *key = av_get_token(buf, key_val_sep); | |
1763 | char *val; | ||
1764 | int ret; | ||
1765 | |||
1766 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2814 times.
|
2814 | if (!key) |
1767 | ✗ | return AVERROR(ENOMEM); | |
1768 | |||
1769 |
4/4✓ Branch 0 taken 2812 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2809 times.
✓ Branch 3 taken 3 times.
|
2814 | if (*key && strspn(*buf, key_val_sep)) { |
1770 | 2809 | (*buf)++; | |
1771 | 2809 | val = av_get_token(buf, pairs_sep); | |
1772 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2809 times.
|
2809 | if (!val) { |
1773 | ✗ | av_freep(&key); | |
1774 | ✗ | return AVERROR(ENOMEM); | |
1775 | } | ||
1776 | } else { | ||
1777 | 5 | av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key); | |
1778 | 5 | av_free(key); | |
1779 | 5 | return AVERROR(EINVAL); | |
1780 | } | ||
1781 | |||
1782 | 2809 | av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val); | |
1783 | |||
1784 | 2809 | ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN); | |
1785 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2804 times.
|
2809 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1786 | 5 | av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key); | |
1787 | |||
1788 | 2809 | av_free(key); | |
1789 | 2809 | av_free(val); | |
1790 | 2809 | return ret; | |
1791 | } | ||
1792 | |||
1793 | 2781 | int av_set_options_string(void *ctx, const char *opts, | |
1794 | const char *key_val_sep, const char *pairs_sep) | ||
1795 | { | ||
1796 | 2781 | int ret, count = 0; | |
1797 | |||
1798 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2781 times.
|
2781 | if (!opts) |
1799 | ✗ | return 0; | |
1800 | |||
1801 |
2/2✓ Branch 0 taken 2814 times.
✓ Branch 1 taken 2742 times.
|
5556 | while (*opts) { |
1802 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 2 taken 2775 times.
|
2814 | if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0) |
1803 | 39 | return ret; | |
1804 | 2775 | count++; | |
1805 | |||
1806 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 2740 times.
|
2775 | if (*opts) |
1807 | 35 | opts++; | |
1808 | } | ||
1809 | |||
1810 | 2742 | return count; | |
1811 | } | ||
1812 | |||
1813 | #define WHITESPACES " \n\t\r" | ||
1814 | |||
1815 | 661701 | static int is_key_char(char c) | |
1816 | { | ||
1817 | 816933 | return (unsigned)((c | 32) - 'a') < 26 || | |
1818 |
4/4✓ Branch 0 taken 109643 times.
✓ Branch 1 taken 45589 times.
✓ Branch 2 taken 109569 times.
✓ Branch 3 taken 74 times.
|
155232 | (unsigned)(c - '0') < 10 || |
1819 |
8/8✓ Branch 0 taken 155232 times.
✓ Branch 1 taken 506469 times.
✓ Branch 2 taken 68858 times.
✓ Branch 3 taken 40711 times.
✓ Branch 4 taken 68735 times.
✓ Branch 5 taken 123 times.
✓ Branch 6 taken 79 times.
✓ Branch 7 taken 68656 times.
|
816933 | c == '-' || c == '_' || c == '/' || c == '.'; |
1820 | } | ||
1821 | |||
1822 | /** | ||
1823 | * Read a key from a string. | ||
1824 | * | ||
1825 | * The key consists of is_key_char characters and must be terminated by a | ||
1826 | * character from the delim string; spaces are ignored. | ||
1827 | * | ||
1828 | * @return 0 for success (even with ellipsis), <0 for failure | ||
1829 | */ | ||
1830 | 68656 | static int get_key(const char **ropts, const char *delim, char **rkey) | |
1831 | { | ||
1832 | 68656 | const char *opts = *ropts; | |
1833 | const char *key_start, *key_end; | ||
1834 | |||
1835 | 68656 | key_start = opts += strspn(opts, WHITESPACES); | |
1836 |
2/2✓ Branch 1 taken 593045 times.
✓ Branch 2 taken 68656 times.
|
661701 | while (is_key_char(*opts)) |
1837 | 593045 | opts++; | |
1838 | 68656 | key_end = opts; | |
1839 | 68656 | opts += strspn(opts, WHITESPACES); | |
1840 |
4/4✓ Branch 0 taken 56350 times.
✓ Branch 1 taken 12306 times.
✓ Branch 2 taken 5059 times.
✓ Branch 3 taken 51291 times.
|
68656 | if (!*opts || !strchr(delim, *opts)) |
1841 | 17365 | return AVERROR(EINVAL); | |
1842 | 51291 | opts++; | |
1843 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 51291 times.
|
51291 | if (!(*rkey = av_malloc(key_end - key_start + 1))) |
1844 | ✗ | return AVERROR(ENOMEM); | |
1845 | 51291 | memcpy(*rkey, key_start, key_end - key_start); | |
1846 | 51291 | (*rkey)[key_end - key_start] = 0; | |
1847 | 51291 | *ropts = opts; | |
1848 | 51291 | return 0; | |
1849 | } | ||
1850 | |||
1851 | 68656 | int av_opt_get_key_value(const char **ropts, | |
1852 | const char *key_val_sep, const char *pairs_sep, | ||
1853 | unsigned flags, | ||
1854 | char **rkey, char **rval) | ||
1855 | { | ||
1856 | int ret; | ||
1857 | 68656 | char *key = NULL, *val; | |
1858 | 68656 | const char *opts = *ropts; | |
1859 | |||
1860 |
2/2✓ Branch 1 taken 17365 times.
✓ Branch 2 taken 51291 times.
|
68656 | if ((ret = get_key(&opts, key_val_sep, &key)) < 0 && |
1861 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17364 times.
|
17365 | !(flags & AV_OPT_FLAG_IMPLICIT_KEY)) |
1862 | 1 | return AVERROR(EINVAL); | |
1863 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 68655 times.
|
68655 | if (!(val = av_get_token(&opts, pairs_sep))) { |
1864 | ✗ | av_free(key); | |
1865 | ✗ | return AVERROR(ENOMEM); | |
1866 | } | ||
1867 | 68655 | *ropts = opts; | |
1868 | 68655 | *rkey = key; | |
1869 | 68655 | *rval = val; | |
1870 | 68655 | return 0; | |
1871 | } | ||
1872 | |||
1873 | 36 | int av_opt_set_from_string(void *ctx, const char *opts, | |
1874 | const char *const *shorthand, | ||
1875 | const char *key_val_sep, const char *pairs_sep) | ||
1876 | { | ||
1877 | 36 | int ret, count = 0; | |
1878 | 36 | const char *dummy_shorthand = NULL; | |
1879 | const char *key; | ||
1880 | |||
1881 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!opts) |
1882 | ✗ | return 0; | |
1883 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!shorthand) |
1884 | ✗ | shorthand = &dummy_shorthand; | |
1885 | |||
1886 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 32 times.
|
81 | while (*opts) { |
1887 | char *parsed_key, *value; | ||
1888 | 49 | ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep, | |
1889 | 49 | *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0, | |
1890 | &parsed_key, &value); | ||
1891 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 48 times.
|
49 | if (ret < 0) { |
1892 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ret == AVERROR(EINVAL)) |
1893 | 1 | av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts); | |
1894 | else | ||
1895 | ✗ | av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts, | |
1896 | ✗ | av_err2str(ret)); | |
1897 | 4 | return ret; | |
1898 | } | ||
1899 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 33 times.
|
48 | if (*opts) |
1900 | 15 | opts++; | |
1901 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 14 times.
|
48 | if (parsed_key) { |
1902 | 34 | key = parsed_key; | |
1903 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 34 times.
|
61 | while (*shorthand) /* discard all remaining shorthand */ |
1904 | 27 | shorthand++; | |
1905 | } else { | ||
1906 | 14 | key = *(shorthand++); | |
1907 | } | ||
1908 | |||
1909 | 48 | av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value); | |
1910 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 45 times.
|
48 | if ((ret = av_opt_set(ctx, key, value, 0)) < 0) { |
1911 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1912 | 2 | av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); | |
1913 | 3 | av_free(value); | |
1914 | 3 | av_free(parsed_key); | |
1915 | 3 | return ret; | |
1916 | } | ||
1917 | |||
1918 | 45 | av_free(value); | |
1919 | 45 | av_free(parsed_key); | |
1920 | 45 | count++; | |
1921 | } | ||
1922 | 32 | return count; | |
1923 | } | ||
1924 | |||
1925 | 578984 | void av_opt_free(void *obj) | |
1926 | { | ||
1927 | 578984 | const AVOption *o = NULL; | |
1928 |
2/2✓ Branch 1 taken 23370159 times.
✓ Branch 2 taken 578984 times.
|
23949143 | while ((o = av_opt_next(obj, o))) { |
1929 | 23370159 | void *pitem = (uint8_t *)obj + o->offset; | |
1930 | |||
1931 |
2/2✓ Branch 0 taken 57504 times.
✓ Branch 1 taken 23312655 times.
|
23370159 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1932 | 57504 | opt_free_array(o, pitem, opt_array_pcount(pitem)); | |
1933 | else | ||
1934 | 23312655 | opt_free_elem(o, pitem); | |
1935 | } | ||
1936 | 578984 | } | |
1937 | |||
1938 | 245053 | int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags) | |
1939 | { | ||
1940 | 245053 | const AVDictionaryEntry *t = NULL; | |
1941 | 245053 | AVDictionary *tmp = NULL; | |
1942 | int ret; | ||
1943 | |||
1944 |
2/2✓ Branch 0 taken 53754 times.
✓ Branch 1 taken 191299 times.
|
245053 | if (!options) |
1945 | 53754 | return 0; | |
1946 | |||
1947 |
2/2✓ Branch 1 taken 184705 times.
✓ Branch 2 taken 191299 times.
|
376004 | while ((t = av_dict_iterate(*options, t))) { |
1948 | 184705 | ret = av_opt_set(obj, t->key, t->value, search_flags); | |
1949 |
2/2✓ Branch 0 taken 50652 times.
✓ Branch 1 taken 134053 times.
|
184705 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1950 | 50652 | ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY); | |
1951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 184705 times.
|
184705 | if (ret < 0) { |
1952 | ✗ | av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); | |
1953 | ✗ | av_dict_free(&tmp); | |
1954 | ✗ | return ret; | |
1955 | } | ||
1956 | } | ||
1957 | 191299 | av_dict_free(options); | |
1958 | 191299 | *options = tmp; | |
1959 | 191299 | return 0; | |
1960 | } | ||
1961 | |||
1962 | 182525 | int av_opt_set_dict(void *obj, AVDictionary **options) | |
1963 | { | ||
1964 | 182525 | return av_opt_set_dict2(obj, options, 0); | |
1965 | } | ||
1966 | |||
1967 | 462694 | const AVOption *av_opt_find(void *obj, const char *name, const char *unit, | |
1968 | int opt_flags, int search_flags) | ||
1969 | { | ||
1970 | 462694 | return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL); | |
1971 | } | ||
1972 | |||
1973 | 37038075 | const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, | |
1974 | int opt_flags, int search_flags, void **target_obj) | ||
1975 | { | ||
1976 | const AVClass *c; | ||
1977 | 37038075 | const AVOption *o = NULL; | |
1978 | |||
1979 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37038075 times.
|
37038075 | if(!obj) |
1980 | ✗ | return NULL; | |
1981 | |||
1982 | 37038075 | c= *(AVClass**)obj; | |
1983 | |||
1984 |
2/2✓ Branch 0 taken 971 times.
✓ Branch 1 taken 37037104 times.
|
37038075 | if (!c) |
1985 | 971 | return NULL; | |
1986 | |||
1987 |
2/2✓ Branch 0 taken 36576836 times.
✓ Branch 1 taken 460268 times.
|
37037104 | if (search_flags & AV_OPT_SEARCH_CHILDREN) { |
1988 |
2/2✓ Branch 0 taken 36274529 times.
✓ Branch 1 taken 302307 times.
|
36576836 | if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) { |
1989 | 36274529 | void *iter = NULL; | |
1990 | const AVClass *child; | ||
1991 |
2/2✓ Branch 1 taken 36040017 times.
✓ Branch 2 taken 36274032 times.
|
72314049 | while (child = av_opt_child_class_iterate(c, &iter)) |
1992 |
2/2✓ Branch 1 taken 497 times.
✓ Branch 2 taken 36039520 times.
|
36040017 | if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL)) |
1993 | 497 | return o; | |
1994 | } else { | ||
1995 | 302307 | void *child = NULL; | |
1996 |
2/2✓ Branch 1 taken 160815 times.
✓ Branch 2 taken 221581 times.
|
382396 | while (child = av_opt_child_next(obj, child)) |
1997 |
2/2✓ Branch 1 taken 80726 times.
✓ Branch 2 taken 80089 times.
|
160815 | if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj)) |
1998 | 80726 | return o; | |
1999 | } | ||
2000 | } | ||
2001 | |||
2002 |
2/2✓ Branch 1 taken 385654788 times.
✓ Branch 2 taken 36435164 times.
|
422089952 | while (o = av_opt_next(obj, o)) { |
2003 |
6/6✓ Branch 0 taken 590713 times.
✓ Branch 1 taken 385064075 times.
✓ Branch 2 taken 588008 times.
✓ Branch 3 taken 2705 times.
✓ Branch 4 taken 491698 times.
✓ Branch 5 taken 96310 times.
|
385654788 | if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags && |
2004 |
4/4✓ Branch 0 taken 66055 times.
✓ Branch 1 taken 425643 times.
✓ Branch 2 taken 96310 times.
✓ Branch 3 taken 66055 times.
|
588008 | ((!unit && o->type != AV_OPT_TYPE_CONST) || |
2005 |
4/6✓ Branch 0 taken 96310 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 96310 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 95074 times.
✓ Branch 5 taken 1236 times.
|
96310 | (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) { |
2006 |
2/2✓ Branch 0 taken 289686 times.
✓ Branch 1 taken 231031 times.
|
520717 | if (target_obj) { |
2007 |
1/2✓ Branch 0 taken 289686 times.
✗ Branch 1 not taken.
|
289686 | if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ)) |
2008 | 289686 | *target_obj = obj; | |
2009 | else | ||
2010 | ✗ | *target_obj = NULL; | |
2011 | } | ||
2012 | 520717 | return o; | |
2013 | } | ||
2014 | } | ||
2015 | 36435164 | return NULL; | |
2016 | } | ||
2017 | |||
2018 | 382419 | void *av_opt_child_next(void *obj, void *prev) | |
2019 | { | ||
2020 | 382419 | const AVClass *c = *(AVClass **)obj; | |
2021 |
2/2✓ Branch 0 taken 262359 times.
✓ Branch 1 taken 120060 times.
|
382419 | if (c->child_next) |
2022 | 262359 | return c->child_next(obj, prev); | |
2023 | 120060 | return NULL; | |
2024 | } | ||
2025 | |||
2026 | 72314049 | const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter) | |
2027 | { | ||
2028 |
2/2✓ Branch 0 taken 36403264 times.
✓ Branch 1 taken 35910785 times.
|
72314049 | if (parent->child_class_iterate) |
2029 | 36403264 | return parent->child_class_iterate(iter); | |
2030 | 35910785 | return NULL; | |
2031 | } | ||
2032 | |||
2033 | 7166 | void *av_opt_ptr(const AVClass *class, void *obj, const char *name) | |
2034 | { | ||
2035 | 7166 | const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL); | |
2036 | |||
2037 | // no direct access to array-type options | ||
2038 |
3/4✓ Branch 0 taken 34 times.
✓ Branch 1 taken 7132 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34 times.
|
7166 | if (!opt || (opt->type & AV_OPT_TYPE_FLAG_ARRAY)) |
2039 | 7132 | return NULL; | |
2040 | 34 | return (uint8_t*)obj + opt->offset; | |
2041 | } | ||
2042 | |||
2043 | 4798546 | static int opt_copy_elem(void *logctx, enum AVOptionType type, | |
2044 | void *dst, const void *src) | ||
2045 | { | ||
2046 |
2/2✓ Branch 0 taken 38423 times.
✓ Branch 1 taken 4760123 times.
|
4798546 | if (type == AV_OPT_TYPE_STRING) { |
2047 | 38423 | const char *src_str = *(const char *const *)src; | |
2048 | 38423 | char **dstp = (char **)dst; | |
2049 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38423 times.
|
38423 | if (*dstp != src_str) |
2050 | ✗ | av_freep(dstp); | |
2051 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38423 times.
|
38423 | if (src_str) { |
2052 | ✗ | *dstp = av_strdup(src_str); | |
2053 | ✗ | if (!*dstp) | |
2054 | ✗ | return AVERROR(ENOMEM); | |
2055 | } | ||
2056 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4760123 times.
|
4760123 | } else if (type == AV_OPT_TYPE_BINARY) { |
2057 | ✗ | const uint8_t *const *src8 = (const uint8_t *const *)src; | |
2058 | ✗ | uint8_t **dst8 = (uint8_t **)dst; | |
2059 | ✗ | int len = *(const int *)(src8 + 1); | |
2060 | ✗ | if (*dst8 != *src8) | |
2061 | ✗ | av_freep(dst8); | |
2062 | ✗ | *dst8 = av_memdup(*src8, len); | |
2063 | ✗ | if (len && !*dst8) { | |
2064 | ✗ | *(int *)(dst8 + 1) = 0; | |
2065 | ✗ | return AVERROR(ENOMEM); | |
2066 | } | ||
2067 | ✗ | *(int *)(dst8 + 1) = len; | |
2068 |
2/2✓ Branch 0 taken 1478267 times.
✓ Branch 1 taken 3281856 times.
|
4760123 | } else if (type == AV_OPT_TYPE_CONST) { |
2069 | // do nothing | ||
2070 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1478267 times.
|
1478267 | } else if (type == AV_OPT_TYPE_DICT) { |
2071 | ✗ | const AVDictionary *sdict = *(const AVDictionary * const *)src; | |
2072 | ✗ | AVDictionary **ddictp = (AVDictionary **)dst; | |
2073 | ✗ | if (sdict != *ddictp) | |
2074 | ✗ | av_dict_free(ddictp); | |
2075 | ✗ | *ddictp = NULL; | |
2076 | ✗ | return av_dict_copy(ddictp, sdict, 0); | |
2077 |
2/2✓ Branch 0 taken 12804 times.
✓ Branch 1 taken 1465463 times.
|
1478267 | } else if (type == AV_OPT_TYPE_CHLAYOUT) { |
2078 |
1/2✓ Branch 0 taken 12804 times.
✗ Branch 1 not taken.
|
12804 | if (dst != src) |
2079 | 12804 | return av_channel_layout_copy(dst, src); | |
2080 |
1/2✓ Branch 1 taken 1465463 times.
✗ Branch 2 not taken.
|
1465463 | } else if (opt_is_pod(type)) { |
2081 | 1465463 | size_t size = opt_elem_size[type]; | |
2082 | 1465463 | memcpy(dst, src, size); | |
2083 | } else { | ||
2084 | ✗ | av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type); | |
2085 | ✗ | return AVERROR(EINVAL); | |
2086 | } | ||
2087 | |||
2088 | 4785742 | return 0; | |
2089 | } | ||
2090 | |||
2091 | 12804 | static int opt_copy_array(void *logctx, const AVOption *o, | |
2092 | void **pdst, const void * const *psrc) | ||
2093 | { | ||
2094 | 12804 | unsigned nb_elems = *opt_array_pcount(psrc); | |
2095 | 12804 | void *dst = NULL; | |
2096 | int ret; | ||
2097 | |||
2098 |
1/2✓ Branch 0 taken 12804 times.
✗ Branch 1 not taken.
|
12804 | if (*pdst == *psrc) { |
2099 | 12804 | *pdst = NULL; | |
2100 | 12804 | *opt_array_pcount(pdst) = 0; | |
2101 | } | ||
2102 | |||
2103 | 12804 | opt_free_array(o, pdst, opt_array_pcount(pdst)); | |
2104 | |||
2105 | 12804 | dst = av_calloc(nb_elems, opt_elem_size[TYPE_BASE(o->type)]); | |
2106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12804 times.
|
12804 | if (!dst) |
2107 | ✗ | return AVERROR(ENOMEM); | |
2108 | |||
2109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12804 times.
|
12804 | for (unsigned i = 0; i < nb_elems; i++) { |
2110 | ✗ | ret = opt_copy_elem(logctx, TYPE_BASE(o->type), | |
2111 | opt_array_pelem(o, dst, i), | ||
2112 | ✗ | opt_array_pelem(o, *(void**)psrc, i)); | |
2113 | ✗ | if (ret < 0) { | |
2114 | ✗ | opt_free_array(o, &dst, &nb_elems); | |
2115 | ✗ | return ret; | |
2116 | } | ||
2117 | } | ||
2118 | |||
2119 | 12804 | *pdst = dst; | |
2120 | 12804 | *opt_array_pcount(pdst) = nb_elems; | |
2121 | |||
2122 | 12804 | return 0; | |
2123 | } | ||
2124 | |||
2125 | 20031 | int av_opt_copy(void *dst, const void *src) | |
2126 | { | ||
2127 | 20031 | const AVOption *o = NULL; | |
2128 | const AVClass *c; | ||
2129 | 20031 | int ret = 0; | |
2130 | |||
2131 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20031 times.
|
20031 | if (!src) |
2132 | ✗ | return AVERROR(EINVAL); | |
2133 | |||
2134 | 20031 | c = *(AVClass **)src; | |
2135 |
2/4✓ Branch 0 taken 20031 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20031 times.
|
20031 | if (!c || c != *(AVClass **)dst) |
2136 | ✗ | return AVERROR(EINVAL); | |
2137 | |||
2138 |
2/2✓ Branch 1 taken 4811350 times.
✓ Branch 2 taken 20031 times.
|
4831381 | while ((o = av_opt_next(src, o))) { |
2139 | 4811350 | void *field_dst = (uint8_t *)dst + o->offset; | |
2140 | 4811350 | void *field_src = (uint8_t *)src + o->offset; | |
2141 | |||
2142 | 9622700 | int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ? | |
2143 |
2/2✓ Branch 0 taken 12804 times.
✓ Branch 1 taken 4798546 times.
|
4811350 | opt_copy_array(dst, o, field_dst, field_src) : |
2144 | 4798546 | opt_copy_elem (dst, o->type, field_dst, field_src); | |
2145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4811350 times.
|
4811350 | if (err < 0) |
2146 | ✗ | ret = err; | |
2147 | } | ||
2148 | 20031 | return ret; | |
2149 | } | ||
2150 | |||
2151 | 31 | int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) | |
2152 | { | ||
2153 | int ret; | ||
2154 | 31 | const AVClass *c = *(AVClass**)obj; | |
2155 | 31 | int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges; | |
2156 | |||
2157 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (!callback) |
2158 | 31 | callback = av_opt_query_ranges_default; | |
2159 | |||
2160 | 31 | ret = callback(ranges_arg, obj, key, flags); | |
2161 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 13 times.
|
31 | if (ret >= 0) { |
2162 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE)) |
2163 | 18 | ret = 1; | |
2164 | 18 | (*ranges_arg)->nb_components = ret; | |
2165 | } | ||
2166 | 31 | return ret; | |
2167 | } | ||
2168 | |||
2169 | 31 | int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) | |
2170 | { | ||
2171 | 31 | AVOptionRanges *ranges = av_mallocz(sizeof(*ranges)); | |
2172 | 31 | AVOptionRange **range_array = av_mallocz(sizeof(void*)); | |
2173 | 31 | AVOptionRange *range = av_mallocz(sizeof(*range)); | |
2174 | 31 | const AVOption *field = av_opt_find(obj, key, NULL, 0, flags); | |
2175 | int ret; | ||
2176 | |||
2177 | 31 | *ranges_arg = NULL; | |
2178 | |||
2179 |
5/8✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 28 times.
|
31 | if (!ranges || !range || !range_array || !field) { |
2180 | 3 | ret = AVERROR(ENOMEM); | |
2181 | 3 | goto fail; | |
2182 | } | ||
2183 | |||
2184 | 28 | ranges->range = range_array; | |
2185 | 28 | ranges->range[0] = range; | |
2186 | 28 | ranges->nb_ranges = 1; | |
2187 | 28 | ranges->nb_components = 1; | |
2188 | 28 | range->is_range = 1; | |
2189 | 28 | range->value_min = field->min; | |
2190 | 28 | range->value_max = field->max; | |
2191 | |||
2192 |
6/6✓ Branch 0 taken 13 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 10 times.
|
28 | switch (field->type) { |
2193 | 13 | case AV_OPT_TYPE_BOOL: | |
2194 | case AV_OPT_TYPE_INT: | ||
2195 | case AV_OPT_TYPE_UINT: | ||
2196 | case AV_OPT_TYPE_INT64: | ||
2197 | case AV_OPT_TYPE_UINT64: | ||
2198 | case AV_OPT_TYPE_PIXEL_FMT: | ||
2199 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
2200 | case AV_OPT_TYPE_FLOAT: | ||
2201 | case AV_OPT_TYPE_DOUBLE: | ||
2202 | case AV_OPT_TYPE_DURATION: | ||
2203 | case AV_OPT_TYPE_COLOR: | ||
2204 | 13 | break; | |
2205 | 2 | case AV_OPT_TYPE_STRING: | |
2206 | 2 | range->component_min = 0; | |
2207 | 2 | range->component_max = 0x10FFFF; // max unicode value | |
2208 | 2 | range->value_min = -1; | |
2209 | 2 | range->value_max = INT_MAX; | |
2210 | 2 | break; | |
2211 | 1 | case AV_OPT_TYPE_RATIONAL: | |
2212 | 1 | range->component_min = INT_MIN; | |
2213 | 1 | range->component_max = INT_MAX; | |
2214 | 1 | break; | |
2215 | 1 | case AV_OPT_TYPE_IMAGE_SIZE: | |
2216 | 1 | range->component_min = 0; | |
2217 | 1 | range->component_max = INT_MAX/128/8; | |
2218 | 1 | range->value_min = 0; | |
2219 | 1 | range->value_max = INT_MAX/8; | |
2220 | 1 | break; | |
2221 | 1 | case AV_OPT_TYPE_VIDEO_RATE: | |
2222 | 1 | range->component_min = 1; | |
2223 | 1 | range->component_max = INT_MAX; | |
2224 | 1 | range->value_min = 1; | |
2225 | 1 | range->value_max = INT_MAX; | |
2226 | 1 | break; | |
2227 | 10 | default: | |
2228 | 10 | ret = AVERROR(ENOSYS); | |
2229 | 10 | goto fail; | |
2230 | } | ||
2231 | |||
2232 | 18 | *ranges_arg = ranges; | |
2233 | 18 | return 1; | |
2234 | 13 | fail: | |
2235 | 13 | av_free(ranges); | |
2236 | 13 | av_free(range); | |
2237 | 13 | av_free(range_array); | |
2238 | 13 | return ret; | |
2239 | } | ||
2240 | |||
2241 | 18 | void av_opt_freep_ranges(AVOptionRanges **rangesp) | |
2242 | { | ||
2243 | int i; | ||
2244 | 18 | AVOptionRanges *ranges = *rangesp; | |
2245 | |||
2246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (!ranges) |
2247 | ✗ | return; | |
2248 | |||
2249 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
|
36 | for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) { |
2250 | 18 | AVOptionRange *range = ranges->range[i]; | |
2251 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (range) { |
2252 | 18 | av_freep(&range->str); | |
2253 | 18 | av_freep(&ranges->range[i]); | |
2254 | } | ||
2255 | } | ||
2256 | 18 | av_freep(&ranges->range); | |
2257 | 18 | av_freep(rangesp); | |
2258 | } | ||
2259 | |||
2260 | 140 | int av_opt_is_set_to_default(void *obj, const AVOption *o) | |
2261 | { | ||
2262 | int64_t i64; | ||
2263 | double d; | ||
2264 | AVRational q; | ||
2265 | int ret, w, h; | ||
2266 | char *str; | ||
2267 | void *dst; | ||
2268 | |||
2269 |
2/4✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 140 times.
|
140 | if (!o || !obj) |
2270 | ✗ | return AVERROR(EINVAL); | |
2271 | |||
2272 | 140 | dst = ((uint8_t*)obj) + o->offset; | |
2273 | |||
2274 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 131 times.
|
140 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) { |
2275 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | const char *def = o->default_val.arr ? o->default_val.arr->def : NULL; |
2276 | uint8_t *val; | ||
2277 | |||
2278 | 9 | ret = opt_get_array(o, dst, &val); | |
2279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (ret < 0) |
2280 | ✗ | return ret; | |
2281 | |||
2282 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 7 times.
|
9 | if (!!val != !!def) |
2283 | 2 | ret = 0; | |
2284 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
|
7 | else if (val) |
2285 | 4 | ret = !strcmp(val, def); | |
2286 | |||
2287 | 9 | av_freep(&val); | |
2288 | |||
2289 | 9 | return ret; | |
2290 | } | ||
2291 | |||
2292 |
11/13✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 17 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
131 | switch (o->type) { |
2293 | ✗ | case AV_OPT_TYPE_CONST: | |
2294 | 131 | return 1; | |
2295 | 69 | case AV_OPT_TYPE_BOOL: | |
2296 | case AV_OPT_TYPE_FLAGS: | ||
2297 | case AV_OPT_TYPE_PIXEL_FMT: | ||
2298 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
2299 | case AV_OPT_TYPE_INT: | ||
2300 | case AV_OPT_TYPE_UINT: | ||
2301 | case AV_OPT_TYPE_DURATION: | ||
2302 | case AV_OPT_TYPE_INT64: | ||
2303 | case AV_OPT_TYPE_UINT64: | ||
2304 | 69 | read_number(o, dst, NULL, NULL, &i64); | |
2305 | 69 | return o->default_val.i64 == i64; | |
2306 | 7 | case AV_OPT_TYPE_CHLAYOUT: { | |
2307 | 7 | AVChannelLayout ch_layout = { 0 }; | |
2308 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 4 times.
|
7 | if (o->default_val.str) { |
2309 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0) |
2310 | ✗ | return ret; | |
2311 | } | ||
2312 | 7 | ret = !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout); | |
2313 | 7 | av_channel_layout_uninit(&ch_layout); | |
2314 | 7 | return ret; | |
2315 | } | ||
2316 | 6 | case AV_OPT_TYPE_STRING: | |
2317 | 6 | str = *(char **)dst; | |
2318 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (str == o->default_val.str) //2 NULLs |
2319 | ✗ | return 1; | |
2320 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
6 | if (!str || !o->default_val.str) //1 NULL |
2321 | 2 | return 0; | |
2322 | 4 | return !strcmp(str, o->default_val.str); | |
2323 | 3 | case AV_OPT_TYPE_DOUBLE: | |
2324 | 3 | d = *(double *)dst; | |
2325 | 3 | return o->default_val.dbl == d; | |
2326 | 3 | case AV_OPT_TYPE_FLOAT: | |
2327 | 3 | d = *(float *)dst; | |
2328 | 3 | return (float)o->default_val.dbl == d; | |
2329 | 17 | case AV_OPT_TYPE_RATIONAL: | |
2330 | 17 | q = av_d2q(o->default_val.dbl, INT_MAX); | |
2331 | 17 | return !av_cmp_q(*(AVRational*)dst, q); | |
2332 | 9 | case AV_OPT_TYPE_BINARY: { | |
2333 | struct { | ||
2334 | uint8_t *data; | ||
2335 | int size; | ||
2336 | 9 | } tmp = {0}; | |
2337 | 9 | int opt_size = *(int *)((void **)dst + 1); | |
2338 | 9 | void *opt_ptr = *(void **)dst; | |
2339 |
6/6✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
|
9 | if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str))) |
2340 | 6 | return 1; | |
2341 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
3 | if (!opt_size || !o->default_val.str || !strlen(o->default_val.str )) |
2342 | 1 | return 0; | |
2343 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (opt_size != strlen(o->default_val.str) / 2) |
2344 | ✗ | return 0; | |
2345 | 2 | ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data); | |
2346 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!ret) |
2347 | 2 | ret = !memcmp(opt_ptr, tmp.data, tmp.size); | |
2348 | 2 | av_free(tmp.data); | |
2349 | 2 | return ret; | |
2350 | } | ||
2351 | 8 | case AV_OPT_TYPE_DICT: { | |
2352 | 8 | AVDictionary *dict1 = NULL; | |
2353 | 8 | AVDictionary *dict2 = *(AVDictionary **)dst; | |
2354 | 8 | const AVDictionaryEntry *en1 = NULL; | |
2355 | 8 | const AVDictionaryEntry *en2 = NULL; | |
2356 | 8 | ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0); | |
2357 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | if (ret < 0) { |
2358 | ✗ | av_dict_free(&dict1); | |
2359 | ✗ | return ret; | |
2360 | } | ||
2361 | do { | ||
2362 | 10 | en1 = av_dict_iterate(dict1, en1); | |
2363 | 10 | en2 = av_dict_iterate(dict2, en2); | |
2364 |
6/8✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
10 | } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value)); |
2365 | 8 | av_dict_free(&dict1); | |
2366 |
4/4✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
|
8 | return (!en1 && !en2); |
2367 | } | ||
2368 | 3 | case AV_OPT_TYPE_IMAGE_SIZE: | |
2369 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (!o->default_val.str || !strcmp(o->default_val.str, "none")) |
2370 | ✗ | w = h = 0; | |
2371 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0) |
2372 | ✗ | return ret; | |
2373 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
3 | return (w == *(int *)dst) && (h == *((int *)dst+1)); |
2374 | 3 | case AV_OPT_TYPE_VIDEO_RATE: | |
2375 | 3 | q = (AVRational){0, 0}; | |
2376 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (o->default_val.str) { |
2377 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0) |
2378 | ✗ | return ret; | |
2379 | } | ||
2380 | 3 | return !av_cmp_q(*(AVRational*)dst, q); | |
2381 | 3 | case AV_OPT_TYPE_COLOR: { | |
2382 | 3 | uint8_t color[4] = {0, 0, 0, 0}; | |
2383 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (o->default_val.str) { |
2384 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0) |
2385 | ✗ | return ret; | |
2386 | } | ||
2387 | 3 | return !memcmp(color, dst, sizeof(color)); | |
2388 | } | ||
2389 | ✗ | default: | |
2390 | ✗ | av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name); | |
2391 | ✗ | break; | |
2392 | } | ||
2393 | ✗ | return AVERROR_PATCHWELCOME; | |
2394 | } | ||
2395 | |||
2396 | 62 | int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags) | |
2397 | { | ||
2398 | const AVOption *o; | ||
2399 | void *target; | ||
2400 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (!obj) |
2401 | ✗ | return AVERROR(EINVAL); | |
2402 | 62 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &target); | |
2403 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 56 times.
|
62 | if (!o) |
2404 | 6 | return AVERROR_OPTION_NOT_FOUND; | |
2405 | 56 | return av_opt_is_set_to_default(target, o); | |
2406 | } | ||
2407 | |||
2408 | 20 | static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt, | |
2409 | AVBPrint *bprint, const char key_val_sep, const char pairs_sep) | ||
2410 | { | ||
2411 | 20 | const AVOption *o = NULL; | |
2412 | 20 | void *child = NULL; | |
2413 | uint8_t *buf; | ||
2414 | int ret; | ||
2415 | 20 | const char special_chars[] = {pairs_sep, key_val_sep, '\0'}; | |
2416 | |||
2417 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 2 times.
|
20 | if (flags & AV_OPT_SERIALIZE_SEARCH_CHILDREN) |
2418 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 18 times.
|
23 | while (child = av_opt_child_next(obj, child)) { |
2419 | 5 | ret = opt_serialize(child, opt_flags, flags, cnt, bprint, | |
2420 | key_val_sep, pairs_sep); | ||
2421 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (ret < 0) |
2422 | ✗ | return ret; | |
2423 | } | ||
2424 | |||
2425 |
2/2✓ Branch 1 taken 213 times.
✓ Branch 2 taken 20 times.
|
233 | while (o = av_opt_next(obj, o)) { |
2426 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 140 times.
|
213 | if (o->type == AV_OPT_TYPE_CONST) |
2427 | 73 | continue; | |
2428 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
140 | if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags) |
2429 | ✗ | continue; | |
2430 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 140 times.
|
140 | else if (((o->flags & opt_flags) != opt_flags)) |
2431 | ✗ | continue; | |
2432 |
4/4✓ Branch 0 taken 84 times.
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 52 times.
✓ Branch 4 taken 32 times.
|
140 | if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0) |
2433 | 52 | continue; | |
2434 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
|
88 | if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) { |
2435 | ✗ | av_bprint_finalize(bprint, NULL); | |
2436 | ✗ | return ret; | |
2437 | } | ||
2438 |
1/2✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 | if (buf) { |
2439 |
2/2✓ Branch 0 taken 73 times.
✓ Branch 1 taken 15 times.
|
88 | if ((*cnt)++) |
2440 | 73 | av_bprint_append_data(bprint, &pairs_sep, 1); | |
2441 | 88 | av_bprint_escape(bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); | |
2442 | 88 | av_bprint_append_data(bprint, &key_val_sep, 1); | |
2443 | 88 | av_bprint_escape(bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); | |
2444 | 88 | av_freep(&buf); | |
2445 | } | ||
2446 | } | ||
2447 | |||
2448 | 20 | return 0; | |
2449 | } | ||
2450 | |||
2451 | 15 | int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, | |
2452 | const char key_val_sep, const char pairs_sep) | ||
2453 | { | ||
2454 | AVBPrint bprint; | ||
2455 | 15 | int ret, cnt = 0; | |
2456 | |||
2457 |
4/8✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15 times.
✗ Branch 7 not taken.
|
15 | if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep || |
2458 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | pairs_sep == '\\' || key_val_sep == '\\') { |
2459 | ✗ | av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found."); | |
2460 | ✗ | return AVERROR(EINVAL); | |
2461 | } | ||
2462 | |||
2463 |
2/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
|
15 | if (!obj || !buffer) |
2464 | ✗ | return AVERROR(EINVAL); | |
2465 | |||
2466 | 15 | *buffer = NULL; | |
2467 | 15 | av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED); | |
2468 | |||
2469 | 15 | ret = opt_serialize(obj, opt_flags, flags, &cnt, &bprint, | |
2470 | key_val_sep, pairs_sep); | ||
2471 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
2472 | ✗ | return ret; | |
2473 | |||
2474 | 15 | ret = av_bprint_finalize(&bprint, buffer); | |
2475 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
|
15 | if (ret < 0) |
2476 | ✗ | return ret; | |
2477 | 15 | return 0; | |
2478 | } | ||
2479 |