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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" |
8 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
12 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
13 #include "base/values.h" | 17 #include "base/values.h" |
14 #include "chromeos/audio/audio_devices_pref_handler_stub.h" | 18 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
15 #include "chromeos/dbus/audio_node.h" | 19 #include "chromeos/dbus/audio_node.h" |
16 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
17 #include "chromeos/dbus/fake_cras_audio_client.h" | 21 #include "chromeos/dbus/fake_cras_audio_client.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
19 | 23 |
20 namespace chromeos { | 24 namespace chromeos { |
21 namespace { | 25 namespace { |
22 | 26 |
23 const uint64 kInternalSpeakerId = 10001; | 27 const uint64_t kInternalSpeakerId = 10001; |
24 const uint64 kHeadphoneId = 10002; | 28 const uint64_t kHeadphoneId = 10002; |
25 const uint64 kInternalMicId = 10003; | 29 const uint64_t kInternalMicId = 10003; |
26 const uint64 kUSBMicId = 10004; | 30 const uint64_t kUSBMicId = 10004; |
27 const uint64 kBluetoothHeadsetId = 10005; | 31 const uint64_t kBluetoothHeadsetId = 10005; |
28 const uint64 kHDMIOutputId = 10006; | 32 const uint64_t kHDMIOutputId = 10006; |
29 const uint64 kUSBHeadphoneId1 = 10007; | 33 const uint64_t kUSBHeadphoneId1 = 10007; |
30 const uint64 kUSBHeadphoneId2 = 10008; | 34 const uint64_t kUSBHeadphoneId2 = 10008; |
31 const uint64 kMicJackId = 10009; | 35 const uint64_t kMicJackId = 10009; |
32 const uint64 kKeyboardMicId = 10010; | 36 const uint64_t kKeyboardMicId = 10010; |
33 const uint64 kOtherTypeOutputId = 90001; | 37 const uint64_t kOtherTypeOutputId = 90001; |
34 const uint64 kOtherTypeInputId = 90002; | 38 const uint64_t kOtherTypeInputId = 90002; |
35 const uint64 kUSBJabraSpeakerOutputId1 = 90003; | 39 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; |
36 const uint64 kUSBJabraSpeakerOutputId2 = 90004; | 40 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; |
37 const uint64 kUSBJabraSpeakerInputId1 = 90005; | 41 const uint64_t kUSBJabraSpeakerInputId1 = 90005; |
38 const uint64 kUSBJabraSpeakerInputId2 = 90006; | 42 const uint64_t kUSBJabraSpeakerInputId2 = 90006; |
39 const uint64 kUSBCameraInputId = 90007; | 43 const uint64_t kUSBCameraInputId = 90007; |
40 | 44 |
41 const AudioNode kInternalSpeaker( | 45 const AudioNode kInternalSpeaker( |
42 false, | 46 false, |
43 kInternalSpeakerId, | 47 kInternalSpeakerId, |
44 "Fake Speaker", | 48 "Fake Speaker", |
45 "INTERNAL_SPEAKER", | 49 "INTERNAL_SPEAKER", |
46 "Speaker", | 50 "Speaker", |
47 false, | 51 false, |
48 0 | 52 0 |
49 ); | 53 ); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 262 |
259 void OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) override { | 263 void OnOutputMuteChanged(bool /* mute_on */, bool system_adjust) override { |
260 ++output_mute_changed_count_; | 264 ++output_mute_changed_count_; |
261 output_mute_by_system_ = system_adjust; | 265 output_mute_by_system_ = system_adjust; |
262 } | 266 } |
263 | 267 |
264 void OnInputMuteChanged(bool /* mute_on */) override { | 268 void OnInputMuteChanged(bool /* mute_on */) override { |
265 ++input_mute_changed_count_; | 269 ++input_mute_changed_count_; |
266 } | 270 } |
267 | 271 |
268 void OnOutputNodeVolumeChanged(uint64 /* node_id */, | 272 void OnOutputNodeVolumeChanged(uint64_t /* node_id */, |
269 int /* volume */) override { | 273 int /* volume */) override { |
270 ++output_volume_changed_count_; | 274 ++output_volume_changed_count_; |
271 } | 275 } |
272 | 276 |
273 void OnInputNodeGainChanged(uint64 /* node_id */, int /* gain */) override { | 277 void OnInputNodeGainChanged(uint64_t /* node_id */, int /* gain */) override { |
274 ++input_gain_changed_count_; | 278 ++input_gain_changed_count_; |
275 } | 279 } |
276 | 280 |
277 private: | 281 private: |
278 int active_output_node_changed_count_; | 282 int active_output_node_changed_count_; |
279 int active_input_node_changed_count_; | 283 int active_input_node_changed_count_; |
280 int audio_nodes_changed_count_; | 284 int audio_nodes_changed_count_; |
281 int output_mute_changed_count_; | 285 int output_mute_changed_count_; |
282 int input_mute_changed_count_; | 286 int input_mute_changed_count_; |
283 int output_volume_changed_count_; | 287 int output_volume_changed_count_; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 cras_audio_handler_->AddAudioObserver(test_observer_.get()); | 338 cras_audio_handler_->AddAudioObserver(test_observer_.get()); |
335 message_loop_.RunUntilIdle(); | 339 message_loop_.RunUntilIdle(); |
336 } | 340 } |
337 | 341 |
338 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { | 342 void ChangeAudioNodes(const AudioNodeList& audio_nodes) { |
339 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( | 343 fake_cras_audio_client_->SetAudioNodesAndNotifyObserversForTesting( |
340 audio_nodes); | 344 audio_nodes); |
341 message_loop_.RunUntilIdle(); | 345 message_loop_.RunUntilIdle(); |
342 } | 346 } |
343 | 347 |
344 const AudioDevice* GetDeviceFromId(uint64 id) { | 348 const AudioDevice* GetDeviceFromId(uint64_t id) { |
345 return cras_audio_handler_->GetDeviceFromId(id); | 349 return cras_audio_handler_->GetDeviceFromId(id); |
346 } | 350 } |
347 | 351 |
348 int GetActiveDeviceCount() const { | 352 int GetActiveDeviceCount() const { |
349 int num_active_nodes = 0; | 353 int num_active_nodes = 0; |
350 AudioDeviceList audio_devices; | 354 AudioDeviceList audio_devices; |
351 cras_audio_handler_->GetAudioDevices(&audio_devices); | 355 cras_audio_handler_->GetAudioDevices(&audio_devices); |
352 for (size_t i = 0; i < audio_devices.size(); ++i) { | 356 for (size_t i = 0; i < audio_devices.size(); ++i) { |
353 if (audio_devices[i].active) | 357 if (audio_devices[i].active) |
354 ++num_active_nodes; | 358 ++num_active_nodes; |
(...skipping 2296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2651 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 2655 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
2652 EXPECT_EQ(kInternalSpeaker.id, active_output.id); | 2656 EXPECT_EQ(kInternalSpeaker.id, active_output.id); |
2653 EXPECT_EQ(kInternalSpeaker.id, | 2657 EXPECT_EQ(kInternalSpeaker.id, |
2654 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 2658 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
2655 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 2659 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
2656 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 2660 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
2657 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 2661 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
2658 } | 2662 } |
2659 | 2663 |
2660 } // namespace chromeos | 2664 } // namespace chromeos |
OLD | NEW |