From 5f82f49d4f31f0622b422e6254aa60d36f4a61fa Mon Sep 17 00:00:00 2001 From: jiabin Date: Fri, 9 Apr 2021 19:03:58 +0000 Subject: [PATCH] Count channel mapping number from the back. The channel mapping array may have leading UNUSED value. In that case, count the channel mapping number from the back to avoid lost channel mapping information. Bug: 183558363 Test: repo steps in the bug Test: atest android.hardware.audio@7.0-util_tests Change-Id: Ic4238e520c16eb1daad7c9e92555e92637f8e7c9 --- audio/core/all-versions/default/util/CoreUtils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/audio/core/all-versions/default/util/CoreUtils.cpp b/audio/core/all-versions/default/util/CoreUtils.cpp index 14f76f3c65..773be21962 100644 --- a/audio/core/all-versions/default/util/CoreUtils.cpp +++ b/audio/core/all-versions/default/util/CoreUtils.cpp @@ -66,13 +66,13 @@ status_t CoreUtils::microphoneInfoFromHal( CONVERT_CHECKED( deviceAddressFromHal(halMicInfo.device, halMicInfo.address, &micInfo->deviceAddress), result); - size_t chCount; - for (chCount = 0; chCount < AUDIO_CHANNEL_COUNT_MAX; ++chCount) { - if (halMicInfo.channel_mapping[chCount] == AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED) { + int chCount; + for (chCount = AUDIO_CHANNEL_COUNT_MAX - 1; chCount >= 0; --chCount) { + if (halMicInfo.channel_mapping[chCount] != AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED) { break; } } - micInfo->channelMapping.resize(chCount); + micInfo->channelMapping.resize(chCount + 1); for (size_t ch = 0; ch < micInfo->channelMapping.size(); ch++) { micInfo->channelMapping[ch] = AudioMicrophoneChannelMapping(halMicInfo.channel_mapping[ch]); }