]> granicus.if.org Git - libvpx/commitdiff
Unify set_contexts() function for encoder and decoder
authorJingning Han <jingning@google.com>
Fri, 15 Jul 2016 15:50:14 +0000 (08:50 -0700)
committerYaowu Xu <yaowu@google.com>
Fri, 21 Oct 2016 16:32:28 +0000 (09:32 -0700)
Remove the separate implementations of set_contexts() in encoder
and decoder.

Change-Id: I9f6e9b075532faae0f74f885d9443589254258a7

av1/common/blockd.c
av1/common/blockd.h
av1/common/onyxc_int.h
av1/decoder/decodeframe.c
av1/decoder/detokenize.c
av1/encoder/encodeframe.c
av1/encoder/tokenize.c

index 8938bbfda5aa6b91315c637accc1e1ff14549ef2..6332fed1fb685928f3279915cd92b7d7c749f273 100644 (file)
@@ -92,40 +92,38 @@ void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
 }
 
 void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
-                      BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
-                      int aoff, int loff) {
+                      TX_SIZE tx_size, int has_eob, int aoff, int loff) {
   ENTROPY_CONTEXT *const a = pd->above_context + aoff;
   ENTROPY_CONTEXT *const l = pd->left_context + loff;
-  const int tx_w_in_blocks = num_4x4_blocks_wide_txsize_lookup[tx_size];
-  const int tx_h_in_blocks = num_4x4_blocks_high_txsize_lookup[tx_size];
+  const int tx_size_in_blocks = 1 << tx_size;
 
   // above
   if (has_eob && xd->mb_to_right_edge < 0) {
     int i;
-    const int blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize] +
-                            (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-    int above_contexts = tx_w_in_blocks;
+    const int blocks_wide =
+        pd->n4_w + (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
+    int above_contexts = tx_size_in_blocks;
     if (above_contexts + aoff > blocks_wide)
       above_contexts = blocks_wide - aoff;
 
     for (i = 0; i < above_contexts; ++i) a[i] = has_eob;
-    for (i = above_contexts; i < tx_w_in_blocks; ++i) a[i] = 0;
+    for (i = above_contexts; i < tx_size_in_blocks; ++i) a[i] = 0;
   } else {
-    memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_w_in_blocks);
+    memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
   }
 
   // left
   if (has_eob && xd->mb_to_bottom_edge < 0) {
     int i;
-    const int blocks_high = num_4x4_blocks_high_lookup[plane_bsize] +
-                            (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-    int left_contexts = tx_h_in_blocks;
+    const int blocks_high =
+        pd->n4_h + (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
+    int left_contexts = tx_size_in_blocks;
     if (left_contexts + loff > blocks_high) left_contexts = blocks_high - loff;
 
     for (i = 0; i < left_contexts; ++i) l[i] = has_eob;
-    for (i = left_contexts; i < tx_h_in_blocks; ++i) l[i] = 0;
+    for (i = left_contexts; i < tx_size_in_blocks; ++i) l[i] = 0;
   } else {
-    memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_h_in_blocks);
+    memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
   }
 }
 
index 6296faa5af7ae080db2f142d1ffff6e094cc0484..4d9bff9b0825b79fbe52ec354f2ea048e4eb16f9 100644 (file)
@@ -757,8 +757,7 @@ void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
                                    void *arg);
 
 void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
-                      BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
-                      int aoff, int loff);
+                      TX_SIZE tx_size, int has_eob, int aoff, int loff);
 
 #if CONFIG_EXT_INTER
 static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
index afc9da412500442f3ce37c1be67476386288ae94..3c8eac834736401b83decea999ca6f8fbc222949 100644 (file)
@@ -520,6 +520,17 @@ static INLINE int calc_mi_size(int len) {
   return len + MAX_MIB_SIZE;
 }
 
+static INLINE void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh, int bwl,
+                                int bhl) {
+  int i;
+  for (i = 0; i < MAX_MB_PLANE; i++) {
+    xd->plane[i].n4_w = (bw << 1) >> xd->plane[i].subsampling_x;
+    xd->plane[i].n4_h = (bh << 1) >> xd->plane[i].subsampling_y;
+    xd->plane[i].n4_wl = bwl - xd->plane[i].subsampling_x;
+    xd->plane[i].n4_hl = bhl - xd->plane[i].subsampling_y;
+  }
+}
+
 static INLINE void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
                                   int mi_row, int bh, int mi_col, int bw,
                                   int mi_rows, int mi_cols) {
index 402dc0612d6cb583d7b577c3431305af44a0556a..67d0eea49d3e2814de899eca213527ce85c35fc3 100644 (file)
@@ -393,17 +393,6 @@ static INLINE void dec_reset_skip_context(MACROBLOCKD *xd) {
   }
 }
 
-static void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh, int bwl,
-                         int bhl) {
-  int i;
-  for (i = 0; i < MAX_MB_PLANE; i++) {
-    xd->plane[i].n4_w = (bw << 1) >> xd->plane[i].subsampling_x;
-    xd->plane[i].n4_h = (bh << 1) >> xd->plane[i].subsampling_y;
-    xd->plane[i].n4_wl = bwl - xd->plane[i].subsampling_x;
-    xd->plane[i].n4_hl = bhl - xd->plane[i].subsampling_y;
-  }
-}
-
 static MB_MODE_INFO *set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd,
                                  BLOCK_SIZE bsize, int mi_row, int mi_col,
                                  int bw, int bh, int x_mis, int y_mis, int bwl,
index 7077788afb75525112bfb6098500699c3e4441e6..42679da0fff8177820c98bdb4351b4d835103967 100644 (file)
@@ -294,47 +294,6 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
   return c;
 }
 
-// TODO(slavarnway): Decode version of av1_set_context.  Modify
-// av1_set_context
-// after testing is complete, then delete this version.
-static void dec_set_contexts(const MACROBLOCKD *xd,
-                             struct macroblockd_plane *pd, TX_SIZE tx_size,
-                             int has_eob, int aoff, int loff) {
-  ENTROPY_CONTEXT *const a = pd->above_context + aoff;
-  ENTROPY_CONTEXT *const l = pd->left_context + loff;
-  const int tx_w_in_blocks = num_4x4_blocks_wide_txsize_lookup[tx_size];
-  const int tx_h_in_blocks = num_4x4_blocks_high_txsize_lookup[tx_size];
-
-  // above
-  if (has_eob && xd->mb_to_right_edge < 0) {
-    int i;
-    const int blocks_wide =
-        pd->n4_w + (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
-    int above_contexts = tx_w_in_blocks;
-    if (above_contexts + aoff > blocks_wide)
-      above_contexts = blocks_wide - aoff;
-
-    for (i = 0; i < above_contexts; ++i) a[i] = has_eob;
-    for (i = above_contexts; i < tx_w_in_blocks; ++i) a[i] = 0;
-  } else {
-    memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_w_in_blocks);
-  }
-
-  // left
-  if (has_eob && xd->mb_to_bottom_edge < 0) {
-    int i;
-    const int blocks_high =
-        pd->n4_h + (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
-    int left_contexts = tx_h_in_blocks;
-    if (left_contexts + loff > blocks_high) left_contexts = blocks_high - loff;
-
-    for (i = 0; i < left_contexts; ++i) l[i] = has_eob;
-    for (i = left_contexts; i < tx_h_in_blocks; ++i) l[i] = 0;
-  } else {
-    memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_h_in_blocks);
-  }
-}
-
 #if CONFIG_PALETTE
 void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
                                aom_reader *r) {
@@ -391,11 +350,6 @@ int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
 #endif  // CONFIG_NEW_QUANT
                    ctx, sc->scan, sc->neighbors, r);
 #endif  // CONFIG_AOM_QM
-  dec_set_contexts(xd, pd, tx_size, eob > 0, x, y);
-  /*
-  av1_set_contexts(xd, pd,
-                    get_plane_block_size(xd->mi[0]->mbmi.sb_type, pd),
-                    tx_size, eob > 0, x, y);
-                    */
+  av1_set_contexts(xd, pd, tx_size, eob > 0, x, y);
   return eob;
 }
index 04d5282b8bac988cd05d2aa5bbcbe180f23f946e..d3b97d68d5bb31c60b996f9afb47cb6aa9b5c126 100644 (file)
@@ -262,6 +262,8 @@ static void set_offsets_without_segment_id(const AV1_COMP *const cpi,
   MACROBLOCKD *const xd = &x->e_mbd;
   const int mi_width = num_8x8_blocks_wide_lookup[bsize];
   const int mi_height = num_8x8_blocks_high_lookup[bsize];
+  const int bwl = b_width_log2_lookup[AOMMAX(bsize, BLOCK_8X8)];
+  const int bhl = b_height_log2_lookup[AOMMAX(bsize, BLOCK_8X8)];
 
   set_skip_context(xd, mi_row, mi_col);
 
@@ -284,6 +286,8 @@ static void set_offsets_without_segment_id(const AV1_COMP *const cpi,
   x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + AOM_INTERP_EXTEND;
   x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + AOM_INTERP_EXTEND;
 
+  set_plane_n4(xd, mi_width, mi_height, bwl, bhl);
+
   // Set up distance of MB to edge of frame in 1/8th pel units.
   assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1)));
   set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, cm->mi_rows,
index fd0f76bb8d66566148ce4edc649d122b99ab6029..13abe6be5b761dd232d56c455c7a150b2bf90701 100644 (file)
@@ -369,8 +369,8 @@ static void cost_coeffs_b(int plane, int block, int blk_row, int blk_col,
   int rate = av1_cost_coeffs(cm, x, plane, block, pt, tx_size, scan_order->scan,
                              scan_order->neighbors, 0);
   args->this_rate += rate;
-  av1_set_contexts(xd, pd, plane_bsize, tx_size, p->eobs[block] > 0, blk_col,
-                   blk_row);
+  (void)plane_bsize;
+  av1_set_contexts(xd, pd, tx_size, p->eobs[block] > 0, blk_col, blk_row);
 }
 
 static void set_entropy_context_b(int plane, int block, int blk_row,
@@ -382,8 +382,8 @@ static void set_entropy_context_b(int plane, int block, int blk_row,
   MACROBLOCKD *const xd = &x->e_mbd;
   struct macroblock_plane *p = &x->plane[plane];
   struct macroblockd_plane *pd = &xd->plane[plane];
-  av1_set_contexts(xd, pd, plane_bsize, tx_size, p->eobs[block] > 0, blk_col,
-                   blk_row);
+  (void)plane_bsize;
+  av1_set_contexts(xd, pd, tx_size, p->eobs[block] > 0, blk_col, blk_row);
 }
 
 static INLINE void add_token(TOKENEXTRA **t, const aom_prob *context_tree,
@@ -501,6 +501,7 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
   int skip_eob = 0;
   int16_t token;
   EXTRABIT extra;
+  (void)plane_bsize;
   pt = get_entropy_context(tx_size, pd->above_context + blk_col,
                            pd->left_context + blk_row);
   scan = scan_order->scan;
@@ -535,7 +536,7 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
 
   *tp = t;
 
-  av1_set_contexts(xd, pd, plane_bsize, tx_size, c > 0, blk_col, blk_row);
+  av1_set_contexts(xd, pd, tx_size, c > 0, blk_col, blk_row);
 }
 
 struct is_skippable_args {