CSD: Add csd start/stop of BT categorized devices
BT devices should only compute CSD once they are categorized as
headphones/headsets. The AudioService will send as the cached list of BT
devices together with their categorization which will allow an initial
triage of devices that can calculate the dosage values. There is also a
possibility to dynamically change/add new categorizations which will
start/stop the CSD computation.
Test: atest sounddosemanager_tests
Bug: 287011781
Change-Id: I161533a38cb718c28a8c5a8eaf962e0e5055b5a1
diff --git a/services/audioflinger/MelReporter.h b/services/audioflinger/MelReporter.h
index 005ca96..e26397c 100644
--- a/services/audioflinger/MelReporter.h
+++ b/services/audioflinger/MelReporter.h
@@ -40,11 +40,11 @@
* Class for listening to new patches and starting the MEL computation. MelReporter is
* concealed within AudioFlinger, their lifetimes are the same.
*/
-class MelReporter : public PatchCommandThread::PatchCommandListener {
+class MelReporter : public PatchCommandThread::PatchCommandListener,
+ public IMelReporterCallback {
public:
explicit MelReporter(const sp<IAfMelReporterCallback>& afMelReporterCallback)
- : mAfMelReporterCallback(afMelReporterCallback),
- mSoundDoseManager(sp<SoundDoseManager>::make()) {}
+ : mAfMelReporterCallback(afMelReporterCallback) {}
void onFirstRef() override;
@@ -76,6 +76,10 @@
std::string dump();
+ // IMelReporterCallback methods
+ void stopMelComputationForDeviceId(audio_port_handle_t deviceId) override;
+ void startMelComputationForDeviceId(audio_port_handle_t deviceId) override;
+
// PatchCommandListener methods
void onCreateAudioPatch(audio_patch_handle_t handle,
const IAfPatchPanel::Patch& patch) final;
@@ -94,13 +98,15 @@
private:
struct ActiveMelPatch {
audio_io_handle_t streamHandle{AUDIO_IO_HANDLE_NONE};
- std::vector<audio_port_handle_t> deviceHandles;
+ /**
+ * Stores device ids and whether they are compatible for CSD calculation.
+ * The boolean value can change since BT audio device types are user-configurable
+ * to headphones/headsets or other device types.
+ */
+ std::vector<std::pair<audio_port_handle_t,bool>> deviceStates;
bool csdActive;
};
- /** Returns true if we should compute MEL for the given device. */
- bool shouldComputeMelForDeviceType(audio_devices_t device);
-
void stopInternalMelComputation();
/** Should be called with the following order of locks: mAudioFlinger.mLock -> mLock. */