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

Commit 65d1ee72 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "Downmix: Use internal ChannelMix if Downmix Effect unsupported" into...

Merge "Downmix: Use internal ChannelMix if Downmix Effect unsupported" into sc-v2-dev am: c813bc53 am: bd325815

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

Change-Id: I1502aa9d5d94c2649e2c777c8bb1e23053fdbd12
parents 74a17b32 bd325815
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -193,6 +193,24 @@ status_t AudioMixer::Track::prepareForDownmix()
        // mDownmixerBufferProvider reset below.
    }

    // See if we should use our built-in non-effect downmixer.
    if (mMixerInFormat == AUDIO_FORMAT_PCM_FLOAT
            && mMixerChannelMask == AUDIO_CHANNEL_OUT_STEREO
            && audio_channel_mask_get_representation(channelMask)
                    == AUDIO_CHANNEL_REPRESENTATION_POSITION) {
        mDownmixerBufferProvider.reset(new ChannelMixBufferProvider(channelMask,
                mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount));
        if (static_cast<ChannelMixBufferProvider *>(mDownmixerBufferProvider.get())
                ->isValid()) {
            mDownmixRequiresFormat = mMixerInFormat;
            reconfigureBufferProviders();
            ALOGD("%s: Fallback using ChannelMix", __func__);
            return NO_ERROR;
        } else {
            ALOGD("%s: ChannelMix not supported for channel mask %#x", __func__, channelMask);
        }
    }

    // Effect downmixer does not accept the channel conversion.  Let's use our remixer.
    mDownmixerBufferProvider.reset(new RemixBufferProvider(channelMask,
            mMixerChannelMask, mMixerInFormat, kCopyBufferFrameCount));
+23 −0
Original line number Diff line number Diff line
@@ -364,6 +364,29 @@ void RemixBufferProvider::copyFrames(void *dst, const void *src, size_t frames)
            src, mInputChannels, mIdxAry, mSampleSize, frames);
}

ChannelMixBufferProvider::ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask,
        audio_channel_mask_t outputChannelMask, audio_format_t format,
        size_t bufferFrameCount) :
        CopyBufferProvider(
                audio_bytes_per_sample(format)
                    * audio_channel_count_from_out_mask(inputChannelMask),
                audio_bytes_per_sample(format)
                    * audio_channel_count_from_out_mask(outputChannelMask),
                bufferFrameCount)
{
    ALOGV("ChannelMixBufferProvider(%p)(%#x, %#x, %#x)",
            this, format, inputChannelMask, outputChannelMask);
    if (outputChannelMask == AUDIO_CHANNEL_OUT_STEREO && format == AUDIO_FORMAT_PCM_FLOAT) {
        mIsValid = mChannelMix.setInputChannelMask(inputChannelMask);
    }
}

void ChannelMixBufferProvider::copyFrames(void *dst, const void *src, size_t frames)
{
    mChannelMix.process(static_cast<const float *>(src), static_cast<float *>(dst),
            frames, false /* accumulate */);
}

ReformatBufferProvider::ReformatBufferProvider(int32_t channelCount,
        audio_format_t inputFormat, audio_format_t outputFormat,
        size_t bufferFrameCount) :
+18 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>

#include <audio_utils/ChannelMix.h>
#include <media/AudioBufferProvider.h>
#include <media/AudioResamplerPublic.h>
#include <system/audio.h>
@@ -129,6 +130,23 @@ protected:
    static const int32_t SESSION_ID_INVALID_AND_IGNORED = -2;
};

// ChannelMixBufferProvider derives from CopyBufferProvider to perform an
// downmix to the proper channel count and mask.
class ChannelMixBufferProvider : public CopyBufferProvider {
public:
    ChannelMixBufferProvider(audio_channel_mask_t inputChannelMask,
            audio_channel_mask_t outputChannelMask, audio_format_t format,
            size_t bufferFrameCount);

    void copyFrames(void *dst, const void *src, size_t frames) override;

    bool isValid() const { return mIsValid; }

protected:
    audio_utils::channels::ChannelMix mChannelMix;
    bool mIsValid = false;
};

// RemixBufferProvider derives from CopyBufferProvider to perform an
// upmix or downmix to the proper channel count and mask.
class RemixBufferProvider : public CopyBufferProvider {