In order to support metadata being set as an option, it's necessary to be able to set dictionaries as values.
Unified · Split
| @@ -13,6 +13,10 @@ libavutil: 2014-08-09 · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | API changes, most recent first: | 14 | API changes, most recent first: |
| 15 | 15 | ||
| 16 | 2014-xx-xx - xxxxxxx - lavu 54.02.0 - opt.h | ||
| 17 | Add av_opt_get_dict_val/set_dict_val with AV_OPT_TYPE_DICT to support | ||
| 18 | dictionary types being set as options. | ||
| 19 | |||
| 16 | 2014-xx-xx - xxxxxxx - lavf 56.01.0 - avformat.h | 20 | 2014-xx-xx - xxxxxxx - lavf 56.01.0 - avformat.h |
| 17 | Add AVFormatContext.event_flags and AVStream.event_flags for signaling to | 21 | Add AVFormatContext.event_flags and AVStream.event_flags for signaling to |
| 18 | the user when events happen in the file/stream. | 22 | the user when events happen in the file/stream. |
| @@ -307,6 +307,24 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int · 306 unmodified lines | |||
| 307 | return 0; | 307 | return 0; |
| 308 | } | 308 | } |
| 309 | 309 | ||
| 310 | int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags) | ||
| 311 | { | ||
| 312 | void *target_obj; | ||
| 313 | AVDictionary **dst; | ||
| 314 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | ||
| 315 | |||
| 316 | if (!o || !target_obj) | ||
| 317 | return AVERROR_OPTION_NOT_FOUND; | ||
| 318 | if (o->flags & AV_OPT_FLAG_READONLY) | ||
| 319 | return AVERROR(EINVAL); | ||
| 320 | |||
| 321 | dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset); | ||
| 322 | av_dict_free(dst); | ||
| 323 | av_dict_copy(dst, val, 0); | ||
| 324 | |||
| 325 | return 0; | ||
| 326 | } | ||
| 327 | |||
| 310 | int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) | 328 | int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) |
| 311 | { | 329 | { |
| 312 | void *dst, *target_obj; | 330 | void *dst, *target_obj; |
| @@ -410,6 +428,23 @@ int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_ · 97 unmodified lines | |||
| 410 | return 0; | 428 | return 0; |
| 411 | } | 429 | } |
| 412 | 430 | ||
| 431 | int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val) | ||
| 432 | { | ||
| 433 | void *target_obj; | ||
| 434 | AVDictionary *src; | ||
| 435 | const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); | ||
| 436 | |||
| 437 | if (!o || !target_obj) | ||
| 438 | return AVERROR_OPTION_NOT_FOUND; | ||
| 439 | if (o->type != AV_OPT_TYPE_DICT) | ||
| 440 | return AVERROR(EINVAL); | ||
| 441 | |||
| 442 | src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset); | ||
| 443 | av_dict_copy(out_val, src, 0); | ||
| 444 | |||
| 445 | return 0; | ||
| 446 | } | ||
| 447 | |||
| 413 | int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) | 448 | int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) |
| 414 | { | 449 | { |
| 415 | const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); | 450 | const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); |
| @@ -539,7 +574,8 @@ void av_opt_set_defaults(void *s) · 123 unmodified lines | |||
| 539 | av_opt_set(s, opt->name, opt->default_val.str, 0); | 574 | av_opt_set(s, opt->name, opt->default_val.str, 0); |
| 540 | break; | 575 | break; |
| 541 | case AV_OPT_TYPE_BINARY: | 576 | case AV_OPT_TYPE_BINARY: |
| 542 | /* Cannot set default for binary */ | 577 | case AV_OPT_TYPE_DICT: |
| 578 | /* Cannot set defaults for these types */ | ||
| 543 | break; | 579 | break; |
| 544 | default: | 580 | default: |
| 545 | av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); | 581 | av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); |
| @@ -621,9 +657,21 @@ int av_set_options_string(void *ctx, const char *opts, · 75 unmodified lines | |||
| 621 | void av_opt_free(void *obj) | 657 | void av_opt_free(void *obj) |
| 622 | { | 658 | { |
| 623 | const AVOption *o = NULL; | 659 | const AVOption *o = NULL; |
| 624 | while ((o = av_opt_next(obj, o))) | 660 | while ((o = av_opt_next(obj, o))) { |
| 625 | if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY) | 661 | switch (o->type) { |
| 662 | case AV_OPT_TYPE_STRING: | ||
| 663 | case AV_OPT_TYPE_BINARY: | ||
| 626 | av_freep((uint8_t *)obj + o->offset); | 664 | av_freep((uint8_t *)obj + o->offset); |
| 665 | break; | ||
| 666 | |||
| 667 | case AV_OPT_TYPE_DICT: | ||
| 668 | av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset)); | ||
| 669 | break; | ||
| 670 | |||
| 671 | default: | ||
| 672 | break; | ||
| 673 | } | ||
| 674 | } | ||
| 627 | } | 675 | } |
| 628 | 676 | ||
| 629 | int av_opt_set_dict(void *obj, AVDictionary **options) | 677 | int av_opt_set_dict(void *obj, AVDictionary **options) |
| @@ -224,6 +224,7 @@ enum AVOptionType{ · 223 unmodified lines | |||
| 224 | AV_OPT_TYPE_STRING, | 224 | AV_OPT_TYPE_STRING, |
| 225 | AV_OPT_TYPE_RATIONAL, | 225 | AV_OPT_TYPE_RATIONAL, |
| 226 | AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length | 226 | AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length |
| 227 | AV_OPT_TYPE_DICT, | ||
| 227 | AV_OPT_TYPE_CONST = 128, | 228 | AV_OPT_TYPE_CONST = 128, |
| 228 | }; | 229 | }; |
| 229 | 230 | ||
| @@ -325,7 +326,7 @@ int av_set_options_string(void *ctx, const char *opts, · 95 unmodified lines | |||
| 325 | const char *key_val_sep, const char *pairs_sep); | 326 | const char *key_val_sep, const char *pairs_sep); |
| 326 | 327 | ||
| 327 | /** | 328 | /** |
| 328 | * Free all string and binary options in obj. | 329 | * Free all allocated objects in obj. |
| 329 | */ | 330 | */ |
| 330 | void av_opt_free(void *obj); | 331 | void av_opt_free(void *obj); |
| 331 | 332 | ||
| @@ -491,11 +492,16 @@ const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *pre · 159 unmodified lines | |||
| 491 | * AVERROR(ERANGE) if the value is out of range | 492 | * AVERROR(ERANGE) if the value is out of range |
| 492 | * AVERROR(EINVAL) if the value is not valid | 493 | * AVERROR(EINVAL) if the value is not valid |
| 493 | */ | 494 | */ |
| 494 | int av_opt_set (void *obj, const char *name, const char *val, int search_flags); | 495 | int av_opt_set (void *obj, const char *name, const char *val, int search_flags); |
| 495 | int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags); | 496 | int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags); |
| 496 | int av_opt_set_double(void *obj, const char *name, double val, int search_flags); | 497 | int av_opt_set_double (void *obj, const char *name, double val, int search_flags); |
| 497 | int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags); | 498 | int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags); |
| 498 | int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags); | 499 | int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags); |
| 500 | /** | ||
| 501 | * @note Any old dictionary present is discarded and replaced with a copy of the new one. The | ||
| 502 | * caller still owns val is and responsible for freeing it. | ||
| 503 | */ | ||
| 504 | int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags); | ||
| 499 | /** | 505 | /** |
| 500 | * @} | 506 | * @} |
| 501 | */ | 507 | */ |
| @@ -515,10 +521,15 @@ int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, · 13 unmodified lines | |||
| 515 | /** | 521 | /** |
| 516 | * @note the returned string will av_malloc()ed and must be av_free()ed by the caller | 522 | * @note the returned string will av_malloc()ed and must be av_free()ed by the caller |
| 517 | */ | 523 | */ |
| 518 | int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val); | 524 | int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val); |
| 519 | int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val); | 525 | int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val); |
| 520 | int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val); | 526 | int av_opt_get_double (void *obj, const char *name, int search_flags, double *out_val); |
| 521 | int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val); | 527 | int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val); |
| 528 | /** | ||
| 529 | * @param[out] out_val The returned dictionary is a copy of the actual value and must | ||
| 530 | * be freed with av_dict_free() by the caller | ||
| 531 | */ | ||
| 532 | int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val); | ||
| 522 | /** | 533 | /** |
| 523 | * @} | 534 | * @} |
| 524 | * @} | 535 | * @} |
| @@ -54,7 +54,7 @@ · 53 unmodified lines | |||
| 54 | */ | 54 | */ |
| 55 | 55 | ||
| 56 | #define LIBAVUTIL_VERSION_MAJOR 54 | 56 | #define LIBAVUTIL_VERSION_MAJOR 54 |
| 57 | #define LIBAVUTIL_VERSION_MINOR 1 | 57 | #define LIBAVUTIL_VERSION_MINOR 2 |
| 58 | #define LIBAVUTIL_VERSION_MICRO 0 | 58 | #define LIBAVUTIL_VERSION_MICRO 0 |
| 59 | 59 | ||
| 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |