Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1c67ad6c authored by Vlad Popa's avatar Vlad Popa
Browse files

CSD: Fixed test api for csd on all devices

The HAL will not send updates for devices that can not be headphones.
This is why when enabling csd on all devices disable the HAL path for
testing purposes and force the internal MELs. In order to receive dosage
updates resend the patches that were already created.

Test: atest SoundDoseTest
Bug: 319585581
Change-Id: Ib8975f7891b16732cbb0fa4839be28c3eec0aa78
parent 4fd6f048
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -311,7 +311,8 @@ void AudioFlinger::onFirstRef()
    }

    mPatchPanel = IAfPatchPanel::create(sp<IAfPatchPanelCallback>::fromExisting(this));
    mMelReporter = sp<MelReporter>::make(sp<IAfMelReporterCallback>::fromExisting(this));
    mMelReporter = sp<MelReporter>::make(sp<IAfMelReporterCallback>::fromExisting(this),
                                         mPatchPanel);
}

status_t AudioFlinger::setAudioHalPids(const std::vector<pid_t>& pids) {
+16 −0
Original line number Diff line number Diff line
@@ -307,6 +307,22 @@ void MelReporter::stopMelComputationForDeviceId(audio_port_handle_t deviceId) {

}

void MelReporter::applyAllAudioPatches() {
    ALOGV("%s", __func__);

    std::vector<IAfPatchPanel::Patch> patchesCopy;
    {
        audio_utils::lock_guard _laf(mAfMelReporterCallback->mutex());
        for (const auto& patch : mAfPatchPanel->patches_l()) {
            patchesCopy.emplace_back(patch.second);
        }
    }

    for (const auto& patch : patchesCopy) {
        onCreateAudioPatch(patch.mHalHandle, patch);
    }
}

std::optional<audio_patch_handle_t> MelReporter::activePatchStreamHandle_l(
        audio_io_handle_t streamHandle) {
    for(const auto& patchIt : mActiveMelPatches) {
+8 −6
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@

namespace android {

constexpr static int kMaxTimestampDeltaInSec = 120;

class IAfMelReporterCallback : public virtual RefBase {
public:
    virtual audio_utils::mutex& mutex() const
@@ -45,8 +43,10 @@ public:
class MelReporter : public PatchCommandThread::PatchCommandListener,
                    public IMelReporterCallback {
public:
    explicit MelReporter(const sp<IAfMelReporterCallback>& afMelReporterCallback)
        : mAfMelReporterCallback(afMelReporterCallback) {}
    MelReporter(const sp<IAfMelReporterCallback>& afMelReporterCallback,
                const sp<IAfPatchPanel>& afPatchPanel)
        : mAfMelReporterCallback(afMelReporterCallback),
          mAfPatchPanel(afPatchPanel) {}

    void onFirstRef() override;

@@ -80,9 +80,10 @@ public:

    // IMelReporterCallback methods
    void stopMelComputationForDeviceId(audio_port_handle_t deviceId) final
            EXCLUDES_MelReporter_Mutex;
            EXCLUDES_AudioFlinger_Mutex EXCLUDES_MelReporter_Mutex;
    void startMelComputationForDeviceId(audio_port_handle_t deviceId) final
            EXCLUDES_MelReporter_Mutex;
            EXCLUDES_AudioFlinger_Mutex EXCLUDES_MelReporter_Mutex;
    void applyAllAudioPatches() final EXCLUDES_AudioFlinger_Mutex EXCLUDES_MelReporter_Mutex;

    // PatchCommandListener methods
    void onCreateAudioPatch(audio_patch_handle_t handle,
@@ -131,6 +132,7 @@ private:
    bool useHalSoundDoseInterface_l() REQUIRES(mutex());

    const sp<IAfMelReporterCallback> mAfMelReporterCallback;
    const sp<IAfPatchPanel> mAfPatchPanel;

    /* const */ sp<SoundDoseManager> mSoundDoseManager;  // set onFirstRef

+13 −2
Original line number Diff line number Diff line
@@ -590,9 +590,20 @@ bool SoundDoseManager::isFrameworkMelForced() const {
}

void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) {
    bool changed = false;
    {
        const std::lock_guard _l(mLock);
        if (mHalSoundDose.size() != 0) {
            // when using the HAL path we cannot enforce to deliver values for all devices
            changed = mUseFrameworkMel != computeCsdOnAllDevices;
            mUseFrameworkMel = computeCsdOnAllDevices;
        }
        mComputeCsdOnAllDevices = computeCsdOnAllDevices;
    }
    if (changed && computeCsdOnAllDevices) {
        mMelReporterCallback->applyAllAudioPatches();
    }
}

bool SoundDoseManager::isComputeCsdForcedOnAllDevices() const {
    const std::lock_guard _l(mLock);
+2 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ public:

    virtual void stopMelComputationForDeviceId(audio_port_handle_t deviceId) = 0;
    virtual void startMelComputationForDeviceId(audio_port_handle_t deviceId) = 0;

    virtual void applyAllAudioPatches() = 0;
};

class SoundDoseManager : public audio_utils::MelProcessor::MelCallback {
Loading