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.
This commit is contained in:
wm4
2013-11-18 13:57:17 +01:00
parent 8f1151a00e
commit 1151dac5f0
2 changed files with 21 additions and 8 deletions

View File

@@ -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;