]> granicus.if.org Git - libvpx/commitdiff
Make the tpl model update operated in 8x8 block unit
authorJingning Han <jingning@google.com>
Mon, 23 Jul 2018 06:00:39 +0000 (23:00 -0700)
committerJingning Han <jingning@google.com>
Mon, 23 Jul 2018 21:13:10 +0000 (14:13 -0700)
Store and update the temporal dependency model in the unit of
8x8 block.

Change-Id: Ic580495242b51db9beaf38dae67968cbd212be4d

vp9/encoder/vp9_encoder.c

index e053c1c9e73f15eddd1d4a452c0db1220274a448..d01cfe49c234b41725b40ab8e1dca8f8da2af2d0 100644 (file)
@@ -5666,8 +5666,34 @@ int round_floor(int ref_pos, int bsize_pix) {
   return round;
 }
 
-void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats,
-                      int mi_row, int mi_col, const BLOCK_SIZE bsize) {
+void tpl_model_store(TplDepStats *tpl_stats, int mi_row, int mi_col,
+                     BLOCK_SIZE bsize, int stride, int64_t intra_cost,
+                     int64_t inter_cost, int ref_frame_idx, int_mv mv) {
+  const int mi_height = num_8x8_blocks_high_lookup[bsize];
+  const int mi_width = num_8x8_blocks_wide_lookup[bsize];
+  int idx, idy;
+
+  intra_cost = intra_cost / (mi_height * mi_width);
+  inter_cost = inter_cost / (mi_height * mi_width);
+
+  intra_cost = VPXMAX(1, intra_cost);
+  inter_cost = VPXMAX(1, inter_cost);
+
+  for (idy = 0; idy < mi_height; ++idy) {
+    for (idx = 0; idx < mi_width; ++idx) {
+      TplDepStats *tpl_ptr =
+          &tpl_stats[(mi_row + idy) * stride + (mi_col + idx)];
+      tpl_ptr->intra_cost = intra_cost;
+      tpl_ptr->inter_cost = inter_cost;
+      tpl_ptr->mc_dep_cost = tpl_ptr->intra_cost + tpl_ptr->mc_flow;
+      tpl_ptr->ref_frame_index = ref_frame_idx;
+      tpl_ptr->mv.as_int = mv.as_int;
+    }
+  }
+}
+
+void tpl_model_update_b(TplDepFrame *tpl_frame, TplDepStats *tpl_stats,
+                        int mi_row, int mi_col, const BLOCK_SIZE bsize) {
   TplDepFrame *ref_tpl_frame = &tpl_frame[tpl_stats->ref_frame_index];
   TplDepStats *ref_stats = ref_tpl_frame->tpl_stats_ptr;
   MV mv = tpl_stats->mv.as_mv;
@@ -5722,6 +5748,22 @@ void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats,
   }
 }
 
+void tpl_model_update(TplDepFrame *tpl_frame, TplDepStats *tpl_stats,
+                      int mi_row, int mi_col, const BLOCK_SIZE bsize) {
+  int idx, idy;
+  const int mi_height = num_8x8_blocks_high_lookup[bsize];
+  const int mi_width = num_8x8_blocks_wide_lookup[bsize];
+
+  for (idy = 0; idy < mi_height; ++idy) {
+    for (idx = 0; idx < mi_width; ++idx) {
+      TplDepStats *tpl_ptr =
+          &tpl_stats[(mi_row + idy) * tpl_frame->stride + (mi_col + idx)];
+      tpl_model_update_b(tpl_frame, tpl_ptr, mi_row + idy, mi_col + idx,
+                         BLOCK_8X8);
+    }
+  }
+}
+
 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) {
@@ -5848,9 +5890,6 @@ void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int frame_idx) {
       int64_t intra_cost;
       PREDICTION_MODE mode;
 
-      TplDepStats *tpl_stats =
-          &tpl_frame->tpl_stats_ptr[mi_row * tpl_frame->stride + mi_col];
-
       // Intra prediction search
       for (mode = DC_PRED; mode <= TM_PRED; ++mode) {
         uint8_t *src, *dst;
@@ -5952,13 +5991,16 @@ void mc_flow_dispenser(VP9_COMP *cpi, GF_PICTURE *gf_picture, int frame_idx) {
       // Motion flow dependency dispenser.
       best_intra_cost = VPXMAX(best_intra_cost, 1);
       best_inter_cost = VPXMIN(best_inter_cost, best_intra_cost);
-      tpl_stats->inter_cost = best_inter_cost << TPL_DEP_COST_SCALE_LOG2;
-      tpl_stats->intra_cost = best_intra_cost << TPL_DEP_COST_SCALE_LOG2;
-      tpl_stats->mc_dep_cost = tpl_stats->intra_cost + tpl_stats->mc_flow;
-      tpl_stats->ref_frame_index = gf_picture[frame_idx].ref_frame[best_rf_idx];
-      tpl_stats->mv.as_int = best_mv.as_int;
 
-      tpl_model_update(cpi->tpl_stats, tpl_stats, mi_row, mi_col, bsize);
+      best_intra_cost <<= TPL_DEP_COST_SCALE_LOG2;
+      best_inter_cost <<= TPL_DEP_COST_SCALE_LOG2;
+
+      tpl_model_store(tpl_frame->tpl_stats_ptr, mi_row, mi_col, bsize,
+                      tpl_frame->stride, best_intra_cost, best_inter_cost,
+                      gf_picture[frame_idx].ref_frame[best_rf_idx], best_mv);
+
+      tpl_model_update(cpi->tpl_stats, tpl_frame->tpl_stats_ptr, mi_row, mi_col,
+                       bsize);
     }
   }
 }