path: root/audio/decode
diff options
authorwm4 <wm4@nowhere>2013-11-18 13:57:17 +0100
committerwm4 <wm4@nowhere>2013-11-18 14:21:00 +0100
commit1151dac5f0e0fda012ce228f5a358c72b26fffe3 (patch)
treea24a6d66c7129d33c40f490f7f20b4811d34478a /audio/decode
parent8f1151a00edf3aac78baa6779284eede3e9ee872 (diff)
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.
Diffstat (limited to 'audio/decode')
1 files changed, 2 insertions, 2 deletions
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;