From 154486f9adc621e620dacd76d78c30a02cc1dcd3 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 25 May 2012 12:32:39 +0200 Subject: opt: Add av_opt_set_bin() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ö --- libavutil/opt.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'libavutil/opt.c') diff --git a/libavutil/opt.c b/libavutil/opt.c index 7c53024d25..af8df7a2eb 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 /** * -- cgit v1.2.3