Commit 822f287f60 for aom

commit 822f287f60cc99775d0293baa8f20dd8af88f2c4
Author: Wan-Teh Chang <wtc@google.com>
Date:   Tue Sep 15 14:43:09 2026 -0700

    Pass num_workers to enc_worker_hook() as arg2

    Pass num_workers to enc_worker_hook() as the second parameter arg2. This
    allows enc_worker_hook() to avoid using cpi->mt_info.num_workers, which
    is really the size of the cpi->mt_info.workers array rather than the
    current value of g_threads.

    Remove the saving and restoring of mt_info->num_workers around the
    av1_encode_tiles_mt(cpi) call in encode_frame_internal(). This
    workaround is no longer necessary.

    A follow-up to commit 532ba44.

    Bug: 558463888, 559075253, 559225640
    Change-Id: Idd5f9bef1e84b2e893699e997c307fe1fd1556c3

diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c
index 50f7fb6519..da817888b0 100644
--- a/av1/encoder/encodeframe.c
+++ b/av1/encoder/encodeframe.c
@@ -2455,10 +2455,7 @@ static inline void encode_frame_internal(AV1_COMP *cpi) {
     const int num_workers = AOMMIN(mt_info->num_mod_workers[MOD_ENC],
                                    cm->tiles.cols * cm->tiles.rows);
     if (num_workers > 1) {
-      const int saved_num_workers = mt_info->num_workers;
-      mt_info->num_workers = num_workers;
       av1_encode_tiles_mt(cpi);
-      mt_info->num_workers = saved_num_workers;
     } else {
       // Preallocate the pc_tree for realtime coding to reduce the cost of
       // memory allocation.
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 22d7de77ef..262a671298 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -750,8 +750,9 @@ static int enc_row_mt_worker_hook(void *arg1, void *unused) {
   return 1;
 }

-static int enc_worker_hook(void *arg1, void *unused) {
+static int enc_worker_hook(void *arg1, void *arg2) {
   EncWorkerData *const thread_data = (EncWorkerData *)arg1;
+  const int num_workers = (int)(intptr_t)arg2;
   AV1_COMP *const cpi = thread_data->cpi;
   MACROBLOCKD *const xd = &thread_data->td->mb.e_mbd;
   struct aom_internal_error_info *const error_info = &thread_data->error_info;
@@ -760,8 +761,6 @@ static int enc_worker_hook(void *arg1, void *unused) {
   const int tile_rows = cm->tiles.rows;
   int t;

-  (void)unused;
-
   xd->error_info = error_info;

   // The jmp_buf is valid only for the duration of the function that calls
@@ -784,8 +783,7 @@ static int enc_worker_hook(void *arg1, void *unused) {
     thread_data->td->pc_root = NULL;
   }

-  for (t = thread_data->start; t < tile_rows * tile_cols;
-       t += cpi->mt_info.num_workers) {
+  for (t = thread_data->start; t < tile_rows * tile_cols; t += num_workers) {
     int tile_row = t / tile_cols;
     int tile_col = t % tile_cols;

@@ -1588,7 +1586,7 @@ static inline void prepare_enc_workers(AV1_COMP *cpi, AVxWorkerHook hook,

     worker->hook = hook;
     worker->data1 = thread_data;
-    worker->data2 = NULL;
+    worker->data2 = (void *)(intptr_t)num_workers;

     thread_data->thread_id = i;
     // Set the starting tile for each thread.