Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 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 | |
| 17 | #pragma once |
| 18 | |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 19 | #include <map> |
| 20 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 21 | #include "BluetoothAudioProvider.h" |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 22 | #include "aidl/android/hardware/bluetooth/audio/LeAudioAseConfiguration.h" |
| 23 | #include "aidl/android/hardware/bluetooth/audio/MetadataLtv.h" |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 24 | #include "aidl/android/hardware/bluetooth/audio/SessionType.h" |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 25 | |
| 26 | namespace aidl { |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace bluetooth { |
| 30 | namespace audio { |
| 31 | |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 32 | using LeAudioAseConfigurationSetting = |
| 33 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting; |
| 34 | using AseDirectionRequirement = IBluetoothAudioProvider:: |
| 35 | LeAudioConfigurationRequirement::AseDirectionRequirement; |
| 36 | using AseDirectionConfiguration = IBluetoothAudioProvider:: |
| 37 | LeAudioAseConfigurationSetting::AseDirectionConfiguration; |
Bao Do | c4adf24 | 2023-11-15 08:03:20 +0000 | [diff] [blame] | 38 | using AseQosDirectionRequirement = IBluetoothAudioProvider:: |
| 39 | LeAudioAseQosConfigurationRequirement::AseQosDirectionRequirement; |
| 40 | using LeAudioAseQosConfiguration = |
| 41 | IBluetoothAudioProvider::LeAudioAseQosConfiguration; |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 42 | using LeAudioBroadcastConfigurationSetting = |
| 43 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting; |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 44 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 45 | class LeAudioOffloadAudioProvider : public BluetoothAudioProvider { |
| 46 | public: |
| 47 | LeAudioOffloadAudioProvider(); |
| 48 | |
| 49 | bool isValid(const SessionType& sessionType) override; |
| 50 | |
| 51 | ndk::ScopedAStatus startSession( |
| 52 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 53 | const AudioConfiguration& audio_config, |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 54 | const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return); |
| 55 | ndk::ScopedAStatus setCodecPriority(const CodecId& in_codecId, |
| 56 | int32_t in_priority) override; |
| 57 | ndk::ScopedAStatus getLeAudioAseConfiguration( |
| 58 | const std::optional<std::vector< |
| 59 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 60 | in_remoteSinkAudioCapabilities, |
| 61 | const std::optional<std::vector< |
| 62 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 63 | in_remoteSourceAudioCapabilities, |
| 64 | const std::vector< |
| 65 | IBluetoothAudioProvider::LeAudioConfigurationRequirement>& |
| 66 | in_requirements, |
| 67 | std::vector<IBluetoothAudioProvider::LeAudioAseConfigurationSetting>* |
| 68 | _aidl_return) override; |
| 69 | ndk::ScopedAStatus getLeAudioAseQosConfiguration( |
| 70 | const IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement& |
| 71 | in_qosRequirement, |
| 72 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair* _aidl_return) |
| 73 | override; |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 74 | ndk::ScopedAStatus onSourceAseMetadataChanged( |
| 75 | IBluetoothAudioProvider::AseState in_state, int32_t in_cigId, |
| 76 | int32_t in_cisId, |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 77 | const std::optional<std::vector<std::optional<MetadataLtv>>>& in_metadata) |
| 78 | override; |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 79 | ndk::ScopedAStatus onSinkAseMetadataChanged( |
| 80 | IBluetoothAudioProvider::AseState in_state, int32_t in_cigId, |
| 81 | int32_t in_cisId, |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 82 | const std::optional<std::vector<std::optional<MetadataLtv>>>& in_metadata) |
| 83 | override; |
| 84 | ndk::ScopedAStatus getLeAudioBroadcastConfiguration( |
| 85 | const std::optional<std::vector< |
| 86 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 87 | in_remoteSinkAudioCapabilities, |
| 88 | const IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement& |
| 89 | in_requirement, |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 90 | LeAudioBroadcastConfigurationSetting* _aidl_return) override; |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 91 | |
| 92 | private: |
| 93 | ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) override; |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 94 | std::map<CodecId, uint32_t> codec_priority_map_; |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 95 | std::vector<LeAudioBroadcastConfigurationSetting> broadcast_settings; |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 96 | |
| 97 | // Private matching function definitions |
| 98 | bool isMatchedValidCodec(CodecId cfg_codec, CodecId req_codec); |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 99 | bool filterCapabilitiesMatchedContext( |
| 100 | AudioContext& setting_context, |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 101 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities); |
| 102 | bool isMatchedSamplingFreq( |
| 103 | CodecSpecificConfigurationLtv::SamplingFrequency& cfg_freq, |
| 104 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies& |
| 105 | capability_freq); |
| 106 | bool isMatchedFrameDuration( |
| 107 | CodecSpecificConfigurationLtv::FrameDuration& cfg_fduration, |
| 108 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations& |
| 109 | capability_fduration); |
| 110 | bool isMatchedAudioChannel( |
| 111 | CodecSpecificConfigurationLtv::AudioChannelAllocation& cfg_channel, |
| 112 | CodecSpecificCapabilitiesLtv::SupportedAudioChannelCounts& |
| 113 | capability_channel); |
| 114 | bool isMatchedCodecFramesPerSDU( |
| 115 | CodecSpecificConfigurationLtv::CodecFrameBlocksPerSDU& cfg_frame_sdu, |
| 116 | CodecSpecificCapabilitiesLtv::SupportedMaxCodecFramesPerSDU& |
| 117 | capability_frame_sdu); |
| 118 | bool isMatchedOctetsPerCodecFrame( |
| 119 | CodecSpecificConfigurationLtv::OctetsPerCodecFrame& cfg_octets, |
| 120 | CodecSpecificCapabilitiesLtv::SupportedOctetsPerCodecFrame& |
| 121 | capability_octets); |
| 122 | bool isCapabilitiesMatchedCodecConfiguration( |
| 123 | std::vector<CodecSpecificConfigurationLtv>& codec_cfg, |
| 124 | std::vector<CodecSpecificCapabilitiesLtv> codec_capabilities); |
Bao Do | 57861bd | 2024-05-23 17:02:54 +0800 | [diff] [blame] | 125 | bool filterMatchedAseConfiguration( |
| 126 | LeAudioAseConfiguration& setting_cfg, |
| 127 | const LeAudioAseConfiguration& requirement_cfg); |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 128 | bool isMatchedBISConfiguration( |
| 129 | LeAudioBisConfiguration bis_cfg, |
| 130 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities); |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 131 | void filterCapabilitiesAseDirectionConfiguration( |
| 132 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 133 | direction_configurations, |
| 134 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities, |
| 135 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 136 | valid_direction_configurations); |
| 137 | void filterRequirementAseDirectionConfiguration( |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 138 | std::optional<std::vector<std::optional<AseDirectionConfiguration>>>& |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 139 | direction_configurations, |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 140 | const std::vector<std::optional<AseDirectionRequirement>>& requirements, |
| 141 | std::optional<std::vector<std::optional<AseDirectionConfiguration>>>& |
Bao Do | 16d8193 | 2024-12-02 15:49:04 +0800 | [diff] [blame] | 142 | valid_direction_configurations, |
| 143 | bool isExact); |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 144 | std::optional<LeAudioAseConfigurationSetting> |
| 145 | getCapabilitiesMatchedAseConfigurationSettings( |
| 146 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting& setting, |
| 147 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities, |
| 148 | uint8_t direction); |
| 149 | std::optional<LeAudioAseConfigurationSetting> |
| 150 | getRequirementMatchedAseConfigurationSettings( |
| 151 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting& setting, |
| 152 | const IBluetoothAudioProvider::LeAudioConfigurationRequirement& |
Bao Do | 16d8193 | 2024-12-02 15:49:04 +0800 | [diff] [blame] | 153 | requirement, |
| 154 | bool isExact); |
Bao Do | c4adf24 | 2023-11-15 08:03:20 +0000 | [diff] [blame] | 155 | bool isMatchedQosRequirement(LeAudioAseQosConfiguration setting_qos, |
| 156 | AseQosDirectionRequirement requirement_qos); |
Bao Do | 5b2fdab | 2023-11-20 08:02:55 +0000 | [diff] [blame] | 157 | std::optional<LeAudioBroadcastConfigurationSetting> |
| 158 | getCapabilitiesMatchedBroadcastConfigurationSettings( |
| 159 | LeAudioBroadcastConfigurationSetting& setting, |
| 160 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities); |
| 161 | void getBroadcastSettings(); |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 162 | std::optional<LeAudioAseQosConfiguration> getDirectionQosConfiguration( |
| 163 | uint8_t direction, |
| 164 | const IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement& |
| 165 | qosRequirement, |
Bao Do | 81092bb | 2024-05-30 21:27:10 +0800 | [diff] [blame] | 166 | std::vector<LeAudioAseConfigurationSetting>& ase_configuration_settings, |
| 167 | bool is_exact); |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 168 | bool isSubgroupConfigurationMatchedContext( |
| 169 | AudioContext requirement_context, |
Bao Do | 81092bb | 2024-05-30 21:27:10 +0800 | [diff] [blame] | 170 | IBluetoothAudioProvider::BroadcastQuality quality, |
Bao Do | 91d7ca2 | 2024-05-09 14:21:01 +0800 | [diff] [blame] | 171 | LeAudioBroadcastSubgroupConfiguration configuration); |
Bao Do | 767222a | 2024-07-26 17:10:57 +0800 | [diff] [blame] | 172 | std::optional<IBluetoothAudioProvider::LeAudioAseConfigurationSetting> |
Bao Do | 57861bd | 2024-05-23 17:02:54 +0800 | [diff] [blame] | 173 | matchWithRequirement( |
| 174 | std::vector<IBluetoothAudioProvider::LeAudioAseConfigurationSetting>& |
| 175 | matched_ase_configuration_settings, |
Bao Do | 767222a | 2024-07-26 17:10:57 +0800 | [diff] [blame] | 176 | const IBluetoothAudioProvider::LeAudioConfigurationRequirement& |
| 177 | requirements, |
Bao Do | 16d8193 | 2024-12-02 15:49:04 +0800 | [diff] [blame] | 178 | bool isMatchContext, bool isExact); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 179 | }; |
| 180 | |
| 181 | class LeAudioOffloadOutputAudioProvider : public LeAudioOffloadAudioProvider { |
| 182 | public: |
| 183 | LeAudioOffloadOutputAudioProvider(); |
| 184 | }; |
| 185 | |
| 186 | class LeAudioOffloadInputAudioProvider : public LeAudioOffloadAudioProvider { |
| 187 | public: |
| 188 | LeAudioOffloadInputAudioProvider(); |
| 189 | }; |
| 190 | |
Alice Kuo | e80a576 | 2022-02-09 14:44:29 +0800 | [diff] [blame] | 191 | class LeAudioOffloadBroadcastAudioProvider |
| 192 | : public LeAudioOffloadAudioProvider { |
| 193 | public: |
| 194 | LeAudioOffloadBroadcastAudioProvider(); |
| 195 | }; |
| 196 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 197 | } // namespace audio |
| 198 | } // namespace bluetooth |
| 199 | } // namespace hardware |
| 200 | } // namespace android |
| 201 | } // namespace aidl |