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

Commit e524c7fd authored by Ping Tsai's avatar Ping Tsai Committed by Eric Laurent
Browse files

audiopolicy: fix pick input profile issue

The exact match profile consider not only the config but also the flags
The compatibilityScore is used to determine the level of match between configurations and flags. It has the following possible values:

- NO_MATCH: Both config and flags are not compatible.
- PARTIAL_MATCH: Both config and flags are partially matched.
- PARTIAL_MATCH_WITH_CONFIG: Partial match with flags(e.g. fast flags) and exact match with config.
- PARTIAL_MATCH_WITH_FLAG: Partial match with config and exact match with flags.
- EXACT_MATCH: Both config and flags are exactly matched.

Bug: 390278647
Test: atest audiopolicy_tests
Flag: EXEMPT bug fix
(cherry picked from https://partner-android-review.googlesource.com/q/commit:9b8b7736b89a9f57280f791118b6d70bf8f3b83d)
Merged-In: Ifaf1ce2fabd468b8859fe818f14d69bd702bf74e
Change-Id: Ifaf1ce2fabd468b8859fe818f14d69bd702bf74e
parent 523b6910
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -70,11 +70,20 @@ public:
        return mMixerBehaviors;
    }

    /**
     * NO_MATCH: Both config and flags are not compatible.
     * PARTIAL_MATCH: Both config and flags are partially matched.
     * PARTIAL_MATCH_WITH_CONFIG: Partial match with flags(e.g. fast flags) and exact match with
     * config.
     * PARTIAL_MATCH_WITH_FLAG: Partial match with config and exact match with flags.
     * EXACT_MATCH: Both config and flags are exactly matched.
     */
    enum CompatibilityScore{
        NO_MATCH = 0,
        PARTIAL_MATCH = 1,
        PARTIAL_MATCH_WITH_FLAG = 2,
        EXACT_MATCH = 3
        PARTIAL_MATCH_WITH_CONFIG = 2,
        PARTIAL_MATCH_WITH_FLAG = 3,
        EXACT_MATCH = 4
    };

    /**
+5 −1
Original line number Diff line number Diff line
@@ -77,7 +77,11 @@ IOProfile::CompatibilityScore IOProfile::getCompatibilityScore(
            }
            result = EXACT_MATCH;
        } else if (checkExactAudioProfile(&config) == NO_ERROR) {
            if (flagsCompatibleScore == EXACT_MATCH) {
                result = EXACT_MATCH;
            } else {
                result = PARTIAL_MATCH_WITH_CONFIG;
            }
        } else if (checkCompatibleAudioProfile(
                myUpdatedSamplingRate, myUpdatedChannelMask, myUpdatedFormat) == NO_ERROR) {
            if (flagsCompatibleScore == EXACT_MATCH) {
+8 −4
Original line number Diff line number Diff line
@@ -8338,6 +8338,7 @@ sp<IOProfile> AudioPolicyManager::getInputProfile(const sp<DeviceDescriptor> &de
        uint32_t updatedSamplingRate = 0;
        audio_format_t updatedFormat = AUDIO_FORMAT_INVALID;
        audio_channel_mask_t updatedChannelMask = AUDIO_CHANNEL_INVALID;
        auto bestCompatibleScore = IOProfile::NO_MATCH;
        for (const auto& hwModule : mHwModules) {
            for (const auto& profile : hwModule->getInputProfiles()) {
                // profile->log();
@@ -8360,10 +8361,13 @@ sp<IOProfile> AudioPolicyManager::getInputProfile(const sp<DeviceDescriptor> &de
                } else if ((flags != AUDIO_INPUT_FLAG_NONE
                        && compatibleScore == IOProfile::PARTIAL_MATCH_WITH_FLAG)
                    || (inexact == nullptr && compatibleScore != IOProfile::NO_MATCH)) {
                    if (compatibleScore > bestCompatibleScore) {
                        inexact = profile;
                        inexactSamplingRate = updatedSamplingRate;
                        inexactFormat = updatedFormat;
                        inexactChannelMask = updatedChannelMask;
                        bestCompatibleScore = compatibleScore;
                    }
                }
            }
        }
+30 −0
Original line number Diff line number Diff line
@@ -1348,6 +1348,36 @@ TEST_F(AudioPolicyManagerTestWithConfigurationFile, UpdateConfigFromInexactProfi
    EXPECT_EQ(expectedChannelMask, requestedChannelMask);
}

TEST_F(AudioPolicyManagerTestWithConfigurationFile, UpdateConfigFromExactProfile) {
    const audio_format_t expectedFormat = AUDIO_FORMAT_PCM_16_BIT;
    const uint32_t expectedSampleRate = 48000;
    const audio_channel_mask_t expectedChannelMask = AUDIO_CHANNEL_IN_STEREO;
    const audio_input_flags_t expectedFlags = AUDIO_INPUT_FLAG_FAST;
    const std::string expectedIOProfile = "mixport_fast_input";

    auto devices = mManager->getAvailableInputDevices();
    sp<DeviceDescriptor> mic = nullptr;
    for (auto device : devices) {
        if (device->type() == AUDIO_DEVICE_IN_BUILTIN_MIC) {
            mic = device;
            break;
        }
    }
    EXPECT_NE(nullptr, mic);

    audio_format_t requestedFormat = AUDIO_FORMAT_PCM_16_BIT;
    uint32_t requestedSampleRate = 48000;
    audio_channel_mask_t requestedChannelMask = AUDIO_CHANNEL_IN_STEREO;
    audio_input_flags_t requestedFlags = AUDIO_INPUT_FLAG_FAST;
    auto profile = mManager->getInputProfile(
            mic, requestedSampleRate, requestedFormat, requestedChannelMask, requestedFlags);
    EXPECT_EQ(expectedIOProfile, profile->getName());
    EXPECT_EQ(expectedFormat, requestedFormat);
    EXPECT_EQ(expectedSampleRate, requestedSampleRate);
    EXPECT_EQ(expectedChannelMask, requestedChannelMask);
    EXPECT_EQ(expectedFlags, profile->getFlags());
}

TEST_F(AudioPolicyManagerTestWithConfigurationFile, MatchesMoreInputFlagsWhenPossible) {
    const audio_format_t expectedFormat = AUDIO_FORMAT_PCM_16_BIT;
    const uint32_t expectedSampleRate = 48000;