[FFmpeg-cvslog] opt: Add av_opt_set_bin()

Samuel Pitoiset git at videolan.org
Sat May 26 22:41:53 CEST 2012


ffmpeg | branch: master | Samuel Pitoiset <samuel.pitoiset at gmail.com> | Fri May 25 12:32:39 2012 +0200| [154486f9adc621e620dacd76d78c30a02cc1dcd3] | committer: Martin Storsjö

opt: Add av_opt_set_bin()

Introduce a new function to set binary data through AVOption,
avoiding having to convert the binary data to a string inbetween.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=154486f9adc621e620dacd76d78c30a02cc1dcd3
---

 doc/APIchanges     |    3 +++
 libavutil/avutil.h |    2 +-
 libavutil/opt.c    |   29 +++++++++++++++++++++++++++++
 libavutil/opt.h    |    1 +
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 18105c5..dca33aa 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2011-04-18
 
 API changes, most recent first:
 
+2012-05-25 - e0e0793 - lavu 51.31.0 - opt.h
+  Add av_opt_set_bin()
+
 2012-05-xx - xxxxxxx - lavf 54.3.0
   Add AVFMT_TS_NONSTRICT format flag to indicate that a muxer supports
   non-increasing monotone timestamps.
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 3e51357..1c8e076 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -152,7 +152,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 51
-#define LIBAVUTIL_VERSION_MINOR 30
+#define LIBAVUTIL_VERSION_MINOR 31
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
diff --git a/libavutil/opt.c b/libavutil/opt.c
index 7c53024..af8df7a 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -316,6 +316,35 @@ int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
     return set_number(obj, name, val.num, val.den, 1, search_flags);
 }
 
+int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
+{
+    void *target_obj;
+    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
+    uint8_t *ptr;
+    uint8_t **dst;
+    int *lendst;
+
+    if (!o || !target_obj)
+        return AVERROR_OPTION_NOT_FOUND;
+
+    if (o->type != AV_OPT_TYPE_BINARY)
+        return AVERROR(EINVAL);
+
+    ptr = av_malloc(len);
+    if (!ptr)
+        return AVERROR(ENOMEM);
+
+    dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
+    lendst = (int *)(dst + 1);
+
+    av_free(*dst);
+    *dst = ptr;
+    *lendst = len;
+    memcpy(ptr, val, len);
+
+    return 0;
+}
+
 #if FF_API_OLD_AVOPTIONS
 /**
  *
diff --git a/libavutil/opt.h b/libavutil/opt.h
index 1954940..8f800fc 100644
--- a/libavutil/opt.h
+++ b/libavutil/opt.h
@@ -560,6 +560,7 @@ int av_opt_set       (void *obj, const char *name, const char *val, int search_f
 int av_opt_set_int   (void *obj, const char *name, int64_t     val, int search_flags);
 int av_opt_set_double(void *obj, const char *name, double      val, int search_flags);
 int av_opt_set_q     (void *obj, const char *name, AVRational  val, int search_flags);
+int av_opt_set_bin   (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
 /**
  * @}
  */



More information about the ffmpeg-cvslog mailing list