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

Commit 169be347 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "bluetoothmodule" into main

* changes:
  aosp aidl bluetooth parameter support
  aosp aidl bluetooth audio hal implementation
parents acd4a677 18f0d512
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ cc_library {
        "alsa/ModuleAlsa.cpp",
        "alsa/StreamAlsa.cpp",
        "alsa/Utils.cpp",
        "bluetooth/DevicePortProxy.cpp",
        "bluetooth/ModuleBluetooth.cpp",
        "bluetooth/StreamBluetooth.cpp",
        "r_submix/ModuleRemoteSubmix.cpp",
        "r_submix/RemoteSubmixUtils.cpp",
        "r_submix/SubmixRoute.cpp",
@@ -105,7 +108,9 @@ cc_library {
        "audio_policy_engine_configuration_aidl_default",
    ],
    shared_libs: [
        "android.hardware.bluetooth.audio-V3-ndk",
        "libaudio_aidl_conversion_common_ndk",
        "libbluetooth_audio_session_aidl",
        "libmedia_helper",
        "libstagefright_foundation",
    ],
@@ -136,7 +141,9 @@ cc_binary {
        "libaudioserviceexampleimpl",
    ],
    shared_libs: [
        "android.hardware.bluetooth.audio-V3-ndk",
        "libaudio_aidl_conversion_common_ndk",
        "libbluetooth_audio_session_aidl",
        "libmedia_helper",
        "libstagefright_foundation",
    ],
+6 −9
Original line number Diff line number Diff line
@@ -82,19 +82,18 @@ ndk::ScopedAStatus Bluetooth::setHfpConfig(const HfpConfig& in_config, HfpConfig

ndk::ScopedAStatus BluetoothA2dp::isEnabled(bool* _aidl_return) {
    *_aidl_return = mEnabled;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus BluetoothA2dp::setEnabled(bool in_enabled) {
    mEnabled = in_enabled;
    LOG(DEBUG) << __func__ << ": " << mEnabled;
    if (mHandler) return mHandler();
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus BluetoothA2dp::supportsOffloadReconfiguration(bool* _aidl_return) {
    *_aidl_return = true;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    *_aidl_return = false;
    return ndk::ScopedAStatus::ok();
}

@@ -102,24 +101,22 @@ ndk::ScopedAStatus BluetoothA2dp::reconfigureOffload(
        const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters
                __unused) {
    LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters);
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}

ndk::ScopedAStatus BluetoothLe::isEnabled(bool* _aidl_return) {
    *_aidl_return = mEnabled;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus BluetoothLe::setEnabled(bool in_enabled) {
    mEnabled = in_enabled;
    LOG(DEBUG) << __func__ << ": " << mEnabled;
    if (mHandler) return mHandler();
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus BluetoothLe::supportsOffloadReconfiguration(bool* _aidl_return) {
    *_aidl_return = true;
    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
    *_aidl_return = false;
    return ndk::ScopedAStatus::ok();
}

@@ -127,7 +124,7 @@ ndk::ScopedAStatus BluetoothLe::reconfigureOffload(
        const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters
                __unused) {
    LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters);
    return ndk::ScopedAStatus::ok();
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}

}  // namespace aidl::android::hardware::audio::core
+82 −0
Original line number Diff line number Diff line
@@ -561,4 +561,86 @@ std::unique_ptr<Configuration> getStubConfiguration() {
    return std::make_unique<Configuration>(configuration);
}

// Bluetooth configuration:
//
// Device ports:
//  * "BT A2DP Out", OUT_DEVICE, CONNECTION_BT_A2DP
//    - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000
//  * "BT A2DP Headphones", OUT_HEADSET, CONNECTION_BT_A2DP
//    - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000
//  * "BT A2DP Speaker", OUT_SPEAKER, CONNECTION_BT_A2DP
//    - profile PCM 16-bit; STEREO; 44100, 48000, 88200, 96000
//  * "BT Hearing Aid Out", OUT_HEARING_AID, CONNECTION_WIRELESS
//    - no profiles specified
//
// Mix ports:
//  * "a2dp output", 1 max open, 1 max active stream
//    - no profiles specified
//  * "hearing aid output", 1 max open, 1 max active stream
//    - profile PCM 16-bit; STEREO; 16000, 24000
//
// Routes:
//  "a2dp output" -> "BT A2DP Out"
//  "a2dp output" -> "BT A2DP Headphones"
//  "a2dp output" -> "BT A2DP Speaker"
//  "hearing aid output" -> "BT Hearing Aid Out"
//
std::unique_ptr<Configuration> getBluetoothConfiguration() {
    static const Configuration configuration = []() {
        const std::vector<AudioProfile> standardPcmAudioProfiles = {
                createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO},
                              {44100, 48000, 88200, 96000})};
        Configuration c;

        // Device ports
        AudioPort btOutDevice =
                createPort(c.nextPortId++, "BT A2DP Out", 0, false,
                           createDeviceExt(AudioDeviceType::OUT_DEVICE, 0,
                                           AudioDeviceDescription::CONNECTION_BT_A2DP));
        c.ports.push_back(btOutDevice);
        c.connectedProfiles[btOutDevice.id] = standardPcmAudioProfiles;

        AudioPort btOutHeadphone =
                createPort(c.nextPortId++, "BT A2DP Headphones", 0, false,
                           createDeviceExt(AudioDeviceType::OUT_HEADSET, 0,
                                           AudioDeviceDescription::CONNECTION_BT_A2DP));
        c.ports.push_back(btOutHeadphone);
        c.connectedProfiles[btOutHeadphone.id] = standardPcmAudioProfiles;

        AudioPort btOutSpeaker =
                createPort(c.nextPortId++, "BT A2DP Speaker", 0, false,
                           createDeviceExt(AudioDeviceType::OUT_SPEAKER, 0,
                                           AudioDeviceDescription::CONNECTION_BT_A2DP));
        c.ports.push_back(btOutSpeaker);
        c.connectedProfiles[btOutSpeaker.id] = standardPcmAudioProfiles;

        AudioPort btOutHearingAid =
                createPort(c.nextPortId++, "BT Hearing Aid Out", 0, false,
                           createDeviceExt(AudioDeviceType::OUT_HEARING_AID, 0,
                                           AudioDeviceDescription::CONNECTION_WIRELESS));
        c.ports.push_back(btOutHearingAid);
        c.connectedProfiles[btOutHearingAid.id] = std::vector<AudioProfile>(
                {createProfile(PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000})});

        // Mix ports
        AudioPort btInMix =
                createPort(c.nextPortId++, "a2dp output", 0, true, createPortMixExt(1, 1));
        c.ports.push_back(btInMix);

        AudioPort btHeadsetInMix =
                createPort(c.nextPortId++, "hearing aid output", 0, true, createPortMixExt(1, 1));
        btHeadsetInMix.profiles.push_back(createProfile(
                PcmType::INT_16_BIT, {AudioChannelLayout::LAYOUT_STEREO}, {16000, 24000}));
        c.ports.push_back(btHeadsetInMix);

        c.routes.push_back(createRoute({btInMix}, btOutDevice));
        c.routes.push_back(createRoute({btInMix}, btOutHeadphone));
        c.routes.push_back(createRoute({btInMix}, btOutSpeaker));
        c.routes.push_back(createRoute({btHeadsetInMix}, btOutHearingAid));

        return c;
    }();
    return std::make_unique<Configuration>(configuration);
}

}  // namespace aidl::android::hardware::audio::core::internal
+18 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <error/expected_utils.h>

#include "core-impl/Module.h"
#include "core-impl/ModuleBluetooth.h"
#include "core-impl/ModulePrimary.h"
#include "core-impl/ModuleRemoteSubmix.h"
#include "core-impl/ModuleStub.h"
@@ -117,6 +118,8 @@ std::shared_ptr<Module> Module::createInstance(Type type) {
            return ndk::SharedRefBase::make<ModuleStub>();
        case Type::USB:
            return ndk::SharedRefBase::make<ModuleUsb>();
        case Type::BLUETOOTH:
            return ndk::SharedRefBase::make<ModuleBluetooth>();
    }
}

@@ -134,6 +137,9 @@ std::ostream& operator<<(std::ostream& os, Module::Type t) {
        case Module::Type::USB:
            os << "usb";
            break;
        case Module::Type::BLUETOOTH:
            os << "bluetooth";
            break;
    }
    return os;
}
@@ -301,6 +307,9 @@ std::unique_ptr<internal::Configuration> Module::initializeConfig() {
        case Type::USB:
            config = std::move(internal::getUsbConfiguration());
            break;
        case Type::BLUETOOTH:
            config = std::move(internal::getBluetoothConfiguration());
            break;
    }
    return config;
}
@@ -1362,4 +1371,13 @@ ndk::ScopedAStatus Module::onMasterVolumeChanged(float volume __unused) {
    return ndk::ScopedAStatus::ok();
}

Module::BtProfileHandles Module::getBtProfileManagerHandles() {
    return std::make_tuple(std::weak_ptr<IBluetooth>(), std::weak_ptr<IBluetoothA2dp>(),
                           std::weak_ptr<IBluetoothLe>());
}

ndk::ScopedAStatus Module::bluetoothParametersUpdated() {
    return mStreams.bluetoothParametersUpdated();
}

}  // namespace aidl::android::hardware::audio::core
+5 −0
Original line number Diff line number Diff line
@@ -723,6 +723,11 @@ ndk::ScopedAStatus StreamCommonImpl::setConnectedDevices(
    return ndk::ScopedAStatus::ok();
}

ndk::ScopedAStatus StreamCommonImpl::bluetoothParametersUpdated() {
    LOG(DEBUG) << __func__;
    return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
}

namespace {
static std::map<AudioDevice, std::string> transformMicrophones(
        const std::vector<MicrophoneInfo>& microphones) {
Loading