From a57cff2132e9cff8767c6df9ff05409d399f43ec Mon Sep 17 00:00:00 2001
From: Jingning Han <jingning@google.com>
Date: Tue, 4 Mar 2014 10:24:25 -0800
Subject: [PATCH] Move set_speed_feature out of frame encoding

Set speed features before running frame encoding. This avoids
redundant RD threshold calculation in key frame coding.

Change-Id: If8e3cf2c02976baa59b310c1c23af9eea0c46e36
---
 vp9/encoder/vp9_encodeframe.c | 3 +++
 vp9/encoder/vp9_onyx_if.c     | 2 ++
 vp9/encoder/vp9_rdopt.c       | 2 --
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c
index b8dc72ab12..a4a9864011 100644
--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -2682,6 +2682,9 @@ void vp9_encode_frame(VP9_COMP *cpi) {
       }
     }
   } else {
+    cpi->mb.e_mbd.lossless = cpi->oxcf.lossless;
+    select_tx_mode(cpi);
+    cm->reference_mode = SINGLE_REFERENCE;
     // Force the usage of the BILINEAR interp_filter.
     cm->interp_filter = BILINEAR;
     encode_frame_internal(cpi);
diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c
index 8dd4e6dbee..52310214a5 100644
--- a/vp9/encoder/vp9_onyx_if.c
+++ b/vp9/encoder/vp9_onyx_if.c
@@ -3251,6 +3251,8 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi,
     set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH);
   }
 
+  vp9_set_speed_features(cpi);
+
   if (cpi->sf.recode_loop == DISALLOW_RECODE) {
     encode_without_recode_loop(cpi, size, dest, q);
   } else {
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index a6f54fd08c..e1230cabce 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -282,8 +282,6 @@ void vp9_initialize_rd_consts(VP9_COMP *cpi) {
   x->errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO;
   x->errorperbit += (x->errorperbit == 0);
 
-  vp9_set_speed_features(cpi);
-
   x->select_txfm_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
                          cm->frame_type != KEY_FRAME) ? 0 : 1;
 
-- 
GitLab