• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 #include "mock_codec_manager.h"
18 
19 #include "le_audio/codec_manager.h"
20 #include "le_audio/le_audio_types.h"
21 
22 MockCodecManager* mock_codec_manager_pimpl_;
GetInstance()23 MockCodecManager* MockCodecManager::GetInstance() {
24   bluetooth::le_audio::CodecManager::GetInstance();
25   return mock_codec_manager_pimpl_;
26 }
27 
28 namespace bluetooth::le_audio {
29 
30 struct CodecManager::impl : public MockCodecManager {
31 public:
32   impl() = default;
33   ~impl() = default;
34 };
35 
CodecManager()36 CodecManager::CodecManager() {}
37 
GetCodecLocation() const38 types::CodecLocation CodecManager::GetCodecLocation() const {
39   if (!pimpl_) {
40     return types::CodecLocation::HOST;
41   }
42   return pimpl_->GetCodecLocation();
43 }
44 
GetCodecConfigProviderInfo(void) const45 std::optional<ProviderInfo> CodecManager::GetCodecConfigProviderInfo(void) const {
46   if (!pimpl_) {
47     return std::nullopt;
48   }
49   return pimpl_->GetCodecConfigProviderInfo();
50 }
51 
IsDualBiDirSwbSupported(void) const52 bool CodecManager::IsDualBiDirSwbSupported(void) const {
53   if (!pimpl_) {
54     return false;
55   }
56 
57   return pimpl_->IsDualBiDirSwbSupported();
58 }
59 
UpdateActiveUnicastAudioHalClient(LeAudioSourceAudioHalClient * source_unicast_client,LeAudioSinkAudioHalClient * sink_unicast_client,bool is_active)60 bool CodecManager::UpdateActiveUnicastAudioHalClient(
61         LeAudioSourceAudioHalClient* source_unicast_client,
62         LeAudioSinkAudioHalClient* sink_unicast_client, bool is_active) {
63   if (pimpl_) {
64     return pimpl_->UpdateActiveUnicastAudioHalClient(source_unicast_client, sink_unicast_client,
65                                                      is_active);
66   }
67   return true;
68 }
69 
UpdateActiveBroadcastAudioHalClient(LeAudioSourceAudioHalClient * source_broadcast_client,bool is_active)70 bool CodecManager::UpdateActiveBroadcastAudioHalClient(
71         LeAudioSourceAudioHalClient* source_broadcast_client, bool is_active) {
72   if (pimpl_) {
73     return pimpl_->UpdateActiveBroadcastAudioHalClient(source_broadcast_client, is_active);
74   }
75   return true;
76 }
77 
UpdateActiveAudioConfig(const types::BidirectionalPair<stream_parameters> & stream_params,std::function<void (const::bluetooth::le_audio::stream_config & config,uint8_t direction)> update_receiver,uint8_t directions_to_update)78 void CodecManager::UpdateActiveAudioConfig(
79         const types::BidirectionalPair<stream_parameters>& stream_params,
80         std::function<void(const ::bluetooth::le_audio::stream_config& config, uint8_t direction)>
81                 update_receiver,
82         uint8_t directions_to_update) {
83   if (pimpl_) {
84     return pimpl_->UpdateActiveAudioConfig(stream_params, update_receiver, directions_to_update);
85   }
86 }
87 
GetCodecConfig(const CodecManager::UnicastConfigurationRequirements & requirements,CodecManager::UnicastConfigurationProvider verifier)88 std::unique_ptr<types::AudioSetConfiguration> CodecManager::GetCodecConfig(
89         const CodecManager::UnicastConfigurationRequirements& requirements,
90         CodecManager::UnicastConfigurationProvider verifier) {
91   if (!pimpl_) {
92     return nullptr;
93   }
94   return pimpl_->GetCodecConfig(requirements, verifier);
95 }
96 
97 std::unique_ptr<::bluetooth::le_audio::broadcaster::BroadcastConfiguration>
GetBroadcastConfig(const bluetooth::le_audio::CodecManager::BroadcastConfigurationRequirements & requirements) const98 CodecManager::GetBroadcastConfig(
99         const bluetooth::le_audio::CodecManager::BroadcastConfigurationRequirements& requirements)
100         const {
101   if (!pimpl_) {
102     return std::unique_ptr<bluetooth::le_audio::broadcaster::BroadcastConfiguration>(nullptr);
103   }
104   return pimpl_->GetBroadcastConfig(requirements);
105 }
106 
CheckCodecConfigIsBiDirSwb(const bluetooth::le_audio::types::AudioSetConfiguration & config) const107 bool CodecManager::CheckCodecConfigIsBiDirSwb(
108         const bluetooth::le_audio::types::AudioSetConfiguration& config) const {
109   if (!pimpl_) {
110     return false;
111   }
112   return pimpl_->CheckCodecConfigIsBiDirSwb(config);
113 }
114 
CheckCodecConfigIsDualBiDirSwb(const bluetooth::le_audio::types::AudioSetConfiguration & config) const115 bool CodecManager::CheckCodecConfigIsDualBiDirSwb(
116         const bluetooth::le_audio::types::AudioSetConfiguration& config) const {
117   if (!pimpl_) {
118     return false;
119   }
120   return pimpl_->CheckCodecConfigIsDualBiDirSwb(config);
121 }
122 
123 std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
GetLocalAudioOutputCodecCapa()124 CodecManager::GetLocalAudioOutputCodecCapa() {
125   if (!pimpl_) {
126     return std::vector<bluetooth::le_audio::btle_audio_codec_config_t>{};
127   }
128   return pimpl_->GetLocalAudioOutputCodecCapa();
129 }
130 
131 std::vector<bluetooth::le_audio::btle_audio_codec_config_t>
GetLocalAudioInputCodecCapa()132 CodecManager::GetLocalAudioInputCodecCapa() {
133   if (!pimpl_) {
134     return std::vector<bluetooth::le_audio::btle_audio_codec_config_t>{};
135   }
136   return pimpl_->GetLocalAudioInputCodecCapa();
137 }
138 
UpdateBroadcastConnHandle(const std::vector<uint16_t> & conn_handle,std::function<void (const::bluetooth::le_audio::broadcast_offload_config & config)> update_receiver)139 void CodecManager::UpdateBroadcastConnHandle(
140         const std::vector<uint16_t>& conn_handle,
141         std::function<void(const ::bluetooth::le_audio::broadcast_offload_config& config)>
142                 update_receiver) {
143   if (pimpl_) {
144     return pimpl_->UpdateBroadcastConnHandle(conn_handle, update_receiver);
145   }
146 }
147 
Start(const std::vector<bluetooth::le_audio::btle_audio_codec_config_t> &)148 void CodecManager::Start(const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>&
149                          /*offloading_preference*/) {
150   // It is needed here as CodecManager which is a singleton creates it, but in
151   // this mock we want to destroy and recreate the mock on each test case.
152   if (!pimpl_) {
153     pimpl_ = std::make_unique<testing::NiceMock<impl>>();
154   }
155 
156   mock_codec_manager_pimpl_ = pimpl_.get();
157   pimpl_->Start();
158 }
159 
Stop()160 void CodecManager::Stop() {
161   // It is needed here as CodecManager which is a singleton creates it, but in
162   // this mock we want to destroy and recreate the mock on each test case.
163   if (pimpl_) {
164     pimpl_->Stop();
165     pimpl_.reset();
166   }
167 
168   mock_codec_manager_pimpl_ = nullptr;
169 }
170 
UpdateCisConfiguration(const std::vector<struct types::cis> & cises,const stream_parameters & stream_params,uint8_t direction)171 bool CodecManager::UpdateCisConfiguration(const std::vector<struct types::cis>& cises,
172                                           const stream_parameters& stream_params,
173                                           uint8_t direction) {
174   if (pimpl_) {
175     return pimpl_->UpdateCisConfiguration(cises, stream_params, direction);
176   }
177   return false;
178 }
179 
ClearCisConfiguration(uint8_t direction)180 void CodecManager::ClearCisConfiguration(uint8_t direction) {
181   if (pimpl_) {
182     return pimpl_->ClearCisConfiguration(direction);
183   }
184 }
185 
IsUsingCodecExtensibility() const186 bool CodecManager::IsUsingCodecExtensibility() const {
187   if (pimpl_) {
188     return pimpl_->IsUsingCodecExtensibility();
189   }
190   return false;
191 }
192 
operator <<(std::ostream & os,const CodecManager::UnicastConfigurationRequirements &)193 std::ostream& operator<<(std::ostream& os, const CodecManager::UnicastConfigurationRequirements&) {
194   return os;
195 }
196 
197 // CodecManager::~CodecManager() = default;
198 
199 }  // namespace bluetooth::le_audio
200