Commit f9e1e6b2 authored by stefano's avatar stefano

Implement av_set_string3().


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@16175 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 4fa5add3
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBAVCODEC_VERSION_MAJOR 52 #define LIBAVCODEC_VERSION_MAJOR 52
#define LIBAVCODEC_VERSION_MINOR 6 #define LIBAVCODEC_VERSION_MINOR 7
#define LIBAVCODEC_VERSION_MICRO 3 #define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
LIBAVCODEC_VERSION_MINOR, \ LIBAVCODEC_VERSION_MINOR, \
......
...@@ -107,10 +107,16 @@ static int hexchar2int(char c) { ...@@ -107,10 +107,16 @@ static int hexchar2int(char c) {
return -1; return -1;
} }
const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){ int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out){
int ret;
const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
if(!o || !val || o->offset<=0) if (o_out)
return NULL; *o_out = o;
if(!o)
return AVERROR(ENOENT);
if(!val || o->offset<=0)
return AVERROR(EINVAL);
if(o->type == FF_OPT_TYPE_BINARY){ if(o->type == FF_OPT_TYPE_BINARY){
uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset);
int *lendst = (int *)(dst + 1); int *lendst = (int *)(dst + 1);
...@@ -118,7 +124,7 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int ...@@ -118,7 +124,7 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int
int len = strlen(val); int len = strlen(val);
av_freep(dst); av_freep(dst);
*lendst = 0; *lendst = 0;
if (len & 1) return NULL; if (len & 1) return AVERROR(EINVAL);
len /= 2; len /= 2;
ptr = bin = av_malloc(len); ptr = bin = av_malloc(len);
while (*val) { while (*val) {
...@@ -126,13 +132,13 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int ...@@ -126,13 +132,13 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int
int b = hexchar2int(*val++); int b = hexchar2int(*val++);
if (a < 0 || b < 0) { if (a < 0 || b < 0) {
av_free(bin); av_free(bin);
return NULL; return AVERROR(EINVAL);
} }
*ptr++ = (a << 4) | b; *ptr++ = (a << 4) | b;
} }
*dst = bin; *dst = bin;
*lendst = len; *lendst = len;
return o; return 0;
} }
if(o->type != FF_OPT_TYPE_STRING){ if(o->type != FF_OPT_TYPE_STRING){
int notfirst=0; int notfirst=0;
...@@ -163,7 +169,7 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int ...@@ -163,7 +169,7 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int
else { else {
if (error) if (error)
av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error); av_log(NULL, AV_LOG_ERROR, "Unable to parse option value \"%s\": %s\n", val, error);
return NULL; return AVERROR(EINVAL);
} }
} }
if(o->type == FF_OPT_TYPE_FLAGS){ if(o->type == FF_OPT_TYPE_FLAGS){
...@@ -174,14 +180,14 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int ...@@ -174,14 +180,14 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int
else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d; else if(cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d;
} }
if (!av_set_number(obj, name, d, 1, 1)) if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0)
return NULL; return ret;
val+= i; val+= i;
if(!*val) if(!*val)
return o; return 0;
notfirst=1; notfirst=1;
} }
return NULL; return AVERROR(EINVAL);
} }
if(alloc){ if(alloc){
...@@ -190,6 +196,13 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int ...@@ -190,6 +196,13 @@ const AVOption *av_set_string2(void *obj, const char *name, const char *val, int
} }
memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
return 0;
}
const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
const AVOption *o;
if (av_set_string3(obj, name, val, alloc, &o) < 0)
return NULL;
return o; return o;
} }
......
...@@ -104,6 +104,14 @@ const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int m ...@@ -104,6 +104,14 @@ const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int m
*/ */
attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val); attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val);
/**
* @return a pointer to the AVOption corresponding to the field set or
* NULL if no matching AVOption exists, or if the value \p val is not
* valid
* @see av_set_string3()
*/
attribute_deprecated const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc);
/** /**
* Sets the field of obj with the given name to value. * Sets the field of obj with the given name to value.
* *
...@@ -120,14 +128,15 @@ attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, ...@@ -120,14 +128,15 @@ attribute_deprecated const AVOption *av_set_string(void *obj, const char *name,
* scalars or named flags separated by '+' or '-'. Prefixing a flag * scalars or named flags separated by '+' or '-'. Prefixing a flag
* with '+' causes it to be set without affecting the other flags; * with '+' causes it to be set without affecting the other flags;
* similarly, '-' unsets a flag. * similarly, '-' unsets a flag.
* @return a pointer to the AVOption corresponding to the field set or * @param[out] o_out if non-NULL put here a pointer to the AVOption
* NULL if no matching AVOption exists, or if the value \p val is not * found
* valid
* @param alloc when 1 then the old value will be av_freed() and the * @param alloc when 1 then the old value will be av_freed() and the
* new av_strduped() * new av_strduped()
* when 0 then no av_free() nor av_strdup() will be used * when 0 then no av_free() nor av_strdup() will be used
* @return 0 if the value has been set, an AVERROR* error code if no
* matching option exists, or if the value \p val is not valid
*/ */
const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc); int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
const AVOption *av_set_double(void *obj, const char *name, double n); const AVOption *av_set_double(void *obj, const char *name, double n);
const AVOption *av_set_q(void *obj, const char *name, AVRational n); const AVOption *av_set_q(void *obj, const char *name, AVRational n);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment