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

Commit c40bbe0f 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
Merged-In: Ic113ab3569360910e66a42cf3600865080461bc3
Change-Id: Ic113ab3569360910e66a42cf3600865080461bc3
parent a2e69003
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -111,7 +111,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) {
@@ -171,7 +171,7 @@ void MelReporter::onCreateAudioPatch(audio_patch_handle_t handle,
    }

    if (!newPatch.deviceHandles.empty()) {
        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);
@@ -226,7 +226,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());
    stopMelComputationForPatch_l(melPatch);
}
+11 −6
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,7 +72,7 @@ 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);

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

    // 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;

    /**
     * The new metadata can determine whether we should compute MEL for the given thread.
@@ -89,7 +90,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};
@@ -101,7 +104,9 @@ private:
    bool shouldComputeMelForDeviceType(audio_devices_t device);

    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());