OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "chromeos/audio/audio_pref_handler.h" | 13 #include "chromeos/audio/audio_pref_handler.h" |
14 #include "chromeos/audio/mock_cras_audio_handler.h" | |
14 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
15 | 16 |
16 using std::max; | 17 using std::max; |
17 using std::min; | 18 using std::min; |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // Default value for unmuting, as a percent in the range [0, 100]. | 24 // Default value for unmuting, as a percent in the range [0, 100]. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 } | 57 } |
57 | 58 |
58 // static | 59 // static |
59 void CrasAudioHandler::Initialize( | 60 void CrasAudioHandler::Initialize( |
60 scoped_refptr<AudioPrefHandler> audio_pref_handler) { | 61 scoped_refptr<AudioPrefHandler> audio_pref_handler) { |
61 CHECK(!g_cras_audio_handler); | 62 CHECK(!g_cras_audio_handler); |
62 g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); | 63 g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); |
63 } | 64 } |
64 | 65 |
65 // static | 66 // static |
67 void CrasAudioHandler::InitializeForTesting() { | |
68 CHECK(!g_cras_audio_handler); | |
69 g_cras_audio_handler = new MockCrasAudioHandler(); | |
70 } | |
71 | |
72 // static | |
66 void CrasAudioHandler::Shutdown() { | 73 void CrasAudioHandler::Shutdown() { |
67 CHECK(g_cras_audio_handler); | 74 CHECK(g_cras_audio_handler); |
68 delete g_cras_audio_handler; | 75 delete g_cras_audio_handler; |
69 g_cras_audio_handler = NULL; | 76 g_cras_audio_handler = NULL; |
70 } | 77 } |
71 | 78 |
72 // static | 79 // static |
73 bool CrasAudioHandler::IsInitialized() { | 80 bool CrasAudioHandler::IsInitialized() { |
74 return g_cras_audio_handler != NULL; | 81 return g_cras_audio_handler != NULL; |
75 } | 82 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 weak_ptr_factory_(this), | 191 weak_ptr_factory_(this), |
185 output_mute_on_(false), | 192 output_mute_on_(false), |
186 input_mute_on_(false), | 193 input_mute_on_(false), |
187 output_volume_(0), | 194 output_volume_(0), |
188 active_output_node_id_(0), | 195 active_output_node_id_(0), |
189 active_input_node_id_(0), | 196 active_input_node_id_(0), |
190 has_alternative_input_(false), | 197 has_alternative_input_(false), |
191 has_alternative_output_(false), | 198 has_alternative_output_(false), |
192 output_mute_locked_(false), | 199 output_mute_locked_(false), |
193 input_mute_locked_(false) { | 200 input_mute_locked_(false) { |
201 // If the DBusThreadManager isn't initialized, there isn't anything we can | |
202 // do. This usually happens when running in a test. | |
203 if (!chromeos::DBusThreadManager::IsInitialized()) | |
204 return; | |
194 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); | 205 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); |
195 DCHECK(audio_pref_handler_.get()); | 206 DCHECK(audio_pref_handler_.get()); |
196 audio_pref_handler_->AddAudioPrefObserver(this); | 207 audio_pref_handler_->AddAudioPrefObserver(this); |
197 SetupInitialAudioState(); | 208 SetupInitialAudioState(); |
198 } | 209 } |
199 | 210 |
200 CrasAudioHandler::~CrasAudioHandler() { | 211 CrasAudioHandler::~CrasAudioHandler() { |
201 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 212 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
202 RemoveObserver(this); | 213 RemoveObserver(this); |
203 audio_pref_handler_->RemoveAudioPrefObserver(this); | 214 audio_pref_handler_->RemoveAudioPrefObserver(this); |
204 audio_pref_handler_ = NULL; | 215 audio_pref_handler_ = NULL; |
205 } | 216 } |
206 | 217 |
218 CrasAudioHandler::CrasAudioHandler() | |
James Cook
2013/04/30 20:55:05
Do you really need this extra constructor, or coul
rkc
2013/04/30 23:04:57
Done.
| |
219 : audio_pref_handler_(NULL), | |
220 weak_ptr_factory_(this), | |
221 output_mute_on_(false), | |
222 input_mute_on_(false), | |
223 output_volume_(0), | |
224 active_output_node_id_(0), | |
225 active_input_node_id_(0), | |
226 has_alternative_input_(false), | |
227 has_alternative_output_(false), | |
228 output_mute_locked_(false), | |
229 input_mute_locked_(false) { | |
230 } | |
231 | |
207 void CrasAudioHandler::AudioClientRestarted() { | 232 void CrasAudioHandler::AudioClientRestarted() { |
208 SetupInitialAudioState(); | 233 SetupInitialAudioState(); |
209 } | 234 } |
210 | 235 |
211 void CrasAudioHandler::OutputVolumeChanged(int volume) { | 236 void CrasAudioHandler::OutputVolumeChanged(int volume) { |
212 if (output_volume_ == volume) | 237 if (output_volume_ == volume) |
213 return; | 238 return; |
214 | 239 |
215 output_volume_ = volume; | 240 output_volume_ = volume; |
216 audio_pref_handler_->SetOutputVolumeValue(output_volume_); | 241 audio_pref_handler_->SetOutputVolumeValue(output_volume_); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 !device.is_input && | 354 !device.is_input && |
330 device.type != AUDIO_TYPE_INTERNAL) { | 355 device.type != AUDIO_TYPE_INTERNAL) { |
331 has_alternative_output_ = true; | 356 has_alternative_output_ = true; |
332 } | 357 } |
333 } | 358 } |
334 | 359 |
335 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); | 360 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
336 } | 361 } |
337 | 362 |
338 } // namespace chromeos | 363 } // namespace chromeos |
OLD | NEW |