CSD: extract SoundDoseManager for MEL handling

The SoundDoseManager owns the aggregator which computes the sound dose.
This is a central place for passing the sound dose properties up to the
higher layers.

Test: UT and dumpsys media.audio_flinger
Bug: 255943034

Change-Id: I2d8139b9115bdd793d4ed418f2da6bc8782d32b3
diff --git a/services/audioflinger/MelReporter.cpp b/services/audioflinger/MelReporter.cpp
index 9a579dd..88500b8 100644
--- a/services/audioflinger/MelReporter.cpp
+++ b/services/audioflinger/MelReporter.cpp
@@ -18,13 +18,11 @@
 // #define LOG_NDEBUG 0
 #define LOG_TAG "AudioFlinger::MelReporter"
 
-#include <cinttypes>
-#include <utils/Log.h>
-#include <android-base/stringprintf.h>
-#include <audio_utils/power.h>
-
 #include "AudioFlinger.h"
 
+#include <audio_utils/power.h>
+#include <utils/Log.h>
+
 namespace android {
 
 bool AudioFlinger::MelReporter::shouldComputeMelForDeviceType(audio_devices_t device) {
@@ -67,7 +65,7 @@
             std::lock_guard _lAf(mAudioFlinger.mLock);
             auto thread = mAudioFlinger.checkPlaybackThread_l(streamHandle);
             if (thread != nullptr) {
-                thread->startMelComputation(mMelAggregator.getOrCreateCallbackForDevice(
+                thread->startMelComputation(mSoundDoseManager.getOrCreateCallbackForDevice(
                     deviceId,
                     newPatch.streamHandle));
             }
@@ -103,24 +101,13 @@
     if (thread != nullptr) {
         thread->stopMelComputation();
     }
-    mMelAggregator.removeStreamCallback(melPatch.streamHandle);
+    mSoundDoseManager.removeStreamCallback(melPatch.streamHandle);
 }
 
 std::string AudioFlinger::MelReporter::dump() {
     std::lock_guard _l(mLock);
-    std::string output;
-
-    base::StringAppendF(&output, "\nMel Reporter:\n");
-    mMelAggregator.foreach([&output](const audio_utils::MelRecord& melRecord) {
-        base::StringAppendF(&output, "Continuous MELs for portId=%d, ", melRecord.portId);
-        base::StringAppendF(&output, "starting at timestamp %" PRId64 ": ", melRecord.timestamp);
-
-        for (const auto& mel : melRecord.mels) {
-            base::StringAppendF(&output, "%d ", mel);
-        }
-        base::StringAppendF(&output, "\n");
-    });
-
+    std::string output("\nSound Dose:\n");
+    output.append(mSoundDoseManager.dump());
     return output;
 }