CSD: report the new csd values to AudioService

We are reporting with every new callback from the MelProcessor the
values that lead to a change of at least 1% of CSD.

Test: manual, logs
Bug: 257238734
Change-Id: I3f0c39c9fda62bfccd3401e065586ca8621627ca
diff --git a/services/audioflinger/sounddose/SoundDoseManager.h b/services/audioflinger/sounddose/SoundDoseManager.h
index 754b569..9a95e8a 100644
--- a/services/audioflinger/sounddose/SoundDoseManager.h
+++ b/services/audioflinger/sounddose/SoundDoseManager.h
@@ -18,16 +18,16 @@
 #pragma once
 
 #include <android/media/ISoundDoseCallback.h>
-#include <audio_utils/MelProcessor.h>
 #include <audio_utils/MelAggregator.h>
+#include <audio_utils/MelProcessor.h>
+#include <utils/Errors.h>
 #include <mutex>
 #include <unordered_map>
-#include <utils/Errors.h>
 
 namespace android {
 
 class SoundDoseManager : public audio_utils::MelProcessor::MelCallback {
-public:
+  public:
     /** CSD is computed with a rolling window of 7 days. */
     static constexpr int64_t kCsdWindowSeconds = 604800;  // 60s * 60m * 24h * 7d
     /** Default RS2 value in dBA as defined in IEC 62368-1 3rd edition. */
@@ -35,7 +35,7 @@
 
     SoundDoseManager()
         : mMelAggregator(sp<audio_utils::MelAggregator>::make(kCsdWindowSeconds)),
-          mRs2Value(kDefaultRs2Value) {};
+          mRs2Value(kDefaultRs2Value){};
 
     /**
      * \brief Creates or gets the MelProcessor assigned to the streamHandle
@@ -48,12 +48,11 @@
      *
      * \return MelProcessor assigned to the stream and device id.
      */
-    sp<audio_utils::MelProcessor> getOrCreateProcessorForDevice(
-        audio_port_handle_t deviceId,
-        audio_io_handle_t streamHandle,
-        uint32_t sampleRate,
-        size_t channelCount,
-        audio_format_t format);
+    sp<audio_utils::MelProcessor> getOrCreateProcessorForDevice(audio_port_handle_t deviceId,
+                                                                audio_io_handle_t streamHandle,
+                                                                uint32_t sampleRate,
+                                                                size_t channelCount,
+                                                                audio_format_t format);
 
     /**
      * \brief Removes stream processor when MEL computation is not needed anymore
@@ -78,21 +77,25 @@
     // used for testing
     size_t getCachedMelRecordsSize() const;
 
+    /** Method for converting from audio_utils::CsdRecord to media::SoundDoseRecord. */
+    static media::SoundDoseRecord csdRecordToSoundDoseRecord(const audio_utils::CsdRecord& legacy);
+
     // ------ Override audio_utils::MelProcessor::MelCallback ------
-    void onNewMelValues(const std::vector<float>& mels,
-                        size_t offset,
-                        size_t length,
+    void onNewMelValues(const std::vector<float>& mels, size_t offset, size_t length,
                         audio_port_handle_t deviceId) const override;
 
     void onMomentaryExposure(float currentMel, audio_port_handle_t deviceId) const override;
-private:
+
+  private:
+    sp<media::ISoundDoseCallback> getSoundDoseCallback() const;
+
     mutable std::mutex mLock;
 
     // no need for lock since MelAggregator is thread-safe
     const sp<audio_utils::MelAggregator> mMelAggregator;
 
-    std::unordered_map<audio_io_handle_t,
-                       wp<audio_utils::MelProcessor>> mActiveProcessors GUARDED_BY(mLock);
+    std::unordered_map<audio_io_handle_t, wp<audio_utils::MelProcessor>> mActiveProcessors
+            GUARDED_BY(mLock);
 
     float mRs2Value GUARDED_BY(mLock);