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

Commit c4b2f5b5 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge Android 14 QPR2 to AOSP main" into main

parents b06a492b 34cdbc2d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -10,3 +10,4 @@ aidl_format = true
aosp_hook_confirmationui = ${REPO_ROOT}/frameworks/base/tools/aosp/aosp_sha.sh ${PREUPLOAD_COMMIT} confirmationui
aosp_hook_gatekeeper = ${REPO_ROOT}/frameworks/base/tools/aosp/aosp_sha.sh ${PREUPLOAD_COMMIT} gatekeeper
aosp_hook_keymaster = ${REPO_ROOT}/frameworks/base/tools/aosp/aosp_sha.sh ${PREUPLOAD_COMMIT} keymaster
generate_vehicle_property_enums = ${REPO_ROOT}/hardware/interfaces/automotive/vehicle/tools/generate_annotation_enums.py --android_build_top ${REPO_ROOT} --preupload_files ${PREUPLOAD_FILES} --check_only
+4 −0
Original line number Diff line number Diff line
@@ -97,8 +97,11 @@ cc_library {
    shared_libs: [
        "android.hardware.bluetooth.audio-impl",
        "libaudio_aidl_conversion_common_ndk",
        "libaudioutils",
        "libbluetooth_audio_session_aidl",
        "liblog",
        "libmedia_helper",
        "libmediautils_vendor",
        "libstagefright_foundation",
    ],
    export_shared_lib_headers: [
@@ -130,6 +133,7 @@ cc_binary {
        "android.hardware.bluetooth.audio-impl",
        "libaudio_aidl_conversion_common_ndk",
        "libbluetooth_audio_session_aidl",
        "liblog",
        "libmedia_helper",
        "libstagefright_foundation",
    ],
+6 −2
Original line number Diff line number Diff line
@@ -212,6 +212,11 @@ ndk::ScopedAStatus Module::createStreamContext(
        StreamContext::DebugParameters params{mDebug.streamTransientStateDelayMs,
                                              mVendorDebug.forceTransientBurst,
                                              mVendorDebug.forceSynchronousDrain};
        std::shared_ptr<ISoundDose> soundDose;
        if (!getSoundDose(&soundDose).isOk()) {
            LOG(ERROR) << __func__ << ": could not create sound dose instance";
            return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
        }
        StreamContext temp(
                std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
                std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
@@ -219,8 +224,7 @@ ndk::ScopedAStatus Module::createStreamContext(
                portConfigIt->sampleRate.value().value, flags, nominalLatencyMs,
                portConfigIt->ext.get<AudioPortExt::mix>().handle,
                std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
                asyncCallback, outEventCallback,
                std::weak_ptr<sounddose::StreamDataProcessorInterface>{}, params);
                asyncCallback, outEventCallback, mSoundDose.getInstance(), params);
        if (temp.isValid()) {
            *out_context = std::move(temp);
        } else {
+89 −0
Original line number Diff line number Diff line
@@ -18,7 +18,15 @@

#include "core-impl/SoundDose.h"

#include <aidl/android/hardware/audio/core/sounddose/ISoundDose.h>
#include <android-base/logging.h>
#include <media/AidlConversionCppNdk.h>
#include <utils/Timers.h>

using aidl::android::hardware::audio::core::sounddose::ISoundDose;
using aidl::android::media::audio::common::AudioDevice;
using aidl::android::media::audio::common::AudioDeviceDescription;
using aidl::android::media::audio::common::AudioFormatDescription;

namespace aidl::android::hardware::audio::core::sounddose {

@@ -28,11 +36,16 @@ ndk::ScopedAStatus SoundDose::setOutputRs2UpperBound(float in_rs2ValueDbA) {
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }

    ::android::audio_utils::lock_guard l(mMutex);
    mRs2Value = in_rs2ValueDbA;
    if (mMelProcessor != nullptr) {
        mMelProcessor->setOutputRs2UpperBound(in_rs2ValueDbA);
    }
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus SoundDose::getOutputRs2UpperBound(float* _aidl_return) {
    ::android::audio_utils::lock_guard l(mMutex);
    *_aidl_return = mRs2Value;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
@@ -44,6 +57,8 @@ ndk::ScopedAStatus SoundDose::registerSoundDoseCallback(
        LOG(ERROR) << __func__ << ": Callback is nullptr";
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }

    ::android::audio_utils::lock_guard l(mCbMutex);
    if (mCallback != nullptr) {
        LOG(ERROR) << __func__ << ": Sound dose callback was already registered";
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
@@ -51,7 +66,81 @@ ndk::ScopedAStatus SoundDose::registerSoundDoseCallback(

    mCallback = in_callback;
    LOG(DEBUG) << __func__ << ": Registered sound dose callback ";

    return ndk::ScopedAStatus::ok();
}

void SoundDose::setAudioDevice(const AudioDevice& audioDevice) {
    ::android::audio_utils::lock_guard l(mCbMutex);
    mAudioDevice = audioDevice;
}

void SoundDose::startDataProcessor(uint32_t sampleRate, uint32_t channelCount,
                                   const AudioFormatDescription& aidlFormat) {
    ::android::audio_utils::lock_guard l(mMutex);
    const auto result = aidl2legacy_AudioFormatDescription_audio_format_t(aidlFormat);
    const audio_format_t format = result.value_or(AUDIO_FORMAT_INVALID);

    if (mMelProcessor == nullptr) {
        // we don't have the deviceId concept on the vendor side so just pass 0
        mMelProcessor = ::android::sp<::android::audio_utils::MelProcessor>::make(
                sampleRate, channelCount, format, mMelCallback, /*deviceId=*/0, mRs2Value);
    } else {
        mMelProcessor->updateAudioFormat(sampleRate, channelCount, format);
    }
}

void SoundDose::process(const void* buffer, size_t bytes) {
    ::android::audio_utils::lock_guard l(mMutex);
    if (mMelProcessor != nullptr) {
        mMelProcessor->process(buffer, bytes);
    }
}

void SoundDose::onNewMelValues(const std::vector<float>& mels, size_t offset, size_t length,
                               audio_port_handle_t deviceId __attribute__((__unused__))) const {
    ::android::audio_utils::lock_guard l(mCbMutex);
    if (!mAudioDevice.has_value()) {
        LOG(WARNING) << __func__ << ": New mel values without a registered device";
        return;
    }
    if (mCallback == nullptr) {
        LOG(ERROR) << __func__ << ": New mel values without a registered callback";
        return;
    }

    ISoundDose::IHalSoundDoseCallback::MelRecord melRecord;
    melRecord.timestamp = nanoseconds_to_seconds(systemTime());
    melRecord.melValues = std::vector<float>(mels.begin() + offset, mels.begin() + offset + length);

    mCallback->onNewMelValues(melRecord, mAudioDevice.value());
}

void SoundDose::MelCallback::onNewMelValues(const std::vector<float>& mels, size_t offset,
                                            size_t length,
                                            audio_port_handle_t deviceId
                                            __attribute__((__unused__))) const {
    mSoundDose.onNewMelValues(mels, offset, length, deviceId);
}

void SoundDose::onMomentaryExposure(float currentMel, audio_port_handle_t deviceId
                                    __attribute__((__unused__))) const {
    ::android::audio_utils::lock_guard l(mCbMutex);
    if (!mAudioDevice.has_value()) {
        LOG(WARNING) << __func__ << ": Momentary exposure without a registered device";
        return;
    }
    if (mCallback == nullptr) {
        LOG(ERROR) << __func__ << ": Momentary exposure without a registered callback";
        return;
    }

    mCallback->onMomentaryExposureWarning(currentMel, mAudioDevice.value());
}

void SoundDose::MelCallback::onMomentaryExposure(float currentMel, audio_port_handle_t deviceId
                                                 __attribute__((__unused__))) const {
    mSoundDose.onMomentaryExposure(currentMel, deviceId);
}

}  // namespace aidl::android::hardware::audio::core::sounddose
+37 −4
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include <aidl/android/hardware/audio/core/sounddose/BnSoundDose.h>
#include <aidl/android/media/audio/common/AudioDevice.h>
#include <aidl/android/media/audio/common/AudioFormatDescription.h>
#include <audio_utils/MelProcessor.h>
#include <audio_utils/mutex.h>

namespace aidl::android::hardware::audio::core::sounddose {

@@ -37,18 +39,49 @@ class StreamDataProcessorInterface {
    virtual void process(const void* buffer, size_t size) = 0;
};

class SoundDose : public BnSoundDose {
class SoundDose final : public BnSoundDose, public StreamDataProcessorInterface {
  public:
    SoundDose() : mRs2Value(DEFAULT_MAX_RS2){};
    SoundDose() : mMelCallback(::android::sp<MelCallback>::make(this)){};

    // -------------------------------------- BnSoundDose ------------------------------------------
    ndk::ScopedAStatus setOutputRs2UpperBound(float in_rs2ValueDbA) override;
    ndk::ScopedAStatus getOutputRs2UpperBound(float* _aidl_return) override;
    ndk::ScopedAStatus registerSoundDoseCallback(
            const std::shared_ptr<ISoundDose::IHalSoundDoseCallback>& in_callback) override;

    // ----------------------------- StreamDataProcessorInterface ----------------------------------
    void setAudioDevice(
            const ::aidl::android::media::audio::common::AudioDevice& audioDevice) override;
    void startDataProcessor(
            uint32_t samplerate, uint32_t channelCount,
            const ::aidl::android::media::audio::common::AudioFormatDescription& format) override;
    void process(const void* buffer, size_t size) override;

  private:
    std::shared_ptr<ISoundDose::IHalSoundDoseCallback> mCallback;
    float mRs2Value;
    class MelCallback : public ::android::audio_utils::MelProcessor::MelCallback {
      public:
        explicit MelCallback(SoundDose* soundDose) : mSoundDose(*soundDose) {}

        // ------------------------------------ MelCallback ----------------------------------------
        void onNewMelValues(const std::vector<float>& mels, size_t offset, size_t length,
                            audio_port_handle_t deviceId) const override;
        void onMomentaryExposure(float currentMel, audio_port_handle_t deviceId) const override;

        SoundDose& mSoundDose;  // must outlive MelCallback, not owning
    };

    void onNewMelValues(const std::vector<float>& mels, size_t offset, size_t length,
                        audio_port_handle_t deviceId) const;
    void onMomentaryExposure(float currentMel, audio_port_handle_t deviceId) const;

    mutable ::android::audio_utils::mutex mCbMutex;
    std::shared_ptr<ISoundDose::IHalSoundDoseCallback> mCallback GUARDED_BY(mCbMutex);
    std::optional<::aidl::android::media::audio::common::AudioDevice> mAudioDevice
            GUARDED_BY(mCbMutex);
    mutable ::android::audio_utils::mutex mMutex;
    float mRs2Value GUARDED_BY(mMutex) = DEFAULT_MAX_RS2;
    ::android::sp<::android::audio_utils::MelProcessor> mMelProcessor GUARDED_BY(mMutex);
    ::android::sp<MelCallback> mMelCallback GUARDED_BY(mMutex);
};

}  // namespace aidl::android::hardware::audio::core::sounddose
Loading