Merge "audio: fetch devices from the deviceportconfigs" into main am: bc717c03e8

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/3322636

Change-Id: I4841149f14920326b11b3174c7a421d30219980a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Mikhail Naganov
2024-11-01 18:04:04 +00:00
committed by Automerger Merge Worker
2 changed files with 17 additions and 8 deletions

View File

@@ -236,19 +236,26 @@ ndk::ScopedAStatus Module::createStreamContext(
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 @@ 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 "

View File

@@ -241,6 +241,8 @@ class Module : public BnModule {
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; }