From e66e9ddfb445461a461d64a32d9a5fd1ae9ae779 Mon Sep 17 00:00:00 2001 From: Attila Nagy Date: Tue, 24 Apr 2012 15:17:28 +0300 Subject: [PATCH] Optimizes updates of encoder block ptrs 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 | 4 ---- vp8/encoder/ethreading.c | 14 ++++++-------- vp8/encoder/firstpass.c | 4 ---- vp8/encoder/onyx_if.c | 22 ++++++++++++++++++++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index d9e2822bf..7ff693cd6 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -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; diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c index 40adc3514..919bc70a0 100644 --- a/vp8/encoder/ethreading.c +++ b/vp8/encoder/ethreading.c @@ -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 diff --git a/vp8/encoder/firstpass.c b/vp8/encoder/firstpass.c index f0d2d3807..c98544f71 100644 --- a/vp8/encoder/firstpass.c +++ b/vp8/encoder/firstpass.c @@ -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); diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 1d8613f38..a3fd2d526 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -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; }