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.
This commit is contained in:
wm4 2013-09-01 19:23:41 +02:00
parent 1ef0d02245
commit 150aeafdd2
1 changed files with 4 additions and 2 deletions

View File

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