summaryrefslogtreecommitdiffstats
path: root/audio/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-07-24 15:26:43 +0200
committerwm4 <wm4@nowhere>2014-07-24 15:26:43 +0200
commitfc28e4af4d77a2aa29857471f0de1dc38996cc20 (patch)
tree128418a827287988396306fb26a1807601df034d /audio/decode
parent986099d32356bb2c9520ae32b987e7155be55605 (diff)
downloadmpv-fc28e4af4d77a2aa29857471f0de1dc38996cc20.tar.bz2
mpv-fc28e4af4d77a2aa29857471f0de1dc38996cc20.tar.xz
audio: adjust format change code
Execute the format change based on whether we logically detected EOF (after filters), instead of when the decode buffer was drained. It's slightly cleaner. (The requirement of len>0 existed before.)
Diffstat (limited to 'audio/decode')
-rw-r--r--audio/decode/dec_audio.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index 218063a699..a090f9a707 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -242,17 +242,18 @@ int audio_init_filters(struct dec_audio *d_audio, int in_samplerate,
static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
int len)
{
+ bool format_change = false;
int error = 0;
+ assert(len > 0); // would break EOF logic below
+
while (mp_audio_buffer_samples(da->decode_buffer) < len) {
// Check for a format change
struct mp_audio config;
mp_audio_buffer_get_format(da->decode_buffer, &config);
- if (!mp_audio_config_equals(&da->decoded, &config)) {
- // If there are still samples left in the buffer, let them drain
- // first, and don't signal a format change to the caller yet.
- if (mp_audio_buffer_samples(da->decode_buffer) == 0)
- error = AD_NEW_FMT;
+ format_change = !mp_audio_config_equals(&da->decoded, &config);
+ if (format_change) {
+ error = AD_EOF; // drain remaining data left in the current buffer
break;
}
if (da->decoded.samples > 0) {
@@ -286,9 +287,9 @@ static int filter_n_bytes(struct dec_audio *da, struct mp_audio_buffer *outbuf,
// remove processed data from decoder buffer:
mp_audio_buffer_skip(da->decode_buffer, len);
- // Assume the filter chain is drained from old data at this point.
- // (If not, the remaining old data is discarded.)
- if (error == AD_NEW_FMT) {
+ // if format was changed, and all data was drained, execute the format change
+ if (format_change && eof) {
+ error = AD_NEW_FMT;
if (!reinit_audio_buffer(da))
error = AD_ERR; // switch to invalid format
}