---
 libavcodec/pthread.c |   18 +++++++++++++-----
 1 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index f0ef1e3..83a3df7 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -440,9 +440,11 @@ int ff_decode_frame_threaded(AVCodecContext *avctx,
     FrameThreadContext *fctx;
     PerThreadContext * volatile p;
     int thread_count = avctx->thread_count, err = 0;
+    int returning_thread;
 
     if (!avctx->thread_opaque) frame_thread_init(avctx);
     fctx = avctx->thread_opaque;
+    returning_thread = fctx->next_finished;
 
     p = &fctx->threads[fctx->next_decoding];
     update_context_from_user(p->avctx, avctx);
@@ -458,24 +460,30 @@ int ff_decode_frame_threaded(AVCodecContext *avctx,
         return 0;
     }
 
-    p = &fctx->threads[fctx->next_finished++];
+    //If it's draining frames at EOF, ignore null frames from the codec.
+    //Only return one when we've run out of codec frames to return.
+    do {
+    p = &fctx->threads[returning_thread++];
 
     pthread_mutex_lock(&p->progress_mutex);
     while (p->state != STATE_INPUT_READY)
         pthread_cond_wait(&p->output_cond, &p->progress_mutex);
     pthread_mutex_unlock(&p->progress_mutex);
 
-    err = update_context_from_copy(avctx, p->avctx, 1);
-    if (err) return err;
-
     *(AVFrame*)data = p->picture;
     *data_size = p->got_picture;
 
     avcodec_get_frame_defaults(&p->picture);
     p->got_picture = 0;
 
+    if (returning_thread >= thread_count) returning_thread = 0;
+    } while (!buf_size && !*data_size && returning_thread != fctx->next_finished);
+
+    err = update_context_from_copy(avctx, p->avctx, 1);
+    if (err) return err;
+
     if (fctx->next_decoding >= thread_count) fctx->next_decoding = 0;
-    if (fctx->next_finished >= thread_count) fctx->next_finished = 0;
+    fctx->next_finished = returning_thread;
 
     return p->result;
 }
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to