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

Commit 355e179c authored by Shunkai Yao's avatar Shunkai Yao Committed by Automerger Merge Worker
Browse files

Merge "AIDL effect: Add EffectProxy implementation and test" am: 4736f153 am: 3b0dae63

parents 7ad4c2f4 3b0dae63
Loading
Loading
Loading
Loading
+14 −11
Original line number Diff line number Diff line
@@ -79,39 +79,42 @@ std::vector<std::string> filterOutNonVendorTags(const std::vector<std::string>&
}  // namespace

// buffer_provider_t is not supported thus skipped
ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t(
        const media::audio::common::AudioConfigBase& aidl, bool isInput) {
ConversionResult<buffer_config_t> aidl2legacy_AudioConfig_buffer_config_t(
        const media::audio::common::AudioConfig& aidl, bool isInput) {
    buffer_config_t legacy;

    legacy.samplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.sampleRate));
    legacy.samplingRate = VALUE_OR_RETURN(convertIntegral<uint32_t>(aidl.base.sampleRate));
    legacy.mask |= EFFECT_CONFIG_SMP_RATE;

    legacy.channels = VALUE_OR_RETURN(
            aidl2legacy_AudioChannelLayout_audio_channel_mask_t(aidl.channelMask, isInput));
            aidl2legacy_AudioChannelLayout_audio_channel_mask_t(aidl.base.channelMask, isInput));
    legacy.mask |= EFFECT_CONFIG_CHANNELS;

    legacy.format = VALUE_OR_RETURN(aidl2legacy_AudioFormatDescription_audio_format_t(aidl.format));
    legacy.format =
            VALUE_OR_RETURN(aidl2legacy_AudioFormatDescription_audio_format_t(aidl.base.format));
    legacy.mask |= EFFECT_CONFIG_FORMAT;
    legacy.buffer.frameCount = aidl.frameCount;

    // TODO: add accessMode and mask
    return legacy;
}

ConversionResult<media::audio::common::AudioConfigBase>
legacy2aidl_buffer_config_t_AudioConfigBase(const buffer_config_t& legacy, bool isInput) {
    media::audio::common::AudioConfigBase aidl;
ConversionResult<media::audio::common::AudioConfig>
legacy2aidl_buffer_config_t_AudioConfig(const buffer_config_t& legacy, bool isInput) {
    media::audio::common::AudioConfig aidl;

    if (legacy.mask & EFFECT_CONFIG_SMP_RATE) {
        aidl.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.samplingRate));
        aidl.base.sampleRate = VALUE_OR_RETURN(convertIntegral<int32_t>(legacy.samplingRate));
    }
    if (legacy.mask & EFFECT_CONFIG_CHANNELS) {
        aidl.channelMask = VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelLayout(
        aidl.base.channelMask = VALUE_OR_RETURN(legacy2aidl_audio_channel_mask_t_AudioChannelLayout(
                static_cast<audio_channel_mask_t>(legacy.channels), isInput));
    }
    if (legacy.mask & EFFECT_CONFIG_FORMAT) {
        aidl.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormatDescription(
        aidl.base.format = VALUE_OR_RETURN(legacy2aidl_audio_format_t_AudioFormatDescription(
                static_cast<audio_format_t>(legacy.format)));
    }
    aidl.frameCount = legacy.buffer.frameCount;

    // TODO: add accessMode and mask
    return aidl;
+3 −3
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@
namespace aidl {
namespace android {

ConversionResult<buffer_config_t> aidl2legacy_AudioConfigBase_buffer_config_t(
        const media::audio::common::AudioConfigBase& aidl, bool isInput);
ConversionResult<media::audio::common::AudioConfigBase> legacy2aidl_buffer_config_t_AudioConfigBase(
ConversionResult<buffer_config_t> aidl2legacy_AudioConfig_buffer_config_t(
        const media::audio::common::AudioConfig& aidl, bool isInput);
ConversionResult<media::audio::common::AudioConfig> legacy2aidl_buffer_config_t_AudioConfig(
        const buffer_config_t& legacy, bool isInput);

::android::status_t aidl2legacy_AudioAttributesTags(
+8 −0
Original line number Diff line number Diff line
@@ -76,3 +76,11 @@ cc_library_headers {

    export_include_dirs: ["include"],
}

cc_library_headers {
    name: "libaudiohalimpl_headers",

    header_libs: ["libaudiohal_headers"],
    export_header_lib_headers: ["libaudiohal_headers"],
    export_include_dirs: ["impl"],
}
+6 −0
Original line number Diff line number Diff line
@@ -274,6 +274,7 @@ cc_library_shared {
        "EffectsFactoryHalAidl.cpp",
        "EffectsFactoryHalEntry.cpp",
        "StreamHalAidl.cpp",
        ":audio_effectproxy_src_files"
    ],
    static_libs: [
        "android.hardware.common-V2-ndk",
@@ -297,3 +298,8 @@ cc_library_shared {
        "-DBACKEND_CPP_NDK",
    ],
}

filegroup {
    name: "audio_effectproxy_src_files",
    srcs: ["EffectProxy.cpp"],
}
+74 −25
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <utils/Log.h>

#include "EffectConversionHelperAidl.h"
#include "EffectProxy.h"

namespace android {
namespace effect {
@@ -37,7 +38,9 @@ using ::aidl::android::aidl_utils::statusTFromBinderStatus;
using ::aidl::android::hardware::audio::effect::CommandId;
using ::aidl::android::hardware::audio::effect::Descriptor;
using ::aidl::android::hardware::audio::effect::Flags;
using ::aidl::android::hardware::audio::effect::IEffect;
using ::aidl::android::hardware::audio::effect::Parameter;
using ::aidl::android::hardware::audio::effect::State;
using ::aidl::android::media::audio::common::AudioDeviceDescription;
using ::aidl::android::media::audio::common::AudioMode;
using ::aidl::android::media::audio::common::AudioSource;
@@ -72,7 +75,9 @@ EffectConversionHelperAidl::EffectConversionHelperAidl(
      mIoId(ioId),
      mDesc(desc),
      mEffect(std::move(effect)),
      mIsInputStream(mDesc.common.flags.type == Flags::Type::PRE_PROC) {
      mIsInputStream(mDesc.common.flags.type == Flags::Type::PRE_PROC),
      mIsProxyEffect(mDesc.common.id.proxy.has_value() &&
                     mDesc.common.id.proxy.value() == mDesc.common.id.uuid) {
    mCommon.session = sessionId;
    mCommon.ioHandle = ioId;
    mCommon.input = mCommon.output = kDefaultAudioConfig;
@@ -96,8 +101,8 @@ status_t EffectConversionHelperAidl::handleInit(uint32_t cmdSize __unused,
        return BAD_VALUE;
    }

    return *(status_t*)pReplyData =
                   statusTFromBinderStatus(mEffect->open(mCommon, std::nullopt, &mOpenReturn));
    // Do nothing for EFFECT_CMD_INIT, call IEffect.open() with EFFECT_CMD_SET_CONFIG
    return *(status_t*)pReplyData = OK;
}

status_t EffectConversionHelperAidl::handleSetParameter(uint32_t cmdSize, const void* pCmdData,
@@ -154,22 +159,55 @@ status_t EffectConversionHelperAidl::handleSetConfig(uint32_t cmdSize, const voi
    }

    effect_config_t* config = (effect_config_t*)pCmdData;
    Parameter::Common aidlCommon = {
            .session = mSessionId,
            .ioHandle = mIoId,
            .input = {.base = VALUE_OR_RETURN_STATUS(
                              ::aidl::android::legacy2aidl_buffer_config_t_AudioConfigBase(
                                      config->inputCfg, mIsInputStream))},
            .output = {.base = VALUE_OR_RETURN_STATUS(
                               ::aidl::android::legacy2aidl_buffer_config_t_AudioConfigBase(
                                       config->outputCfg, mIsInputStream))}};

    Parameter aidlParam = UNION_MAKE(Parameter, common, aidlCommon);

    status_t ret = statusTFromBinderStatus(mEffect->setParameter(aidlParam));
    EffectParamWriter writer(*(effect_param_t*)pReplyData);
    writer.setStatus(ret);
    return ret;
    Parameter::Common common = {
            .input =
                    VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_buffer_config_t_AudioConfig(
                            config->inputCfg, mIsInputStream)),
            .output =
                    VALUE_OR_RETURN_STATUS(::aidl::android::legacy2aidl_buffer_config_t_AudioConfig(
                            config->outputCfg, mIsInputStream)),
            .session = mCommon.session,
            .ioHandle = mCommon.ioHandle};

    State state;
    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getState(&state)));
    // in case of buffer/ioHandle re-configure for an opened effect, close it and re-open
    if (state != State::INIT && mCommon != common) {
        ALOGI("%s at state %s, closing effect", __func__,
              android::internal::ToString(state).c_str());
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->close()));
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->getState(&state)));
        mStatusQ.reset();
        mInputQ.reset();
        mOutputQ.reset();
    }

    if (state == State::INIT) {
        ALOGI("%s at state %s, opening effect", __func__,
              android::internal::ToString(state).c_str());
        IEffect::OpenEffectReturn openReturn;
        RETURN_STATUS_IF_ERROR(
                statusTFromBinderStatus(mEffect->open(common, std::nullopt, &openReturn)));

        if (mIsProxyEffect) {
            const auto& ret =
                    std::static_pointer_cast<EffectProxy>(mEffect)->getEffectReturnParam();
            mStatusQ = std::make_shared<StatusMQ>(ret->statusMQ);
            mInputQ = std::make_shared<DataMQ>(ret->inputDataMQ);
            mOutputQ = std::make_shared<DataMQ>(ret->outputDataMQ);
        } else {
            mStatusQ = std::make_shared<StatusMQ>(openReturn.statusMQ);
            mInputQ = std::make_shared<DataMQ>(openReturn.inputDataMQ);
            mOutputQ = std::make_shared<DataMQ>(openReturn.outputDataMQ);
        }
        mCommon = common;
    } else if (mCommon != common) {
        ALOGI("%s at state %s, setParameter", __func__, android::internal::ToString(state).c_str());
        Parameter aidlParam = UNION_MAKE(Parameter, common, mCommon);
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(mEffect->setParameter(aidlParam)));
    }

    return *static_cast<int32_t*>(pReplyData) = OK;
}

status_t EffectConversionHelperAidl::handleGetConfig(uint32_t cmdSize __unused,
@@ -187,11 +225,9 @@ status_t EffectConversionHelperAidl::handleGetConfig(uint32_t cmdSize __unused,
    const auto& common = param.get<Parameter::common>();
    effect_config_t* pConfig = (effect_config_t*)pReplyData;
    pConfig->inputCfg = VALUE_OR_RETURN_STATUS(
            ::aidl::android::aidl2legacy_AudioConfigBase_buffer_config_t(common.input.base, true));
    pConfig->outputCfg =
            VALUE_OR_RETURN_STATUS(::aidl::android::aidl2legacy_AudioConfigBase_buffer_config_t(
                    common.output.base, false));
    mCommon = common;
            ::aidl::android::aidl2legacy_AudioConfig_buffer_config_t(common.input, true));
    pConfig->outputCfg = VALUE_OR_RETURN_STATUS(
            ::aidl::android::aidl2legacy_AudioConfig_buffer_config_t(common.output, false));
    return OK;
}

@@ -294,7 +330,20 @@ status_t EffectConversionHelperAidl::handleSetOffload(uint32_t cmdSize, const vo
              pReplyData);
        return BAD_VALUE;
    }
    // TODO: handle this after effectproxy implemented in libaudiohal
    effect_offload_param_t* offload = (effect_offload_param_t*)pCmdData;
    // send to proxy to update active sub-effect
    if (mIsProxyEffect) {
        ALOGI("%s offload param offload %s ioHandle %d", __func__,
              offload->isOffload ? "true" : "false", offload->ioHandle);
        mCommon.ioHandle = offload->ioHandle;
        RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
                std::static_pointer_cast<EffectProxy>(mEffect)->setOffloadParam(offload)));
        // update FMQs
        const auto& ret = std::static_pointer_cast<EffectProxy>(mEffect)->getEffectReturnParam();
        mStatusQ = std::make_shared<StatusMQ>(ret->statusMQ);
        mInputQ = std::make_shared<DataMQ>(ret->inputDataMQ);
        mOutputQ = std::make_shared<DataMQ>(ret->outputDataMQ);
    }
    return *static_cast<int32_t*>(pReplyData) = OK;
}

Loading