[FFmpeg-devel] [PATCH 1/4] avutil/opt: add opt_size()

Michael Niedermayer michaelni at gmx.at
Fri May 30 21:24:22 CEST 2014


If people want, this could be exported as av_opt_size()
---
 libavutil/opt.c |   22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index 199eadb..b4dd0fd 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -1517,6 +1517,28 @@ void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
     return (uint8_t*)obj + opt->offset;
 }
 
+static int opt_size(enum AVOptionType type)
+{
+    switch(type) {
+    case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_FLAGS:     return sizeof(int);
+    case AV_OPT_TYPE_DURATION:
+    case AV_OPT_TYPE_CHANNEL_LAYOUT:
+    case AV_OPT_TYPE_INT64:     return sizeof(int64_t);
+    case AV_OPT_TYPE_DOUBLE:    return sizeof(double);
+    case AV_OPT_TYPE_FLOAT:     return sizeof(float);
+    case AV_OPT_TYPE_STRING:    return sizeof(uint8_t*);
+    case AV_OPT_TYPE_VIDEO_RATE:
+    case AV_OPT_TYPE_RATIONAL:  return sizeof(AVRational);
+    case AV_OPT_TYPE_BINARY:    return sizeof(uint8_t*) + sizeof(int);
+    case AV_OPT_TYPE_IMAGE_SIZE:return sizeof(int[2]);
+    case AV_OPT_TYPE_PIXEL_FMT: return sizeof(enum AVPixelFormat);
+    case AV_OPT_TYPE_SAMPLE_FMT:return sizeof(enum AVSampleFormat);
+    case AV_OPT_TYPE_COLOR:     return 4;
+    }
+    return 0;
+}
+
 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
 {
     int ret;
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list