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" |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 24 | |
| 25 | namespace aidl { |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace bluetooth { |
| 29 | namespace audio { |
| 30 | |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 31 | using LeAudioAseConfigurationSetting = |
| 32 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting; |
| 33 | using AseDirectionRequirement = IBluetoothAudioProvider:: |
| 34 | LeAudioConfigurationRequirement::AseDirectionRequirement; |
| 35 | using AseDirectionConfiguration = IBluetoothAudioProvider:: |
| 36 | LeAudioAseConfigurationSetting::AseDirectionConfiguration; |
| 37 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 38 | class LeAudioOffloadAudioProvider : public BluetoothAudioProvider { |
| 39 | public: |
| 40 | LeAudioOffloadAudioProvider(); |
| 41 | |
| 42 | bool isValid(const SessionType& sessionType) override; |
| 43 | |
| 44 | ndk::ScopedAStatus startSession( |
| 45 | const std::shared_ptr<IBluetoothAudioPort>& host_if, |
Chen Chen | c92270e | 2022-02-14 18:29:52 -0800 | [diff] [blame] | 46 | const AudioConfiguration& audio_config, |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 47 | const std::vector<LatencyMode>& latency_modes, DataMQDesc* _aidl_return); |
| 48 | ndk::ScopedAStatus setCodecPriority(const CodecId& in_codecId, |
| 49 | int32_t in_priority) override; |
| 50 | ndk::ScopedAStatus getLeAudioAseConfiguration( |
| 51 | const std::optional<std::vector< |
| 52 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 53 | in_remoteSinkAudioCapabilities, |
| 54 | const std::optional<std::vector< |
| 55 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 56 | in_remoteSourceAudioCapabilities, |
| 57 | const std::vector< |
| 58 | IBluetoothAudioProvider::LeAudioConfigurationRequirement>& |
| 59 | in_requirements, |
| 60 | std::vector<IBluetoothAudioProvider::LeAudioAseConfigurationSetting>* |
| 61 | _aidl_return) override; |
| 62 | ndk::ScopedAStatus getLeAudioAseQosConfiguration( |
| 63 | const IBluetoothAudioProvider::LeAudioAseQosConfigurationRequirement& |
| 64 | in_qosRequirement, |
| 65 | IBluetoothAudioProvider::LeAudioAseQosConfigurationPair* _aidl_return) |
| 66 | override; |
| 67 | ndk::ScopedAStatus onSinkAseMetadataChanged( |
| 68 | IBluetoothAudioProvider::AseState in_state, |
| 69 | const std::optional<std::vector<std::optional<MetadataLtv>>>& in_metadata) |
| 70 | override; |
| 71 | ndk::ScopedAStatus onSourceAseMetadataChanged( |
| 72 | IBluetoothAudioProvider::AseState in_state, |
| 73 | const std::optional<std::vector<std::optional<MetadataLtv>>>& in_metadata) |
| 74 | override; |
| 75 | ndk::ScopedAStatus getLeAudioBroadcastConfiguration( |
| 76 | const std::optional<std::vector< |
| 77 | std::optional<IBluetoothAudioProvider::LeAudioDeviceCapabilities>>>& |
| 78 | in_remoteSinkAudioCapabilities, |
| 79 | const IBluetoothAudioProvider::LeAudioBroadcastConfigurationRequirement& |
| 80 | in_requirement, |
| 81 | IBluetoothAudioProvider::LeAudioBroadcastConfigurationSetting* |
| 82 | _aidl_return) override; |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | ndk::ScopedAStatus onSessionReady(DataMQDesc* _aidl_return) override; |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 86 | std::map<CodecId, uint32_t> codec_priority_map_; |
| 87 | |
| 88 | // Private matching function definitions |
| 89 | bool isMatchedValidCodec(CodecId cfg_codec, CodecId req_codec); |
Bao Do | 867af60 | 2023-11-15 05:41:12 +0000 | [diff] [blame^] | 90 | bool isCapabilitiesMatchedContext( |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 91 | AudioContext setting_context, |
| 92 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities); |
| 93 | bool isMatchedSamplingFreq( |
| 94 | CodecSpecificConfigurationLtv::SamplingFrequency& cfg_freq, |
| 95 | CodecSpecificCapabilitiesLtv::SupportedSamplingFrequencies& |
| 96 | capability_freq); |
| 97 | bool isMatchedFrameDuration( |
| 98 | CodecSpecificConfigurationLtv::FrameDuration& cfg_fduration, |
| 99 | CodecSpecificCapabilitiesLtv::SupportedFrameDurations& |
| 100 | capability_fduration); |
| 101 | bool isMatchedAudioChannel( |
| 102 | CodecSpecificConfigurationLtv::AudioChannelAllocation& cfg_channel, |
| 103 | CodecSpecificCapabilitiesLtv::SupportedAudioChannelCounts& |
| 104 | capability_channel); |
| 105 | bool isMatchedCodecFramesPerSDU( |
| 106 | CodecSpecificConfigurationLtv::CodecFrameBlocksPerSDU& cfg_frame_sdu, |
| 107 | CodecSpecificCapabilitiesLtv::SupportedMaxCodecFramesPerSDU& |
| 108 | capability_frame_sdu); |
| 109 | bool isMatchedOctetsPerCodecFrame( |
| 110 | CodecSpecificConfigurationLtv::OctetsPerCodecFrame& cfg_octets, |
| 111 | CodecSpecificCapabilitiesLtv::SupportedOctetsPerCodecFrame& |
| 112 | capability_octets); |
| 113 | bool isCapabilitiesMatchedCodecConfiguration( |
| 114 | std::vector<CodecSpecificConfigurationLtv>& codec_cfg, |
| 115 | std::vector<CodecSpecificCapabilitiesLtv> codec_capabilities); |
Bao Do | 867af60 | 2023-11-15 05:41:12 +0000 | [diff] [blame^] | 116 | bool isMatchedAseConfiguration(LeAudioAseConfiguration setting_cfg, |
| 117 | LeAudioAseConfiguration requirement_cfg); |
Bao Do | 6112bda | 2023-11-15 03:57:59 +0000 | [diff] [blame] | 118 | void filterCapabilitiesAseDirectionConfiguration( |
| 119 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 120 | direction_configurations, |
| 121 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities, |
| 122 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 123 | valid_direction_configurations); |
| 124 | void filterRequirementAseDirectionConfiguration( |
| 125 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 126 | direction_configurations, |
| 127 | const std::optional<std::vector<std::optional<AseDirectionRequirement>>>& |
| 128 | requirements, |
| 129 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 130 | valid_direction_configurations); |
| 131 | std::optional<LeAudioAseConfigurationSetting> |
| 132 | getCapabilitiesMatchedAseConfigurationSettings( |
| 133 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting& setting, |
| 134 | const IBluetoothAudioProvider::LeAudioDeviceCapabilities& capabilities, |
| 135 | uint8_t direction); |
| 136 | std::optional<LeAudioAseConfigurationSetting> |
| 137 | getRequirementMatchedAseConfigurationSettings( |
| 138 | IBluetoothAudioProvider::LeAudioAseConfigurationSetting& setting, |
| 139 | const IBluetoothAudioProvider::LeAudioConfigurationRequirement& |
| 140 | requirement); |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | class LeAudioOffloadOutputAudioProvider : public LeAudioOffloadAudioProvider { |
| 144 | public: |
| 145 | LeAudioOffloadOutputAudioProvider(); |
| 146 | }; |
| 147 | |
| 148 | class LeAudioOffloadInputAudioProvider : public LeAudioOffloadAudioProvider { |
| 149 | public: |
| 150 | LeAudioOffloadInputAudioProvider(); |
| 151 | }; |
| 152 | |
Alice Kuo | e80a576 | 2022-02-09 14:44:29 +0800 | [diff] [blame] | 153 | class LeAudioOffloadBroadcastAudioProvider |
| 154 | : public LeAudioOffloadAudioProvider { |
| 155 | public: |
| 156 | LeAudioOffloadBroadcastAudioProvider(); |
| 157 | }; |
| 158 | |
Josh Wu | 6ab53e7 | 2021-12-29 23:53:33 -0800 | [diff] [blame] | 159 | } // namespace audio |
| 160 | } // namespace bluetooth |
| 161 | } // namespace hardware |
| 162 | } // namespace android |
| 163 | } // namespace aidl |