# HG changeset patch # User michael # Date 1126448562 0 # Node ID b6def74f5811dc309894b5197bcfce98e2c78bc9 # Parent 55809f38eb63a61aba3f33566d09525da5fa68f5 flags and named constants with type checking of course for AVOption spliting AVOption specific stuff out of avcodec.h into opt.h diff -r 55809f38eb63 -r b6def74f5811 avcodec.h --- 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 /* 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. */ diff -r 55809f38eb63 -r b6def74f5811 opt.c --- 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 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; diff -r 55809f38eb63 -r b6def74f5811 opt.h --- /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 diff -r 55809f38eb63 -r b6def74f5811 utils.c --- 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},