Loading services/audiopolicy/common/managerdefinitions/include/IOProfile.h +11 −2 Original line number Diff line number Diff line Loading @@ -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 }; /** Loading services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading services/audiopolicy/managerdefault/AudioPolicyManager.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -8347,6 +8347,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(); Loading @@ -8369,10 +8370,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; } } } } Loading services/audiopolicy/tests/audiopolicymanager_tests.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading
services/audiopolicy/common/managerdefinitions/include/IOProfile.h +11 −2 Original line number Diff line number Diff line Loading @@ -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 }; /** Loading
services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp +5 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading
services/audiopolicy/managerdefault/AudioPolicyManager.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -8347,6 +8347,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(); Loading @@ -8369,10 +8370,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; } } } } Loading
services/audiopolicy/tests/audiopolicymanager_tests.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -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; Loading