summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-01 19:23:41 +0200
committerwm4 <wm4@nowhere>2013-09-01 20:17:50 +0200
commit570826448a9ff522157d0e8ee0f497c0e2eeff61 (patch)
tree838af6936943d659dcebd31ce2776db69f73e381 /audio
parentead525e17a0e81bdac915dccbb0503f07cb426bf (diff)
downloadmpv-570826448a9ff522157d0e8ee0f497c0e2eeff61.tar.bz2
mpv-570826448a9ff522157d0e8ee0f497c0e2eeff61.tar.xz
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/decode/ad_lavc.c6
1 files changed, 4 insertions, 2 deletions
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;
}