From 570826448a9ff522157d0e8ee0f497c0e2eeff61 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 1 Sep 2013 19:23:41 +0200 Subject: audio: fix playback of Musepack SV8 files This is basically a libavcodec API oddity: it can happen that avcodec_decode_audio4() returns 0 (meaning 0 bytes were consumed). It requires you to feed the complete packet again to decode the full packet, and to successfully decode the following packets. We ignored this case with the argument that there's the danger of an endless decode loop (because nothing of that packet is apparently decoded, so it would retry forever), but change it in order to decode mpc8 files correctly. Also add some comments to explain the mess. --- audio/decode/ad_lavc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'audio/decode') diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 409fda4951..8f965e962b 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -389,13 +389,15 @@ static int decode_new_packet(struct sh_audio *sh) } int got_frame = 0; int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt); - if (ret > 0) { + // At least "shorten" decodes sub-frames, instead of the whole packet. + // At least "mpc8" can return 0 and wants the packet again next time. + if (ret >= 0) { ret = FFMIN(ret, mpkt->len); // sanity check against decoder overreads mpkt->buffer += ret; mpkt->len -= ret; mpkt->pts = MP_NOPTS_VALUE; // don't reset PTS next time } - if (mpkt->len == 0 || ret <= 0) { + if (mpkt->len == 0 || ret < 0) { talloc_free(mpkt); priv->packet = NULL; } -- cgit v1.2.3