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 | 571025847 | 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 571025847 times.
|
571025847 | if (!obj) |
52 | ✗ | return NULL; | |
53 | 571025847 | class = *(const AVClass**)obj; | |
54 |
7/8✓ Branch 0 taken 45748866 times.
✓ Branch 1 taken 525276981 times.
✓ Branch 2 taken 45748866 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 45419037 times.
✓ Branch 5 taken 329829 times.
✓ Branch 6 taken 45308954 times.
✓ Branch 7 taken 110083 times.
|
571025847 | if (!last && class && class->option && class->option[0].name) |
55 | 45308954 | return class->option; | |
56 |
4/4✓ Branch 0 taken 525276981 times.
✓ Branch 1 taken 439912 times.
✓ Branch 2 taken 480500962 times.
✓ Branch 3 taken 44776019 times.
|
525716893 | if (last && last[1].name) |
57 | 480500962 | return ++last; | |
58 | 45215931 | return NULL; | |
59 | } | ||
60 | |||
61 | static const struct { | ||
62 | size_t size; | ||
63 | const char *name; | ||
64 | } opt_type_desc[] = { | ||
65 | [AV_OPT_TYPE_FLAGS] = { sizeof(unsigned), "<flags>" }, | ||
66 | [AV_OPT_TYPE_INT] = { sizeof(int), "<int>" }, | ||
67 | [AV_OPT_TYPE_INT64] = { sizeof(int64_t), "<int64>" }, | ||
68 | [AV_OPT_TYPE_UINT] = { sizeof(unsigned), "<unsigned>" }, | ||
69 | [AV_OPT_TYPE_UINT64] = { sizeof(uint64_t), "<uint64>" }, | ||
70 | [AV_OPT_TYPE_DOUBLE] = { sizeof(double), "<double>" }, | ||
71 | [AV_OPT_TYPE_FLOAT] = { sizeof(float), "<float>" }, | ||
72 | [AV_OPT_TYPE_STRING] = { sizeof(char *), "<string>" }, | ||
73 | [AV_OPT_TYPE_RATIONAL] = { sizeof(AVRational), "<rational>" }, | ||
74 | [AV_OPT_TYPE_BINARY] = { sizeof(uint8_t *), "<binary>" }, | ||
75 | [AV_OPT_TYPE_DICT] = { sizeof(AVDictionary *), "<dictionary>" }, | ||
76 | [AV_OPT_TYPE_IMAGE_SIZE] = { sizeof(int[2]), "<image_size>" }, | ||
77 | [AV_OPT_TYPE_VIDEO_RATE] = { sizeof(AVRational), "<video_rate>" }, | ||
78 | [AV_OPT_TYPE_PIXEL_FMT] = { sizeof(int), "<pix_fmt>" }, | ||
79 | [AV_OPT_TYPE_SAMPLE_FMT] = { sizeof(int), "<sample_fmt>" }, | ||
80 | [AV_OPT_TYPE_DURATION] = { sizeof(int64_t), "<duration>" }, | ||
81 | [AV_OPT_TYPE_COLOR] = { sizeof(uint8_t[4]), "<color>" }, | ||
82 | [AV_OPT_TYPE_CHLAYOUT] = { sizeof(AVChannelLayout),"<channel_layout>" }, | ||
83 | [AV_OPT_TYPE_BOOL] = { sizeof(int), "<boolean>" }, | ||
84 | }; | ||
85 | |||
86 | // option is plain old data | ||
87 | 1674614 | static int opt_is_pod(enum AVOptionType type) | |
88 | { | ||
89 |
1/2✓ Branch 0 taken 1674614 times.
✗ Branch 1 not taken.
|
1674614 | switch (type) { |
90 | 1674614 | case AV_OPT_TYPE_FLAGS: | |
91 | case AV_OPT_TYPE_INT: | ||
92 | case AV_OPT_TYPE_INT64: | ||
93 | case AV_OPT_TYPE_DOUBLE: | ||
94 | case AV_OPT_TYPE_FLOAT: | ||
95 | case AV_OPT_TYPE_RATIONAL: | ||
96 | case AV_OPT_TYPE_UINT64: | ||
97 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
98 | case AV_OPT_TYPE_PIXEL_FMT: | ||
99 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
100 | case AV_OPT_TYPE_VIDEO_RATE: | ||
101 | case AV_OPT_TYPE_DURATION: | ||
102 | case AV_OPT_TYPE_COLOR: | ||
103 | case AV_OPT_TYPE_BOOL: | ||
104 | case AV_OPT_TYPE_UINT: | ||
105 | 1674614 | return 1; | |
106 | } | ||
107 | ✗ | return 0; | |
108 | } | ||
109 | |||
110 | 99472 | static uint8_t opt_array_sep(const AVOption *o) | |
111 | { | ||
112 | 99472 | const AVOptionArrayDef *d = o->default_val.arr; | |
113 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
114 |
4/4✓ Branch 0 taken 13884 times.
✓ Branch 1 taken 85588 times.
✓ Branch 2 taken 13859 times.
✓ Branch 3 taken 25 times.
|
99472 | return (d && d->sep) ? d->sep : ','; |
115 | } | ||
116 | |||
117 | 5772 | static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx) | |
118 | { | ||
119 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
120 | 5772 | return (uint8_t *)array + idx * opt_type_desc[TYPE_BASE(o->type)].size; | |
121 | } | ||
122 | |||
123 | 155328 | static unsigned *opt_array_pcount(const void *parray) | |
124 | { | ||
125 | 155328 | return (unsigned *)((const void * const *)parray + 1); | |
126 | } | ||
127 | |||
128 | 25403165 | static void opt_free_elem(enum AVOptionType type, void *ptr) | |
129 | { | ||
130 |
4/4✓ Branch 0 taken 955448 times.
✓ Branch 1 taken 243 times.
✓ Branch 2 taken 62645 times.
✓ Branch 3 taken 24384829 times.
|
25403165 | switch (TYPE_BASE(type)) { |
131 | 955448 | case AV_OPT_TYPE_STRING: | |
132 | case AV_OPT_TYPE_BINARY: | ||
133 | 955448 | av_freep(ptr); | |
134 | 955448 | break; | |
135 | |||
136 | 243 | case AV_OPT_TYPE_DICT: | |
137 | 243 | av_dict_free((AVDictionary **)ptr); | |
138 | 243 | break; | |
139 | |||
140 | 62645 | case AV_OPT_TYPE_CHLAYOUT: | |
141 | 62645 | av_channel_layout_uninit((AVChannelLayout *)ptr); | |
142 | 62645 | break; | |
143 | |||
144 | 24384829 | default: | |
145 | 24384829 | break; | |
146 | } | ||
147 | 25403165 | } | |
148 | |||
149 | 113927 | static void opt_free_array(const AVOption *o, void *parray, unsigned *count) | |
150 | { | ||
151 |
2/2✓ Branch 0 taken 2877 times.
✓ Branch 1 taken 113927 times.
|
116804 | for (unsigned i = 0; i < *count; i++) |
152 | 2877 | opt_free_elem(o->type, opt_array_pelem(o, *(void **)parray, i)); | |
153 | |||
154 | 113927 | av_freep(parray); | |
155 | 113927 | *count = 0; | |
156 | 113927 | } | |
157 | |||
158 | /** | ||
159 | * Perform common setup for option-setting functions. | ||
160 | * | ||
161 | * @param require_type when non-0, require the option to be of this type | ||
162 | * @param ptgt target object is written here | ||
163 | * @param po the option is written here | ||
164 | * @param pdst pointer to option value is written here | ||
165 | */ | ||
166 | 260551 | static int opt_set_init(void *obj, const char *name, int search_flags, | |
167 | int require_type, | ||
168 | void **ptgt, const AVOption **po, void **pdst) | ||
169 | { | ||
170 | const AVOption *o; | ||
171 | void *tgt; | ||
172 | |||
173 | 260551 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &tgt); | |
174 |
3/4✓ Branch 0 taken 197663 times.
✓ Branch 1 taken 62888 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 197663 times.
|
260551 | if (!o || !tgt) |
175 | 62888 | return AVERROR_OPTION_NOT_FOUND; | |
176 | |||
177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 197663 times.
|
197663 | if (o->flags & AV_OPT_FLAG_READONLY) |
178 | ✗ | return AVERROR(EINVAL); | |
179 | |||
180 |
3/4✓ Branch 0 taken 3188 times.
✓ Branch 1 taken 194475 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3188 times.
|
197663 | if (require_type && (o->type != require_type)) { |
181 | ✗ | av_log(obj, AV_LOG_ERROR, | |
182 | "Tried to set option '%s' of type %s from value of type %s, " | ||
183 | ✗ | "this is not supported\n", o->name, opt_type_desc[o->type].name, | |
184 | ✗ | opt_type_desc[require_type].name); | |
185 | ✗ | return AVERROR(EINVAL); | |
186 | } | ||
187 | |||
188 |
2/2✓ Branch 0 taken 173977 times.
✓ Branch 1 taken 23686 times.
|
197663 | if (!(o->flags & AV_OPT_FLAG_RUNTIME_PARAM)) { |
189 | 173977 | unsigned *state_flags = NULL; | |
190 | const AVClass *class; | ||
191 | |||
192 | // try state flags first from the target (child), then from its parent | ||
193 | 173977 | class = *(const AVClass**)tgt; | |
194 | 173977 | if ( | |
195 | #if LIBAVUTIL_VERSION_MAJOR < 60 | ||
196 |
2/2✓ Branch 0 taken 173947 times.
✓ Branch 1 taken 30 times.
|
173977 | class->version >= AV_VERSION_INT(59, 41, 100) && |
197 | #endif | ||
198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 173947 times.
|
173947 | class->state_flags_offset) |
199 | ✗ | state_flags = (unsigned*)((uint8_t*)tgt + class->state_flags_offset); | |
200 | |||
201 |
3/4✓ Branch 0 taken 173977 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44062 times.
✓ Branch 3 taken 129915 times.
|
173977 | if (!state_flags && obj != tgt) { |
202 | 44062 | class = *(const AVClass**)obj; | |
203 | 44062 | if ( | |
204 | #if LIBAVUTIL_VERSION_MAJOR < 60 | ||
205 |
1/2✓ Branch 0 taken 44062 times.
✗ Branch 1 not taken.
|
44062 | class->version >= AV_VERSION_INT(59, 41, 100) && |
206 | #endif | ||
207 |
2/2✓ Branch 0 taken 43312 times.
✓ Branch 1 taken 750 times.
|
44062 | class->state_flags_offset) |
208 | 43312 | state_flags = (unsigned*)((uint8_t*)obj + class->state_flags_offset); | |
209 | } | ||
210 | |||
211 |
3/4✓ Branch 0 taken 43312 times.
✓ Branch 1 taken 130665 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 43312 times.
|
173977 | if (state_flags && (*state_flags & AV_CLASS_STATE_INITIALIZED)) { |
212 | ✗ | av_log(obj, AV_LOG_ERROR, "Option '%s' is not a runtime option and " | |
213 | "so cannot be set after the object has been initialized\n", | ||
214 | ✗ | o->name); | |
215 | #if LIBAVUTIL_VERSION_MAJOR >= 60 | ||
216 | return AVERROR(EINVAL); | ||
217 | #endif | ||
218 | } | ||
219 | } | ||
220 | |||
221 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 197613 times.
|
197663 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
222 | 50 | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
223 | |||
224 |
2/2✓ Branch 0 taken 194475 times.
✓ Branch 1 taken 3188 times.
|
197663 | if (po) |
225 | 194475 | *po = o; | |
226 |
2/2✓ Branch 0 taken 186261 times.
✓ Branch 1 taken 11402 times.
|
197663 | if (ptgt) |
227 | 186261 | *ptgt = tgt; | |
228 |
1/2✓ Branch 0 taken 197663 times.
✗ Branch 1 not taken.
|
197663 | if (pdst) |
229 | 197663 | *pdst = ((uint8_t *)tgt) + o->offset; | |
230 | |||
231 | 197663 | return 0; | |
232 | } | ||
233 | |||
234 | ✗ | static AVRational double_to_rational(double d) | |
235 | { | ||
236 | ✗ | AVRational r = av_d2q(d, 1 << 24); | |
237 | ✗ | if ((!r.num || !r.den) && d) | |
238 | ✗ | r = av_d2q(d, INT_MAX); | |
239 | ✗ | return r; | |
240 | } | ||
241 | |||
242 | 12099 | static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum) | |
243 | { | ||
244 |
6/11✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 12052 times.
✓ Branch 4 taken 23 times.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
12099 | switch (TYPE_BASE(o->type)) { |
245 | 9 | case AV_OPT_TYPE_FLAGS: | |
246 | 9 | *intnum = *(unsigned int*)dst; | |
247 | 9 | return 0; | |
248 | 3 | case AV_OPT_TYPE_PIXEL_FMT: | |
249 | 3 | *intnum = *(enum AVPixelFormat *)dst; | |
250 | 3 | return 0; | |
251 | 3 | case AV_OPT_TYPE_SAMPLE_FMT: | |
252 | 3 | *intnum = *(enum AVSampleFormat *)dst; | |
253 | 3 | return 0; | |
254 | 12052 | case AV_OPT_TYPE_BOOL: | |
255 | case AV_OPT_TYPE_INT: | ||
256 | 12052 | *intnum = *(int *)dst; | |
257 | 12052 | return 0; | |
258 | 23 | case AV_OPT_TYPE_UINT: | |
259 | 23 | *intnum = *(unsigned int *)dst; | |
260 | 23 | return 0; | |
261 | 9 | case AV_OPT_TYPE_DURATION: | |
262 | case AV_OPT_TYPE_INT64: | ||
263 | case AV_OPT_TYPE_UINT64: | ||
264 | 9 | *intnum = *(int64_t *)dst; | |
265 | 9 | return 0; | |
266 | ✗ | case AV_OPT_TYPE_FLOAT: | |
267 | ✗ | *num = *(float *)dst; | |
268 | ✗ | return 0; | |
269 | ✗ | case AV_OPT_TYPE_DOUBLE: | |
270 | ✗ | *num = *(double *)dst; | |
271 | ✗ | return 0; | |
272 | ✗ | case AV_OPT_TYPE_RATIONAL: | |
273 | ✗ | *intnum = ((AVRational *)dst)->num; | |
274 | ✗ | *den = ((AVRational *)dst)->den; | |
275 | ✗ | return 0; | |
276 | ✗ | case AV_OPT_TYPE_CONST: | |
277 | ✗ | *intnum = o->default_val.i64; | |
278 | ✗ | return 0; | |
279 | } | ||
280 | ✗ | return AVERROR(EINVAL); | |
281 | } | ||
282 | |||
283 | 7963411 | static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum) | |
284 | { | ||
285 | 7963411 | const enum AVOptionType type = TYPE_BASE(o->type); | |
286 | |||
287 |
4/4✓ Branch 0 taken 7104302 times.
✓ Branch 1 taken 859109 times.
✓ Branch 2 taken 7104301 times.
✓ Branch 3 taken 1 times.
|
7963411 | if (type != AV_OPT_TYPE_FLAGS && |
288 |
4/4✓ Branch 0 taken 7104293 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 7104286 times.
|
7104301 | (!den || o->max * den < num * intnum || o->min * den > num * intnum)) { |
289 |
4/6✓ Branch 0 taken 15 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
16 | num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN); |
290 | 16 | av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
291 | 16 | num, o->name, o->min, o->max); | |
292 | 16 | return AVERROR(ERANGE); | |
293 | } | ||
294 |
2/2✓ Branch 0 taken 859109 times.
✓ Branch 1 taken 7104286 times.
|
7963395 | if (type == AV_OPT_TYPE_FLAGS) { |
295 | 859109 | double d = num*intnum/den; | |
296 |
3/6✓ Branch 0 taken 859109 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 859109 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 859109 times.
|
859109 | if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) { |
297 | ✗ | av_log(obj, AV_LOG_ERROR, | |
298 | "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n", | ||
299 | ✗ | num*intnum/den, o->name); | |
300 | ✗ | return AVERROR(ERANGE); | |
301 | } | ||
302 | } | ||
303 | |||
304 |
7/9✓ Branch 0 taken 99347 times.
✓ Branch 1 taken 49093 times.
✓ Branch 2 taken 6282278 times.
✓ Branch 3 taken 466158 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 774951 times.
✓ Branch 6 taken 99089 times.
✓ Branch 7 taken 192479 times.
✗ Branch 8 not taken.
|
7963395 | switch (type) { |
305 | 99347 | case AV_OPT_TYPE_PIXEL_FMT: | |
306 | 99347 | *(enum AVPixelFormat *)dst = llrint(num / den) * intnum; | |
307 | 99347 | break; | |
308 | 49093 | case AV_OPT_TYPE_SAMPLE_FMT: | |
309 | 49093 | *(enum AVSampleFormat *)dst = llrint(num / den) * intnum; | |
310 | 49093 | break; | |
311 | 6282278 | case AV_OPT_TYPE_BOOL: | |
312 | case AV_OPT_TYPE_FLAGS: | ||
313 | case AV_OPT_TYPE_INT: | ||
314 | case AV_OPT_TYPE_UINT: | ||
315 | 6282278 | *(int *)dst = llrint(num / den) * intnum; | |
316 | 6282278 | break; | |
317 | 466158 | case AV_OPT_TYPE_DURATION: | |
318 | case AV_OPT_TYPE_INT64:{ | ||
319 | 466158 | double d = num / den; | |
320 |
3/4✓ Branch 0 taken 1160 times.
✓ Branch 1 taken 464998 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1160 times.
|
466158 | if (intnum == 1 && d == (double)INT64_MAX) { |
321 | ✗ | *(int64_t *)dst = INT64_MAX; | |
322 | } else | ||
323 | 466158 | *(int64_t *)dst = llrint(d) * intnum; | |
324 | 466158 | break;} | |
325 | ✗ | case AV_OPT_TYPE_UINT64:{ | |
326 | ✗ | double d = num / den; | |
327 | // We must special case uint64_t here as llrint() does not support values | ||
328 | // outside the int64_t range and there is no portable function which does | ||
329 | // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double | ||
330 | // while INT64_MAX is not | ||
331 | ✗ | if (intnum == 1 && d == (double)UINT64_MAX) { | |
332 | ✗ | *(uint64_t *)dst = UINT64_MAX; | |
333 | ✗ | } else if (d > INT64_MAX + 1ULL) { | |
334 | ✗ | *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum; | |
335 | } else { | ||
336 | ✗ | *(uint64_t *)dst = llrint(d) * intnum; | |
337 | } | ||
338 | ✗ | break;} | |
339 | 774951 | case AV_OPT_TYPE_FLOAT: | |
340 | 774951 | *(float *)dst = num * intnum / den; | |
341 | 774951 | break; | |
342 | 99089 | case AV_OPT_TYPE_DOUBLE: | |
343 | 99089 | *(double *)dst = num * intnum / den; | |
344 | 99089 | break; | |
345 | 192479 | case AV_OPT_TYPE_RATIONAL: | |
346 | case AV_OPT_TYPE_VIDEO_RATE: | ||
347 |
1/2✓ Branch 0 taken 192479 times.
✗ Branch 1 not taken.
|
192479 | if ((int) num == num) |
348 | 192479 | *(AVRational *)dst = (AVRational) { num *intnum, den }; | |
349 | else | ||
350 | ✗ | *(AVRational *)dst = double_to_rational(num * intnum / den); | |
351 | 192479 | break; | |
352 | ✗ | default: | |
353 | ✗ | return AVERROR(EINVAL); | |
354 | } | ||
355 | 7963395 | return 0; | |
356 | } | ||
357 | |||
358 | 16046 | static int hexchar2int(char c) { | |
359 |
3/4✓ Branch 0 taken 16046 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11576 times.
✓ Branch 3 taken 4470 times.
|
16046 | if (c >= '0' && c <= '9') |
360 | 11576 | return c - '0'; | |
361 |
4/4✓ Branch 0 taken 4468 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4467 times.
✓ Branch 3 taken 1 times.
|
4470 | if (c >= 'a' && c <= 'f') |
362 | 4467 | return c - 'a' + 10; | |
363 |
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') |
364 | 2 | return c - 'A' + 10; | |
365 | 1 | return -1; | |
366 | } | ||
367 | |||
368 | 40347 | static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
369 | { | ||
370 | 40347 | int *lendst = (int *)(dst + 1); | |
371 | uint8_t *bin, *ptr; | ||
372 | int len; | ||
373 | |||
374 | 40347 | av_freep(dst); | |
375 | 40347 | *lendst = 0; | |
376 | |||
377 |
4/4✓ Branch 0 taken 523 times.
✓ Branch 1 taken 39824 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 512 times.
|
40347 | if (!val || !(len = strlen(val))) |
378 | 39835 | return 0; | |
379 | |||
380 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 511 times.
|
512 | if (len & 1) |
381 | 1 | return AVERROR(EINVAL); | |
382 | 511 | len /= 2; | |
383 | |||
384 | 511 | ptr = bin = av_malloc(len); | |
385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 511 times.
|
511 | if (!ptr) |
386 | ✗ | return AVERROR(ENOMEM); | |
387 |
2/2✓ Branch 0 taken 8023 times.
✓ Branch 1 taken 510 times.
|
8533 | while (*val) { |
388 | 8023 | int a = hexchar2int(*val++); | |
389 | 8023 | int b = hexchar2int(*val++); | |
390 |
3/4✓ Branch 0 taken 8023 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 8022 times.
|
8023 | if (a < 0 || b < 0) { |
391 | 1 | av_free(bin); | |
392 | 1 | return AVERROR(EINVAL); | |
393 | } | ||
394 | 8022 | *ptr++ = (a << 4) | b; | |
395 | } | ||
396 | 510 | *dst = bin; | |
397 | 510 | *lendst = len; | |
398 | |||
399 | 510 | return 0; | |
400 | } | ||
401 | |||
402 | 499967 | static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
403 | { | ||
404 | 499967 | av_freep(dst); | |
405 |
2/2✓ Branch 0 taken 407517 times.
✓ Branch 1 taken 92450 times.
|
499967 | if (!val) |
406 | 407517 | return 0; | |
407 | 92450 | *dst = av_strdup(val); | |
408 |
1/2✓ Branch 0 taken 92450 times.
✗ Branch 1 not taken.
|
92450 | return *dst ? 0 : AVERROR(ENOMEM); |
409 | } | ||
410 | |||
411 | #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \ | ||
412 | opt->type == AV_OPT_TYPE_UINT64 || \ | ||
413 | opt->type == AV_OPT_TYPE_CONST || \ | ||
414 | opt->type == AV_OPT_TYPE_FLAGS || \ | ||
415 | opt->type == AV_OPT_TYPE_UINT || \ | ||
416 | opt->type == AV_OPT_TYPE_INT) \ | ||
417 | ? opt->default_val.i64 \ | ||
418 | : opt->default_val.dbl) | ||
419 | |||
420 | 123312 | static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst) | |
421 | { | ||
422 | 123312 | const enum AVOptionType type = TYPE_BASE(o->type); | |
423 | 123312 | int ret = 0; | |
424 | |||
425 |
3/4✓ Branch 0 taken 122013 times.
✓ Branch 1 taken 1299 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 122013 times.
|
123312 | if (type == AV_OPT_TYPE_RATIONAL || type == AV_OPT_TYPE_VIDEO_RATE) { |
426 | int num, den; | ||
427 | char c; | ||
428 |
2/2✓ Branch 0 taken 1281 times.
✓ Branch 1 taken 18 times.
|
1299 | if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) { |
429 |
2/2✓ Branch 1 taken 1279 times.
✓ Branch 2 taken 2 times.
|
1281 | if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0) |
430 | 1279 | return ret; | |
431 | 2 | ret = 0; | |
432 | } | ||
433 | } | ||
434 | |||
435 | 43000 | for (;;) { | |
436 | 165033 | int i = 0; | |
437 | char buf[256]; | ||
438 | 165033 | int cmd = 0; | |
439 | double d; | ||
440 | 165033 | int64_t intnum = 1; | |
441 | |||
442 |
2/2✓ Branch 0 taken 100220 times.
✓ Branch 1 taken 64813 times.
|
165033 | if (type == AV_OPT_TYPE_FLAGS) { |
443 |
4/4✓ Branch 0 taken 21772 times.
✓ Branch 1 taken 78448 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 21749 times.
|
100220 | if (*val == '+' || *val == '-') |
444 | 78471 | cmd = *(val++); | |
445 |
7/8✓ Branch 0 taken 831408 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 774188 times.
✓ Branch 3 taken 57220 times.
✓ Branch 4 taken 731189 times.
✓ Branch 5 taken 42999 times.
✓ Branch 6 taken 731188 times.
✓ Branch 7 taken 1 times.
|
831408 | for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++) |
446 | 731188 | buf[i] = val[i]; | |
447 | 100220 | buf[i] = 0; | |
448 | } | ||
449 | |||
450 | { | ||
451 | int res; | ||
452 | 165033 | int ci = 0; | |
453 | double const_values[64]; | ||
454 | const char * const_names[64]; | ||
455 | 165033 | int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0; | |
456 |
2/2✓ Branch 0 taken 100220 times.
✓ Branch 1 taken 64813 times.
|
165033 | const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags); |
457 |
3/4✓ Branch 0 taken 116951 times.
✓ Branch 1 taken 48082 times.
✓ Branch 2 taken 116951 times.
✗ Branch 3 not taken.
|
165033 | if (o_named && o_named->type == AV_OPT_TYPE_CONST) { |
458 |
3/12✓ Branch 0 taken 116951 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 116951 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 116951 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
116951 | d = DEFAULT_NUMVAL(o_named); |
459 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 116951 times.
|
116951 | if (o_named->flags & AV_OPT_FLAG_DEPRECATED) |
460 | ✗ | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", | |
461 | ✗ | o_named->name, o_named->help); | |
462 | } else { | ||
463 |
2/2✓ Branch 0 taken 34121 times.
✓ Branch 1 taken 13961 times.
|
48082 | if (o->unit) { |
464 |
2/2✓ Branch 1 taken 7539037 times.
✓ Branch 2 taken 34121 times.
|
7573158 | for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) { |
465 |
2/2✓ Branch 0 taken 5266630 times.
✓ Branch 1 taken 2272407 times.
|
7539037 | if (o_named->type == AV_OPT_TYPE_CONST && |
466 |
1/2✓ Branch 0 taken 5266630 times.
✗ Branch 1 not taken.
|
5266630 | o_named->unit && |
467 |
2/2✓ Branch 0 taken 309753 times.
✓ Branch 1 taken 4956877 times.
|
5266630 | !strcmp(o_named->unit, o->unit)) { |
468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 309753 times.
|
309753 | if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) { |
469 | ✗ | av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit); | |
470 | 8 | return AVERROR_PATCHWELCOME; | |
471 | } | ||
472 | 309753 | const_names [ci ] = o_named->name; | |
473 |
3/12✓ Branch 0 taken 309753 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 309753 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 309753 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
309753 | const_values[ci++] = DEFAULT_NUMVAL(o_named); |
474 | } | ||
475 | } | ||
476 | } | ||
477 | 48082 | const_names [ci ] = "default"; | |
478 |
10/12✓ Branch 0 taken 46919 times.
✓ Branch 1 taken 1163 times.
✓ Branch 2 taken 46919 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 46919 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 39008 times.
✓ Branch 7 taken 7911 times.
✓ Branch 8 taken 38926 times.
✓ Branch 9 taken 82 times.
✓ Branch 10 taken 38047 times.
✓ Branch 11 taken 879 times.
|
48082 | const_values[ci++] = DEFAULT_NUMVAL(o); |
479 | 48082 | const_names [ci ] = "max"; | |
480 | 48082 | const_values[ci++] = o->max; | |
481 | 48082 | const_names [ci ] = "min"; | |
482 | 48082 | const_values[ci++] = o->min; | |
483 | 48082 | const_names [ci ] = "none"; | |
484 | 48082 | const_values[ci++] = 0; | |
485 | 48082 | const_names [ci ] = "all"; | |
486 | 48082 | const_values[ci++] = ~0; | |
487 | 48082 | const_names [ci] = NULL; | |
488 | 48082 | const_values[ci] = 0; | |
489 | |||
490 |
2/2✓ Branch 0 taken 7911 times.
✓ Branch 1 taken 40171 times.
|
48082 | res = av_expr_parse_and_eval(&d, i ? buf : val, const_names, |
491 | const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); | ||
492 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 48074 times.
|
48082 | if (res < 0) { |
493 | 8 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val); | |
494 | 8 | return res; | |
495 | } | ||
496 | } | ||
497 | } | ||
498 |
2/2✓ Branch 0 taken 100220 times.
✓ Branch 1 taken 64805 times.
|
165025 | if (type == AV_OPT_TYPE_FLAGS) { |
499 | 100220 | intnum = *(unsigned int*)dst; | |
500 |
2/2✓ Branch 0 taken 78448 times.
✓ Branch 1 taken 21772 times.
|
100220 | if (cmd == '+') |
501 | 78448 | d = intnum | (int64_t)d; | |
502 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 21749 times.
|
21772 | else if (cmd == '-') |
503 | 23 | d = intnum &~(int64_t)d; | |
504 | } | ||
505 | |||
506 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 165011 times.
|
165025 | if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0) |
507 | 14 | return ret; | |
508 | 165011 | val += i; | |
509 |
4/4✓ Branch 0 taken 100220 times.
✓ Branch 1 taken 64791 times.
✓ Branch 2 taken 57220 times.
✓ Branch 3 taken 43000 times.
|
165011 | if (!i || !*val) |
510 | 122011 | return 0; | |
511 | } | ||
512 | } | ||
513 | |||
514 | 40556 | static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst) | |
515 | { | ||
516 | int ret; | ||
517 | |||
518 |
3/4✓ Branch 0 taken 5603 times.
✓ Branch 1 taken 34953 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5603 times.
|
40556 | if (!val || !strcmp(val, "none")) { |
519 | 34953 | dst[0] = | |
520 | 34953 | dst[1] = 0; | |
521 | 34953 | return 0; | |
522 | } | ||
523 | 5603 | ret = av_parse_video_size(dst, dst + 1, val); | |
524 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5602 times.
|
5603 | if (ret < 0) |
525 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val); | |
526 | 5603 | return ret; | |
527 | } | ||
528 | |||
529 | 8154 | static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst) | |
530 | { | ||
531 | 8154 | int ret = av_parse_video_rate(dst, val); | |
532 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 8153 times.
|
8154 | if (ret < 0) |
533 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val); | |
534 | 8154 | return ret; | |
535 | } | ||
536 | |||
537 | 346 | static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
538 | { | ||
539 | int ret; | ||
540 | |||
541 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 346 times.
|
346 | if (!val) { |
542 | ✗ | return 0; | |
543 | } else { | ||
544 | 346 | ret = av_parse_color(dst, val, -1, obj); | |
545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 346 times.
|
346 | if (ret < 0) |
546 | ✗ | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val); | |
547 | 346 | return ret; | |
548 | } | ||
549 | return 0; | ||
550 | } | ||
551 | |||
552 | 37 | static const char *get_bool_name(int val) | |
553 | { | ||
554 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 32 times.
|
37 | if (val < 0) |
555 | 5 | return "auto"; | |
556 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 11 times.
|
32 | return val ? "true" : "false"; |
557 | } | ||
558 | |||
559 | 9573 | static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst) | |
560 | { | ||
561 | int n; | ||
562 | |||
563 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9573 times.
|
9573 | if (!val) |
564 | ✗ | return 0; | |
565 | |||
566 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9570 times.
|
9573 | if (!strcmp(val, "auto")) { |
567 | 3 | n = -1; | |
568 |
2/2✓ Branch 1 taken 1269 times.
✓ Branch 2 taken 8301 times.
|
9570 | } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) { |
569 | 1269 | n = 1; | |
570 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 8289 times.
|
8301 | } else if (av_match_name(val, "false,n,no,disable,disabled,off")) { |
571 | 12 | n = 0; | |
572 | } else { | ||
573 | 8289 | char *end = NULL; | |
574 | 8289 | n = strtol(val, &end, 10); | |
575 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8289 times.
|
8289 | if (val + strlen(val) != end) |
576 | ✗ | goto fail; | |
577 | } | ||
578 | |||
579 |
2/4✓ Branch 0 taken 9573 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9573 times.
|
9573 | if (n < o->min || n > o->max) |
580 | ✗ | goto fail; | |
581 | |||
582 | 9573 | *dst = n; | |
583 | 9573 | return 0; | |
584 | |||
585 | ✗ | fail: | |
586 | ✗ | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val); | |
587 | ✗ | return AVERROR(EINVAL); | |
588 | } | ||
589 | |||
590 | 4589 | static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst, | |
591 | int fmt_nb, int ((*get_fmt)(const char *)), const char *desc) | ||
592 | { | ||
593 | int fmt, min, max; | ||
594 | |||
595 |
2/4✓ Branch 0 taken 4589 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4589 times.
|
4589 | if (!val || !strcmp(val, "none")) { |
596 | ✗ | fmt = -1; | |
597 | } else { | ||
598 | 4589 | fmt = get_fmt(val); | |
599 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4585 times.
|
4589 | if (fmt == -1) { |
600 | char *tail; | ||
601 | 4 | fmt = strtol(val, &tail, 0); | |
602 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
4 | if (*tail || (unsigned)fmt >= fmt_nb) { |
603 | 2 | av_log(obj, AV_LOG_ERROR, | |
604 | "Unable to parse option value \"%s\" as %s\n", val, desc); | ||
605 | 2 | return AVERROR(EINVAL); | |
606 | } | ||
607 | } | ||
608 | } | ||
609 | |||
610 |
2/2✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 2539 times.
|
4587 | min = FFMAX(o->min, -1); |
611 |
2/2✓ Branch 0 taken 2541 times.
✓ Branch 1 taken 2046 times.
|
4587 | max = FFMIN(o->max, fmt_nb-1); |
612 | |||
613 | // hack for compatibility with old ffmpeg | ||
614 |
4/4✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 2539 times.
✓ Branch 2 taken 2046 times.
✓ Branch 3 taken 2 times.
|
4587 | if(min == 0 && max == 0) { |
615 | 2046 | min = -1; | |
616 | 2046 | max = fmt_nb-1; | |
617 | } | ||
618 | |||
619 |
2/4✓ Branch 0 taken 4587 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4587 times.
|
4587 | if (fmt < min || fmt > max) { |
620 | ✗ | av_log(obj, AV_LOG_ERROR, | |
621 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
622 | ✗ | fmt, o->name, desc, min, max); | |
623 | ✗ | return AVERROR(ERANGE); | |
624 | } | ||
625 | |||
626 | 4587 | *(int *)dst = fmt; | |
627 | 4587 | return 0; | |
628 | } | ||
629 | |||
630 | 7 | static int get_pix_fmt(const char *name) | |
631 | { | ||
632 | 7 | return av_get_pix_fmt(name); | |
633 | } | ||
634 | |||
635 | 7 | static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
636 | { | ||
637 | 7 | return set_string_fmt(obj, o, val, dst, | |
638 | AV_PIX_FMT_NB, get_pix_fmt, "pixel format"); | ||
639 | } | ||
640 | |||
641 | 4582 | static int get_sample_fmt(const char *name) | |
642 | { | ||
643 | 4582 | return av_get_sample_fmt(name); | |
644 | } | ||
645 | |||
646 | 4582 | static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
647 | { | ||
648 | 4582 | return set_string_fmt(obj, o, val, dst, | |
649 | AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format"); | ||
650 | } | ||
651 | |||
652 | 272 | static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
653 | { | ||
654 | 272 | AVDictionary *options = NULL; | |
655 | |||
656 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 214 times.
|
272 | if (val) { |
657 | 58 | int ret = av_dict_parse_string(&options, val, "=", ":", 0); | |
658 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) { |
659 | ✗ | av_dict_free(&options); | |
660 | ✗ | return ret; | |
661 | } | ||
662 | } | ||
663 | |||
664 | 272 | av_dict_free((AVDictionary **)dst); | |
665 | 272 | *dst = (uint8_t *)options; | |
666 | |||
667 | 272 | return 0; | |
668 | } | ||
669 | |||
670 | 45986 | static int set_string_channel_layout(void *obj, const AVOption *o, | |
671 | const char *val, void *dst) | ||
672 | { | ||
673 | 45986 | AVChannelLayout *channel_layout = dst; | |
674 | 45986 | av_channel_layout_uninit(channel_layout); | |
675 |
2/2✓ Branch 0 taken 45292 times.
✓ Branch 1 taken 694 times.
|
45986 | if (!val) |
676 | 45292 | return 0; | |
677 | 694 | return av_channel_layout_from_string(channel_layout, val); | |
678 | } | ||
679 | |||
680 | 186935 | static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, | |
681 | const char *val, void *dst) | ||
682 | { | ||
683 | 186935 | const enum AVOptionType type = TYPE_BASE(o->type); | |
684 | int ret; | ||
685 | |||
686 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 186935 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
186935 | if (!val && (type != AV_OPT_TYPE_STRING && |
687 | ✗ | type != AV_OPT_TYPE_PIXEL_FMT && type != AV_OPT_TYPE_SAMPLE_FMT && | |
688 | ✗ | type != AV_OPT_TYPE_IMAGE_SIZE && | |
689 | ✗ | type != AV_OPT_TYPE_DURATION && type != AV_OPT_TYPE_COLOR && | |
690 | type != AV_OPT_TYPE_BOOL)) | ||
691 | ✗ | return AVERROR(EINVAL); | |
692 | |||
693 |
12/13✓ Branch 0 taken 9573 times.
✓ Branch 1 taken 59157 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 110257 times.
✓ Branch 4 taken 2167 times.
✓ Branch 5 taken 202 times.
✓ Branch 6 taken 7 times.
✓ Branch 7 taken 4582 times.
✓ Branch 8 taken 279 times.
✓ Branch 9 taken 38 times.
✓ Branch 10 taken 608 times.
✓ Branch 11 taken 51 times.
✗ Branch 12 not taken.
|
186935 | switch (type) { |
694 | 9573 | case AV_OPT_TYPE_BOOL: | |
695 | 9573 | return set_string_bool(obj, o, val, dst); | |
696 | 59157 | case AV_OPT_TYPE_STRING: | |
697 | 59157 | return set_string(obj, o, val, dst); | |
698 | 14 | case AV_OPT_TYPE_BINARY: | |
699 | 14 | return set_string_binary(obj, o, val, dst); | |
700 | 110257 | case AV_OPT_TYPE_FLAGS: | |
701 | case AV_OPT_TYPE_INT: | ||
702 | case AV_OPT_TYPE_UINT: | ||
703 | case AV_OPT_TYPE_INT64: | ||
704 | case AV_OPT_TYPE_UINT64: | ||
705 | case AV_OPT_TYPE_FLOAT: | ||
706 | case AV_OPT_TYPE_DOUBLE: | ||
707 | case AV_OPT_TYPE_RATIONAL: | ||
708 | 110257 | return set_string_number(obj, target_obj, o, val, dst); | |
709 | 2167 | case AV_OPT_TYPE_IMAGE_SIZE: | |
710 | 2167 | return set_string_image_size(obj, o, val, dst); | |
711 | 202 | case AV_OPT_TYPE_VIDEO_RATE: { | |
712 | AVRational tmp; | ||
713 | 202 | ret = set_string_video_rate(obj, o, val, &tmp); | |
714 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 201 times.
|
202 | if (ret < 0) |
715 | 1 | return ret; | |
716 | 201 | return write_number(obj, o, dst, 1, tmp.den, tmp.num); | |
717 | } | ||
718 | 7 | case AV_OPT_TYPE_PIXEL_FMT: | |
719 | 7 | return set_string_pixel_fmt(obj, o, val, dst); | |
720 | 4582 | case AV_OPT_TYPE_SAMPLE_FMT: | |
721 | 4582 | return set_string_sample_fmt(obj, o, val, dst); | |
722 | 279 | case AV_OPT_TYPE_DURATION: | |
723 | { | ||
724 | 279 | int64_t usecs = 0; | |
725 |
1/2✓ Branch 0 taken 279 times.
✗ Branch 1 not taken.
|
279 | if (val) { |
726 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 278 times.
|
279 | if ((ret = av_parse_time(&usecs, val, 1)) < 0) { |
727 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val); | |
728 | 1 | return ret; | |
729 | } | ||
730 | } | ||
731 |
2/4✓ Branch 0 taken 278 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 278 times.
|
278 | if (usecs < o->min || usecs > o->max) { |
732 | ✗ | av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
733 | ✗ | usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0); | |
734 | ✗ | return AVERROR(ERANGE); | |
735 | } | ||
736 | 278 | *(int64_t *)dst = usecs; | |
737 | 278 | return 0; | |
738 | } | ||
739 | 38 | case AV_OPT_TYPE_COLOR: | |
740 | 38 | return set_string_color(obj, o, val, dst); | |
741 | 608 | case AV_OPT_TYPE_CHLAYOUT: | |
742 | 608 | ret = set_string_channel_layout(obj, o, val, dst); | |
743 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 607 times.
|
608 | if (ret < 0) { |
744 | 1 | av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val); | |
745 | 1 | ret = AVERROR(EINVAL); | |
746 | } | ||
747 | 608 | return ret; | |
748 | 51 | case AV_OPT_TYPE_DICT: | |
749 | 51 | return set_string_dict(obj, o, val, dst); | |
750 | } | ||
751 | |||
752 | ✗ | av_log(obj, AV_LOG_ERROR, "Invalid option type.\n"); | |
753 | ✗ | return AVERROR(EINVAL); | |
754 | } | ||
755 | |||
756 | 2147 | static int opt_set_array(void *obj, void *target_obj, const AVOption *o, | |
757 | const char *val, void *dst) | ||
758 | { | ||
759 | 2147 | const AVOptionArrayDef *arr = o->default_val.arr; | |
760 | 2147 | const size_t elem_size = opt_type_desc[TYPE_BASE(o->type)].size; | |
761 | 2147 | const uint8_t sep = opt_array_sep(o); | |
762 | 2147 | uint8_t *str = NULL; | |
763 | |||
764 | 2147 | void *elems = NULL; | |
765 | 2147 | unsigned nb_elems = 0; | |
766 | int ret; | ||
767 | |||
768 |
4/4✓ Branch 0 taken 2136 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2134 times.
✓ Branch 3 taken 2 times.
|
2147 | if (val && *val) { |
769 | 2134 | str = av_malloc(strlen(val) + 1); | |
770 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2134 times.
|
2134 | if (!str) |
771 | ✗ | return AVERROR(ENOMEM); | |
772 | } | ||
773 | |||
774 | // split and unescape the string | ||
775 |
4/4✓ Branch 0 taken 4952 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2817 times.
✓ Branch 3 taken 2135 times.
|
4963 | while (val && *val) { |
776 | 2817 | uint8_t *p = str; | |
777 | void *tmp; | ||
778 | |||
779 |
3/6✓ Branch 0 taken 2809 times.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2809 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
2817 | if (arr && arr->size_max && nb_elems >= arr->size_max) { |
780 | ✗ | av_log(obj, AV_LOG_ERROR, | |
781 | "Cannot assign more than %u elements to array option %s\n", | ||
782 | ✗ | arr->size_max, o->name); | |
783 | ✗ | ret = AVERROR(EINVAL); | |
784 | ✗ | goto fail; | |
785 | } | ||
786 | |||
787 |
2/2✓ Branch 0 taken 11961 times.
✓ Branch 1 taken 2134 times.
|
14095 | for (; *val; val++, p++) { |
788 |
3/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 11898 times.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
|
11961 | if (*val == '\\' && val[1]) |
789 | 63 | val++; | |
790 |
2/2✓ Branch 0 taken 683 times.
✓ Branch 1 taken 11215 times.
|
11898 | else if (*val == sep) { |
791 | 683 | val++; | |
792 | 683 | break; | |
793 | } | ||
794 | 11278 | *p = *val; | |
795 | } | ||
796 | 2817 | *p = 0; | |
797 | |||
798 | 2817 | tmp = av_realloc_array(elems, nb_elems + 1, elem_size); | |
799 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2817 times.
|
2817 | if (!tmp) { |
800 | ✗ | ret = AVERROR(ENOMEM); | |
801 | ✗ | goto fail; | |
802 | } | ||
803 | 2817 | elems = tmp; | |
804 | |||
805 | 2817 | tmp = opt_array_pelem(o, elems, nb_elems); | |
806 | 2817 | memset(tmp, 0, elem_size); | |
807 | |||
808 | 2817 | ret = opt_set_elem(obj, target_obj, o, str, tmp); | |
809 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2816 times.
|
2817 | if (ret < 0) |
810 | 1 | goto fail; | |
811 | 2816 | nb_elems++; | |
812 | } | ||
813 | 2146 | av_freep(&str); | |
814 | |||
815 | 2146 | opt_free_array(o, dst, opt_array_pcount(dst)); | |
816 | |||
817 |
3/4✓ Branch 0 taken 2131 times.
✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2131 times.
|
2146 | if (arr && nb_elems < arr->size_min) { |
818 | ✗ | av_log(obj, AV_LOG_ERROR, | |
819 | "Cannot assign fewer than %u elements to array option %s\n", | ||
820 | ✗ | arr->size_min, o->name); | |
821 | ✗ | ret = AVERROR(EINVAL); | |
822 | ✗ | goto fail; | |
823 | } | ||
824 | |||
825 | 2146 | *((void **)dst) = elems; | |
826 | 2146 | *opt_array_pcount(dst) = nb_elems; | |
827 | |||
828 | 2146 | return 0; | |
829 | 1 | fail: | |
830 | 1 | av_freep(&str); | |
831 | 1 | opt_free_array(o, &elems, &nb_elems); | |
832 | 1 | return ret; | |
833 | } | ||
834 | |||
835 | 232641 | int av_opt_set(void *obj, const char *name, const char *val, int search_flags) | |
836 | { | ||
837 | void *dst, *target_obj; | ||
838 | const AVOption *o; | ||
839 | int ret; | ||
840 | |||
841 | 232641 | ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &dst); | |
842 |
2/2✓ Branch 0 taken 46390 times.
✓ Branch 1 taken 186251 times.
|
232641 | if (ret < 0) |
843 | 46390 | return ret; | |
844 | |||
845 | 186251 | return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ? | |
846 |
2/2✓ Branch 0 taken 2133 times.
✓ Branch 1 taken 184118 times.
|
186251 | opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst); |
847 | } | ||
848 | |||
849 | #define OPT_EVAL_NUMBER(name, opttype, vartype) \ | ||
850 | int av_opt_eval_ ## name(void *obj, const AVOption *o, \ | ||
851 | const char *val, vartype *name ## _out) \ | ||
852 | { \ | ||
853 | if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \ | ||
854 | return AVERROR(EINVAL); \ | ||
855 | return set_string_number(obj, obj, o, val, name ## _out); \ | ||
856 | } | ||
857 | |||
858 |
3/6✓ Branch 0 taken 13035 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13035 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 13035 times.
|
13035 | OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int) |
859 |
3/6✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 20 times.
|
20 | OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int) |
860 | ✗ | OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned) | |
861 | ✗ | OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t) | |
862 | ✗ | OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float) | |
863 | ✗ | OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double) | |
864 | ✗ | OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational) | |
865 | |||
866 | 24712 | static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, | |
867 | int search_flags, int require_type) | ||
868 | { | ||
869 | void *dst; | ||
870 | const AVOption *o; | ||
871 | int ret; | ||
872 | |||
873 | 24712 | ret = opt_set_init(obj, name, search_flags, require_type, NULL, &o, &dst); | |
874 |
2/2✓ Branch 0 taken 16498 times.
✓ Branch 1 taken 8214 times.
|
24712 | if (ret < 0) |
875 | 16498 | return ret; | |
876 | |||
877 | 8214 | return write_number(obj, o, dst, num, den, intnum); | |
878 | } | ||
879 | |||
880 | 24712 | int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags) | |
881 | { | ||
882 | 24712 | return set_number(obj, name, 1, 1, val, search_flags, 0); | |
883 | } | ||
884 | |||
885 | ✗ | int av_opt_set_double(void *obj, const char *name, double val, int search_flags) | |
886 | { | ||
887 | ✗ | return set_number(obj, name, val, 1, 1, search_flags, 0); | |
888 | } | ||
889 | |||
890 | ✗ | int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) | |
891 | { | ||
892 | ✗ | return set_number(obj, name, val.num, val.den, 1, search_flags, 0); | |
893 | } | ||
894 | |||
895 | 24 | int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags) | |
896 | { | ||
897 | uint8_t *ptr; | ||
898 | uint8_t **dst; | ||
899 | int *lendst; | ||
900 | int ret; | ||
901 | |||
902 | 24 | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_BINARY, | |
903 | NULL, NULL, (void**)&dst); | ||
904 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | if (ret < 0) |
905 | ✗ | return ret; | |
906 | |||
907 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | ptr = len ? av_malloc(len) : NULL; |
908 |
2/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
|
24 | if (len && !ptr) |
909 | ✗ | return AVERROR(ENOMEM); | |
910 | |||
911 | 24 | lendst = (int *)(dst + 1); | |
912 | |||
913 | 24 | av_free(*dst); | |
914 | 24 | *dst = ptr; | |
915 | 24 | *lendst = len; | |
916 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (len) |
917 | 24 | memcpy(ptr, val, len); | |
918 | |||
919 | 24 | return 0; | |
920 | } | ||
921 | |||
922 | ✗ | int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags) | |
923 | { | ||
924 | const AVOption *o; | ||
925 | int *dst; | ||
926 | int ret; | ||
927 | |||
928 | ✗ | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_IMAGE_SIZE, | |
929 | NULL, &o, (void**)&dst); | ||
930 | ✗ | if (ret < 0) | |
931 | ✗ | return ret; | |
932 | |||
933 | ✗ | if (w<0 || h<0) { | |
934 | ✗ | av_log(obj, AV_LOG_ERROR, | |
935 | ✗ | "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name); | |
936 | ✗ | return AVERROR(EINVAL); | |
937 | } | ||
938 | |||
939 | ✗ | dst[0] = w; | |
940 | ✗ | dst[1] = h; | |
941 | |||
942 | ✗ | return 0; | |
943 | } | ||
944 | |||
945 | ✗ | int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags) | |
946 | { | ||
947 | ✗ | return set_number(obj, name, val.num, val.den, 1, search_flags, AV_OPT_TYPE_VIDEO_RATE); | |
948 | } | ||
949 | |||
950 | ✗ | static int set_format(void *obj, const char *name, int fmt, int search_flags, | |
951 | enum AVOptionType type, const char *desc, int nb_fmts) | ||
952 | { | ||
953 | const AVOption *o; | ||
954 | int *dst; | ||
955 | int min, max, ret; | ||
956 | |||
957 | ✗ | ret = opt_set_init(obj, name, search_flags, type, NULL, &o, (void**)&dst); | |
958 | ✗ | if (ret < 0) | |
959 | ✗ | return ret; | |
960 | |||
961 | ✗ | min = FFMAX(o->min, -1); | |
962 | ✗ | max = FFMIN(o->max, nb_fmts-1); | |
963 | |||
964 | ✗ | if (fmt < min || fmt > max) { | |
965 | ✗ | av_log(obj, AV_LOG_ERROR, | |
966 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
967 | fmt, name, desc, min, max); | ||
968 | ✗ | return AVERROR(ERANGE); | |
969 | } | ||
970 | ✗ | *dst = fmt; | |
971 | ✗ | return 0; | |
972 | } | ||
973 | |||
974 | ✗ | int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags) | |
975 | { | ||
976 | ✗ | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB); | |
977 | } | ||
978 | |||
979 | ✗ | int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags) | |
980 | { | ||
981 | ✗ | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB); | |
982 | } | ||
983 | |||
984 | ✗ | int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, | |
985 | int search_flags) | ||
986 | { | ||
987 | AVDictionary **dst; | ||
988 | int ret; | ||
989 | |||
990 | ✗ | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_DICT, NULL, NULL, | |
991 | (void**)&dst); | ||
992 | ✗ | if (ret < 0) | |
993 | ✗ | return ret; | |
994 | |||
995 | ✗ | av_dict_free(dst); | |
996 | |||
997 | ✗ | return av_dict_copy(dst, val, 0); | |
998 | } | ||
999 | |||
1000 | 3164 | int av_opt_set_chlayout(void *obj, const char *name, | |
1001 | const AVChannelLayout *channel_layout, | ||
1002 | int search_flags) | ||
1003 | { | ||
1004 | AVChannelLayout *dst; | ||
1005 | int ret; | ||
1006 | |||
1007 | 3164 | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_CHLAYOUT, NULL, NULL, | |
1008 | (void**)&dst); | ||
1009 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3164 times.
|
3164 | if (ret < 0) |
1010 | ✗ | return ret; | |
1011 | |||
1012 | 3164 | return av_channel_layout_copy(dst, channel_layout); | |
1013 | } | ||
1014 | |||
1015 | 5 | static void format_duration(char *buf, size_t size, int64_t d) | |
1016 | { | ||
1017 | char *e; | ||
1018 | |||
1019 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | av_assert0(size >= 25); |
1020 |
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) { |
1021 | ✗ | *(buf++) = '-'; | |
1022 | ✗ | size--; | |
1023 | ✗ | d = -d; | |
1024 | } | ||
1025 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (d == INT64_MAX) |
1026 | ✗ | snprintf(buf, size, "INT64_MAX"); | |
1027 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d == INT64_MIN) |
1028 | ✗ | snprintf(buf, size, "INT64_MIN"); | |
1029 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > (int64_t)3600*1000000) |
1030 | ✗ | snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000, | |
1031 | ✗ | (int)((d / 60000000) % 60), | |
1032 | ✗ | (int)((d / 1000000) % 60), | |
1033 | ✗ | (int)(d % 1000000)); | |
1034 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > 60*1000000) |
1035 | ✗ | snprintf(buf, size, "%d:%02d.%06d", | |
1036 | ✗ | (int)(d / 60000000), | |
1037 | ✗ | (int)((d / 1000000) % 60), | |
1038 | ✗ | (int)(d % 1000000)); | |
1039 | else | ||
1040 | 5 | snprintf(buf, size, "%d.%06d", | |
1041 | 5 | (int)(d / 1000000), | |
1042 | 5 | (int)(d % 1000000)); | |
1043 | 5 | e = buf + strlen(buf); | |
1044 |
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') |
1045 | 15 | *(--e) = 0; | |
1046 |
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] == '.') |
1047 | ✗ | *(--e) = 0; | |
1048 | 5 | } | |
1049 | |||
1050 | 11045 | static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, | |
1051 | const void *dst, int search_flags) | ||
1052 | { | ||
1053 | int ret; | ||
1054 | |||
1055 |
17/20✓ Branch 0 taken 34 times.
✓ Branch 1 taken 5838 times.
✓ Branch 2 taken 5026 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 12 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 26 times.
✓ Branch 11 taken 12 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 8 times.
✓ Branch 18 taken 22 times.
✗ Branch 19 not taken.
|
11045 | switch (TYPE_BASE(o->type)) { |
1056 | 34 | case AV_OPT_TYPE_BOOL: | |
1057 | 34 | ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst)); | |
1058 | 34 | break; | |
1059 | 5838 | case AV_OPT_TYPE_FLAGS: | |
1060 | 5838 | ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst); | |
1061 | 5838 | break; | |
1062 | 5026 | case AV_OPT_TYPE_INT: | |
1063 | 5026 | ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst); | |
1064 | 5026 | break; | |
1065 | 19 | case AV_OPT_TYPE_UINT: | |
1066 | 19 | ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst); | |
1067 | 19 | break; | |
1068 | 18 | case AV_OPT_TYPE_INT64: | |
1069 | 18 | ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst); | |
1070 | 18 | break; | |
1071 | ✗ | case AV_OPT_TYPE_UINT64: | |
1072 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst); | |
1073 | ✗ | break; | |
1074 | 5 | case AV_OPT_TYPE_FLOAT: | |
1075 | 5 | ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst); | |
1076 | 5 | break; | |
1077 | 5 | case AV_OPT_TYPE_DOUBLE: | |
1078 | 5 | ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst); | |
1079 | 5 | break; | |
1080 | 12 | case AV_OPT_TYPE_VIDEO_RATE: | |
1081 | case AV_OPT_TYPE_RATIONAL: | ||
1082 | 12 | ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den); | |
1083 | 12 | break; | |
1084 | ✗ | case AV_OPT_TYPE_CONST: | |
1085 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64); | |
1086 | ✗ | break; | |
1087 | 26 | case AV_OPT_TYPE_STRING: | |
1088 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (*(uint8_t **)dst) { |
1089 | 26 | *pbuf = av_strdup(*(uint8_t **)dst); | |
1090 | ✗ | } else if (search_flags & AV_OPT_ALLOW_NULL) { | |
1091 | ✗ | *pbuf = NULL; | |
1092 | ✗ | return 0; | |
1093 | } else { | ||
1094 | ✗ | *pbuf = av_strdup(""); | |
1095 | } | ||
1096 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | return *pbuf ? 0 : AVERROR(ENOMEM); |
1097 | 12 | case AV_OPT_TYPE_BINARY: { | |
1098 | const uint8_t *bin; | ||
1099 | int len; | ||
1100 | |||
1101 |
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)) { |
1102 | ✗ | *pbuf = NULL; | |
1103 | ✗ | return 0; | |
1104 | } | ||
1105 | 12 | len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *)); | |
1106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if ((uint64_t)len * 2 + 1 > INT_MAX) |
1107 | ✗ | return AVERROR(EINVAL); | |
1108 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if (!(*pbuf = av_malloc(len * 2 + 1))) |
1109 | ✗ | return AVERROR(ENOMEM); | |
1110 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
|
12 | if (!len) { |
1111 | 8 | *pbuf[0] = '\0'; | |
1112 | 8 | return 0; | |
1113 | } | ||
1114 | 4 | bin = *(uint8_t **)dst; | |
1115 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (int i = 0; i < len; i++) |
1116 | 16 | snprintf(*pbuf + i * 2, 3, "%02X", bin[i]); | |
1117 | 4 | return 0; | |
1118 | } | ||
1119 | 4 | case AV_OPT_TYPE_IMAGE_SIZE: | |
1120 | 4 | ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]); | |
1121 | 4 | break; | |
1122 | 4 | case AV_OPT_TYPE_PIXEL_FMT: | |
1123 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none")); | |
1124 | 4 | break; | |
1125 | 4 | case AV_OPT_TYPE_SAMPLE_FMT: | |
1126 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none")); | |
1127 | 4 | break; | |
1128 | 4 | case AV_OPT_TYPE_DURATION: { | |
1129 | 4 | int64_t i64 = *(int64_t *)dst; | |
1130 | 4 | format_duration(*pbuf, buf_len, i64); | |
1131 | 4 | ret = strlen(*pbuf); // no overflow possible, checked by an assert | |
1132 | 4 | break; | |
1133 | } | ||
1134 | 4 | case AV_OPT_TYPE_COLOR: | |
1135 | 4 | ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x", | |
1136 | 4 | (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1], | |
1137 | 4 | (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]); | |
1138 | 4 | break; | |
1139 | 8 | case AV_OPT_TYPE_CHLAYOUT: | |
1140 | 8 | ret = av_channel_layout_describe(dst, *pbuf, buf_len); | |
1141 | 8 | break; | |
1142 | 22 | case AV_OPT_TYPE_DICT: | |
1143 |
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)) { |
1144 | ✗ | *pbuf = NULL; | |
1145 | ✗ | return 0; | |
1146 | } | ||
1147 | 22 | return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':'); | |
1148 | ✗ | default: | |
1149 | ✗ | return AVERROR(EINVAL); | |
1150 | } | ||
1151 | |||
1152 | 10985 | return ret; | |
1153 | } | ||
1154 | |||
1155 | 61 | static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val) | |
1156 | { | ||
1157 | 61 | const unsigned count = *opt_array_pcount(dst); | |
1158 | 61 | const uint8_t sep = opt_array_sep(o); | |
1159 | |||
1160 | 61 | uint8_t *str = NULL; | |
1161 | 61 | size_t str_len = 0; | |
1162 | int ret; | ||
1163 | |||
1164 | 61 | *out_val = NULL; | |
1165 | |||
1166 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 61 times.
|
91 | for (unsigned i = 0; i < count; i++) { |
1167 | 30 | uint8_t buf[128], *out = buf; | |
1168 | size_t out_len; | ||
1169 | |||
1170 | 30 | ret = opt_get_elem(o, &out, sizeof(buf), | |
1171 | 30 | opt_array_pelem(o, *(void **)dst, i), 0); | |
1172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) |
1173 | ✗ | goto fail; | |
1174 | |||
1175 | 30 | out_len = strlen(out); | |
1176 |
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 || |
1177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | !!i + out_len * 2 > SIZE_MAX - str_len - 1) { |
1178 | ✗ | ret = AVERROR(ERANGE); | |
1179 | ✗ | goto fail; | |
1180 | } | ||
1181 | |||
1182 | // terminator escaping separator | ||
1183 | // ↓ ↓ ↓ | ||
1184 | 30 | ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i); | |
1185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) |
1186 | ✗ | goto fail; | |
1187 | |||
1188 | // add separator if needed | ||
1189 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 12 times.
|
30 | if (i) |
1190 | 18 | str[str_len++] = sep; | |
1191 | |||
1192 | // escape the element | ||
1193 |
2/2✓ Branch 0 taken 258 times.
✓ Branch 1 taken 30 times.
|
288 | for (unsigned j = 0; j < out_len; j++) { |
1194 | 258 | uint8_t val = out[j]; | |
1195 |
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 == '\\') |
1196 | 42 | str[str_len++] = '\\'; | |
1197 | 258 | str[str_len++] = val; | |
1198 | } | ||
1199 | 30 | str[str_len] = 0; | |
1200 | |||
1201 | 30 | fail: | |
1202 |
1/2✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
|
30 | if (out != buf) |
1203 | 30 | av_freep(&out); | |
1204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if (ret < 0) { |
1205 | ✗ | av_freep(&str); | |
1206 | ✗ | return ret; | |
1207 | } | ||
1208 | } | ||
1209 | |||
1210 | 61 | *out_val = str; | |
1211 | |||
1212 | 61 | return 0; | |
1213 | } | ||
1214 | |||
1215 | 15293 | int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) | |
1216 | { | ||
1217 | void *dst, *target_obj; | ||
1218 | 15293 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1219 | uint8_t *out, buf[128]; | ||
1220 | int ret; | ||
1221 | |||
1222 |
4/8✓ Branch 0 taken 11062 times.
✓ Branch 1 taken 4231 times.
✓ Branch 2 taken 11062 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11062 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
15293 | if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) |
1223 | 4231 | return AVERROR_OPTION_NOT_FOUND; | |
1224 | |||
1225 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11062 times.
|
11062 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
1226 | ✗ | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
1227 | |||
1228 | 11062 | dst = (uint8_t *)target_obj + o->offset; | |
1229 | |||
1230 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 11010 times.
|
11062 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1231 | 52 | ret = opt_get_array(o, dst, out_val); | |
1232 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | if (ret < 0) |
1233 | ✗ | return ret; | |
1234 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 43 times.
✓ Branch 3 taken 1 times.
|
52 | if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) { |
1235 | 43 | *out_val = av_strdup(""); | |
1236 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (!*out_val) |
1237 | ✗ | return AVERROR(ENOMEM); | |
1238 | } | ||
1239 | 52 | return 0; | |
1240 | } | ||
1241 | |||
1242 | 11010 | buf[0] = 0; | |
1243 | 11010 | out = buf; | |
1244 | 11010 | ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags); | |
1245 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11010 times.
|
11010 | if (ret < 0) |
1246 | ✗ | return ret; | |
1247 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 10980 times.
|
11010 | if (out != buf) { |
1248 | 30 | *out_val = out; | |
1249 | 30 | return 0; | |
1250 | } | ||
1251 | |||
1252 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10980 times.
|
10980 | if (ret >= sizeof(buf)) |
1253 | ✗ | return AVERROR(EINVAL); | |
1254 | 10980 | *out_val = av_strdup(out); | |
1255 |
1/2✓ Branch 0 taken 10980 times.
✗ Branch 1 not taken.
|
10980 | return *out_val ? 0 : AVERROR(ENOMEM); |
1256 | } | ||
1257 | |||
1258 | 12024 | static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, | |
1259 | int search_flags) | ||
1260 | { | ||
1261 | void *dst, *target_obj; | ||
1262 | 12024 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1263 |
3/4✓ Branch 0 taken 12010 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12010 times.
|
12024 | if (!o || !target_obj) |
1264 | 14 | return AVERROR_OPTION_NOT_FOUND; | |
1265 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12010 times.
|
12010 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1266 | ✗ | return AVERROR(EINVAL); | |
1267 | |||
1268 | 12010 | dst = ((uint8_t *)target_obj) + o->offset; | |
1269 | |||
1270 | 12010 | return read_number(o, dst, num, den, intnum); | |
1271 | } | ||
1272 | |||
1273 | 12024 | int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val) | |
1274 | { | ||
1275 | 12024 | int64_t intnum = 1; | |
1276 | 12024 | double num = 1; | |
1277 | 12024 | int ret, den = 1; | |
1278 | |||
1279 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 12010 times.
|
12024 | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) |
1280 | 14 | return ret; | |
1281 |
1/2✓ Branch 0 taken 12010 times.
✗ Branch 1 not taken.
|
12010 | if (num == den) |
1282 | 12010 | *out_val = intnum; | |
1283 | else | ||
1284 | ✗ | *out_val = num * intnum / den; | |
1285 | 12010 | return 0; | |
1286 | } | ||
1287 | |||
1288 | ✗ | int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val) | |
1289 | { | ||
1290 | ✗ | int64_t intnum = 1; | |
1291 | ✗ | double num = 1; | |
1292 | ✗ | int ret, den = 1; | |
1293 | |||
1294 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
1295 | ✗ | return ret; | |
1296 | ✗ | *out_val = num * intnum / den; | |
1297 | ✗ | return 0; | |
1298 | } | ||
1299 | |||
1300 | ✗ | int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val) | |
1301 | { | ||
1302 | ✗ | int64_t intnum = 1; | |
1303 | ✗ | double num = 1; | |
1304 | ✗ | int ret, den = 1; | |
1305 | |||
1306 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
1307 | ✗ | return ret; | |
1308 | |||
1309 | ✗ | if (num == 1.0 && (int)intnum == intnum) | |
1310 | ✗ | *out_val = (AVRational){intnum, den}; | |
1311 | else | ||
1312 | ✗ | *out_val = double_to_rational(num*intnum/den); | |
1313 | ✗ | return 0; | |
1314 | } | ||
1315 | |||
1316 | ✗ | int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out) | |
1317 | { | ||
1318 | void *dst, *target_obj; | ||
1319 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1320 | ✗ | if (!o || !target_obj) | |
1321 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1322 | ✗ | if (o->type != AV_OPT_TYPE_IMAGE_SIZE) { | |
1323 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1324 | "The value for option '%s' is not a image size.\n", name); | ||
1325 | ✗ | return AVERROR(EINVAL); | |
1326 | } | ||
1327 | |||
1328 | ✗ | dst = ((uint8_t*)target_obj) + o->offset; | |
1329 | ✗ | if (w_out) *w_out = *(int *)dst; | |
1330 | ✗ | if (h_out) *h_out = *((int *)dst+1); | |
1331 | ✗ | return 0; | |
1332 | } | ||
1333 | |||
1334 | ✗ | int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val) | |
1335 | { | ||
1336 | ✗ | return av_opt_get_q(obj, name, search_flags, out_val); | |
1337 | } | ||
1338 | |||
1339 | 2928 | static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, | |
1340 | enum AVOptionType type, const char *desc) | ||
1341 | { | ||
1342 | void *dst, *target_obj; | ||
1343 | 2928 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1344 |
2/4✓ Branch 0 taken 2928 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2928 times.
|
2928 | if (!o || !target_obj) |
1345 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1346 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2928 times.
|
2928 | if (o->type != type) { |
1347 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1348 | "The value for option '%s' is not a %s format.\n", desc, name); | ||
1349 | ✗ | return AVERROR(EINVAL); | |
1350 | } | ||
1351 | |||
1352 | 2928 | dst = ((uint8_t*)target_obj) + o->offset; | |
1353 | 2928 | *out_fmt = *(int *)dst; | |
1354 | 2928 | return 0; | |
1355 | } | ||
1356 | |||
1357 | ✗ | int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt) | |
1358 | { | ||
1359 | ✗ | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel"); | |
1360 | } | ||
1361 | |||
1362 | 2928 | int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt) | |
1363 | { | ||
1364 | 2928 | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample"); | |
1365 | } | ||
1366 | |||
1367 | 2928 | int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl) | |
1368 | { | ||
1369 | void *dst, *target_obj; | ||
1370 | 2928 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1371 |
2/4✓ Branch 0 taken 2928 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2928 times.
|
2928 | if (!o || !target_obj) |
1372 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
1373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2928 times.
|
2928 | if (o->type != AV_OPT_TYPE_CHLAYOUT) { |
1374 | ✗ | av_log(obj, AV_LOG_ERROR, | |
1375 | "The value for option '%s' is not a channel layout.\n", name); | ||
1376 | ✗ | return AVERROR(EINVAL); | |
1377 | } | ||
1378 | |||
1379 | 2928 | dst = ((uint8_t*)target_obj) + o->offset; | |
1380 | 2928 | return av_channel_layout_copy(cl, dst); | |
1381 | } | ||
1382 | |||
1383 | 7533 | int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val) | |
1384 | { | ||
1385 | void *target_obj; | ||
1386 | AVDictionary *src; | ||
1387 | 7533 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
1388 | |||
1389 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 7533 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
7533 | if (!o || !target_obj) |
1390 | 7533 | return AVERROR_OPTION_NOT_FOUND; | |
1391 | ✗ | if (o->type != AV_OPT_TYPE_DICT) | |
1392 | ✗ | return AVERROR(EINVAL); | |
1393 | |||
1394 | ✗ | src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset); | |
1395 | |||
1396 | ✗ | return av_dict_copy(out_val, src, 0); | |
1397 | } | ||
1398 | |||
1399 | ✗ | int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) | |
1400 | { | ||
1401 | ✗ | const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); | |
1402 | ✗ | const AVOption *flag = av_opt_find(obj, flag_name, | |
1403 | field ? field->unit : NULL, 0, 0); | ||
1404 | int64_t res; | ||
1405 | |||
1406 | ✗ | if (!field || !flag || flag->type != AV_OPT_TYPE_CONST || | |
1407 | ✗ | av_opt_get_int(obj, field_name, 0, &res) < 0) | |
1408 | ✗ | return 0; | |
1409 | ✗ | return res & flag->default_val.i64; | |
1410 | } | ||
1411 | |||
1412 | 4 | static void log_int_value(void *av_log_obj, int level, int64_t i) | |
1413 | { | ||
1414 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (i == INT_MAX) { |
1415 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
1416 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT_MIN) { |
1417 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
1418 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == UINT32_MAX) { |
1419 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
1420 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MAX) { |
1421 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
1422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MIN) { |
1423 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
1424 | } else { | ||
1425 | 4 | av_log(av_log_obj, level, "%"PRId64, i); | |
1426 | } | ||
1427 | 4 | } | |
1428 | |||
1429 | 16 | static void log_value(void *av_log_obj, int level, double d) | |
1430 | { | ||
1431 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (d == INT_MAX) { |
1432 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
1433 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT_MIN) { |
1434 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
1435 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == UINT32_MAX) { |
1436 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
1437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == (double)INT64_MAX) { |
1438 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
1439 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT64_MIN) { |
1440 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
1441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MAX) { |
1442 | ✗ | av_log(av_log_obj, level, "FLT_MAX"); | |
1443 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MIN) { |
1444 | ✗ | av_log(av_log_obj, level, "FLT_MIN"); | |
1445 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MAX) { |
1446 | ✗ | av_log(av_log_obj, level, "-FLT_MAX"); | |
1447 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MIN) { |
1448 | ✗ | av_log(av_log_obj, level, "-FLT_MIN"); | |
1449 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MAX) { |
1450 | ✗ | av_log(av_log_obj, level, "DBL_MAX"); | |
1451 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MIN) { |
1452 | ✗ | av_log(av_log_obj, level, "DBL_MIN"); | |
1453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MAX) { |
1454 | ✗ | av_log(av_log_obj, level, "-DBL_MAX"); | |
1455 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MIN) { |
1456 | ✗ | av_log(av_log_obj, level, "-DBL_MIN"); | |
1457 | } else { | ||
1458 | 16 | av_log(av_log_obj, level, "%g", d); | |
1459 | } | ||
1460 | 16 | } | |
1461 | |||
1462 | 4 | static const char *get_opt_const_name(void *obj, const char *unit, int64_t value) | |
1463 | { | ||
1464 | 4 | const AVOption *opt = NULL; | |
1465 | |||
1466 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (!unit) |
1467 | 4 | return NULL; | |
1468 | ✗ | while ((opt = av_opt_next(obj, opt))) | |
1469 | ✗ | if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && | |
1470 | ✗ | opt->default_val.i64 == value) | |
1471 | ✗ | return opt->name; | |
1472 | ✗ | return NULL; | |
1473 | } | ||
1474 | |||
1475 | 1 | static char *get_opt_flags_string(void *obj, const char *unit, int64_t value) | |
1476 | { | ||
1477 | 1 | const AVOption *opt = NULL; | |
1478 | char flags[512]; | ||
1479 | |||
1480 | 1 | flags[0] = 0; | |
1481 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!unit) |
1482 | ✗ | return NULL; | |
1483 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 1 times.
|
32 | while ((opt = av_opt_next(obj, opt))) { |
1484 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
31 | if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && |
1485 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | opt->default_val.i64 & value) { |
1486 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (flags[0]) |
1487 | ✗ | av_strlcatf(flags, sizeof(flags), "+"); | |
1488 | 1 | av_strlcatf(flags, sizeof(flags), "%s", opt->name); | |
1489 | } | ||
1490 | } | ||
1491 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (flags[0]) |
1492 | 1 | return av_strdup(flags); | |
1493 | ✗ | return NULL; | |
1494 | } | ||
1495 | |||
1496 | 31 | static void log_type(void *av_log_obj, const AVOption *o, | |
1497 | enum AVOptionType parent_type) | ||
1498 | { | ||
1499 | 31 | const enum AVOptionType type = TYPE_BASE(o->type); | |
1500 | |||
1501 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
31 | if (o->type == AV_OPT_TYPE_CONST && TYPE_BASE(parent_type) == AV_OPT_TYPE_INT) |
1502 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64); | |
1503 |
3/4✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 3 times.
|
31 | else if (type < FF_ARRAY_ELEMS(opt_type_desc) && opt_type_desc[type].name) { |
1504 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 25 times.
|
28 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1505 | 3 | av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", opt_type_desc[type].name); | |
1506 | else | ||
1507 | 25 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", opt_type_desc[type].name); | |
1508 | } | ||
1509 | else | ||
1510 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); | |
1511 | 31 | } | |
1512 | |||
1513 | 31 | static void log_default(void *obj, void *av_log_obj, const AVOption *opt) | |
1514 | { | ||
1515 |
4/4✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 25 times.
|
31 | if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY) |
1516 | 6 | return; | |
1517 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | if ((opt->type == AV_OPT_TYPE_COLOR || |
1518 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
|
24 | opt->type == AV_OPT_TYPE_IMAGE_SIZE || |
1519 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
|
23 | opt->type == AV_OPT_TYPE_STRING || |
1520 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 2 times.
|
21 | opt->type == AV_OPT_TYPE_DICT || |
1521 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
|
19 | opt->type == AV_OPT_TYPE_CHLAYOUT || |
1522 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
|
18 | opt->type == AV_OPT_TYPE_VIDEO_RATE) && |
1523 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | !opt->default_val.str) |
1524 | 1 | return; | |
1525 | |||
1526 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
|
24 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1527 | 3 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
1528 |
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) |
1529 | 2 | av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def); | |
1530 | 3 | return; | |
1531 | } | ||
1532 | |||
1533 | 21 | av_log(av_log_obj, AV_LOG_INFO, " (default "); | |
1534 |
9/10✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 7 times.
✗ Branch 9 not taken.
|
21 | switch (opt->type) { |
1535 | 3 | case AV_OPT_TYPE_BOOL: | |
1536 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64)); | |
1537 | 3 | break; | |
1538 | 1 | case AV_OPT_TYPE_FLAGS: { | |
1539 | 1 | char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64); | |
1540 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (def_flags) { |
1541 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags); | |
1542 | 1 | av_freep(&def_flags); | |
1543 | } else { | ||
1544 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64); | |
1545 | } | ||
1546 | 1 | break; | |
1547 | } | ||
1548 | 1 | case AV_OPT_TYPE_DURATION: { | |
1549 | char buf[25]; | ||
1550 | 1 | format_duration(buf, sizeof(buf), opt->default_val.i64); | |
1551 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", buf); | |
1552 | 1 | break; | |
1553 | } | ||
1554 | 4 | case AV_OPT_TYPE_UINT: | |
1555 | case AV_OPT_TYPE_INT: | ||
1556 | case AV_OPT_TYPE_UINT64: | ||
1557 | case AV_OPT_TYPE_INT64: { | ||
1558 | 4 | const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64); | |
1559 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (def_const) |
1560 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%s", def_const); | |
1561 | else | ||
1562 | 4 | log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64); | |
1563 | 4 | break; | |
1564 | } | ||
1565 | 2 | case AV_OPT_TYPE_DOUBLE: | |
1566 | case AV_OPT_TYPE_FLOAT: | ||
1567 | 2 | log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl); | |
1568 | 2 | break; | |
1569 | 1 | case AV_OPT_TYPE_RATIONAL: { | |
1570 | 1 | AVRational q = av_d2q(opt->default_val.dbl, INT_MAX); | |
1571 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); } | |
1572 | 1 | break; | |
1573 | 1 | case AV_OPT_TYPE_PIXEL_FMT: | |
1574 | 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")); | |
1575 | 1 | break; | |
1576 | 1 | case AV_OPT_TYPE_SAMPLE_FMT: | |
1577 | 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")); | |
1578 | 1 | break; | |
1579 | 7 | case AV_OPT_TYPE_COLOR: | |
1580 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
1581 | case AV_OPT_TYPE_STRING: | ||
1582 | case AV_OPT_TYPE_DICT: | ||
1583 | case AV_OPT_TYPE_VIDEO_RATE: | ||
1584 | case AV_OPT_TYPE_CHLAYOUT: | ||
1585 | 7 | av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str); | |
1586 | 7 | break; | |
1587 | } | ||
1588 | 21 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
1589 | } | ||
1590 | |||
1591 | 2 | static void opt_list(void *obj, void *av_log_obj, const char *unit, | |
1592 | int req_flags, int rej_flags, enum AVOptionType parent_type) | ||
1593 | { | ||
1594 | 2 | const AVOption *opt = NULL; | |
1595 | AVOptionRanges *r; | ||
1596 | int i; | ||
1597 | |||
1598 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
|
64 | while ((opt = av_opt_next(obj, opt))) { |
1599 |
2/4✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
|
62 | if (!(opt->flags & req_flags) || (opt->flags & rej_flags)) |
1600 | ✗ | continue; | |
1601 | |||
1602 | /* Don't print CONST's on level one. | ||
1603 | * Don't print anything but CONST's on level two. | ||
1604 | * Only print items from the requested unit. | ||
1605 | */ | ||
1606 |
4/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 31 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 28 times.
|
62 | if (!unit && opt->type == AV_OPT_TYPE_CONST) |
1607 | 3 | continue; | |
1608 |
4/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 3 times.
|
59 | else if (unit && opt->type != AV_OPT_TYPE_CONST) |
1609 | 28 | continue; | |
1610 |
4/6✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
31 | else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit)) |
1611 | ✗ | continue; | |
1612 |
3/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
31 | else if (unit && opt->type == AV_OPT_TYPE_CONST) |
1613 | 3 | av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); | |
1614 | else | ||
1615 | 28 | av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ", | |
1616 | 28 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-", | |
1617 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | opt->name); |
1618 | |||
1619 | 31 | log_type(av_log_obj, opt, parent_type); | |
1620 | |||
1621 | 341 | av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c", | |
1622 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
|
31 | (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.', |
1623 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.', |
1624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.', |
1625 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.', |
1626 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.', |
1627 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.', |
1628 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.', |
1629 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.', |
1630 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.', |
1631 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
|
31 | (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.', |
1632 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.'); |
1633 | |||
1634 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (opt->help) |
1635 | 31 | av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
1636 | |||
1637 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 2 taken 13 times.
|
31 | if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) { |
1638 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 11 times.
|
18 | switch (opt->type) { |
1639 | 7 | case AV_OPT_TYPE_INT: | |
1640 | case AV_OPT_TYPE_UINT: | ||
1641 | case AV_OPT_TYPE_INT64: | ||
1642 | case AV_OPT_TYPE_UINT64: | ||
1643 | case AV_OPT_TYPE_DOUBLE: | ||
1644 | case AV_OPT_TYPE_FLOAT: | ||
1645 | case AV_OPT_TYPE_RATIONAL: | ||
1646 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | for (i = 0; i < r->nb_ranges; i++) { |
1647 | 7 | av_log(av_log_obj, AV_LOG_INFO, " (from "); | |
1648 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min); | |
1649 | 7 | av_log(av_log_obj, AV_LOG_INFO, " to "); | |
1650 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max); | |
1651 | 7 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
1652 | } | ||
1653 | 7 | break; | |
1654 | } | ||
1655 | 18 | av_opt_freep_ranges(&r); | |
1656 | } | ||
1657 | |||
1658 | 31 | log_default(obj, av_log_obj, opt); | |
1659 | |||
1660 | 31 | av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
1661 |
4/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 27 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
31 | if (opt->unit && opt->type != AV_OPT_TYPE_CONST) |
1662 | 1 | opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type); | |
1663 | } | ||
1664 | 2 | } | |
1665 | |||
1666 | 1 | int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags) | |
1667 | { | ||
1668 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!obj) |
1669 | ✗ | return -1; | |
1670 | |||
1671 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name); | |
1672 | |||
1673 | 1 | opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1); | |
1674 | |||
1675 | 1 | return 0; | |
1676 | } | ||
1677 | |||
1678 | 366053 | void av_opt_set_defaults(void *s) | |
1679 | { | ||
1680 | 366053 | av_opt_set_defaults2(s, 0, 0); | |
1681 | 366053 | } | |
1682 | |||
1683 | 427613 | void av_opt_set_defaults2(void *s, int mask, int flags) | |
1684 | { | ||
1685 | 427613 | const AVOption *opt = NULL; | |
1686 |
2/2✓ Branch 1 taken 26683693 times.
✓ Branch 2 taken 427613 times.
|
27111306 | while ((opt = av_opt_next(s, opt))) { |
1687 | 26683693 | void *dst = ((uint8_t*)s) + opt->offset; | |
1688 | |||
1689 |
2/2✓ Branch 0 taken 3042708 times.
✓ Branch 1 taken 23640985 times.
|
26683693 | if ((opt->flags & mask) != flags) |
1690 | 3042708 | continue; | |
1691 | |||
1692 |
2/2✓ Branch 0 taken 2098 times.
✓ Branch 1 taken 23638887 times.
|
23640985 | if (opt->flags & AV_OPT_FLAG_READONLY) |
1693 | 2098 | continue; | |
1694 | |||
1695 |
2/2✓ Branch 0 taken 97264 times.
✓ Branch 1 taken 23541623 times.
|
23638887 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
1696 | 97264 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
1697 | 97264 | const char sep = opt_array_sep(opt); | |
1698 | |||
1699 |
11/16✓ Branch 0 taken 97264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 97264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11731 times.
✓ Branch 5 taken 85533 times.
✓ Branch 6 taken 11731 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 11731 times.
✓ Branch 9 taken 85533 times.
✓ Branch 10 taken 11731 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11731 times.
✓ Branch 13 taken 85533 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 11731 times.
|
97264 | av_assert0(sep && sep != '\\' && |
1700 | (sep < 'a' || sep > 'z') && | ||
1701 | (sep < 'A' || sep > 'Z') && | ||
1702 | (sep < '0' || sep > '9')); | ||
1703 | |||
1704 |
4/4✓ Branch 0 taken 11738 times.
✓ Branch 1 taken 85526 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 11724 times.
|
97264 | if (arr && arr->def) |
1705 | 14 | opt_set_array(s, s, opt, arr->def, dst); | |
1706 | |||
1707 | 97264 | continue; | |
1708 | } | ||
1709 | |||
1710 |
11/12✓ Branch 0 taken 15179544 times.
✓ Branch 1 taken 6724182 times.
✓ Branch 2 taken 873527 times.
✓ Branch 3 taken 190981 times.
✓ Branch 4 taken 308 times.
✓ Branch 5 taken 440810 times.
✓ Branch 6 taken 38389 times.
✓ Branch 7 taken 7952 times.
✓ Branch 8 taken 40331 times.
✓ Branch 9 taken 45378 times.
✓ Branch 10 taken 221 times.
✗ Branch 11 not taken.
|
23541623 | switch (opt->type) { |
1711 | 15179544 | case AV_OPT_TYPE_CONST: | |
1712 | /* Nothing to be done here */ | ||
1713 | 15179544 | break; | |
1714 | 6724182 | case AV_OPT_TYPE_BOOL: | |
1715 | case AV_OPT_TYPE_FLAGS: | ||
1716 | case AV_OPT_TYPE_INT: | ||
1717 | case AV_OPT_TYPE_UINT: | ||
1718 | case AV_OPT_TYPE_INT64: | ||
1719 | case AV_OPT_TYPE_UINT64: | ||
1720 | case AV_OPT_TYPE_DURATION: | ||
1721 | case AV_OPT_TYPE_PIXEL_FMT: | ||
1722 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
1723 | 6724182 | write_number(s, opt, dst, 1, 1, opt->default_val.i64); | |
1724 | 6724182 | break; | |
1725 | 873527 | case AV_OPT_TYPE_DOUBLE: | |
1726 | case AV_OPT_TYPE_FLOAT: { | ||
1727 | double val; | ||
1728 | 873527 | val = opt->default_val.dbl; | |
1729 | 873527 | write_number(s, opt, dst, val, 1, 1); | |
1730 | } | ||
1731 | 873527 | break; | |
1732 | 190981 | case AV_OPT_TYPE_RATIONAL: { | |
1733 | AVRational val; | ||
1734 | 190981 | val = av_d2q(opt->default_val.dbl, INT_MAX); | |
1735 | 190981 | write_number(s, opt, dst, 1, val.den, val.num); | |
1736 | } | ||
1737 | 190981 | break; | |
1738 | 308 | case AV_OPT_TYPE_COLOR: | |
1739 | 308 | set_string_color(s, opt, opt->default_val.str, dst); | |
1740 | 308 | break; | |
1741 | 440810 | case AV_OPT_TYPE_STRING: | |
1742 | 440810 | set_string(s, opt, opt->default_val.str, dst); | |
1743 | 440810 | break; | |
1744 | 38389 | case AV_OPT_TYPE_IMAGE_SIZE: | |
1745 | 38389 | set_string_image_size(s, opt, opt->default_val.str, dst); | |
1746 | 38389 | break; | |
1747 | 7952 | case AV_OPT_TYPE_VIDEO_RATE: | |
1748 | 7952 | set_string_video_rate(s, opt, opt->default_val.str, dst); | |
1749 | 7952 | break; | |
1750 | 40331 | case AV_OPT_TYPE_BINARY: | |
1751 | 40331 | set_string_binary(s, opt, opt->default_val.str, dst); | |
1752 | 40331 | break; | |
1753 | 45378 | case AV_OPT_TYPE_CHLAYOUT: | |
1754 | 45378 | set_string_channel_layout(s, opt, opt->default_val.str, dst); | |
1755 | 45378 | break; | |
1756 | 221 | case AV_OPT_TYPE_DICT: | |
1757 | 221 | set_string_dict(s, opt, opt->default_val.str, dst); | |
1758 | 221 | break; | |
1759 | ✗ | default: | |
1760 | ✗ | av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", | |
1761 | ✗ | opt->type, opt->name); | |
1762 | } | ||
1763 | } | ||
1764 | 427613 | } | |
1765 | |||
1766 | /** | ||
1767 | * Store the value in the field in ctx that is named like key. | ||
1768 | * ctx must be an AVClass context, storing is done using AVOptions. | ||
1769 | * | ||
1770 | * @param buf the string to parse, buf will be updated to point at the | ||
1771 | * separator just after the parsed key/value pair | ||
1772 | * @param key_val_sep a 0-terminated list of characters used to | ||
1773 | * separate key from value | ||
1774 | * @param pairs_sep a 0-terminated list of characters used to separate | ||
1775 | * two pairs from each other | ||
1776 | * @return 0 if the key/value pair has been successfully parsed and | ||
1777 | * set, or a negative value corresponding to an AVERROR code in case | ||
1778 | * of error: | ||
1779 | * AVERROR(EINVAL) if the key/value pair cannot be parsed, | ||
1780 | * the error code issued by av_opt_set() if the key/value pair | ||
1781 | * cannot be set | ||
1782 | */ | ||
1783 | 3114 | static int parse_key_value_pair(void *ctx, const char **buf, | |
1784 | const char *key_val_sep, const char *pairs_sep) | ||
1785 | { | ||
1786 | 3114 | char *key = av_get_token(buf, key_val_sep); | |
1787 | char *val; | ||
1788 | int ret; | ||
1789 | |||
1790 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3114 times.
|
3114 | if (!key) |
1791 | ✗ | return AVERROR(ENOMEM); | |
1792 | |||
1793 |
4/4✓ Branch 0 taken 3112 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3109 times.
✓ Branch 3 taken 3 times.
|
3114 | if (*key && strspn(*buf, key_val_sep)) { |
1794 | 3109 | (*buf)++; | |
1795 | 3109 | val = av_get_token(buf, pairs_sep); | |
1796 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3109 times.
|
3109 | if (!val) { |
1797 | ✗ | av_freep(&key); | |
1798 | ✗ | return AVERROR(ENOMEM); | |
1799 | } | ||
1800 | } else { | ||
1801 | 5 | av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key); | |
1802 | 5 | av_free(key); | |
1803 | 5 | return AVERROR(EINVAL); | |
1804 | } | ||
1805 | |||
1806 | 3109 | av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val); | |
1807 | |||
1808 | 3109 | ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN); | |
1809 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3104 times.
|
3109 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1810 | 5 | av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key); | |
1811 | |||
1812 | 3109 | av_free(key); | |
1813 | 3109 | av_free(val); | |
1814 | 3109 | return ret; | |
1815 | } | ||
1816 | |||
1817 | 3081 | int av_set_options_string(void *ctx, const char *opts, | |
1818 | const char *key_val_sep, const char *pairs_sep) | ||
1819 | { | ||
1820 | 3081 | int ret, count = 0; | |
1821 | |||
1822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3081 times.
|
3081 | if (!opts) |
1823 | ✗ | return 0; | |
1824 | |||
1825 |
2/2✓ Branch 0 taken 3114 times.
✓ Branch 1 taken 3042 times.
|
6156 | while (*opts) { |
1826 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 2 taken 3075 times.
|
3114 | if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0) |
1827 | 39 | return ret; | |
1828 | 3075 | count++; | |
1829 | |||
1830 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 3040 times.
|
3075 | if (*opts) |
1831 | 35 | opts++; | |
1832 | } | ||
1833 | |||
1834 | 3042 | return count; | |
1835 | } | ||
1836 | |||
1837 | #define WHITESPACES " \n\t\r" | ||
1838 | |||
1839 | 410034 | static int is_key_char(char c) | |
1840 | { | ||
1841 | 530030 | return (unsigned)((c | 32) - 'a') < 26 || | |
1842 |
4/4✓ Branch 0 taken 70976 times.
✓ Branch 1 taken 49020 times.
✓ Branch 2 taken 70902 times.
✓ Branch 3 taken 74 times.
|
119996 | (unsigned)(c - '0') < 10 || |
1843 |
8/8✓ Branch 0 taken 119996 times.
✓ Branch 1 taken 290038 times.
✓ Branch 2 taken 46653 times.
✓ Branch 3 taken 24249 times.
✓ Branch 4 taken 46530 times.
✓ Branch 5 taken 123 times.
✓ Branch 6 taken 79 times.
✓ Branch 7 taken 46451 times.
|
530030 | c == '-' || c == '_' || c == '/' || c == '.'; |
1844 | } | ||
1845 | |||
1846 | /** | ||
1847 | * Read a key from a string. | ||
1848 | * | ||
1849 | * The key consists of is_key_char characters and must be terminated by a | ||
1850 | * character from the delim string; spaces are ignored. | ||
1851 | * | ||
1852 | * @return 0 for success (even with ellipsis), <0 for failure | ||
1853 | */ | ||
1854 | 46451 | static int get_key(const char **ropts, const char *delim, char **rkey) | |
1855 | { | ||
1856 | 46451 | const char *opts = *ropts; | |
1857 | const char *key_start, *key_end; | ||
1858 | |||
1859 | 46451 | key_start = opts += strspn(opts, WHITESPACES); | |
1860 |
2/2✓ Branch 1 taken 363583 times.
✓ Branch 2 taken 46451 times.
|
410034 | while (is_key_char(*opts)) |
1861 | 363583 | opts++; | |
1862 | 46451 | key_end = opts; | |
1863 | 46451 | opts += strspn(opts, WHITESPACES); | |
1864 |
4/4✓ Branch 0 taken 34328 times.
✓ Branch 1 taken 12123 times.
✓ Branch 2 taken 6590 times.
✓ Branch 3 taken 27738 times.
|
46451 | if (!*opts || !strchr(delim, *opts)) |
1865 | 18713 | return AVERROR(EINVAL); | |
1866 | 27738 | opts++; | |
1867 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 27738 times.
|
27738 | if (!(*rkey = av_malloc(key_end - key_start + 1))) |
1868 | ✗ | return AVERROR(ENOMEM); | |
1869 | 27738 | memcpy(*rkey, key_start, key_end - key_start); | |
1870 | 27738 | (*rkey)[key_end - key_start] = 0; | |
1871 | 27738 | *ropts = opts; | |
1872 | 27738 | return 0; | |
1873 | } | ||
1874 | |||
1875 | 46451 | int av_opt_get_key_value(const char **ropts, | |
1876 | const char *key_val_sep, const char *pairs_sep, | ||
1877 | unsigned flags, | ||
1878 | char **rkey, char **rval) | ||
1879 | { | ||
1880 | int ret; | ||
1881 | 46451 | char *key = NULL, *val; | |
1882 | 46451 | const char *opts = *ropts; | |
1883 | |||
1884 |
2/2✓ Branch 1 taken 18713 times.
✓ Branch 2 taken 27738 times.
|
46451 | if ((ret = get_key(&opts, key_val_sep, &key)) < 0 && |
1885 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 18712 times.
|
18713 | !(flags & AV_OPT_FLAG_IMPLICIT_KEY)) |
1886 | 1 | return AVERROR(EINVAL); | |
1887 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 46450 times.
|
46450 | if (!(val = av_get_token(&opts, pairs_sep))) { |
1888 | ✗ | av_free(key); | |
1889 | ✗ | return AVERROR(ENOMEM); | |
1890 | } | ||
1891 | 46450 | *ropts = opts; | |
1892 | 46450 | *rkey = key; | |
1893 | 46450 | *rval = val; | |
1894 | 46450 | return 0; | |
1895 | } | ||
1896 | |||
1897 | 36 | int av_opt_set_from_string(void *ctx, const char *opts, | |
1898 | const char *const *shorthand, | ||
1899 | const char *key_val_sep, const char *pairs_sep) | ||
1900 | { | ||
1901 | 36 | int ret, count = 0; | |
1902 | 36 | const char *dummy_shorthand = NULL; | |
1903 | const char *key; | ||
1904 | |||
1905 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!opts) |
1906 | ✗ | return 0; | |
1907 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 36 times.
|
36 | if (!shorthand) |
1908 | ✗ | shorthand = &dummy_shorthand; | |
1909 | |||
1910 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 32 times.
|
81 | while (*opts) { |
1911 | char *parsed_key, *value; | ||
1912 | 49 | ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep, | |
1913 | 49 | *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0, | |
1914 | &parsed_key, &value); | ||
1915 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 48 times.
|
49 | if (ret < 0) { |
1916 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ret == AVERROR(EINVAL)) |
1917 | 1 | av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts); | |
1918 | else | ||
1919 | ✗ | av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts, | |
1920 | ✗ | av_err2str(ret)); | |
1921 | 4 | return ret; | |
1922 | } | ||
1923 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 33 times.
|
48 | if (*opts) |
1924 | 15 | opts++; | |
1925 |
2/2✓ Branch 0 taken 34 times.
✓ Branch 1 taken 14 times.
|
48 | if (parsed_key) { |
1926 | 34 | key = parsed_key; | |
1927 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 34 times.
|
61 | while (*shorthand) /* discard all remaining shorthand */ |
1928 | 27 | shorthand++; | |
1929 | } else { | ||
1930 | 14 | key = *(shorthand++); | |
1931 | } | ||
1932 | |||
1933 | 48 | av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value); | |
1934 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 45 times.
|
48 | if ((ret = av_opt_set(ctx, key, value, 0)) < 0) { |
1935 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1936 | 2 | av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); | |
1937 | 3 | av_free(value); | |
1938 | 3 | av_free(parsed_key); | |
1939 | 3 | return ret; | |
1940 | } | ||
1941 | |||
1942 | 45 | av_free(value); | |
1943 | 45 | av_free(parsed_key); | |
1944 | 45 | count++; | |
1945 | } | ||
1946 | 32 | return count; | |
1947 | } | ||
1948 | |||
1949 | 655867 | void av_opt_free(void *obj) | |
1950 | { | ||
1951 | 655867 | const AVOption *o = NULL; | |
1952 |
2/2✓ Branch 1 taken 25498990 times.
✓ Branch 2 taken 655867 times.
|
26154857 | while ((o = av_opt_next(obj, o))) { |
1953 | 25498990 | void *pitem = (uint8_t *)obj + o->offset; | |
1954 | |||
1955 |
2/2✓ Branch 0 taken 98702 times.
✓ Branch 1 taken 25400288 times.
|
25498990 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
1956 | 98702 | opt_free_array(o, pitem, opt_array_pcount(pitem)); | |
1957 | else | ||
1958 | 25400288 | opt_free_elem(o->type, pitem); | |
1959 | } | ||
1960 | 655867 | } | |
1961 | |||
1962 | 271937 | int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags) | |
1963 | { | ||
1964 | 271937 | const AVDictionaryEntry *t = NULL; | |
1965 | 271937 | AVDictionary *tmp = NULL; | |
1966 | int ret; | ||
1967 | |||
1968 |
2/2✓ Branch 0 taken 66572 times.
✓ Branch 1 taken 205365 times.
|
271937 | if (!options) |
1969 | 66572 | return 0; | |
1970 | |||
1971 |
2/2✓ Branch 1 taken 161243 times.
✓ Branch 2 taken 205365 times.
|
366608 | while ((t = av_dict_iterate(*options, t))) { |
1972 | 161243 | ret = av_opt_set(obj, t->key, t->value, search_flags); | |
1973 |
2/2✓ Branch 0 taken 46379 times.
✓ Branch 1 taken 114864 times.
|
161243 | if (ret == AVERROR_OPTION_NOT_FOUND) |
1974 | 46379 | ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY); | |
1975 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 161243 times.
|
161243 | if (ret < 0) { |
1976 | ✗ | av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); | |
1977 | ✗ | av_dict_free(&tmp); | |
1978 | ✗ | return ret; | |
1979 | } | ||
1980 | } | ||
1981 | 205365 | av_dict_free(options); | |
1982 | 205365 | *options = tmp; | |
1983 | 205365 | return 0; | |
1984 | } | ||
1985 | |||
1986 | 159076 | int av_opt_set_dict(void *obj, AVDictionary **options) | |
1987 | { | ||
1988 | 159076 | return av_opt_set_dict2(obj, options, 0); | |
1989 | } | ||
1990 | |||
1991 | 540923 | const AVOption *av_opt_find(void *obj, const char *name, const char *unit, | |
1992 | int opt_flags, int search_flags) | ||
1993 | { | ||
1994 | 540923 | return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL); | |
1995 | } | ||
1996 | |||
1997 | 44634027 | const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, | |
1998 | int opt_flags, int search_flags, void **target_obj) | ||
1999 | { | ||
2000 | const AVClass *c; | ||
2001 | 44634027 | const AVOption *o = NULL; | |
2002 | |||
2003 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44634027 times.
|
44634027 | if(!obj) |
2004 | ✗ | return NULL; | |
2005 | |||
2006 | 44634027 | c= *(AVClass**)obj; | |
2007 | |||
2008 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44634027 times.
|
44634027 | if (!c) |
2009 | ✗ | return NULL; | |
2010 | |||
2011 |
2/2✓ Branch 0 taken 44235943 times.
✓ Branch 1 taken 398084 times.
|
44634027 | if (search_flags & AV_OPT_SEARCH_CHILDREN) { |
2012 |
2/2✓ Branch 0 taken 43914634 times.
✓ Branch 1 taken 321309 times.
|
44235943 | if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) { |
2013 | 43914634 | void *iter = NULL; | |
2014 | const AVClass *child; | ||
2015 |
2/2✓ Branch 1 taken 43632468 times.
✓ Branch 2 taken 43914116 times.
|
87546584 | while (child = av_opt_child_class_iterate( |