audio: Populate MicrophoneInfo with vendor data

Added a virtual method Module::getMicrophoneInfos
so that vendor implementations can provide actual
data about device microphones. This information
is not part of the APM config file.

Bug: 205884982
Test: atest VtsHalAudioCoreTargetTestTest
(cherry picked from commit dc9d1a4b42)
Change-Id: I3ea9ba8da79fd29f8d69c5a575a57851d73df7b8
This commit is contained in:
Lorena Torres-Huerta 2023-01-18 00:11:48 +00:00 committed by Mikhail Naganov
parent cc21b6f2e6
commit 533cc78aab
3 changed files with 27 additions and 11 deletions

View file

@ -41,7 +41,6 @@ using aidl::android::media::audio::common::AudioPortExt;
using aidl::android::media::audio::common::AudioPortMixExt;
using aidl::android::media::audio::common::AudioProfile;
using aidl::android::media::audio::common::Int;
using aidl::android::media::audio::common::MicrophoneInfo;
using aidl::android::media::audio::common::PcmType;
using Configuration = aidl::android::hardware::audio::core::Module::Configuration;
@ -274,13 +273,6 @@ std::unique_ptr<Configuration> getPrimaryConfiguration() {
c.portConfigs.insert(c.portConfigs.end(), c.initialConfigs.begin(), c.initialConfigs.end());
MicrophoneInfo mic;
mic.id = "mic";
mic.device = micInDevice.ext.get<AudioPortExt::Tag::device>().device;
mic.group = 0;
mic.indexInTheGroup = 0;
c.microphones = std::vector<MicrophoneInfo>{mic};
return c;
}();
return std::make_unique<Configuration>(configuration);

View file

@ -43,6 +43,7 @@ using aidl::android::hardware::audio::common::SourceMetadata;
using aidl::android::hardware::audio::core::sounddose::ISoundDose;
using aidl::android::media::audio::common::AudioChannelLayout;
using aidl::android::media::audio::common::AudioDevice;
using aidl::android::media::audio::common::AudioDeviceType;
using aidl::android::media::audio::common::AudioFormatDescription;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioInputFlags;
@ -795,7 +796,7 @@ ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_ar
context.fillDescriptor(&_aidl_return->desc);
std::shared_ptr<StreamIn> stream;
RETURN_STATUS_IF_ERROR(createInputStream(std::move(context), in_args.sinkMetadata,
getConfig().microphones, &stream));
getMicrophoneInfos(), &stream));
StreamWrapper streamWrapper(stream);
if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
RETURN_STATUS_IF_ERROR(
@ -1229,7 +1230,7 @@ ndk::ScopedAStatus Module::setMicMute(bool in_mute) {
}
ndk::ScopedAStatus Module::getMicrophones(std::vector<MicrophoneInfo>* _aidl_return) {
*_aidl_return = getConfig().microphones;
*_aidl_return = getMicrophoneInfos();
LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
return ndk::ScopedAStatus::ok();
}
@ -1508,6 +1509,29 @@ ndk::ScopedAStatus Module::onMasterVolumeChanged(float volume __unused) {
return ndk::ScopedAStatus::ok();
}
std::vector<MicrophoneInfo> Module::getMicrophoneInfos() {
std::vector<MicrophoneInfo> result;
Configuration& config = getConfig();
for (const AudioPort& port : config.ports) {
if (port.ext.getTag() == AudioPortExt::Tag::device) {
const AudioDeviceType deviceType =
port.ext.get<AudioPortExt::Tag::device>().device.type.type;
if (deviceType == AudioDeviceType::IN_MICROPHONE ||
deviceType == AudioDeviceType::IN_MICROPHONE_BACK) {
// Placeholder values. Vendor implementations must populate MicrophoneInfo
// accordingly based on their physical microphone parameters.
result.push_back(MicrophoneInfo{
.id = port.name,
.device = port.ext.get<AudioPortExt::Tag::device>().device,
.group = 0,
.indexInTheGroup = 0,
});
}
}
}
return result;
}
Module::BtProfileHandles Module::getBtProfileManagerHandles() {
return std::make_tuple(std::weak_ptr<IBluetooth>(), std::weak_ptr<IBluetoothA2dp>(),
std::weak_ptr<IBluetoothLe>());

View file

@ -32,7 +32,6 @@ namespace aidl::android::hardware::audio::core {
class Module : public BnModule {
public:
struct Configuration {
std::vector<::aidl::android::media::audio::common::MicrophoneInfo> microphones;
std::vector<::aidl::android::media::audio::common::AudioPort> ports;
std::vector<::aidl::android::media::audio::common::AudioPortConfig> portConfigs;
std::vector<::aidl::android::media::audio::common::AudioPortConfig> initialConfigs;
@ -207,6 +206,7 @@ class Module : public BnModule {
const ::aidl::android::media::audio::common::AudioPort& audioPort, bool connected);
virtual ndk::ScopedAStatus onMasterMuteChanged(bool mute);
virtual ndk::ScopedAStatus onMasterVolumeChanged(float volume);
virtual std::vector<::aidl::android::media::audio::common::MicrophoneInfo> getMicrophoneInfos();
virtual std::unique_ptr<Configuration> initializeConfig();
// Utility and helper functions accessible to subclasses.