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 MockCodecManager* mock_codec_manager_pimpl_;
GetInstance()20 MockCodecManager* MockCodecManager::GetInstance() {
21 le_audio::CodecManager::GetInstance();
22 return mock_codec_manager_pimpl_;
23 }
24
25 namespace le_audio {
26
27 struct CodecManager::impl : public MockCodecManager {
28 public:
29 impl() = default;
30 ~impl() = default;
31 };
32
CodecManager()33 CodecManager::CodecManager() {}
34
GetCodecLocation() const35 types::CodecLocation CodecManager::GetCodecLocation() const {
36 if (!pimpl_) return types::CodecLocation::HOST;
37 return pimpl_->GetCodecLocation();
38 }
39
UpdateActiveSourceAudioConfig(const stream_configuration & stream_conf,uint16_t delay_ms,std::function<void (const::le_audio::offload_config & config)> update_receiver)40 void CodecManager::UpdateActiveSourceAudioConfig(
41 const stream_configuration& stream_conf, uint16_t delay_ms,
42 std::function<void(const ::le_audio::offload_config& config)>
43 update_receiver) {
44 if (pimpl_)
45 return pimpl_->UpdateActiveSourceAudioConfig(stream_conf, delay_ms,
46 update_receiver);
47 }
48
UpdateActiveSinkAudioConfig(const stream_configuration & stream_conf,uint16_t delay_ms,std::function<void (const::le_audio::offload_config & config)> update_receiver)49 void CodecManager::UpdateActiveSinkAudioConfig(
50 const stream_configuration& stream_conf, uint16_t delay_ms,
51 std::function<void(const ::le_audio::offload_config& config)>
52 update_receiver) {
53 if (pimpl_)
54 return pimpl_->UpdateActiveSinkAudioConfig(stream_conf, delay_ms,
55 update_receiver);
56 }
57
58 const set_configurations::AudioSetConfigurations*
GetOffloadCodecConfig(types::LeAudioContextType ctx_type)59 CodecManager::GetOffloadCodecConfig(types::LeAudioContextType ctx_type) {
60 if (!pimpl_) return nullptr;
61 return pimpl_->GetOffloadCodecConfig(ctx_type);
62 }
63
64 const ::le_audio::broadcast_offload_config*
GetBroadcastOffloadConfig()65 CodecManager::GetBroadcastOffloadConfig() {
66 if (!pimpl_) return nullptr;
67 return pimpl_->GetBroadcastOffloadConfig();
68 }
69
UpdateBroadcastConnHandle(const std::vector<uint16_t> & conn_handle,std::function<void (const::le_audio::broadcast_offload_config & config)> update_receiver)70 void CodecManager::UpdateBroadcastConnHandle(
71 const std::vector<uint16_t>& conn_handle,
72 std::function<void(const ::le_audio::broadcast_offload_config& config)>
73 update_receiver) {
74 if (pimpl_)
75 return pimpl_->UpdateBroadcastConnHandle(conn_handle, update_receiver);
76 }
77
GetAidlVersionInUsed() const78 int CodecManager::GetAidlVersionInUsed() const {
79 if (!pimpl_) return -1;
80 return pimpl_->GetAidlVersionInUsed();
81 }
82
Start(const std::vector<bluetooth::le_audio::btle_audio_codec_config_t> & offloading_preference)83 void CodecManager::Start(
84 const std::vector<bluetooth::le_audio::btle_audio_codec_config_t>&
85 offloading_preference) {
86 // It is needed here as CodecManager which is a singleton creates it, but in
87 // this mock we want to destroy and recreate the mock on each test case.
88 if (!pimpl_) {
89 pimpl_ = std::make_unique<testing::NiceMock<impl>>();
90 }
91
92 mock_codec_manager_pimpl_ = pimpl_.get();
93 pimpl_->Start();
94 }
95
Stop()96 void CodecManager::Stop() {
97 // It is needed here as CodecManager which is a singleton creates it, but in
98 // this mock we want to destroy and recreate the mock on each test case.
99 if (pimpl_) {
100 pimpl_->Stop();
101 pimpl_.reset();
102 }
103
104 mock_codec_manager_pimpl_ = nullptr;
105 }
106
107 // CodecManager::~CodecManager() = default;
108
109 } // namespace le_audio
110