1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/audio/mock_audio_manager.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/check.h"
12 #include "media/audio/mock_audio_debug_recording_manager.h"
13 #include "media/base/audio_parameters.h"
14
15 namespace media {
16
MockAudioManager(std::unique_ptr<AudioThread> audio_thread)17 MockAudioManager::MockAudioManager(std::unique_ptr<AudioThread> audio_thread)
18 : AudioManager(std::move(audio_thread)) {}
19
20 MockAudioManager::~MockAudioManager() = default;
21
ShutdownOnAudioThread()22 void MockAudioManager::ShutdownOnAudioThread() {
23 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
24 }
25
HasAudioOutputDevices()26 bool MockAudioManager::HasAudioOutputDevices() {
27 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
28 return has_output_devices_;
29 }
30
HasAudioInputDevices()31 bool MockAudioManager::HasAudioInputDevices() {
32 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
33 return has_input_devices_;
34 }
35
GetAudioInputDeviceDescriptions(AudioDeviceDescriptions * device_descriptions)36 void MockAudioManager::GetAudioInputDeviceDescriptions(
37 AudioDeviceDescriptions* device_descriptions) {
38 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
39 if (!get_input_device_descriptions_cb_)
40 return;
41 get_input_device_descriptions_cb_.Run(device_descriptions);
42 }
43
GetAudioOutputDeviceDescriptions(AudioDeviceDescriptions * device_descriptions)44 void MockAudioManager::GetAudioOutputDeviceDescriptions(
45 AudioDeviceDescriptions* device_descriptions) {
46 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
47 if (!get_output_device_descriptions_cb_)
48 return;
49 get_output_device_descriptions_cb_.Run(device_descriptions);
50 }
51
MakeAudioOutputStream(const media::AudioParameters & params,const std::string & device_id,const LogCallback & log_callback)52 media::AudioOutputStream* MockAudioManager::MakeAudioOutputStream(
53 const media::AudioParameters& params,
54 const std::string& device_id,
55 const LogCallback& log_callback) {
56 return MakeAudioOutputStreamProxy(params, device_id);
57 }
58
MakeAudioOutputStreamProxy(const media::AudioParameters & params,const std::string & device_id)59 media::AudioOutputStream* MockAudioManager::MakeAudioOutputStreamProxy(
60 const media::AudioParameters& params,
61 const std::string& device_id) {
62 return make_output_stream_cb_ ? make_output_stream_cb_.Run(params, device_id)
63 : nullptr;
64 }
65
MakeAudioInputStream(const media::AudioParameters & params,const std::string & device_id,const LogCallback & log_callback)66 media::AudioInputStream* MockAudioManager::MakeAudioInputStream(
67 const media::AudioParameters& params,
68 const std::string& device_id,
69 const LogCallback& log_callback) {
70 return make_input_stream_cb_ ? make_input_stream_cb_.Run(params, device_id)
71 : nullptr;
72 }
73
AddOutputDeviceChangeListener(AudioDeviceListener * listener)74 void MockAudioManager::AddOutputDeviceChangeListener(
75 AudioDeviceListener* listener) {
76 }
77
RemoveOutputDeviceChangeListener(AudioDeviceListener * listener)78 void MockAudioManager::RemoveOutputDeviceChangeListener(
79 AudioDeviceListener* listener) {
80 }
81
GetDefaultOutputStreamParameters()82 AudioParameters MockAudioManager::GetDefaultOutputStreamParameters() {
83 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
84 return default_output_params_;
85 }
86
GetOutputStreamParameters(const std::string & device_id)87 AudioParameters MockAudioManager::GetOutputStreamParameters(
88 const std::string& device_id) {
89 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
90 return output_params_;
91 }
92
GetInputStreamParameters(const std::string & device_id)93 AudioParameters MockAudioManager::GetInputStreamParameters(
94 const std::string& device_id) {
95 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
96 return input_params_;
97 }
98
GetAssociatedOutputDeviceID(const std::string & input_device_id)99 std::string MockAudioManager::GetAssociatedOutputDeviceID(
100 const std::string& input_device_id) {
101 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
102 return get_associated_output_device_id_cb_
103 ? get_associated_output_device_id_cb_.Run(input_device_id)
104 : std::string();
105 }
106
GetDefaultInputDeviceID()107 std::string MockAudioManager::GetDefaultInputDeviceID() {
108 return std::string();
109 }
GetDefaultOutputDeviceID()110 std::string MockAudioManager::GetDefaultOutputDeviceID() {
111 return std::string();
112 }
GetCommunicationsInputDeviceID()113 std::string MockAudioManager::GetCommunicationsInputDeviceID() {
114 return std::string();
115 }
GetCommunicationsOutputDeviceID()116 std::string MockAudioManager::GetCommunicationsOutputDeviceID() {
117 return std::string();
118 }
119
CreateAudioLog(AudioLogFactory::AudioComponent component,int component_id)120 std::unique_ptr<AudioLog> MockAudioManager::CreateAudioLog(
121 AudioLogFactory::AudioComponent component,
122 int component_id) {
123 return nullptr;
124 }
125
InitializeDebugRecording()126 void MockAudioManager::InitializeDebugRecording() {
127 if (!GetTaskRunner()->BelongsToCurrentThread()) {
128 GetTaskRunner()->PostTask(
129 FROM_HERE, base::BindOnce(&MockAudioManager::InitializeDebugRecording,
130 base::Unretained(this)));
131 return;
132 }
133
134 DCHECK(!debug_recording_manager_);
135 debug_recording_manager_ =
136 std::make_unique<MockAudioDebugRecordingManager>(GetTaskRunner());
137 }
138
GetAudioDebugRecordingManager()139 AudioDebugRecordingManager* MockAudioManager::GetAudioDebugRecordingManager() {
140 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
141 return debug_recording_manager_.get();
142 }
143
GetName()144 const char* MockAudioManager::GetName() {
145 return nullptr;
146 }
147
SetMakeOutputStreamCB(MakeOutputStreamCallback cb)148 void MockAudioManager::SetMakeOutputStreamCB(MakeOutputStreamCallback cb) {
149 make_output_stream_cb_ = std::move(cb);
150 }
151
SetMakeInputStreamCB(MakeInputStreamCallback cb)152 void MockAudioManager::SetMakeInputStreamCB(MakeInputStreamCallback cb) {
153 make_input_stream_cb_ = std::move(cb);
154 }
155
SetInputStreamParameters(const AudioParameters & params)156 void MockAudioManager::SetInputStreamParameters(const AudioParameters& params) {
157 input_params_ = params;
158 }
159
SetOutputStreamParameters(const AudioParameters & params)160 void MockAudioManager::SetOutputStreamParameters(
161 const AudioParameters& params) {
162 output_params_ = params;
163 }
164
SetDefaultOutputStreamParameters(const AudioParameters & params)165 void MockAudioManager::SetDefaultOutputStreamParameters(
166 const AudioParameters& params) {
167 default_output_params_ = params;
168 }
169
SetHasInputDevices(bool has_input_devices)170 void MockAudioManager::SetHasInputDevices(bool has_input_devices) {
171 has_input_devices_ = has_input_devices;
172 }
173
SetHasOutputDevices(bool has_output_devices)174 void MockAudioManager::SetHasOutputDevices(bool has_output_devices) {
175 has_output_devices_ = has_output_devices;
176 }
177
SetInputDeviceDescriptionsCallback(GetDeviceDescriptionsCallback callback)178 void MockAudioManager::SetInputDeviceDescriptionsCallback(
179 GetDeviceDescriptionsCallback callback) {
180 get_input_device_descriptions_cb_ = std::move(callback);
181 }
182
SetOutputDeviceDescriptionsCallback(GetDeviceDescriptionsCallback callback)183 void MockAudioManager::SetOutputDeviceDescriptionsCallback(
184 GetDeviceDescriptionsCallback callback) {
185 get_output_device_descriptions_cb_ = std::move(callback);
186 }
187
SetAssociatedOutputDeviceIDCallback(GetAssociatedOutputDeviceIDCallback callback)188 void MockAudioManager::SetAssociatedOutputDeviceIDCallback(
189 GetAssociatedOutputDeviceIDCallback callback) {
190 get_associated_output_device_id_cb_ = std::move(callback);
191 }
192
193 } // namespace media.
194