From 1151dac5f0e0fda012ce228f5a358c72b26fffe3 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 18 Nov 2013 13:57:17 +0100 Subject: audio: use the decoder buffer's format, not sh_audio When the decoder detects a format change, it overwrites the values stored in sh_audio (this affects the members sample_format, samplerate, channels). In the case when the old audio data still needs to be played/filtered, the audio format as identified by sh_audio and the format used for the decoder buffer can mismatch. In particular, they will mismatch in the very unlikely but possible case the audio chain is reinitialized while old data is draining during a format change. Or in other words, sh_audio might contain the new format, while the audio chain is still configured to use the old format. Currently, the audio code (player/audio.c and init_audio_filters) access sh_audio to get the current format. This is in theory incorrect for the reasons mentioned above. Use the decoder buffer's format instead, which should be correct at any point. --- audio/decode/dec_audio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'audio/decode') diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index c79e4ffc42..e2200918ef 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -207,9 +207,9 @@ int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate, struct af_stream *afs = sh_audio->afilter; // input format: same as codec's output format: + mp_audio_buffer_get_format(sh_audio->decode_buffer, &afs->input); + // Sample rate can be different when adjusting playback speed afs->input.rate = in_samplerate; - mp_audio_set_channels(&afs->input, &sh_audio->channels); - mp_audio_set_format(&afs->input, sh_audio->sample_format); // output format: same as ao driver's input format (if missing, fallback to input) afs->output.rate = *out_samplerate; -- cgit v1.2.3