shithub: libvpx

Download patch

ref: 2fd01596a550e2b280ea2913cb930c915807a096
parent: bc7c99e7eca8d30d005e7d5db8b0aada2459fb15
parent: d3c316a3e450d581e69d3722009bae28a4c8a62e
author: Jingning Han <jingning@google.com>
date: Mon Jul 16 23:49:47 EDT 2018

Merge changes Iee11abf6,I8acbc718,Ia9a84311

* changes:
  Account for quantization effect in the tpl model
  Assign estimate qp for overlay frame
  Use the estimate qp to set motion search control

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -35,6 +35,7 @@
 #include "vp9/common/vp9_reconinter.h"
 #include "vp9/common/vp9_reconintra.h"
 #include "vp9/common/vp9_tile_common.h"
+#include "vp9/common/vp9_scan.h"
 
 #include "vp9/encoder/vp9_alt_ref_aq.h"
 #include "vp9/encoder/vp9_aq_360.h"
@@ -5504,6 +5505,7 @@
   int alt_index = -1;
   int lst_index = -1;
   int extend_frame_count = 0;
+  int pframe_qindex = cpi->tpl_stats[2].base_qindex;
 
   *tpl_group_frames = 0;
 
@@ -5550,6 +5552,8 @@
 
     if (buf == NULL) break;
 
+    cpi->tpl_stats[frame_idx].base_qindex = pframe_qindex;
+
     gf_picture[frame_idx].frame = &buf->img;
     gf_picture[frame_idx].ref_frame[0] = gld_index;
     gf_picture[frame_idx].ref_frame[1] = lst_index;
@@ -5706,6 +5710,26 @@
   }
 }
 
+void get_quantize_error(MACROBLOCK *x, int plane, tran_low_t *coeff,
+                        tran_low_t *qcoeff, tran_low_t *dqcoeff,
+                        TX_SIZE tx_size, int64_t *recon_error, int64_t *sse) {
+  MACROBLOCKD *const xd = &x->e_mbd;
+  const struct macroblock_plane *const p = &x->plane[plane];
+  const struct macroblockd_plane *const pd = &xd->plane[plane];
+  const scan_order *const scan_order = &vp9_default_scan_orders[tx_size];
+  uint16_t eob;
+  int pix_num = 1 << num_pels_log2_lookup[txsize_to_bsize[tx_size]];
+
+  vp9_quantize_fp_32x32(coeff, pix_num, x->skip_block, p->round_fp, p->quant_fp,
+                        qcoeff, dqcoeff, pd->dequant, &eob, scan_order->scan,
+                        scan_order->iscan);
+
+  *recon_error = vp9_block_error(coeff, dqcoeff, pix_num, sse);
+
+  *recon_error = VPXMAX(*recon_error, 1);
+  *sse = VPXMAX(*sse, 1);
+}
+
 void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int frame_idx) {
   TplDepFrame *tpl_frame = &cpi->tpl_stats[frame_idx];
   YV12_BUFFER_CONFIG *this_frame = gf_picture[frame_idx].frame;
@@ -5729,6 +5753,8 @@
 #endif
   DECLARE_ALIGNED(16, int16_t, src_diff[32 * 32]);
   DECLARE_ALIGNED(16, tran_low_t, coeff[32 * 32]);
+  DECLARE_ALIGNED(16, tran_low_t, qcoeff[32 * 32]);
+  DECLARE_ALIGNED(16, tran_low_t, dqcoeff[32 * 32]);
 
   MODE_INFO mi_above, mi_left;
 
@@ -5738,6 +5764,7 @@
   const int mi_height = num_8x8_blocks_high_lookup[bsize];
   const int mi_width = num_8x8_blocks_wide_lookup[bsize];
   const int pix_num = bw * bh;
+  int64_t recon_error, sse;
 
   // Setup scaling factor
 #if CONFIG_VP9_HIGHBITDEPTH
@@ -5767,12 +5794,17 @@
   xd->mi[0] = cm->mi;
 
   // Get rd multiplier set up.
-  rdmult = (int)vp9_compute_rd_mult_based_on_qindex(cpi, ARNR_FILT_QINDEX);
+  rdmult =
+      (int)vp9_compute_rd_mult_based_on_qindex(cpi, tpl_frame->base_qindex);
   if (rdmult < 1) rdmult = 1;
   set_error_per_bit(&cpi->td.mb, rdmult);
-  vp9_initialize_me_consts(cpi, &cpi->td.mb, ARNR_FILT_QINDEX);
+  vp9_initialize_me_consts(cpi, &cpi->td.mb, tpl_frame->base_qindex);
 
   tpl_frame->is_valid = 1;
+
+  cm->base_qindex = tpl_frame->base_qindex;
+  vp9_frame_init_quantizer(cpi);
+
   for (mi_row = 0; mi_row < cm->mi_rows; mi_row += mi_height) {
     // Motion estimation row boundary
     x->mv_limits.row_min = -((mi_row * MI_SIZE) + (17 - 2 * VP9_INTERP_EXTEND));
@@ -5888,6 +5920,8 @@
           best_rf_idx = rf_idx;
           best_inter_cost = inter_cost;
           best_mv.as_int = mv.as_int;
+          get_quantize_error(x, 0, coeff, qcoeff, dqcoeff, TX_32X32,
+                             &recon_error, &sse);
         }
       }
 
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -1443,7 +1443,7 @@
   int idx;
   const int gf_index = cpi->twopass.gf_group.index;
 
-  for (idx = 1; idx <= gop_length; ++idx) {
+  for (idx = 1; idx <= gop_length + 1 && idx < MAX_LAG_BUFFERS; ++idx) {
     TplDepFrame *tpl_frame = &cpi->tpl_stats[idx];
     int target_rate = cpi->twopass.gf_group.bit_allocation[idx];
     cpi->twopass.gf_group.index = idx;
@@ -1451,6 +1451,7 @@
     vp9_configure_buffer_updates(cpi, idx);
     tpl_frame->base_qindex =
         rc_pick_q_and_bounds_two_pass(cpi, &bottom_index, &top_index, idx);
+    tpl_frame->base_qindex = VPXMAX(tpl_frame->base_qindex, 1);
   }
   // Reset the actual index and frame update
   cpi->twopass.gf_group.index = gf_index;