Bao Do | fbc99e0 | 2023-11-15 03:21:03 +0000 | [diff] [blame] | 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( |
Bao Do | f6ce19d | 2024-07-04 11:07:02 +0800 | [diff] [blame] | 76 | const std::string& name, LeAudioAseConfiguration& ase, |
Bao Do | fbc99e0 | 2023-11-15 03:21:03 +0000 | [diff] [blame] | 77 | const le_audio::AudioSetSubConfiguration* flat_subconfig, |
| 78 | const le_audio::QosConfiguration* qos_cfg); |
| 79 | |
| 80 | static void populateAseQosConfiguration( |
| 81 | LeAudioAseQosConfiguration& qos, |
Bao Do | f6ce19d | 2024-07-04 11:07:02 +0800 | [diff] [blame] | 82 | const le_audio::QosConfiguration* qos_cfg, LeAudioAseConfiguration& ase, |
| 83 | uint8_t ase_channel_cnt); |
Bao Do | fbc99e0 | 2023-11-15 03:21:03 +0000 | [diff] [blame] | 84 | |
| 85 | static AseDirectionConfiguration SetConfigurationFromFlatSubconfig( |
Bao Do | f6ce19d | 2024-07-04 11:07:02 +0800 | [diff] [blame] | 86 | const std::string& name, |
Bao Do | fbc99e0 | 2023-11-15 03:21:03 +0000 | [diff] [blame] | 87 | const le_audio::AudioSetSubConfiguration* flat_subconfig, |
| 88 | const le_audio::QosConfiguration* qos_cfg, CodecLocation location); |
| 89 | |
| 90 | static void processSubconfig( |
Bao Do | f6ce19d | 2024-07-04 11:07:02 +0800 | [diff] [blame] | 91 | const std::string& name, |
Bao Do | fbc99e0 | 2023-11-15 03:21:03 +0000 | [diff] [blame] | 92 | const le_audio::AudioSetSubConfiguration* subconfig, |
| 93 | const le_audio::QosConfiguration* qos_cfg, |
| 94 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 95 | directionAseConfiguration, |
| 96 | CodecLocation location); |
| 97 | |
| 98 | static void PopulateAseConfigurationFromFlat( |
| 99 | const le_audio::AudioSetConfiguration* flat_cfg, |
| 100 | std::vector<const le_audio::CodecConfiguration*>* codec_cfgs, |
| 101 | std::vector<const le_audio::QosConfiguration*>* qos_cfgs, |
| 102 | CodecLocation location, |
| 103 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 104 | sourceAseConfiguration, |
| 105 | std::vector<std::optional<AseDirectionConfiguration>>& |
| 106 | sinkAseConfiguration, |
| 107 | ConfigurationFlags& configurationFlags); |
| 108 | |
| 109 | static bool LoadConfigurationsFromFiles(const char* schema_file, |
| 110 | const char* content_file, |
| 111 | CodecLocation location); |
| 112 | |
| 113 | static bool LoadScenariosFromFiles(const char* schema_file, |
| 114 | const char* content_file); |
| 115 | |
| 116 | static bool LoadContent( |
| 117 | std::vector<std::pair<const char* /*schema*/, const char* /*content*/>> |
| 118 | config_files, |
| 119 | std::vector<std::pair<const char* /*schema*/, const char* /*content*/>> |
| 120 | scenario_files, |
| 121 | CodecLocation location); |
| 122 | }; |
| 123 | |
| 124 | } // namespace audio |
| 125 | } // namespace bluetooth |
| 126 | } // namespace hardware |
| 127 | } // namespace android |
| 128 | } // namespace aidl |