shithub: libvpx

Download patch

ref: a0ad16e20313e649bfdbbb9b7eb54af7cca3b9a0
parent: 2cd48bdc92c28d5a4edd8500393b26befbb19e79
author: Scott LaVarnway <slavarnway@google.com>
date: Mon Dec 10 12:32:58 EST 2012

Moved error_bins to macroblock struct

Change-Id: Ic9956ddf1c2ddffcf7be7fdfc23ad9a2426fc47a
WIP: Fixing unsafe threading in VP8 encoder.

--- a/vp8/encoder/block.h
+++ b/vp8/encoder/block.h
@@ -19,6 +19,7 @@
 #include "vpx_ports/mem.h"
 
 #define MAX_MODES 20
+#define MAX_ERROR_BINS 1024
 
 /* motion search site */
 typedef struct
@@ -148,6 +149,7 @@
 
     int last_zbin_over_quant;
     int zbin_over_quant;
+    int error_bins[MAX_ERROR_BINS];
 
     void (*short_fdct4x4)(short *input, short *output, int pitch);
     void (*short_fdct8x4)(short *input, short *output, int pitch);
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -897,6 +897,10 @@
                     cpi->mb.count_mb_ref_frame_usage[c_idx] +=
                         x->count_mb_ref_frame_usage[c_idx];
 
+                for(c_idx = 0; c_idx < MAX_ERROR_BINS; c_idx++)
+                    cpi->mb.error_bins[c_idx] +=
+                        cpi->mb_row_ei[i].mb.error_bins[c_idx];
+
                 /* add up counts for each thread */
                 sum_coef_counts(x, &cpi->mb_row_ei[i].mb);
             }
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -427,6 +427,8 @@
         z->zbin_over_quant = x->zbin_over_quant;
         z->zbin_mode_boost_enabled = x->zbin_mode_boost_enabled;
         z->zbin_mode_boost = x->zbin_mode_boost;
+
+        vpx_memset(z->error_bins, 0, sizeof(z->error_bins));
     }
 }
 
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -837,7 +837,7 @@
 
             for (i = 0; i < min; i++)
             {
-                sum += cpi->error_bins[i];
+                sum += cpi->mb.error_bins[i];
             }
 
             total_skip = sum;
@@ -846,7 +846,7 @@
             /* i starts from 2 to make sure thresh started from 2048 */
             for (; i < 1024; i++)
             {
-                sum += cpi->error_bins[i];
+                sum += cpi->mb.error_bins[i];
 
                 if (10 * sum >= (unsigned int)(cpi->Speed - 6)*(total_mbs - total_skip))
                     break;
@@ -901,7 +901,7 @@
         if (Speed >= 15)
             sf->half_pixel_search = 0;
 
-        vpx_memset(cpi->error_bins, 0, sizeof(cpi->error_bins));
+        vpx_memset(cpi->mb.error_bins, 0, sizeof(cpi->mb.error_bins));
 
     }; /* switch */
 
@@ -1998,7 +1998,7 @@
     cpi->refining_search_sad = vp8_refining_search_sad;
 
     /* make sure frame 1 is okay */
-    cpi->error_bins[0] = cpi->common.MBs;
+    cpi->mb.error_bins[0] = cpi->common.MBs;
 
     /* vp8cx_init_quantizer() is first called here. Add check in
      * vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -488,7 +488,6 @@
     int ref_frame_flags;
 
     SPEED_FEATURES sf;
-    int error_bins[1024];
 
     /* Count ZEROMV on all reference frames. */
     int zeromv_count;
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -1160,7 +1160,7 @@
             this_rdbin = 1023;
         }
 
-        cpi->error_bins[this_rdbin] ++;
+        x->error_bins[this_rdbin] ++;
     }
 
 #if CONFIG_TEMPORAL_DENOISING