1 2 /* 3 * Copyright (C) 2023 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <aidl/android/hardware/bluetooth/audio/IBluetoothAudioProvider.h> 19 20 #include <map> 21 #include <mutex> 22 #include <optional> 23 #include <string> 24 #include <string_view> 25 #include <tuple> 26 27 #include "audio_set_configurations_generated.h" 28 #include "audio_set_scenarios_generated.h" 29 30 namespace aidl { 31 namespace android { 32 namespace hardware { 33 namespace bluetooth { 34 namespace audio { 35 36 using LeAudioAseConfigurationSetting = 37 IBluetoothAudioProvider::LeAudioAseConfigurationSetting; 38 using AseDirectionConfiguration = IBluetoothAudioProvider:: 39 LeAudioAseConfigurationSetting::AseDirectionConfiguration; 40 using LeAudioAseQosConfiguration = 41 IBluetoothAudioProvider::LeAudioAseQosConfiguration; 42 using LeAudioDataPathConfiguration = 43 IBluetoothAudioProvider::LeAudioDataPathConfiguration; 44 45 enum class CodecLocation { 46 HOST, 47 ADSP, 48 CONTROLLER, 49 }; 50 51 class AudioSetConfigurationProviderJson { 52 public: 53 static std::vector<LeAudioAseConfigurationSetting> 54 GetLeAudioAseConfigurationSettings(); 55 56 private: 57 static void LoadAudioSetConfigurationProviderJson(); 58 59 static const le_audio::CodecSpecificConfiguration* LookupCodecSpecificParam( 60 const flatbuffers::Vector<flatbuffers::Offset< 61 le_audio::CodecSpecificConfiguration>>* flat_codec_specific_params, 62 le_audio::CodecSpecificLtvGenericTypes type); 63 64 static void populateAudioChannelAllocation( 65 CodecSpecificConfigurationLtv::AudioChannelAllocation& 66 audio_channel_allocation, 67 uint32_t audio_location); 68 69 static void populateConfigurationData( 70 LeAudioAseConfiguration& ase, 71 const flatbuffers::Vector< 72 flatbuffers::Offset<le_audio::CodecSpecificConfiguration>>* 73 flat_codec_specific_params); 74 75 static void populateAseConfiguration( 76 LeAudioAseConfiguration& ase, 77 const le_audio::AudioSetSubConfiguration* flat_subconfig, 78 const le_audio::QosConfiguration* qos_cfg); 79 80 static void populateAseQosConfiguration( 81 LeAudioAseQosConfiguration& qos, 82 const le_audio::QosConfiguration* qos_cfg, LeAudioAseConfiguration& ase); 83 84 static AseDirectionConfiguration SetConfigurationFromFlatSubconfig( 85 const le_audio::AudioSetSubConfiguration* flat_subconfig, 86 const le_audio::QosConfiguration* qos_cfg, CodecLocation location); 87 88 static void processSubconfig( 89 const le_audio::AudioSetSubConfiguration* subconfig, 90 const le_audio::QosConfiguration* qos_cfg, 91 std::vector<std::optional<AseDirectionConfiguration>>& 92 directionAseConfiguration, 93 CodecLocation location); 94 95 static void PopulateAseConfigurationFromFlat( 96 const le_audio::AudioSetConfiguration* flat_cfg, 97 std::vector<const le_audio::CodecConfiguration*>* codec_cfgs, 98 std::vector<const le_audio::QosConfiguration*>* qos_cfgs, 99 CodecLocation location, 100 std::vector<std::optional<AseDirectionConfiguration>>& 101 sourceAseConfiguration, 102 std::vector<std::optional<AseDirectionConfiguration>>& 103 sinkAseConfiguration, 104 ConfigurationFlags& configurationFlags); 105 106 static bool LoadConfigurationsFromFiles(const char* schema_file, 107 const char* content_file, 108 CodecLocation location); 109 110 static bool LoadScenariosFromFiles(const char* schema_file, 111 const char* content_file); 112 113 static bool LoadContent( 114 std::vector<std::pair<const char* /*schema*/, const char* /*content*/>> 115 config_files, 116 std::vector<std::pair<const char* /*schema*/, const char* /*content*/>> 117 scenario_files, 118 CodecLocation location); 119 }; 120 121 } // namespace audio 122 } // namespace bluetooth 123 } // namespace hardware 124 } // namespace android 125 } // namespace aidl 126