opt: Add av_opt_set_bin()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 25 May 2012 10:32:39 +0000 (12:32 +0200)
committerMartin Storsjö <martin@martin.st>
Sat, 26 May 2012 11:31:44 +0000 (14:31 +0300)
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@martin.st>
doc/APIchanges
libavutil/avutil.h
libavutil/opt.c
libavutil/opt.h

index 18105c55ba0ff5f32c5b5e2358743bb17d38782e..dca33aa0eb5670e451ceaeff308e6cae89014801 100644 (file)
@@ -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.
index 3e51357ae6a49fca8055c830884de96d29f30fda..1c8e0767df3287e5973f5340b32cb924eb473637 100644 (file)
  */
 
 #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, \
index 7c53024d251e7ed8963a275f60f4714d5e5f8436..af8df7a2eb102c53de2ce8087cef8a6d6345a782 100644 (file)
@@ -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
 /**
  *
index 19549408e2e3df94e7059b24a25e367211920c60..8f800fcf988144397fa454b565b3c511c45b3d9e 100644 (file)
@@ -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);
 /**
  * @}
  */