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

Commit 77448a57 authored by Andy Hung's avatar Andy Hung
Browse files

MelReporter: Add clang thread-safety

Update virtual methods to final.

Test: atest AudioTrackTest AudioRecordTest
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioPlaybackCaptureTest
Test: Camera YouTube
Bug: 275748373
Change-Id: Ic113ab3569360910e66a42cf3600865080461bc3
parent 3e07ef09
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ void MelReporter::updateMetadataForCsd(audio_io_handle_t streamHandle,
        return;
    }

    audio_utils::lock_guard _laf(mAfMelReporterCallback->mutex());
    audio_utils::lock_guard _laf(mAfMelReporterCallback->mutex());  // AudioFlinger_Mutex
    audio_utils::lock_guard _l(mutex());
    auto activeMelPatchId = activePatchStreamHandle_l(streamHandle);
    if (!activeMelPatchId) {
@@ -154,7 +154,7 @@ void MelReporter::onCreateAudioPatch(audio_patch_handle_t handle,
    }

    if (!newPatch.deviceStates.empty() && newPatch.csdActive) {
        audio_utils::lock_guard _afl(mAfMelReporterCallback->mutex());
        audio_utils::lock_guard _afl(mAfMelReporterCallback->mutex());  // AudioFlinger_Mutex
        audio_utils::lock_guard _l(mutex());
        ALOGV("%s add patch handle %d to active devices", __func__, handle);
        startMelComputationForActivePatch_l(newPatch);
@@ -231,7 +231,7 @@ void MelReporter::onReleaseAudioPatch(audio_patch_handle_t handle) {
        mActiveMelPatches.erase(patchIt);
    }

    audio_utils::lock_guard _afl(mAfMelReporterCallback->mutex());
    audio_utils::lock_guard _afl(mAfMelReporterCallback->mutex());  // AudioFlinger_Mutex
    audio_utils::lock_guard _l(mutex());
    if (melPatch.csdActive) {
        // only need to stop if patch was active
+16 −9
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public:
     * implementation, false otherwise.
     */
    bool activateHalSoundDoseComputation(const std::string& module,
                                         const sp<DeviceHalInterface>& device);
            const sp<DeviceHalInterface>& device) EXCLUDES_MelReporter_Mutex;

    /**
     * Activates the MEL reporting from internal framework values. These are used
@@ -72,23 +72,26 @@ public:
     * Note: the internal CSD computation does not guarantee a certification with
     * IEC62368-1 3rd edition or EN50332-3
     */
    void activateInternalSoundDoseComputation();
    void activateInternalSoundDoseComputation() EXCLUDES_MelReporter_Mutex;

    sp<media::ISoundDose> getSoundDoseInterface(const sp<media::ISoundDoseCallback>& callback);

    std::string dump();

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

    // PatchCommandListener methods
    void onCreateAudioPatch(audio_patch_handle_t handle,
        const IAfPatchPanel::Patch& patch) final;
    void onReleaseAudioPatch(audio_patch_handle_t handle) final;
            const IAfPatchPanel::Patch& patch) final
            EXCLUDES_AudioFlinger_Mutex;
    void onReleaseAudioPatch(audio_patch_handle_t handle) final EXCLUDES_AudioFlinger_Mutex;
    void onUpdateAudioPatch(audio_patch_handle_t oldHandle,
                            audio_patch_handle_t newHandle,
                            const IAfPatchPanel::Patch& patch) final;
            const IAfPatchPanel::Patch& patch) final EXCLUDES_AudioFlinger_Mutex;

    /**
     * The new metadata can determine whether we should compute MEL for the given thread.
@@ -96,7 +99,9 @@ public:
     * Otherwise, this method will disable CSD.
     **/
    void updateMetadataForCsd(audio_io_handle_t streamHandle,
                              const std::vector<playback_track_metadata_v7_t>& metadataVec);
            const std::vector<playback_track_metadata_v7_t>& metadataVec)
            EXCLUDES_AudioFlinger_Mutex;

private:
    struct ActiveMelPatch {
        audio_io_handle_t streamHandle{AUDIO_IO_HANDLE_NONE};
@@ -110,7 +115,9 @@ private:
    };

    void stopInternalMelComputation();
    audio_utils::mutex& mutex() const { return mMutex; }
    audio_utils::mutex& mutex() const RETURN_CAPABILITY(audio_utils::MelReporter_Mutex) {
        return mMutex;
    }

    /** Should be called with the following order of locks: mAudioFlinger.mutex() -> mutex(). */
    void stopMelComputationForPatch_l(const ActiveMelPatch& patch) REQUIRES(mutex());