CSD: add logic for using HAL sound dose values
When the HAL supports the sound dose computation we prefer to use the
MEL value provided by the HAL. These should be more accurate and can be
used for certification with IEC62368-1 3rd edition and EN50332-3.
Current implementation supports the standalone sound dose HAL.
Test: sounddosemanager_tests UT & bluejay-userdebug with internal MEL
Bug: 252776298
Change-Id: Ibbda76781fc869ac457d03d4f9a871fb353a9ba8
diff --git a/services/audioflinger/MelReporter.h b/services/audioflinger/MelReporter.h
index b1abc59..acbc8ed 100644
--- a/services/audioflinger/MelReporter.h
+++ b/services/audioflinger/MelReporter.h
@@ -32,17 +32,34 @@
class MelReporter : public PatchCommandThread::PatchCommandListener {
public:
explicit MelReporter(AudioFlinger& audioFlinger)
- : mAudioFlinger(audioFlinger) {}
+ : mAudioFlinger(audioFlinger),
+ mSoundDoseManager(sp<SoundDoseManager>::make()) {}
- void onFirstRef() override {
- mAudioFlinger.mPatchCommandThread->addListener(this);
- }
+ void onFirstRef() override;
/** Returns true if we should compute MEL for the given device. */
bool shouldComputeMelForDeviceType(audio_devices_t device);
- // For now only support internal MelReporting
- [[nodiscard]] bool isHalReportingEnabled() const { return false; }
+ /**
+ * Activates the MEL reporting from the HAL sound dose interface. If the HAL
+ * does not support the sound dose interface for this module, the internal MEL
+ * calculation will be use.
+ *
+ * For now support internal MelReporting only if the sound dose standalone HAL
+ * is not implemented
+ *
+ * @return true if the MEL reporting will be done from the sound dose HAL
+ * interface
+ */
+ bool activateHalSoundDoseComputation(const std::string& module);
+
+ /**
+ * Activates the MEL reporting from internal framework values. These are used
+ * as a fallback when there is no sound dose interface implementation from HAL.
+ * Note: the internal CSD computation does not guarantee a certification with
+ * IEC62368-1 3rd edition or EN50332-3
+ */
+ void activateInternalSoundDoseComputation();
sp<media::ISoundDose> getSoundDoseInterface(const sp<media::ISoundDoseCallback>& callback);
@@ -54,9 +71,17 @@
void onReleaseAudioPatch(audio_patch_handle_t handle) override;
private:
- AudioFlinger& mAudioFlinger; // does not own the object
+ void stopInternalMelComputation();
+ void stopInternalMelComputationForStream(audio_io_handle_t streamId);
- SoundDoseManager mSoundDoseManager;
+ void startMelComputationForNewPatch(audio_io_handle_t streamHandle,
+ audio_port_handle_t deviceId);
+
+ AudioFlinger& mAudioFlinger; // does not own the object
+ std::shared_ptr<::aidl::android::hardware::audio::sounddose::ISoundDoseFactory>
+ mSoundDoseFactory;
+
+ sp<SoundDoseManager> mSoundDoseManager;
struct ActiveMelPatch {
audio_io_handle_t streamHandle{AUDIO_IO_HANDLE_NONE};
@@ -70,4 +95,5 @@
std::mutex mLock;
std::unordered_map<audio_patch_handle_t, ActiveMelPatch>
mActiveMelPatches GUARDED_BY(AudioFlinger::MelReporter::mLock);
+ bool mUseHalSoundDoseInterface GUARDED_BY(AudioFlinger::MelReporter::mLock) = false;
};