1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <aidl/android/hardware/bluetooth/audio/BnBluetoothAudioProvider.h> 19 #include <aidl/android/hardware/bluetooth/audio/LatencyMode.h> 20 #include <aidl/android/hardware/bluetooth/audio/SessionType.h> 21 #include <fmq/AidlMessageQueue.h> 22 23 using ::aidl::android::hardware::common::fmq::MQDescriptor; 24 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite; 25 using ::android::AidlMessageQueue; 26 27 using MqDataType = int8_t; 28 using MqDataMode = SynchronizedReadWrite; 29 using DataMQ = AidlMessageQueue<MqDataType, MqDataMode>; 30 using DataMQDesc = MQDescriptor<MqDataType, MqDataMode>; 31 32 namespace aidl { 33 namespace android { 34 namespace hardware { 35 namespace bluetooth { 36 namespace audio { 37 38 /// Enable flag for the reference implementation for A2dp Codec 39 /// Extensibility. 40 /// 41 /// A2dp Codec extensibility cannot be enabled until the following 42 /// requirements are fulfilled. 43 /// 44 /// 1. The Bluetooth controller must support the HCI Requirements 45 /// v1.04 or later, and must support the vendor HCI command 46 /// A2DP Offload Start (v2), A2DP Offload Stop (v2) as indicated 47 /// by the field a2dp_offload_v2 of the vendor capabilities. 48 /// 49 /// 2. The implementation of the provider must be completed with 50 /// DSP configuration for streaming. 51 enum : bool { 52 kEnableA2dpCodecExtensibility = false, 53 }; 54 55 class BluetoothAudioProvider : public BnBluetoothAudioProvider { 56 public: 57 BluetoothAudioProvider(); 58 ndk::ScopedAStatus startSession( 59 const std::shared_ptr<IBluetoothAudioPort>& host_if, 60 const AudioConfiguration& audio_config, 61 const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return); 62 ndk::ScopedAStatus endSession(); 63 ndk::ScopedAStatus streamStarted(BluetoothAudioStatus status); 64 ndk::ScopedAStatus streamSuspended(BluetoothAudioStatus status); 65 ndk::ScopedAStatus updateAudioConfiguration( 66 const AudioConfiguration& audio_config); 67 ndk::ScopedAStatus setLowLatencyModeAllowed(bool allowed); 68 ndk::ScopedAStatus setCodecPriority( 69 const ::aidl::android::hardware::bluetooth::audio::CodecId& in_codecId, 70 int32_t in_priority) override; 71 ndk::ScopedAStatus getLeAudioAseConfiguration( 72 const std::optional<std::vector<std::optional< 73 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 74 LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities, 75 const std::optional<std::vector<std::optional< 76 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 77 LeAudioDeviceCapabilities>>>& in_remoteSourceAudioCapabilities, 78 const std::vector< 79 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 80 LeAudioConfigurationRequirement>& in_requirements, 81 std::vector<::aidl::android::hardware::bluetooth::audio:: 82 IBluetoothAudioProvider::LeAudioAseConfigurationSetting>* 83 _aidl_return) override; 84 ndk::ScopedAStatus getLeAudioAseQosConfiguration( 85 const ::aidl::android::hardware::bluetooth::audio:: 86 IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement& 87 in_qosRequirement, 88 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 89 LeAudioAseQosConfigurationPair* _aidl_return) override; 90 ndk::ScopedAStatus getLeAudioAseDatapathConfiguration( 91 const std::optional<::aidl::android::hardware::bluetooth::audio:: 92 IBluetoothAudioProvider::StreamConfig>& 93 in_sinkConfig, 94 const std::optional<::aidl::android::hardware::bluetooth::audio:: 95 IBluetoothAudioProvider::StreamConfig>& 96 in_sourceConfig, 97 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 98 LeAudioDataPathConfigurationPair* _aidl_return) override; 99 ndk::ScopedAStatus onSinkAseMetadataChanged( 100 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 101 AseState in_state, 102 int32_t cigId, int32_t cisId, 103 const std::optional<std::vector<std::optional< 104 ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>& 105 in_metadata) override; 106 ndk::ScopedAStatus onSourceAseMetadataChanged( 107 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 108 AseState in_state, 109 int32_t cigId, int32_t cisId, 110 const std::optional<std::vector<std::optional< 111 ::aidl::android::hardware::bluetooth::audio::MetadataLtv>>>& 112 in_metadata) override; 113 ndk::ScopedAStatus getLeAudioBroadcastConfiguration( 114 const std::optional<std::vector<std::optional< 115 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 116 LeAudioDeviceCapabilities>>>& in_remoteSinkAudioCapabilities, 117 const ::aidl::android::hardware::bluetooth::audio:: 118 IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement& 119 in_requirement, 120 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 121 LeAudioBroadcastConfigurationSetting* _aidl_return) override; 122 ndk::ScopedAStatus getLeAudioBroadcastDatapathConfiguration( 123 const ::aidl::android::hardware::bluetooth::audio::AudioContext& 124 in_context, 125 const std::vector<::aidl::android::hardware::bluetooth::audio:: 126 LeAudioBroadcastConfiguration::BroadcastStreamMap>& 127 in_streamMap, 128 ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider:: 129 LeAudioDataPathConfiguration* _aidl_return) override; 130 131 ndk::ScopedAStatus parseA2dpConfiguration( 132 const CodecId& codec_id, const std::vector<uint8_t>& configuration, 133 CodecParameters* codec_parameters, A2dpStatus* _aidl_return); 134 ndk::ScopedAStatus getA2dpConfiguration( 135 const std::vector<A2dpRemoteCapabilities>& remote_a2dp_capabilities, 136 const A2dpConfigurationHint& hint, 137 std::optional<audio::A2dpConfiguration>* _aidl_return); 138 139 virtual bool isValid(const SessionType& sessionType) = 0; 140 141 protected: 142 virtual ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) = 0; 143 144 ::ndk::ScopedAIBinder_DeathRecipient death_recipient_; 145 146 std::shared_ptr<IBluetoothAudioPort> stack_iface_; 147 std::unique_ptr<AudioConfiguration> audio_config_ = nullptr; 148 SessionType session_type_; 149 std::vector<LatencyMode> latency_modes_; 150 }; 151 } // namespace audio 152 } // namespace bluetooth 153 } // namespace hardware 154 } // namespace android 155 } // namespace aidl 156