From f7492518c76e946d40a5948b52163fb14bcf6a7a Mon Sep 17 00:00:00 2001 From: Lorena Torres-Huerta Date: Sat, 14 Jan 2023 02:49:41 +0000 Subject: [PATCH] audio: Set connectedProfiles for non-attached device ports. For external (non-attached) device ports that have dynamic profiles, 'connectedProfiles' must be provided. They are used when 'ModuleDebug.simulateDeviceConnections' is enabled. Bug: 205884982 Test: atest VtsHalAudioCoreTargetTest (cherry picked from commit a29393db39b35a4d6b819deef0861fc6fab048c5) Change-Id: I69707d610c34f8f1eae9ef81768b76c40e985c0f --- audio/aidl/default/Configuration.cpp | 16 ++++++++++++++ audio/aidl/default/Module.cpp | 21 +++++++++++++++++++ .../default/include/core-impl/Configuration.h | 2 ++ audio/aidl/default/include/core-impl/Module.h | 4 ++-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/audio/aidl/default/Configuration.cpp b/audio/aidl/default/Configuration.cpp index cf5f066c7c..d09552b3c0 100644 --- a/audio/aidl/default/Configuration.cpp +++ b/audio/aidl/default/Configuration.cpp @@ -135,6 +135,22 @@ static AudioRoute createRoute(const std::vector& sources, const Audio return route; } +std::vector getStandard16And24BitPcmAudioProfiles() { + auto createStdPcmAudioProfile = [](const PcmType& pcmType) { + return AudioProfile{ + .format = AudioFormatDescription{.type = AudioFormatType::PCM, .pcm = pcmType}, + .channelMasks = {AudioChannelLayout::make( + AudioChannelLayout::LAYOUT_MONO), + AudioChannelLayout::make( + AudioChannelLayout::LAYOUT_STEREO)}, + .sampleRates = {8000, 11025, 16000, 32000, 44100, 48000}}; + }; + return { + createStdPcmAudioProfile(PcmType::INT_16_BIT), + createStdPcmAudioProfile(PcmType::INT_24_BIT), + }; +} + // Primary (default) configuration: // // Device ports: diff --git a/audio/aidl/default/Module.cpp b/audio/aidl/default/Module.cpp index cad239f161..10450099e1 100644 --- a/audio/aidl/default/Module.cpp +++ b/audio/aidl/default/Module.cpp @@ -185,6 +185,11 @@ std::ostream& operator<<(std::ostream& os, Module::Type t) { return os; } +Module::Module(Type type, std::unique_ptr&& config) + : mType(type), mConfig(std::move(config)) { + populateConnectedProfiles(); +} + void Module::cleanUpPatch(int32_t patchId) { erase_all_values(mPatches, std::set{patchId}); } @@ -320,6 +325,22 @@ ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, Audio return ndk::ScopedAStatus::ok(); } +void Module::populateConnectedProfiles() { + Configuration& config = getConfig(); + for (const AudioPort& port : config.ports) { + if (port.ext.getTag() == AudioPortExt::device) { + if (auto devicePort = port.ext.get(); + !devicePort.device.type.connection.empty() && port.profiles.empty()) { + if (auto connIt = config.connectedProfiles.find(port.id); + connIt == config.connectedProfiles.end()) { + config.connectedProfiles.emplace( + port.id, internal::getStandard16And24BitPcmAudioProfiles()); + } + } + } + } +} + template std::set Module::portIdsFromPortConfigIds(C portConfigIds) { std::set result; diff --git a/audio/aidl/default/include/core-impl/Configuration.h b/audio/aidl/default/include/core-impl/Configuration.h index aa7b9fff97..a56c8c9f98 100644 --- a/audio/aidl/default/include/core-impl/Configuration.h +++ b/audio/aidl/default/include/core-impl/Configuration.h @@ -23,5 +23,7 @@ namespace aidl::android::hardware::audio::core::internal { std::unique_ptr getConfiguration(Module::Type moduleType); +std::vector +getStandard16And24BitPcmAudioProfiles(); } // namespace aidl::android::hardware::audio::core::internal diff --git a/audio/aidl/default/include/core-impl/Module.h b/audio/aidl/default/include/core-impl/Module.h index bc5c5781db..718c07d973 100644 --- a/audio/aidl/default/include/core-impl/Module.h +++ b/audio/aidl/default/include/core-impl/Module.h @@ -60,8 +60,7 @@ class Module : public BnModule { std::unique_ptr&& config); static std::optional typeFromString(const std::string& type); - Module(Type type, std::unique_ptr&& config) - : mType(type), mConfig(std::move(config)) {} + Module(Type type, std::unique_ptr&& config); protected: // The vendor extension done via inheritance can override interface methods and augment @@ -235,6 +234,7 @@ class Module : public BnModule { const Streams& getStreams() const { return mStreams; } Type getType() const { return mType; } bool isMmapSupported(); + void populateConnectedProfiles(); template std::set portIdsFromPortConfigIds(C portConfigIds); void registerPatch(const AudioPatch& patch);