From a5c33faaccec6787419fe373a9e7ae0932b15ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Sat, 2 Oct 2010 08:44:33 +0000 Subject: Add init and uninit functions to cmdutils, reduces code duplication between ffmpeg and ffplay and avoids a valgrind error by freeing avformat_opts->key. Originally committed as revision 25309 to svn://svn.ffmpeg.org/ffmpeg/trunk --- cmdutils.c | 19 +++++++++++++++++++ cmdutils.h | 11 +++++++++++ ffmpeg.c | 12 ++---------- ffplay.c | 16 +++------------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/cmdutils.c b/cmdutils.c index ff399299b6..313b37deb1 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -57,6 +57,25 @@ struct SwsContext *sws_opts; const int this_year = 2010; +void init_opts(void) +{ + int i; + for (i = 0; i < AVMEDIA_TYPE_NB; i++) + avcodec_opts[i] = avcodec_alloc_context2(i); + avformat_opts = avformat_alloc_context(); + sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); +} + +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); + av_freep(&sws_opts); +} + void log_callback_help(void* ptr, int level, const char* fmt, va_list vl) { vfprintf(stdout, fmt, vl); diff --git a/cmdutils.h b/cmdutils.h index e753c43081..4ce62b64a8 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -44,6 +44,17 @@ extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; extern AVFormatContext *avformat_opts; extern struct SwsContext *sws_opts; +/** + * Initialize the cmdutils option system, in particular + * allocate the *_opts contexts. + */ +void init_opts(void); +/** + * Uninitialize the cmdutils option system, in particular + * free the *_opts contexts and their contents. + */ +void uninit_opts(void); + /** * Trivial log callback. * Only suitable for show_help and similar since it lacks prefix handling. diff --git a/ffmpeg.c b/ffmpeg.c index 9b99786431..52028baf08 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -636,10 +636,7 @@ static int ffmpeg_exit(int ret) av_free(video_standard); - for (i=0;i