diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2011-05-01 00:21:56 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-05-01 00:26:05 +0200 |
commit | ffb5a0d533498102c31aa131bc91a4cce868b0a8 (patch) | |
tree | 1c78494488bab5bafa3bda2ab20295f13860fc2e /libavutil | |
parent | 1a9f9f81b1244b952126bb65bc741b04d3534f81 (diff) | |
parent | 85770f2a2651497861ed938efcd0df3696ff5e45 (diff) | |
download | ffmpeg-ffb5a0d533498102c31aa131bc91a4cce868b0a8.tar.gz |
Merge commit '85770f2a2651497861ed938efcd0df3696ff5e45'
* commit '85770f2a2651497861ed938efcd0df3696ff5e45':
AVOptions: make default_val a union, as proposed in AVOption2.
Move ff_dynarray_add to lavu and make it public.
lavf: remove duplicate assignment in avformat_alloc_context.
lavf: use designated initializers for AVClasses.
options: simplify av_find_opt by using av_next_option.
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/avutil.h | 2 | ||||
-rw-r--r-- | libavutil/mem.c | 20 | ||||
-rw-r--r-- | libavutil/mem.h | 9 | ||||
-rw-r--r-- | libavutil/opt.c | 19 | ||||
-rw-r--r-- | libavutil/opt.h | 52 |
5 files changed, 40 insertions, 62 deletions
diff --git a/libavutil/avutil.h b/libavutil/avutil.h index b0462f1d91..83a559d7ce 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -40,7 +40,7 @@ #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 1 +#define LIBAVUTIL_VERSION_MINOR 2 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/mem.c b/libavutil/mem.c index f0f18d1ce9..965daa93c8 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -173,3 +173,23 @@ char *av_strdup(const char *s) return ptr; } +/* add one element to a dynamic array */ +void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem) +{ + /* see similar ffmpeg.c:grow_array() */ + int nb, nb_alloc; + intptr_t *tab; + + nb = *nb_ptr; + tab = *(intptr_t**)tab_ptr; + if ((nb & (nb - 1)) == 0) { + if (nb == 0) + nb_alloc = 1; + else + nb_alloc = nb * 2; + tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); + *(intptr_t**)tab_ptr = tab; + } + tab[nb++] = (intptr_t)elem; + *nb_ptr = nb; +} diff --git a/libavutil/mem.h b/libavutil/mem.h index 7aab706e7d..7c30e160fb 100644 --- a/libavutil/mem.h +++ b/libavutil/mem.h @@ -123,4 +123,13 @@ char *av_strdup(const char *s) av_malloc_attrib; */ void av_freep(void *ptr); +/** + * Add an element to a dynamic array. + * + * @param tab_ptr Pointer to the array. + * @param nb_ptr Pointer to the number of elements in the array. + * @param elem Element to be added. + */ +void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); + #endif /* AVUTIL_MEM_H */ diff --git a/libavutil/opt.c b/libavutil/opt.c index e6cf34081c..5705b40490 100644 --- a/libavutil/opt.c +++ b/libavutil/opt.c @@ -33,10 +33,9 @@ //FIXME order them and do a bin search const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags) { - AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass - const AVOption *o= c->option; + const AVOption *o = NULL; - for (; o && o->name; o++) { + while ((o = av_next_option(v, o))) { if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags) return o; } @@ -164,8 +163,8 @@ int av_set_string3(void *obj, const char *name, const char *val, int alloc, cons { const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0); if (o_named && o_named->type == FF_OPT_TYPE_CONST) - d= o_named->default_val; - else if (!strcmp(buf, "default")) d= o->default_val; + d= o_named->default_val.dbl; + else if (!strcmp(buf, "default")) d= o->default_val.dbl; else if (!strcmp(buf, "max" )) d= o->max; else if (!strcmp(buf, "min" )) d= o->min; else if (!strcmp(buf, "none" )) d= 0; @@ -417,25 +416,25 @@ void av_opt_set_defaults2(void *s, int mask, int flags) case FF_OPT_TYPE_FLAGS: case FF_OPT_TYPE_INT: { int val; - val = opt->default_val; + val = opt->default_val.dbl; av_set_int(s, opt->name, val); } break; case FF_OPT_TYPE_INT64: - if ((double)(opt->default_val+0.6) == opt->default_val) + if ((double)(opt->default_val.dbl+0.6) == opt->default_val.dbl) av_log(s, AV_LOG_DEBUG, "loss of precision in default of %s\n", opt->name); - av_set_int(s, opt->name, opt->default_val); + av_set_int(s, opt->name, opt->default_val.dbl); break; case FF_OPT_TYPE_DOUBLE: case FF_OPT_TYPE_FLOAT: { double val; - val = opt->default_val; + val = opt->default_val.dbl; av_set_double(s, opt->name, val); } break; case FF_OPT_TYPE_RATIONAL: { AVRational val; - val = av_d2q(opt->default_val, INT_MAX); + val = av_d2q(opt->default_val.dbl, INT_MAX); av_set_q(s, opt->name, val); } break; diff --git a/libavutil/opt.h b/libavutil/opt.h index 67c2dd7c12..018d8a2b4f 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -64,69 +64,20 @@ typedef struct AVOption { /** * the default value for scalar options */ - double default_val; - double min; ///< minimum valid value for the option - double max; ///< maximum valid value for the option - - 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 - - /** - * The logical unit to which the option belongs. Non-constant - * options and corresponding named constants share the same - * unit. May be NULL. - */ - const char *unit; -} AVOption; - -/** - * AVOption2. - * THIS IS NOT PART OF THE API/ABI YET! - * This is identical to AVOption except that default_val was replaced by - * an union, it should be compatible with AVOption on normal platforms. - */ -typedef struct AVOption2 { - const char *name; - - /** - * short English help text - * @todo What about other languages? - */ - const char *help; - - /** - * The offset relative to the context structure where the option - * value is stored. It should be 0 for named constants. - */ - int offset; - enum AVOptionType type; - - /** - * the default value for scalar options - */ union { double dbl; const char *str; } default_val; - double min; ///< minimum valid value for the option double max; ///< maximum valid value for the option 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 /** @@ -135,8 +86,7 @@ typedef struct AVOption2 { * unit. May be NULL. */ const char *unit; -} AVOption2; - +} AVOption; /** * Look for an option in obj. Look only for the options which |