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

Commit 59df2f67 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

aosp aidl bluetooth audio hal implementation

Bug: 228804498
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Id5fb60fe53ead9f5d2e6ecbb9988a23835cf2509
(cherry picked from commit b03b5c4a)
Merged-In: Id5fb60fe53ead9f5d2e6ecbb9988a23835cf2509
parent 4bb14a9c
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",
    ],
+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
+9 −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;
}
+5 −0
Original line number Diff line number Diff line
@@ -19,6 +19,11 @@
    <version>1</version>
    <fqname>IModule/usb</fqname>
  </hal>
  <hal format="aidl">
    <name>android.hardware.audio.core</name>
    <version>1</version>
    <fqname>IModule/bluetooth</fqname>
  </hal>
  <hal format="aidl">
    <name>android.hardware.audio.core</name>
    <version>1</version>
+562 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading