Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 04b2cdba authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

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
parent 17894fc6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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 ||
+20 −4
Original line number Diff line number Diff line
@@ -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);
    }
+3 −1
Original line number Diff line number Diff line
@@ -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;