libaudiohal@aidl: Fix `setPortConfigFromConfig` for unspecified values
AudioPortConfig type expects that unspecified parameters shall be
left unset: they are @nullable to match the legacy approach with
flags which was used in struct audio_port_config. However,
`setPortConfigFromConfig` was mistakingly setting parameters even
when they had default values in the source AudioConfig. This was
confusing the implementation of `IModule::setAudioPortConfig`.
Bug: 298175108
Test: atest audiosystem_tests
Change-Id: Ie352bb3874a9d0a357a30e766ebb6ba14ab6e0c9
diff --git a/media/libaudiohal/impl/DeviceHalAidl.cpp b/media/libaudiohal/impl/DeviceHalAidl.cpp
index e22acc4..c6552ef 100644
--- a/media/libaudiohal/impl/DeviceHalAidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalAidl.cpp
@@ -42,6 +42,7 @@
using aidl::android::media::audio::common::AudioDevice;
using aidl::android::media::audio::common::AudioDeviceAddress;
using aidl::android::media::audio::common::AudioDeviceType;
+using aidl::android::media::audio::common::AudioFormatDescription;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioInputFlags;
using aidl::android::media::audio::common::AudioIoFlags;
@@ -97,9 +98,15 @@
}
void setPortConfigFromConfig(AudioPortConfig* portConfig, const AudioConfig& config) {
- portConfig->sampleRate = Int{ .value = config.base.sampleRate };
- portConfig->channelMask = config.base.channelMask;
- portConfig->format = config.base.format;
+ if (config.base.sampleRate != 0) {
+ portConfig->sampleRate = Int{ .value = config.base.sampleRate };
+ }
+ if (config.base.channelMask != AudioChannelLayout{}) {
+ portConfig->channelMask = config.base.channelMask;
+ }
+ if (config.base.format != AudioFormatDescription{}) {
+ portConfig->format = config.base.format;
+ }
}
// Note: these converters are for types defined in different AIDL files. Although these
@@ -1050,7 +1057,9 @@
matchDevice.address = AudioDeviceAddress::make<AudioDeviceAddress::id>();
auto portsIt = findPort(matchDevice);
if (portsIt == mPorts.end()) {
- ALOGW("%s: device port for device %s is not found in the module %s",
+ // Since 'setConnectedState' is called for all modules, it is normal when the device
+ // port not found in every one of them.
+ ALOGD("%s: device port for device %s is not found in the module %s",
__func__, matchDevice.toString().c_str(), mInstance.c_str());
return BAD_VALUE;
}