From 45971abd1df697201ba31023bc797793491ab9f6 Mon Sep 17 00:00:00 2001 From: Yaowu Xu Date: Thu, 29 Jan 2015 10:22:48 -0800 Subject: [PATCH] Optimize coef update 1. move the check of search method of USE_TX_8X8 up one level to avoid operations of build_tree_distributions() 2. count tx used and avoid computaton for coef udpate when one size is not used at all. Change-Id: Ia3e54a2588aa531c41377a1bfaa64385d04a592c --- vp9/common/vp9_entropymode.h | 1 + vp9/encoder/vp9_bitstream.c | 17 +++++++++-------- vp9/encoder/vp9_encodeframe.c | 6 +++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/vp9/common/vp9_entropymode.h b/vp9/common/vp9_entropymode.h index 6db10806d..972509d7d 100644 --- a/vp9/common/vp9_entropymode.h +++ b/vp9/common/vp9_entropymode.h @@ -33,6 +33,7 @@ struct tx_counts { unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES]; unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1]; unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2]; + unsigned int tx_totals[TX_SIZES]; }; typedef struct frame_contexts { diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index a72856db4..c7d489db6 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -611,10 +611,6 @@ static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, case ONE_LOOP_REDUCED: { int updates = 0; int noupdates_before_first = 0; - if (tx_size >= TX_16X16 && cpi->sf.tx_size_search_method == USE_TX_8X8) { - vp9_write_bit(bc, 0); - return; - } for (i = 0; i < PLANE_TYPES; ++i) { for (j = 0; j < REF_TYPES; ++j) { for (k = 0; k < COEF_BANDS; ++k) { @@ -678,10 +674,15 @@ static void update_coef_probs(VP9_COMP *cpi, vp9_writer* w) { for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) { vp9_coeff_stats frame_branch_ct[PLANE_TYPES]; vp9_coeff_probs_model frame_coef_probs[PLANE_TYPES]; - build_tree_distribution(cpi, tx_size, frame_branch_ct, - frame_coef_probs); - update_coef_probs_common(w, cpi, tx_size, frame_branch_ct, - frame_coef_probs); + if (cpi->td.counts->tx.tx_totals[tx_size] == 0 || + (tx_size >= TX_16X16 && cpi->sf.tx_size_search_method == USE_TX_8X8)) { + vp9_write_bit(w, 0); + } else { + build_tree_distribution(cpi, tx_size, frame_branch_ct, + frame_coef_probs); + update_coef_probs_common(w, cpi, tx_size, frame_branch_ct, + frame_coef_probs); + } } } diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 730a229ca..18929c74a 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -3805,6 +3805,9 @@ void vp9_encode_frame(VP9_COMP *cpi) { } } + vpx_memset(cpi->td.counts->tx.tx_totals, 0, + sizeof(cpi->td.counts->tx.tx_totals)); + if (cpi->sf.frame_parameter_update) { int i; @@ -3891,7 +3894,6 @@ void vp9_encode_frame(VP9_COMP *cpi) { count16x16_lp += counts->tx.p32x32[i][TX_16X16]; count32x32 += counts->tx.p32x32[i][TX_32X32]; } - if (count4x4 == 0 && count16x16_lp == 0 && count16x16_16x16p == 0 && count32x32 == 0) { cm->tx_mode = ALLOW_8X8; @@ -4015,5 +4017,7 @@ static void encode_superblock(VP9_COMP *cpi, ThreadData *td, if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; } + ++td->counts->tx.tx_totals[mbmi->tx_size]; + ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; } } -- 2.40.0