]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/opt.c
R and B components are stored as a differences to G component in Fraps v5.
[ffmpeg] / libavcodec / opt.c
index 70f2f3d91f9d88ff08513a24d901efc70a4b4a55..acf94ba824043e971e57bee15fee019d56050cee 100644 (file)
@@ -94,14 +94,14 @@ static const AVOption *set_all_opt(void *v, const char *unit, double d){
     return ret;
 }
 
-static double const_values[]={
+static const double const_values[]={
     M_PI,
     M_E,
     FF_QP2LAMBDA,
     0
 };
 
-static const char *const_names[]={
+static const char * const const_names[]={
     "PI",
     "E",
     "QP2LAMBDA",
@@ -115,7 +115,7 @@ static int hexchar2int(char c) {
     return -1;
 }
 
-const AVOption *av_set_string(void *obj, const char *name, const char *val){
+const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){
     const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
     if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
         return set_all_opt(obj, o->unit, o->default_val);
@@ -146,6 +146,7 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){
         return o;
     }
     if(o->type != FF_OPT_TYPE_STRING){
+        int notfirst=0;
         for(;;){
             int i;
             char buf[256];
@@ -180,8 +181,8 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){
                 if     (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
                 else if(cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
             }else{
-                if     (cmd=='+') d= av_get_double(obj, name, NULL) + d;
-                else if(cmd=='-') d= av_get_double(obj, name, NULL) - d;
+                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))
@@ -189,14 +190,24 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){
             val+= i;
             if(!*val)
                 return o;
+            notfirst=1;
         }
         return NULL;
     }
 
+    if(alloc){
+        av_free(*(void**)(((uint8_t*)obj) + o->offset));
+        val= av_strdup(val);
+    }
+
     memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
     return o;
 }
 
+const AVOption *av_set_string(void *obj, const char *name, const char *val){
+    return av_set_string2(obj, name, val, 0);
+}
+
 const AVOption *av_set_double(void *obj, const char *name, double n){
     return av_set_number(obj, name, n, 1, 1);
 }