History

AVOption: add support for dictionary types.

In order to support metadata being set as an option, it's necessary to be able to set dictionaries as values.

Andrew Stone committed 12 years ago

Commit a8c104a1 parent afbd4b74 files · +77 −14Browse files

Unified · Split

4 files
  1. doc/APIchanges +4 −0
  2. libavutil/opt.c +51 −3
  3. libavutil/opt.h +21 −10
  4. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2014-08-09 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
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+
1620 2014-xx-xx - xxxxxxx - lavf 56.01.0 - avformat.h
1721 Add AVFormatContext.event_flags and AVStream.event_flags for signaling to
1822 the user when events happen in the file/stream.
libavutil/opt.c+51−3
@@ -307,6 +307,24 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int · 306 unmodified lines
307307 return 0;
308308 }
309309
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+
310328 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
311329 {
312330 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
410428 return 0;
411429 }
412430
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+
413448 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
414449 {
415450 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
539574 av_opt_set(s, opt->name, opt->default_val.str, 0);
540575 break;
541576 case AV_OPT_TYPE_BINARY:
542− /* Cannot set default for binary */
577+ case AV_OPT_TYPE_DICT:
578+ /* Cannot set defaults for these types */
543579 break;
544580 default:
545581 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
621657 void av_opt_free(void *obj)
622658 {
623659 const AVOption *o = NULL;
624− while ((o = av_opt_next(obj, o)))
625− if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY)
660+ while ((o = av_opt_next(obj, o))) {
661+ switch (o->type) {
662+ case AV_OPT_TYPE_STRING:
663+ case AV_OPT_TYPE_BINARY:
626664 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+ }
627675 }
628676
629677 int av_opt_set_dict(void *obj, AVDictionary **options)
libavutil/opt.h+21−10
@@ -224,6 +224,7 @@ enum AVOptionType{ · 223 unmodified lines
224224 AV_OPT_TYPE_STRING,
225225 AV_OPT_TYPE_RATIONAL,
226226 AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
227+ AV_OPT_TYPE_DICT,
227228 AV_OPT_TYPE_CONST = 128,
228229 };
229230
@@ -325,7 +326,7 @@ int av_set_options_string(void *ctx, const char *opts, · 95 unmodified lines
325326 const char *key_val_sep, const char *pairs_sep);
326327
327328 /**
328− * Free all string and binary options in obj.
329+ * Free all allocated objects in obj.
329330 */
330331 void av_opt_free(void *obj);
331332
@@ -491,11 +492,16 @@ const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *pre · 159 unmodified lines
491492 * AVERROR(ERANGE) if the value is out of range
492493 * AVERROR(EINVAL) if the value is not valid
493494 */
494−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_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_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
495+int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
496+int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
497+int av_opt_set_double (void *obj, const char *name, double val, int search_flags);
498+int av_opt_set_q (void *obj, const char *name, AVRational val, 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);
499505 /**
500506 * @}
501507 */
@@ -515,10 +521,15 @@ int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, · 13 unmodified lines
515521 /**
516522 * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
517523 */
518−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);
520−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);
524+int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
525+int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
526+int av_opt_get_double (void *obj, const char *name, int search_flags, double *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);
522533 /**
523534 * @}
524535 * @}
libavutil/version.h+1−1
@@ -54,7 +54,7 @@ · 53 unmodified lines
5454 */
5555
5656 #define LIBAVUTIL_VERSION_MAJOR 54
57−#define LIBAVUTIL_VERSION_MINOR 1
57+#define LIBAVUTIL_VERSION_MINOR 2
5858 #define LIBAVUTIL_VERSION_MICRO 0
5959
6060 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t