Commit 20c21f8b authored by Anton Khirnov's avatar Anton Khirnov

cmdutils: get rid of dummy contexts for examining AVOptions.

Replace it with newly introduced libavutil API.
parent fb4ca26b
...@@ -3782,6 +3782,7 @@ static void show_help(void) ...@@ -3782,6 +3782,7 @@ static void show_help(void)
AVCodec *c; AVCodec *c;
AVOutputFormat *oformat = NULL; AVOutputFormat *oformat = NULL;
AVInputFormat *iformat = NULL; AVInputFormat *iformat = NULL;
const AVClass *class;
av_log_set_callback(log_callback_help); av_log_set_callback(log_callback_help);
show_usage(); show_usage();
...@@ -3809,7 +3810,8 @@ static void show_help(void) ...@@ -3809,7 +3810,8 @@ static void show_help(void)
OPT_GRAB, OPT_GRAB,
OPT_GRAB); OPT_GRAB);
printf("\n"); 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"); printf("\n");
/* individual codec options */ /* individual codec options */
...@@ -3821,7 +3823,8 @@ static void show_help(void) ...@@ -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"); printf("\n");
/* individual muxer options */ /* individual muxer options */
...@@ -3840,7 +3843,8 @@ static void show_help(void) ...@@ -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) static int opt_target(const char *opt, const char *arg)
......
...@@ -2974,6 +2974,7 @@ static void show_usage(void) ...@@ -2974,6 +2974,7 @@ static void show_usage(void)
static void show_help(void) static void show_help(void)
{ {
const AVClass *class;
av_log_set_callback(log_callback_help); av_log_set_callback(log_callback_help);
show_usage(); show_usage();
show_help_options(options, "Main options:\n", show_help_options(options, "Main options:\n",
...@@ -2981,14 +2982,17 @@ static void show_help(void) ...@@ -2981,14 +2982,17 @@ static void show_help(void)
show_help_options(options, "\nAdvanced options:\n", show_help_options(options, "\nAdvanced options:\n",
OPT_EXPERT, OPT_EXPERT); OPT_EXPERT, OPT_EXPERT);
printf("\n"); printf("\n");
av_opt_show2(avcodec_opts[0], NULL, class = avcodec_get_class();
av_opt_show2(&class, NULL,
AV_OPT_FLAG_DECODING_PARAM, 0); AV_OPT_FLAG_DECODING_PARAM, 0);
printf("\n"); printf("\n");
av_opt_show2(avformat_opts, NULL, class = avformat_get_class();
av_opt_show2(&class, NULL,
AV_OPT_FLAG_DECODING_PARAM, 0); AV_OPT_FLAG_DECODING_PARAM, 0);
#if !CONFIG_AVFILTER #if !CONFIG_AVFILTER
printf("\n"); printf("\n");
av_opt_show2(sws_opts, NULL, class = sws_get_class();
av_opt_show2(&class, NULL,
AV_OPT_FLAG_ENCODING_PARAM, 0); AV_OPT_FLAG_ENCODING_PARAM, 0);
#endif #endif
printf("\nWhile playing:\n" printf("\nWhile playing:\n"
......
...@@ -355,11 +355,12 @@ static void opt_input_file(const char *arg) ...@@ -355,11 +355,12 @@ static void opt_input_file(const char *arg)
static void show_help(void) static void show_help(void)
{ {
const AVClass *class = avformat_get_class();
av_log_set_callback(log_callback_help); av_log_set_callback(log_callback_help);
show_usage(); show_usage();
show_help_options(options, "Main options:\n", 0, 0); show_help_options(options, "Main options:\n", 0, 0);
printf("\n"); printf("\n");
av_opt_show2(avformat_opts, NULL, av_opt_show2(&class, NULL,
AV_OPT_FLAG_DECODING_PARAM, 0); AV_OPT_FLAG_DECODING_PARAM, 0);
} }
...@@ -399,8 +400,6 @@ int main(int argc, char **argv) ...@@ -399,8 +400,6 @@ int main(int argc, char **argv)
avdevice_register_all(); avdevice_register_all();
#endif #endif
avformat_opts = avformat_alloc_context();
show_banner(); show_banner();
parse_options(argc, argv, options, opt_input_file); parse_options(argc, argv, options, opt_input_file);
...@@ -413,7 +412,5 @@ int main(int argc, char **argv) ...@@ -413,7 +412,5 @@ int main(int argc, char **argv)
ret = probe_file(input_filename); ret = probe_file(input_filename);
av_free(avformat_opts);
return ret; return ret;
} }
...@@ -49,8 +49,6 @@ ...@@ -49,8 +49,6 @@
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
AVFormatContext *avformat_opts;
struct SwsContext *sws_opts; struct SwsContext *sws_opts;
AVDictionary *format_opts, *codec_opts; AVDictionary *format_opts, *codec_opts;
...@@ -58,10 +56,6 @@ static const int this_year = 2011; ...@@ -58,10 +56,6 @@ static const int this_year = 2011;
void init_opts(void) 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 #if CONFIG_SWSCALE
sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL);
#endif #endif
...@@ -69,11 +63,6 @@ void init_opts(void) ...@@ -69,11 +63,6 @@ void init_opts(void)
void uninit_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 #if CONFIG_SWSCALE
sws_freeContext(sws_opts); sws_freeContext(sws_opts);
sws_opts = NULL; sws_opts = NULL;
...@@ -291,18 +280,19 @@ int opt_default(const char *opt, const char *arg) ...@@ -291,18 +280,19 @@ int opt_default(const char *opt, const char *arg)
const AVOption *o; const AVOption *o;
char opt_stripped[128]; char opt_stripped[128];
const char *p; const char *p;
const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc = sws_get_class();
if (!(p = strchr(opt, ':'))) if (!(p = strchr(opt, ':')))
p = opt + strlen(opt); p = opt + strlen(opt);
av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1)); 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') && ((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); 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); 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 // XXX we only support sws_flags, not arbitrary sws options
int ret = av_set_string3(sws_opts, opt, arg, 1, NULL); int ret = av_set_string3(sws_opts, opt, arg, 1, NULL);
if (ret < 0) { if (ret < 0) {
...@@ -826,6 +816,7 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFor ...@@ -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); 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; int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM : AV_OPT_FLAG_DECODING_PARAM;
char prefix = 0; char prefix = 0;
const AVClass *cc = avcodec_get_class();
if (!codec) if (!codec)
return NULL; return NULL;
...@@ -847,10 +838,10 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFor ...@@ -847,10 +838,10 @@ AVDictionary *filter_codec_opts(AVDictionary *opts, enum CodecID codec_id, AVFor
default: return NULL; default: return NULL;
} }
if (av_opt_find(avcodec_opts[0], 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, 0))) (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); 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); av_dict_set(&ret, t->key+1, t->value, 0);
if (p) if (p)
......
...@@ -3947,6 +3947,7 @@ static void show_help(void) ...@@ -3947,6 +3947,7 @@ static void show_help(void)
AVCodec *c; AVCodec *c;
AVOutputFormat *oformat = NULL; AVOutputFormat *oformat = NULL;
AVInputFormat *iformat = NULL; AVInputFormat *iformat = NULL;
const AVClass *class;
av_log_set_callback(log_callback_help); av_log_set_callback(log_callback_help);
show_usage(); show_usage();
...@@ -3974,7 +3975,8 @@ static void show_help(void) ...@@ -3974,7 +3975,8 @@ static void show_help(void)
OPT_GRAB, OPT_GRAB,
OPT_GRAB); OPT_GRAB);
printf("\n"); 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"); printf("\n");
/* individual codec options */ /* individual codec options */
...@@ -3986,7 +3988,8 @@ static void show_help(void) ...@@ -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"); printf("\n");
/* individual muxer options */ /* individual muxer options */
...@@ -4005,7 +4008,8 @@ static void show_help(void) ...@@ -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) static int opt_target(const char *opt, const char *arg)
......
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