Allocate ctxt for each thread in enc row-mt

Context is allocated for each thread to facilitate context
update in row based multi-threading of encoder.

Change-Id: I1d0517906348435682a2d3e208a0fa8ca79b149e
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 26c520d..e94b832 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -3033,6 +3033,7 @@
     aom_get_worker_interface()->end(worker);
 
     // Deallocate allocated thread data.
+    if (cpi->row_mt == 1) aom_free(thread_data->td->tctx);
     if (t < cpi->num_workers - 1) {
       aom_free(thread_data->td->palette_buffer);
       aom_free(thread_data->td->tmp_conv_dst);
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 7009990..3727956 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -176,10 +176,12 @@
 
     TileDataEnc *const this_tile =
         &cpi->tile_data[tile_row * cm->tile_cols + tile_col];
-    thread_data->td->tctx = &this_tile->tctx;
-    thread_data->td->mb.e_mbd.tile_ctx = thread_data->td->tctx;
-    thread_data->td->mb.backup_tile_ctx = &this_tile->backup_tctx;
-    av1_encode_tile(cpi, thread_data->td, tile_row, tile_col);
+    ThreadData *td = thread_data->td;
+
+    td->mb.e_mbd.tile_ctx = td->tctx;
+    td->mb.backup_tile_ctx = &this_tile->backup_tctx;
+    memcpy(td->mb.e_mbd.tile_ctx, &this_tile->tctx, sizeof(FRAME_CONTEXT));
+    av1_encode_tile(cpi, td, tile_row, tile_col);
   }
 
   return 1;
@@ -301,6 +303,10 @@
       // Main thread acts as a worker and uses the thread data in cpi.
       thread_data->td = &cpi->td;
     }
+    if (cpi->row_mt == 1)
+      CHECK_MEM_ERROR(
+          cm, thread_data->td->tctx,
+          (FRAME_CONTEXT *)aom_memalign(16, sizeof(*thread_data->td->tctx)));
     winterface->sync(worker);
   }
 }