From 380d64ecb19984a1466e727244a41445ae919060 Mon Sep 17 00:00:00 2001
From: Attila Nagy <attilanagy@google.com>
Date: Fri, 16 Sep 2011 13:54:06 +0300
Subject: [PATCH] Multithreaded encoder, late sync loopfilter

Sync with loopfilter thread just at the beginning of next frame encoding.
This returns control to application faster and allows a better multicore scaling.
When PSNR packets are generated the final filtered frame is needed imediatly
so we cannot delay the sync.

Change-Id: I288d97b5e331d41d6f5bb49d97986fa12ac6f066
---
 vp8/encoder/onyx_if.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c
index 35e187e545..efe98944e9 100644
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3764,6 +3764,17 @@ static void encode_frame_to_data_rate
             vp8_setup_key_frame(cpi);
         }
 
+#if CONFIG_MULTITHREAD
+        /*  wait for loopfilter thread done (for last picture)
+         *  don't do it for first frame, re-code and when PSNR is calculated
+         */
+        if (cpi->b_multi_threaded && cm->current_video_frame && (!Loop) &&
+                (!cpi->b_calculate_psnr))
+        {
+            sem_wait(&cpi->h_event_end_lpf);
+        }
+#endif
+
         // transform / motion compensation build reconstruction frame
         vp8_encode_frame(cpi);
 
@@ -4136,8 +4147,8 @@ static void encode_frame_to_data_rate
     vp8_pack_bitstream(cpi, dest, size);
 
 #if CONFIG_MULTITHREAD
-    /* wait for loopfilter thread done */
-    if (cpi->b_multi_threaded)
+    /* if PSNR packets are generated we have to wait for the lpf */
+    if (cpi->b_multi_threaded && cpi->b_calculate_psnr)
     {
         sem_wait(&cpi->h_event_end_lpf);
     }
-- 
GitLab