audio: fetch devices from the deviceportconfigs
As part of IModule::setAudioPatch, streams might have device
change. The new device portconfigs have the device information.
They should be same as devices fetched
mix port config id -> connected device port config ids [from mPatches]
-> associated AudioPorts [from ports] -> associated AudioDevices.
Bug: 370242708
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I5765a1e5ea9f586add1c3ab50cbaef4641a32e1a
diff --git a/audio/aidl/default/Module.cpp b/audio/aidl/default/Module.cpp
index 45ce5ef..a2a357c 100644
--- a/audio/aidl/default/Module.cpp
+++ b/audio/aidl/default/Module.cpp
@@ -236,19 +236,26 @@
return ndk::ScopedAStatus::ok();
}
-std::vector<AudioDevice> Module::findConnectedDevices(int32_t portConfigId) {
+std::vector<AudioDevice> Module::getDevicesFromDevicePortConfigIds(
+ const std::set<int32_t>& devicePortConfigIds) {
std::vector<AudioDevice> result;
- auto& ports = getConfig().ports;
- auto portIds = portIdsFromPortConfigIds(findConnectedPortConfigIds(portConfigId));
- for (auto it = portIds.begin(); it != portIds.end(); ++it) {
- auto portIt = findById<AudioPort>(ports, *it);
- if (portIt != ports.end() && portIt->ext.getTag() == AudioPortExt::Tag::device) {
- result.push_back(portIt->ext.template get<AudioPortExt::Tag::device>().device);
+ auto& configs = getConfig().portConfigs;
+ for (const auto& id : devicePortConfigIds) {
+ auto it = findById<AudioPortConfig>(configs, id);
+ if (it != configs.end() && it->ext.getTag() == AudioPortExt::Tag::device) {
+ result.push_back(it->ext.template get<AudioPortExt::Tag::device>().device);
+ } else {
+ LOG(FATAL) << __func__ << ": " << mType
+ << ": failed to find device for id" << id;
}
}
return result;
}
+std::vector<AudioDevice> Module::findConnectedDevices(int32_t portConfigId) {
+ return getDevicesFromDevicePortConfigIds(findConnectedPortConfigIds(portConfigId));
+}
+
std::set<int32_t> Module::findConnectedPortConfigIds(int32_t portConfigId) {
std::set<int32_t> result;
auto patchIdsRange = mPatches.equal_range(portConfigId);
@@ -483,7 +490,7 @@
const int32_t mixPortConfigId = connectionPair.first;
if (auto it = oldConnections.find(mixPortConfigId);
it == oldConnections.end() || it->second != connectionPair.second) {
- const auto connectedDevices = findConnectedDevices(mixPortConfigId);
+ const auto connectedDevices = getDevicesFromDevicePortConfigIds(connectionPair.second);
if (connectedDevices.empty()) {
// This is important as workers use the vector size to derive the connection status.
LOG(FATAL) << "updateStreamsConnectedState: No connected devices found for port "
diff --git a/audio/aidl/default/include/core-impl/Module.h b/audio/aidl/default/include/core-impl/Module.h
index 8548aff..7e32cf2 100644
--- a/audio/aidl/default/include/core-impl/Module.h
+++ b/audio/aidl/default/include/core-impl/Module.h
@@ -241,6 +241,8 @@
std::vector<AudioRoute*> getAudioRoutesForAudioPortImpl(int32_t portId);
Configuration& getConfig();
const ConnectedDevicePorts& getConnectedDevicePorts() const { return mConnectedDevicePorts; }
+ std::vector<::aidl::android::media::audio::common::AudioDevice>
+ getDevicesFromDevicePortConfigIds(const std::set<int32_t>& devicePortConfigIds);
bool getMasterMute() const { return mMasterMute; }
bool getMasterVolume() const { return mMasterVolume; }
bool getMicMute() const { return mMicMute; }