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

Commit 9321ea07 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add helper methods for the sound dose test API"

parents 66d26145 91930468
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -22,9 +22,9 @@ import android.media.SoundDoseRecord;
 * Interface used to push the sound dose related information from the
 * AudioService#SoundDoseHelper to the audio server
 */
oneway interface ISoundDose {
interface ISoundDose {
    /** Set a new RS2 value used for momentary exposure warnings. */
    void setOutputRs2(float rs2Value);
    oneway void setOutputRs2(float rs2Value);

    /**
     * Resets the native CSD values. This can happen after a crash in the
@@ -33,5 +33,15 @@ oneway interface ISoundDose {
     * dosage values and MELs together with their timestamps that lead to this
     * CSD.
     */
    void resetCsd(float currentCsd, in SoundDoseRecord[] records);
    oneway void resetCsd(float currentCsd, in SoundDoseRecord[] records);

    /* -------------------------- Test API methods --------------------------
    /** Get the currently used RS2 value. */
    float getOutputRs2();
    /** Get the current CSD from audioserver. */
    float getCsd();
    /** Enables/Disables MEL computations from framework. */
    oneway void forceUseFrameworkMel(boolean useFrameworkMel);
    /** Enables/Disables the computation of CSD on all devices. */
    oneway void forceComputeCsdOnAllDevices(boolean computeCsdOnAllDevices);
}
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@
namespace android {

bool AudioFlinger::MelReporter::shouldComputeMelForDeviceType(audio_devices_t device) {
    if (mSoundDoseManager.computeCsdOnAllDevices()) {
        return true;
    }

    switch (device) {
        case AUDIO_DEVICE_OUT_WIRED_HEADSET:
        case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public:
    }

    /** Returns true if we should compute MEL for the given device. */
    static bool shouldComputeMelForDeviceType(audio_devices_t device);
    bool shouldComputeMelForDeviceType(audio_devices_t device);

    // For now only support internal MelReporting
    [[nodiscard]] bool isHalReportingEnabled() const { return false; }
+58 −0
Original line number Diff line number Diff line
@@ -117,6 +117,64 @@ binder::Status SoundDoseManager::SoundDose::resetCsd(
    return binder::Status::ok();
}

binder::Status SoundDoseManager::SoundDose::getOutputRs2(float* value) {
    ALOGV("%s", __func__);
    auto soundDoseManager = mSoundDoseManager.promote();
    if (soundDoseManager != nullptr) {
        std::lock_guard _l(soundDoseManager->mLock);
        *value = soundDoseManager->mRs2Value;
    }
    return binder::Status::ok();
}

binder::Status SoundDoseManager::SoundDose::getCsd(float* value) {
    ALOGV("%s", __func__);
    auto soundDoseManager = mSoundDoseManager.promote();
    if (soundDoseManager != nullptr) {
        *value = soundDoseManager->mMelAggregator->getCsd();
    }
    return binder::Status::ok();
}

binder::Status SoundDoseManager::SoundDose::forceUseFrameworkMel(bool useFrameworkMel) {
    ALOGV("%s", __func__);
    auto soundDoseManager = mSoundDoseManager.promote();
    if (soundDoseManager != nullptr) {
        soundDoseManager->setUseFrameworkMel(useFrameworkMel);
    }
    return binder::Status::ok();
}

binder::Status SoundDoseManager::SoundDose::forceComputeCsdOnAllDevices(
        bool computeCsdOnAllDevices) {
    ALOGV("%s", __func__);
    auto soundDoseManager = mSoundDoseManager.promote();
    if (soundDoseManager != nullptr) {
        soundDoseManager->setComputeCsdOnAllDevices(computeCsdOnAllDevices);
    }
    return binder::Status::ok();
}

void SoundDoseManager::setUseFrameworkMel(bool useFrameworkMel) {
    std::lock_guard _l(mLock);
    mUseFrameworkMel = useFrameworkMel;
}

bool SoundDoseManager::useFrameworkMel() const {
    std::lock_guard _l(mLock);
    return mUseFrameworkMel;
}

void SoundDoseManager::setComputeCsdOnAllDevices(bool computeCsdOnAllDevices) {
    std::lock_guard _l(mLock);
    mComputeCsdOnAllDevices = computeCsdOnAllDevices;
}

bool SoundDoseManager::computeCsdOnAllDevices() const {
    std::lock_guard _l(mLock);
    return mComputeCsdOnAllDevices;
}

void SoundDoseManager::resetSoundDose() {
    std::lock_guard lock(mLock);
    mSoundDose = nullptr;
+14 −1
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ class SoundDoseManager : public audio_utils::MelProcessor::MelCallback {

    // used for testing
    size_t getCachedMelRecordsSize() const;
    bool useFrameworkMel() const;
    bool computeCsdOnAllDevices() const;


    /** Method for converting from audio_utils::CsdRecord to media::SoundDoseRecord. */
    static media::SoundDoseRecord csdRecordToSoundDoseRecord(const audio_utils::CsdRecord& legacy);
@@ -107,6 +110,10 @@ private:
        binder::Status setOutputRs2(float value) override;
        binder::Status resetCsd(float currentCsd,
                                const std::vector<media::SoundDoseRecord>& records) override;
        binder::Status getOutputRs2(float* value);
        binder::Status getCsd(float* value);
        binder::Status forceUseFrameworkMel(bool useFrameworkMel);
        binder::Status forceComputeCsdOnAllDevices(bool computeCsdOnAllDevices);

        wp<SoundDoseManager> mSoundDoseManager;
        const sp<media::ISoundDoseCallback> mSoundDoseCallback;
@@ -118,6 +125,9 @@ private:

    sp<media::ISoundDoseCallback> getSoundDoseCallback() const;

    void setUseFrameworkMel(bool useFrameworkMel);
    void setComputeCsdOnAllDevices(bool computeCsdOnAllDevices);

    mutable std::mutex mLock;

    // no need for lock since MelAggregator is thread-safe
@@ -129,6 +139,9 @@ private:
    float mRs2Value GUARDED_BY(mLock);

    sp<SoundDose> mSoundDose GUARDED_BY(mLock);

    bool mUseFrameworkMel GUARDED_BY(mLock);
    bool mComputeCsdOnAllDevices GUARDED_BY(mLock);
};

}  // namespace android