Blob Blame History Raw
From c1524f293784d9957c2339fc462fcea5c9619bee Mon Sep 17 00:00:00 2001
From: Jim Bankoski <jimbankoski@google.com>
Date: Tue, 7 Jan 2020 11:38:36 +0100
Subject: [PATCH] vp8:fix threading issues

1 - stops de allocating before threads are closed.
2 - limits threads to mb_rows when mb_rows < partitions

BUG=webm:851
---
 vp8/decoder/decodframe.c |   2 +
 vp8/decoder/onyxd_if.c   |   2 -
 vp8/decoder/threading.c  | 107 +++++++++++++++++++--------------------
 3 files changed, 55 insertions(+), 56 deletions(-)

diff --git a/vp8/decoder/decodframe.c b/vp8/decoder/decodframe.c
index 16da78a2c..ee14c3b04 100644
--- a/vp8/decoder/decodframe.c
+++ b/vp8/decoder/decodframe.c
@@ -904,6 +904,8 @@ static void setup_token_decoder(VP8D_COMP *pbi,
     /* Clamp number of decoder threads */
     if (pbi->decoding_thread_count > num_token_partitions - 1)
         pbi->decoding_thread_count = num_token_partitions - 1;
+    if (pbi->decoding_thread_count > pbi->common.mb_rows - 1)
+        pbi->decoding_thread_count = pbi->common.mb_rows - 1;
 #endif
 }
 
diff --git a/vp8/decoder/onyxd_if.c b/vp8/decoder/onyxd_if.c
index 2d9e343bc..57fa39bc7 100644
--- a/vp8/decoder/onyxd_if.c
+++ b/vp8/decoder/onyxd_if.c
@@ -509,8 +509,6 @@ int vp8_remove_decoder_instances(struct frame_buffers *fb)
         if (!pbi)
             return VPX_CODEC_ERROR;
 #if CONFIG_MULTITHREAD
-        if (pbi->b_multithreaded_rd)
-            vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
         vp8_decoder_remove_threads(pbi);
 #endif
 
diff --git a/vp8/decoder/threading.c b/vp8/decoder/threading.c
index fe290cffe..9001d275f 100644
--- a/vp8/decoder/threading.c
+++ b/vp8/decoder/threading.c
@@ -696,78 +696,75 @@ void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows)
 {
     int i;
 
-    if (pbi->b_multithreaded_rd)
-    {
-            vpx_free(pbi->mt_current_mb_col);
-            pbi->mt_current_mb_col = NULL ;
+    vpx_free(pbi->mt_current_mb_col);
+    pbi->mt_current_mb_col = NULL ;
 
-        /* Free above_row buffers. */
-        if (pbi->mt_yabove_row)
+    /* Free above_row buffers. */
+    if (pbi->mt_yabove_row)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_yabove_row[i]);
-                    pbi->mt_yabove_row[i] = NULL ;
-            }
-            vpx_free(pbi->mt_yabove_row);
-            pbi->mt_yabove_row = NULL ;
+                vpx_free(pbi->mt_yabove_row[i]);
+                pbi->mt_yabove_row[i] = NULL ;
         }
+        vpx_free(pbi->mt_yabove_row);
+        pbi->mt_yabove_row = NULL ;
+    }
 
-        if (pbi->mt_uabove_row)
+    if (pbi->mt_uabove_row)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_uabove_row[i]);
-                    pbi->mt_uabove_row[i] = NULL ;
-            }
-            vpx_free(pbi->mt_uabove_row);
-            pbi->mt_uabove_row = NULL ;
+                vpx_free(pbi->mt_uabove_row[i]);
+                pbi->mt_uabove_row[i] = NULL ;
         }
+        vpx_free(pbi->mt_uabove_row);
+        pbi->mt_uabove_row = NULL ;
+    }
 
-        if (pbi->mt_vabove_row)
+    if (pbi->mt_vabove_row)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_vabove_row[i]);
-                    pbi->mt_vabove_row[i] = NULL ;
-            }
-            vpx_free(pbi->mt_vabove_row);
-            pbi->mt_vabove_row = NULL ;
+                vpx_free(pbi->mt_vabove_row[i]);
+                pbi->mt_vabove_row[i] = NULL ;
         }
+        vpx_free(pbi->mt_vabove_row);
+        pbi->mt_vabove_row = NULL ;
+    }
 
-        /* Free left_col buffers. */
-        if (pbi->mt_yleft_col)
+    /* Free left_col buffers. */
+    if (pbi->mt_yleft_col)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_yleft_col[i]);
-                    pbi->mt_yleft_col[i] = NULL ;
-            }
-            vpx_free(pbi->mt_yleft_col);
-            pbi->mt_yleft_col = NULL ;
+                vpx_free(pbi->mt_yleft_col[i]);
+                pbi->mt_yleft_col[i] = NULL ;
         }
+        vpx_free(pbi->mt_yleft_col);
+        pbi->mt_yleft_col = NULL ;
+    }
 
-        if (pbi->mt_uleft_col)
+    if (pbi->mt_uleft_col)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_uleft_col[i]);
-                    pbi->mt_uleft_col[i] = NULL ;
-            }
-            vpx_free(pbi->mt_uleft_col);
-            pbi->mt_uleft_col = NULL ;
+                vpx_free(pbi->mt_uleft_col[i]);
+                pbi->mt_uleft_col[i] = NULL ;
         }
+        vpx_free(pbi->mt_uleft_col);
+        pbi->mt_uleft_col = NULL ;
+    }
 
-        if (pbi->mt_vleft_col)
+    if (pbi->mt_vleft_col)
+    {
+        for (i=0; i< mb_rows; i++)
         {
-            for (i=0; i< mb_rows; i++)
-            {
-                    vpx_free(pbi->mt_vleft_col[i]);
-                    pbi->mt_vleft_col[i] = NULL ;
-            }
-            vpx_free(pbi->mt_vleft_col);
-            pbi->mt_vleft_col = NULL ;
+                vpx_free(pbi->mt_vleft_col[i]);
+                pbi->mt_vleft_col[i] = NULL ;
         }
+        vpx_free(pbi->mt_vleft_col);
+        pbi->mt_vleft_col = NULL ;
     }
 }
 
@@ -859,6 +856,8 @@ void vp8_decoder_remove_threads(VP8D_COMP *pbi)
 
             vpx_free(pbi->de_thread_data);
             pbi->de_thread_data = NULL;
+
+            vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
     }
 }
 
-- 
2.24.1