aom: Define the MAX_NUM_THREADS macro in enc_enums.h

From e937f26e1e6cd69401070ba68a1e73857d3e1132 Mon Sep 17 00:00:00 2001
From: Wan-Teh Chang <[EMAIL REDACTED]>
Date: Thu, 15 Feb 2024 15:44:28 -0800
Subject: [PATCH] Define the MAX_NUM_THREADS macro in enc_enums.h

The MAX_NUM_THREADS macro is unrelated to the AVxWorkerInterface, so it
doesn't need to be defined in aom_util/aom_thread.h. Move the definition
of the MAX_NUM_THREADS macro to av1/encoder/enc_enums.h.

Note: The ideal place to define the MAX_NUM_THREADS macro is
av1/encoder/ethread.h. Unfortunately av1/encoder/ethread.h must be
included after av1/encoder/encoder.h, but av1/encoder/encoder.h uses the
MAX_NUM_THREADS macro. I could not fix the mutual dependency.

Bug: aomedia:3554
Change-Id: I6add9d8a920fe7a0095b79aeebd2abe4a4f625be
---
 aom_util/aom_thread.h       | 2 --
 av1/av1_cx_iface.c          | 1 +
 av1/encoder/enc_enums.h     | 4 ++++
 av1/encoder/encoder.h       | 2 +-
 av1/encoder/ethread.c       | 1 +
 av1/encoder/global_motion.h | 3 +--
 test/ethread_test.cc        | 5 ++---
 7 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/aom_util/aom_thread.h b/aom_util/aom_thread.h
index 92e162f121..80ed314752 100644
--- a/aom_util/aom_thread.h
+++ b/aom_util/aom_thread.h
@@ -21,8 +21,6 @@
 extern "C" {
 #endif
 
-#define MAX_NUM_THREADS 64
-
 // State of the worker thread object
 typedef enum {
   AVX_WORKER_STATUS_NOT_OK = 0,  // object is unusable
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 2b6b1504e6..39c03c9ecb 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -32,6 +32,7 @@
 #include "av1/common/enums.h"
 #include "av1/common/scale.h"
 #include "av1/encoder/bitstream.h"
+#include "av1/encoder/enc_enums.h"
 #include "av1/encoder/encoder.h"
 #include "av1/encoder/encoder_alloc.h"
 #include "av1/encoder/encoder_utils.h"
diff --git a/av1/encoder/enc_enums.h b/av1/encoder/enc_enums.h
index 20cefa16a5..0a8b0f258a 100644
--- a/av1/encoder/enc_enums.h
+++ b/av1/encoder/enc_enums.h
@@ -12,10 +12,14 @@
 #ifndef AOM_AV1_ENCODER_ENC_ENUMS_H_
 #define AOM_AV1_ENCODER_ENC_ENUMS_H_
 
+#include "aom_ports/mem.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#define MAX_NUM_THREADS 64
+
 // This enumerator type needs to be kept aligned with the mode order in
 // const MODE_DEFINITION av1_mode_defs[MAX_MODES] used in the rd code.
 enum {
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 4de5d426ce..a919bd906a 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -37,6 +37,7 @@
 #include "av1/encoder/av1_quantize.h"
 #include "av1/encoder/block.h"
 #include "av1/encoder/context_tree.h"
+#include "av1/encoder/enc_enums.h"
 #include "av1/encoder/encodemb.h"
 #include "av1/encoder/external_partition.h"
 #include "av1/encoder/firstpass.h"
@@ -74,7 +75,6 @@
 #endif
 
 #include "aom/internal/aom_codec_internal.h"
-#include "aom_util/aom_thread.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 3cc8e20f97..1d0092a5ed 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -19,6 +19,7 @@
 
 #include "av1/encoder/allintra_vis.h"
 #include "av1/encoder/bitstream.h"
+#include "av1/encoder/enc_enums.h"
 #include "av1/encoder/encodeframe.h"
 #include "av1/encoder/encodeframe_utils.h"
 #include "av1/encoder/encoder.h"
diff --git a/av1/encoder/global_motion.h b/av1/encoder/global_motion.h
index dc18940752..2645f93e3c 100644
--- a/av1/encoder/global_motion.h
+++ b/av1/encoder/global_motion.h
@@ -14,9 +14,8 @@
 
 #include "aom/aom_integer.h"
 #include "aom_dsp/flow_estimation/flow_estimation.h"
-#include "aom_scale/yv12config.h"
 #include "aom_util/aom_pthread.h"
-#include "aom_util/aom_thread.h"
+#include "av1/encoder/enc_enums.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/test/ethread_test.cc b/test/ethread_test.cc
index ce45394eb8..415f5de269 100644
--- a/test/ethread_test.cc
+++ b/test/ethread_test.cc
@@ -18,6 +18,7 @@
 #include "test/util.h"
 #include "test/y4m_video_source.h"
 #include "test/yuv_video_source.h"
+#include "av1/encoder/enc_enums.h"
 #include "av1/encoder/firstpass.h"
 
 namespace {
@@ -411,9 +412,7 @@ class AVxEncoderThreadTest
                                 const std::vector<size_t> ref_size_enc,
                                 const std::vector<std::string> ref_md5_enc,
                                 const std::vector<std::string> ref_md5_dec) {
-    // This value should be kept the same as MAX_NUM_THREADS
-    // in aom_thread.h
-    cfg_.g_threads = 64;
+    cfg_.g_threads = MAX_NUM_THREADS;
     ASSERT_NO_FATAL_FAILURE(RunLoop(video));
     std::vector<size_t> multi_thr_max_row_mt_size_enc;
     std::vector<std::string> multi_thr_max_row_mt_md5_enc;