shithub: libvpx

Download patch

ref: 0fff2fb34c7924aa59322518db41ee1953d813f9
parent: 930773a1ede62d8b29ab2f66361e6e59b11ea6b9
author: Jim Bankoski <[email protected]>
date: Thu Jul 21 05:20:10 EDT 2016

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

Change-Id: I7ead53e80cc0f8c2e4c1c53506eff8431de2a37e

--- a/vp8/decoder/decodeframe.c
+++ b/vp8/decoder/decodeframe.c
@@ -798,6 +798,9 @@
   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
 }
 
--- a/vp8/decoder/onyxd_if.c
+++ b/vp8/decoder/onyxd_if.c
@@ -331,7 +331,6 @@
     if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0) {
       cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
     }
-
     goto decode_exit;
   }
 
@@ -464,9 +463,6 @@
 
     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
 
--- a/vp8/decoder/threading.c
+++ b/vp8/decoder/threading.c
@@ -631,65 +631,63 @@
 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) {
-      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;
+  /* Free above_row buffers. */
+  if (pbi->mt_yabove_row) {
+    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;
+  }
 
-    if (pbi->mt_uabove_row) {
-      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;
+  if (pbi->mt_uabove_row) {
+    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;
+  }
 
-    if (pbi->mt_vabove_row) {
-      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;
+  if (pbi->mt_vabove_row) {
+    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;
+  }
 
-    /* Free left_col buffers. */
-    if (pbi->mt_yleft_col) {
-      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;
+  /* Free left_col buffers. */
+  if (pbi->mt_yleft_col) {
+    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;
+  }
 
-    if (pbi->mt_uleft_col) {
-      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;
+  if (pbi->mt_uleft_col) {
+    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;
+  }
 
-    if (pbi->mt_vleft_col) {
-      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;
+  if (pbi->mt_vleft_col) {
+    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;
   }
 }
 
@@ -760,7 +758,6 @@
   /* shutdown MB Decoding thread; */
   if (pbi->b_multithreaded_rd) {
     int i;
-
     pbi->b_multithreaded_rd = 0;
 
     /* allow all threads to exit */
@@ -786,6 +783,8 @@
 
     vpx_free(pbi->de_thread_data);
     pbi->de_thread_data = NULL;
+
+    vp8mt_de_alloc_temp_buffers(pbi, pbi->common.mb_rows);
   }
 }