shithub: libvpx

Download patch

ref: 64910657759e305bef9f03599ebc0472ae2d2ff0
parent: c580428928260781d80ada0a39bb7e4b00a5f443
author: Pengchong Jin <[email protected]>
date: Mon Jul 28 12:04:36 EDT 2014

Remove the redundant index computation in the first pass

Remove the redundant index computation when store the first
pass block-wise statistics. Currently, a single byte is
allocated for a 16x16 blocks, and all the frame statistics
saved during the first pass will be kept in memory for use
in the second pass. For a 1920x1080 300-frame clip, it will
take about 2.3 MB memory. This feature is off in current
setting.

Change-Id: I135a95b348ec093d54c6a07e1e8237626909e3bd

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -553,6 +553,9 @@
       const int use_dc_pred = (mb_col || mb_row) && (!mb_col || !mb_row);
       double error_weight = 1.0;
       const BLOCK_SIZE bsize = get_bsize(cm, mb_row, mb_col);
+#if CONFIG_FP_MB_STATS
+      const int mb_index = mb_row * cm->mb_cols + mb_col;
+#endif
 
       vp9_clear_system_state();
 
@@ -600,7 +603,7 @@
 #if CONFIG_FP_MB_STATS
       if (cpi->use_fp_mb_stats) {
         // initialization
-        cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] = 0;
+        cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
       }
 #endif
 
@@ -704,26 +707,20 @@
 #if CONFIG_FP_MB_STATS
         if (cpi->use_fp_mb_stats) {
           // intra predication statistics
-          cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] = 0;
-          cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-              FPMB_DCINTRA_MASK;
-          cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] &=
-              (~FPMB_NONZERO_MOTION_MASK);
+          cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
+          cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_DCINTRA_MASK;
+          cpi->twopass.frame_mb_stats_buf[mb_index] &=
+              ~FPMB_NONZERO_MOTION_MASK;
           if (this_error > FPMB_ERROR_LEVEL4_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-                FPMB_ERROR_LEVEL4_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LEVEL4_MASK;
           } else if (this_error > FPMB_ERROR_LEVEL3_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-                FPMB_ERROR_LEVEL3_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LEVEL3_MASK;
           } else if (this_error > FPMB_ERROR_LEVEL2_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-                FPMB_ERROR_LEVEL2_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LEVEL2_MASK;
           } else if (this_error > FPMB_ERROR_LEVEL1_TH) {
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-                FPMB_ERROR_LEVEL1_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LEVEL1_MASK;
           } else {
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
-                FPMB_ERROR_LEVEL0_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] |= FPMB_ERROR_LEVEL0_MASK;
           }
         }
 #endif
@@ -759,25 +756,24 @@
 #if CONFIG_FP_MB_STATS
           if (cpi->use_fp_mb_stats) {
             // inter predication statistics
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] = 0;
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] &=
-                (~FPMB_DCINTRA_MASK);
-            cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] &=
-                (~FPMB_NONZERO_MOTION_MASK);
+            cpi->twopass.frame_mb_stats_buf[mb_index] = 0;
+            cpi->twopass.frame_mb_stats_buf[mb_index] &= ~FPMB_DCINTRA_MASK;
+            cpi->twopass.frame_mb_stats_buf[mb_index] &=
+                ~FPMB_NONZERO_MOTION_MASK;
             if (this_error > FPMB_ERROR_LEVEL4_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_ERROR_LEVEL4_MASK;
             } else if (this_error > FPMB_ERROR_LEVEL3_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_ERROR_LEVEL3_MASK;
             } else if (this_error > FPMB_ERROR_LEVEL2_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_ERROR_LEVEL2_MASK;
             } else if (this_error > FPMB_ERROR_LEVEL1_TH) {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_ERROR_LEVEL1_MASK;
             } else {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_ERROR_LEVEL0_MASK;
             }
           }
@@ -788,7 +784,7 @@
 
 #if CONFIG_FP_MB_STATS
             if (cpi->use_fp_mb_stats) {
-              cpi->twopass.frame_mb_stats_buf[mb_row * cm->mb_cols + mb_col] |=
+              cpi->twopass.frame_mb_stats_buf[mb_index] |=
                   FPMB_NONZERO_MOTION_MASK;
             }
 #endif