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

Commit 2900c0a6 authored by Vlad Popa's avatar Vlad Popa
Browse files

CSD: extract SoundDoseManager for MEL handling

The SoundDoseManager owns the aggregator which computes the sound dose.
This is a central place for passing the sound dose properties up to the
higher layers.

Test: UT and dumpsys media.audio_flinger
Bug: 255943034

Change-Id: I2d8139b9115bdd793d4ed418f2da6bc8782d32b3
parent 994212ec
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ cc_library_shared {
        "libmemunreachable",
        "libmedia_helper",
        "libshmemcompat",
        "libsounddose",
        "libvibrator",
        "packagemanager_aidl-cpp",
    ],
@@ -103,6 +104,7 @@ cc_library_shared {
        "libaudiohal_headers",
        "libaudioutils_headers",
        "libmedia_headers",
        "libsounddose_headers",
    ],

    export_shared_lib_headers: [
+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@
#include <audio_utils/SimpleLog.h>
#include <audio_utils/TimestampVerifier.h>

#include <sounddose/SoundDoseManager.h>

#include "FastCapture.h"
#include "FastMixer.h"
#include <media/nbaio/NBAIO.h>
+7 −20
Original line number Diff line number Diff line
@@ -18,13 +18,11 @@
// #define LOG_NDEBUG 0
#define LOG_TAG "AudioFlinger::MelReporter"

#include <cinttypes>
#include <utils/Log.h>
#include <android-base/stringprintf.h>
#include <audio_utils/power.h>

#include "AudioFlinger.h"

#include <audio_utils/power.h>
#include <utils/Log.h>

namespace android {

bool AudioFlinger::MelReporter::shouldComputeMelForDeviceType(audio_devices_t device) {
@@ -67,7 +65,7 @@ void AudioFlinger::MelReporter::onCreateAudioPatch(audio_patch_handle_t handle,
            std::lock_guard _lAf(mAudioFlinger.mLock);
            auto thread = mAudioFlinger.checkPlaybackThread_l(streamHandle);
            if (thread != nullptr) {
                thread->startMelComputation(mMelAggregator.getOrCreateCallbackForDevice(
                thread->startMelComputation(mSoundDoseManager.getOrCreateCallbackForDevice(
                    deviceId,
                    newPatch.streamHandle));
            }
@@ -103,24 +101,13 @@ void AudioFlinger::MelReporter::onReleaseAudioPatch(audio_patch_handle_t handle)
    if (thread != nullptr) {
        thread->stopMelComputation();
    }
    mMelAggregator.removeStreamCallback(melPatch.streamHandle);
    mSoundDoseManager.removeStreamCallback(melPatch.streamHandle);
}

std::string AudioFlinger::MelReporter::dump() {
    std::lock_guard _l(mLock);
    std::string output;

    base::StringAppendF(&output, "\nMel Reporter:\n");
    mMelAggregator.foreach([&output](const audio_utils::MelRecord& melRecord) {
        base::StringAppendF(&output, "Continuous MELs for portId=%d, ", melRecord.portId);
        base::StringAppendF(&output, "starting at timestamp %" PRId64 ": ", melRecord.timestamp);

        for (const auto& mel : melRecord.mels) {
            base::StringAppendF(&output, "%d ", mel);
        }
        base::StringAppendF(&output, "\n");
    });

    std::string output("\nSound Dose:\n");
    output.append(mSoundDoseManager.dump());
    return output;
}

+4 −4
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@
    #error This header file should only be included from AudioFlinger.h
#endif

#include <unordered_map>
#include <mutex>
#include <sounddose/SoundDoseManager.h>
#include <unordered_map>

constexpr static int kMaxTimestampDeltaInSec = 120;

@@ -31,8 +32,7 @@ constexpr static int kMaxTimestampDeltaInSec = 120;
class MelReporter : public PatchCommandThread::PatchCommandListener {
public:
    explicit MelReporter(AudioFlinger& audioFlinger)
        : mAudioFlinger(audioFlinger),
          mMelAggregator(kMaxTimestampDeltaInSec) {}
        : mAudioFlinger(audioFlinger) {}

    void onFirstRef() override {
        mAudioFlinger.mPatchCommandThread->addListener(this);
@@ -54,7 +54,7 @@ public:
private:
    AudioFlinger& mAudioFlinger;  // does not own the object

    audio_utils::MelAggregator mMelAggregator;
    SoundDoseManager mSoundDoseManager;

    struct ActiveMelPatch {
        audio_io_handle_t streamHandle{AUDIO_IO_HANDLE_NONE};
+43 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_av_services_audioflinger_license"],
}

cc_library {
    name: "libsounddose",

    product_available: true,
    double_loadable: true,
    host_supported: true,

    srcs: [
        "SoundDoseManager.cpp",
    ],

    shared_libs: [
        "libaudioutils",
        "libbase",
        "liblog",
        "libutils",
    ],

    header_libs: [
        "libaudioutils_headers",
    ],

    cflags: [
        "-Wall",
        "-Werror",
    ],
}

cc_library_headers {
    name: "libsounddose_headers",
    host_supported: true,
    device_supported: true,
    export_include_dirs: ["."],
}
Loading