shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [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 | |
| 19 | #include <aidl/android/hardware/bluetooth/audio/LeAudioCodecCapabilitiesSetting.h> |
| 20 | #include <android-base/logging.h> |
| 21 | |
| 22 | #include <unordered_map> |
Patty Huang | ac077ef | 2022-11-23 14:45:15 +0800 | [diff] [blame] | 23 | #include <vector> |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 24 | |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 25 | #include "aidl/android/hardware/bluetooth/audio/CodecInfo.h" |
Bao Do | 0041aaa | 2024-04-17 14:15:10 +0800 | [diff] [blame] | 26 | #include "aidl/android/hardware/bluetooth/audio/CodecSpecificConfigurationLtv.h" |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 27 | #include "aidl/android/hardware/bluetooth/audio/SessionType.h" |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 28 | #include "aidl_android_hardware_bluetooth_audio_setting.h" |
| 29 | |
| 30 | namespace aidl { |
| 31 | namespace android { |
| 32 | namespace hardware { |
| 33 | namespace bluetooth { |
| 34 | namespace audio { |
| 35 | |
| 36 | class BluetoothLeAudioCodecsProvider { |
| 37 | public: |
shihchienc | d7f565a | 2022-10-14 13:45:37 +0000 | [diff] [blame] | 38 | static std::optional<setting::LeAudioOffloadSetting> |
| 39 | ParseFromLeAudioOffloadSettingFile(); |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 40 | static std::vector<LeAudioCodecCapabilitiesSetting> |
shihchienc | d7f565a | 2022-10-14 13:45:37 +0000 | [diff] [blame] | 41 | GetLeAudioCodecCapabilities( |
| 42 | const std::optional<setting::LeAudioOffloadSetting>& |
| 43 | le_audio_offload_setting); |
| 44 | static void ClearLeAudioCodecCapabilities(); |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 45 | static std::unordered_map<SessionType, std::vector<CodecInfo>> |
| 46 | GetLeAudioCodecInfo(const std::optional<setting::LeAudioOffloadSetting>& |
| 47 | le_audio_offload_setting); |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 48 | |
| 49 | private: |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 50 | static inline std::vector<setting::Scenario> supported_scenarios_; |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 51 | static inline std::unordered_map<std::string, setting::Configuration> |
| 52 | configuration_map_; |
| 53 | static inline std::unordered_map<std::string, setting::CodecConfiguration> |
| 54 | codec_configuration_map_; |
| 55 | static inline std::unordered_map<std::string, setting::StrategyConfiguration> |
| 56 | strategy_configuration_map_; |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 57 | static inline std::unordered_map<SessionType, std::vector<CodecInfo>> |
| 58 | session_codecs_map_; |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 59 | |
| 60 | static std::vector<setting::Scenario> GetScenarios( |
| 61 | const std::optional<setting::LeAudioOffloadSetting>& |
| 62 | le_audio_offload_setting); |
| 63 | static void UpdateConfigurationsToMap( |
| 64 | const std::optional<setting::LeAudioOffloadSetting>& |
| 65 | le_audio_offload_setting); |
| 66 | static void UpdateCodecConfigurationsToMap( |
| 67 | const std::optional<setting::LeAudioOffloadSetting>& |
| 68 | le_audio_offload_setting); |
| 69 | static void UpdateStrategyConfigurationsToMap( |
| 70 | const std::optional<setting::LeAudioOffloadSetting>& |
| 71 | le_audio_offload_setting); |
Bao Do | 6aeb5d7 | 2023-12-11 10:53:18 +0000 | [diff] [blame] | 72 | static void LoadConfigurationToMap( |
| 73 | const std::optional<setting::LeAudioOffloadSetting>& |
| 74 | le_audio_offload_setting); |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 75 | |
| 76 | static std::vector<LeAudioCodecCapabilitiesSetting> |
| 77 | ComposeLeAudioCodecCapabilities( |
| 78 | const std::vector<setting::Scenario>& supported_scenarios); |
| 79 | |
| 80 | static UnicastCapability GetUnicastCapability( |
| 81 | const std::string& coding_direction); |
Patty Huang | ac077ef | 2022-11-23 14:45:15 +0800 | [diff] [blame] | 82 | static BroadcastCapability GetBroadcastCapability( |
| 83 | const std::string& coding_direction); |
| 84 | |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 85 | template <class T> |
| 86 | static inline UnicastCapability ComposeUnicastCapability( |
| 87 | const CodecType& codec_type, const AudioLocation& audio_location, |
Bao Do | 0041aaa | 2024-04-17 14:15:10 +0800 | [diff] [blame] | 88 | const std::optional< |
| 89 | CodecSpecificConfigurationLtv::AudioChannelAllocation>& |
| 90 | audio_channel_allocation, |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 91 | const uint8_t& device_cnt, const uint8_t& channel_count, |
| 92 | const T& capability); |
| 93 | |
Patty Huang | ac077ef | 2022-11-23 14:45:15 +0800 | [diff] [blame] | 94 | template <class T> |
| 95 | static inline BroadcastCapability ComposeBroadcastCapability( |
| 96 | const CodecType& codec_type, const AudioLocation& audio_location, |
Bao Do | 0041aaa | 2024-04-17 14:15:10 +0800 | [diff] [blame] | 97 | const std::optional< |
| 98 | CodecSpecificConfigurationLtv::AudioChannelAllocation>& |
| 99 | audio_channel_allocation, |
Patty Huang | ac077ef | 2022-11-23 14:45:15 +0800 | [diff] [blame] | 100 | const uint8_t& channel_count, const std::vector<T>& capability); |
| 101 | |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 102 | static inline Lc3Capabilities ComposeLc3Capability( |
| 103 | const setting::CodecConfiguration& codec_configuration); |
| 104 | |
Alice Kuo | f850de6 | 2023-10-04 04:02:24 +0800 | [diff] [blame] | 105 | static inline AptxAdaptiveLeCapabilities ComposeAptxAdaptiveLeCapability( |
| 106 | const setting::CodecConfiguration& codec_configuration); |
| 107 | |
shihchienc | 8ed901a | 2022-09-06 08:44:44 +0000 | [diff] [blame] | 108 | static inline AudioLocation GetAudioLocation( |
| 109 | const setting::AudioLocation& audio_location); |
| 110 | static inline CodecType GetCodecType(const setting::CodecType& codec_type); |
| 111 | |
| 112 | static inline bool IsValidCodecConfiguration( |
| 113 | const setting::CodecConfiguration& codec_configuration); |
| 114 | static inline bool IsValidStrategyConfiguration( |
| 115 | const setting::StrategyConfiguration& strategy_configuration); |
| 116 | }; |
| 117 | |
| 118 | } // namespace audio |
| 119 | } // namespace bluetooth |
| 120 | } // namespace hardware |
| 121 | } // namespace android |
| 122 | } // namespace aidl |