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

Commit cbfb7ef1 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 7803374 from abf84e8f to sc-v2-release

Change-Id: I20a27bd9e2184540274631c1fb399169e0e3d558
parents 64072e95 abf84e8f
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -188,9 +188,11 @@ static bool Downmix_validChannelMask(uint32_t mask)
    if (!mask) {
        return false;
    }
    // check against unsupported channels
    if (mask & ~AUDIO_CHANNEL_OUT_22POINT2) {
        ALOGE("Unsupported channels in %u", mask & ~AUDIO_CHANNEL_OUT_22POINT2);
    // check against unsupported channels (up to FCC_26)
    constexpr uint32_t MAXIMUM_CHANNEL_MASK = AUDIO_CHANNEL_OUT_22POINT2
            | AUDIO_CHANNEL_OUT_FRONT_WIDE_LEFT | AUDIO_CHANNEL_OUT_FRONT_WIDE_RIGHT;
    if (mask & ~MAXIMUM_CHANNEL_MASK) {
        ALOGE("Unsupported channels in %#x", mask & ~MAXIMUM_CHANNEL_MASK);
        return false;
    }
    return true;
@@ -647,6 +649,12 @@ static int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pCon
        ALOGE("Downmix_Configure error: invalid config");
        return -EINVAL;
    }
    // when configuring the effect, do not allow a blank or unsupported channel mask
    if (!Downmix_validChannelMask(pConfig->inputCfg.channels)) {
        ALOGE("Downmix_Configure error: input channel mask(0x%x) not supported",
                                                    pConfig->inputCfg.channels);
        return -EINVAL;
    }

    if (&pDwmModule->config != pConfig) {
        memcpy(&pDwmModule->config, pConfig, sizeof(effect_config_t));
@@ -657,12 +665,6 @@ static int Downmix_Configure(downmix_module_t *pDwmModule, effect_config_t *pCon
        pDownmixer->apply_volume_correction = false;
        pDownmixer->input_channel_count = 8; // matches default input of AUDIO_CHANNEL_OUT_7POINT1
    } else {
        // when configuring the effect, do not allow a blank or unsupported channel mask
        if (!Downmix_validChannelMask(pConfig->inputCfg.channels)) {
            ALOGE("Downmix_Configure error: input channel mask(0x%x) not supported",
                                                        pConfig->inputCfg.channels);
            return -EINVAL;
        }
        pDownmixer->input_channel_count =
                audio_channel_count_from_out_mask(pConfig->inputCfg.channels);
    }
+39 −1
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ static constexpr audio_channel_mask_t kChannelPositionMasks[] = {
    AUDIO_CHANNEL_OUT_7POINT1POINT4,
    AUDIO_CHANNEL_OUT_13POINT_360RA,
    AUDIO_CHANNEL_OUT_22POINT2,
    audio_channel_mask_t(AUDIO_CHANNEL_OUT_22POINT2
            | AUDIO_CHANNEL_OUT_FRONT_WIDE_LEFT | AUDIO_CHANNEL_OUT_FRONT_WIDE_RIGHT),
};

constexpr float COEF_25 = 0.2508909536f;
@@ -82,6 +84,8 @@ constexpr inline float kScaleFromChannelIdxLeft[] = {
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_CENTER   = 0x200000u,
    0.f, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_RIGHT    = 0x400000u,
    0.f, // AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2       = 0x800000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_FRONT_WIDE_LEFT       = 0x1000000u,
    0.f,       // AUDIO_CHANNEL_OUT_FRONT_WIDE_RIGHT      = 0x2000000u,
};

constexpr inline float kScaleFromChannelIdxRight[] = {
@@ -109,6 +113,8 @@ constexpr inline float kScaleFromChannelIdxRight[] = {
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_CENTER   = 0x200000u,
    1.f,       // AUDIO_CHANNEL_OUT_BOTTOM_FRONT_RIGHT    = 0x400000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_LOW_FREQUENCY_2       = 0x800000u,
    0.f,       // AUDIO_CHANNEL_OUT_FRONT_WIDE_LEFT       = 0x1000000u,
    M_SQRT1_2, // AUDIO_CHANNEL_OUT_FRONT_WIDE_RIGHT      = 0x2000000u,
};

// Downmix doesn't change with sample rate
@@ -156,7 +162,7 @@ public:
        double savedPower[32][2]{};
        for (unsigned i = 0, channel = channelMask; channel != 0; ++i) {
            const int index = __builtin_ctz(channel);
            ASSERT_LT(index, FCC_24);
            ASSERT_LT(index, FCC_26);
            const int pairIndex = pairIdxFromChannelIdx(index);
            const AUDIO_GEOMETRY_SIDE side = sideFromChannelIdx(index);
            const int channelBit = 1 << index;
@@ -243,6 +249,7 @@ public:
                handle_, EFFECT_CMD_SET_CONFIG,
                sizeof(effect_config_t), &config_, &replySize, &reply);
        ASSERT_EQ(0, err);
        ASSERT_EQ(0, reply);
        err = (downmixApi->command)(
                handle_, EFFECT_CMD_ENABLE,
                0, nullptr, &replySize, &reply);
@@ -253,6 +260,27 @@ public:
        ASSERT_EQ(0, err);
    }

    // This test assumes the channel mask is invalid.
    void testInvalidChannelMask(audio_channel_mask_t invalidChannelMask) {
        reconfig(48000 /* sampleRate */, invalidChannelMask);
        const int32_t sessionId = 0;
        const int32_t ioId = 0;
        int32_t err = AUDIO_EFFECT_LIBRARY_INFO_SYM.create_effect(
                &downmix_uuid_, sessionId, ioId,  &handle_);
        ASSERT_EQ(0, err);

        const struct effect_interface_s * const downmixApi = *handle_;
        int32_t reply = 0;
        uint32_t replySize = (uint32_t)sizeof(reply);
        err = (downmixApi->command)(
                handle_, EFFECT_CMD_SET_CONFIG,
                sizeof(effect_config_t), &config_, &replySize, &reply);
        ASSERT_EQ(0, err);
        ASSERT_NE(0, reply);  // error has occurred.
        err = AUDIO_EFFECT_LIBRARY_INFO_SYM.release_effect(handle_);
        ASSERT_EQ(0, err);
    }

private:
    void reconfig(int sampleRate, audio_channel_mask_t channelMask) {
        config_.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
@@ -299,6 +327,16 @@ private:
    int inputChannelCount_{};
};

TEST(DownmixTestSimple, invalidChannelMask) {
    // Fill in a dummy test method to use DownmixTest outside of a parameterized test.
    class DownmixTestComplete : public DownmixTest {
        void TestBody() override {}
    } downmixtest;

    constexpr auto INVALID_CHANNEL_MASK = audio_channel_mask_t(1 << 31);
    downmixtest.testInvalidChannelMask(INVALID_CHANNEL_MASK);
}

TEST_P(DownmixTest, basic) {
    testBalance(kSampleRates[std::get<0>(GetParam())],
            kChannelPositionMasks[std::get<1>(GetParam())]);