Commit 860a40c8 authored by Michael Niedermayer's avatar Michael Niedermayer

AVOption first try

Originally committed as revision 4563 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent f926cbe7
......@@ -17,7 +17,8 @@ OBJS= bitstream.o utils.o mem.o allcodecs.o \
ratecontrol.o adpcm.o eval.o error_resilience.o \
fft.o mdct.o raw.o golomb.o cabac.o\
dpcm.o adx.o faandct.o parser.o g726.o \
vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o
vp3dsp.o h264idct.o rangecoder.o pnm.o h263.o msmpeg4.o h263dec.o dvdsub.o dvbsub.o dvbsubdec.o\
opt.o
ifeq ($(CONFIG_AASC_DECODER),yes)
OBJS+= aasc.o
......
......@@ -21,8 +21,8 @@ extern "C" {
#define AV_STRINGIFY(s) AV_TOSTRING(s)
#define AV_TOSTRING(s) #s
#define LIBAVCODEC_VERSION_INT ((49<<16)+(0<<8)+2)
#define LIBAVCODEC_VERSION 49.0.2
#define LIBAVCODEC_VERSION_INT ((49<<16)+(1<<8)+0)
#define LIBAVCODEC_VERSION 49.1.0
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION)
......@@ -671,6 +671,35 @@ typedef struct AVFrame {
#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;
} AVOption;
/**
* Used by av_log
*/
......@@ -681,6 +710,7 @@ struct AVCLASS {
or AVFormatContext, which begin with an AVClass.
Needed because av_log is in libavcodec and has no visibility
of AVIn/OutputFormat */
AVOption *option;
};
/**
......@@ -1847,41 +1877,13 @@ typedef struct AVCodecContext {
enum AVDiscard skip_frame;
} AVCodecContext;
int av_set_string(void *obj, const char *name, const char *val);
int av_set_double(void *obj, const char *name, double n);
int av_set_q(void *obj, const char *name, AVRational n);
int av_set_int(void *obj, const char *name, int64_t n);
const char *av_get_string(void *obj, const char *name);
double av_get_double(void *obj, const char *name);
/**
* AVOption.
*/
typedef struct AVOption {
/** options' name */
const char *name; /* if name is NULL, it indicates a link to next */
/** short English text help or const struct AVOption* subpointer */
const char *help; // const struct AVOption* sub;
/** offset to context structure where the parsed value should be stored */
int offset;
/** options' type */
int type;
#define FF_OPT_TYPE_BOOL 1 ///< boolean - true,1,on (or simply presence)
#define FF_OPT_TYPE_DOUBLE 2 ///< double
#define FF_OPT_TYPE_INT 3 ///< integer
#define FF_OPT_TYPE_STRING 4 ///< string (finished with \0)
#define FF_OPT_TYPE_MASK 0x1f ///< mask for types - upper bits are various flags
//#define FF_OPT_TYPE_EXPERT 0x20 // flag for expert option
#define FF_OPT_TYPE_FLAG (FF_OPT_TYPE_BOOL | 0x40)
#define FF_OPT_TYPE_RCOVERRIDE (FF_OPT_TYPE_STRING | 0x80)
/** min value (min == max -> no limits) */
double min;
/** maximum value for double/int */
double max;
/** default boo [0,1]l/double/int value */
double defval;
/**
* default string value (with optional semicolon delimited extra option-list
* i.e. option1;option2;option3
* defval might select other then first argument as default
*/
const char *defstr;
#define FF_OPT_MAX_DEPTH 10
} AVOption;
/**
* AVCodec.
......
/*
* AVOptions
* Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/**
* @file opt.c
* AVOptions
* @author Michael Niedermayer <michaelni@gmx.at>
*/
#include "avcodec.h"
static double av_parse_num(const char *name, char **tail){
double d;
d= strtod(name, tail);
if(*tail>name && (**tail=='/' || **tail==':'))
d/=strtod((*tail)+1, tail);
return d;
}
//FIXME order them and do a bin search
static AVOption *find_opt(void *v, const char *name){
AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
AVOption *o= c->option;
for(;o && o->name; o++){
if(!strcmp(o->name, name))
return o;
}
return NULL;
}
static int av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
AVOption *o= find_opt(obj, name);
void *dst;
if(!o || o->offset<=0)
return -1;
if(o->max*den < num*intnum || o->min*den > num*intnum)
return -1;
dst= ((uint8_t*)obj) + o->offset;
switch(o->type){
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;
case FF_OPT_TYPE_DOUBLE:
*(double*)dst= num*intnum/den;
break;
case FF_OPT_TYPE_RATIONAL:
if((int)num == num)
*(AVRational*)dst= (AVRational){num*intnum, den};
else
*(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
default:
return -1;
}
return 0;
}
//FIXME use eval.c maybe?
int av_set_string(void *obj, const char *name, const char *val){
AVOption *o= find_opt(obj, name);
if(!o || !val || o->offset<=0)
return -1;
if(o->type != FF_OPT_TYPE_STRING){
double d=0, tmp_d;
for(;;){
int i;
char buf[256], *tail;
for(i=0; i<sizeof(buf)-1 && 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{
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;
else return -1;
}
if(*val == '+') val++;
if(!*val)
return av_set_number(obj, name, d, 1, 1);
}
return -1;
}
memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val));
return 0;
}
int av_set_double(void *obj, const char *name, double n){
return av_set_number(obj, name, n, 1, 1);
}
int av_set_q(void *obj, const char *name, AVRational n){
return av_set_number(obj, name, n.num, n.den, 1);
}
int av_set_int(void *obj, const char *name, int64_t n){
return av_set_number(obj, name, 1, 1, n);
}
const char *av_get_string(void *obj, const char *name){
AVOption *o= find_opt(obj, name);
if(!o || o->offset<=0)
return NULL;
if(o->type != FF_OPT_TYPE_STRING) //FIXME convert to string? but what about free()?
return NULL;
return (const char*)(((uint8_t*)obj) + o->offset);
}
double av_get_double(void *obj, const char *name){
AVOption *o= find_opt(obj, name);
void *dst;
if(!o || o->offset<=0)
return NAN;
dst= ((uint8_t*)obj) + o->offset;
switch(o->type){
case FF_OPT_TYPE_INT: return *(int*)dst;
case FF_OPT_TYPE_INT64: return *(int64_t*)dst; //FIXME maybe write a av_get_int64() ?
case FF_OPT_TYPE_FLOAT: return *(float*)dst;
case FF_OPT_TYPE_DOUBLE: return *(double*)dst;
case FF_OPT_TYPE_RATIONAL: return av_q2d(*(AVRational*)dst); //FIXME maybe write a av_get_q() ?
default: return NAN;
}
}
This diff is collapsed.
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