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> 23 #include <vector> 24 25 #include "aidl/android/hardware/bluetooth/audio/CodecInfo.h" 26 #include "aidl/android/hardware/bluetooth/audio/CodecSpecificConfigurationLtv.h" 27 #include "aidl/android/hardware/bluetooth/audio/SessionType.h" 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: 38 static std::optional<setting::LeAudioOffloadSetting> 39 ParseFromLeAudioOffloadSettingFile(); 40 static std::vector<LeAudioCodecCapabilitiesSetting> 41 GetLeAudioCodecCapabilities( 42 const std::optional<setting::LeAudioOffloadSetting>& 43 le_audio_offload_setting); 44 static void ClearLeAudioCodecCapabilities(); 45 static std::unordered_map<SessionType, std::vector<CodecInfo>> 46 GetLeAudioCodecInfo(const std::optional<setting::LeAudioOffloadSetting>& 47 le_audio_offload_setting); 48 49 private: 50 static inline std::vector<setting::Scenario> supported_scenarios_; 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_; 57 static inline std::unordered_map<SessionType, std::vector<CodecInfo>> 58 session_codecs_map_; 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); 72 static void LoadConfigurationToMap( 73 const std::optional<setting::LeAudioOffloadSetting>& 74 le_audio_offload_setting); 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); 82 static BroadcastCapability GetBroadcastCapability( 83 const std::string& coding_direction); 84 85 template <class T> 86 static inline UnicastCapability ComposeUnicastCapability( 87 const CodecType& codec_type, const AudioLocation& audio_location, 88 const std::optional< 89 CodecSpecificConfigurationLtv::AudioChannelAllocation>& 90 audio_channel_allocation, 91 const uint8_t& device_cnt, const uint8_t& channel_count, 92 const T& capability); 93 94 template <class T> 95 static inline BroadcastCapability ComposeBroadcastCapability( 96 const CodecType& codec_type, const AudioLocation& audio_location, 97 const std::optional< 98 CodecSpecificConfigurationLtv::AudioChannelAllocation>& 99 audio_channel_allocation, 100 const uint8_t& channel_count, const std::vector<T>& capability); 101 102 static inline Lc3Capabilities ComposeLc3Capability( 103 const setting::CodecConfiguration& codec_configuration); 104 105 static inline AptxAdaptiveLeCapabilities ComposeAptxAdaptiveLeCapability( 106 const setting::CodecConfiguration& codec_configuration); 107 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 123