MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_opt_set_array

Function av_opt_set_array

libavutil/opt.c:2287–2472  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2285}
2286
2287int av_opt_set_array(void *obj, const char *name, int search_flags,
2288 unsigned int start_elem, unsigned int nb_elems,
2289 enum AVOptionType val_type, const void *val)
2290{
2291 const size_t elem_size_val = opt_type_desc[TYPE_BASE(val_type)].size;
2292
2293 const AVOption *o;
2294 const AVOptionArrayDef *arr;
2295 void *target_obj;
2296
2297 void *parray;
2298 void *new_elems;
2299 unsigned *array_size, new_size;
2300 size_t elem_size;
2301
2302 int ret = 0;
2303
2304 ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &parray);
2305 if (ret < 0)
2306 return ret;
2307
2308 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) ||
2309 (val_type & AV_OPT_TYPE_FLAG_ARRAY))
2310 return AVERROR(EINVAL);
2311
2312 arr = o->default_val.arr;
2313 array_size = opt_array_pcount(parray);
2314 elem_size = opt_type_desc[TYPE_BASE(o->type)].size;
2315
2316 if (start_elem > *array_size)
2317 return AVERROR(EINVAL);
2318
2319 // compute new array size
2320 if (!val) {
2321 if (*array_size - start_elem < nb_elems)
2322 return AVERROR(EINVAL);
2323
2324 new_size = *array_size - nb_elems;
2325 } else if (search_flags & AV_OPT_ARRAY_REPLACE) {
2326 if (start_elem >= UINT_MAX - nb_elems)
2327 return AVERROR(EINVAL);
2328
2329 new_size = FFMAX(*array_size, start_elem + nb_elems);
2330 } else {
2331 if (nb_elems >= UINT_MAX - *array_size)
2332 return AVERROR(EINVAL);
2333
2334 new_size = *array_size + nb_elems;
2335 }
2336
2337 if (arr &&
2338 ((arr->size_max && new_size > arr->size_max) ||
2339 (arr->size_min && new_size < arr->size_min)))
2340 return AVERROR(EINVAL);
2341
2342 // desired operation is shrinking the array
2343 if (!val) {
2344 void *array = *(void**)parray;

Callers 5

lavfi_read_headerFunction · 0.85
configure_video_filtersFunction · 0.85
configure_audio_filtersFunction · 0.85
multiview_setupFunction · 0.85
init_filtersFunction · 0.85

Calls 12

opt_array_pcountFunction · 0.85
opt_free_elemFunction · 0.85
opt_array_pelemFunction · 0.85
av_realloc_arrayFunction · 0.85
av_freepFunction · 0.85
av_callocFunction · 0.85
opt_copy_elemFunction · 0.85
read_numberFunction · 0.85
av_logFunction · 0.85
opt_set_elemFunction · 0.85
write_numberFunction · 0.85
opt_free_arrayFunction · 0.85

Tested by

no test coverage detected