audio: Add some utility methods, improve logging

Add 'isDefaultAudioFormat' to Utils.h.

Print the module type in 'setModuleDebug'.

Align 'suggestDeviceAddressTag' with framework code.

Bug: 273252382
Test: m
Change-Id: I0248d2e866522a63a745d4af6132b7d2b6a01564
This commit is contained in:
Mikhail Naganov
2023-03-24 18:27:58 -07:00
parent 17894fc62b
commit 04b2cdba73
3 changed files with 29 additions and 5 deletions

View File

@@ -99,6 +99,12 @@ constexpr size_t getFrameSizeInBytes(
return 0;
}
constexpr bool isDefaultAudioFormat(
const ::aidl::android::media::audio::common::AudioFormatDescription& desc) {
return desc.type == ::aidl::android::media::audio::common::AudioFormatType::DEFAULT &&
desc.pcm == ::aidl::android::media::audio::common::PcmType::DEFAULT;
}
constexpr bool isTelephonyDeviceType(
::aidl::android::media::audio::common::AudioDeviceType device) {
return device == ::aidl::android::media::audio::common::AudioDeviceType::IN_TELEPHONY_RX ||

View File

@@ -143,6 +143,21 @@ StreamOut::CreateInstance Module::getStreamOutCreator(Type type) {
}
}
std::ostream& operator<<(std::ostream& os, Module::Type t) {
switch (t) {
case Module::Type::DEFAULT:
os << "default";
break;
case Module::Type::R_SUBMIX:
os << "r_submix";
break;
case Module::Type::USB:
os << "usb";
break;
}
return os;
}
void Module::cleanUpPatch(int32_t patchId) {
erase_all_values(mPatches, std::set<int32_t>{patchId});
}
@@ -352,16 +367,17 @@ void Module::updateStreamsConnectedState(const AudioPatch& oldPatch, const Audio
ndk::ScopedAStatus Module::setModuleDebug(
const ::aidl::android::hardware::audio::core::ModuleDebug& in_debug) {
LOG(DEBUG) << __func__ << ": old flags:" << mDebug.toString()
LOG(DEBUG) << __func__ << ": " << mType << ": old flags:" << mDebug.toString()
<< ", new flags: " << in_debug.toString();
if (mDebug.simulateDeviceConnections != in_debug.simulateDeviceConnections &&
!mConnectedDevicePorts.empty()) {
LOG(ERROR) << __func__ << ": attempting to change device connections simulation "
<< "while having external devices connected";
LOG(ERROR) << __func__ << ": " << mType
<< ": attempting to change device connections simulation while having external "
<< "devices connected";
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
}
if (in_debug.streamTransientStateDelayMs < 0) {
LOG(ERROR) << __func__ << ": streamTransientStateDelayMs is negative: "
LOG(ERROR) << __func__ << ": " << mType << ": streamTransientStateDelayMs is negative: "
<< in_debug.streamTransientStateDelayMs;
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}

View File

@@ -129,7 +129,9 @@ AudioDeviceAddress::Tag suggestDeviceAddressTag(const AudioDeviceDescription& de
using Tag = AudioDeviceAddress::Tag;
if (std::string_view connection = description.connection;
connection == AudioDeviceDescription::CONNECTION_BT_A2DP ||
connection == AudioDeviceDescription::CONNECTION_BT_LE ||
// Note: BT LE Broadcast uses a "group id".
(description.type != AudioDeviceType::OUT_BROADCAST &&
connection == AudioDeviceDescription::CONNECTION_BT_LE) ||
connection == AudioDeviceDescription::CONNECTION_BT_SCO ||
connection == AudioDeviceDescription::CONNECTION_WIRELESS) {
return Tag::mac;