Fix number of workers in tpl multi-threading

The number of workers used to assign macroblock
rows in tpl multi-threading was incorrect.
This patch fixes the issue.

BUG=aomedia:2710

Change-Id: I940dfea0d8e1ba2c3e84befd52e18a4ee7203b06
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 19826f8..7dabbbd 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -1171,7 +1171,6 @@
   (void)unused;
   EncWorkerData *thread_data = (EncWorkerData *)arg1;
   AV1_COMP *cpi = thread_data->cpi;
-  MultiThreadInfo *mt_info = &cpi->mt_info;
   AV1_COMMON *cm = &cpi->common;
   MACROBLOCK *x = &thread_data->td->mb;
   MACROBLOCKD *xd = &x->e_mbd;
@@ -1179,7 +1178,7 @@
   BLOCK_SIZE bsize = convert_length_to_bsize(MC_FLOW_BSIZE_1D);
   TX_SIZE tx_size = max_txsize_lookup[bsize];
   int mi_height = mi_size_high[bsize];
-  int num_active_workers = mt_info->num_enc_workers;
+  int num_active_workers = cpi->tpl_data.tpl_mt_sync.num_threads_working;
   for (int mi_row = thread_data->start * mi_height; mi_row < mi_params->mi_rows;
        mi_row += num_active_workers * mi_height) {
     // Motion estimation row boundary
@@ -1288,6 +1287,11 @@
   int mb_rows = mi_params->mb_rows;
   int num_workers = compute_num_tpl_workers(cpi);
 
+  if (mt_info->num_enc_workers == 0)
+    create_enc_workers(cpi, num_workers);
+  else
+    num_workers = AOMMIN(num_workers, mt_info->num_enc_workers);
+
   if (!tpl_sync->sync_range || mb_rows != tpl_sync->rows ||
       num_workers > tpl_sync->num_threads_working) {
     av1_tpl_dealloc(tpl_sync);
@@ -1299,11 +1303,6 @@
   memset(tpl_sync->num_finished_cols, -1,
          sizeof(*tpl_sync->num_finished_cols) * mb_rows);
 
-  if (mt_info->num_enc_workers == 0)
-    create_enc_workers(cpi, num_workers);
-  else
-    num_workers = AOMMIN(num_workers, mt_info->num_enc_workers);
-
   prepare_tpl_workers(cpi, tpl_worker_hook, num_workers);
   launch_enc_workers(&cpi->mt_info, num_workers);
   sync_enc_workers(&cpi->mt_info, cm, num_workers);