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