]> granicus.if.org Git - libvpx/commitdiff
Optimizes updates of encoder block ptrs
authorAttila Nagy <attilanagy@google.com>
Tue, 24 Apr 2012 12:17:28 +0000 (15:17 +0300)
committerAttila Nagy <attilanagy@google.com>
Fri, 27 Jul 2012 06:59:09 +0000 (09:59 +0300)
Precalculated block ptrs do not need updates during encoding.
Set these at init stage.

Moved the allocation of 'mt_current_mb_col' (last encoded MB on each
row) to vp8_alloc_compressor_data(), so that it is correctly
reallocated when frame size is changing.

Change-Id: Idcdaa2d0cf3a7f782b7d888626b7cf22a4ffb5c1

vp8/encoder/encodeframe.c
vp8/encoder/ethreading.c
vp8/encoder/firstpass.c
vp8/encoder/onyx_if.c

index d9e2822bf93f05cbe7c54387ee8225189444363b..7ff693cd6b3358a3b04ec59ad5dda6f876412f56 100644 (file)
@@ -641,10 +641,6 @@ static void init_encode_frame_mb_context(VP8_COMP *cpi)
 
     vp8_build_block_offsets(x);
 
-    vp8_setup_block_dptrs(&x->e_mbd);
-
-    vp8_setup_block_ptrs(x);
-
     xd->mode_info_context->mbmi.mode = DC_PRED;
     xd->mode_info_context->mbmi.uv_mode = DC_PRED;
 
index 40adc3514ce0540226c16b62d07d2bb0eaaced52..919bc70a09ba2f4aafe7f9e14dd4a7f4fee985ba 100644 (file)
@@ -474,10 +474,6 @@ void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
 
         vp8_build_block_offsets(mb);
 
-        vp8_setup_block_dptrs(mbd);
-
-        vp8_setup_block_ptrs(mb);
-
         mbd->left_context = &cm->left_context;
         mb->mvc = cm->fc.mvc;
 
@@ -522,8 +518,6 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
         vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
         CHECK_MEM_ERROR(cpi->en_thread_data,
                         vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
-        CHECK_MEM_ERROR(cpi->mt_current_mb_col,
-                        vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cm->mb_rows));
 
         sem_init(&cpi->h_event_end_encoding, 0, 0);
 
@@ -537,9 +531,14 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
 
         for (ithread = 0; ithread < th_count; ithread++)
         {
-            ENCODETHREAD_DATA * ethd = &cpi->en_thread_data[ithread];
+            ENCODETHREAD_DATA *ethd = &cpi->en_thread_data[ithread];
+
+            /* Setup block ptrs and offsets */
+            vp8_setup_block_ptrs(&cpi->mb_row_ei[ithread].mb);
+            vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd);
 
             sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
+
             ethd->ithread = ithread;
             ethd->ptr1 = (void *)cpi;
             ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
@@ -590,7 +589,6 @@ void vp8cx_remove_encoder_threads(VP8_COMP *cpi)
         vpx_free(cpi->h_encoding_thread);
         vpx_free(cpi->mb_row_ei);
         vpx_free(cpi->en_thread_data);
-        vpx_free(cpi->mt_current_mb_col);
     }
 }
 #endif
index f0d2d38078fbe27ae02411f95b4a1b7116b27a53..c98544f71f2edd6bd9e235954decd23f5fb85199 100644 (file)
@@ -562,10 +562,6 @@ void vp8_first_pass(VP8_COMP *cpi)
 
     vp8_build_block_offsets(x);
 
-    vp8_setup_block_dptrs(&x->e_mbd);
-
-    vp8_setup_block_ptrs(x);
-
     /* set up frame new frame for intra coded blocks */
     vp8_setup_intra_recon(new_yv12);
     vp8cx_frame_init_quantizer(cpi);
index 1d8613f381608c91e81762ec0595d1c1bbb8b790..a3fd2d5264c3bb2682b555750752a33c29c51a19 100644 (file)
@@ -11,6 +11,7 @@
 
 #include "vpx_config.h"
 #include "vp8/common/onyxc_int.h"
+#include "vp8/common/blockd.h"
 #include "onyx_int.h"
 #include "vp8/common/systemdependent.h"
 #include "quantize.h"
@@ -359,6 +360,11 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
 
     vpx_free(cpi->mb.pip);
     cpi->mb.pip = 0;
+
+#if CONFIG_MULTITHREAD
+    vpx_free(cpi->mt_current_mb_col);
+    cpi->mt_current_mb_col = NULL;
+#endif
 }
 
 static void enable_segmentation(VP8_COMP *cpi)
@@ -1122,11 +1128,19 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
         cpi->mt_sync_range = 8;
     else
         cpi->mt_sync_range = 16;
+
+    if (cpi->oxcf.multi_threaded > 1)
+    {
+        vpx_free(cpi->mt_current_mb_col);
+        CHECK_MEM_ERROR(cpi->mt_current_mb_col,
+                        vpx_malloc(sizeof(*cpi->mt_current_mb_col) * cm->mb_rows));
+    }
+
 #endif
 
     vpx_free(cpi->tplist);
-
-    CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
+    CHECK_MEM_ERROR(cpi->tplist,
+                    vpx_malloc(sizeof(TOKENLIST) * cpi->common.mb_rows));
 }
 
 
@@ -2032,6 +2046,10 @@ struct VP8_COMP* vp8_create_compressor(VP8_CONFIG *oxcf)
     cpi->mb.inter_bmode_costs = cpi->rd_costs.inter_bmode_costs;
     cpi->mb.token_costs = cpi->rd_costs.token_costs;
 
+    /* setup block ptrs & offsets */
+    vp8_setup_block_ptrs(&cpi->mb);
+    vp8_setup_block_dptrs(&cpi->mb.e_mbd);
+
     return  cpi;
 }