| 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 | |||
| 43 | #include <float.h> | ||
| 44 | |||
| 45 | #define TYPE_BASE(type) ((type) & ~AV_OPT_TYPE_FLAG_ARRAY) | ||
| 46 | |||
| 47 | 664951773 | const AVOption *av_opt_next(const void *obj, const AVOption *last) | |
| 48 | { | ||
| 49 | const AVClass *class; | ||
| 50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 664951773 times.
|
664951773 | if (!obj) |
| 51 | ✗ | return NULL; | |
| 52 | 664951773 | class = *(const AVClass**)obj; | |
| 53 |
7/8✓ Branch 0 taken 52258903 times.
✓ Branch 1 taken 612692870 times.
✓ Branch 2 taken 52258903 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51890720 times.
✓ Branch 5 taken 368183 times.
✓ Branch 6 taken 51768059 times.
✓ Branch 7 taken 122661 times.
|
664951773 | if (!last && class && class->option && class->option[0].name) |
| 54 | 51768059 | return class->option; | |
| 55 |
4/4✓ Branch 0 taken 612692870 times.
✓ Branch 1 taken 490844 times.
✓ Branch 2 taken 561575245 times.
✓ Branch 3 taken 51117625 times.
|
613183714 | if (last && last[1].name) |
| 56 | 561575245 | return ++last; | |
| 57 | 51608469 | return NULL; | |
| 58 | } | ||
| 59 | |||
| 60 | static const struct { | ||
| 61 | size_t size; | ||
| 62 | const char *name; | ||
| 63 | } opt_type_desc[] = { | ||
| 64 | [AV_OPT_TYPE_FLAGS] = { sizeof(unsigned), "<flags>" }, | ||
| 65 | [AV_OPT_TYPE_INT] = { sizeof(int), "<int>" }, | ||
| 66 | [AV_OPT_TYPE_INT64] = { sizeof(int64_t), "<int64>" }, | ||
| 67 | [AV_OPT_TYPE_UINT] = { sizeof(unsigned), "<unsigned>" }, | ||
| 68 | [AV_OPT_TYPE_UINT64] = { sizeof(uint64_t), "<uint64>" }, | ||
| 69 | [AV_OPT_TYPE_DOUBLE] = { sizeof(double), "<double>" }, | ||
| 70 | [AV_OPT_TYPE_FLOAT] = { sizeof(float), "<float>" }, | ||
| 71 | [AV_OPT_TYPE_STRING] = { sizeof(char *), "<string>" }, | ||
| 72 | [AV_OPT_TYPE_RATIONAL] = { sizeof(AVRational), "<rational>" }, | ||
| 73 | [AV_OPT_TYPE_BINARY] = { sizeof(uint8_t *), "<binary>" }, | ||
| 74 | [AV_OPT_TYPE_DICT] = { sizeof(AVDictionary *), "<dictionary>" }, | ||
| 75 | [AV_OPT_TYPE_IMAGE_SIZE] = { sizeof(int[2]), "<image_size>" }, | ||
| 76 | [AV_OPT_TYPE_VIDEO_RATE] = { sizeof(AVRational), "<video_rate>" }, | ||
| 77 | [AV_OPT_TYPE_PIXEL_FMT] = { sizeof(enum AVPixelFormat), "<pix_fmt>" }, | ||
| 78 | [AV_OPT_TYPE_SAMPLE_FMT] = { sizeof(enum AVSampleFormat), "<sample_fmt>" }, | ||
| 79 | [AV_OPT_TYPE_DURATION] = { sizeof(int64_t), "<duration>" }, | ||
| 80 | [AV_OPT_TYPE_COLOR] = { sizeof(uint8_t[4]), "<color>" }, | ||
| 81 | [AV_OPT_TYPE_CHLAYOUT] = { sizeof(AVChannelLayout),"<channel_layout>" }, | ||
| 82 | [AV_OPT_TYPE_BOOL] = { sizeof(int), "<boolean>" }, | ||
| 83 | }; | ||
| 84 | |||
| 85 | // option is plain old data | ||
| 86 | 1968225 | static int opt_is_pod(enum AVOptionType type) | |
| 87 | { | ||
| 88 |
1/2✓ Branch 0 taken 1968225 times.
✗ Branch 1 not taken.
|
1968225 | switch (type) { |
| 89 | 1968225 | case AV_OPT_TYPE_FLAGS: | |
| 90 | case AV_OPT_TYPE_INT: | ||
| 91 | case AV_OPT_TYPE_INT64: | ||
| 92 | case AV_OPT_TYPE_DOUBLE: | ||
| 93 | case AV_OPT_TYPE_FLOAT: | ||
| 94 | case AV_OPT_TYPE_RATIONAL: | ||
| 95 | case AV_OPT_TYPE_UINT64: | ||
| 96 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
| 97 | case AV_OPT_TYPE_PIXEL_FMT: | ||
| 98 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
| 99 | case AV_OPT_TYPE_VIDEO_RATE: | ||
| 100 | case AV_OPT_TYPE_DURATION: | ||
| 101 | case AV_OPT_TYPE_COLOR: | ||
| 102 | case AV_OPT_TYPE_BOOL: | ||
| 103 | case AV_OPT_TYPE_UINT: | ||
| 104 | 1968225 | return 1; | |
| 105 | } | ||
| 106 | ✗ | return 0; | |
| 107 | } | ||
| 108 | |||
| 109 | 116397 | static uint8_t opt_array_sep(const AVOption *o) | |
| 110 | { | ||
| 111 | 116397 | const AVOptionArrayDef *d = o->default_val.arr; | |
| 112 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
| 113 |
4/4✓ Branch 0 taken 15009 times.
✓ Branch 1 taken 101388 times.
✓ Branch 2 taken 14984 times.
✓ Branch 3 taken 25 times.
|
116397 | return (d && d->sep) ? d->sep : ','; |
| 114 | } | ||
| 115 | |||
| 116 | 7498 | static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx) | |
| 117 | { | ||
| 118 | av_assert1(o->type & AV_OPT_TYPE_FLAG_ARRAY); | ||
| 119 | 7498 | return (uint8_t *)array + idx * opt_type_desc[TYPE_BASE(o->type)].size; | |
| 120 | } | ||
| 121 | |||
| 122 | 175295 | static unsigned *opt_array_pcount(const void *parray) | |
| 123 | { | ||
| 124 | 175295 | return (unsigned *)((const void * const *)parray + 1); | |
| 125 | } | ||
| 126 | |||
| 127 | 29269189 | static void opt_free_elem(enum AVOptionType type, void *ptr) | |
| 128 | { | ||
| 129 |
4/4✓ Branch 0 taken 1021518 times.
✓ Branch 1 taken 916 times.
✓ Branch 2 taken 70155 times.
✓ Branch 3 taken 28176600 times.
|
29269189 | switch (TYPE_BASE(type)) { |
| 130 | 1021518 | case AV_OPT_TYPE_STRING: | |
| 131 | case AV_OPT_TYPE_BINARY: | ||
| 132 | 1021518 | av_freep(ptr); | |
| 133 | 1021518 | break; | |
| 134 | |||
| 135 | 916 | case AV_OPT_TYPE_DICT: | |
| 136 | 916 | av_dict_free((AVDictionary **)ptr); | |
| 137 | 916 | break; | |
| 138 | |||
| 139 | 70155 | case AV_OPT_TYPE_CHLAYOUT: | |
| 140 | 70155 | av_channel_layout_uninit((AVChannelLayout *)ptr); | |
| 141 | 70155 | break; | |
| 142 | |||
| 143 | 28176600 | default: | |
| 144 | 28176600 | break; | |
| 145 | } | ||
| 146 | 29269189 | } | |
| 147 | |||
| 148 | 131893 | static void opt_free_array(const AVOption *o, void *parray, unsigned *count) | |
| 149 | { | ||
| 150 |
2/2✓ Branch 0 taken 3778 times.
✓ Branch 1 taken 131893 times.
|
135671 | for (unsigned i = 0; i < *count; i++) |
| 151 | 3778 | opt_free_elem(o->type, opt_array_pelem(o, *(void **)parray, i)); | |
| 152 | |||
| 153 | 131893 | av_freep(parray); | |
| 154 | 131893 | *count = 0; | |
| 155 | 131893 | } | |
| 156 | |||
| 157 | /** | ||
| 158 | * Perform common setup for option-setting functions. | ||
| 159 | * | ||
| 160 | * @param require_type when non-0, require the option to be of this type | ||
| 161 | * @param ptgt target object is written here | ||
| 162 | * @param po the option is written here | ||
| 163 | * @param pdst pointer to option value is written here | ||
| 164 | */ | ||
| 165 | 313300 | static int opt_set_init(void *obj, const char *name, int search_flags, | |
| 166 | int require_type, | ||
| 167 | void **ptgt, const AVOption **po, void **pdst) | ||
| 168 | { | ||
| 169 | void *logctx; | ||
| 170 | const AVOption *o; | ||
| 171 | void *tgt; | ||
| 172 | |||
| 173 | 313300 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &tgt); | |
| 174 |
3/6✓ Branch 0 taken 245224 times.
✓ Branch 1 taken 68076 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 245224 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
313300 | if (!o || (!tgt && !(search_flags & AV_OPT_SEARCH_FAKE_OBJ))) |
| 175 | 68076 | return AVERROR_OPTION_NOT_FOUND; | |
| 176 | |||
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 245224 times.
|
245224 | if (o->flags & AV_OPT_FLAG_READONLY) |
| 178 | ✗ | return AVERROR(EINVAL); | |
| 179 | |||
| 180 |
1/2✓ Branch 0 taken 245224 times.
✗ Branch 1 not taken.
|
245224 | logctx = tgt ? obj : NULL; |
| 181 | |||
| 182 |
3/4✓ Branch 0 taken 3499 times.
✓ Branch 1 taken 241725 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3499 times.
|
245224 | if (require_type && (o->type != require_type)) { |
| 183 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 184 | "Tried to set option '%s' of type %s from value of type %s, " | ||
| 185 | ✗ | "this is not supported\n", o->name, opt_type_desc[o->type].name, | |
| 186 | ✗ | opt_type_desc[require_type].name); | |
| 187 | ✗ | return AVERROR(EINVAL); | |
| 188 | } | ||
| 189 | |||
| 190 |
2/2✓ Branch 0 taken 218573 times.
✓ Branch 1 taken 26651 times.
|
245224 | if (!(o->flags & AV_OPT_FLAG_RUNTIME_PARAM)) { |
| 191 | 218573 | unsigned *state_flags = NULL; | |
| 192 | const AVClass *class; | ||
| 193 | |||
| 194 | // try state flags first from the target (child), then from its parent | ||
| 195 | 218573 | class = *(const AVClass**)tgt; | |
| 196 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 218573 times.
|
218573 | if (class->state_flags_offset) |
| 197 | ✗ | state_flags = (unsigned*)((uint8_t*)tgt + class->state_flags_offset); | |
| 198 | |||
| 199 |
3/4✓ Branch 0 taken 218573 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51392 times.
✓ Branch 3 taken 167181 times.
|
218573 | if (!state_flags && obj != tgt) { |
| 200 | 51392 | class = *(const AVClass**)obj; | |
| 201 |
2/2✓ Branch 0 taken 50088 times.
✓ Branch 1 taken 1304 times.
|
51392 | if (class->state_flags_offset) |
| 202 | 50088 | state_flags = (unsigned*)((uint8_t*)obj + class->state_flags_offset); | |
| 203 | } | ||
| 204 | |||
| 205 |
3/4✓ Branch 0 taken 50088 times.
✓ Branch 1 taken 168485 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 50088 times.
|
218573 | if (state_flags && (*state_flags & AV_CLASS_STATE_INITIALIZED)) { |
| 206 | ✗ | av_log(logctx, AV_LOG_ERROR, "Option '%s' is not a runtime option and " | |
| 207 | "so cannot be set after the object has been initialized\n", | ||
| 208 | ✗ | o->name); | |
| 209 | ✗ | return AVERROR(EINVAL); | |
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 245222 times.
|
245224 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
| 214 | 2 | av_log(logctx, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
| 215 | |||
| 216 |
2/2✓ Branch 0 taken 241728 times.
✓ Branch 1 taken 3496 times.
|
245224 | if (po) |
| 217 | 241728 | *po = o; | |
| 218 |
2/2✓ Branch 0 taken 228248 times.
✓ Branch 1 taken 16976 times.
|
245224 | if (ptgt) |
| 219 | 228248 | *ptgt = tgt; | |
| 220 |
1/2✓ Branch 0 taken 245224 times.
✗ Branch 1 not taken.
|
245224 | if (pdst) |
| 221 |
1/2✓ Branch 0 taken 245224 times.
✗ Branch 1 not taken.
|
245224 | *pdst = tgt ? ((uint8_t *)tgt) + o->offset : NULL; |
| 222 | |||
| 223 | 245224 | return 0; | |
| 224 | } | ||
| 225 | |||
| 226 | ✗ | static AVRational double_to_rational(double d) | |
| 227 | { | ||
| 228 | ✗ | AVRational r = av_d2q(d, 1 << 24); | |
| 229 | ✗ | if ((!r.num || !r.den) && d) | |
| 230 | ✗ | r = av_d2q(d, INT_MAX); | |
| 231 | ✗ | return r; | |
| 232 | } | ||
| 233 | |||
| 234 | 25132 | static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum) | |
| 235 | { | ||
| 236 |
6/11✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 24900 times.
✓ Branch 4 taken 32 times.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
25132 | switch (TYPE_BASE(o->type)) { |
| 237 | 13 | case AV_OPT_TYPE_FLAGS: | |
| 238 | 13 | *intnum = *(unsigned int*)dst; | |
| 239 | 13 | return 0; | |
| 240 | 3 | case AV_OPT_TYPE_PIXEL_FMT: | |
| 241 | 3 | *intnum = *(enum AVPixelFormat *)dst; | |
| 242 | 3 | return 0; | |
| 243 | 173 | case AV_OPT_TYPE_SAMPLE_FMT: | |
| 244 | 173 | *intnum = *(enum AVSampleFormat *)dst; | |
| 245 | 173 | return 0; | |
| 246 | 24900 | case AV_OPT_TYPE_BOOL: | |
| 247 | case AV_OPT_TYPE_INT: | ||
| 248 | 24900 | *intnum = *(int *)dst; | |
| 249 | 24900 | return 0; | |
| 250 | 32 | case AV_OPT_TYPE_UINT: | |
| 251 | 32 | *intnum = *(unsigned int *)dst; | |
| 252 | 32 | return 0; | |
| 253 | 11 | case AV_OPT_TYPE_DURATION: | |
| 254 | case AV_OPT_TYPE_INT64: | ||
| 255 | case AV_OPT_TYPE_UINT64: | ||
| 256 | 11 | *intnum = *(int64_t *)dst; | |
| 257 | 11 | return 0; | |
| 258 | ✗ | case AV_OPT_TYPE_FLOAT: | |
| 259 | ✗ | *num = *(float *)dst; | |
| 260 | ✗ | return 0; | |
| 261 | ✗ | case AV_OPT_TYPE_DOUBLE: | |
| 262 | ✗ | *num = *(double *)dst; | |
| 263 | ✗ | return 0; | |
| 264 | ✗ | case AV_OPT_TYPE_RATIONAL: | |
| 265 | ✗ | *intnum = ((AVRational *)dst)->num; | |
| 266 | ✗ | *den = ((AVRational *)dst)->den; | |
| 267 | ✗ | return 0; | |
| 268 | ✗ | case AV_OPT_TYPE_CONST: | |
| 269 | ✗ | *intnum = o->default_val.i64; | |
| 270 | ✗ | return 0; | |
| 271 | } | ||
| 272 | ✗ | return AVERROR(EINVAL); | |
| 273 | } | ||
| 274 | |||
| 275 | 10423495 | static int write_number(void *obj, const AVOption *o, void *dst, | |
| 276 | double num, int den, int64_t intnum, | ||
| 277 | int ignore_range) | ||
| 278 | { | ||
| 279 |
1/2✓ Branch 0 taken 10423495 times.
✗ Branch 1 not taken.
|
10423495 | void *logctx = dst ? obj : NULL; |
| 280 | 10423495 | const enum AVOptionType type = TYPE_BASE(o->type); | |
| 281 | |||
| 282 |
6/6✓ Branch 0 taken 223751 times.
✓ Branch 1 taken 10199744 times.
✓ Branch 2 taken 101438 times.
✓ Branch 3 taken 122313 times.
✓ Branch 4 taken 101437 times.
✓ Branch 5 taken 1 times.
|
10423495 | if (!ignore_range && type != AV_OPT_TYPE_FLAGS && |
| 283 |
4/4✓ Branch 0 taken 101429 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 101422 times.
|
101437 | (!den || o->max * den < num * intnum || o->min * den > num * intnum)) { |
| 284 |
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); |
| 285 | 16 | av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
| 286 | 16 | num, o->name, o->min, o->max); | |
| 287 | 16 | return AVERROR(ERANGE); | |
| 288 | } | ||
| 289 |
4/4✓ Branch 0 taken 223735 times.
✓ Branch 1 taken 10199744 times.
✓ Branch 2 taken 122313 times.
✓ Branch 3 taken 101422 times.
|
10423479 | if (!ignore_range && type == AV_OPT_TYPE_FLAGS) { |
| 290 | 122313 | double d = num*intnum/den; | |
| 291 |
3/6✓ Branch 0 taken 122313 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 122313 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 122313 times.
|
122313 | if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) { |
| 292 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 293 | "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n", | ||
| 294 | ✗ | num*intnum/den, o->name); | |
| 295 | ✗ | return AVERROR(ERANGE); | |
| 296 | } | ||
| 297 | } | ||
| 298 | |||
| 299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10423479 times.
|
10423479 | if (!dst) |
| 300 | ✗ | return 0; | |
| 301 | |||
| 302 |
7/9✓ Branch 0 taken 221525 times.
✓ Branch 1 taken 54372 times.
✓ Branch 2 taken 8365662 times.
✓ Branch 3 taken 517922 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 841036 times.
✓ Branch 6 taken 212597 times.
✓ Branch 7 taken 210365 times.
✗ Branch 8 not taken.
|
10423479 | switch (type) { |
| 303 | 221525 | case AV_OPT_TYPE_PIXEL_FMT: | |
| 304 | 221525 | *(enum AVPixelFormat *)dst = llrint(num / den) * intnum; | |
| 305 | 221525 | break; | |
| 306 | 54372 | case AV_OPT_TYPE_SAMPLE_FMT: | |
| 307 | 54372 | *(enum AVSampleFormat *)dst = llrint(num / den) * intnum; | |
| 308 | 54372 | break; | |
| 309 | 8365662 | case AV_OPT_TYPE_BOOL: | |
| 310 | case AV_OPT_TYPE_FLAGS: | ||
| 311 | case AV_OPT_TYPE_INT: | ||
| 312 | case AV_OPT_TYPE_UINT: | ||
| 313 | 8365662 | *(int *)dst = llrint(num / den) * intnum; | |
| 314 | 8365662 | break; | |
| 315 | 517922 | case AV_OPT_TYPE_DURATION: | |
| 316 | case AV_OPT_TYPE_INT64:{ | ||
| 317 | 517922 | double d = num / den; | |
| 318 |
3/4✓ Branch 0 taken 1524 times.
✓ Branch 1 taken 516398 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1524 times.
|
517922 | if (intnum == 1 && d == (double)INT64_MAX) { |
| 319 | ✗ | *(int64_t *)dst = INT64_MAX; | |
| 320 | } else | ||
| 321 | 517922 | *(int64_t *)dst = llrint(d) * intnum; | |
| 322 | 517922 | break;} | |
| 323 | ✗ | case AV_OPT_TYPE_UINT64:{ | |
| 324 | ✗ | double d = num / den; | |
| 325 | // We must special case uint64_t here as llrint() does not support values | ||
| 326 | // outside the int64_t range and there is no portable function which does | ||
| 327 | // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double | ||
| 328 | // while INT64_MAX is not | ||
| 329 | ✗ | if (intnum == 1 && d == (double)UINT64_MAX) { | |
| 330 | ✗ | *(uint64_t *)dst = UINT64_MAX; | |
| 331 | ✗ | } else if (d > INT64_MAX + 1ULL) { | |
| 332 | ✗ | *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum; | |
| 333 | } else { | ||
| 334 | ✗ | *(uint64_t *)dst = llrint(d) * intnum; | |
| 335 | } | ||
| 336 | ✗ | break;} | |
| 337 | 841036 | case AV_OPT_TYPE_FLOAT: | |
| 338 | 841036 | *(float *)dst = num * intnum / den; | |
| 339 | 841036 | break; | |
| 340 | 212597 | case AV_OPT_TYPE_DOUBLE: | |
| 341 | 212597 | *(double *)dst = num * intnum / den; | |
| 342 | 212597 | break; | |
| 343 | 210365 | case AV_OPT_TYPE_RATIONAL: | |
| 344 | case AV_OPT_TYPE_VIDEO_RATE: | ||
| 345 |
1/2✓ Branch 0 taken 210365 times.
✗ Branch 1 not taken.
|
210365 | if ((int) num == num) |
| 346 | 210365 | *(AVRational *)dst = (AVRational) { num *intnum, den }; | |
| 347 | else | ||
| 348 | ✗ | *(AVRational *)dst = double_to_rational(num * intnum / den); | |
| 349 | 210365 | break; | |
| 350 | ✗ | default: | |
| 351 | ✗ | return AVERROR(EINVAL); | |
| 352 | } | ||
| 353 | 10423479 | return 0; | |
| 354 | } | ||
| 355 | |||
| 356 | 20238 | static int hexchar2int(char c) { | |
| 357 |
3/4✓ Branch 0 taken 20238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14544 times.
✓ Branch 3 taken 5694 times.
|
20238 | if (c >= '0' && c <= '9') |
| 358 | 14544 | return c - '0'; | |
| 359 |
4/4✓ Branch 0 taken 5692 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 5691 times.
✓ Branch 3 taken 1 times.
|
5694 | if (c >= 'a' && c <= 'f') |
| 360 | 5691 | return c - 'a' + 10; | |
| 361 |
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') |
| 362 | 2 | return c - 'A' + 10; | |
| 363 | 1 | return -1; | |
| 364 | } | ||
| 365 | |||
| 366 | 20797 | static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
| 367 | { | ||
| 368 | int *lendst; | ||
| 369 | uint8_t *bin, *ptr; | ||
| 370 | int len; | ||
| 371 | |||
| 372 |
1/2✓ Branch 0 taken 20797 times.
✗ Branch 1 not taken.
|
20797 | if (dst) { |
| 373 | 20797 | lendst = (int *)(dst + 1); | |
| 374 | 20797 | av_freep(dst); | |
| 375 | 20797 | *lendst = 0; | |
| 376 | } | ||
| 377 | |||
| 378 |
4/4✓ Branch 0 taken 654 times.
✓ Branch 1 taken 20143 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 643 times.
|
20797 | if (!val || !(len = strlen(val))) |
| 379 | 20154 | return 0; | |
| 380 | |||
| 381 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 642 times.
|
643 | if (len & 1) |
| 382 | 1 | return AVERROR(EINVAL); | |
| 383 | 642 | len /= 2; | |
| 384 | |||
| 385 | 642 | ptr = bin = av_malloc(len); | |
| 386 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 642 times.
|
642 | if (!ptr) |
| 387 | ✗ | return AVERROR(ENOMEM); | |
| 388 |
2/2✓ Branch 0 taken 10119 times.
✓ Branch 1 taken 641 times.
|
10760 | while (*val) { |
| 389 | 10119 | int a = hexchar2int(*val++); | |
| 390 | 10119 | int b = hexchar2int(*val++); | |
| 391 |
3/4✓ Branch 0 taken 10119 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 10118 times.
|
10119 | if (a < 0 || b < 0) { |
| 392 | 1 | av_free(bin); | |
| 393 | 1 | return AVERROR(EINVAL); | |
| 394 | } | ||
| 395 | 10118 | *ptr++ = (a << 4) | b; | |
| 396 | } | ||
| 397 | |||
| 398 |
1/2✓ Branch 0 taken 641 times.
✗ Branch 1 not taken.
|
641 | if (dst) { |
| 399 | 641 | *dst = bin; | |
| 400 | 641 | *lendst = len; | |
| 401 | } else { | ||
| 402 | ✗ | av_free(bin); | |
| 403 | } | ||
| 404 | |||
| 405 | 641 | return 0; | |
| 406 | } | ||
| 407 | |||
| 408 | 569130 | static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
| 409 | { | ||
| 410 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 569130 times.
|
569130 | if (!dst) |
| 411 | ✗ | return 0; | |
| 412 | 569130 | av_freep(dst); | |
| 413 |
2/2✓ Branch 0 taken 467092 times.
✓ Branch 1 taken 102038 times.
|
569130 | if (!val) |
| 414 | 467092 | return 0; | |
| 415 | 102038 | *dst = av_strdup(val); | |
| 416 |
1/2✓ Branch 0 taken 102038 times.
✗ Branch 1 not taken.
|
102038 | return *dst ? 0 : AVERROR(ENOMEM); |
| 417 | } | ||
| 418 | |||
| 419 | #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \ | ||
| 420 | opt->type == AV_OPT_TYPE_UINT64 || \ | ||
| 421 | opt->type == AV_OPT_TYPE_CONST || \ | ||
| 422 | opt->type == AV_OPT_TYPE_FLAGS || \ | ||
| 423 | opt->type == AV_OPT_TYPE_UINT || \ | ||
| 424 | opt->type == AV_OPT_TYPE_INT) \ | ||
| 425 | ? opt->default_val.i64 \ | ||
| 426 | : opt->default_val.dbl) | ||
| 427 | |||
| 428 | 156694 | static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst) | |
| 429 | { | ||
| 430 |
1/2✓ Branch 0 taken 156694 times.
✗ Branch 1 not taken.
|
156694 | void *logctx = dst ? obj : NULL; |
| 431 | 156694 | const enum AVOptionType type = TYPE_BASE(o->type); | |
| 432 | 156694 | int ret = 0; | |
| 433 | |||
| 434 |
3/4✓ Branch 0 taken 155226 times.
✓ Branch 1 taken 1468 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 155226 times.
|
156694 | if (type == AV_OPT_TYPE_RATIONAL || type == AV_OPT_TYPE_VIDEO_RATE) { |
| 435 | int num, den; | ||
| 436 | char c; | ||
| 437 |
2/2✓ Branch 0 taken 1448 times.
✓ Branch 1 taken 20 times.
|
1468 | if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) { |
| 438 |
2/2✓ Branch 1 taken 1446 times.
✓ Branch 2 taken 2 times.
|
1448 | if ((ret = write_number(obj, o, dst, 1, den, num, 0)) >= 0) |
| 439 | 1446 | return ret; | |
| 440 | 2 | ret = 0; | |
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | 53324 | for (;;) { | |
| 445 | 208572 | int i = 0; | |
| 446 | char buf[256]; | ||
| 447 | 208572 | int cmd = 0; | |
| 448 | double d; | ||
| 449 | 208572 | int64_t intnum = 1; | |
| 450 | |||
| 451 |
2/2✓ Branch 0 taken 122313 times.
✓ Branch 1 taken 86259 times.
|
208572 | if (type == AV_OPT_TYPE_FLAGS) { |
| 452 |
4/4✓ Branch 0 taken 23626 times.
✓ Branch 1 taken 98687 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 23598 times.
|
122313 | if (*val == '+' || *val == '-') |
| 453 | 98715 | cmd = *(val++); | |
| 454 |
7/8✓ Branch 0 taken 1029072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 960083 times.
✓ Branch 3 taken 68989 times.
✓ Branch 4 taken 906760 times.
✓ Branch 5 taken 53323 times.
✓ Branch 6 taken 906759 times.
✓ Branch 7 taken 1 times.
|
1029072 | for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++) |
| 455 | 906759 | buf[i] = val[i]; | |
| 456 | 122313 | buf[i] = 0; | |
| 457 | } | ||
| 458 | |||
| 459 | { | ||
| 460 | int res; | ||
| 461 | 208572 | int ci = 0; | |
| 462 | double const_values[64]; | ||
| 463 | const char * const_names[64]; | ||
| 464 | 208572 | int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0; | |
| 465 |
2/2✓ Branch 0 taken 122313 times.
✓ Branch 1 taken 86259 times.
|
208572 | const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags); |
| 466 |
3/4✓ Branch 0 taken 155102 times.
✓ Branch 1 taken 53470 times.
✓ Branch 2 taken 155102 times.
✗ Branch 3 not taken.
|
208572 | if (o_named && o_named->type == AV_OPT_TYPE_CONST) { |
| 467 |
3/12✓ Branch 0 taken 155102 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 155102 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 155102 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.
|
155102 | d = DEFAULT_NUMVAL(o_named); |
| 468 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 155101 times.
|
155102 | if (o_named->flags & AV_OPT_FLAG_DEPRECATED) |
| 469 | 1 | av_log(logctx, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", | |
| 470 | 1 | o_named->name, o_named->help); | |
| 471 | } else { | ||
| 472 |
2/2✓ Branch 0 taken 37400 times.
✓ Branch 1 taken 16070 times.
|
53470 | if (o->unit) { |
| 473 |
2/2✓ Branch 1 taken 10526087 times.
✓ Branch 2 taken 37400 times.
|
10563487 | for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) { |
| 474 |
2/2✓ Branch 0 taken 7414718 times.
✓ Branch 1 taken 3111369 times.
|
10526087 | if (o_named->type == AV_OPT_TYPE_CONST && |
| 475 |
1/2✓ Branch 0 taken 7414718 times.
✗ Branch 1 not taken.
|
7414718 | o_named->unit && |
| 476 |
2/2✓ Branch 0 taken 345129 times.
✓ Branch 1 taken 7069589 times.
|
7414718 | !strcmp(o_named->unit, o->unit)) { |
| 477 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 345129 times.
|
345129 | if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) { |
| 478 | ✗ | av_log(logctx, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit); | |
| 479 | 8 | return AVERROR_PATCHWELCOME; | |
| 480 | } | ||
| 481 | 345129 | const_names [ci ] = o_named->name; | |
| 482 |
3/12✓ Branch 0 taken 345129 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 345129 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 345129 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.
|
345129 | const_values[ci++] = DEFAULT_NUMVAL(o_named); |
| 483 | } | ||
| 484 | } | ||
| 485 | } | ||
| 486 | 53470 | const_names [ci ] = "default"; | |
| 487 |
10/12✓ Branch 0 taken 51943 times.
✓ Branch 1 taken 1527 times.
✓ Branch 2 taken 51943 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 51943 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 43188 times.
✓ Branch 7 taken 8755 times.
✓ Branch 8 taken 43085 times.
✓ Branch 9 taken 103 times.
✓ Branch 10 taken 41942 times.
✓ Branch 11 taken 1143 times.
|
53470 | const_values[ci++] = DEFAULT_NUMVAL(o); |
| 488 | 53470 | const_names [ci ] = "max"; | |
| 489 | 53470 | const_values[ci++] = o->max; | |
| 490 | 53470 | const_names [ci ] = "min"; | |
| 491 | 53470 | const_values[ci++] = o->min; | |
| 492 | 53470 | const_names [ci ] = "none"; | |
| 493 | 53470 | const_values[ci++] = 0; | |
| 494 | 53470 | const_names [ci ] = "all"; | |
| 495 | 53470 | const_values[ci++] = ~0; | |
| 496 | 53470 | const_names [ci] = NULL; | |
| 497 | 53470 | const_values[ci] = 0; | |
| 498 | |||
| 499 |
2/2✓ Branch 0 taken 8755 times.
✓ Branch 1 taken 44715 times.
|
53470 | res = av_expr_parse_and_eval(&d, i ? buf : val, const_names, |
| 500 | const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); | ||
| 501 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 53462 times.
|
53470 | if (res < 0) { |
| 502 | 8 | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\"\n", o->name, val); | |
| 503 | 8 | return res; | |
| 504 | } | ||
| 505 | } | ||
| 506 | } | ||
| 507 |
3/4✓ Branch 0 taken 122313 times.
✓ Branch 1 taken 86251 times.
✓ Branch 2 taken 122313 times.
✗ Branch 3 not taken.
|
208564 | if (type == AV_OPT_TYPE_FLAGS && dst) { |
| 508 | 122313 | intnum = *(unsigned int*)dst; | |
| 509 |
2/2✓ Branch 0 taken 98687 times.
✓ Branch 1 taken 23626 times.
|
122313 | if (cmd == '+') |
| 510 | 98687 | d = intnum | (int64_t)d; | |
| 511 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 23598 times.
|
23626 | else if (cmd == '-') |
| 512 | 28 | d = intnum &~(int64_t)d; | |
| 513 | } | ||
| 514 | |||
| 515 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 208550 times.
|
208564 | if ((ret = write_number(obj, o, dst, d, 1, 1, 0)) < 0) |
| 516 | 14 | return ret; | |
| 517 | 208550 | val += i; | |
| 518 |
4/4✓ Branch 0 taken 122313 times.
✓ Branch 1 taken 86237 times.
✓ Branch 2 taken 68989 times.
✓ Branch 3 taken 53324 times.
|
208550 | if (!i || !*val) |
| 519 | 155226 | return 0; | |
| 520 | } | ||
| 521 | } | ||
| 522 | |||
| 523 | 54545 | static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst) | |
| 524 | { | ||
| 525 |
1/2✓ Branch 0 taken 54545 times.
✗ Branch 1 not taken.
|
54545 | void *logctx = dst ? obj : NULL; |
| 526 | int tmp[2]; | ||
| 527 | int ret; | ||
| 528 | |||
| 529 |
3/4✓ Branch 0 taken 7807 times.
✓ Branch 1 taken 46738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7807 times.
|
54545 | if (!val || !strcmp(val, "none")) { |
| 530 |
1/2✓ Branch 0 taken 46738 times.
✗ Branch 1 not taken.
|
46738 | if (dst) { |
| 531 | 46738 | dst[0] = | |
| 532 | 46738 | dst[1] = 0; | |
| 533 | } | ||
| 534 | 46738 | return 0; | |
| 535 | } | ||
| 536 | 7807 | ret = av_parse_video_size(&tmp[0], &tmp[1], val); | |
| 537 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7806 times.
|
7807 | if (ret < 0) |
| 538 | 1 | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as image size\n", o->name, val); | |
| 539 |
1/2✓ Branch 0 taken 7807 times.
✗ Branch 1 not taken.
|
7807 | if (dst) |
| 540 | 7807 | memcpy(dst, tmp, sizeof(tmp)); | |
| 541 | 7807 | return ret; | |
| 542 | } | ||
| 543 | |||
| 544 | 9891 | static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst) | |
| 545 | { | ||
| 546 |
1/2✓ Branch 0 taken 9891 times.
✗ Branch 1 not taken.
|
9891 | void *logctx = dst ? obj : NULL; |
| 547 | AVRational tmp; | ||
| 548 | 9891 | int ret = av_parse_video_rate(&tmp, val); | |
| 549 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9890 times.
|
9891 | if (ret < 0) |
| 550 | 1 | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as video rate\n", o->name, val); | |
| 551 |
1/2✓ Branch 0 taken 9891 times.
✗ Branch 1 not taken.
|
9891 | if (dst) |
| 552 | 9891 | *dst = tmp; | |
| 553 | 9891 | return ret; | |
| 554 | } | ||
| 555 | |||
| 556 | 408 | static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
| 557 | { | ||
| 558 |
1/2✓ Branch 0 taken 408 times.
✗ Branch 1 not taken.
|
408 | void *logctx = dst ? obj : NULL; |
| 559 | int ret; | ||
| 560 | |||
| 561 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
|
408 | if (!val) { |
| 562 | ✗ | return 0; | |
| 563 | } else { | ||
| 564 | uint8_t tmp[4]; | ||
| 565 | 408 | ret = av_parse_color(tmp, val, -1, obj); | |
| 566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 408 times.
|
408 | if (ret < 0) |
| 567 | ✗ | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as color\n", o->name, val); | |
| 568 |
1/2✓ Branch 0 taken 408 times.
✗ Branch 1 not taken.
|
408 | if (dst) |
| 569 | 408 | memcpy(dst, tmp, sizeof(tmp)); | |
| 570 | 408 | return ret; | |
| 571 | } | ||
| 572 | return 0; | ||
| 573 | } | ||
| 574 | |||
| 575 | 72 | static const char *get_bool_name(int val) | |
| 576 | { | ||
| 577 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 67 times.
|
72 | if (val < 0) |
| 578 | 5 | return "auto"; | |
| 579 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 45 times.
|
67 | return val ? "true" : "false"; |
| 580 | } | ||
| 581 | |||
| 582 | 10246 | static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst) | |
| 583 | { | ||
| 584 |
1/2✓ Branch 0 taken 10246 times.
✗ Branch 1 not taken.
|
10246 | void *logctx = dst ? obj : NULL; |
| 585 | int n; | ||
| 586 | |||
| 587 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10246 times.
|
10246 | if (!val) |
| 588 | ✗ | return 0; | |
| 589 | |||
| 590 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10243 times.
|
10246 | if (!strcmp(val, "auto")) { |
| 591 | 3 | n = -1; | |
| 592 |
2/2✓ Branch 1 taken 1269 times.
✓ Branch 2 taken 8974 times.
|
10243 | } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) { |
| 593 | 1269 | n = 1; | |
| 594 |
2/2✓ Branch 1 taken 125 times.
✓ Branch 2 taken 8849 times.
|
8974 | } else if (av_match_name(val, "false,n,no,disable,disabled,off")) { |
| 595 | 125 | n = 0; | |
| 596 | } else { | ||
| 597 | 8849 | char *end = NULL; | |
| 598 | 8849 | n = strtol(val, &end, 10); | |
| 599 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8849 times.
|
8849 | if (val + strlen(val) != end) |
| 600 | ✗ | goto fail; | |
| 601 | } | ||
| 602 | |||
| 603 |
2/4✓ Branch 0 taken 10246 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10246 times.
|
10246 | if (n < o->min || n > o->max) |
| 604 | ✗ | goto fail; | |
| 605 | |||
| 606 |
1/2✓ Branch 0 taken 10246 times.
✗ Branch 1 not taken.
|
10246 | if (dst) |
| 607 | 10246 | *dst = n; | |
| 608 | 10246 | return 0; | |
| 609 | |||
| 610 | ✗ | fail: | |
| 611 | ✗ | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as boolean\n", o->name, val); | |
| 612 | ✗ | return AVERROR(EINVAL); | |
| 613 | } | ||
| 614 | |||
| 615 | 5458 | static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst, | |
| 616 | int fmt_nb, int ((*get_fmt)(const char *)), const char *desc, | ||
| 617 | enum AVOptionType type) | ||
| 618 | { | ||
| 619 |
1/2✓ Branch 0 taken 5458 times.
✗ Branch 1 not taken.
|
5458 | void *logctx = dst ? obj : NULL; |
| 620 | int fmt, min, max; | ||
| 621 | |||
| 622 |
2/4✓ Branch 0 taken 5458 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5458 times.
|
5458 | if (!val || !strcmp(val, "none")) { |
| 623 | ✗ | fmt = -1; | |
| 624 | } else { | ||
| 625 | 5458 | fmt = get_fmt(val); | |
| 626 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5454 times.
|
5458 | if (fmt == -1) { |
| 627 | char *tail; | ||
| 628 | 4 | fmt = strtol(val, &tail, 0); | |
| 629 |
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) { |
| 630 | 2 | av_log(logctx, AV_LOG_ERROR, | |
| 631 | 2 | "Unable to parse \"%s\" option value \"%s\" as %s\n", o->name, val, desc); | |
| 632 | 2 | return AVERROR(EINVAL); | |
| 633 | } | ||
| 634 | } | ||
| 635 | } | ||
| 636 | |||
| 637 |
2/2✓ Branch 0 taken 2773 times.
✓ Branch 1 taken 2683 times.
|
5456 | min = FFMAX(o->min, -1); |
| 638 |
2/2✓ Branch 0 taken 3259 times.
✓ Branch 1 taken 2197 times.
|
5456 | max = FFMIN(o->max, fmt_nb-1); |
| 639 | |||
| 640 | // hack for compatibility with old ffmpeg | ||
| 641 |
4/4✓ Branch 0 taken 2773 times.
✓ Branch 1 taken 2683 times.
✓ Branch 2 taken 2197 times.
✓ Branch 3 taken 576 times.
|
5456 | if(min == 0 && max == 0) { |
| 642 | 2197 | min = -1; | |
| 643 | 2197 | max = fmt_nb-1; | |
| 644 | } | ||
| 645 | |||
| 646 |
2/4✓ Branch 0 taken 5456 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5456 times.
|
5456 | if (fmt < min || fmt > max) { |
| 647 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 648 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
| 649 | ✗ | fmt, o->name, desc, min, max); | |
| 650 | ✗ | return AVERROR(ERANGE); | |
| 651 | } | ||
| 652 | |||
| 653 |
1/2✓ Branch 0 taken 5456 times.
✗ Branch 1 not taken.
|
5456 | if (dst) |
| 654 |
2/3✓ Branch 0 taken 580 times.
✓ Branch 1 taken 4876 times.
✗ Branch 2 not taken.
|
5456 | switch (type) { |
| 655 | 580 | case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = fmt; break; | |
| 656 | 4876 | case AV_OPT_TYPE_SAMPLE_FMT: *(enum AVSampleFormat*)dst = fmt; break; | |
| 657 | ✗ | default: av_unreachable("set_string_fmt() is only called for pixel and sample formats"); | |
| 658 | } | ||
| 659 | 5456 | return 0; | |
| 660 | } | ||
| 661 | |||
| 662 | 581 | static int get_pix_fmt(const char *name) | |
| 663 | { | ||
| 664 | 581 | return av_get_pix_fmt(name); | |
| 665 | } | ||
| 666 | |||
| 667 | 581 | static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
| 668 | { | ||
| 669 | 581 | return set_string_fmt(obj, o, val, dst, | |
| 670 | AV_PIX_FMT_NB, get_pix_fmt, | ||
| 671 | "pixel format", AV_OPT_TYPE_PIXEL_FMT); | ||
| 672 | } | ||
| 673 | |||
| 674 | 4877 | static int get_sample_fmt(const char *name) | |
| 675 | { | ||
| 676 | 4877 | return av_get_sample_fmt(name); | |
| 677 | } | ||
| 678 | |||
| 679 | 4877 | static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst) | |
| 680 | { | ||
| 681 | 4877 | return set_string_fmt(obj, o, val, dst, | |
| 682 | AV_SAMPLE_FMT_NB, get_sample_fmt, | ||
| 683 | "sample format", AV_OPT_TYPE_SAMPLE_FMT); | ||
| 684 | } | ||
| 685 | |||
| 686 | 955 | static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst) | |
| 687 | { | ||
| 688 | 955 | AVDictionary *options = NULL; | |
| 689 | |||
| 690 |
2/2✓ Branch 0 taken 68 times.
✓ Branch 1 taken 887 times.
|
955 | if (val) { |
| 691 | 68 | int ret = av_dict_parse_string(&options, val, "=", ":", 0); | |
| 692 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if (ret < 0) { |
| 693 | ✗ | av_dict_free(&options); | |
| 694 | ✗ | return ret; | |
| 695 | } | ||
| 696 | } | ||
| 697 | |||
| 698 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 955 times.
|
955 | if (!dst) { |
| 699 | ✗ | av_dict_free(&options); | |
| 700 | ✗ | return 0; | |
| 701 | } | ||
| 702 | |||
| 703 | 955 | av_dict_free((AVDictionary **)dst); | |
| 704 | 955 | *dst = (uint8_t *)options; | |
| 705 | |||
| 706 | 955 | return 0; | |
| 707 | } | ||
| 708 | |||
| 709 | 62397 | static int set_string_channel_layout(void *obj, const AVOption *o, | |
| 710 | const char *val, void *dst) | ||
| 711 | { | ||
| 712 | AVChannelLayout tmp; | ||
| 713 | 62397 | AVChannelLayout *channel_layout = dst; | |
| 714 | int ret; | ||
| 715 |
1/2✓ Branch 0 taken 62397 times.
✗ Branch 1 not taken.
|
62397 | if (dst) |
| 716 | 62397 | av_channel_layout_uninit(channel_layout); | |
| 717 | else | ||
| 718 | ✗ | channel_layout = &tmp; | |
| 719 |
2/2✓ Branch 0 taken 60091 times.
✓ Branch 1 taken 2306 times.
|
62397 | if (!val) |
| 720 | 60091 | return 0; | |
| 721 | 2306 | ret = av_channel_layout_from_string(channel_layout, val); | |
| 722 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2305 times.
|
2306 | if (ret < 0) |
| 723 | 1 | return ret; | |
| 724 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2305 times.
|
2305 | if (!dst) |
| 725 | ✗ | av_channel_layout_uninit(channel_layout); | |
| 726 | 2305 | return 0; | |
| 727 | } | ||
| 728 | |||
| 729 | 229301 | static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, | |
| 730 | const char *val, void *dst) | ||
| 731 | { | ||
| 732 |
1/2✓ Branch 0 taken 229301 times.
✗ Branch 1 not taken.
|
229301 | void *logctx = dst ? obj : NULL; |
| 733 | 229301 | const enum AVOptionType type = TYPE_BASE(o->type); | |
| 734 | int ret; | ||
| 735 | |||
| 736 |
1/6✗ Branch 0 not taken.
✓ Branch 1 taken 229301 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
229301 | if (!val && (type != AV_OPT_TYPE_STRING && |
| 737 | ✗ | type != AV_OPT_TYPE_PIXEL_FMT && type != AV_OPT_TYPE_SAMPLE_FMT && | |
| 738 | ✗ | type != AV_OPT_TYPE_IMAGE_SIZE && | |
| 739 | ✗ | type != AV_OPT_TYPE_DURATION && type != AV_OPT_TYPE_COLOR && | |
| 740 | type != AV_OPT_TYPE_BOOL)) | ||
| 741 | ✗ | return AVERROR(EINVAL); | |
| 742 | |||
| 743 |
12/13✓ Branch 0 taken 10246 times.
✓ Branch 1 taken 65588 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 142124 times.
✓ Branch 4 taken 2888 times.
✓ Branch 5 taken 263 times.
✓ Branch 6 taken 581 times.
✓ Branch 7 taken 4877 times.
✓ Branch 8 taken 385 times.
✓ Branch 9 taken 53 times.
✓ Branch 10 taken 2206 times.
✓ Branch 11 taken 61 times.
✗ Branch 12 not taken.
|
229301 | switch (type) { |
| 744 | 10246 | case AV_OPT_TYPE_BOOL: | |
| 745 | 10246 | return set_string_bool(obj, o, val, dst); | |
| 746 | 65588 | case AV_OPT_TYPE_STRING: | |
| 747 | 65588 | return set_string(obj, o, val, dst); | |
| 748 | 29 | case AV_OPT_TYPE_BINARY: | |
| 749 | 29 | return set_string_binary(obj, o, val, dst); | |
| 750 | 142124 | case AV_OPT_TYPE_FLAGS: | |
| 751 | case AV_OPT_TYPE_INT: | ||
| 752 | case AV_OPT_TYPE_UINT: | ||
| 753 | case AV_OPT_TYPE_INT64: | ||
| 754 | case AV_OPT_TYPE_UINT64: | ||
| 755 | case AV_OPT_TYPE_FLOAT: | ||
| 756 | case AV_OPT_TYPE_DOUBLE: | ||
| 757 | case AV_OPT_TYPE_RATIONAL: | ||
| 758 | 142124 | return set_string_number(obj, target_obj, o, val, dst); | |
| 759 | 2888 | case AV_OPT_TYPE_IMAGE_SIZE: | |
| 760 | 2888 | return set_string_image_size(obj, o, val, dst); | |
| 761 | 263 | case AV_OPT_TYPE_VIDEO_RATE: { | |
| 762 | AVRational tmp; | ||
| 763 | 263 | ret = set_string_video_rate(obj, o, val, &tmp); | |
| 764 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 262 times.
|
263 | if (ret < 0) |
| 765 | 1 | return ret; | |
| 766 | 262 | return write_number(obj, o, dst, 1, tmp.den, tmp.num, 0); | |
| 767 | } | ||
| 768 | 581 | case AV_OPT_TYPE_PIXEL_FMT: | |
| 769 | 581 | return set_string_pixel_fmt(obj, o, val, dst); | |
| 770 | 4877 | case AV_OPT_TYPE_SAMPLE_FMT: | |
| 771 | 4877 | return set_string_sample_fmt(obj, o, val, dst); | |
| 772 | 385 | case AV_OPT_TYPE_DURATION: | |
| 773 | { | ||
| 774 | 385 | int64_t usecs = 0; | |
| 775 |
1/2✓ Branch 0 taken 385 times.
✗ Branch 1 not taken.
|
385 | if (val) { |
| 776 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 384 times.
|
385 | if ((ret = av_parse_time(&usecs, val, 1)) < 0) { |
| 777 | 1 | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as duration\n", o->name, val); | |
| 778 | 1 | return ret; | |
| 779 | } | ||
| 780 | } | ||
| 781 |
2/4✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 384 times.
|
384 | if (usecs < o->min || usecs > o->max) { |
| 782 | ✗ | av_log(logctx, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n", | |
| 783 | ✗ | usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0); | |
| 784 | ✗ | return AVERROR(ERANGE); | |
| 785 | } | ||
| 786 |
1/2✓ Branch 0 taken 384 times.
✗ Branch 1 not taken.
|
384 | if (dst) |
| 787 | 384 | *(int64_t *)dst = usecs; | |
| 788 | 384 | return 0; | |
| 789 | } | ||
| 790 | 53 | case AV_OPT_TYPE_COLOR: | |
| 791 | 53 | return set_string_color(obj, o, val, dst); | |
| 792 | 2206 | case AV_OPT_TYPE_CHLAYOUT: | |
| 793 | 2206 | ret = set_string_channel_layout(obj, o, val, dst); | |
| 794 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2205 times.
|
2206 | if (ret < 0) { |
| 795 | 1 | av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as channel layout\n", o->name, val); | |
| 796 | 1 | ret = AVERROR(EINVAL); | |
| 797 | } | ||
| 798 | 2206 | return ret; | |
| 799 | 61 | case AV_OPT_TYPE_DICT: | |
| 800 | 61 | return set_string_dict(obj, o, val, dst); | |
| 801 | } | ||
| 802 | |||
| 803 | ✗ | av_log(logctx, AV_LOG_ERROR, "Invalid option type.\n"); | |
| 804 | ✗ | return AVERROR(EINVAL); | |
| 805 | } | ||
| 806 | |||
| 807 | 2353 | static int opt_set_array(void *obj, void *target_obj, const AVOption *o, | |
| 808 | const char *val, void *dst) | ||
| 809 | { | ||
| 810 | 2353 | const AVOptionArrayDef *arr = o->default_val.arr; | |
| 811 | 2353 | const size_t elem_size = opt_type_desc[TYPE_BASE(o->type)].size; | |
| 812 | 2353 | const uint8_t sep = opt_array_sep(o); | |
| 813 | 2353 | uint8_t *str = NULL; | |
| 814 | |||
| 815 |
1/2✓ Branch 0 taken 2353 times.
✗ Branch 1 not taken.
|
2353 | void *logctx = dst ? obj : NULL; |
| 816 | 2353 | void *elems = NULL; | |
| 817 | 2353 | unsigned nb_elems = 0; | |
| 818 | int ret; | ||
| 819 | |||
| 820 |
4/4✓ Branch 0 taken 2341 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 2339 times.
✓ Branch 3 taken 2 times.
|
2353 | if (val && *val) { |
| 821 | 2339 | str = av_malloc(strlen(val) + 1); | |
| 822 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2339 times.
|
2339 | if (!str) |
| 823 | ✗ | return AVERROR(ENOMEM); | |
| 824 | } | ||
| 825 | |||
| 826 | // split and unescape the string | ||
| 827 |
4/4✓ Branch 0 taken 5777 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 3437 times.
✓ Branch 3 taken 2340 times.
|
5789 | while (val && *val) { |
| 828 | 3437 | uint8_t *p = str; | |
| 829 | void *tmp; | ||
| 830 | |||
| 831 |
5/6✓ Branch 0 taken 3424 times.
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 3392 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 32 times.
|
3437 | if (arr && arr->size_max && nb_elems >= arr->size_max) { |
| 832 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 833 | "Cannot assign more than %u elements to array option %s\n", | ||
| 834 | ✗ | arr->size_max, o->name); | |
| 835 | ✗ | ret = AVERROR(EINVAL); | |
| 836 | ✗ | goto fail; | |
| 837 | } | ||
| 838 | |||
| 839 |
2/2✓ Branch 0 taken 15545 times.
✓ Branch 1 taken 2339 times.
|
17884 | for (; *val; val++, p++) { |
| 840 |
3/4✓ Branch 0 taken 63 times.
✓ Branch 1 taken 15482 times.
✓ Branch 2 taken 63 times.
✗ Branch 3 not taken.
|
15545 | if (*val == '\\' && val[1]) |
| 841 | 63 | val++; | |
| 842 |
2/2✓ Branch 0 taken 1098 times.
✓ Branch 1 taken 14384 times.
|
15482 | else if (*val == sep) { |
| 843 | 1098 | val++; | |
| 844 | 1098 | break; | |
| 845 | } | ||
| 846 | 14447 | *p = *val; | |
| 847 | } | ||
| 848 | 3437 | *p = 0; | |
| 849 | |||
| 850 | 3437 | tmp = av_realloc_array(elems, nb_elems + 1, elem_size); | |
| 851 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3437 times.
|
3437 | if (!tmp) { |
| 852 | ✗ | ret = AVERROR(ENOMEM); | |
| 853 | ✗ | goto fail; | |
| 854 | } | ||
| 855 | 3437 | elems = tmp; | |
| 856 | |||
| 857 | 3437 | tmp = opt_array_pelem(o, elems, nb_elems); | |
| 858 | 3437 | memset(tmp, 0, elem_size); | |
| 859 | |||
| 860 | 3437 | ret = opt_set_elem(obj, target_obj, o, str, tmp); | |
| 861 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3436 times.
|
3437 | if (ret < 0) |
| 862 | 1 | goto fail; | |
| 863 | 3436 | nb_elems++; | |
| 864 | } | ||
| 865 | 2352 | av_freep(&str); | |
| 866 | |||
| 867 |
1/2✓ Branch 0 taken 2352 times.
✗ Branch 1 not taken.
|
2352 | if (dst) |
| 868 | 2352 | opt_free_array(o, dst, opt_array_pcount(dst)); | |
| 869 | |||
| 870 |
3/4✓ Branch 0 taken 2333 times.
✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2333 times.
|
2352 | if (arr && nb_elems < arr->size_min) { |
| 871 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 872 | "Cannot assign fewer than %u elements to array option %s\n", | ||
| 873 | ✗ | arr->size_min, o->name); | |
| 874 | ✗ | ret = AVERROR(EINVAL); | |
| 875 | ✗ | goto fail; | |
| 876 | } | ||
| 877 | |||
| 878 |
1/2✓ Branch 0 taken 2352 times.
✗ Branch 1 not taken.
|
2352 | if (dst) { |
| 879 | 2352 | *((void **)dst) = elems; | |
| 880 | 2352 | *opt_array_pcount(dst) = nb_elems; | |
| 881 | } else | ||
| 882 | ✗ | opt_free_array(o, &elems, &nb_elems); | |
| 883 | |||
| 884 | 2352 | return 0; | |
| 885 | 1 | fail: | |
| 886 | 1 | av_freep(&str); | |
| 887 | 1 | opt_free_array(o, &elems, &nb_elems); | |
| 888 | 1 | return ret; | |
| 889 | } | ||
| 890 | |||
| 891 | 279891 | int av_opt_set(void *obj, const char *name, const char *val, int search_flags) | |
| 892 | { | ||
| 893 | void *dst, *target_obj; | ||
| 894 | const AVOption *o; | ||
| 895 | int ret; | ||
| 896 | |||
| 897 | 279891 | ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &dst); | |
| 898 |
2/2✓ Branch 0 taken 51688 times.
✓ Branch 1 taken 228203 times.
|
279891 | if (ret < 0) |
| 899 | 51688 | return ret; | |
| 900 | |||
| 901 | 228203 | return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ? | |
| 902 |
2/2✓ Branch 0 taken 2339 times.
✓ Branch 1 taken 225864 times.
|
228203 | opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst); |
| 903 | } | ||
| 904 | |||
| 905 | #define OPT_EVAL_NUMBER(name, opttype, vartype) \ | ||
| 906 | int av_opt_eval_ ## name(void *obj, const AVOption *o, \ | ||
| 907 | const char *val, vartype *name ## _out) \ | ||
| 908 | { \ | ||
| 909 | if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \ | ||
| 910 | return AVERROR(EINVAL); \ | ||
| 911 | return set_string_number(obj, obj, o, val, name ## _out); \ | ||
| 912 | } | ||
| 913 | |||
| 914 |
3/6✓ Branch 0 taken 14542 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14542 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14542 times.
|
14542 | OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int) |
| 915 |
3/6✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 28 times.
|
28 | OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int) |
| 916 | ✗ | OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned) | |
| 917 | ✗ | OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t) | |
| 918 | ✗ | OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float) | |
| 919 | ✗ | OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double) | |
| 920 | ✗ | OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational) | |
| 921 | |||
| 922 | 29865 | static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, | |
| 923 | int search_flags, int require_type) | ||
| 924 | { | ||
| 925 | void *dst; | ||
| 926 | const AVOption *o; | ||
| 927 | int ret; | ||
| 928 | |||
| 929 | 29865 | ret = opt_set_init(obj, name, search_flags, require_type, NULL, &o, &dst); | |
| 930 |
2/2✓ Branch 0 taken 16388 times.
✓ Branch 1 taken 13477 times.
|
29865 | if (ret < 0) |
| 931 | 16388 | return ret; | |
| 932 |
1/2✓ Branch 0 taken 13477 times.
✗ Branch 1 not taken.
|
13477 | if (dst) |
| 933 | 13477 | ret = write_number(obj, o, dst, num, den, intnum, 0); | |
| 934 | |||
| 935 | 13477 | return ret; | |
| 936 | } | ||
| 937 | |||
| 938 | 29835 | int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags) | |
| 939 | { | ||
| 940 | 29835 | return set_number(obj, name, 1, 1, val, search_flags, 0); | |
| 941 | } | ||
| 942 | |||
| 943 | 24 | int av_opt_set_double(void *obj, const char *name, double val, int search_flags) | |
| 944 | { | ||
| 945 | 24 | return set_number(obj, name, val, 1, 1, search_flags, 0); | |
| 946 | } | ||
| 947 | |||
| 948 | 6 | int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) | |
| 949 | { | ||
| 950 | 6 | return set_number(obj, name, val.num, val.den, 1, search_flags, 0); | |
| 951 | } | ||
| 952 | |||
| 953 | ✗ | int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags) | |
| 954 | { | ||
| 955 | uint8_t *ptr; | ||
| 956 | uint8_t **dst; | ||
| 957 | int *lendst; | ||
| 958 | int ret; | ||
| 959 | |||
| 960 | ✗ | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_BINARY, | |
| 961 | NULL, NULL, (void**)&dst); | ||
| 962 | ✗ | if (ret < 0) | |
| 963 | ✗ | return ret; | |
| 964 | |||
| 965 | ✗ | if (dst) { | |
| 966 | ✗ | ptr = len ? av_malloc(len) : NULL; | |
| 967 | ✗ | if (len && !ptr) | |
| 968 | ✗ | return AVERROR(ENOMEM); | |
| 969 | |||
| 970 | ✗ | lendst = (int *)(dst + 1); | |
| 971 | |||
| 972 | ✗ | av_free(*dst); | |
| 973 | ✗ | *dst = ptr; | |
| 974 | ✗ | *lendst = len; | |
| 975 | ✗ | if (len) | |
| 976 | ✗ | memcpy(ptr, val, len); | |
| 977 | } | ||
| 978 | |||
| 979 | ✗ | return 0; | |
| 980 | } | ||
| 981 | |||
| 982 | ✗ | int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags) | |
| 983 | { | ||
| 984 | const AVOption *o; | ||
| 985 | void *logctx; | ||
| 986 | int *dst; | ||
| 987 | int ret; | ||
| 988 | |||
| 989 | ✗ | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_IMAGE_SIZE, | |
| 990 | NULL, &o, (void**)&dst); | ||
| 991 | ✗ | if (ret < 0) | |
| 992 | ✗ | return ret; | |
| 993 | |||
| 994 | ✗ | logctx = dst ? obj : NULL; | |
| 995 | |||
| 996 | ✗ | if (w<0 || h<0) { | |
| 997 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 998 | ✗ | "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name); | |
| 999 | ✗ | return AVERROR(EINVAL); | |
| 1000 | } | ||
| 1001 | |||
| 1002 | ✗ | if (dst) { | |
| 1003 | ✗ | dst[0] = w; | |
| 1004 | ✗ | dst[1] = h; | |
| 1005 | } | ||
| 1006 | |||
| 1007 | ✗ | return 0; | |
| 1008 | } | ||
| 1009 | |||
| 1010 | ✗ | int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags) | |
| 1011 | { | ||
| 1012 | ✗ | return set_number(obj, name, val.num, val.den, 1, search_flags, AV_OPT_TYPE_VIDEO_RATE); | |
| 1013 | } | ||
| 1014 | |||
| 1015 | 3 | static int set_format(void *obj, const char *name, int fmt, int search_flags, | |
| 1016 | enum AVOptionType type, const char *desc, int nb_fmts) | ||
| 1017 | { | ||
| 1018 | const AVOption *o; | ||
| 1019 | void *logctx; | ||
| 1020 | int *dst; | ||
| 1021 | int min, max, ret; | ||
| 1022 | |||
| 1023 | 3 | ret = opt_set_init(obj, name, search_flags, type, NULL, &o, (void**)&dst); | |
| 1024 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (ret < 0) |
| 1025 | ✗ | return ret; | |
| 1026 | |||
| 1027 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | logctx = dst ? obj : NULL; |
| 1028 | |||
| 1029 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | min = FFMAX(o->min, -1); |
| 1030 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | max = FFMIN(o->max, nb_fmts-1); |
| 1031 | |||
| 1032 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (fmt < min || fmt > max) { |
| 1033 | ✗ | av_log(logctx, AV_LOG_ERROR, | |
| 1034 | "Value %d for parameter '%s' out of %s format range [%d - %d]\n", | ||
| 1035 | fmt, name, desc, min, max); | ||
| 1036 | ✗ | return AVERROR(ERANGE); | |
| 1037 | } | ||
| 1038 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (dst) |
| 1039 | 3 | *dst = fmt; | |
| 1040 | 3 | return 0; | |
| 1041 | } | ||
| 1042 | |||
| 1043 | ✗ | int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags) | |
| 1044 | { | ||
| 1045 | ✗ | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB); | |
| 1046 | } | ||
| 1047 | |||
| 1048 | 3 | int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags) | |
| 1049 | { | ||
| 1050 | 3 | return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB); | |
| 1051 | } | ||
| 1052 | |||
| 1053 | ✗ | int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, | |
| 1054 | int search_flags) | ||
| 1055 | { | ||
| 1056 | AVDictionary **dst; | ||
| 1057 | int ret; | ||
| 1058 | |||
| 1059 | ✗ | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_DICT, NULL, NULL, | |
| 1060 | (void**)&dst); | ||
| 1061 | ✗ | if (ret < 0) | |
| 1062 | ✗ | return ret; | |
| 1063 | |||
| 1064 | ✗ | if (dst) { | |
| 1065 | ✗ | av_dict_free(dst); | |
| 1066 | |||
| 1067 | ✗ | ret = av_dict_copy(dst, val, 0); | |
| 1068 | } | ||
| 1069 | |||
| 1070 | ✗ | return ret; | |
| 1071 | } | ||
| 1072 | |||
| 1073 | 3496 | int av_opt_set_chlayout(void *obj, const char *name, | |
| 1074 | const AVChannelLayout *channel_layout, | ||
| 1075 | int search_flags) | ||
| 1076 | { | ||
| 1077 | AVChannelLayout *dst; | ||
| 1078 | int ret; | ||
| 1079 | |||
| 1080 | 3496 | ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_CHLAYOUT, NULL, NULL, | |
| 1081 | (void**)&dst); | ||
| 1082 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3496 times.
|
3496 | if (ret < 0) |
| 1083 | ✗ | return ret; | |
| 1084 | |||
| 1085 |
1/2✓ Branch 0 taken 3496 times.
✗ Branch 1 not taken.
|
3496 | if (dst) |
| 1086 | 3496 | ret = av_channel_layout_copy(dst, channel_layout); | |
| 1087 | |||
| 1088 | 3496 | return ret; | |
| 1089 | } | ||
| 1090 | |||
| 1091 | 5 | static void format_duration(char *buf, size_t size, int64_t d) | |
| 1092 | { | ||
| 1093 | char *e; | ||
| 1094 | |||
| 1095 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | av_assert0(size >= 25); |
| 1096 |
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) { |
| 1097 | ✗ | *(buf++) = '-'; | |
| 1098 | ✗ | size--; | |
| 1099 | ✗ | d = -d; | |
| 1100 | } | ||
| 1101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (d == INT64_MAX) |
| 1102 | ✗ | snprintf(buf, size, "INT64_MAX"); | |
| 1103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d == INT64_MIN) |
| 1104 | ✗ | snprintf(buf, size, "INT64_MIN"); | |
| 1105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > (int64_t)3600*1000000) |
| 1106 | ✗ | snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000, | |
| 1107 | ✗ | (int)((d / 60000000) % 60), | |
| 1108 | ✗ | (int)((d / 1000000) % 60), | |
| 1109 | ✗ | (int)(d % 1000000)); | |
| 1110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | else if (d > 60*1000000) |
| 1111 | ✗ | snprintf(buf, size, "%d:%02d.%06d", | |
| 1112 | ✗ | (int)(d / 60000000), | |
| 1113 | ✗ | (int)((d / 1000000) % 60), | |
| 1114 | ✗ | (int)(d % 1000000)); | |
| 1115 | else | ||
| 1116 | 5 | snprintf(buf, size, "%d.%06d", | |
| 1117 | 5 | (int)(d / 1000000), | |
| 1118 | 5 | (int)(d % 1000000)); | |
| 1119 | 5 | e = buf + strlen(buf); | |
| 1120 |
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') |
| 1121 | 15 | *(--e) = 0; | |
| 1122 |
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] == '.') |
| 1123 | ✗ | *(--e) = 0; | |
| 1124 | 5 | } | |
| 1125 | |||
| 1126 | 7157 | static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, | |
| 1127 | const void *dst, int search_flags) | ||
| 1128 | { | ||
| 1129 | int ret; | ||
| 1130 | |||
| 1131 |
17/20✓ Branch 0 taken 69 times.
✓ Branch 1 taken 6708 times.
✓ Branch 2 taken 134 times.
✓ Branch 3 taken 23 times.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 57 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 45 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 10 times.
✓ Branch 18 taken 24 times.
✗ Branch 19 not taken.
|
7157 | switch (TYPE_BASE(o->type)) { |
| 1132 | 69 | case AV_OPT_TYPE_BOOL: | |
| 1133 | 69 | ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst)); | |
| 1134 | 69 | break; | |
| 1135 | 6708 | case AV_OPT_TYPE_FLAGS: | |
| 1136 | 6708 | ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst); | |
| 1137 | 6708 | break; | |
| 1138 | 134 | case AV_OPT_TYPE_INT: | |
| 1139 | 134 | ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst); | |
| 1140 | 134 | break; | |
| 1141 | 23 | case AV_OPT_TYPE_UINT: | |
| 1142 | 23 | ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst); | |
| 1143 | 23 | break; | |
| 1144 | 24 | case AV_OPT_TYPE_INT64: | |
| 1145 | 24 | ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst); | |
| 1146 | 24 | break; | |
| 1147 | ✗ | case AV_OPT_TYPE_UINT64: | |
| 1148 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst); | |
| 1149 | ✗ | break; | |
| 1150 | 57 | case AV_OPT_TYPE_FLOAT: | |
| 1151 | 57 | ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst); | |
| 1152 | 57 | break; | |
| 1153 | 5 | case AV_OPT_TYPE_DOUBLE: | |
| 1154 | 5 | ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst); | |
| 1155 | 5 | break; | |
| 1156 | 45 | case AV_OPT_TYPE_VIDEO_RATE: | |
| 1157 | case AV_OPT_TYPE_RATIONAL: | ||
| 1158 | 45 | ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den); | |
| 1159 | 45 | break; | |
| 1160 | ✗ | case AV_OPT_TYPE_CONST: | |
| 1161 | ✗ | ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64); | |
| 1162 | ✗ | break; | |
| 1163 | 26 | case AV_OPT_TYPE_STRING: | |
| 1164 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (*(uint8_t **)dst) { |
| 1165 | 26 | *pbuf = av_strdup(*(uint8_t **)dst); | |
| 1166 | ✗ | } else if (search_flags & AV_OPT_ALLOW_NULL) { | |
| 1167 | ✗ | *pbuf = NULL; | |
| 1168 | ✗ | return 0; | |
| 1169 | } else { | ||
| 1170 | ✗ | *pbuf = av_strdup(""); | |
| 1171 | } | ||
| 1172 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | return *pbuf ? 0 : AVERROR(ENOMEM); |
| 1173 | 12 | case AV_OPT_TYPE_BINARY: { | |
| 1174 | const uint8_t *bin; | ||
| 1175 | int len; | ||
| 1176 | |||
| 1177 |
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)) { |
| 1178 | ✗ | *pbuf = NULL; | |
| 1179 | ✗ | return 0; | |
| 1180 | } | ||
| 1181 | 12 | len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *)); | |
| 1182 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if ((uint64_t)len * 2 + 1 > INT_MAX) |
| 1183 | ✗ | return AVERROR(EINVAL); | |
| 1184 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if (!(*pbuf = av_malloc(len * 2 + 1))) |
| 1185 | ✗ | return AVERROR(ENOMEM); | |
| 1186 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
|
12 | if (!len) { |
| 1187 | 8 | *pbuf[0] = '\0'; | |
| 1188 | 8 | return 0; | |
| 1189 | } | ||
| 1190 | 4 | bin = *(uint8_t **)dst; | |
| 1191 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (int i = 0; i < len; i++) |
| 1192 | 16 | snprintf(*pbuf + i * 2, 3, "%02X", bin[i]); | |
| 1193 | 4 | return 0; | |
| 1194 | } | ||
| 1195 | 4 | case AV_OPT_TYPE_IMAGE_SIZE: | |
| 1196 | 4 | ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]); | |
| 1197 | 4 | break; | |
| 1198 | 4 | case AV_OPT_TYPE_PIXEL_FMT: | |
| 1199 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none")); | |
| 1200 | 4 | break; | |
| 1201 | 4 | case AV_OPT_TYPE_SAMPLE_FMT: | |
| 1202 | 4 | ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none")); | |
| 1203 | 4 | break; | |
| 1204 | 4 | case AV_OPT_TYPE_DURATION: { | |
| 1205 | 4 | int64_t i64 = *(int64_t *)dst; | |
| 1206 | 4 | format_duration(*pbuf, buf_len, i64); | |
| 1207 | 4 | ret = strlen(*pbuf); // no overflow possible, checked by an assert | |
| 1208 | 4 | break; | |
| 1209 | } | ||
| 1210 | 4 | case AV_OPT_TYPE_COLOR: | |
| 1211 | 4 | ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x", | |
| 1212 | 4 | (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1], | |
| 1213 | 4 | (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]); | |
| 1214 | 4 | break; | |
| 1215 | 10 | case AV_OPT_TYPE_CHLAYOUT: | |
| 1216 | 10 | ret = av_channel_layout_describe(dst, *pbuf, buf_len); | |
| 1217 | 10 | break; | |
| 1218 | 24 | case AV_OPT_TYPE_DICT: | |
| 1219 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
24 | if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) { |
| 1220 | ✗ | *pbuf = NULL; | |
| 1221 | ✗ | return 0; | |
| 1222 | } | ||
| 1223 | 24 | return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':'); | |
| 1224 | ✗ | default: | |
| 1225 | ✗ | return AVERROR(EINVAL); | |
| 1226 | } | ||
| 1227 | |||
| 1228 | 7095 | return ret; | |
| 1229 | } | ||
| 1230 | |||
| 1231 | 88 | static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val) | |
| 1232 | { | ||
| 1233 | 88 | const unsigned count = *opt_array_pcount(dst); | |
| 1234 | 88 | const uint8_t sep = opt_array_sep(o); | |
| 1235 | |||
| 1236 | 88 | uint8_t *str = NULL; | |
| 1237 | 88 | size_t str_len = 0; | |
| 1238 | int ret; | ||
| 1239 | |||
| 1240 | 88 | *out_val = NULL; | |
| 1241 | |||
| 1242 |
2/2✓ Branch 0 taken 62 times.
✓ Branch 1 taken 88 times.
|
150 | for (unsigned i = 0; i < count; i++) { |
| 1243 | 62 | uint8_t buf[128], *out = buf; | |
| 1244 | size_t out_len; | ||
| 1245 | |||
| 1246 | 62 | ret = opt_get_elem(o, &out, sizeof(buf), | |
| 1247 | 62 | opt_array_pelem(o, *(void **)dst, i), 0); | |
| 1248 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (ret < 0) |
| 1249 | ✗ | goto fail; | |
| 1250 | |||
| 1251 | 62 | out_len = strlen(out); | |
| 1252 |
3/4✓ Branch 0 taken 48 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 62 times.
✗ Branch 3 not taken.
|
62 | if (out_len > SIZE_MAX / 2 - !!i || |
| 1253 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | !!i + out_len * 2 > SIZE_MAX - str_len - 1) { |
| 1254 | ✗ | ret = AVERROR(ERANGE); | |
| 1255 | ✗ | goto fail; | |
| 1256 | } | ||
| 1257 | |||
| 1258 | // terminator escaping separator | ||
| 1259 | // ↓ ↓ ↓ | ||
| 1260 | 62 | ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i); | |
| 1261 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (ret < 0) |
| 1262 | ✗ | goto fail; | |
| 1263 | |||
| 1264 | // add separator if needed | ||
| 1265 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 14 times.
|
62 | if (i) |
| 1266 | 48 | str[str_len++] = sep; | |
| 1267 | |||
| 1268 | // escape the element | ||
| 1269 |
2/2✓ Branch 0 taken 514 times.
✓ Branch 1 taken 62 times.
|
576 | for (unsigned j = 0; j < out_len; j++) { |
| 1270 | 514 | uint8_t val = out[j]; | |
| 1271 |
4/4✓ Branch 0 taken 502 times.
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 30 times.
✓ Branch 3 taken 472 times.
|
514 | if (val == sep || val == '\\') |
| 1272 | 42 | str[str_len++] = '\\'; | |
| 1273 | 514 | str[str_len++] = val; | |
| 1274 | } | ||
| 1275 | 62 | str[str_len] = 0; | |
| 1276 | |||
| 1277 | 62 | fail: | |
| 1278 |
2/2✓ Branch 0 taken 30 times.
✓ Branch 1 taken 32 times.
|
62 | if (out != buf) |
| 1279 | 30 | av_freep(&out); | |
| 1280 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (ret < 0) { |
| 1281 | ✗ | av_freep(&str); | |
| 1282 | ✗ | return ret; | |
| 1283 | } | ||
| 1284 | } | ||
| 1285 | |||
| 1286 | 88 | *out_val = str; | |
| 1287 | |||
| 1288 | 88 | return 0; | |
| 1289 | } | ||
| 1290 | |||
| 1291 | 11994 | int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) | |
| 1292 | { | ||
| 1293 | void *dst, *target_obj; | ||
| 1294 | 11994 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1295 | uint8_t *out, buf[128]; | ||
| 1296 | int ret; | ||
| 1297 | |||
| 1298 |
4/8✓ Branch 0 taken 7166 times.
✓ Branch 1 taken 4828 times.
✓ Branch 2 taken 7166 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7166 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
11994 | if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) |
| 1299 | 4828 | return AVERROR_OPTION_NOT_FOUND; | |
| 1300 | |||
| 1301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7166 times.
|
7166 | if (o->flags & AV_OPT_FLAG_DEPRECATED) |
| 1302 | ✗ | av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help); | |
| 1303 | |||
| 1304 | 7166 | dst = (uint8_t *)target_obj + o->offset; | |
| 1305 | |||
| 1306 |
2/2✓ Branch 0 taken 76 times.
✓ Branch 1 taken 7090 times.
|
7166 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) { |
| 1307 | 76 | ret = opt_get_array(o, dst, out_val); | |
| 1308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
|
76 | if (ret < 0) |
| 1309 | ✗ | return ret; | |
| 1310 |
4/4✓ Branch 0 taken 67 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 1 times.
|
76 | if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) { |
| 1311 | 66 | *out_val = av_strdup(""); | |
| 1312 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (!*out_val) |
| 1313 | ✗ | return AVERROR(ENOMEM); | |
| 1314 | } | ||
| 1315 | 76 | return 0; | |
| 1316 | } | ||
| 1317 | |||
| 1318 | 7090 | buf[0] = 0; | |
| 1319 | 7090 | out = buf; | |
| 1320 | 7090 | ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags); | |
| 1321 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7090 times.
|
7090 | if (ret < 0) |
| 1322 | ✗ | return ret; | |
| 1323 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 7058 times.
|
7090 | if (out != buf) { |
| 1324 | 32 | *out_val = out; | |
| 1325 | 32 | return 0; | |
| 1326 | } | ||
| 1327 | |||
| 1328 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7058 times.
|
7058 | if (ret >= sizeof(buf)) |
| 1329 | ✗ | return AVERROR(EINVAL); | |
| 1330 | 7058 | *out_val = av_strdup(out); | |
| 1331 |
1/2✓ Branch 0 taken 7058 times.
✗ Branch 1 not taken.
|
7058 | return *out_val ? 0 : AVERROR(ENOMEM); |
| 1332 | } | ||
| 1333 | |||
| 1334 | 24867 | static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, | |
| 1335 | int search_flags) | ||
| 1336 | { | ||
| 1337 | void *dst, *target_obj; | ||
| 1338 | 24867 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1339 |
3/4✓ Branch 0 taken 24853 times.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24853 times.
|
24867 | if (!o || !target_obj) |
| 1340 | 14 | return AVERROR_OPTION_NOT_FOUND; | |
| 1341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24853 times.
|
24853 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
| 1342 | ✗ | return AVERROR(EINVAL); | |
| 1343 | |||
| 1344 | 24853 | dst = ((uint8_t *)target_obj) + o->offset; | |
| 1345 | |||
| 1346 | 24853 | return read_number(o, dst, num, den, intnum); | |
| 1347 | } | ||
| 1348 | |||
| 1349 | 24867 | int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val) | |
| 1350 | { | ||
| 1351 | 24867 | int64_t intnum = 1; | |
| 1352 | 24867 | double num = 1; | |
| 1353 | 24867 | int ret, den = 1; | |
| 1354 | |||
| 1355 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 24853 times.
|
24867 | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) |
| 1356 | 14 | return ret; | |
| 1357 |
1/2✓ Branch 0 taken 24853 times.
✗ Branch 1 not taken.
|
24853 | if (num == den) |
| 1358 | 24853 | *out_val = intnum; | |
| 1359 | else | ||
| 1360 | ✗ | *out_val = num * intnum / den; | |
| 1361 | 24853 | return 0; | |
| 1362 | } | ||
| 1363 | |||
| 1364 | ✗ | int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val) | |
| 1365 | { | ||
| 1366 | ✗ | int64_t intnum = 1; | |
| 1367 | ✗ | double num = 1; | |
| 1368 | ✗ | int ret, den = 1; | |
| 1369 | |||
| 1370 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
| 1371 | ✗ | return ret; | |
| 1372 | ✗ | *out_val = num * intnum / den; | |
| 1373 | ✗ | return 0; | |
| 1374 | } | ||
| 1375 | |||
| 1376 | ✗ | int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val) | |
| 1377 | { | ||
| 1378 | ✗ | int64_t intnum = 1; | |
| 1379 | ✗ | double num = 1; | |
| 1380 | ✗ | int ret, den = 1; | |
| 1381 | |||
| 1382 | ✗ | if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0) | |
| 1383 | ✗ | return ret; | |
| 1384 | |||
| 1385 | ✗ | if (num == 1.0 && (int)intnum == intnum) | |
| 1386 | ✗ | *out_val = (AVRational){intnum, den}; | |
| 1387 | else | ||
| 1388 | ✗ | *out_val = double_to_rational(num*intnum/den); | |
| 1389 | ✗ | return 0; | |
| 1390 | } | ||
| 1391 | |||
| 1392 | ✗ | int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out) | |
| 1393 | { | ||
| 1394 | void *dst, *target_obj; | ||
| 1395 | ✗ | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1396 | ✗ | if (!o || !target_obj) | |
| 1397 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
| 1398 | ✗ | if (o->type != AV_OPT_TYPE_IMAGE_SIZE) { | |
| 1399 | ✗ | av_log(obj, AV_LOG_ERROR, | |
| 1400 | "The value for option '%s' is not a image size.\n", name); | ||
| 1401 | ✗ | return AVERROR(EINVAL); | |
| 1402 | } | ||
| 1403 | |||
| 1404 | ✗ | dst = ((uint8_t*)target_obj) + o->offset; | |
| 1405 | ✗ | if (w_out) *w_out = *(int *)dst; | |
| 1406 | ✗ | if (h_out) *h_out = *((int *)dst+1); | |
| 1407 | ✗ | return 0; | |
| 1408 | } | ||
| 1409 | |||
| 1410 | ✗ | int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val) | |
| 1411 | { | ||
| 1412 | ✗ | return av_opt_get_q(obj, name, search_flags, out_val); | |
| 1413 | } | ||
| 1414 | |||
| 1415 | 3136 | static int get_format(void *obj, const char *name, int search_flags, void *out_fmt, | |
| 1416 | enum AVOptionType type, const char *desc) | ||
| 1417 | { | ||
| 1418 | void *dst, *target_obj; | ||
| 1419 | 3136 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1420 |
2/4✓ Branch 0 taken 3136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3136 times.
|
3136 | if (!o || !target_obj) |
| 1421 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
| 1422 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3136 times.
|
3136 | if (o->type != type) { |
| 1423 | ✗ | av_log(obj, AV_LOG_ERROR, | |
| 1424 | "The value for option '%s' is not a %s format.\n", desc, name); | ||
| 1425 | ✗ | return AVERROR(EINVAL); | |
| 1426 | } | ||
| 1427 | |||
| 1428 | 3136 | dst = ((uint8_t*)target_obj) + o->offset; | |
| 1429 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3136 times.
|
3136 | if (type == AV_OPT_TYPE_PIXEL_FMT) |
| 1430 | ✗ | *(enum AVPixelFormat *)out_fmt = *(enum AVPixelFormat *)dst; | |
| 1431 | else | ||
| 1432 | 3136 | *(enum AVSampleFormat*)out_fmt = *(enum AVSampleFormat*)dst; | |
| 1433 | |||
| 1434 | 3136 | return 0; | |
| 1435 | } | ||
| 1436 | |||
| 1437 | ✗ | int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt) | |
| 1438 | { | ||
| 1439 | ✗ | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel"); | |
| 1440 | } | ||
| 1441 | |||
| 1442 | 3136 | int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt) | |
| 1443 | { | ||
| 1444 | 3136 | return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample"); | |
| 1445 | } | ||
| 1446 | |||
| 1447 | 3136 | int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl) | |
| 1448 | { | ||
| 1449 | void *dst, *target_obj; | ||
| 1450 | 3136 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1451 |
2/4✓ Branch 0 taken 3136 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3136 times.
|
3136 | if (!o || !target_obj) |
| 1452 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
| 1453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3136 times.
|
3136 | if (o->type != AV_OPT_TYPE_CHLAYOUT) { |
| 1454 | ✗ | av_log(obj, AV_LOG_ERROR, | |
| 1455 | "The value for option '%s' is not a channel layout.\n", name); | ||
| 1456 | ✗ | return AVERROR(EINVAL); | |
| 1457 | } | ||
| 1458 | |||
| 1459 | 3136 | dst = ((uint8_t*)target_obj) + o->offset; | |
| 1460 | 3136 | return av_channel_layout_copy(cl, dst); | |
| 1461 | } | ||
| 1462 | |||
| 1463 | 8229 | int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val) | |
| 1464 | { | ||
| 1465 | void *target_obj; | ||
| 1466 | AVDictionary *src; | ||
| 1467 | 8229 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 1468 | |||
| 1469 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 8229 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
8229 | if (!o || !target_obj) |
| 1470 | 8229 | return AVERROR_OPTION_NOT_FOUND; | |
| 1471 | ✗ | if (o->type != AV_OPT_TYPE_DICT) | |
| 1472 | ✗ | return AVERROR(EINVAL); | |
| 1473 | |||
| 1474 | ✗ | src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset); | |
| 1475 | |||
| 1476 | ✗ | return av_dict_copy(out_val, src, 0); | |
| 1477 | } | ||
| 1478 | |||
| 1479 | ✗ | int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) | |
| 1480 | { | ||
| 1481 | ✗ | const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); | |
| 1482 | ✗ | const AVOption *flag = av_opt_find(obj, flag_name, | |
| 1483 | field ? field->unit : NULL, 0, 0); | ||
| 1484 | int64_t res; | ||
| 1485 | |||
| 1486 | ✗ | if (!field || !flag || flag->type != AV_OPT_TYPE_CONST || | |
| 1487 | ✗ | av_opt_get_int(obj, field_name, 0, &res) < 0) | |
| 1488 | ✗ | return 0; | |
| 1489 | ✗ | return res & flag->default_val.i64; | |
| 1490 | } | ||
| 1491 | |||
| 1492 | 4 | static void log_int_value(void *av_log_obj, int level, int64_t i) | |
| 1493 | { | ||
| 1494 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (i == INT_MAX) { |
| 1495 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
| 1496 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT_MIN) { |
| 1497 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
| 1498 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == UINT32_MAX) { |
| 1499 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
| 1500 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MAX) { |
| 1501 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
| 1502 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | } else if (i == INT64_MIN) { |
| 1503 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
| 1504 | } else { | ||
| 1505 | 4 | av_log(av_log_obj, level, "%"PRId64, i); | |
| 1506 | } | ||
| 1507 | 4 | } | |
| 1508 | |||
| 1509 | 16 | static void log_value(void *av_log_obj, int level, double d) | |
| 1510 | { | ||
| 1511 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | if (d == INT_MAX) { |
| 1512 | ✗ | av_log(av_log_obj, level, "INT_MAX"); | |
| 1513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT_MIN) { |
| 1514 | ✗ | av_log(av_log_obj, level, "INT_MIN"); | |
| 1515 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == UINT32_MAX) { |
| 1516 | ✗ | av_log(av_log_obj, level, "UINT32_MAX"); | |
| 1517 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == (double)INT64_MAX) { |
| 1518 | ✗ | av_log(av_log_obj, level, "I64_MAX"); | |
| 1519 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == INT64_MIN) { |
| 1520 | ✗ | av_log(av_log_obj, level, "I64_MIN"); | |
| 1521 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MAX) { |
| 1522 | ✗ | av_log(av_log_obj, level, "FLT_MAX"); | |
| 1523 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == FLT_MIN) { |
| 1524 | ✗ | av_log(av_log_obj, level, "FLT_MIN"); | |
| 1525 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MAX) { |
| 1526 | ✗ | av_log(av_log_obj, level, "-FLT_MAX"); | |
| 1527 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -FLT_MIN) { |
| 1528 | ✗ | av_log(av_log_obj, level, "-FLT_MIN"); | |
| 1529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MAX) { |
| 1530 | ✗ | av_log(av_log_obj, level, "DBL_MAX"); | |
| 1531 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == DBL_MIN) { |
| 1532 | ✗ | av_log(av_log_obj, level, "DBL_MIN"); | |
| 1533 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MAX) { |
| 1534 | ✗ | av_log(av_log_obj, level, "-DBL_MAX"); | |
| 1535 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 | } else if (d == -DBL_MIN) { |
| 1536 | ✗ | av_log(av_log_obj, level, "-DBL_MIN"); | |
| 1537 | } else { | ||
| 1538 | 16 | av_log(av_log_obj, level, "%g", d); | |
| 1539 | } | ||
| 1540 | 16 | } | |
| 1541 | |||
| 1542 | 4 | static const char *get_opt_const_name(void *obj, const char *unit, int64_t value) | |
| 1543 | { | ||
| 1544 | 4 | const AVOption *opt = NULL; | |
| 1545 | |||
| 1546 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (!unit) |
| 1547 | 4 | return NULL; | |
| 1548 | ✗ | while ((opt = av_opt_next(obj, opt))) | |
| 1549 | ✗ | if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) && | |
| 1550 | ✗ | opt->default_val.i64 == value) | |
| 1551 | ✗ | return opt->name; | |
| 1552 | ✗ | return NULL; | |
| 1553 | } | ||
| 1554 | |||
| 1555 | 1 | static char *get_opt_flags_string(void *obj, const char *unit, int64_t value) | |
| 1556 | { | ||
| 1557 | 1 | const AVOption *opt = NULL; | |
| 1558 | char flags[512]; | ||
| 1559 | |||
| 1560 | 1 | flags[0] = 0; | |
| 1561 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!unit) |
| 1562 | ✗ | return NULL; | |
| 1563 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 2 taken 1 times.
|
32 | while ((opt = av_opt_next(obj, opt))) { |
| 1564 |
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) && |
| 1565 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | opt->default_val.i64 & value) { |
| 1566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (flags[0]) |
| 1567 | ✗ | av_strlcatf(flags, sizeof(flags), "+"); | |
| 1568 | 1 | av_strlcatf(flags, sizeof(flags), "%s", opt->name); | |
| 1569 | } | ||
| 1570 | } | ||
| 1571 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (flags[0]) |
| 1572 | 1 | return av_strdup(flags); | |
| 1573 | ✗ | return NULL; | |
| 1574 | } | ||
| 1575 | |||
| 1576 | 31 | static void log_type(void *av_log_obj, const AVOption *o, | |
| 1577 | enum AVOptionType parent_type) | ||
| 1578 | { | ||
| 1579 | 31 | const enum AVOptionType type = TYPE_BASE(o->type); | |
| 1580 | |||
| 1581 |
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 | if (o->type == AV_OPT_TYPE_CONST && (TYPE_BASE(parent_type) == AV_OPT_TYPE_INT || TYPE_BASE(parent_type) == AV_OPT_TYPE_INT64)) |
| 1582 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64); | |
| 1583 |
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) { |
| 1584 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 25 times.
|
28 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
| 1585 | 3 | av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", opt_type_desc[type].name); | |
| 1586 | else | ||
| 1587 | 25 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", opt_type_desc[type].name); | |
| 1588 | } | ||
| 1589 | else | ||
| 1590 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%-12s ", ""); | |
| 1591 | 31 | } | |
| 1592 | |||
| 1593 | 31 | static void log_default(void *obj, void *av_log_obj, const AVOption *opt) | |
| 1594 | { | ||
| 1595 |
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) |
| 1596 | 6 | return; | |
| 1597 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
|
25 | if ((opt->type == AV_OPT_TYPE_COLOR || |
| 1598 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
|
24 | opt->type == AV_OPT_TYPE_IMAGE_SIZE || |
| 1599 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 2 times.
|
23 | opt->type == AV_OPT_TYPE_STRING || |
| 1600 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 2 times.
|
21 | opt->type == AV_OPT_TYPE_DICT || |
| 1601 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
|
19 | opt->type == AV_OPT_TYPE_CHLAYOUT || |
| 1602 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 17 times.
|
18 | opt->type == AV_OPT_TYPE_VIDEO_RATE) && |
| 1603 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | !opt->default_val.str) |
| 1604 | 1 | return; | |
| 1605 | |||
| 1606 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 21 times.
|
24 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
| 1607 | 3 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
| 1608 |
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) |
| 1609 | 2 | av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def); | |
| 1610 | 3 | return; | |
| 1611 | } | ||
| 1612 | |||
| 1613 | 21 | av_log(av_log_obj, AV_LOG_INFO, " (default "); | |
| 1614 |
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) { |
| 1615 | 3 | case AV_OPT_TYPE_BOOL: | |
| 1616 | 3 | av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64)); | |
| 1617 | 3 | break; | |
| 1618 | 1 | case AV_OPT_TYPE_FLAGS: { | |
| 1619 | 1 | char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64); | |
| 1620 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (def_flags) { |
| 1621 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags); | |
| 1622 | 1 | av_freep(&def_flags); | |
| 1623 | } else { | ||
| 1624 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64); | |
| 1625 | } | ||
| 1626 | 1 | break; | |
| 1627 | } | ||
| 1628 | 1 | case AV_OPT_TYPE_DURATION: { | |
| 1629 | char buf[25]; | ||
| 1630 | 1 | format_duration(buf, sizeof(buf), opt->default_val.i64); | |
| 1631 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s", buf); | |
| 1632 | 1 | break; | |
| 1633 | } | ||
| 1634 | 4 | case AV_OPT_TYPE_UINT: | |
| 1635 | case AV_OPT_TYPE_INT: | ||
| 1636 | case AV_OPT_TYPE_UINT64: | ||
| 1637 | case AV_OPT_TYPE_INT64: { | ||
| 1638 | 4 | const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64); | |
| 1639 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (def_const) |
| 1640 | ✗ | av_log(av_log_obj, AV_LOG_INFO, "%s", def_const); | |
| 1641 | else | ||
| 1642 | 4 | log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64); | |
| 1643 | 4 | break; | |
| 1644 | } | ||
| 1645 | 2 | case AV_OPT_TYPE_DOUBLE: | |
| 1646 | case AV_OPT_TYPE_FLOAT: | ||
| 1647 | 2 | log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl); | |
| 1648 | 2 | break; | |
| 1649 | 1 | case AV_OPT_TYPE_RATIONAL: { | |
| 1650 | 1 | AVRational q = av_d2q(opt->default_val.dbl, INT_MAX); | |
| 1651 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); } | |
| 1652 | 1 | break; | |
| 1653 | 1 | case AV_OPT_TYPE_PIXEL_FMT: | |
| 1654 | 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")); | |
| 1655 | 1 | break; | |
| 1656 | 1 | case AV_OPT_TYPE_SAMPLE_FMT: | |
| 1657 | 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")); | |
| 1658 | 1 | break; | |
| 1659 | 7 | case AV_OPT_TYPE_COLOR: | |
| 1660 | case AV_OPT_TYPE_IMAGE_SIZE: | ||
| 1661 | case AV_OPT_TYPE_STRING: | ||
| 1662 | case AV_OPT_TYPE_DICT: | ||
| 1663 | case AV_OPT_TYPE_VIDEO_RATE: | ||
| 1664 | case AV_OPT_TYPE_CHLAYOUT: | ||
| 1665 | 7 | av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str); | |
| 1666 | 7 | break; | |
| 1667 | } | ||
| 1668 | 21 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
| 1669 | } | ||
| 1670 | |||
| 1671 | 2 | static void opt_list(void *obj, void *av_log_obj, const char *unit, | |
| 1672 | int req_flags, int rej_flags, enum AVOptionType parent_type) | ||
| 1673 | { | ||
| 1674 | 2 | const AVOption *opt = NULL; | |
| 1675 | AVOptionRanges *r; | ||
| 1676 | int i; | ||
| 1677 | |||
| 1678 |
2/2✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
|
64 | while ((opt = av_opt_next(obj, opt))) { |
| 1679 |
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)) |
| 1680 | ✗ | continue; | |
| 1681 | |||
| 1682 | /* Don't print CONST's on level one. | ||
| 1683 | * Don't print anything but CONST's on level two. | ||
| 1684 | * Only print items from the requested unit. | ||
| 1685 | */ | ||
| 1686 |
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) |
| 1687 | 3 | continue; | |
| 1688 |
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) |
| 1689 | 28 | continue; | |
| 1690 |
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)) |
| 1691 | ✗ | continue; | |
| 1692 |
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) |
| 1693 | 3 | av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); | |
| 1694 | else | ||
| 1695 | 28 | av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ", | |
| 1696 | 28 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-", | |
| 1697 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | opt->name); |
| 1698 | |||
| 1699 | 31 | log_type(av_log_obj, opt, parent_type); | |
| 1700 | |||
| 1701 | 341 | av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c", | |
| 1702 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
|
31 | (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.', |
| 1703 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.', |
| 1704 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.', |
| 1705 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.', |
| 1706 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.', |
| 1707 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.', |
| 1708 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.', |
| 1709 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.', |
| 1710 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.', |
| 1711 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 28 times.
|
31 | (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.', |
| 1712 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
|
31 | (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.'); |
| 1713 | |||
| 1714 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (opt->help) |
| 1715 | 31 | av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); | |
| 1716 | |||
| 1717 |
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) { |
| 1718 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 11 times.
|
18 | switch (opt->type) { |
| 1719 | 7 | case AV_OPT_TYPE_INT: | |
| 1720 | case AV_OPT_TYPE_UINT: | ||
| 1721 | case AV_OPT_TYPE_INT64: | ||
| 1722 | case AV_OPT_TYPE_UINT64: | ||
| 1723 | case AV_OPT_TYPE_DOUBLE: | ||
| 1724 | case AV_OPT_TYPE_FLOAT: | ||
| 1725 | case AV_OPT_TYPE_RATIONAL: | ||
| 1726 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 7 times.
|
14 | for (i = 0; i < r->nb_ranges; i++) { |
| 1727 | 7 | av_log(av_log_obj, AV_LOG_INFO, " (from "); | |
| 1728 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min); | |
| 1729 | 7 | av_log(av_log_obj, AV_LOG_INFO, " to "); | |
| 1730 | 7 | log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max); | |
| 1731 | 7 | av_log(av_log_obj, AV_LOG_INFO, ")"); | |
| 1732 | } | ||
| 1733 | 7 | break; | |
| 1734 | } | ||
| 1735 | 18 | av_opt_freep_ranges(&r); | |
| 1736 | } | ||
| 1737 | |||
| 1738 | 31 | log_default(obj, av_log_obj, opt); | |
| 1739 | |||
| 1740 | 31 | av_log(av_log_obj, AV_LOG_INFO, "\n"); | |
| 1741 |
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) |
| 1742 | 1 | opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type); | |
| 1743 | } | ||
| 1744 | 2 | } | |
| 1745 | |||
| 1746 | 1 | int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags) | |
| 1747 | { | ||
| 1748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!obj) |
| 1749 | ✗ | return -1; | |
| 1750 | |||
| 1751 | 1 | av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name); | |
| 1752 | |||
| 1753 | 1 | opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1); | |
| 1754 | |||
| 1755 | 1 | return 0; | |
| 1756 | } | ||
| 1757 | |||
| 1758 | 457894 | void av_opt_set_defaults(void *s) | |
| 1759 | { | ||
| 1760 | 457894 | av_opt_set_defaults2(s, 0, 0); | |
| 1761 | 457894 | } | |
| 1762 | |||
| 1763 | 525163 | void av_opt_set_defaults2(void *s, int mask, int flags) | |
| 1764 | { | ||
| 1765 | 525163 | const AVOption *opt = NULL; | |
| 1766 |
2/2✓ Branch 1 taken 35689349 times.
✓ Branch 2 taken 525163 times.
|
36214512 | while ((opt = av_opt_next(s, opt))) { |
| 1767 | 35689349 | void *dst = ((uint8_t*)s) + opt->offset; | |
| 1768 | |||
| 1769 |
2/2✓ Branch 0 taken 3489812 times.
✓ Branch 1 taken 32199537 times.
|
35689349 | if ((opt->flags & mask) != flags) |
| 1770 | 3489812 | continue; | |
| 1771 | |||
| 1772 |
2/2✓ Branch 0 taken 3516 times.
✓ Branch 1 taken 32196021 times.
|
32199537 | if (opt->flags & AV_OPT_FLAG_READONLY) |
| 1773 | 3516 | continue; | |
| 1774 | |||
| 1775 |
2/2✓ Branch 0 taken 113956 times.
✓ Branch 1 taken 32082065 times.
|
32196021 | if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) { |
| 1776 | 113956 | const AVOptionArrayDef *arr = opt->default_val.arr; | |
| 1777 | 113956 | const char sep = opt_array_sep(opt); | |
| 1778 | |||
| 1779 |
11/16✓ Branch 0 taken 113956 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 113956 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12650 times.
✓ Branch 5 taken 101306 times.
✓ Branch 6 taken 12650 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 12650 times.
✓ Branch 9 taken 101306 times.
✓ Branch 10 taken 12650 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 12650 times.
✓ Branch 13 taken 101306 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 12650 times.
|
113956 | av_assert0(sep && sep != '\\' && |
| 1780 | (sep < 'a' || sep > 'z') && | ||
| 1781 | (sep < 'A' || sep > 'Z') && | ||
| 1782 | (sep < '0' || sep > '9')); | ||
| 1783 | |||
| 1784 |
4/4✓ Branch 0 taken 12657 times.
✓ Branch 1 taken 101299 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 12643 times.
|
113956 | if (arr && arr->def) |
| 1785 | 14 | opt_set_array(s, s, opt, arr->def, dst); | |
| 1786 | |||
| 1787 | 113956 | continue; | |
| 1788 | } | ||
| 1789 | |||
| 1790 |
11/12✓ Branch 0 taken 21235288 times.
✓ Branch 1 taken 8938031 times.
✓ Branch 2 taken 1053082 times.
✓ Branch 3 taken 208631 times.
✓ Branch 4 taken 355 times.
✓ Branch 5 taken 503542 times.
✓ Branch 6 taken 51657 times.
✓ Branch 7 taken 9628 times.
✓ Branch 8 taken 20766 times.
✓ Branch 9 taken 60191 times.
✓ Branch 10 taken 894 times.
✗ Branch 11 not taken.
|
32082065 | switch (opt->type) { |
| 1791 | 21235288 | case AV_OPT_TYPE_CONST: | |
| 1792 | /* Nothing to be done here */ | ||
| 1793 | 21235288 | break; | |
| 1794 | 8938031 | case AV_OPT_TYPE_BOOL: | |
| 1795 | case AV_OPT_TYPE_FLAGS: | ||
| 1796 | case AV_OPT_TYPE_INT: | ||
| 1797 | case AV_OPT_TYPE_UINT: | ||
| 1798 | case AV_OPT_TYPE_INT64: | ||
| 1799 | case AV_OPT_TYPE_UINT64: | ||
| 1800 | case AV_OPT_TYPE_DURATION: | ||
| 1801 | case AV_OPT_TYPE_PIXEL_FMT: | ||
| 1802 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
| 1803 | 8938031 | write_number(s, opt, dst, 1, 1, opt->default_val.i64, 1); | |
| 1804 | 8938031 | break; | |
| 1805 | 1053082 | case AV_OPT_TYPE_DOUBLE: | |
| 1806 | case AV_OPT_TYPE_FLOAT: { | ||
| 1807 | double val; | ||
| 1808 | 1053082 | val = opt->default_val.dbl; | |
| 1809 | 1053082 | write_number(s, opt, dst, val, 1, 1, 1); | |
| 1810 | } | ||
| 1811 | 1053082 | break; | |
| 1812 | 208631 | case AV_OPT_TYPE_RATIONAL: { | |
| 1813 | AVRational val; | ||
| 1814 | 208631 | val = av_d2q(opt->default_val.dbl, INT_MAX); | |
| 1815 | 208631 | write_number(s, opt, dst, 1, val.den, val.num, 1); | |
| 1816 | } | ||
| 1817 | 208631 | break; | |
| 1818 | 355 | case AV_OPT_TYPE_COLOR: | |
| 1819 | 355 | set_string_color(s, opt, opt->default_val.str, dst); | |
| 1820 | 355 | break; | |
| 1821 | 503542 | case AV_OPT_TYPE_STRING: | |
| 1822 | 503542 | set_string(s, opt, opt->default_val.str, dst); | |
| 1823 | 503542 | break; | |
| 1824 | 51657 | case AV_OPT_TYPE_IMAGE_SIZE: | |
| 1825 | 51657 | set_string_image_size(s, opt, opt->default_val.str, dst); | |
| 1826 | 51657 | break; | |
| 1827 | 9628 | case AV_OPT_TYPE_VIDEO_RATE: | |
| 1828 | 9628 | set_string_video_rate(s, opt, opt->default_val.str, dst); | |
| 1829 | 9628 | break; | |
| 1830 | 20766 | case AV_OPT_TYPE_BINARY: | |
| 1831 | 20766 | set_string_binary(s, opt, opt->default_val.str, dst); | |
| 1832 | 20766 | break; | |
| 1833 | 60191 | case AV_OPT_TYPE_CHLAYOUT: | |
| 1834 | 60191 | set_string_channel_layout(s, opt, opt->default_val.str, dst); | |
| 1835 | 60191 | break; | |
| 1836 | 894 | case AV_OPT_TYPE_DICT: | |
| 1837 | 894 | set_string_dict(s, opt, opt->default_val.str, dst); | |
| 1838 | 894 | break; | |
| 1839 | ✗ | default: | |
| 1840 | ✗ | av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", | |
| 1841 | ✗ | opt->type, opt->name); | |
| 1842 | } | ||
| 1843 | } | ||
| 1844 | 525163 | } | |
| 1845 | |||
| 1846 | /** | ||
| 1847 | * Store the value in the field in ctx that is named like key. | ||
| 1848 | * ctx must be an AVClass context, storing is done using AVOptions. | ||
| 1849 | * | ||
| 1850 | * @param buf the string to parse, buf will be updated to point at the | ||
| 1851 | * separator just after the parsed key/value pair | ||
| 1852 | * @param key_val_sep a 0-terminated list of characters used to | ||
| 1853 | * separate key from value | ||
| 1854 | * @param pairs_sep a 0-terminated list of characters used to separate | ||
| 1855 | * two pairs from each other | ||
| 1856 | * @return 0 if the key/value pair has been successfully parsed and | ||
| 1857 | * set, or a negative value corresponding to an AVERROR code in case | ||
| 1858 | * of error: | ||
| 1859 | * AVERROR(EINVAL) if the key/value pair cannot be parsed, | ||
| 1860 | * the error code issued by av_opt_set() if the key/value pair | ||
| 1861 | * cannot be set | ||
| 1862 | */ | ||
| 1863 | 3273 | static int parse_key_value_pair(void *ctx, const char **buf, | |
| 1864 | const char *key_val_sep, const char *pairs_sep) | ||
| 1865 | { | ||
| 1866 | 3273 | char *key = av_get_token(buf, key_val_sep); | |
| 1867 | char *val; | ||
| 1868 | int ret; | ||
| 1869 | |||
| 1870 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3273 times.
|
3273 | if (!key) |
| 1871 | ✗ | return AVERROR(ENOMEM); | |
| 1872 | |||
| 1873 |
4/4✓ Branch 0 taken 3271 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3268 times.
✓ Branch 3 taken 3 times.
|
3273 | if (*key && strspn(*buf, key_val_sep)) { |
| 1874 | 3268 | (*buf)++; | |
| 1875 | 3268 | val = av_get_token(buf, pairs_sep); | |
| 1876 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3268 times.
|
3268 | if (!val) { |
| 1877 | ✗ | av_freep(&key); | |
| 1878 | ✗ | return AVERROR(ENOMEM); | |
| 1879 | } | ||
| 1880 | } else { | ||
| 1881 | 5 | av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key); | |
| 1882 | 5 | av_free(key); | |
| 1883 | 5 | return AVERROR(EINVAL); | |
| 1884 | } | ||
| 1885 | |||
| 1886 | 3268 | av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val); | |
| 1887 | |||
| 1888 | 3268 | ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN); | |
| 1889 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3263 times.
|
3268 | if (ret == AVERROR_OPTION_NOT_FOUND) |
| 1890 | 5 | av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key); | |
| 1891 | |||
| 1892 | 3268 | av_free(key); | |
| 1893 | 3268 | av_free(val); | |
| 1894 | 3268 | return ret; | |
| 1895 | } | ||
| 1896 | |||
| 1897 | 3240 | int av_set_options_string(void *ctx, const char *opts, | |
| 1898 | const char *key_val_sep, const char *pairs_sep) | ||
| 1899 | { | ||
| 1900 | 3240 | int ret, count = 0; | |
| 1901 | |||
| 1902 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3240 times.
|
3240 | if (!opts) |
| 1903 | ✗ | return 0; | |
| 1904 | |||
| 1905 |
2/2✓ Branch 0 taken 3273 times.
✓ Branch 1 taken 3201 times.
|
6474 | while (*opts) { |
| 1906 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 2 taken 3234 times.
|
3273 | if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0) |
| 1907 | 39 | return ret; | |
| 1908 | 3234 | count++; | |
| 1909 | |||
| 1910 |
2/2✓ Branch 0 taken 35 times.
✓ Branch 1 taken 3199 times.
|
3234 | if (*opts) |
| 1911 | 35 | opts++; | |
| 1912 | } | ||
| 1913 | |||
| 1914 | 3201 | return count; | |
| 1915 | } | ||
| 1916 | |||
| 1917 | #define WHITESPACES " \n\t\r" | ||
| 1918 | |||
| 1919 | 467301 | static int is_key_char(char c) | |
| 1920 | { | ||
| 1921 | 605251 | return (unsigned)((c | 32) - 'a') < 26 || | |
| 1922 |
4/4✓ Branch 0 taken 81363 times.
✓ Branch 1 taken 56587 times.
✓ Branch 2 taken 81282 times.
✓ Branch 3 taken 81 times.
|
137950 | (unsigned)(c - '0') < 10 || |
| 1923 |
8/8✓ Branch 0 taken 137950 times.
✓ Branch 1 taken 329351 times.
✓ Branch 2 taken 54132 times.
✓ Branch 3 taken 27150 times.
✓ Branch 4 taken 54030 times.
✓ Branch 5 taken 102 times.
✓ Branch 6 taken 82 times.
✓ Branch 7 taken 53948 times.
|
605251 | c == '-' || c == '_' || c == '/' || c == '.'; |
| 1924 | } | ||
| 1925 | |||
| 1926 | /** | ||
| 1927 | * Read a key from a string. | ||
| 1928 | * | ||
| 1929 | * The key consists of is_key_char characters and must be terminated by a | ||
| 1930 | * character from the delim string; spaces are ignored. | ||
| 1931 | * | ||
| 1932 | * @return 0 for success (even with ellipsis), <0 for failure | ||
| 1933 | */ | ||
| 1934 | 53948 | static int get_key(const char **ropts, const char *delim, char **rkey) | |
| 1935 | { | ||
| 1936 | 53948 | const char *opts = *ropts; | |
| 1937 | const char *key_start, *key_end; | ||
| 1938 | |||
| 1939 | 53948 | key_start = opts += strspn(opts, WHITESPACES); | |
| 1940 |
2/2✓ Branch 1 taken 413353 times.
✓ Branch 2 taken 53948 times.
|
467301 | while (is_key_char(*opts)) |
| 1941 | 413353 | opts++; | |
| 1942 | 53948 | key_end = opts; | |
| 1943 | 53948 | opts += strspn(opts, WHITESPACES); | |
| 1944 |
4/4✓ Branch 0 taken 39998 times.
✓ Branch 1 taken 13950 times.
✓ Branch 2 taken 7543 times.
✓ Branch 3 taken 32455 times.
|
53948 | if (!*opts || !strchr(delim, *opts)) |
| 1945 | 21493 | return AVERROR(EINVAL); | |
| 1946 | 32455 | opts++; | |
| 1947 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 32455 times.
|
32455 | if (!(*rkey = av_malloc(key_end - key_start + 1))) |
| 1948 | ✗ | return AVERROR(ENOMEM); | |
| 1949 | 32455 | memcpy(*rkey, key_start, key_end - key_start); | |
| 1950 | 32455 | (*rkey)[key_end - key_start] = 0; | |
| 1951 | 32455 | *ropts = opts; | |
| 1952 | 32455 | return 0; | |
| 1953 | } | ||
| 1954 | |||
| 1955 | 53948 | int av_opt_get_key_value(const char **ropts, | |
| 1956 | const char *key_val_sep, const char *pairs_sep, | ||
| 1957 | unsigned flags, | ||
| 1958 | char **rkey, char **rval) | ||
| 1959 | { | ||
| 1960 | int ret; | ||
| 1961 | 53948 | char *key = NULL, *val; | |
| 1962 | 53948 | const char *opts = *ropts; | |
| 1963 | |||
| 1964 |
2/2✓ Branch 1 taken 21493 times.
✓ Branch 2 taken 32455 times.
|
53948 | if ((ret = get_key(&opts, key_val_sep, &key)) < 0 && |
| 1965 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 21492 times.
|
21493 | !(flags & AV_OPT_FLAG_IMPLICIT_KEY)) |
| 1966 | 1 | return AVERROR(EINVAL); | |
| 1967 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 53947 times.
|
53947 | if (!(val = av_get_token(&opts, pairs_sep))) { |
| 1968 | ✗ | av_free(key); | |
| 1969 | ✗ | return AVERROR(ENOMEM); | |
| 1970 | } | ||
| 1971 | 53947 | *ropts = opts; | |
| 1972 | 53947 | *rkey = key; | |
| 1973 | 53947 | *rval = val; | |
| 1974 | 53947 | return 0; | |
| 1975 | } | ||
| 1976 | |||
| 1977 | 113 | int av_opt_set_from_string(void *ctx, const char *opts, | |
| 1978 | const char *const *shorthand, | ||
| 1979 | const char *key_val_sep, const char *pairs_sep) | ||
| 1980 | { | ||
| 1981 | 113 | int ret, count = 0; | |
| 1982 | 113 | const char *dummy_shorthand = NULL; | |
| 1983 | const char *key; | ||
| 1984 | |||
| 1985 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | if (!opts) |
| 1986 | ✗ | return 0; | |
| 1987 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 113 times.
|
113 | if (!shorthand) |
| 1988 | ✗ | shorthand = &dummy_shorthand; | |
| 1989 | |||
| 1990 |
2/2✓ Branch 0 taken 221 times.
✓ Branch 1 taken 109 times.
|
330 | while (*opts) { |
| 1991 | char *parsed_key, *value; | ||
| 1992 | 221 | ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep, | |
| 1993 | 221 | *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0, | |
| 1994 | &parsed_key, &value); | ||
| 1995 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 220 times.
|
221 | if (ret < 0) { |
| 1996 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (ret == AVERROR(EINVAL)) |
| 1997 | 1 | av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts); | |
| 1998 | else | ||
| 1999 | ✗ | av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts, | |
| 2000 | ✗ | av_err2str(ret)); | |
| 2001 | 4 | return ret; | |
| 2002 | } | ||
| 2003 |
2/2✓ Branch 0 taken 110 times.
✓ Branch 1 taken 110 times.
|
220 | if (*opts) |
| 2004 | 110 | opts++; | |
| 2005 |
2/2✓ Branch 0 taken 206 times.
✓ Branch 1 taken 14 times.
|
220 | if (parsed_key) { |
| 2006 | 206 | key = parsed_key; | |
| 2007 |
2/2✓ Branch 0 taken 104 times.
✓ Branch 1 taken 206 times.
|
310 | while (*shorthand) /* discard all remaining shorthand */ |
| 2008 | 104 | shorthand++; | |
| 2009 | } else { | ||
| 2010 | 14 | key = *(shorthand++); | |
| 2011 | } | ||
| 2012 | |||
| 2013 | 220 | av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value); | |
| 2014 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 217 times.
|
220 | if ((ret = av_opt_set(ctx, key, value, 0)) < 0) { |
| 2015 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (ret == AVERROR_OPTION_NOT_FOUND) |
| 2016 | 2 | av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key); | |
| 2017 | 3 | av_free(value); | |
| 2018 | 3 | av_free(parsed_key); | |
| 2019 | 3 | return ret; | |
| 2020 | } | ||
| 2021 | |||
| 2022 | 217 | av_free(value); | |
| 2023 | 217 | av_free(parsed_key); | |
| 2024 | 217 | count++; | |
| 2025 | } | ||
| 2026 | 109 | return count; | |
| 2027 | } | ||
| 2028 | |||
| 2029 | 700839 | void av_opt_free(void *obj) | |
| 2030 | { | ||
| 2031 | 700839 | const AVOption *o = NULL; | |
| 2032 |
2/2✓ Branch 1 taken 29381203 times.
✓ Branch 2 taken 700839 times.
|
30082042 | while ((o = av_opt_next(obj, o))) { |
| 2033 | 29381203 | void *pitem = (uint8_t *)obj + o->offset; | |
| 2034 | |||
| 2035 |
2/2✓ Branch 0 taken 115792 times.
✓ Branch 1 taken 29265411 times.
|
29381203 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) |
| 2036 | 115792 | opt_free_array(o, pitem, opt_array_pcount(pitem)); | |
| 2037 | else | ||
| 2038 | 29265411 | opt_free_elem(o->type, pitem); | |
| 2039 | } | ||
| 2040 | 700839 | } | |
| 2041 | |||
| 2042 | 301967 | int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags) | |
| 2043 | { | ||
| 2044 | 301967 | const AVDictionaryEntry *t = NULL; | |
| 2045 | 301967 | AVDictionary *tmp = NULL; | |
| 2046 | int ret; | ||
| 2047 | |||
| 2048 |
2/2✓ Branch 0 taken 72680 times.
✓ Branch 1 taken 229287 times.
|
301967 | if (!options) |
| 2049 | 72680 | return 0; | |
| 2050 | |||
| 2051 |
2/2✓ Branch 1 taken 203026 times.
✓ Branch 2 taken 229287 times.
|
432313 | while ((t = av_dict_iterate(*options, t))) { |
| 2052 | 203026 | ret = av_opt_set(obj, t->key, t->value, search_flags); | |
| 2053 |
2/2✓ Branch 0 taken 51677 times.
✓ Branch 1 taken 151349 times.
|
203026 | if (ret == AVERROR_OPTION_NOT_FOUND) |
| 2054 | 51677 | ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY); | |
| 2055 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 203026 times.
|
203026 | if (ret < 0) { |
| 2056 | ✗ | av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); | |
| 2057 | ✗ | av_dict_free(&tmp); | |
| 2058 | ✗ | return ret; | |
| 2059 | } | ||
| 2060 | } | ||
| 2061 | 229287 | av_dict_free(options); | |
| 2062 | 229287 | *options = tmp; | |
| 2063 | 229287 | return 0; | |
| 2064 | } | ||
| 2065 | |||
| 2066 | 169726 | int av_opt_set_dict(void *obj, AVDictionary **options) | |
| 2067 | { | ||
| 2068 | 169726 | return av_opt_set_dict2(obj, options, 0); | |
| 2069 | } | ||
| 2070 | |||
| 2071 | 626545 | const AVOption *av_opt_find(void *obj, const char *name, const char *unit, | |
| 2072 | int opt_flags, int search_flags) | ||
| 2073 | { | ||
| 2074 | 626545 | return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL); | |
| 2075 | } | ||
| 2076 | |||
| 2077 | 50996037 | const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, | |
| 2078 | int opt_flags, int search_flags, void **target_obj) | ||
| 2079 | { | ||
| 2080 | const AVClass *c; | ||
| 2081 | 50996037 | const AVOption *o = NULL; | |
| 2082 | |||
| 2083 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50996037 times.
|
50996037 | if(!obj) |
| 2084 | ✗ | return NULL; | |
| 2085 | |||
| 2086 | 50996037 | c= *(AVClass**)obj; | |
| 2087 | |||
| 2088 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 50996037 times.
|
50996037 | if (!c) |
| 2089 | ✗ | return NULL; | |
| 2090 | |||
| 2091 |
2/2✓ Branch 0 taken 50523297 times.
✓ Branch 1 taken 472740 times.
|
50996037 | if (search_flags & AV_OPT_SEARCH_CHILDREN) { |
| 2092 |
2/2✓ Branch 0 taken 50134167 times.
✓ Branch 1 taken 389130 times.
|
50523297 | if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) { |
| 2093 | 50134167 | void *iter = NULL; | |
| 2094 | const AVClass *child; | ||
| 2095 |
2/2✓ Branch 1 taken 49820069 times.
✓ Branch 2 taken 50133446 times.
|
99953515 | while (child = av_opt_child_class_iterate(c, &iter)) |
| 2096 |
2/2✓ Branch 1 taken 721 times.
✓ Branch 2 taken 49819348 times.
|
49820069 | if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL)) |
| 2097 | 721 | return o; | |
| 2098 | } else { | ||
| 2099 | 389130 | void *child = NULL; | |
| 2100 |
2/2✓ Branch 1 taken 184663 times.
✓ Branch 2 taken 318425 times.
|
503088 | while (child = av_opt_child_next(obj, child)) |
| 2101 |
2/2✓ Branch 1 taken 70705 times.
✓ Branch 2 taken 113958 times.
|
184663 | if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj)) |
| 2102 | 70705 | return o; | |
| 2103 | } | ||
| 2104 | } | ||
| 2105 | |||
| 2106 |
2/2✓ Branch 1 taken 530989799 times.
✓ Branch 2 taken 50305719 times.
|
581295518 | while (o = av_opt_next(obj, o)) { |
| 2107 |
6/6✓ Branch 0 taken 718875 times.
✓ Branch 1 taken 530270924 times.
✓ Branch 2 taken 715445 times.
✓ Branch 3 taken 3430 times.
✓ Branch 4 taken 558881 times.
✓ Branch 5 taken 156564 times.
|
530989799 | if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags && |
| 2108 |
4/4✓ Branch 0 taken 95091 times.
✓ Branch 1 taken 463790 times.
✓ Branch 2 taken 156564 times.
✓ Branch 3 taken 95091 times.
|
715445 | ((!unit && o->type != AV_OPT_TYPE_CONST) || |
| 2109 |
4/6✓ Branch 0 taken 156564 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 156564 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 155102 times.
✓ Branch 5 taken 1462 times.
|
156564 | (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) { |
| 2110 |
2/2✓ Branch 0 taken 283607 times.
✓ Branch 1 taken 335285 times.
|
618892 | if (target_obj) { |
| 2111 |
1/2✓ Branch 0 taken 283607 times.
✗ Branch 1 not taken.
|
283607 | if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ)) |
| 2112 | 283607 | *target_obj = obj; | |
| 2113 | else | ||
| 2114 | ✗ | *target_obj = NULL; | |
| 2115 | } | ||
| 2116 | 618892 | return o; | |
| 2117 | } | ||
| 2118 | } | ||
| 2119 | 50305719 | return NULL; | |
| 2120 | } | ||
| 2121 | |||
| 2122 | 503125 | void *av_opt_child_next(void *obj, void *prev) | |
| 2123 | { | ||
| 2124 | 503125 | const AVClass *c = *(AVClass **)obj; | |
| 2125 |
2/2✓ Branch 0 taken 371693 times.
✓ Branch 1 taken 131432 times.
|
503125 | if (c->child_next) |
| 2126 | 371693 | return c->child_next(obj, prev); | |
| 2127 | 131432 | return NULL; | |
| 2128 | } | ||
| 2129 | |||
| 2130 | 99953515 | const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter) | |
| 2131 | { | ||
| 2132 |
2/2✓ Branch 0 taken 50309928 times.
✓ Branch 1 taken 49643587 times.
|
99953515 | if (parent->child_class_iterate) |
| 2133 | 50309928 | return parent->child_class_iterate(iter); | |
| 2134 | 49643587 | return NULL; | |
| 2135 | } | ||
| 2136 | |||
| 2137 | 6693587 | static int opt_copy_elem(void *logctx, enum AVOptionType type, | |
| 2138 | void *dst, const void *src) | ||
| 2139 | { | ||
| 2140 |
2/2✓ Branch 0 taken 41787 times.
✓ Branch 1 taken 6651800 times.
|
6693587 | if (type == AV_OPT_TYPE_STRING) { |
| 2141 | 41787 | const char *src_str = *(const char *const *)src; | |
| 2142 | 41787 | char **dstp = (char **)dst; | |
| 2143 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 41781 times.
|
41787 | if (*dstp != src_str) |
| 2144 | 6 | av_freep(dstp); | |
| 2145 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 41781 times.
|
41787 | if (src_str) { |
| 2146 | 6 | *dstp = av_strdup(src_str); | |
| 2147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!*dstp) |
| 2148 | ✗ | return AVERROR(ENOMEM); | |
| 2149 | } | ||
| 2150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6651800 times.
|
6651800 | } else if (type == AV_OPT_TYPE_BINARY) { |
| 2151 | ✗ | const uint8_t *const *src8 = (const uint8_t *const *)src; | |
| 2152 | ✗ | uint8_t **dst8 = (uint8_t **)dst; | |
| 2153 | ✗ | int len = *(const int *)(src8 + 1); | |
| 2154 | ✗ | if (*dst8 != *src8) | |
| 2155 | ✗ | av_freep(dst8); | |
| 2156 | ✗ | *dst8 = av_memdup(*src8, len); | |
| 2157 | ✗ | if (len && !*dst8) { | |
| 2158 | ✗ | *(int *)(dst8 + 1) = 0; | |
| 2159 | ✗ | return AVERROR(ENOMEM); | |
| 2160 | } | ||
| 2161 | ✗ | *(int *)(dst8 + 1) = len; | |
| 2162 |
2/2✓ Branch 0 taken 1981879 times.
✓ Branch 1 taken 4669921 times.
|
6651800 | } else if (type == AV_OPT_TYPE_CONST) { |
| 2163 | // do nothing | ||
| 2164 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1981877 times.
|
1981879 | } else if (type == AV_OPT_TYPE_DICT) { |
| 2165 | 2 | const AVDictionary *sdict = *(const AVDictionary * const *)src; | |
| 2166 | 2 | AVDictionary **ddictp = (AVDictionary **)dst; | |
| 2167 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (sdict != *ddictp) |
| 2168 | 2 | av_dict_free(ddictp); | |
| 2169 | 2 | *ddictp = NULL; | |
| 2170 | 2 | return av_dict_copy(ddictp, sdict, 0); | |
| 2171 |
2/2✓ Branch 0 taken 13652 times.
✓ Branch 1 taken 1968225 times.
|
1981877 | } else if (type == AV_OPT_TYPE_CHLAYOUT) { |
| 2172 |
1/2✓ Branch 0 taken 13652 times.
✗ Branch 1 not taken.
|
13652 | if (dst != src) |
| 2173 | 13652 | return av_channel_layout_copy(dst, src); | |
| 2174 |
1/2✓ Branch 1 taken 1968225 times.
✗ Branch 2 not taken.
|
1968225 | } else if (opt_is_pod(type)) { |
| 2175 | 1968225 | size_t size = opt_type_desc[type].size; | |
| 2176 | 1968225 | memcpy(dst, src, size); | |
| 2177 | } else { | ||
| 2178 | ✗ | av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type); | |
| 2179 | ✗ | return AVERROR(EINVAL); | |
| 2180 | } | ||
| 2181 | |||
| 2182 | 6679933 | return 0; | |
| 2183 | } | ||
| 2184 | |||
| 2185 | 13658 | static int opt_copy_array(void *logctx, const AVOption *o, | |
| 2186 | void **pdst, const void * const *psrc) | ||
| 2187 | { | ||
| 2188 | 13658 | unsigned nb_elems = *opt_array_pcount(psrc); | |
| 2189 | 13658 | void *dst = NULL; | |
| 2190 | int ret; | ||
| 2191 | |||
| 2192 |
1/2✓ Branch 0 taken 13658 times.
✗ Branch 1 not taken.
|
13658 | if (*pdst == *psrc) { |
| 2193 | 13658 | *pdst = NULL; | |
| 2194 | 13658 | *opt_array_pcount(pdst) = 0; | |
| 2195 | } | ||
| 2196 | |||
| 2197 | 13658 | opt_free_array(o, pdst, opt_array_pcount(pdst)); | |
| 2198 | |||
| 2199 | 13658 | dst = av_calloc(nb_elems, opt_type_desc[TYPE_BASE(o->type)].size); | |
| 2200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13658 times.
|
13658 | if (!dst) |
| 2201 | ✗ | return AVERROR(ENOMEM); | |
| 2202 | |||
| 2203 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13658 times.
|
13658 | for (unsigned i = 0; i < nb_elems; i++) { |
| 2204 | ✗ | ret = opt_copy_elem(logctx, TYPE_BASE(o->type), | |
| 2205 | opt_array_pelem(o, dst, i), | ||
| 2206 | ✗ | opt_array_pelem(o, *(void**)psrc, i)); | |
| 2207 | ✗ | if (ret < 0) { | |
| 2208 | ✗ | opt_free_array(o, &dst, &nb_elems); | |
| 2209 | ✗ | return ret; | |
| 2210 | } | ||
| 2211 | } | ||
| 2212 | |||
| 2213 | 13658 | *pdst = dst; | |
| 2214 | 13658 | *opt_array_pcount(pdst) = nb_elems; | |
| 2215 | |||
| 2216 | 13658 | return 0; | |
| 2217 | } | ||
| 2218 | |||
| 2219 | 37460 | int av_opt_copy(void *dst, const void *src) | |
| 2220 | { | ||
| 2221 | 37460 | const AVOption *o = NULL; | |
| 2222 | const AVClass *c; | ||
| 2223 | 37460 | int ret = 0; | |
| 2224 | |||
| 2225 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37460 times.
|
37460 | if (!src) |
| 2226 | ✗ | return AVERROR(EINVAL); | |
| 2227 | |||
| 2228 | 37460 | c = *(AVClass **)src; | |
| 2229 |
2/4✓ Branch 0 taken 37460 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37460 times.
|
37460 | if (!c || c != *(AVClass **)dst) |
| 2230 | ✗ | return AVERROR(EINVAL); | |
| 2231 | |||
| 2232 |
2/2✓ Branch 1 taken 6707031 times.
✓ Branch 2 taken 37460 times.
|
6744491 | while ((o = av_opt_next(src, o))) { |
| 2233 | 6707031 | void *field_dst = (uint8_t *)dst + o->offset; | |
| 2234 | 6707031 | void *field_src = (uint8_t *)src + o->offset; | |
| 2235 | |||
| 2236 | 13414062 | int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ? | |
| 2237 |
2/2✓ Branch 0 taken 13658 times.
✓ Branch 1 taken 6693373 times.
|
6707031 | opt_copy_array(dst, o, field_dst, field_src) : |
| 2238 | 6693373 | opt_copy_elem (dst, o->type, field_dst, field_src); | |
| 2239 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6707031 times.
|
6707031 | if (err < 0) |
| 2240 | ✗ | ret = err; | |
| 2241 | } | ||
| 2242 | 37460 | return ret; | |
| 2243 | } | ||
| 2244 | |||
| 2245 | 20 | int av_opt_get_array_size(void *obj, const char *name, int search_flags, | |
| 2246 | unsigned int *out_val) | ||
| 2247 | { | ||
| 2248 | void *target_obj, *parray; | ||
| 2249 | const AVOption *o; | ||
| 2250 | |||
| 2251 | 20 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 2252 |
2/4✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 20 times.
|
20 | if (!o || !target_obj) |
| 2253 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
| 2254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
|
20 | if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY)) |
| 2255 | ✗ | return AVERROR(EINVAL); | |
| 2256 | |||
| 2257 | 20 | parray = (uint8_t *)target_obj + o->offset; | |
| 2258 | 20 | *out_val = *opt_array_pcount(parray); | |
| 2259 | |||
| 2260 | 20 | return 0; | |
| 2261 | } | ||
| 2262 | |||
| 2263 | 14 | int av_opt_get_array(void *obj, const char *name, int search_flags, | |
| 2264 | unsigned int start_elem, unsigned int nb_elems, | ||
| 2265 | enum AVOptionType out_type, void *out_val) | ||
| 2266 | { | ||
| 2267 | 14 | const size_t elem_size_out = opt_type_desc[TYPE_BASE(out_type)].size; | |
| 2268 | |||
| 2269 | const AVOption *o; | ||
| 2270 | void *target_obj; | ||
| 2271 | |||
| 2272 | const void *parray; | ||
| 2273 | unsigned array_size; | ||
| 2274 | |||
| 2275 | int ret; | ||
| 2276 | |||
| 2277 | 14 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | |
| 2278 |
2/4✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
14 | if (!o || !target_obj) |
| 2279 | ✗ | return AVERROR_OPTION_NOT_FOUND; | |
| 2280 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) || |
| 2281 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | (out_type & AV_OPT_TYPE_FLAG_ARRAY)) |
| 2282 | ✗ | return AVERROR(EINVAL); | |
| 2283 | |||
| 2284 | 14 | parray = (uint8_t *)target_obj + o->offset; | |
| 2285 | 14 | array_size = *opt_array_pcount(parray); | |
| 2286 | |||
| 2287 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | if (start_elem >= array_size || |
| 2288 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | array_size - start_elem < nb_elems) |
| 2289 | ✗ | return AVERROR(EINVAL); | |
| 2290 | |||
| 2291 |
2/2✓ Branch 0 taken 32 times.
✓ Branch 1 taken 14 times.
|
46 | for (unsigned i = 0; i < nb_elems; i++) { |
| 2292 | 32 | const void *src = opt_array_pelem(o, *(void**)parray, start_elem + i); | |
| 2293 | 32 | void *dst = (uint8_t*)out_val + i * elem_size_out; | |
| 2294 | |||
| 2295 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 7 times.
|
32 | if (out_type == TYPE_BASE(o->type)) { |
| 2296 | 25 | ret = opt_copy_elem(obj, out_type, dst, src); | |
| 2297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25 times.
|
25 | if (ret < 0) |
| 2298 | ✗ | goto fail; | |
| 2299 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
|
7 | } else if (out_type == AV_OPT_TYPE_STRING) { |
| 2300 | 5 | uint8_t buf[128], *out = buf; | |
| 2301 | |||
| 2302 | 5 | ret = opt_get_elem(o, &out, sizeof(buf), src, search_flags); | |
| 2303 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (ret < 0) |
| 2304 | ✗ | goto fail; | |
| 2305 | |||
| 2306 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if (out == buf) { |
| 2307 | 5 | out = av_strdup(buf); | |
| 2308 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
|
5 | if (!out) { |
| 2309 | ✗ | ret = AVERROR(ENOMEM); | |
| 2310 | ✗ | goto fail; | |
| 2311 | } | ||
| 2312 | } | ||
| 2313 | |||
| 2314 | 5 | *(uint8_t**)dst = out; | |
| 2315 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | } else if (out_type == AV_OPT_TYPE_INT64 || |
| 2316 | ✗ | out_type == AV_OPT_TYPE_DOUBLE || | |
| 2317 | 2 | out_type == AV_OPT_TYPE_RATIONAL) { | |
| 2318 | 2 | double num = 1.0; | |
| 2319 | 2 | int den = 1; | |
| 2320 | 2 | int64_t intnum = 1; | |
| 2321 | |||
| 2322 | 2 | ret = read_number(o, src, &num, &den, &intnum); | |
| 2323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (ret < 0) |
| 2324 | ✗ | goto fail; | |
| 2325 | |||
| 2326 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | switch (out_type) { |
| 2327 | ✗ | case AV_OPT_TYPE_INT64: | |
| 2328 | ✗ | *(int64_t*)dst = (num == den) ? intnum : num * intnum / den; | |
| 2329 | 2 | break; | |
| 2330 | 2 | case AV_OPT_TYPE_DOUBLE: | |
| 2331 | 2 | *(double*)dst = num * intnum / den; | |
| 2332 | 2 | break; | |
| 2333 | ✗ | case AV_OPT_TYPE_RATIONAL: | |
| 2334 | ✗ | *(AVRational*)dst = (num == 1.0 && (int)intnum == intnum) ? | |
| 2335 | ✗ | (AVRational){ intnum, den } : | |
| 2336 | ✗ | double_to_rational(num * intnum / den); | |
| 2337 | ✗ | break; | |
| 2338 | ✗ | default: av_assert0(0); | |
| 2339 | } | ||
| 2340 | } else | ||
| 2341 | ✗ | return AVERROR(ENOSYS); | |
| 2342 | } | ||
| 2343 | |||
| 2344 | 14 | return 0; | |
| 2345 | ✗ | fail: | |
| 2346 | ✗ | for (unsigned i = 0; i < nb_elems; i++) | |
| 2347 | ✗ | opt_free_elem(out_type, (uint8_t*)out_val + i * elem_size_out); | |
| 2348 | ✗ | return ret; | |
| 2349 | } | ||
| 2350 | |||
| 2351 | 45 | int av_opt_set_array(void *obj, const char *name, int search_flags, | |
| 2352 | unsigned int start_elem, unsigned int nb_elems, | ||
| 2353 | enum AVOptionType val_type, const void *val) | ||
| 2354 | { | ||
| 2355 | 45 | const size_t elem_size_val = opt_type_desc[TYPE_BASE(val_type)].size; | |
| 2356 | |||
| 2357 | const AVOption *o; | ||
| 2358 | const AVOptionArrayDef *arr; | ||
| 2359 | void *target_obj; | ||
| 2360 | |||
| 2361 | void *parray; | ||
| 2362 | void *new_elems; | ||
| 2363 | unsigned *array_size, new_size; | ||
| 2364 | size_t elem_size; | ||
| 2365 | |||
| 2366 | 45 | int ret = 0; | |
| 2367 | |||
| 2368 | 45 | ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &parray); | |
| 2369 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (ret < 0) |
| 2370 | ✗ | return ret; | |
| 2371 | |||
| 2372 |
1/2✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
|
45 | if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) || |
| 2373 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | (val_type & AV_OPT_TYPE_FLAG_ARRAY)) |
| 2374 | ✗ | return AVERROR(EINVAL); | |
| 2375 | |||
| 2376 | 45 | arr = o->default_val.arr; | |
| 2377 | 45 | array_size = opt_array_pcount(parray); | |
| 2378 | 45 | elem_size = opt_type_desc[TYPE_BASE(o->type)].size; | |
| 2379 | |||
| 2380 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (start_elem > *array_size) |
| 2381 | ✗ | return AVERROR(EINVAL); | |
| 2382 | |||
| 2383 | // compute new array size | ||
| 2384 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (!val) { |
| 2385 | ✗ | if (*array_size - start_elem < nb_elems) | |
| 2386 | ✗ | return AVERROR(EINVAL); | |
| 2387 | |||
| 2388 | ✗ | new_size = *array_size - nb_elems; | |
| 2389 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | } else if (search_flags & AV_OPT_ARRAY_REPLACE) { |
| 2390 | ✗ | if (start_elem >= UINT_MAX - nb_elems) | |
| 2391 | ✗ | return AVERROR(EINVAL); | |
| 2392 | |||
| 2393 | ✗ | new_size = FFMAX(*array_size, start_elem + nb_elems); | |
| 2394 | } else { | ||
| 2395 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (nb_elems >= UINT_MAX - *array_size) |
| 2396 | ✗ | return AVERROR(EINVAL); | |
| 2397 | |||
| 2398 | 45 | new_size = *array_size + nb_elems; | |
| 2399 | } | ||
| 2400 | |||
| 2401 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (arr && |
| 2402 | ✗ | ((arr->size_max && new_size > arr->size_max) || | |
| 2403 | ✗ | (arr->size_min && new_size < arr->size_min))) | |
| 2404 | ✗ | return AVERROR(EINVAL); | |
| 2405 | |||
| 2406 | // desired operation is shrinking the array | ||
| 2407 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (!val) { |
| 2408 | ✗ | void *array = *(void**)parray; | |
| 2409 | |||
| 2410 | ✗ | for (unsigned i = 0; i < nb_elems; i++) { | |
| 2411 | ✗ | opt_free_elem(o->type, | |
| 2412 | opt_array_pelem(o, array, start_elem + i)); | ||
| 2413 | } | ||
| 2414 | |||
| 2415 | ✗ | if (new_size > 0) { | |
| 2416 | ✗ | memmove(opt_array_pelem(o, array, start_elem), | |
| 2417 | ✗ | opt_array_pelem(o, array, start_elem + nb_elems), | |
| 2418 | ✗ | elem_size * (*array_size - start_elem - nb_elems)); | |
| 2419 | |||
| 2420 | ✗ | array = av_realloc_array(array, new_size, elem_size); | |
| 2421 | ✗ | if (!array) | |
| 2422 | ✗ | return AVERROR(ENOMEM); | |
| 2423 | |||
| 2424 | ✗ | *(void**)parray = array; | |
| 2425 | } else | ||
| 2426 | ✗ | av_freep(parray); | |
| 2427 | |||
| 2428 | ✗ | *array_size = new_size; | |
| 2429 | |||
| 2430 | ✗ | return 0; | |
| 2431 | } | ||
| 2432 | |||
| 2433 | // otherwise, desired operation is insert/replace; | ||
| 2434 | // first, store new elements in a separate array to simplify | ||
| 2435 | // rollback on failure | ||
| 2436 | 45 | new_elems = av_calloc(nb_elems, elem_size); | |
| 2437 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 45 times.
|
45 | if (!new_elems) |
| 2438 | ✗ | return AVERROR(ENOMEM); | |
| 2439 | |||
| 2440 | // convert/validate each new element | ||
| 2441 |
2/2✓ Branch 0 taken 189 times.
✓ Branch 1 taken 45 times.
|
234 | for (unsigned i = 0; i < nb_elems; i++) { |
| 2442 | 189 | void *dst = opt_array_pelem(o, new_elems, i); | |
| 2443 | 189 | const void *src = (uint8_t*)val + i * elem_size_val; | |
| 2444 | |||
| 2445 | 189 | double num = 1.0; | |
| 2446 | 189 | int den = 1; | |
| 2447 | 189 | int64_t intnum = 1; | |
| 2448 | |||
| 2449 |
1/2✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
|
189 | if (val_type == TYPE_BASE(o->type)) { |
| 2450 | int err; | ||
| 2451 | |||
| 2452 | 189 | ret = opt_copy_elem(obj, val_type, dst, src); | |
| 2453 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 189 times.
|
189 | if (ret < 0) |
| 2454 | ✗ | goto fail; | |
| 2455 | |||
| 2456 | // validate the range for numeric options | ||
| 2457 | 189 | err = read_number(o, dst, &num, &den, &intnum); | |
| 2458 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | if (err >= 0 && TYPE_BASE(o->type) != AV_OPT_TYPE_FLAGS && |
| 2459 |
3/6✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 189 times.
|
189 | (!den || o->max * den < num * intnum || o->min * den > num * intnum)) { |
| 2460 | ✗ | num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN); | |
| 2461 | ✗ | av_log(obj, AV_LOG_ERROR, "Cannot set array element %u for " | |
| 2462 | "parameter '%s': value %f out of range [%g - %g]\n", | ||
| 2463 | ✗ | start_elem + i, o->name, num, o->min, o->max); | |
| 2464 | ✗ | ret = AVERROR(ERANGE); | |
| 2465 | ✗ | goto fail; | |
| 2466 | } | ||
| 2467 | ✗ | } else if (val_type == AV_OPT_TYPE_STRING) { | |
| 2468 | ✗ | ret = opt_set_elem(obj, target_obj, o, *(const char **)src, dst); | |
| 2469 | ✗ | if (ret < 0) | |
| 2470 | ✗ | goto fail; | |
| 2471 | ✗ | } else if (val_type == AV_OPT_TYPE_INT || | |
| 2472 | ✗ | val_type == AV_OPT_TYPE_INT64 || | |
| 2473 | ✗ | val_type == AV_OPT_TYPE_FLOAT || | |
| 2474 | ✗ | val_type == AV_OPT_TYPE_DOUBLE || | |
| 2475 | val_type == AV_OPT_TYPE_RATIONAL) { | ||
| 2476 | |||
| 2477 | ✗ | switch (val_type) { | |
| 2478 | ✗ | case AV_OPT_TYPE_INT: intnum = *(int*)src; break; | |
| 2479 | ✗ | case AV_OPT_TYPE_INT64: intnum = *(int64_t*)src; break; | |
| 2480 | ✗ | case AV_OPT_TYPE_FLOAT: num = *(float*)src; break; | |
| 2481 | ✗ | case AV_OPT_TYPE_DOUBLE: num = *(double*)src; break; | |
| 2482 | ✗ | case AV_OPT_TYPE_RATIONAL: intnum = ((AVRational*)src)->num; | |
| 2483 | ✗ | den = ((AVRational*)src)->den; break; | |
| 2484 | ✗ | default: av_assert0(0); | |
| 2485 | } | ||
| 2486 | |||
| 2487 | ✗ | ret = write_number(obj, o, dst, num, den, intnum, 0); | |
| 2488 | ✗ | if (ret < 0) | |
| 2489 | ✗ | goto fail; | |
| 2490 | } else { | ||
| 2491 | ✗ | ret = AVERROR(ENOSYS); | |
| 2492 | ✗ | goto fail; | |
| 2493 | } | ||
| 2494 | } | ||
| 2495 | |||
| 2496 | // commit new elements to the array | ||
| 2497 |
2/4✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45 times.
✗ Branch 3 not taken.
|
45 | if (start_elem == 0 && nb_elems == new_size) { |
| 2498 | // replacing the existing array entirely | ||
| 2499 | 45 | opt_free_array(o, parray, array_size); | |
| 2500 | 45 | *(void**)parray = new_elems; | |
| 2501 | 45 | *array_size = nb_elems; | |
| 2502 | |||
| 2503 | 45 | new_elems = NULL; | |
| 2504 | 45 | nb_elems = 0; | |
| 2505 | } else { | ||
| 2506 | ✗ | void *array = av_realloc_array(*(void**)parray, new_size, elem_size); | |
| 2507 | ✗ | if (!array) { | |
| 2508 | ✗ | ret = AVERROR(ENOMEM); | |
| 2509 | ✗ | goto fail; | |
| 2510 | } | ||
| 2511 | |||
| 2512 | ✗ | if (search_flags & AV_OPT_ARRAY_REPLACE) { | |
| 2513 | // free the elements being overwritten | ||
| 2514 | ✗ | for (unsigned i = start_elem; i < FFMIN(start_elem + nb_elems, *array_size); i++) | |
| 2515 | ✗ | opt_free_elem(o->type, opt_array_pelem(o, array, i)); | |
| 2516 | } else { | ||
| 2517 | // shift existing elements to the end | ||
| 2518 | ✗ | memmove(opt_array_pelem(o, array, start_elem + nb_elems), | |
| 2519 | ✗ | opt_array_pelem(o, array, start_elem), | |
| 2520 | ✗ | elem_size * (*array_size - start_elem)); | |
| 2521 | } | ||
| 2522 | |||
| 2523 | ✗ | memcpy((uint8_t*)array + elem_size * start_elem, new_elems, elem_size * nb_elems); | |
| 2524 | |||
| 2525 | ✗ | av_freep(&new_elems); | |
| 2526 | ✗ | nb_elems = 0; | |
| 2527 | |||
| 2528 | ✗ | *(void**)parray = array; | |
| 2529 | ✗ | *array_size = new_size; | |
| 2530 | } | ||
| 2531 | |||
| 2532 | 45 | fail: | |
| 2533 | 45 | opt_free_array(o, &new_elems, &nb_elems); | |
| 2534 | |||
| 2535 | 45 | return ret; | |
| 2536 | } | ||
| 2537 | |||
| 2538 | 31 | int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) | |
| 2539 | { | ||
| 2540 | int ret; | ||
| 2541 | 31 | const AVClass *c = *(AVClass**)obj; | |
| 2542 | 31 | int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges; | |
| 2543 | |||
| 2544 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (!callback) |
| 2545 | 31 | callback = av_opt_query_ranges_default; | |
| 2546 | |||
| 2547 | 31 | ret = callback(ranges_arg, obj, key, flags); | |
| 2548 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 13 times.
|
31 | if (ret >= 0) { |
| 2549 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE)) |
| 2550 | 18 | ret = 1; | |
| 2551 | 18 | (*ranges_arg)->nb_components = ret; | |
| 2552 | } | ||
| 2553 | 31 | return ret; | |
| 2554 | } | ||
| 2555 | |||
| 2556 | 31 | int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags) | |
| 2557 | { | ||
| 2558 | 31 | AVOptionRanges *ranges = av_mallocz(sizeof(*ranges)); | |
| 2559 | 31 | AVOptionRange **range_array = av_mallocz(sizeof(void*)); | |
| 2560 | 31 | AVOptionRange *range = av_mallocz(sizeof(*range)); | |
| 2561 | 31 | const AVOption *field = av_opt_find(obj, key, NULL, 0, flags); | |
| 2562 | int ret; | ||
| 2563 | |||
| 2564 | 31 | *ranges_arg = NULL; | |
| 2565 | |||
| 2566 |
5/8✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 28 times.
|
31 | if (!ranges || !range || !range_array || !field) { |
| 2567 | 3 | ret = AVERROR(ENOMEM); | |
| 2568 | 3 | goto fail; | |
| 2569 | } | ||
| 2570 | |||
| 2571 | 28 | ranges->range = range_array; | |
| 2572 | 28 | ranges->range[0] = range; | |
| 2573 | 28 | ranges->nb_ranges = 1; | |
| 2574 | 28 | ranges->nb_components = 1; | |
| 2575 | 28 | range->is_range = 1; | |
| 2576 | 28 | range->value_min = field->min; | |
| 2577 | 28 | range->value_max = field->max; | |
| 2578 | |||
| 2579 |
6/6✓ Branch 0 taken 13 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 10 times.
|
28 | switch (field->type) { |
| 2580 | 13 | case AV_OPT_TYPE_BOOL: | |
| 2581 | case AV_OPT_TYPE_INT: | ||
| 2582 | case AV_OPT_TYPE_UINT: | ||
| 2583 | case AV_OPT_TYPE_INT64: | ||
| 2584 | case AV_OPT_TYPE_UINT64: | ||
| 2585 | case AV_OPT_TYPE_PIXEL_FMT: | ||
| 2586 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
| 2587 | case AV_OPT_TYPE_FLOAT: | ||
| 2588 | case AV_OPT_TYPE_DOUBLE: | ||
| 2589 | case AV_OPT_TYPE_DURATION: | ||
| 2590 | case AV_OPT_TYPE_COLOR: | ||
| 2591 | 13 | break; | |
| 2592 | 2 | case AV_OPT_TYPE_STRING: | |
| 2593 | 2 | range->component_min = 0; | |
| 2594 | 2 | range->component_max = 0x10FFFF; // max unicode value | |
| 2595 | 2 | range->value_min = -1; | |
| 2596 | 2 | range->value_max = INT_MAX; | |
| 2597 | 2 | break; | |
| 2598 | 1 | case AV_OPT_TYPE_RATIONAL: | |
| 2599 | 1 | range->component_min = INT_MIN; | |
| 2600 | 1 | range->component_max = INT_MAX; | |
| 2601 | 1 | break; | |
| 2602 | 1 | case AV_OPT_TYPE_IMAGE_SIZE: | |
| 2603 | 1 | range->component_min = 0; | |
| 2604 | 1 | range->component_max = INT_MAX/128/8; | |
| 2605 | 1 | range->value_min = 0; | |
| 2606 | 1 | range->value_max = INT_MAX/8; | |
| 2607 | 1 | break; | |
| 2608 | 1 | case AV_OPT_TYPE_VIDEO_RATE: | |
| 2609 | 1 | range->component_min = 1; | |
| 2610 | 1 | range->component_max = INT_MAX; | |
| 2611 | 1 | range->value_min = 1; | |
| 2612 | 1 | range->value_max = INT_MAX; | |
| 2613 | 1 | break; | |
| 2614 | 10 | default: | |
| 2615 | 10 | ret = AVERROR(ENOSYS); | |
| 2616 | 10 | goto fail; | |
| 2617 | } | ||
| 2618 | |||
| 2619 | 18 | *ranges_arg = ranges; | |
| 2620 | 18 | return 1; | |
| 2621 | 13 | fail: | |
| 2622 | 13 | av_free(ranges); | |
| 2623 | 13 | av_free(range); | |
| 2624 | 13 | av_free(range_array); | |
| 2625 | 13 | return ret; | |
| 2626 | } | ||
| 2627 | |||
| 2628 | 18 | void av_opt_freep_ranges(AVOptionRanges **rangesp) | |
| 2629 | { | ||
| 2630 | int i; | ||
| 2631 | 18 | AVOptionRanges *ranges = *rangesp; | |
| 2632 | |||
| 2633 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (!ranges) |
| 2634 | ✗ | return; | |
| 2635 | |||
| 2636 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
|
36 | for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) { |
| 2637 | 18 | AVOptionRange *range = ranges->range[i]; | |
| 2638 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (range) { |
| 2639 | 18 | av_freep(&range->str); | |
| 2640 | 18 | av_freep(&ranges->range[i]); | |
| 2641 | } | ||
| 2642 | } | ||
| 2643 | 18 | av_freep(&ranges->range); | |
| 2644 | 18 | av_freep(rangesp); | |
| 2645 | } | ||
| 2646 | |||
| 2647 | 174 | int av_opt_is_set_to_default(void *obj, const AVOption *o) | |
| 2648 | { | ||
| 2649 | int64_t i64; | ||
| 2650 | double d; | ||
| 2651 | AVRational q; | ||
| 2652 | int ret, w, h; | ||
| 2653 | char *str; | ||
| 2654 | void *dst; | ||
| 2655 | |||
| 2656 |
2/4✓ Branch 0 taken 174 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 174 times.
|
174 | if (!o || !obj) |
| 2657 | ✗ | return AVERROR(EINVAL); | |
| 2658 | |||
| 2659 | 174 | dst = ((uint8_t*)obj) + o->offset; | |
| 2660 | |||
| 2661 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 162 times.
|
174 | if (o->type & AV_OPT_TYPE_FLAG_ARRAY) { |
| 2662 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
|
12 | const char *def = o->default_val.arr ? o->default_val.arr->def : NULL; |
| 2663 | uint8_t *val; | ||
| 2664 | |||
| 2665 | 12 | ret = opt_get_array(o, dst, &val); | |
| 2666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (ret < 0) |
| 2667 | ✗ | return ret; | |
| 2668 | |||
| 2669 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
|
12 | if (!!val != !!def) |
| 2670 | 3 | ret = 0; | |
| 2671 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 5 times.
|
9 | else if (val) |
| 2672 | 4 | ret = !strcmp(val, def); | |
| 2673 | else | ||
| 2674 | 5 | ret = 1; | |
| 2675 | |||
| 2676 | 12 | av_freep(&val); | |
| 2677 | |||
| 2678 | 12 | return ret; | |
| 2679 | } | ||
| 2680 | |||
| 2681 |
11/13✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 25 times.
✓ Branch 7 taken 9 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 11 taken 3 times.
✗ Branch 12 not taken.
|
162 | switch (o->type) { |
| 2682 | ✗ | case AV_OPT_TYPE_CONST: | |
| 2683 | 162 | return 1; | |
| 2684 | 88 | case AV_OPT_TYPE_BOOL: | |
| 2685 | case AV_OPT_TYPE_FLAGS: | ||
| 2686 | case AV_OPT_TYPE_PIXEL_FMT: | ||
| 2687 | case AV_OPT_TYPE_SAMPLE_FMT: | ||
| 2688 | case AV_OPT_TYPE_INT: | ||
| 2689 | case AV_OPT_TYPE_UINT: | ||
| 2690 | case AV_OPT_TYPE_DURATION: | ||
| 2691 | case AV_OPT_TYPE_INT64: | ||
| 2692 | case AV_OPT_TYPE_UINT64: | ||
| 2693 | 88 | read_number(o, dst, NULL, NULL, &i64); | |
| 2694 | 88 | return o->default_val.i64 == i64; | |
| 2695 | 9 | case AV_OPT_TYPE_CHLAYOUT: { | |
| 2696 | 9 | AVChannelLayout ch_layout = { 0 }; | |
| 2697 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 | if (o->default_val.str) { |
| 2698 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0) |
| 2699 | ✗ | return ret; | |
| 2700 | } | ||
| 2701 | 9 | ret = !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout); | |
| 2702 | 9 | av_channel_layout_uninit(&ch_layout); | |
| 2703 | 9 | return ret; | |
| 2704 | } | ||
| 2705 | 6 | case AV_OPT_TYPE_STRING: | |
| 2706 | 6 | str = *(char **)dst; | |
| 2707 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (str == o->default_val.str) //2 NULLs |
| 2708 | ✗ | return 1; | |
| 2709 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
6 | if (!str || !o->default_val.str) //1 NULL |
| 2710 | 2 | return 0; | |
| 2711 | 4 | return !strcmp(str, o->default_val.str); | |
| 2712 | 3 | case AV_OPT_TYPE_DOUBLE: | |
| 2713 | 3 | d = *(double *)dst; | |
| 2714 |
3/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3 | return o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl); |
| 2715 | 3 | case AV_OPT_TYPE_FLOAT: | |
| 2716 | 3 | d = *(float *)dst; | |
| 2717 |
3/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
3 | return (float)o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl); |
| 2718 | 25 | case AV_OPT_TYPE_RATIONAL: { | |
| 2719 | 25 | AVRational v = *(AVRational *) dst; | |
| 2720 | 25 | q = av_d2q(o->default_val.dbl, INT_MAX); | |
| 2721 |
3/6✓ Branch 1 taken 6 times.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
25 | return !av_cmp_q(v, q) || (!q.den && !v.den); |
| 2722 | } | ||
| 2723 | 9 | case AV_OPT_TYPE_BINARY: { | |
| 2724 | struct { | ||
| 2725 | uint8_t *data; | ||
| 2726 | int size; | ||
| 2727 | 9 | } tmp = {0}; | |
| 2728 | 9 | int opt_size = *(int *)((void **)dst + 1); | |
| 2729 | 9 | void *opt_ptr = *(void **)dst; | |
| 2730 |
6/6✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 1 times.
|
9 | if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str))) |
| 2731 | 6 | return 1; | |
| 2732 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
3 | if (!opt_size || !o->default_val.str || !strlen(o->default_val.str )) |
| 2733 | 1 | return 0; | |
| 2734 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (opt_size != strlen(o->default_val.str) / 2) |
| 2735 | ✗ | return 0; | |
| 2736 | 2 | ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data); | |
| 2737 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (!ret) |
| 2738 | 2 | ret = !memcmp(opt_ptr, tmp.data, tmp.size); | |
| 2739 | 2 | av_free(tmp.data); | |
| 2740 | 2 | return ret; | |
| 2741 | } | ||
| 2742 | 10 | case AV_OPT_TYPE_DICT: { | |
| 2743 | 10 | AVDictionary *dict1 = NULL; | |
| 2744 | 10 | AVDictionary *dict2 = *(AVDictionary **)dst; | |
| 2745 | 10 | const AVDictionaryEntry *en1 = NULL; | |
| 2746 | 10 | const AVDictionaryEntry *en2 = NULL; | |
| 2747 | 10 | ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0); | |
| 2748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | if (ret < 0) { |
| 2749 | ✗ | av_dict_free(&dict1); | |
| 2750 | ✗ | return ret; | |
| 2751 | } | ||
| 2752 | do { | ||
| 2753 | 12 | en1 = av_dict_iterate(dict1, en1); | |
| 2754 | 12 | en2 = av_dict_iterate(dict2, en2); | |
| 2755 |
6/8✓ Branch 0 taken 3 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
12 | } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value)); |
| 2756 | 10 | av_dict_free(&dict1); | |
| 2757 |
4/4✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4 times.
|
10 | return (!en1 && !en2); |
| 2758 | } | ||
| 2759 | 3 | case AV_OPT_TYPE_IMAGE_SIZE: | |
| 2760 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | if (!o->default_val.str || !strcmp(o->default_val.str, "none")) |
| 2761 | ✗ | w = h = 0; | |
| 2762 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0) |
| 2763 | ✗ | return ret; | |
| 2764 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
3 | return (w == *(int *)dst) && (h == *((int *)dst+1)); |
| 2765 | 3 | case AV_OPT_TYPE_VIDEO_RATE: | |
| 2766 | 3 | q = (AVRational){0, 0}; | |
| 2767 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (o->default_val.str) { |
| 2768 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0) |
| 2769 | ✗ | return ret; | |
| 2770 | } | ||
| 2771 | 3 | return !av_cmp_q(*(AVRational*)dst, q); | |
| 2772 | 3 | case AV_OPT_TYPE_COLOR: { | |
| 2773 | 3 | uint8_t color[4] = {0, 0, 0, 0}; | |
| 2774 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (o->default_val.str) { |
| 2775 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0) |
| 2776 | ✗ | return ret; | |
| 2777 | } | ||
| 2778 | 3 | return !memcmp(color, dst, sizeof(color)); | |
| 2779 | } | ||
| 2780 | ✗ | default: | |
| 2781 | ✗ | av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name); | |
| 2782 | ✗ | break; | |
| 2783 | } | ||
| 2784 | ✗ | return AVERROR_PATCHWELCOME; | |
| 2785 | } | ||
| 2786 | |||
| 2787 | 62 | int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags) | |
| 2788 | { | ||
| 2789 | const AVOption *o; | ||
| 2790 | void *target; | ||
| 2791 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (!obj) |
| 2792 | ✗ | return AVERROR(EINVAL); | |
| 2793 | 62 | o = av_opt_find2(obj, name, NULL, 0, search_flags, &target); | |
| 2794 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 56 times.
|
62 | if (!o) |
| 2795 | 6 | return AVERROR_OPTION_NOT_FOUND; | |
| 2796 | 56 | return av_opt_is_set_to_default(target, o); | |
| 2797 | } | ||
| 2798 | |||
| 2799 | 30 | static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt, | |
| 2800 | AVBPrint *bprint, const char key_val_sep, const char pairs_sep) | ||
| 2801 | { | ||
| 2802 | 30 | const AVOption *o = NULL; | |
| 2803 | 30 | void *child = NULL; | |
| 2804 | uint8_t *buf; | ||
| 2805 | int ret; | ||
| 2806 | 30 | const char special_chars[] = {pairs_sep, key_val_sep, '\0'}; | |
| 2807 | |||
| 2808 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2 times.
|
30 | if (flags & AV_OPT_SERIALIZE_SEARCH_CHILDREN) |
| 2809 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 28 times.
|
37 | while (child = av_opt_child_next(obj, child)) { |
| 2810 | 9 | ret = opt_serialize(child, opt_flags, flags, cnt, bprint, | |
| 2811 | key_val_sep, pairs_sep); | ||
| 2812 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
|
9 | if (ret < 0) |
| 2813 | ✗ | return ret; | |
| 2814 | } | ||
| 2815 | |||
| 2816 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 2 taken 30 times.
|
330 | while (o = av_opt_next(obj, o)) { |
| 2817 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 174 times.
|
300 | if (o->type == AV_OPT_TYPE_CONST) |
| 2818 | 126 | continue; | |
| 2819 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
174 | if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags) |
| 2820 | ✗ | continue; | |
| 2821 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 174 times.
|
174 | else if (((o->flags & opt_flags) != opt_flags)) |
| 2822 | ✗ | continue; | |
| 2823 |
4/4✓ Branch 0 taken 118 times.
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 73 times.
✓ Branch 4 taken 45 times.
|
174 | if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0) |
| 2824 | 73 | continue; | |
| 2825 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
|
101 | if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) { |
| 2826 | ✗ | av_bprint_finalize(bprint, NULL); | |
| 2827 | ✗ | return ret; | |
| 2828 | } | ||
| 2829 |
1/2✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
|
101 | if (buf) { |
| 2830 |
2/2✓ Branch 0 taken 80 times.
✓ Branch 1 taken 21 times.
|
101 | if ((*cnt)++) |
| 2831 | 80 | av_bprint_append_data(bprint, &pairs_sep, 1); | |
| 2832 | 101 | av_bprint_escape(bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); | |
| 2833 | 101 | av_bprint_append_data(bprint, &key_val_sep, 1); | |
| 2834 | 101 | av_bprint_escape(bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0); | |
| 2835 | 101 | av_freep(&buf); | |
| 2836 | } | ||
| 2837 | } | ||
| 2838 | |||
| 2839 | 30 | return 0; | |
| 2840 | } | ||
| 2841 | |||
| 2842 | 21 | int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, | |
| 2843 | const char key_val_sep, const char pairs_sep) | ||
| 2844 | { | ||
| 2845 | AVBPrint bprint; | ||
| 2846 | 21 | int ret, cnt = 0; | |
| 2847 | |||
| 2848 |
4/8✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✗ Branch 7 not taken.
|
21 | if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep || |
| 2849 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | pairs_sep == '\\' || key_val_sep == '\\') { |
| 2850 | ✗ | av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found."); | |
| 2851 | ✗ | return AVERROR(EINVAL); | |
| 2852 | } | ||
| 2853 | |||
| 2854 |
2/4✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
|
21 | if (!obj || !buffer) |
| 2855 | ✗ | return AVERROR(EINVAL); | |
| 2856 | |||
| 2857 | 21 | *buffer = NULL; | |
| 2858 | 21 | av_bprint_init(&bprint, 64, AV_BPRINT_SIZE_UNLIMITED); | |
| 2859 | |||
| 2860 | 21 | ret = opt_serialize(obj, opt_flags, flags, &cnt, &bprint, | |
| 2861 | key_val_sep, pairs_sep); | ||
| 2862 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
| 2863 | ✗ | return ret; | |
| 2864 | |||
| 2865 | 21 | ret = av_bprint_finalize(&bprint, buffer); | |
| 2866 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
| 2867 | ✗ | return ret; | |
| 2868 | 21 | return 0; | |
| 2869 | } | ||
| 2870 |