changeset 2874:b6def74f5811 libavcodec

flags and named constants with type checking of course for AVOption spliting AVOption specific stuff out of avcodec.h into opt.h
author michael
date Sun, 11 Sep 2005 14:22:42 +0000
parents 55809f38eb63
children 1021498a5159
files avcodec.h opt.c opt.h utils.c
diffstat 4 files changed, 92 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/avcodec.h	Sun Sep 11 11:10:25 2005 +0000
+++ b/avcodec.h	Sun Sep 11 14:22:42 2005 +0000
@@ -12,6 +12,7 @@
 #endif
 
 #include "avutil.h"
+#include "opt.h"
 #include <sys/types.h> /* size_t */
 
 //FIXME the following 2 really dont belong in here
@@ -671,44 +672,6 @@
 
 #define DEFAULT_FRAME_RATE_BASE 1001000
 
-enum AVOptionType{
-    FF_OPT_TYPE_INT,
-    FF_OPT_TYPE_INT64,
-    FF_OPT_TYPE_DOUBLE,
-    FF_OPT_TYPE_FLOAT,
-    FF_OPT_TYPE_STRING,
-    FF_OPT_TYPE_RATIONAL,
-    FF_OPT_TYPE_CONST=128,
-};
-
-/**
- * AVOption.
- */
-typedef struct AVOption {
-    const char *name;
-
-    /**
-     * short English text help.
-     * @fixme what about other languages
-     */
-    const char *help;
-    int offset;             ///< offset to context structure where the parsed value should be stored 
-    enum AVOptionType type;
-    
-    double default_val;
-    double min;
-    double max;
-    
-    int flags;
-#define AV_OPT_FLAG_ENCODING_PARAM  1   ///< a generic parameter which can be set by the user for muxing or encoding
-#define AV_OPT_FLAG_DECODING_PARAM  2   ///< a generic parameter which can be set by the user for demuxing or decoding
-#define AV_OPT_FLAG_METADATA        4   ///< some data extracted or inserted into the file like title, comment, ...
-#define AV_OPT_FLAG_AUDIO_PARAM     8
-#define AV_OPT_FLAG_VIDEO_PARAM     16
-#define AV_OPT_FLAG_SUBTITLE_PARAM  32
-//FIXME think about enc-audio, ... style flags
-} AVOption;
-
 /**
  * Used by av_log
  */
@@ -1887,17 +1850,6 @@
     enum AVDiscard skip_frame;
 } AVCodecContext;
 
-AVOption *av_set_string(void *obj, const char *name, const char *val);
-AVOption *av_set_double(void *obj, const char *name, double n);
-AVOption *av_set_q(void *obj, const char *name, AVRational n);
-AVOption *av_set_int(void *obj, const char *name, int64_t n);
-double av_get_double(void *obj, const char *name, AVOption **o_out);
-AVRational av_get_q(void *obj, const char *name, AVOption **o_out);
-int64_t av_get_int(void *obj, const char *name, AVOption **o_out);
-const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len);
-AVOption *av_next_option(void *obj, AVOption *last);
-int av_opt_show(void *obj, FILE *f);
-
 /**
  * AVCodec.
  */
--- a/opt.c	Sun Sep 11 11:10:25 2005 +0000
+++ b/opt.c	Sun Sep 11 14:22:42 2005 +0000
@@ -64,6 +64,7 @@
     dst= ((uint8_t*)obj) + o->offset;
 
     switch(o->type){
+    case FF_OPT_TYPE_FLAGS:   
     case FF_OPT_TYPE_INT:   *(int       *)dst= lrintf(num/den)*intnum; break;
     case FF_OPT_TYPE_INT64: *(int64_t   *)dst= lrintf(num/den)*intnum; break;
     case FF_OPT_TYPE_FLOAT: *(float     *)dst= num*intnum/den;         break;
@@ -83,32 +84,39 @@
     if(!o || !val || o->offset<=0) 
         return NULL;
     if(o->type != FF_OPT_TYPE_STRING){
-        double d=0, tmp_d;
         for(;;){
             int i;
             char buf[256], *tail;
+            int cmd=0;
+            double d;
 
-            for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+'; i++)
+            if(*val == '+' || *val == '-')
+                cmd= *(val++);
+            
+            for(i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++)
                 buf[i]= val[i];
             buf[i]=0;
             val+= i;
             
-            tmp_d= av_parse_num(buf, &tail);
-            if(tail > buf)
-                d+= tmp_d;
-            else{
+            d= av_parse_num(buf, &tail);
+            if(tail <= buf){
                 AVOption *o_named= find_opt(obj, buf);
-                if(o_named && o_named->type == FF_OPT_TYPE_CONST) 
-                    d+= o_named->default_val;
-                else if(!strcmp(buf, "default")) d+= o->default_val;
-                else if(!strcmp(buf, "max"    )) d+= o->max;
-                else if(!strcmp(buf, "min"    )) d+= o->min;
+                if(o_named && o_named->type == FF_OPT_TYPE_CONST && !strcmp(o_named->unit, o->unit)) 
+                    d= o_named->default_val;
+                else if(!strcmp(buf, "default")) d= o->default_val;
+                else if(!strcmp(buf, "max"    )) d= o->max;
+                else if(!strcmp(buf, "min"    )) d= o->min;
                 else return NULL;
             }
+            if(o->type == FF_OPT_TYPE_FLAGS){
+                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= -d;
 
-            if(*val == '+') val++;
+            av_set_number(obj, name, d, 1, 1);
             if(!*val)
-                return av_set_number(obj, name, d, 1, 1);
+                return o;
         }
         return NULL;
     }
@@ -149,6 +157,7 @@
         return dst;
     
     switch(o->type){
+    case FF_OPT_TYPE_FLAGS:     snprintf(buf, buf_len, "0x%08X",*(int    *)dst);break;
     case FF_OPT_TYPE_INT:       snprintf(buf, buf_len, "%d" , *(int    *)dst);break;
     case FF_OPT_TYPE_INT64:     snprintf(buf, buf_len, "%Ld", *(int64_t*)dst);break;
     case FF_OPT_TYPE_FLOAT:     snprintf(buf, buf_len, "%f" , *(float  *)dst);break;
@@ -170,6 +179,7 @@
     if(o_out) *o_out= o;
 
     switch(o->type){
+    case FF_OPT_TYPE_FLAGS:   
     case FF_OPT_TYPE_INT:       *intnum= *(int    *)dst;return 0;
     case FF_OPT_TYPE_INT64:     *intnum= *(int64_t*)dst;return 0;
     case FF_OPT_TYPE_FLOAT:     *num=    *(float  *)dst;return 0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/opt.h	Sun Sep 11 14:22:42 2005 +0000
@@ -0,0 +1,61 @@
+#ifndef AVOPT_H
+#define AVOPT_H
+
+/**
+ * @file opt.h
+ * AVOptions
+ */
+
+enum AVOptionType{
+    FF_OPT_TYPE_FLAGS,
+    FF_OPT_TYPE_INT,
+    FF_OPT_TYPE_INT64,
+    FF_OPT_TYPE_DOUBLE,
+    FF_OPT_TYPE_FLOAT,
+    FF_OPT_TYPE_STRING,
+    FF_OPT_TYPE_RATIONAL,
+    FF_OPT_TYPE_CONST=128,
+};
+
+/**
+ * AVOption.
+ */
+typedef struct AVOption {
+    const char *name;
+
+    /**
+     * short English text help.
+     * @fixme what about other languages
+     */
+    const char *help;
+    int offset;             ///< offset to context structure where the parsed value should be stored 
+    enum AVOptionType type;
+    
+    double default_val;
+    double min;
+    double max;
+    
+    int flags;
+#define AV_OPT_FLAG_ENCODING_PARAM  1   ///< a generic parameter which can be set by the user for muxing or encoding
+#define AV_OPT_FLAG_DECODING_PARAM  2   ///< a generic parameter which can be set by the user for demuxing or decoding
+#define AV_OPT_FLAG_METADATA        4   ///< some data extracted or inserted into the file like title, comment, ...
+#define AV_OPT_FLAG_AUDIO_PARAM     8
+#define AV_OPT_FLAG_VIDEO_PARAM     16
+#define AV_OPT_FLAG_SUBTITLE_PARAM  32
+//FIXME think about enc-audio, ... style flags
+    const char *unit;
+} AVOption;
+
+
+AVOption *av_set_string(void *obj, const char *name, const char *val);
+AVOption *av_set_double(void *obj, const char *name, double n);
+AVOption *av_set_q(void *obj, const char *name, AVRational n);
+AVOption *av_set_int(void *obj, const char *name, int64_t n);
+double av_get_double(void *obj, const char *name, AVOption **o_out);
+AVRational av_get_q(void *obj, const char *name, AVOption **o_out);
+int64_t av_get_int(void *obj, const char *name, AVOption **o_out);
+const char *av_get_string(void *obj, const char *name, AVOption **o_out, char *buf, int buf_len);
+AVOption *av_next_option(void *obj, AVOption *last);
+int av_opt_show(void *obj, FILE *f);
+
+#endif
--- a/utils.c	Sun Sep 11 11:10:25 2005 +0000
+++ b/utils.c	Sun Sep 11 14:22:42 2005 +0000
@@ -447,9 +447,12 @@
 static AVOption options[]={
 {"bit_rate", NULL, OFFSET(bit_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
 {"bit_rate_tolerance", NULL, OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, //FIXME
+{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "flags"},
+{"MV4", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
+{"OBMC", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
+{"QPEL", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
 {"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
-{"me_method", NULL, OFFSET(me_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
+{"me_method", NULL, OFFSET(me_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "me_method"},
 {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
 {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
 {"gop_size", NULL, OFFSET(gop_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
@@ -519,7 +522,8 @@
 {"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
 {"prediction_method", NULL, OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 {"aspect", NULL, OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX, V|E},
-{"debug", NULL, OFFSET(debug), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|S|E|D},
+{"debug", NULL, OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|S|E|D, "debug"},
+{"PICT", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|E, "debug"},
 {"debug_mv", NULL, OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
 {"mb_qmin", NULL, OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
 {"mb_qmax", NULL, OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},