From 5938e02185430ca711106aaec9b5622dbf588af3 Mon Sep 17 00:00:00 2001 From: Sean McGovern Date: Mon, 25 Jul 2011 18:51:02 -0400 Subject: [PATCH 1/5] cpu detection: avoid a signed overflow 1<<31 overflows because 1 is signed, so force it to unsigned. Signed-off-by: Ronald S. Bultje --- libavutil/x86/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c index 78aeadf0a1..f747e4dba8 100644 --- a/libavutil/x86/cpu.c +++ b/libavutil/x86/cpu.c @@ -113,7 +113,7 @@ int ff_get_cpu_flags_x86(void) if(max_ext_level >= 0x80000001){ cpuid(0x80000001, eax, ebx, ecx, ext_caps); - if (ext_caps & (1<<31)) + if (ext_caps & (1U<<31)) rval |= AV_CPU_FLAG_3DNOW; if (ext_caps & (1<<30)) rval |= AV_CPU_FLAG_3DNOWEXT; From c11fb8288d282da430f598bb029deccbacb31591 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 23 Aug 2011 07:11:26 +0200 Subject: [PATCH 2/5] AVOptions: add AV_OPT_SEARCH_FAKE_OBJ flag for av_opt_find(). It allows to search for options only with AVClass, without allocating the corresponding context. --- doc/APIchanges | 3 +++ libavcodec/options.c | 2 +- libavformat/options.c | 2 +- libavutil/avutil.h | 2 +- libavutil/opt.h | 9 +++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index a31268195f..240e613dda 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-08-xx - xxxxxxx - lavu 51.10.0 + Add AV_OPT_SEARCH_FAKE_OBJ flag for av_opt_find() function. + 2011-08-xx - xxxxxx - lavu 51.9.0 Add av_fifo_peek2(), deprecate av_fifo_peek(). diff --git a/libavcodec/options.c b/libavcodec/options.c index a715dfafcb..97525634d8 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -44,7 +44,7 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, i AVCodecContext *s = obj; AVCodec *c = NULL; - if (s->priv_data) { + if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ) && s->priv_data) { if (s->codec->priv_class) return av_opt_find(s->priv_data, name, unit, opt_flags, search_flags); return NULL; diff --git a/libavformat/options.c b/libavformat/options.c index 3ca8c83480..5ea0b181cb 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -38,7 +38,7 @@ static const AVOption *opt_find(void *obj, const char *name, const char *unit, i AVFormatContext *s = obj; AVInputFormat *ifmt = NULL; AVOutputFormat *ofmt = NULL; - if (s->priv_data) { + if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ) && s->priv_data) { if ((s->iformat && !s->iformat->priv_class) || (s->oformat && !s->oformat->priv_class)) return NULL; diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 484659a58b..24594107bc 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 9 +#define LIBAVUTIL_VERSION_MINOR 10 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/opt.h b/libavutil/opt.h index 30aa54f5b6..21dac7c569 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -215,6 +215,13 @@ int av_opt_set_dict(void *obj, struct AVDictionary **options); #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the given object first. */ +/** + * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass + * instead of a required pointer to a struct containing AVClass. This is + * useful for searching for options without needing to allocate the corresponding + * object. + */ +#define AV_OPT_SEARCH_FAKE_OBJ 0x0002 /** * Look for an option in an object. Consider only options which @@ -222,6 +229,8 @@ int av_opt_set_dict(void *obj, struct AVDictionary **options); * * @param[in] obj A pointer to a struct whose first element is a * pointer to an AVClass. + * Alternatively a double pointer to an AVClass, if + * AV_OPT_SEARCH_FAKE_OBJ search flag is set. * @param[in] name The name of the option to look for. * @param[in] unit When searching for named constants, name of the unit * it belongs to. From fb4ca26bdbddfbbf21a2a212485d225438b4b234 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 23 Aug 2011 07:23:52 +0200 Subject: [PATCH 3/5] lavf,lavc,sws: add {avcodec,avformat,sws}_get_class() functions. --- doc/APIchanges | 5 +++++ libavcodec/avcodec.h | 8 ++++++++ libavcodec/options.c | 5 +++++ libavcodec/version.h | 2 +- libavformat/avformat.h | 8 ++++++++ libavformat/options.c | 5 +++++ libavformat/version.h | 2 +- libswscale/options.c | 5 +++++ libswscale/swscale.h | 9 ++++++++- 9 files changed, 46 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 240e613dda..65d76bd60d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,11 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-08-xx - xxxxxxx - lavc 53.10.0 + lavf 53.6.0 + lsws 2.1.0 + Add {avcodec,avformat,sws}_get_class(). + 2011-08-xx - xxxxxxx - lavu 51.10.0 Add AV_OPT_SEARCH_FAKE_OBJ flag for av_opt_find() function. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 73a68b9740..f30584cb98 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4306,4 +4306,12 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)); */ enum AVMediaType avcodec_get_type(enum CodecID codec_id); +/** + * Get the AVClass for AVCodecContext. It can be used in combination with + * AV_OPT_SEARCH_FAKE_OBJ for examining options. + * + * @see av_opt_find(). + */ +const AVClass *avcodec_get_class(void); + #endif /* AVCODEC_AVCODEC_H */ diff --git a/libavcodec/options.c b/libavcodec/options.c index 97525634d8..9684ed547b 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -662,3 +662,8 @@ fail: av_freep(&dest->rc_eq); return AVERROR(ENOMEM); } + +const AVClass *avcodec_get_class(void) +{ + return &av_codec_context_class; +} diff --git a/libavcodec/version.h b/libavcodec/version.h index d4c358e182..a430e3b55b 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -21,7 +21,7 @@ #define AVCODEC_VERSION_H #define LIBAVCODEC_VERSION_MAJOR 53 -#define LIBAVCODEC_VERSION_MINOR 9 +#define LIBAVCODEC_VERSION_MINOR 10 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 2a00a9fea4..cc5457e8a2 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -1613,4 +1613,12 @@ int av_match_ext(const char *filename, const char *extensions); */ int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance); +/** + * Get the AVClass for AVFormatContext. It can be used in combination with + * AV_OPT_SEARCH_FAKE_OBJ for examining options. + * + * @see av_opt_find(). + */ +const AVClass *avformat_get_class(void); + #endif /* AVFORMAT_AVFORMAT_H */ diff --git a/libavformat/options.c b/libavformat/options.c index 5ea0b181cb..43a6dec323 100644 --- a/libavformat/options.c +++ b/libavformat/options.c @@ -123,3 +123,8 @@ AVFormatContext *avformat_alloc_context(void) avformat_get_context_defaults(ic); return ic; } + +const AVClass *avformat_get_class(void) +{ + return &av_format_context_class; +} diff --git a/libavformat/version.h b/libavformat/version.h index 36f14390e5..f952967f5d 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -24,7 +24,7 @@ #include "libavutil/avutil.h" #define LIBAVFORMAT_VERSION_MAJOR 53 -#define LIBAVFORMAT_VERSION_MINOR 5 +#define LIBAVFORMAT_VERSION_MINOR 6 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ diff --git a/libswscale/options.c b/libswscale/options.c index ecd0ecd53a..d550629239 100644 --- a/libswscale/options.c +++ b/libswscale/options.c @@ -67,3 +67,8 @@ static const AVOption options[] = { }; const AVClass sws_context_class = { "SWScaler", sws_context_to_name, options }; + +const AVClass *sws_get_class(void) +{ + return &sws_context_class; +} diff --git a/libswscale/swscale.h b/libswscale/swscale.h index f05a61e212..91378a40c4 100644 --- a/libswscale/swscale.h +++ b/libswscale/swscale.h @@ -32,7 +32,7 @@ #include "libavutil/pixfmt.h" #define LIBSWSCALE_VERSION_MAJOR 2 -#define LIBSWSCALE_VERSION_MINOR 0 +#define LIBSWSCALE_VERSION_MINOR 1 #define LIBSWSCALE_VERSION_MICRO 0 #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ @@ -351,5 +351,12 @@ void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pix */ void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); +/** + * Get the AVClass for swsContext. It can be used in combination with + * AV_OPT_SEARCH_FAKE_OBJ for examining options. + * + * @see av_opt_find(). + */ +const AVClass *sws_get_class(void); #endif /* SWSCALE_SWSCALE_H */ From 20c21f8b759cd4e759208f85dd6e34991c959043 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 23 Aug 2011 07:43:54 +0200 Subject: [PATCH 4/5] cmdutils: get rid of dummy contexts for examining AVOptions. Replace it with newly introduced libavutil API. --- avconv.c | 10 +++++++--- avplay.c | 10 +++++++--- avprobe.c | 7 ++----- cmdutils.c | 27 +++++++++------------------ ffmpeg.c | 10 +++++++--- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/avconv.c b/avconv.c index f5f4dea36f..b2dce53fff 100644 --- a/avconv.c +++ b/avconv.c @@ -3782,6 +3782,7 @@ static void show_help(void) AVCodec *c; AVOutputFormat *oformat = NULL; AVInputFormat *iformat = NULL; + const AVClass *class; av_log_set_callback(log_callback_help); show_usage(); @@ -3809,7 +3810,8 @@ static void show_help(void) OPT_GRAB, OPT_GRAB); printf("\n"); - av_opt_show2(avcodec_opts[0], NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = avcodec_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); printf("\n"); /* individual codec options */ @@ -3821,7 +3823,8 @@ static void show_help(void) } } - av_opt_show2(avformat_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = avformat_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); printf("\n"); /* individual muxer options */ @@ -3840,7 +3843,8 @@ static void show_help(void) } } - av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = sws_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); } static int opt_target(const char *opt, const char *arg) diff --git a/avplay.c b/avplay.c index 710c1b5469..1880668d65 100644 --- a/avplay.c +++ b/avplay.c @@ -2974,6 +2974,7 @@ static void show_usage(void) static void show_help(void) { + const AVClass *class; av_log_set_callback(log_callback_help); show_usage(); show_help_options(options, "Main options:\n", @@ -2981,14 +2982,17 @@ static void show_help(void) show_help_options(options, "\nAdvanced options:\n", OPT_EXPERT, OPT_EXPERT); printf("\n"); - av_opt_show2(avcodec_opts[0], NULL, + class = avcodec_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0); printf("\n"); - av_opt_show2(avformat_opts, NULL, + class = avformat_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0); #if !CONFIG_AVFILTER printf("\n"); - av_opt_show2(sws_opts, NULL, + class = sws_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM, 0); #endif printf("\nWhile playing:\n" diff --git a/avprobe.c b/avprobe.c index d502421416..f0ba6bae09 100644 --- a/avprobe.c +++ b/avprobe.c @@ -355,11 +355,12 @@ static void opt_input_file(const char *arg) static void show_help(void) { + const AVClass *class = avformat_get_class(); av_log_set_callback(log_callback_help); show_usage(); show_help_options(options, "Main options:\n", 0, 0); printf("\n"); - av_opt_show2(avformat_opts, NULL, + av_opt_show2(&class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0); } @@ -399,8 +400,6 @@ int main(int argc, char **argv) avdevice_register_all(); #endif - avformat_opts = avformat_alloc_context(); - show_banner(); parse_options(argc, argv, options, opt_input_file); @@ -413,7 +412,5 @@ int main(int argc, char **argv) ret = probe_file(input_filename); - av_free(avformat_opts); - return ret; } diff --git a/cmdutils.c b/cmdutils.c index e00e902e48..a6402af596 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -49,8 +49,6 @@ #include #endif -AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; -AVFormatContext *avformat_opts; struct SwsContext *sws_opts; AVDictionary *format_opts, *codec_opts; @@ -58,10 +56,6 @@ static const int this_year = 2011; void init_opts(void) { - int i; - for (i = 0; i < AVMEDIA_TYPE_NB; i++) - avcodec_opts[i] = avcodec_alloc_context3(NULL); - avformat_opts = avformat_alloc_context(); #if CONFIG_SWSCALE sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); #endif @@ -69,11 +63,6 @@ void init_opts(void) void uninit_opts(void) { - int i; - for (i = 0; i < AVMEDIA_TYPE_NB; i++) - av_freep(&avcodec_opts[i]); - av_freep(&avformat_opts->key); - av_freep(&avformat_opts); #if CONFIG_SWSCALE sws_freeContext(sws_opts); sws_opts = NULL; @@ -291,18 +280,19 @@ int opt_default(const char *opt, const char *arg) const AVOption *o; char opt_stripped[128]; const char *p; + const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc = sws_get_class(); if (!(p = strchr(opt, ':'))) p = opt + strlen(opt); av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1)); - if ((o = av_opt_find(avcodec_opts[0], opt_stripped, NULL, 0, AV_OPT_SEARCH_CHILDREN)) || + if ((o = av_opt_find(&cc, opt_stripped, NULL, 0, AV_OPT_SEARCH_CHILDREN|AV_OPT_SEARCH_FAKE_OBJ)) || ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && - (o = av_opt_find(avcodec_opts[0], opt+1, NULL, 0, 0)))) + (o = av_opt_find(&cc, opt+1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) av_dict_set(&codec_opts, opt, arg, FLAGS); - else if ((o = av_opt_find(avformat_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) + else if ((o = av_opt_find(&fc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) av_dict_set(&format_opts, opt, arg, FLAGS); - else if ((o = av_opt_find(sws_opts, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN))) { + else if ((o = av_opt_find(&sc, opt, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { // XXX we only support sws_flags, not arbitrary sws options int ret = av_set_string3(sws_opts, opt, arg, 1, NULL); if (ret < 0) { @@ -826,6 +816,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFor AVCodec *codec = s->oformat ? avcodec_find_encoder(codec_id) : avcodec_find_decoder(codec_id); int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM; char prefix = 0; + const AVClass *cc = avcodec_get_class(); if (!codec) return NULL; @@ -847,10 +838,10 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFor default: return NULL; } - if (av_opt_find(avcodec_opts[0], t->key, NULL, flags, 0) || - (codec && codec->priv_class && av_opt_find(&codec->priv_class, t->key, NULL, flags, 0))) + if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || + (codec && codec->priv_class && av_opt_find(&codec->priv_class, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ))) av_dict_set(&ret, t->key, t->value, 0); - else if (t->key[0] == prefix && av_opt_find(avcodec_opts[0], t->key+1, NULL, flags, 0)) + else if (t->key[0] == prefix && av_opt_find(&cc, t->key+1, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ)) av_dict_set(&ret, t->key+1, t->value, 0); if (p) diff --git a/ffmpeg.c b/ffmpeg.c index f2e5bae8b2..36d870172e 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -3947,6 +3947,7 @@ static void show_help(void) AVCodec *c; AVOutputFormat *oformat = NULL; AVInputFormat *iformat = NULL; + const AVClass *class; av_log_set_callback(log_callback_help); show_usage(); @@ -3974,7 +3975,8 @@ static void show_help(void) OPT_GRAB, OPT_GRAB); printf("\n"); - av_opt_show2(avcodec_opts[0], NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = avcodec_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); printf("\n"); /* individual codec options */ @@ -3986,7 +3988,8 @@ static void show_help(void) } } - av_opt_show2(avformat_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = avformat_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); printf("\n"); /* individual muxer options */ @@ -4005,7 +4008,8 @@ static void show_help(void) } } - av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); + class = sws_get_class(); + av_opt_show2(&class, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); } static int opt_target(const char *opt, const char *arg) From e955a682e125d44143415ff2b96a99a4dac78da2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 23 Aug 2011 07:46:51 +0200 Subject: [PATCH 5/5] AVOptions: fix av_set_string3() doxy to match reality. Fixes bug 28. --- libavutil/opt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavutil/opt.h b/libavutil/opt.h index 21dac7c569..68d2c798e2 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -134,7 +134,7 @@ const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int m * when 0 then no av_free() nor av_strdup() will be used * @return 0 if the value has been set, or an AVERROR code in case of * error: - * AVERROR(ENOENT) if no matching option exists + * AVERROR_OPTION_NOT_FOUND if no matching option exists * AVERROR(ERANGE) if the value is out of range * AVERROR(EINVAL) if the value is not valid */