summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-12-15 22:26:39 +0100
committerwm4 <wm4@nowhere>2019-12-15 22:26:39 +0100
commit8e08a2ec972feb192fac27fa64f3ae68ad522d4a (patch)
tree64254d401407bc97ff4b61cc94e0fc43809399fb
parenta32db637b5c66c0304147caadf02d7b28083bcee (diff)
downloadmpv-8e08a2ec972feb192fac27fa64f3ae68ad522d4a.tar.bz2
mpv-8e08a2ec972feb192fac27fa64f3ae68ad522d4a.tar.xz
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.
-rw-r--r--video/decode/vd_lavc.c27
1 files 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;