mirror of https://github.com/mpv-player/mpv
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:
parent
ead525e17a
commit
570826448a
|
@ -389,13 +389,15 @@ static int decode_new_packet(struct sh_audio *sh)
|
||||||
}
|
}
|
||||||
int got_frame = 0;
|
int got_frame = 0;
|
||||||
int ret = avcodec_decode_audio4(avctx, priv->avframe, &got_frame, &pkt);
|
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
|
ret = FFMIN(ret, mpkt->len); // sanity check against decoder overreads
|
||||||
mpkt->buffer += ret;
|
mpkt->buffer += ret;
|
||||||
mpkt->len -= ret;
|
mpkt->len -= ret;
|
||||||
mpkt->pts = MP_NOPTS_VALUE; // don't reset PTS next time
|
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);
|
talloc_free(mpkt);
|
||||||
priv->packet = NULL;
|
priv->packet = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue