ref: 7cc80b6c6f2ef7ef13e1c618e7b8bec09316b74e
parent: 57405c1b06ca6b640b24fec4cf2c6e6dbca539b2
author: Paul Brossier <piem@piem.org>
date: Wed Nov 30 11:35:55 EST 2016
src/io/source_avcodec.c: replace with new context before closing old one
--- a/src/io/source_avcodec.c
+++ b/src/io/source_avcodec.c
@@ -237,13 +237,8 @@
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 @@
return;
}
s->avr = avr;
+ if (oldavr != NULL) {
+ avresample_close( oldavr );
+ av_free ( oldavr );
+ oldavr = NULL;
+ }
s->multi = multi;
}
}