Browse code

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@martin.st>

Samuel Pitoiset authored on 2012/05/25 19:32:39
Showing 4 changed files
... ...
@@ -13,6 +13,9 @@ libavutil:     2011-04-18
13 13
 
14 14
 API changes, most recent first:
15 15
 
16
+2012-05-25 - e0e0793 - lavu 51.31.0 - opt.h
17
+  Add av_opt_set_bin()
18
+
16 19
 2012-05-xx - xxxxxxx - lavf 54.3.0
17 20
   Add AVFMT_TS_NONSTRICT format flag to indicate that a muxer supports
18 21
   non-increasing monotone timestamps.
... ...
@@ -152,7 +152,7 @@
152 152
  */
153 153
 
154 154
 #define LIBAVUTIL_VERSION_MAJOR 51
155
-#define LIBAVUTIL_VERSION_MINOR 30
155
+#define LIBAVUTIL_VERSION_MINOR 31
156 156
 #define LIBAVUTIL_VERSION_MICRO  0
157 157
 
158 158
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
... ...
@@ -316,6 +316,35 @@ int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
316 316
     return set_number(obj, name, val.num, val.den, 1, search_flags);
317 317
 }
318 318
 
319
+int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
320
+{
321
+    void *target_obj;
322
+    const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
323
+    uint8_t *ptr;
324
+    uint8_t **dst;
325
+    int *lendst;
326
+
327
+    if (!o || !target_obj)
328
+        return AVERROR_OPTION_NOT_FOUND;
329
+
330
+    if (o->type != AV_OPT_TYPE_BINARY)
331
+        return AVERROR(EINVAL);
332
+
333
+    ptr = av_malloc(len);
334
+    if (!ptr)
335
+        return AVERROR(ENOMEM);
336
+
337
+    dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
338
+    lendst = (int *)(dst + 1);
339
+
340
+    av_free(*dst);
341
+    *dst = ptr;
342
+    *lendst = len;
343
+    memcpy(ptr, val, len);
344
+
345
+    return 0;
346
+}
347
+
319 348
 #if FF_API_OLD_AVOPTIONS
320 349
 /**
321 350
  *
... ...
@@ -560,6 +560,7 @@ int av_opt_set       (void *obj, const char *name, const char *val, int search_f
560 560
 int av_opt_set_int   (void *obj, const char *name, int64_t     val, int search_flags);
561 561
 int av_opt_set_double(void *obj, const char *name, double      val, int search_flags);
562 562
 int av_opt_set_q     (void *obj, const char *name, AVRational  val, int search_flags);
563
+int av_opt_set_bin   (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
563 564
 /**
564 565
  * @}
565 566
  */