aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2014-02-15 08:24:23 +0100
committerAnton Khirnov <anton@khirnov.net>2014-02-19 21:52:17 +0100
commitc3ecd968f0e78da6e77f0c06c2f785b266d83cf1 (patch)
tree88a439d1877ec9f8e3736c824d00f37bd9a9028d
parent6bb8720f00e2e6209665f819fb351fd42b82d5d0 (diff)
downloadffmpeg-c3ecd968f0e78da6e77f0c06c2f785b266d83cf1.tar.gz
AVOptions: add flags for read/read-only options
-rw-r--r--doc/APIchanges4
-rw-r--r--libavutil/opt.c14
-rw-r--r--libavutil/opt.h9
-rw-r--r--libavutil/version.h4
4 files changed, 26 insertions, 5 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index e25728a568..d8f5f51b90 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2013-12-xx
API changes, most recent first:
+2014-xx-xx - xxxxxxx - lavu 53.04.0 - opt.h
+ Add AV_OPT_FLAG_EXPORT and AV_OPT_FLAG_READONLY to mark options meant (only)
+ for reading.
+
2014-xx-xx - xxxxxxx - lavu 53.03.01 - opt.h
Deprecate unused AV_OPT_FLAG_METADATA.
diff --git a/libavutil/opt.c b/libavutil/opt.c
index ede4a49abe..9f9f1f2fe1 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -213,7 +213,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (!val)
+ if (!val || o->flags & AV_OPT_FLAG_READONLY)
return AVERROR(EINVAL);
dst = ((uint8_t*)target_obj) + o->offset;
@@ -235,7 +235,7 @@ int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
#define OPT_EVAL_NUMBER(name, opttype, vartype)\
int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
{\
- if (!o || o->type != opttype)\
+ if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
return AVERROR(EINVAL);\
return set_string_number(obj, obj, o, val, name ## _out);\
}
@@ -256,6 +256,9 @@ static int set_number(void *obj, const char *name, double num, int den, int64_t
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
+ if (o->flags & AV_OPT_FLAG_READONLY)
+ return AVERROR(EINVAL);
+
dst = ((uint8_t*)target_obj) + o->offset;
return write_number(obj, o, dst, num, den, intnum);
}
@@ -286,7 +289,7 @@ int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int
if (!o || !target_obj)
return AVERROR_OPTION_NOT_FOUND;
- if (o->type != AV_OPT_TYPE_BINARY)
+ if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
return AVERROR(EINVAL);
ptr = av_malloc(len);
@@ -479,6 +482,8 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.');
+ av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.');
if (opt->help)
av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
@@ -505,6 +510,9 @@ void av_opt_set_defaults(void *s)
{
const AVOption *opt = NULL;
while ((opt = av_opt_next(s, opt)) != NULL) {
+ if (opt->flags & AV_OPT_FLAG_READONLY)
+ continue;
+
switch (opt->type) {
case AV_OPT_TYPE_CONST:
/* Nothing to be done here */
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 2568a7103e..b90feaad8f 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -268,6 +268,15 @@ typedef struct AVOption {
#define AV_OPT_FLAG_AUDIO_PARAM 8
#define AV_OPT_FLAG_VIDEO_PARAM 16
#define AV_OPT_FLAG_SUBTITLE_PARAM 32
+/**
+ * The option is inteded for exporting values to the caller.
+ */
+#define AV_OPT_FLAG_EXPORT 64
+/**
+ * The option may not be set through the AVOptions API, only read.
+ * This flag only makes sense when AV_OPT_FLAG_EXPORT is also set.
+ */
+#define AV_OPT_FLAG_READONLY 128
//FIXME think about enc-audio, ... style flags
/**
diff --git a/libavutil/version.h b/libavutil/version.h
index 74946d0f5c..fd33bf5348 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,8 +54,8 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 53
-#define LIBAVUTIL_VERSION_MINOR 3
-#define LIBAVUTIL_VERSION_MICRO 1
+#define LIBAVUTIL_VERSION_MINOR 4
+#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \