Merge "AudioFlinger: Fix lock inversion for timestampCorrectionEnabled" into main am: 69639a63dc am: 9d411de4ee

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2832878

Change-Id: I3dc69b7a6d105b0cc7c063861f84d09215687747
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 9bf4299..f75790e 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -8104,6 +8104,9 @@
     // used to request a deferred sleep, to be executed later while mutex is unlocked
     uint32_t sleepUs = 0;
 
+    // timestamp correction enable is determined under lock, used in processing step.
+    bool timestampCorrectionEnabled = false;
+
     int64_t lastLoopCountRead = -2;  // never matches "previous" loop, when loopCount = 0.
 
     // loop while there is work to do
@@ -8268,6 +8271,7 @@
             }
             sleepUs = 0;
 
+            timestampCorrectionEnabled = isTimestampCorrectionEnabled_l();
             lockEffectChains_l(effectChains);
         }
 
@@ -8424,13 +8428,6 @@
                     && time > mTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL]) {
 
                 mTimestampVerifier.add(position, time, mSampleRate);
-
-                // Correct timestamps
-                bool timestampCorrectionEnabled = false;
-                {
-                    audio_utils::lock_guard l(mutex());
-                    timestampCorrectionEnabled = isTimestampCorrectionEnabled_l();
-                }
                 if (timestampCorrectionEnabled) {
                     ALOGVV("TS_BEFORE: %d %lld %lld",
                             id(), (long long)time, (long long)position);