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