From 8e08a2ec972feb192fac27fa64f3ae68ad522d4a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 15 Dec 2019 22:26:39 +0100 Subject: vd_lavc: simplify decode return error checking This code checked AVFrame.buf[0] instead of the decode return code to see whether a frame was decoded. This is sort of suspicious; while I think that the lavc API actually guarantees it, it's not intuitive anyway. In addition, the code was unnecessarily roundabout. Replace it with a proper error code check. Remove the other error return (that was, or should have been, redundant before). The no-frame path is now cleanly separated. Add an assert on the frame-returned path; if this fails, lavc violated its own API. --- video/decode/vd_lavc.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index ef0f95e60e..0fe3edd7ac 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -1035,20 +1035,25 @@ static int decode_frame(struct mp_filter *vd) send_queued_packet(vd); int ret = avcodec_receive_frame(avctx, ctx->pic); - if (ret == AVERROR_EOF) { - // If flushing was initialized earlier and has ended now, make it start - // over in case we get new packets at some point in the future. This - // must take the delay queue into account, so avctx returns EOF until - // the delay queue has been drained. - if (!ctx->num_delay_queue) - reset_avctx(vd); + if (ret < 0) { + if (ret == AVERROR_EOF) { + // If flushing was initialized earlier and has ended now, make it + // start over in case we get new packets at some point in the future. + // This must take the delay queue into account, so avctx returns EOF + // until the delay queue has been drained. + if (!ctx->num_delay_queue) + reset_avctx(vd); + } else if (ret == AVERROR(EAGAIN)) { + // just retry after caller writes a packet + } else { + handle_err(vd); + } return ret; - } else if (ret < 0 && ret != AVERROR(EAGAIN)) { - handle_err(vd); } - if (!ctx->pic->buf[0]) - return ret; + // If something was decoded successfully, it must return a frame with valid + // data. + assert(ctx->pic->buf[0]); ctx->hwdec_fail_count = 0; -- cgit v1.2.3