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

Commit bbd7f95d authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Effect AIDL: remove unnecessary mutex in Reverb" into main

parents f37c4620 de1b3cef
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descrip
namespace aidl::android::hardware::audio::effect {

EffectReverb::EffectReverb(const AudioUuid& uuid) {
    LOG(DEBUG) << __func__ << uuid.toString();
    if (uuid == getEffectImplUuidAuxEnvReverb()) {
        mType = lvm::ReverbEffectType::AUX_ENV;
        mDescriptor = &lvm::kAuxEnvReverbDesc;
@@ -106,18 +105,16 @@ EffectReverb::EffectReverb(const AudioUuid& uuid) {

EffectReverb::~EffectReverb() {
    cleanUp();
    LOG(DEBUG) << __func__;
}

ndk::ScopedAStatus EffectReverb::getDescriptor(Descriptor* _aidl_return) {
    RETURN_IF(!_aidl_return, EX_ILLEGAL_ARGUMENT, "Parameter:nullptr");
    LOG(DEBUG) << _aidl_return->toString();
    *_aidl_return = *mDescriptor;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus EffectReverb::setParameterSpecific(const Parameter::Specific& specific) {
    LOG(DEBUG) << __func__ << " specific " << specific.toString();
    LOG(VERBOSE) << __func__ << " specific " << specific.toString();
    RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");

    auto tag = specific.getTag();
+73 −121
Original line number Diff line number Diff line
@@ -68,8 +68,6 @@ RetCode ReverbContext::init() {

    // allocate lvm reverb instance
    LVREV_ReturnStatus_en status = LVREV_SUCCESS;
    {
        std::lock_guard lg(mMutex);
    LVREV_InstanceParams_st params = {
            .MaxBlockSize = lvm::kMaxCallSize,
            // Max format, could be mono during process
@@ -85,7 +83,6 @@ RetCode ReverbContext::init() {
    initControlParameter(controlParams);
    status = LVREV_SetControlParameters(mInstance, &controlParams);
    GOTO_IF_LVREV_ERROR(status, deinit, "LVREV_SetControlParametersFailed");
    }

    return RetCode::SUCCESS;

@@ -95,7 +92,6 @@ deinit:
}

void ReverbContext::deInit() {
    std::lock_guard lg(mMutex);
    if (mInstance) {
        LVREV_FreeInstance(mInstance);
        mInstance = nullptr;
@@ -143,8 +139,6 @@ RetCode ReverbContext::setPresetReverbPreset(const PresetReverb::Presets& preset
RetCode ReverbContext::setEnvironmentalReverbRoomLevel(int roomLevel) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -155,7 +149,6 @@ RetCode ReverbContext::setEnvironmentalReverbRoomLevel(int roomLevel) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }
    mRoomLevel = roomLevel;
    return RetCode::SUCCESS;
}
@@ -163,8 +156,6 @@ RetCode ReverbContext::setEnvironmentalReverbRoomLevel(int roomLevel) {
RetCode ReverbContext::setEnvironmentalReverbRoomHfLevel(int roomHfLevel) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -172,7 +163,6 @@ RetCode ReverbContext::setEnvironmentalReverbRoomHfLevel(int roomHfLevel) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }
    mRoomHfLevel = roomHfLevel;
    return RetCode::SUCCESS;
}
@@ -185,8 +175,6 @@ RetCode ReverbContext::setEnvironmentalReverbDecayTime(int decayTime) {

    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -195,7 +183,7 @@ RetCode ReverbContext::setEnvironmentalReverbDecayTime(int decayTime) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }

    mDecayTime = time;
    return RetCode::SUCCESS;
}
@@ -203,8 +191,6 @@ RetCode ReverbContext::setEnvironmentalReverbDecayTime(int decayTime) {
RetCode ReverbContext::setEnvironmentalReverbDecayHfRatio(int decayHfRatio) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -212,7 +198,6 @@ RetCode ReverbContext::setEnvironmentalReverbDecayHfRatio(int decayHfRatio) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }
    mDecayHfRatio = decayHfRatio;
    return RetCode::SUCCESS;
}
@@ -220,8 +205,6 @@ RetCode ReverbContext::setEnvironmentalReverbDecayHfRatio(int decayHfRatio) {
RetCode ReverbContext::setEnvironmentalReverbLevel(int level) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -232,7 +215,7 @@ RetCode ReverbContext::setEnvironmentalReverbLevel(int level) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }

    mLevel = level;
    return RetCode::SUCCESS;
}
@@ -245,8 +228,6 @@ RetCode ReverbContext::setEnvironmentalReverbDelay(int delay) {
RetCode ReverbContext::setEnvironmentalReverbDiffusion(int diffusion) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -254,7 +235,7 @@ RetCode ReverbContext::setEnvironmentalReverbDiffusion(int diffusion) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }

    mDiffusion = diffusion;
    return RetCode::SUCCESS;
}
@@ -262,8 +243,6 @@ RetCode ReverbContext::setEnvironmentalReverbDiffusion(int diffusion) {
RetCode ReverbContext::setEnvironmentalReverbDensity(int density) {
    // Update Control Parameter
    LVREV_ControlParams_st params;
    {
        std::lock_guard lg(mMutex);
    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_GetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " getControlParamFailed");

@@ -271,7 +250,7 @@ RetCode ReverbContext::setEnvironmentalReverbDensity(int density) {

    RETURN_VALUE_IF(LVREV_SUCCESS != LVREV_SetControlParameters(mInstance, &params),
                    RetCode::ERROR_EFFECT_LIB_ERROR, " setControlParamFailed");
    }

    mDensity = density;
    return RetCode::SUCCESS;
}
@@ -362,9 +341,6 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
    RETURN_VALUE_IF(inputFrameCount != outputFrameCount, status, "FrameCountMismatch");
    RETURN_VALUE_IF(0 == getInputFrameSize(), status, "zeroFrameSize");

    LOG(DEBUG) << __func__ << " start processing";
    std::lock_guard lg(mMutex);

    int channels = ::aidl::android::hardware::audio::common::getChannelCount(
            mCommon.input.base.channelMask);
    int outChannels = ::aidl::android::hardware::audio::common::getChannelCount(
@@ -405,7 +381,6 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
    } else {
        if (!mEnabled && mSamplesToExitCount > 0) {
            std::fill(outFrames.begin(), outFrames.end(), 0);
            LOG(VERBOSE) << "Zeroing " << channels << " samples per frame at the end of call ";
        }

        /* Process the samples, producing a stereo output */
@@ -415,7 +390,7 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
                              outFrames.data(), /* Output buffer */
                              frameCount);      /* Number of samples to read */
        if (lvrevStatus != LVREV_SUCCESS) {
            LOG(ERROR) << __func__ << lvrevStatus;
            LOG(ERROR) << __func__ << " LVREV_Process error: " << lvrevStatus;
            return {EX_UNSUPPORTED_OPERATION, 0, 0};
        }
    }
@@ -464,20 +439,11 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
        }
    }

    bool accumulate = false;
    if (outChannels > 2) {
        // Accumulate if required
        if (accumulate) {
            for (int i = 0; i < frameCount; i++) {
                out[outChannels * i] += outFrames[FCC_2 * i];
                out[outChannels * i + 1] += outFrames[FCC_2 * i + 1];
            }
        } else {
        for (int i = 0; i < frameCount; i++) {
            out[outChannels * i] = outFrames[FCC_2 * i];
            out[outChannels * i + 1] = outFrames[FCC_2 * i + 1];
        }
        }
        if (!isAuxiliary()) {
            for (int i = 0; i < frameCount; i++) {
                // channels and outChannels are expected to be same.
@@ -486,17 +452,6 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
                }
            }
        }
    } else {
        if (accumulate) {
            if (outChannels == FCC_1) {
                for (int i = 0; i < frameCount; i++) {
                    out[i] += ((outFrames[i * FCC_2] + outFrames[i * FCC_2 + 1]) * 0.5f);
                }
            } else {
                for (int i = 0; i < frameCount * FCC_2; i++) {
                    out[i] += outFrames[i];
                }
            }
    } else {
        if (outChannels == FCC_1) {
            From2iToMono_Float(outFrames.data(), out, frameCount);
@@ -506,9 +461,6 @@ IEffect::Status ReverbContext::process(float* in, float* out, int samples) {
            }
        }
    }
    }

    LOG(DEBUG) << __func__ << " done processing";

    if (!mEnabled && mSamplesToExitCount > 0) {
        // signed - unsigned will trigger integer overflow if result becomes negative.
+1 −2
Original line number Diff line number Diff line
@@ -158,10 +158,9 @@ class ReverbContext final : public EffectContext {
             {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000}},
            {PresetReverb::Presets::PLATE, {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750}}};

    std::mutex mMutex;
    const lvm::ReverbEffectType mType;
    bool mEnabled = false;
    LVREV_Handle_t mInstance GUARDED_BY(mMutex) = LVM_NULL;
    LVREV_Handle_t mInstance = LVM_NULL;

    int mRoomLevel = 0;
    int mRoomHfLevel = 0;