Cleanup of enc row-mt for update_cdf=0

In case of row-based multi-threading of encoder for
--cdf-update-mode=0, allocation of memory for row_ctx
could be avoided. Code cleanup is done for the same.

Change-Id: I80c0ad90e8c27badcfa94d9c20b358bb58f2496a
diff --git a/av1/encoder/av1_multi_thread.c b/av1/encoder/av1_multi_thread.c
index ff4c4ac..1260c7a 100644
--- a/av1/encoder/av1_multi_thread.c
+++ b/av1/encoder/av1_multi_thread.c
@@ -35,12 +35,14 @@
           &cpi->tile_data[tile_row * multi_thread_ctxt->allocated_tile_cols +
                           tile_col];
       av1_row_mt_sync_mem_alloc(&this_tile->row_mt_sync, cm, max_sb_rows);
-      CHECK_MEM_ERROR(
-          cm, this_tile->row_ctx,
-          (FRAME_CONTEXT *)aom_memalign(
-              16, AOMMAX(1, (av1_get_sb_cols_in_tile(cm, this_tile->tile_info) -
-                             1)) *
-                      sizeof(*this_tile->row_ctx)));
+      if (cpi->oxcf.cdf_update_mode)
+        CHECK_MEM_ERROR(
+            cm, this_tile->row_ctx,
+            (FRAME_CONTEXT *)aom_memalign(
+                16,
+                AOMMAX(1, (av1_get_sb_cols_in_tile(cm, this_tile->tile_info) -
+                           1)) *
+                    sizeof(*this_tile->row_ctx)));
     }
   }
 }
@@ -59,7 +61,7 @@
           &cpi->tile_data[tile_row * multi_thread_ctxt->allocated_tile_cols +
                           tile_col];
       av1_row_mt_sync_mem_dealloc(&this_tile->row_mt_sync);
-      aom_free(this_tile->row_ctx);
+      if (cpi->oxcf.cdf_update_mode) aom_free(this_tile->row_ctx);
     }
   }
   multi_thread_ctxt->allocated_sb_rows = 0;
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 85caff6..0206f3b 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -5526,21 +5526,20 @@
        mi_col < tile_info->mi_col_end; mi_col += mib_size, sb_col_in_tile++) {
     (*(cpi->row_mt_sync_read_ptr))(&tile_data->row_mt_sync, sb_row,
                                    sb_col_in_tile);
-    if ((cpi->row_mt == 1) && (tile_info->mi_row_start != mi_row)) {
+    if (tile_data->allow_update_cdf && (cpi->row_mt == 1) &&
+        (tile_info->mi_row_start != mi_row)) {
       if ((tile_info->mi_col_start == mi_col)) {
         // restore frame context of 1st column sb
         memcpy(xd->tile_ctx, x->row_ctx, sizeof(*xd->tile_ctx));
       } else {
-        if (tile_data->allow_update_cdf) {
-          int wt_left = AVG_CDF_WEIGHT_LEFT;
-          int wt_tr = AVG_CDF_WEIGHT_TOP_RIGHT;
-          if (tile_info->mi_col_end > (mi_col + mib_size))
-            avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile, wt_left,
-                            wt_tr);
-          else
-            avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile - 1,
-                            wt_left, wt_tr);
-        }
+        int wt_left = AVG_CDF_WEIGHT_LEFT;
+        int wt_tr = AVG_CDF_WEIGHT_TOP_RIGHT;
+        if (tile_info->mi_col_end > (mi_col + mib_size))
+          avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile, wt_left,
+                          wt_tr);
+        else
+          avg_cdf_symbols(xd->tile_ctx, x->row_ctx + sb_col_in_tile - 1,
+                          wt_left, wt_tr);
       }
     }
     av1_fill_coeff_costs(&td->mb, xd->tile_ctx, num_planes);
@@ -5647,7 +5646,8 @@
       av1_inter_mode_data_fit(tile_data, x->rdmult);
     }
 #endif
-    if ((cpi->row_mt == 1) && (tile_info->mi_row_end > (mi_row + mib_size))) {
+    if (tile_data->allow_update_cdf && (cpi->row_mt == 1) &&
+        (tile_info->mi_row_end > (mi_row + mib_size))) {
       if (sb_cols_in_tile == 1)
         memcpy(x->row_ctx, xd->tile_ctx, sizeof(*xd->tile_ctx));
       else if (sb_col_in_tile >= 1)
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index a82f2af..943567f 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -310,9 +310,14 @@
 
     td->mb.e_mbd.tile_ctx = td->tctx;
     td->mb.tile_pb_ctx = &this_tile->tctx;
-    td->mb.row_ctx = this_tile->row_ctx;
-    if (current_mi_row == this_tile->tile_info.mi_row_start)
+    if (this_tile->allow_update_cdf) {
+      td->mb.row_ctx = this_tile->row_ctx;
+      if (current_mi_row == this_tile->tile_info.mi_row_start)
+        memcpy(td->mb.e_mbd.tile_ctx, &this_tile->tctx, sizeof(FRAME_CONTEXT));
+    } else {
       memcpy(td->mb.e_mbd.tile_ctx, &this_tile->tctx, sizeof(FRAME_CONTEXT));
+    }
+
     av1_init_above_context(cm, &td->mb.e_mbd, tile_row);
 
     // Disable exhaustive search speed features for row based multi-threading of