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
diff --git a/audio/core/all-versions/default/util/CoreUtils.cpp b/audio/core/all-versions/default/util/CoreUtils.cpp
index 14f76f3..773be21 100644
--- a/audio/core/all-versions/default/util/CoreUtils.cpp
+++ b/audio/core/all-versions/default/util/CoreUtils.cpp
@@ -66,13 +66,13 @@
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]);
}