2021-11-16 01:31:03 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2022 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
2022-06-17 21:41:19 +00:00
|
|
|
#include <chrono>
|
2021-11-16 01:31:03 +00:00
|
|
|
|
2022-09-12 22:57:14 +00:00
|
|
|
#include <Utils.h>
|
2022-06-16 00:35:31 +00:00
|
|
|
#include <aidl/android/media/audio/common/AudioIoFlags.h>
|
|
|
|
|
#include <aidl/android/media/audio/common/AudioOutputFlags.h>
|
2021-11-16 01:31:03 +00:00
|
|
|
|
|
|
|
|
#include "ModuleConfig.h"
|
|
|
|
|
|
|
|
|
|
using namespace android;
|
2022-06-17 21:41:19 +00:00
|
|
|
using namespace std::chrono_literals;
|
2021-11-16 01:31:03 +00:00
|
|
|
|
2022-06-16 00:35:31 +00:00
|
|
|
using aidl::android::hardware::audio::core::IModule;
|
|
|
|
|
using aidl::android::media::audio::common::AudioChannelLayout;
|
2022-06-17 21:41:19 +00:00
|
|
|
using aidl::android::media::audio::common::AudioEncapsulationMode;
|
2022-06-16 00:35:31 +00:00
|
|
|
using aidl::android::media::audio::common::AudioFormatDescription;
|
|
|
|
|
using aidl::android::media::audio::common::AudioFormatType;
|
|
|
|
|
using aidl::android::media::audio::common::AudioIoFlags;
|
2022-06-17 21:41:19 +00:00
|
|
|
using aidl::android::media::audio::common::AudioOffloadInfo;
|
2022-06-16 00:35:31 +00:00
|
|
|
using aidl::android::media::audio::common::AudioOutputFlags;
|
|
|
|
|
using aidl::android::media::audio::common::AudioPort;
|
|
|
|
|
using aidl::android::media::audio::common::AudioPortConfig;
|
|
|
|
|
using aidl::android::media::audio::common::AudioPortExt;
|
|
|
|
|
using aidl::android::media::audio::common::AudioProfile;
|
2022-06-17 21:41:19 +00:00
|
|
|
using aidl::android::media::audio::common::AudioUsage;
|
2022-06-16 00:35:31 +00:00
|
|
|
using aidl::android::media::audio::common::Int;
|
2022-09-12 22:57:14 +00:00
|
|
|
using android::hardware::audio::common::isBitPositionFlagSet;
|
2021-11-16 01:31:03 +00:00
|
|
|
|
2022-06-17 21:41:19 +00:00
|
|
|
// static
|
|
|
|
|
std::optional<AudioOffloadInfo> ModuleConfig::generateOffloadInfoIfNeeded(
|
|
|
|
|
const AudioPortConfig& portConfig) {
|
|
|
|
|
if (portConfig.flags.has_value() &&
|
|
|
|
|
portConfig.flags.value().getTag() == AudioIoFlags::Tag::output &&
|
2022-09-12 22:57:14 +00:00
|
|
|
isBitPositionFlagSet(portConfig.flags.value().get<AudioIoFlags::Tag::output>(),
|
|
|
|
|
AudioOutputFlags::COMPRESS_OFFLOAD)) {
|
2022-06-17 21:41:19 +00:00
|
|
|
AudioOffloadInfo offloadInfo;
|
|
|
|
|
offloadInfo.base.sampleRate = portConfig.sampleRate.value().value;
|
|
|
|
|
offloadInfo.base.channelMask = portConfig.channelMask.value();
|
|
|
|
|
offloadInfo.base.format = portConfig.format.value();
|
|
|
|
|
offloadInfo.bitRatePerSecond = 256; // Arbitrary value.
|
|
|
|
|
offloadInfo.durationUs = std::chrono::microseconds(1min).count(); // Arbitrary value.
|
|
|
|
|
offloadInfo.usage = AudioUsage::MEDIA;
|
|
|
|
|
offloadInfo.encapsulationMode = AudioEncapsulationMode::NONE;
|
|
|
|
|
return offloadInfo;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 01:31:03 +00:00
|
|
|
template <typename T>
|
|
|
|
|
auto findById(const std::vector<T>& v, int32_t id) {
|
|
|
|
|
return std::find_if(v.begin(), v.end(), [&](const auto& p) { return p.id == id; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ModuleConfig::ModuleConfig(IModule* module) {
|
|
|
|
|
mStatus = module->getAudioPorts(&mPorts);
|
|
|
|
|
if (!mStatus.isOk()) return;
|
|
|
|
|
for (const auto& port : mPorts) {
|
|
|
|
|
if (port.ext.getTag() != AudioPortExt::Tag::device) continue;
|
|
|
|
|
const auto& devicePort = port.ext.get<AudioPortExt::Tag::device>();
|
|
|
|
|
if (devicePort.device.type.connection.empty()) {
|
2022-05-02 22:52:13 +00:00
|
|
|
const bool isInput = port.flags.getTag() == AudioIoFlags::Tag::input;
|
2021-11-16 01:31:03 +00:00
|
|
|
// Permanently attached device.
|
|
|
|
|
if (isInput) {
|
|
|
|
|
mAttachedSourceDevicePorts.insert(port.id);
|
|
|
|
|
} else {
|
|
|
|
|
mAttachedSinkDevicePorts.insert(port.id);
|
|
|
|
|
}
|
2022-05-02 22:52:13 +00:00
|
|
|
} else if (port.profiles.empty()) {
|
|
|
|
|
mExternalDevicePorts.insert(port.id);
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!mStatus.isOk()) return;
|
|
|
|
|
mStatus = module->getAudioRoutes(&mRoutes);
|
|
|
|
|
if (!mStatus.isOk()) return;
|
|
|
|
|
mStatus = module->getAudioPortConfigs(&mInitialConfigs);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 22:52:13 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getAttachedDevicePorts() const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [&](const auto& port) {
|
|
|
|
|
return mAttachedSinkDevicePorts.count(port.id) != 0 ||
|
|
|
|
|
mAttachedSourceDevicePorts.count(port.id) != 0;
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<AudioPort> ModuleConfig::getExternalDevicePorts() const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result),
|
|
|
|
|
[&](const auto& port) { return mExternalDevicePorts.count(port.id) != 0; });
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 01:31:03 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getInputMixPorts() const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [](const auto& port) {
|
|
|
|
|
return port.ext.getTag() == AudioPortExt::Tag::mix &&
|
|
|
|
|
port.flags.getTag() == AudioIoFlags::Tag::input;
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<AudioPort> ModuleConfig::getOutputMixPorts() const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
std::copy_if(mPorts.begin(), mPorts.end(), std::back_inserter(result), [](const auto& port) {
|
|
|
|
|
return port.ext.getTag() == AudioPortExt::Tag::mix &&
|
|
|
|
|
port.flags.getTag() == AudioIoFlags::Tag::output;
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 01:20:45 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getNonBlockingMixPorts(bool attachedOnly,
|
|
|
|
|
bool singlePort) const {
|
|
|
|
|
return findMixPorts(false /*isInput*/, singlePort, [&](const AudioPort& port) {
|
|
|
|
|
return isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::output>(),
|
|
|
|
|
AudioOutputFlags::NON_BLOCKING) &&
|
|
|
|
|
(!attachedOnly || !getAttachedSinkDevicesPortsForMixPort(port).empty());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 22:57:14 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getOffloadMixPorts(bool attachedOnly, bool singlePort) const {
|
2022-09-13 01:20:45 +00:00
|
|
|
return findMixPorts(false /*isInput*/, singlePort, [&](const AudioPort& port) {
|
|
|
|
|
return isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::output>(),
|
|
|
|
|
AudioOutputFlags::COMPRESS_OFFLOAD) &&
|
|
|
|
|
(!attachedOnly || !getAttachedSinkDevicesPortsForMixPort(port).empty());
|
|
|
|
|
});
|
2022-09-12 22:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-22 23:23:25 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getAttachedDevicesPortsForMixPort(
|
|
|
|
|
bool isInput, const AudioPortConfig& mixPortConfig) const {
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, mixPortConfig.portId);
|
|
|
|
|
if (mixPortIt != mPorts.end()) {
|
|
|
|
|
return getAttachedDevicesPortsForMixPort(isInput, *mixPortIt);
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-16 01:31:03 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::getAttachedSinkDevicesPortsForMixPort(
|
|
|
|
|
const AudioPort& mixPort) const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
if (mAttachedSinkDevicePorts.count(route.sinkPortId) != 0 &&
|
|
|
|
|
std::find(route.sourcePortIds.begin(), route.sourcePortIds.end(), mixPort.id) !=
|
|
|
|
|
route.sourcePortIds.end()) {
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId);
|
|
|
|
|
if (devicePortIt != mPorts.end()) result.push_back(*devicePortIt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<AudioPort> ModuleConfig::getAttachedSourceDevicesPortsForMixPort(
|
|
|
|
|
const AudioPort& mixPort) const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
if (route.sinkPortId == mixPort.id) {
|
|
|
|
|
for (const auto srcId : route.sourcePortIds) {
|
|
|
|
|
if (mAttachedSourceDevicePorts.count(srcId) != 0) {
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, srcId);
|
|
|
|
|
if (devicePortIt != mPorts.end()) result.push_back(*devicePortIt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<AudioPort> ModuleConfig::getSourceMixPortForAttachedDevice() const {
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
if (mAttachedSinkDevicePorts.count(route.sinkPortId) != 0) {
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, route.sourcePortIds[0]);
|
|
|
|
|
if (mixPortIt != mPorts.end()) return *mixPortIt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<ModuleConfig::SrcSinkPair> ModuleConfig::getNonRoutableSrcSinkPair(
|
|
|
|
|
bool isInput) const {
|
|
|
|
|
const auto mixPorts = getMixPorts(isInput);
|
|
|
|
|
std::set<std::pair<int32_t, int32_t>> allowedRoutes;
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
for (const auto srcPortId : route.sourcePortIds) {
|
|
|
|
|
allowedRoutes.emplace(std::make_pair(srcPortId, route.sinkPortId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
auto make_pair = [isInput](auto& device, auto& mix) {
|
|
|
|
|
return isInput ? std::make_pair(device, mix) : std::make_pair(mix, device);
|
|
|
|
|
};
|
|
|
|
|
for (const auto portId : isInput ? mAttachedSourceDevicePorts : mAttachedSinkDevicePorts) {
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, portId);
|
|
|
|
|
if (devicePortIt == mPorts.end()) continue;
|
|
|
|
|
auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt);
|
|
|
|
|
for (const auto& mixPort : mixPorts) {
|
|
|
|
|
if (std::find(allowedRoutes.begin(), allowedRoutes.end(),
|
|
|
|
|
make_pair(portId, mixPort.id)) == allowedRoutes.end()) {
|
|
|
|
|
auto mixPortConfig = getSingleConfigForMixPort(isInput, mixPort);
|
|
|
|
|
if (mixPortConfig.has_value()) {
|
|
|
|
|
return make_pair(devicePortConfig, mixPortConfig.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<ModuleConfig::SrcSinkPair> ModuleConfig::getRoutableSrcSinkPair(bool isInput) const {
|
|
|
|
|
if (isInput) {
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
auto srcPortIdIt = std::find_if(
|
|
|
|
|
route.sourcePortIds.begin(), route.sourcePortIds.end(),
|
|
|
|
|
[&](const auto& portId) { return mAttachedSourceDevicePorts.count(portId); });
|
|
|
|
|
if (srcPortIdIt == route.sourcePortIds.end()) continue;
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, *srcPortIdIt);
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, route.sinkPortId);
|
|
|
|
|
if (devicePortIt == mPorts.end() || mixPortIt == mPorts.end()) continue;
|
|
|
|
|
auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt);
|
|
|
|
|
auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt);
|
|
|
|
|
if (!mixPortConfig.has_value()) continue;
|
|
|
|
|
return std::make_pair(devicePortConfig, mixPortConfig.value());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
if (mAttachedSinkDevicePorts.count(route.sinkPortId) == 0) continue;
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, route.sourcePortIds[0]);
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId);
|
|
|
|
|
if (devicePortIt == mPorts.end() || mixPortIt == mPorts.end()) continue;
|
|
|
|
|
auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt);
|
|
|
|
|
auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt);
|
|
|
|
|
if (!mixPortConfig.has_value()) continue;
|
|
|
|
|
return std::make_pair(mixPortConfig.value(), devicePortConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<ModuleConfig::SrcSinkGroup> ModuleConfig::getRoutableSrcSinkGroups(bool isInput) const {
|
|
|
|
|
std::vector<SrcSinkGroup> result;
|
|
|
|
|
if (isInput) {
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
std::vector<int32_t> srcPortIds;
|
|
|
|
|
std::copy_if(route.sourcePortIds.begin(), route.sourcePortIds.end(),
|
|
|
|
|
std::back_inserter(srcPortIds), [&](const auto& portId) {
|
|
|
|
|
return mAttachedSourceDevicePorts.count(portId);
|
|
|
|
|
});
|
|
|
|
|
if (srcPortIds.empty()) continue;
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, route.sinkPortId);
|
|
|
|
|
if (mixPortIt == mPorts.end()) continue;
|
|
|
|
|
auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt);
|
|
|
|
|
if (!mixPortConfig.has_value()) continue;
|
|
|
|
|
std::vector<SrcSinkPair> pairs;
|
|
|
|
|
for (const auto srcPortId : srcPortIds) {
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, srcPortId);
|
|
|
|
|
if (devicePortIt == mPorts.end()) continue;
|
|
|
|
|
// Using all configs for every source would be too much.
|
|
|
|
|
auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt);
|
|
|
|
|
pairs.emplace_back(devicePortConfig, mixPortConfig.value());
|
|
|
|
|
}
|
|
|
|
|
if (!pairs.empty()) {
|
|
|
|
|
result.emplace_back(route, std::move(pairs));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (const auto& route : mRoutes) {
|
|
|
|
|
if (mAttachedSinkDevicePorts.count(route.sinkPortId) == 0) continue;
|
|
|
|
|
const auto devicePortIt = findById<AudioPort>(mPorts, route.sinkPortId);
|
|
|
|
|
if (devicePortIt == mPorts.end()) continue;
|
|
|
|
|
auto devicePortConfig = getSingleConfigForDevicePort(*devicePortIt);
|
|
|
|
|
std::vector<SrcSinkPair> pairs;
|
|
|
|
|
for (const auto srcPortId : route.sourcePortIds) {
|
|
|
|
|
const auto mixPortIt = findById<AudioPort>(mPorts, srcPortId);
|
|
|
|
|
if (mixPortIt == mPorts.end()) continue;
|
|
|
|
|
// Using all configs for every source would be too much.
|
|
|
|
|
auto mixPortConfig = getSingleConfigForMixPort(isInput, *mixPortIt);
|
|
|
|
|
if (mixPortConfig.has_value()) {
|
|
|
|
|
pairs.emplace_back(mixPortConfig.value(), devicePortConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!pairs.empty()) {
|
|
|
|
|
result.emplace_back(route, std::move(pairs));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 22:52:13 +00:00
|
|
|
std::string ModuleConfig::toString() const {
|
|
|
|
|
std::string result;
|
|
|
|
|
result.append("Ports: ");
|
|
|
|
|
result.append(android::internal::ToString(mPorts));
|
2022-06-17 21:36:18 +00:00
|
|
|
result.append("\nInitial configs: ");
|
2022-05-02 22:52:13 +00:00
|
|
|
result.append(android::internal::ToString(mInitialConfigs));
|
2022-06-17 21:36:18 +00:00
|
|
|
result.append("\nAttached sink device ports: ");
|
2022-05-02 22:52:13 +00:00
|
|
|
result.append(android::internal::ToString(mAttachedSinkDevicePorts));
|
2022-06-17 21:36:18 +00:00
|
|
|
result.append("\nAttached source device ports: ");
|
2022-05-02 22:52:13 +00:00
|
|
|
result.append(android::internal::ToString(mAttachedSourceDevicePorts));
|
2022-06-17 21:36:18 +00:00
|
|
|
result.append("\nExternal device ports: ");
|
2022-05-02 22:52:13 +00:00
|
|
|
result.append(android::internal::ToString(mExternalDevicePorts));
|
2022-06-17 21:36:18 +00:00
|
|
|
result.append("\nRoutes: ");
|
2022-05-02 22:52:13 +00:00
|
|
|
result.append(android::internal::ToString(mRoutes));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 21:41:19 +00:00
|
|
|
static size_t combineAudioConfigs(const AudioPort& port, const AudioProfile& profile,
|
|
|
|
|
std::vector<AudioPortConfig>* result) {
|
|
|
|
|
const size_t newConfigCount = profile.channelMasks.size() * profile.sampleRates.size();
|
|
|
|
|
result->reserve(result->capacity() + newConfigCount);
|
2021-11-16 01:31:03 +00:00
|
|
|
for (auto channelMask : profile.channelMasks) {
|
|
|
|
|
for (auto sampleRate : profile.sampleRates) {
|
|
|
|
|
AudioPortConfig config{};
|
|
|
|
|
config.portId = port.id;
|
|
|
|
|
Int sr;
|
|
|
|
|
sr.value = sampleRate;
|
|
|
|
|
config.sampleRate = sr;
|
|
|
|
|
config.channelMask = channelMask;
|
|
|
|
|
config.format = profile.format;
|
2022-06-17 21:41:19 +00:00
|
|
|
config.flags = port.flags;
|
2021-11-16 01:31:03 +00:00
|
|
|
config.ext = port.ext;
|
2022-06-17 21:41:19 +00:00
|
|
|
result->push_back(std::move(config));
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2022-06-17 21:41:19 +00:00
|
|
|
return newConfigCount;
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-17 21:41:19 +00:00
|
|
|
static bool isDynamicProfile(const AudioProfile& profile) {
|
|
|
|
|
return (profile.format.type == AudioFormatType::DEFAULT && profile.format.encoding.empty()) ||
|
|
|
|
|
profile.sampleRates.empty() || profile.channelMasks.empty();
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-13 01:20:45 +00:00
|
|
|
std::vector<AudioPort> ModuleConfig::findMixPorts(
|
|
|
|
|
bool isInput, bool singlePort, std::function<bool(const AudioPort&)> pred) const {
|
|
|
|
|
std::vector<AudioPort> result;
|
|
|
|
|
const auto mixPorts = getMixPorts(isInput);
|
|
|
|
|
for (auto mixPortIt = mixPorts.begin(); mixPortIt != mixPorts.end();) {
|
|
|
|
|
mixPortIt = std::find_if(mixPortIt, mixPorts.end(), pred);
|
|
|
|
|
if (mixPortIt == mixPorts.end()) break;
|
|
|
|
|
result.push_back(*mixPortIt++);
|
|
|
|
|
if (singlePort) break;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 21:41:19 +00:00
|
|
|
std::vector<AudioPortConfig> ModuleConfig::generateAudioMixPortConfigs(
|
|
|
|
|
const std::vector<AudioPort>& ports, bool isInput, bool singleProfile) const {
|
2021-11-16 01:31:03 +00:00
|
|
|
std::vector<AudioPortConfig> result;
|
|
|
|
|
for (const auto& mixPort : ports) {
|
2022-06-17 21:41:19 +00:00
|
|
|
if (getAttachedDevicesPortsForMixPort(isInput, mixPort).empty()) {
|
|
|
|
|
continue;
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
for (const auto& profile : mixPort.profiles) {
|
2022-06-17 21:41:19 +00:00
|
|
|
if (isDynamicProfile(profile)) continue;
|
|
|
|
|
combineAudioConfigs(mixPort, profile, &result);
|
|
|
|
|
if (singleProfile && !result.empty()) {
|
|
|
|
|
result.resize(1);
|
|
|
|
|
return result;
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<AudioPortConfig> ModuleConfig::generateAudioDevicePortConfigs(
|
|
|
|
|
const std::vector<AudioPort>& ports, bool singleProfile) const {
|
|
|
|
|
std::vector<AudioPortConfig> result;
|
|
|
|
|
for (const auto& devicePort : ports) {
|
|
|
|
|
const size_t resultSizeBefore = result.size();
|
|
|
|
|
for (const auto& profile : devicePort.profiles) {
|
2022-06-17 21:41:19 +00:00
|
|
|
combineAudioConfigs(devicePort, profile, &result);
|
|
|
|
|
if (singleProfile && !result.empty()) {
|
|
|
|
|
result.resize(1);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
if (resultSizeBefore == result.size()) {
|
2022-05-02 22:52:13 +00:00
|
|
|
std::copy_if(mInitialConfigs.begin(), mInitialConfigs.end(), std::back_inserter(result),
|
|
|
|
|
[&](const auto& config) { return config.portId == devicePort.id; });
|
|
|
|
|
if (resultSizeBefore == result.size()) {
|
|
|
|
|
AudioPortConfig empty;
|
|
|
|
|
empty.portId = devicePort.id;
|
|
|
|
|
empty.ext = devicePort.ext;
|
|
|
|
|
result.push_back(empty);
|
|
|
|
|
}
|
2021-11-16 01:31:03 +00:00
|
|
|
}
|
|
|
|
|
if (singleProfile) return result;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|