Libaudiohal: only match haptic port if haptic channel mask is requested.
Haptic mix port usually doesn't contain an output flag but it can be
identified by the channel mask. If the request doesn't contain haptic
channel mask, there is no need to use haptic mix port as there should be
some other mix port will be matched.
Bug: 251215866
Test: make
Change-Id: I472fed3e10cd6d5d5864de9eb9328f634db949fb
diff --git a/media/libaudiohal/impl/Hal2AidlMapper.cpp b/media/libaudiohal/impl/Hal2AidlMapper.cpp
index f187057..47fcd27 100644
--- a/media/libaudiohal/impl/Hal2AidlMapper.cpp
+++ b/media/libaudiohal/impl/Hal2AidlMapper.cpp
@@ -82,6 +82,16 @@
}
}
+bool containHapticChannel(AudioChannelLayout channel) {
+ return channel.getTag() == AudioChannelLayout::Tag::layoutMask &&
+ ((channel.get<AudioChannelLayout::Tag::layoutMask>()
+ & AudioChannelLayout::CHANNEL_HAPTIC_A)
+ == AudioChannelLayout::CHANNEL_HAPTIC_A ||
+ (channel.get<AudioChannelLayout::Tag::layoutMask>()
+ & AudioChannelLayout::CHANNEL_HAPTIC_B)
+ == AudioChannelLayout::CHANNEL_HAPTIC_B);
+}
+
} // namespace
Hal2AidlMapper::Hal2AidlMapper(const std::string& instance, const std::shared_ptr<IModule>& module)
@@ -438,11 +448,20 @@
Hal2AidlMapper::Ports::iterator Hal2AidlMapper::findPort(
const AudioConfig& config, const AudioIoFlags& flags,
const std::set<int32_t>& destinationPortIds) {
- auto belongsToProfile = [&config](const AudioProfile& prof) {
+ auto channelMaskMatches = [](const std::vector<AudioChannelLayout>& channelMasks,
+ const AudioChannelLayout& channelMask) {
+ // Return true when 1) the channel mask is none and none of the channel mask from the
+ // collection contains haptic channel mask, or 2) the channel mask collection contains
+ // the queried channel mask.
+ return (channelMask.getTag() == AudioChannelLayout::none &&
+ std::none_of(channelMasks.begin(), channelMasks.end(),
+ containHapticChannel)) ||
+ std::find(channelMasks.begin(), channelMasks.end(), channelMask)
+ != channelMasks.end();
+ };
+ auto belongsToProfile = [&config, &channelMaskMatches](const AudioProfile& prof) {
return (isDefaultAudioFormat(config.base.format) || prof.format == config.base.format) &&
- (config.base.channelMask.getTag() == AudioChannelLayout::none ||
- std::find(prof.channelMasks.begin(), prof.channelMasks.end(),
- config.base.channelMask) != prof.channelMasks.end()) &&
+ channelMaskMatches(prof.channelMasks, config.base.channelMask) &&
(config.base.sampleRate == 0 ||
std::find(prof.sampleRates.begin(), prof.sampleRates.end(),
config.base.sampleRate) != prof.sampleRates.end());