diff mbox

[FFmpeg-devel] avcodec/pthread_frame, decode: allow errors to happen on draining

Message ID 20170427183204.20445-1-mfcc64@gmail.com
State Superseded
Headers show

Commit Message

Muhammad Faiz April 27, 2017, 6:32 p.m. UTC
So, all frames and errors are correctly reported in order.
Fix fate failure with THREADS>=4:
  make fate-h264-attachment-631 THREADS=4

Suggested-by: wm4, Ronald S. Bultje, Marton Balint
Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
---
 libavcodec/decode.c        |  3 ++-
 libavcodec/pthread_frame.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

Comments

Michael Niedermayer April 28, 2017, 1:21 a.m. UTC | #1
On Fri, Apr 28, 2017 at 01:32:04AM +0700, Muhammad Faiz wrote:
> So, all frames and errors are correctly reported in order.
> Fix fate failure with THREADS>=4:
>   make fate-h264-attachment-631 THREADS=4
> 
> Suggested-by: wm4, Ronald S. Bultje, Marton Balint
> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
> ---
>  libavcodec/decode.c        |  3 ++-
>  libavcodec/pthread_frame.c | 15 +++++++--------
>  2 files changed, 9 insertions(+), 9 deletions(-)

This breaks with opus and shorten, ill send you the sample files
privatly


[...]
diff mbox

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 6ff3c40..f4d32e3 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -568,7 +568,8 @@  FF_ENABLE_DEPRECATION_WARNINGS
         avctx->time_base = av_inv_q(av_mul_q(avctx->framerate, (AVRational){avctx->ticks_per_frame, 1}));
 #endif
 
-    if (avctx->internal->draining && !got_frame)
+    /* do not stop draining when got_frame != 0 or ret < 0 */
+    if (avctx->internal->draining && !got_frame && ret >= 0)
         avci->draining_done = 1;
 
     avci->compat_decode_consumed += ret;
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 13d6828..363b139 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -509,8 +509,8 @@  int ff_thread_decode_frame(AVCodecContext *avctx,
     /*
      * Return the next available frame from the oldest thread.
      * If we're at the end of the stream, then we have to skip threads that
-     * didn't output a frame, because we don't want to accidentally signal
-     * EOF (avpkt->size == 0 && *got_picture_ptr == 0).
+     * didn't output a frame/error, because we don't want to accidentally signal
+     * EOF (avpkt->size == 0 && *got_picture_ptr == 0 && err >= 0).
      */
 
     do {
@@ -526,20 +526,19 @@  int ff_thread_decode_frame(AVCodecContext *avctx,
         av_frame_move_ref(picture, p->frame);
         *got_picture_ptr = p->got_frame;
         picture->pkt_dts = p->avpkt.dts;
-
-        if (p->result < 0)
-            err = p->result;
+        err = p->result;
 
         /*
          * A later call with avkpt->size == 0 may loop over all threads,
-         * including this one, searching for a frame to return before being
+         * including this one, searching for a frame/error to return before being
          * stopped by the "finished != fctx->next_finished" condition.
-         * Make sure we don't mistakenly return the same frame again.
+         * Make sure we don't mistakenly return the same frame/error again.
          */
         p->got_frame = 0;
+        p->result = 0;
 
         if (finished >= avctx->thread_count) finished = 0;
-    } while (!avpkt->size && !*got_picture_ptr && finished != fctx->next_finished);
+    } while (!avpkt->size && !*got_picture_ptr && err >= 0 && finished != fctx->next_finished);
 
     update_context_from_thread(avctx, p->avctx, 1);