From 7cc80b6c6f2ef7ef13e1c618e7b8bec09316b74e Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 30 Nov 2016 16:35:55 +0100 Subject: [PATCH] src/io/source_avcodec.c: replace with new context before closing old one --- src/io/source_avcodec.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/io/source_avcodec.c b/src/io/source_avcodec.c index 74a321a9..0a16597c 100644 --- a/src/io/source_avcodec.c +++ b/src/io/source_avcodec.c @@ -237,13 +237,8 @@ void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t mul int64_t input_layout = av_get_default_channel_layout(s->input_channels); uint_t output_channels = multi ? s->input_channels : 1; int64_t output_layout = av_get_default_channel_layout(output_channels); - if (s->avr != NULL) { - avresample_close( s->avr ); - av_free ( s->avr ); - s->avr = NULL; - } - AVAudioResampleContext *avr = s->avr; - avr = avresample_alloc_context(); + AVAudioResampleContext *avr = avresample_alloc_context(); + AVAudioResampleContext *oldavr = s->avr; av_opt_set_int(avr, "in_channel_layout", input_layout, 0); av_opt_set_int(avr, "out_channel_layout", output_layout, 0); @@ -267,6 +262,11 @@ void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t mul return; } s->avr = avr; + if (oldavr != NULL) { + avresample_close( oldavr ); + av_free ( oldavr ); + oldavr = NULL; + } s->multi = multi; } } -- 2.11.0