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

Commit 4e2547cf authored by Andy Hung's avatar Andy Hung
Browse files

Spatializer: Respect FCC_LIMIT for input masks

Avoid channel combinations not permitted by a mixer.
Fix minor efficiency in getMaxChannelMask.
Fix crash on spatializer config failure.

Test: See bug for repro steps.
Bug: 239121938
Change-Id: Ia55a49bd1a35ccc0b60900afa57707bb4435254b
parent 72cb1621
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -59,11 +59,13 @@ using namespace std::chrono_literals;
       if (!_tmp.ok()) return aidl_utils::binderStatusFromStatusT(_tmp.error()); \
       std::move(_tmp.value()); })

audio_channel_mask_t getMaxChannelMask(std::vector<audio_channel_mask_t> masks) {
static audio_channel_mask_t getMaxChannelMask(
        const std::vector<audio_channel_mask_t>& masks, size_t channelLimit = SIZE_MAX) {
    uint32_t maxCount = 0;
    audio_channel_mask_t maxMask = AUDIO_CHANNEL_NONE;
    for (auto mask : masks) {
        const size_t count = audio_channel_count_from_out_mask(mask);
        if (count > channelLimit) continue;  // ignore masks greater than channelLimit
        if (count > maxCount) {
            maxMask = mask;
            maxCount = count;
@@ -238,10 +240,13 @@ sp<Spatializer> Spatializer::create(SpatializerPolicyCallback *callback) {
        spatializer = new Spatializer(descriptors[0], callback);
        if (spatializer->loadEngineConfiguration(effect) != NO_ERROR) {
            spatializer.clear();
        }
            ALOGW("%s loadEngine error: %d  effect Id %" PRId64,
                    __func__, status, effect ? effect->effectId() : 0);
        } else {
            spatializer->mLocalLog.log("%s with effect Id %" PRId64, __func__,
                                       effect ? effect->effectId() : 0);
        }
    }

    return spatializer;
}
@@ -387,7 +392,7 @@ audio_config_base_t Spatializer::getAudioInConfig() const {
    std::lock_guard lock(mLock);
    audio_config_base_t config = AUDIO_CONFIG_BASE_INITIALIZER;
    // For now use highest supported channel count
    config.channel_mask = getMaxChannelMask(mChannelMasks);
    config.channel_mask = getMaxChannelMask(mChannelMasks, FCC_LIMIT);
    return config;
}