CSD: Add Mel processing for FastMixer

Moved the MelProcessor into the AudioStreamOutSink. This should be ok
now to use in the FastMixer since the new MelProcessor logic is not
blocking and the callbacks are executed asynchronously in the MelWorker.

Test: OboeTester + dumpsys and logs
Bug: 264255998
Change-Id: Idce0a2653b4f8fa42ea12893c6e77e765806f3b1
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index c617ef7..0f65aec 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -3428,12 +3428,6 @@
         if (framesWritten > 0) {
             bytesWritten = framesWritten * mFrameSize;
 
-            // Send to MelProcessor for sound dose measurement.
-            auto processor = mMelProcessor.load();
-            if (processor) {
-                processor->process((char *)mSinkBuffer + offset, bytesWritten);
-            }
-
 #ifdef TEE_SINK
             mTee.write((char *)mSinkBuffer + offset, framesWritten);
 #endif
@@ -3479,15 +3473,14 @@
 void AudioFlinger::PlaybackThread::startMelComputation(
         const sp<audio_utils::MelProcessor>& processor)
 {
-    ALOGV("%s: starting mel processor for thread %d", __func__, id());
-    mMelProcessor = processor;
+    auto outputSink = static_cast<AudioStreamOutSink*>(mOutputSink.get());
+    outputSink->startMelComputation(processor);
 }
 
-void AudioFlinger::PlaybackThread::stopMelComputation() {
-    if (mMelProcessor.load() != nullptr) {
-        ALOGV("%s: stopping mel processor for thread %d", __func__, id());
-        mMelProcessor = nullptr;
-    }
+void AudioFlinger::PlaybackThread::stopMelComputation()
+{
+    auto outputSink = static_cast<AudioStreamOutSink*>(mOutputSink.get());
+    outputSink->stopMelComputation();
 }
 
 void AudioFlinger::PlaybackThread::threadLoop_drain()
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index 47d5333..f0062bc 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -1215,8 +1215,6 @@
     audio_channel_mask_t            mMixerChannelMask = AUDIO_CHANNEL_NONE;
 
 private:
-    mediautils::atomic_sp<audio_utils::MelProcessor> mMelProcessor;
-
     // mMasterMute is in both PlaybackThread and in AudioFlinger.  When a
     // PlaybackThread needs to find out if master-muted, it checks it's local
     // copy rather than the one in AudioFlinger.  This optimization saves a lock.
diff --git a/services/audioflinger/sounddose/SoundDoseManager.cpp b/services/audioflinger/sounddose/SoundDoseManager.cpp
index 03a14d0..2f82e17 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.cpp
+++ b/services/audioflinger/sounddose/SoundDoseManager.cpp
@@ -74,7 +74,7 @@
     } else {
         ALOGV("%s: creating new callback for stream id %d", __func__, streamHandle);
         sp<audio_utils::MelProcessor> melProcessor = sp<audio_utils::MelProcessor>::make(
-                sampleRate, channelCount, format, *this, deviceId, mRs2Value);
+                sampleRate, channelCount, format, this, deviceId, mRs2Value);
         const auto activeTypeIt = mActiveDeviceTypes.find(deviceId);
         if (activeTypeIt != mActiveDeviceTypes.end()) {
             melProcessor->setAttenuation(mMelAttenuationDB[activeTypeIt->second]);