]> granicus.if.org Git - libvpx/commitdiff
Refactor decoder side qcoeff reset
authorJingning Han <jingning@google.com>
Fri, 21 Oct 2016 18:48:15 +0000 (11:48 -0700)
committerJingning Han <jingning@google.com>
Fri, 21 Oct 2016 22:10:23 +0000 (15:10 -0700)
Allow the decoder to memset partial dequantized coefficient line
to zero.

Change-Id: I1f07dc7bf802958754502c1b5c819cc81e7a08cb

av1/decoder/decodeframe.c
av1/decoder/detokenize.c
av1/decoder/detokenize.h

index 2e6e74403312d00ea4b55ff055e6e8341ed2b299..d63afe560aff0cd9199f7a16cf5484f3fe5d602c 100644 (file)
@@ -232,34 +232,26 @@ static void read_mv_probs(nmv_context *ctx, int allow_hp, aom_reader *r) {
 static void inverse_transform_block(MACROBLOCKD *xd, int plane,
                                     const TX_TYPE tx_type,
                                     const TX_SIZE tx_size, uint8_t *dst,
-                                    int stride, int eob) {
+                                    int stride, int16_t scan_line, int eob) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
-  if (eob > 0) {
-    tran_low_t *const dqcoeff = pd->dqcoeff;
-    INV_TXFM_PARAM inv_txfm_param;
-    inv_txfm_param.tx_type = tx_type;
-    inv_txfm_param.tx_size = tx_size;
-    inv_txfm_param.eob = eob;
-    inv_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
+  tran_low_t *const dqcoeff = pd->dqcoeff;
+  INV_TXFM_PARAM inv_txfm_param;
+  inv_txfm_param.tx_type = tx_type;
+  inv_txfm_param.tx_size = tx_size;
+  inv_txfm_param.eob = eob;
+  inv_txfm_param.lossless = xd->lossless[xd->mi[0]->mbmi.segment_id];
 
 #if CONFIG_AOM_HIGHBITDEPTH
-    if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
-      inv_txfm_param.bd = xd->bd;
-      highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
-    } else {
+  if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
+    inv_txfm_param.bd = xd->bd;
+    highbd_inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+  } else {
 #endif  // CONFIG_AOM_HIGHBITDEPTH
-      inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
+    inv_txfm_add(dqcoeff, dst, stride, &inv_txfm_param);
 #if CONFIG_AOM_HIGHBITDEPTH
-    }
-#endif  // CONFIG_AOM_HIGHBITDEPTH
-
-    // TODO(jingning): This cleans up different reset requests from various
-    // experiments, but incurs unnecessary memset size.
-    if (eob == 1)
-      dqcoeff[0] = 0;
-    else
-      memset(dqcoeff, 0, tx_size_2d[tx_size] * sizeof(dqcoeff[0]));
   }
+#endif  // CONFIG_AOM_HIGHBITDEPTH
+  memset(dqcoeff, 0, (scan_line + 1) * sizeof(dqcoeff[0]));
 }
 
 static void predict_and_reconstruct_intra_block(AV1_COMMON *cm,
@@ -288,10 +280,13 @@ static void predict_and_reconstruct_intra_block(AV1_COMMON *cm,
   if (!mbmi->skip) {
     TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
     const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, 0);
-    const int eob = av1_decode_block_tokens(
-        xd, plane, scan_order, col, row, tx_size, tx_type, r, mbmi->segment_id);
-    inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
-                            eob);
+    int16_t max_scan_line = 0;
+    const int eob =
+        av1_decode_block_tokens(xd, plane, scan_order, col, row, tx_size,
+                                tx_type, &max_scan_line, r, mbmi->segment_id);
+    if (eob)
+      inverse_transform_block(xd, plane, tx_type, tx_size, dst, pd->dst.stride,
+                              max_scan_line, eob);
   }
 }
 
@@ -322,13 +317,14 @@ static void decode_reconstruct_tx(AV1_COMMON *cm, MACROBLOCKD *const xd,
     PLANE_TYPE plane_type = (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
     TX_TYPE tx_type = get_tx_type(plane_type, xd, block, plane_tx_size);
     const SCAN_ORDER *sc = get_scan(cm, plane_tx_size, tx_type, 1);
+    int16_t max_scan_line = 0;
     const int eob =
         av1_decode_block_tokens(xd, plane, sc, blk_col, blk_row, plane_tx_size,
-                                tx_type, r, mbmi->segment_id);
+                                tx_type, &max_scan_line, r, mbmi->segment_id);
     inverse_transform_block(
         xd, plane, tx_type, plane_tx_size,
         &pd->dst.buf[4 * blk_row * pd->dst.stride + 4 * blk_col],
-        pd->dst.stride, eob);
+        pd->dst.stride, max_scan_line, eob);
     *eob_total += eob;
   } else {
     int bsl = b_width_log2_lookup[bsize];
@@ -366,12 +362,14 @@ static int reconstruct_inter_block(AV1_COMMON *cm, MACROBLOCKD *const xd,
   int block_idx = (row << 1) + col;
   TX_TYPE tx_type = get_tx_type(plane_type, xd, block_idx, tx_size);
   const SCAN_ORDER *scan_order = get_scan(cm, tx_size, tx_type, 1);
-  const int eob = av1_decode_block_tokens(xd, plane, scan_order, col, row,
-                                          tx_size, tx_type, r, segment_id);
-
-  inverse_transform_block(xd, plane, tx_type, tx_size,
-                          &pd->dst.buf[4 * row * pd->dst.stride + 4 * col],
-                          pd->dst.stride, eob);
+  int16_t max_scan_line = 0;
+  const int eob =
+      av1_decode_block_tokens(xd, plane, scan_order, col, row, tx_size, tx_type,
+                              &max_scan_line, r, segment_id);
+  if (eob)
+    inverse_transform_block(xd, plane, tx_type, tx_size,
+                            &pd->dst.buf[4 * row * pd->dst.stride + 4 * col],
+                            pd->dst.stride, max_scan_line, eob);
   return eob;
 }
 #endif  // !CONFIG_VAR_TX || CONFIG_SUPER_TX
index f2f74f54061753cd6092dbab404606b4cd291da1..9c01b93b4658e9648ec870619406dbabdb3847b3 100644 (file)
@@ -61,7 +61,7 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
                         dequant_val_type_nuq *dq_val,
 #endif  // CONFIG_NEW_QUANT
                         int ctx, const int16_t *scan, const int16_t *nb,
-                        aom_reader *r)
+                        int16_t *max_scan_line, aom_reader *r)
 #endif
 {
   FRAME_COUNTS *counts = xd->counts;
@@ -166,6 +166,9 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
       dqv_val = &dq_val[band][0];
 #endif  // CONFIG_NEW_QUANT
     }
+
+    *max_scan_line = AOMMAX(*max_scan_line, scan[c]);
+
 #if CONFIG_RANS
     cdf = &coef_cdfs[band][ctx];
     token = ONE_TOKEN +
@@ -327,7 +330,8 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane,
 
 int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
                             const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
-                            TX_TYPE tx_type, aom_reader *r, int seg_id) {
+                            TX_TYPE tx_type, int16_t *max_scan_line,
+                            aom_reader *r, int seg_id) {
   struct macroblockd_plane *const pd = &xd->plane[plane];
   const int16_t *const dequant = pd->seg_dequant[seg_id];
   const int ctx =
@@ -339,16 +343,16 @@ int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
 #endif  //  CONFIG_NEW_QUANT
 
 #if CONFIG_AOM_QM
-  const int eob =
-      decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
-                   ctx, sc->scan, sc->neighbors, r, pd->seg_iqmatrix[seg_id]);
+  const int eob = decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size,
+                               tx_type, dequant, ctx, sc->scan, sc->neighbors,
+                               &sc->max_scan_line, r, pd->seg_iqmatrix[seg_id]);
 #else
   const int eob =
       decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size, tx_type, dequant,
 #if CONFIG_NEW_QUANT
                    pd->seg_dequant_nuq[seg_id][dq],
 #endif  // CONFIG_NEW_QUANT
-                   ctx, sc->scan, sc->neighbors, r);
+                   ctx, sc->scan, sc->neighbors, max_scan_line, r);
 #endif  // CONFIG_AOM_QM
   av1_set_contexts(xd, pd, tx_size, eob > 0, x, y);
   return eob;
index 9c08ff9b8700524d48575df166d1700b8cc40f16..1eb1e6c1a3148f5166aa2bc637a95f7c3c11e6dc 100644 (file)
@@ -28,7 +28,7 @@ void av1_decode_palette_tokens(MACROBLOCKD *const xd, int plane, aom_reader *r);
 
 int av1_decode_block_tokens(MACROBLOCKD *const xd, int plane,
                             const SCAN_ORDER *sc, int x, int y, TX_SIZE tx_size,
-                            TX_TYPE tx_type,
+                            TX_TYPE tx_type, int16_t *max_scan_line,
 #if CONFIG_ANS
                             struct AnsDecoder *const r,
 #else