Fix number of workers in multi-thread case

The number of workers accessed in tpl and encoding stages
could exceed the number of workers created in case of
resizing. This patch fixes this issue.

BUG=aomedia:2710

Change-Id: I60ca6858156e27d457d85bfe7fad39b77ba1a30c
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 4b924d7..62683b6 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -2257,7 +2257,7 @@
       num_workers = av1_fp_compute_num_enc_workers(cpi);
 #endif
     } else {
-      num_workers = av1_compute_num_enc_workers(cpi);
+      num_workers = av1_compute_num_enc_workers(cpi, cpi->oxcf.max_threads);
     }
     if ((num_workers > 1) && (cpi->mt_info.num_workers == 0))
       av1_create_workers(cpi, num_workers);
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 63f7b87..35cf820 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -857,12 +857,12 @@
 }
 
 // Computes the number of workers for encoding stage (row/tile multi-threading)
-int av1_compute_num_enc_workers(AV1_COMP *cpi) {
-  if (cpi->oxcf.max_threads <= 1) return 1;
-  if (cpi->oxcf.row_mt && (cpi->oxcf.max_threads > 1))
-    return compute_num_enc_row_mt_workers(&cpi->common, cpi->oxcf.max_threads);
+int av1_compute_num_enc_workers(AV1_COMP *cpi, int max_workers) {
+  if (max_workers <= 1) return 1;
+  if (cpi->oxcf.row_mt && (max_workers > 1))
+    return compute_num_enc_row_mt_workers(&cpi->common, max_workers);
   else
-    return compute_num_enc_tile_mt_workers(&cpi->common, cpi->oxcf.max_threads);
+    return compute_num_enc_tile_mt_workers(&cpi->common, max_workers);
 }
 
 void av1_encode_tiles_mt(AV1_COMP *cpi) {
@@ -870,7 +870,7 @@
   MultiThreadInfo *const mt_info = &cpi->mt_info;
   const int tile_cols = cm->tiles.cols;
   const int tile_rows = cm->tiles.rows;
-  int num_workers = av1_compute_num_enc_workers(cpi);
+  int num_workers = av1_compute_num_enc_workers(cpi, mt_info->num_workers);
 
   assert(IMPLIES(cpi->tile_data == NULL,
                  cpi->allocated_tiles < tile_cols * tile_rows));
@@ -976,7 +976,7 @@
   // threads to the theoretical limit in row-mt does not have much impact on
   // post-processing multi-threading stage. Need to revisit this when
   // post-processing time starts shooting up.
-  int num_workers = av1_compute_num_enc_workers(cpi);
+  int num_workers = av1_compute_num_enc_workers(cpi, mt_info->num_workers);
 
   assert(IMPLIES(cpi->tile_data == NULL,
                  cpi->allocated_tiles < tile_cols * tile_rows));
@@ -1274,7 +1274,7 @@
 
 // Computes num_workers for tpl multi-threading.
 static AOM_INLINE int compute_num_tpl_workers(AV1_COMP *cpi) {
-  return av1_compute_num_enc_workers(cpi);
+  return av1_compute_num_enc_workers(cpi, cpi->mt_info.num_workers);
 }
 
 // Implements multi-threading for tpl.
diff --git a/av1/encoder/ethread.h b/av1/encoder/ethread.h
index 02964ec..21bfc01 100644
--- a/av1/encoder/ethread.h
+++ b/av1/encoder/ethread.h
@@ -70,7 +70,7 @@
 
 #endif  // !CONFIG_REALTIME_ONLY
 
-int av1_compute_num_enc_workers(AV1_COMP *cpi);
+int av1_compute_num_enc_workers(AV1_COMP *cpi, int max_workers);
 
 void av1_create_workers(AV1_COMP *cpi, int num_workers);