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

Commit 37802e77 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "AudioFlinger: Clean up Effect configuration macros" am: fb603cc6 am:...

Merge "AudioFlinger: Clean up Effect configuration macros" am: fb603cc6 am: 6dc0a48a am: 4641074b

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/2603925



Change-Id: I2ec7b4c24e868c47fa0103dcbaef115bfe118c67
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8ca862de 4641074b
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -3002,14 +3002,6 @@ sp<AudioFlinger::ThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t mo
        return nullptr;
        return nullptr;
    }
    }


#ifndef MULTICHANNEL_EFFECT_CHAIN
    if (flags & AUDIO_OUTPUT_FLAG_SPATIALIZER) {
        ALOGE("openOutput_l() cannot create spatializer thread "
                "without #define MULTICHANNEL_EFFECT_CHAIN");
        return nullptr;
    }
#endif

    mHardwareStatus = AUDIO_HW_OUTPUT_OPEN;
    mHardwareStatus = AUDIO_HW_OUTPUT_OPEN;


    // FOR TESTING ONLY:
    // FOR TESTING ONLY:
+0 −5
Original line number Original line Diff line number Diff line
@@ -608,13 +608,8 @@ private:
    };
    };


    // --- PlaybackThread ---
    // --- PlaybackThread ---
#ifdef FLOAT_EFFECT_CHAIN
#define EFFECT_BUFFER_FORMAT AUDIO_FORMAT_PCM_FLOAT
#define EFFECT_BUFFER_FORMAT AUDIO_FORMAT_PCM_FLOAT
using effect_buffer_t = float;
using effect_buffer_t = float;
#else
#define EFFECT_BUFFER_FORMAT AUDIO_FORMAT_PCM_16_BIT
using effect_buffer_t = int16_t;
#endif


#include "Threads.h"
#include "Threads.h"


+0 −11
Original line number Original line Diff line number Diff line
@@ -41,15 +41,4 @@
// uncomment to log CPU statistics every n wall clock seconds
// uncomment to log CPU statistics every n wall clock seconds
//#define DEBUG_CPU_USAGE 10
//#define DEBUG_CPU_USAGE 10


// define FLOAT_EFFECT_CHAIN to request float effects (falls back to int16_t if unavailable)
#define FLOAT_EFFECT_CHAIN

#ifdef FLOAT_EFFECT_CHAIN
// define FLOAT_AUX to process aux effect buffers in float (FLOAT_EFFECT_CHAIN must be defined)
#define FLOAT_AUX

// define MULTICHANNEL_EFFECT_CHAIN to allow multichannel effects (FLOAT_EFFECT_CHAIN defined)
#define MULTICHANNEL_EFFECT_CHAIN
#endif

#endif // ANDROID_AUDIOFLINGER_CONFIGURATION_H
#endif // ANDROID_AUDIOFLINGER_CONFIGURATION_H
+3 −83
Original line number Original line Diff line number Diff line
@@ -573,9 +573,7 @@ AudioFlinger::EffectModule::EffectModule(const sp<AudioFlinger::EffectCallbackIn
      mDisableWaitCnt(0),    // set by process() and updateState()
      mDisableWaitCnt(0),    // set by process() and updateState()
      mOffloaded(false),
      mOffloaded(false),
      mIsOutput(false)
      mIsOutput(false)
#ifdef FLOAT_EFFECT_CHAIN
      , mSupportsFloat(false)
      , mSupportsFloat(false)
#endif
{
{
    ALOGV("Constructor %p pinned %d", this, pinned);
    ALOGV("Constructor %p pinned %d", this, pinned);
    int lStatus;
    int lStatus;
@@ -694,31 +692,16 @@ void AudioFlinger::EffectModule::process()
                            mConfig.inputCfg.buffer.frameCount,
                            mConfig.inputCfg.buffer.frameCount,
                            mConfig.outputCfg.buffer.frameCount);
                            mConfig.outputCfg.buffer.frameCount);
    const auto accumulateInputToOutput = [this, safeInputOutputSampleCount]() {
    const auto accumulateInputToOutput = [this, safeInputOutputSampleCount]() {
#ifdef FLOAT_EFFECT_CHAIN
        accumulate_float(
        accumulate_float(
                mConfig.outputCfg.buffer.f32,
                mConfig.outputCfg.buffer.f32,
                mConfig.inputCfg.buffer.f32,
                mConfig.inputCfg.buffer.f32,
                safeInputOutputSampleCount);
                safeInputOutputSampleCount);
#else
        accumulate_i16(
                mConfig.outputCfg.buffer.s16,
                mConfig.inputCfg.buffer.s16,
                safeInputOutputSampleCount);
#endif
    };
    };
    const auto copyInputToOutput = [this, safeInputOutputSampleCount]() {
    const auto copyInputToOutput = [this, safeInputOutputSampleCount]() {
#ifdef FLOAT_EFFECT_CHAIN
        memcpy(
        memcpy(
                mConfig.outputCfg.buffer.f32,
                mConfig.outputCfg.buffer.f32,
                mConfig.inputCfg.buffer.f32,
                mConfig.inputCfg.buffer.f32,
                safeInputOutputSampleCount * sizeof(*mConfig.outputCfg.buffer.f32));
                safeInputOutputSampleCount * sizeof(*mConfig.outputCfg.buffer.f32));

#else
        memcpy(
                mConfig.outputCfg.buffer.s16,
                mConfig.inputCfg.buffer.s16,
                safeInputOutputSampleCount * sizeof(*mConfig.outputCfg.buffer.s16));
#endif
    };
    };


    if (isProcessEnabled()) {
    if (isProcessEnabled()) {
@@ -727,35 +710,14 @@ void AudioFlinger::EffectModule::process()
            if (auxType) {
            if (auxType) {
                // We overwrite the aux input buffer here and clear after processing.
                // We overwrite the aux input buffer here and clear after processing.
                // aux input is always mono.
                // aux input is always mono.
#ifdef FLOAT_EFFECT_CHAIN

                if (mSupportsFloat) {
                if (!mSupportsFloat) {
#ifndef FLOAT_AUX
                    // Do in-place float conversion for auxiliary effect input buffer.
                    static_assert(sizeof(float) <= sizeof(int32_t),
                            "in-place conversion requires sizeof(float) <= sizeof(int32_t)");

                    memcpy_to_float_from_q4_27(
                            mConfig.inputCfg.buffer.f32,
                            mConfig.inputCfg.buffer.s32,
                            mConfig.inputCfg.buffer.frameCount);
#endif // !FLOAT_AUX
                } else
#endif // FLOAT_EFFECT_CHAIN
                {
#ifdef FLOAT_AUX
                    memcpy_to_i16_from_float(
                    memcpy_to_i16_from_float(
                            mConfig.inputCfg.buffer.s16,
                            mConfig.inputCfg.buffer.s16,
                            mConfig.inputCfg.buffer.f32,
                            mConfig.inputCfg.buffer.f32,
                            mConfig.inputCfg.buffer.frameCount);
                            mConfig.inputCfg.buffer.frameCount);
#else
                    memcpy_to_i16_from_q4_27(
                            mConfig.inputCfg.buffer.s16,
                            mConfig.inputCfg.buffer.s32,
                            mConfig.inputCfg.buffer.frameCount);
#endif
                }
                }
            }
            }
#ifdef FLOAT_EFFECT_CHAIN
            sp<EffectBufferHalInterface> inBuffer = mInBuffer;
            sp<EffectBufferHalInterface> inBuffer = mInBuffer;
            sp<EffectBufferHalInterface> outBuffer = mOutBuffer;
            sp<EffectBufferHalInterface> outBuffer = mOutBuffer;


@@ -802,9 +764,7 @@ void AudioFlinger::EffectModule::process()
                    outBuffer = mOutConversionBuffer;
                    outBuffer = mOutConversionBuffer;
                }
                }
            }
            }
#endif
            ret = mEffectInterface->process();
            ret = mEffectInterface->process();
#ifdef FLOAT_EFFECT_CHAIN
            if (!mSupportsFloat) { // convert output int16_t back to float.
            if (!mSupportsFloat) { // convert output int16_t back to float.
                sp<EffectBufferHalInterface> target =
                sp<EffectBufferHalInterface> target =
                        mOutChannelCountRequested != outChannelCount
                        mOutChannelCountRequested != outChannelCount
@@ -821,11 +781,8 @@ void AudioFlinger::EffectModule::process()
                        sizeof(float),
                        sizeof(float),
                        sizeof(float) * outChannelCount * mConfig.outputCfg.buffer.frameCount);
                        sizeof(float) * outChannelCount * mConfig.outputCfg.buffer.frameCount);
            }
            }
#endif
        } else {
        } else {
#ifdef FLOAT_EFFECT_CHAIN
            data_bypass:
            data_bypass:
#endif
            if (!auxType  /* aux effects do not require data bypass */
            if (!auxType  /* aux effects do not require data bypass */
                    && mConfig.inputCfg.buffer.raw != mConfig.outputCfg.buffer.raw) {
                    && mConfig.inputCfg.buffer.raw != mConfig.outputCfg.buffer.raw) {
                if (mConfig.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
                if (mConfig.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
@@ -844,13 +801,8 @@ void AudioFlinger::EffectModule::process()


        // clear auxiliary effect input buffer for next accumulation
        // clear auxiliary effect input buffer for next accumulation
        if (auxType) {
        if (auxType) {
#ifdef FLOAT_AUX
            const size_t size =
            const size_t size =
                    mConfig.inputCfg.buffer.frameCount * inChannelCount * sizeof(float);
                    mConfig.inputCfg.buffer.frameCount * inChannelCount * sizeof(float);
#else
            const size_t size =
                    mConfig.inputCfg.buffer.frameCount * inChannelCount * sizeof(int32_t);
#endif
            memset(mConfig.inputCfg.buffer.raw, 0, size);
            memset(mConfig.inputCfg.buffer.raw, 0, size);
        }
        }
    } else if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT &&
    } else if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT &&
@@ -905,23 +857,6 @@ status_t AudioFlinger::EffectModule::configure()
            ALOGV("Overriding auxiliary effect input channels %#x as MONO",
            ALOGV("Overriding auxiliary effect input channels %#x as MONO",
                    mConfig.inputCfg.channels);
                    mConfig.inputCfg.channels);
        }
        }
#ifndef MULTICHANNEL_EFFECT_CHAIN
        if (mConfig.outputCfg.channels != AUDIO_CHANNEL_OUT_STEREO) {
            mConfig.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
            ALOGV("Overriding auxiliary effect output channels %#x as STEREO",
                    mConfig.outputCfg.channels);
        }
#endif
    } else {
#ifndef MULTICHANNEL_EFFECT_CHAIN
        // TODO: Update this logic when multichannel effects are implemented.
        // For offloaded tracks consider mono output as stereo for proper effect initialization
        if (channelMask == AUDIO_CHANNEL_OUT_MONO) {
            mConfig.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
            mConfig.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
            ALOGV("Overriding effect input and output as STEREO");
        }
#endif
    }
    }
    if (isHapticGenerator()) {
    if (isHapticGenerator()) {
        audio_channel_mask_t hapticChannelMask = callback->hapticChannelMask();
        audio_channel_mask_t hapticChannelMask = callback->hapticChannelMask();
@@ -982,7 +917,6 @@ status_t AudioFlinger::EffectModule::configure()
        status = cmdStatus;
        status = cmdStatus;
    }
    }


#ifdef MULTICHANNEL_EFFECT_CHAIN
    if (status != NO_ERROR &&
    if (status != NO_ERROR &&
            EffectConfiguration::isHidl() && // only HIDL effects support channel conversion
            EffectConfiguration::isHidl() && // only HIDL effects support channel conversion
            mIsOutput &&
            mIsOutput &&
@@ -1008,9 +942,7 @@ status_t AudioFlinger::EffectModule::configure()
            status = cmdStatus;
            status = cmdStatus;
        }
        }
    }
    }
#endif


#ifdef FLOAT_EFFECT_CHAIN
    if (status == NO_ERROR) {
    if (status == NO_ERROR) {
        mSupportsFloat = true;
        mSupportsFloat = true;
    }
    }
@@ -1036,7 +968,6 @@ status_t AudioFlinger::EffectModule::configure()
            ALOGE("%s failed %d with int16_t (as well as float)", __func__, status);
            ALOGE("%s failed %d with int16_t (as well as float)", __func__, status);
        }
        }
    }
    }
#endif


    if (status == NO_ERROR) {
    if (status == NO_ERROR) {
        // Establish Buffer strategy
        // Establish Buffer strategy
@@ -1349,7 +1280,6 @@ void AudioFlinger::EffectModule::setInBuffer(const sp<EffectBufferHalInterface>&
    mInBuffer = buffer;
    mInBuffer = buffer;
    mEffectInterface->setInBuffer(buffer);
    mEffectInterface->setInBuffer(buffer);


#ifdef FLOAT_EFFECT_CHAIN
    // aux effects do in place conversion to float - we don't allocate mInConversionBuffer.
    // aux effects do in place conversion to float - we don't allocate mInConversionBuffer.
    // Theoretically insert effects can also do in-place conversions (destroying
    // Theoretically insert effects can also do in-place conversions (destroying
    // the original buffer) when the output buffer is identical to the input buffer,
    // the original buffer) when the output buffer is identical to the input buffer,
@@ -1381,7 +1311,6 @@ void AudioFlinger::EffectModule::setInBuffer(const sp<EffectBufferHalInterface>&
            ALOGE("%s cannot create mInConversionBuffer", __func__);
            ALOGE("%s cannot create mInConversionBuffer", __func__);
        }
        }
    }
    }
#endif
}
}


void AudioFlinger::EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
void AudioFlinger::EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>& buffer) {
@@ -1397,7 +1326,6 @@ void AudioFlinger::EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>
    mOutBuffer = buffer;
    mOutBuffer = buffer;
    mEffectInterface->setOutBuffer(buffer);
    mEffectInterface->setOutBuffer(buffer);


#ifdef FLOAT_EFFECT_CHAIN
    // Note: Any effect that does not accumulate does not need mOutConversionBuffer and
    // Note: Any effect that does not accumulate does not need mOutConversionBuffer and
    // can do in-place conversion from int16_t to float.  We don't optimize here.
    // can do in-place conversion from int16_t to float.  We don't optimize here.
    const uint32_t outChannelCount =
    const uint32_t outChannelCount =
@@ -1425,7 +1353,6 @@ void AudioFlinger::EffectModule::setOutBuffer(const sp<EffectBufferHalInterface>
            ALOGE("%s cannot create mOutConversionBuffer", __func__);
            ALOGE("%s cannot create mOutConversionBuffer", __func__);
        }
        }
    }
    }
#endif
}
}


status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right, bool controller)
status_t AudioFlinger::EffectModule::setVolume(uint32_t *left, uint32_t *right, bool controller)
@@ -1721,15 +1648,12 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
            mConfig.outputCfg.format,
            mConfig.outputCfg.format,
            formatToString((audio_format_t)mConfig.outputCfg.format).c_str());
            formatToString((audio_format_t)mConfig.outputCfg.format).c_str());


#ifdef FLOAT_EFFECT_CHAIN

    result.appendFormat("\t\t- HAL buffers:\n"
    result.appendFormat("\t\t- HAL buffers:\n"
            "\t\t\tIn(%s) InConversion(%s) Out(%s) OutConversion(%s)\n",
            "\t\t\tIn(%s) InConversion(%s) Out(%s) OutConversion(%s)\n",
            dumpInOutBuffer(true /* isInput */, mInBuffer).c_str(),
            dumpInOutBuffer(true /* isInput */, mInBuffer).c_str(),
            dumpInOutBuffer(true /* isInput */, mInConversionBuffer).c_str(),
            dumpInOutBuffer(true /* isInput */, mInConversionBuffer).c_str(),
            dumpInOutBuffer(false /* isInput */, mOutBuffer).c_str(),
            dumpInOutBuffer(false /* isInput */, mOutBuffer).c_str(),
            dumpInOutBuffer(false /* isInput */, mOutConversionBuffer).c_str());
            dumpInOutBuffer(false /* isInput */, mOutConversionBuffer).c_str());
#endif


    write(fd, result.string(), result.length());
    write(fd, result.string(), result.length());


@@ -2363,13 +2287,9 @@ status_t AudioFlinger::EffectChain::addEffect_ll(const sp<EffectModule>& effect)
        // calling the process in effect engine
        // calling the process in effect engine
        size_t numSamples = mEffectCallback->frameCount();
        size_t numSamples = mEffectCallback->frameCount();
        sp<EffectBufferHalInterface> halBuffer;
        sp<EffectBufferHalInterface> halBuffer;
#ifdef FLOAT_EFFECT_CHAIN

        status_t result = mEffectCallback->allocateHalBuffer(
        status_t result = mEffectCallback->allocateHalBuffer(
                numSamples * sizeof(float), &halBuffer);
                numSamples * sizeof(float), &halBuffer);
#else
        status_t result = mEffectCallback->allocateHalBuffer(
                numSamples * sizeof(int32_t), &halBuffer);
#endif
        if (result != OK) return result;
        if (result != OK) return result;


        effect->configure();
        effect->configure();
+0 −2
Original line number Original line Diff line number Diff line
@@ -323,13 +323,11 @@ private:
    audio_io_handle_t mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    audio_io_handle_t mCurrentHalStream = AUDIO_IO_HANDLE_NONE;
    bool     mIsOutput;             // direction of the AF thread
    bool     mIsOutput;             // direction of the AF thread


#ifdef FLOAT_EFFECT_CHAIN
    bool    mSupportsFloat;         // effect supports float processing
    bool    mSupportsFloat;         // effect supports float processing
    sp<EffectBufferHalInterface> mInConversionBuffer;  // Buffers for HAL conversion if needed.
    sp<EffectBufferHalInterface> mInConversionBuffer;  // Buffers for HAL conversion if needed.
    sp<EffectBufferHalInterface> mOutConversionBuffer;
    sp<EffectBufferHalInterface> mOutConversionBuffer;
    uint32_t mInChannelCountRequested;
    uint32_t mInChannelCountRequested;
    uint32_t mOutChannelCountRequested;
    uint32_t mOutChannelCountRequested;
#endif


    class AutoLockReentrant {
    class AutoLockReentrant {
    public:
    public:
Loading