diff --git a/audio/aidl/default/Module.cpp b/audio/aidl/default/Module.cpp index 45ce5ef1d1..a2a357ce88 100644 --- a/audio/aidl/default/Module.cpp +++ b/audio/aidl/default/Module.cpp @@ -236,19 +236,26 @@ ndk::ScopedAStatus Module::createStreamContext( return ndk::ScopedAStatus::ok(); } -std::vector Module::findConnectedDevices(int32_t portConfigId) { +std::vector Module::getDevicesFromDevicePortConfigIds( + const std::set& devicePortConfigIds) { std::vector result; - auto& ports = getConfig().ports; - auto portIds = portIdsFromPortConfigIds(findConnectedPortConfigIds(portConfigId)); - for (auto it = portIds.begin(); it != portIds.end(); ++it) { - auto portIt = findById(ports, *it); - if (portIt != ports.end() && portIt->ext.getTag() == AudioPortExt::Tag::device) { - result.push_back(portIt->ext.template get().device); + auto& configs = getConfig().portConfigs; + for (const auto& id : devicePortConfigIds) { + auto it = findById(configs, id); + if (it != configs.end() && it->ext.getTag() == AudioPortExt::Tag::device) { + result.push_back(it->ext.template get().device); + } else { + LOG(FATAL) << __func__ << ": " << mType + << ": failed to find device for id" << id; } } return result; } +std::vector Module::findConnectedDevices(int32_t portConfigId) { + return getDevicesFromDevicePortConfigIds(findConnectedPortConfigIds(portConfigId)); +} + std::set Module::findConnectedPortConfigIds(int32_t portConfigId) { std::set result; auto patchIdsRange = mPatches.equal_range(portConfigId); @@ -483,7 +490,7 @@ ndk::ScopedAStatus Module::updateStreamsConnectedState(const AudioPatch& oldPatc 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 8548aff5f3..7e32cf2217 100644 --- a/audio/aidl/default/include/core-impl/Module.h +++ b/audio/aidl/default/include/core-impl/Module.h @@ -241,6 +241,8 @@ class Module : public BnModule { std::vector getAudioRoutesForAudioPortImpl(int32_t portId); Configuration& getConfig(); const ConnectedDevicePorts& getConnectedDevicePorts() const { return mConnectedDevicePorts; } + std::vector<::aidl::android::media::audio::common::AudioDevice> + getDevicesFromDevicePortConfigIds(const std::set& devicePortConfigIds); bool getMasterMute() const { return mMasterMute; } bool getMasterVolume() const { return mMasterVolume; } bool getMicMute() const { return mMicMute; }