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