deps/media-playback: Always check for new frame first
Fixes potential decoding errors with FFmpeg's new decode API. Because avcodec_send_packet may process multiple packets, you must call avcodec_receive_frame continually until no more frames are left.
This commit is contained in:
parent
d54b51edf4
commit
4aea3ce7da
13
deps/media-playback/media-playback/decode.c
vendored
13
deps/media-playback/media-playback/decode.c
vendored
@ -210,6 +210,14 @@ static int decode_packet(struct mp_decode *d, int *got_frame)
|
|||||||
*got_frame = 0;
|
*got_frame = 0;
|
||||||
|
|
||||||
#ifdef USE_NEW_FFMPEG_DECODE_API
|
#ifdef USE_NEW_FFMPEG_DECODE_API
|
||||||
|
ret = avcodec_receive_frame(d->decoder, d->frame);
|
||||||
|
if (ret != 0 && ret != AVERROR(EAGAIN)) {
|
||||||
|
if (ret == AVERROR_EOF)
|
||||||
|
ret = 0;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
ret = avcodec_send_packet(d->decoder, &d->pkt);
|
ret = avcodec_send_packet(d->decoder, &d->pkt);
|
||||||
if (ret != 0 && ret != AVERROR(EAGAIN)) {
|
if (ret != 0 && ret != AVERROR(EAGAIN)) {
|
||||||
if (ret == AVERROR_EOF)
|
if (ret == AVERROR_EOF)
|
||||||
@ -226,6 +234,11 @@ static int decode_packet(struct mp_decode *d, int *got_frame)
|
|||||||
|
|
||||||
*got_frame = (ret == 0);
|
*got_frame = (ret == 0);
|
||||||
ret = d->pkt.size;
|
ret = d->pkt.size;
|
||||||
|
} else {
|
||||||
|
ret = 0;
|
||||||
|
*got_frame = 1;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (d->audio) {
|
if (d->audio) {
|
||||||
ret = avcodec_decode_audio4(d->decoder,
|
ret = avcodec_decode_audio4(d->decoder,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user