]> git.sesse.net Git - ffmpeg/commitdiff
avcodec: consider an error during decoder draining as EOF
authorwm4 <nfxjfg@googlemail.com>
Thu, 2 Mar 2017 09:37:26 +0000 (10:37 +0100)
committerwm4 <nfxjfg@googlemail.com>
Mon, 6 Mar 2017 10:06:09 +0000 (11:06 +0100)
There is no reason that draining couldn't return an error or two. But
some decoders don't handle this very well, and might always return an
error. This can lead to API users getting into an infinite loop and
burning CPU, because no progress is made and EOF is never returned.

In fact, ffmpeg.c contains a hack against such a case. It is made
unnecessary with this commit, and removed with the next one. (This
particular error case seems to have been fixed since the hack was
added, though.)

This might lose frames if decoding returns errors during draining.

libavcodec/utils.c

index 1156e430794f8dd4b0edc3b78829d5ebf33af67f..db3adb18d45165dd3246dd4a4ec33ea17e6e2ff8 100644 (file)
@@ -2807,12 +2807,12 @@ static int do_decode(AVCodecContext *avctx, AVPacket *pkt)
     if (ret == AVERROR(EAGAIN))
         ret = pkt->size;
 
-    if (ret < 0)
-        return ret;
-
     if (avctx->internal->draining && !got_frame)
         avctx->internal->draining_done = 1;
 
+    if (ret < 0)
+        return ret;
+
     if (ret >= pkt->size) {
         av_packet_unref(avctx->internal->buffer_pkt);
     } else {