Fix possible deadlock between effect and af lock

When updating the CSD metadata we should not hold the effect lock.
Updating the metadata after we unlock the effect chain.

Test: logs and dumpsys
Bug: 267272643
Change-Id: I3c5f1f1d398e5bcdaaeefb413c63eb0394a7f397
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 8de900e..4ca8a8e 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -4080,11 +4080,6 @@
             setHalLatencyMode_l();
         } // mLock scope ends
 
-        if (!metadataUpdate.playbackMetadataUpdate.empty()) {
-            mAudioFlinger->mMelReporter->updateMetadataForCsd(id(),
-                    metadataUpdate.playbackMetadataUpdate);
-        }
-
         if (mBytesRemaining == 0) {
             mCurrentWriteLength = 0;
             if (mMixerStatus == MIXER_TRACKS_READY) {
@@ -4275,6 +4270,11 @@
         // enable changes in effect chain
         unlockEffectChains(effectChains);
 
+        if (!metadataUpdate.playbackMetadataUpdate.empty()) {
+            mAudioFlinger->mMelReporter->updateMetadataForCsd(id(),
+                    metadataUpdate.playbackMetadataUpdate);
+        }
+
         if (!waitingAsyncCallback()) {
             // mSleepTimeUs == 0 means we must write to audio hardware
             if (mSleepTimeUs == 0) {