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/trunktags/n0.8
@@ -57,6 +57,25 @@ struct SwsContext *sws_opts; | |||||
const int this_year = 2010; | 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) | void log_callback_help(void* ptr, int level, const char* fmt, va_list vl) | ||||
{ | { | ||||
vfprintf(stdout, fmt, vl); | vfprintf(stdout, fmt, vl); | ||||
@@ -44,6 +44,17 @@ extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; | |||||
extern AVFormatContext *avformat_opts; | extern AVFormatContext *avformat_opts; | ||||
extern struct SwsContext *sws_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. | * Trivial log callback. | ||||
* Only suitable for show_help and similar since it lacks prefix handling. | * Only suitable for show_help and similar since it lacks prefix handling. | ||||
@@ -636,10 +636,7 @@ static int ffmpeg_exit(int ret) | |||||
av_free(video_standard); | av_free(video_standard); | ||||
for (i=0;i<AVMEDIA_TYPE_NB;i++) | |||||
av_free(avcodec_opts[i]); | |||||
av_free(avformat_opts); | |||||
av_free(sws_opts); | |||||
uninit_opts(); | |||||
av_free(audio_buf); | av_free(audio_buf); | ||||
av_free(audio_out); | av_free(audio_out); | ||||
allocated_audio_buf_size= allocated_audio_out_size= 0; | allocated_audio_buf_size= allocated_audio_out_size= 0; | ||||
@@ -4336,7 +4333,6 @@ static const OptionDef options[] = { | |||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
int i; | |||||
int64_t ti; | int64_t ti; | ||||
av_log_set_flags(AV_LOG_SKIP_REPEATED); | av_log_set_flags(AV_LOG_SKIP_REPEATED); | ||||
@@ -4355,11 +4351,7 @@ int main(int argc, char **argv) | |||||
url_set_interrupt_cb(decode_interrupt_cb); | url_set_interrupt_cb(decode_interrupt_cb); | ||||
#endif | #endif | ||||
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_flags, NULL,NULL,NULL); | |||||
init_opts(); | |||||
show_banner(); | show_banner(); | ||||
@@ -1326,15 +1326,11 @@ static void stream_close(VideoState *is) | |||||
static void do_exit(void) | static void do_exit(void) | ||||
{ | { | ||||
int i; | |||||
if (cur_stream) { | if (cur_stream) { | ||||
stream_close(cur_stream); | stream_close(cur_stream); | ||||
cur_stream = NULL; | cur_stream = NULL; | ||||
} | } | ||||
for (i = 0; i < AVMEDIA_TYPE_NB; i++) | |||||
av_free(avcodec_opts[i]); | |||||
av_free(avformat_opts); | |||||
av_free(sws_opts); | |||||
uninit_opts(); | |||||
#if CONFIG_AVFILTER | #if CONFIG_AVFILTER | ||||
avfilter_uninit(); | avfilter_uninit(); | ||||
#endif | #endif | ||||
@@ -3140,7 +3136,7 @@ static void opt_input_file(const char *filename) | |||||
/* Called from the main */ | /* Called from the main */ | ||||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||||
{ | { | ||||
int flags, i; | |||||
int flags; | |||||
av_log_set_flags(AV_LOG_SKIP_REPEATED); | av_log_set_flags(AV_LOG_SKIP_REPEATED); | ||||
@@ -3154,13 +3150,7 @@ int main(int argc, char **argv) | |||||
#endif | #endif | ||||
av_register_all(); | av_register_all(); | ||||
for(i=0; i<AVMEDIA_TYPE_NB; i++){ | |||||
avcodec_opts[i]= avcodec_alloc_context2(i); | |||||
} | |||||
avformat_opts = avformat_alloc_context(); | |||||
#if !CONFIG_AVFILTER | |||||
sws_opts = sws_getContext(16,16,0, 16,16,0, sws_flags, NULL,NULL,NULL); | |||||
#endif | |||||
init_opts(); | |||||
show_banner(); | show_banner(); | ||||