Move PVQ flag checking into av1_optimize_b

Change-Id: I00554b925c0a870e766bc116c6d9cb02bd47a101
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c
index 257e231..405943a 100644
--- a/av1/encoder/encodemb.c
+++ b/av1/encoder/encodemb.c
@@ -144,6 +144,7 @@
 
 int av1_optimize_b(const AV1_COMMON *cm, MACROBLOCK *mb, int plane, int block,
                    TX_SIZE tx_size, int ctx) {
+#if !CONFIG_PVQ
   MACROBLOCKD *const xd = &mb->e_mbd;
   struct macroblock_plane *const p = &mb->plane[plane];
   struct macroblockd_plane *const pd = &xd->plane[plane];
@@ -485,6 +486,13 @@
   mb->plane[plane].eobs[block] = final_eob;
   assert(final_eob <= default_eob);
   return final_eob;
+#else   // !CONFIG_PVQ
+  (void)cm;
+  (void)tx_size;
+  (void)ctx;
+  struct macroblock_plane *const p = &mb->plane[plane];
+  return p->eobs[block];
+#endif  // !CONFIG_PVQ
 }
 
 #if !CONFIG_PVQ
@@ -1097,7 +1105,6 @@
   const int dst_stride = pd->dst.stride;
   uint8_t *dst =
       &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]];
-  int ctx = 0;
 #if CONFIG_PVQ
   int tx_blk_size;
   int i, j;
@@ -1107,11 +1114,9 @@
                                  tx_size);
   av1_subtract_txb(x, plane, plane_bsize, blk_col, blk_row, tx_size);
 
-#if !CONFIG_PVQ
   const ENTROPY_CONTEXT *a = &args->ta[blk_col];
   const ENTROPY_CONTEXT *l = &args->tl[blk_row];
-  ctx = combine_entropy_contexts(*a, *l);
-
+  int ctx = combine_entropy_contexts(*a, *l);
   if (args->enable_optimize_b) {
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     ctx, AV1_XFORM_QUANT_FP);
@@ -1123,13 +1128,7 @@
                     ctx, AV1_XFORM_QUANT_B);
   }
 
-  av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride,
-                              *eob);
-#else  // #if !CONFIG_PVQ
-
-  av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
-                  ctx, AV1_XFORM_QUANT_FP);
-
+#if CONFIG_PVQ
   // *(args->skip) == mbmi->skip
   if (!x->pvq_skip[plane]) *(args->skip) = 0;
 
@@ -1154,11 +1153,9 @@
 #if CONFIG_AOM_HIGHBITDEPTH
   }
 #endif  // CONFIG_AOM_HIGHBITDEPTH
-
+#endif  // #if CONFIG_PVQ
   av1_inverse_transform_block(xd, dqcoeff, tx_type, tx_size, dst, dst_stride,
                               *eob);
-#endif  // #if !CONFIG_PVQ
-
 #if !CONFIG_PVQ
   if (*eob) *(args->skip) = 0;
 #else
diff --git a/av1/encoder/rdopt.c b/av1/encoder/rdopt.c
index b1e4c84..f0881c8 100644
--- a/av1/encoder/rdopt.c
+++ b/av1/encoder/rdopt.c
@@ -1625,10 +1625,8 @@
     // full forward transform and quantization
     av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                     coeff_ctx, AV1_XFORM_QUANT_FP);
-#if !CONFIG_PVQ
     if (x->plane[plane].eobs[block] && !xd->lossless[mbmi->segment_id])
       av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
-#endif  // !CONFIG_PVQ
     dist_block(args->cpi, x, plane, plane_bsize, block, blk_row, blk_col,
                tx_size, &this_rd_stats.dist, &this_rd_stats.sse);
   }
@@ -3995,7 +3993,6 @@
   av1_xform_quant(cm, x, plane, block, blk_row, blk_col, plane_bsize, tx_size,
                   coeff_ctx, AV1_XFORM_QUANT_FP);
 
-  // TODO(yushin) : If PVQ is enabled, this should not be called.
   av1_optimize_b(cm, x, plane, block, tx_size, coeff_ctx);
 
 // TODO(any): Use dist_block to compute distortion
@@ -5374,15 +5371,10 @@
       assert(IMPLIES(tx_size == TX_4X8 || tx_size == TX_8X4,
                      idx == 0 && idy == 0));
       coeff_ctx = combine_entropy_contexts(*(ta + (k & 1)), *(tl + (k >> 1)));
-#if !CONFIG_PVQ
       av1_xform_quant(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
                       BLOCK_8X8, tx_size, coeff_ctx, AV1_XFORM_QUANT_FP);
       if (xd->lossless[xd->mi[0]->mbmi.segment_id] == 0)
         av1_optimize_b(cm, x, 0, block, tx_size, coeff_ctx);
-#else
-      av1_xform_quant(cm, x, 0, block, idy + (i >> 1), idx + (i & 0x01),
-                      BLOCK_8X8, tx_size, coeff_ctx, AV1_XFORM_QUANT_FP);
-#endif  // !CONFIG_PVQ
       dist_block(cpi, x, 0, BLOCK_8X8, block, idy + (i >> 1), idx + (i & 0x1),
                  tx_size, &dist, &ssz);
       thisdistortion += dist;