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> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chromeos/audio/audio_devices_pref_handler.h" | 19 #include "chromeos/audio/audio_devices_pref_handler.h" |
20 #include "chromeos/audio/audio_devices_pref_handler_stub.h" | 20 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
21 #include "chromeos/dbus/audio_node.h" | 21 #include "chromeos/dbus/audio_node.h" |
22 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
23 #include "chromeos/dbus/fake_cras_audio_client.h" | 23 #include "chromeos/dbus/fake_cras_audio_client.h" |
| 24 #include "media/base/video_facing.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 namespace chromeos { | 27 namespace chromeos { |
27 namespace { | 28 namespace { |
28 | 29 |
29 const uint64_t kInternalSpeakerId = 10001; | 30 const uint64_t kInternalSpeakerId = 10001; |
30 const uint64_t kHeadphoneId = 10002; | 31 const uint64_t kHeadphoneId = 10002; |
31 const uint64_t kInternalMicId = 10003; | 32 const uint64_t kInternalMicId = 10003; |
32 const uint64_t kUSBMicId = 10004; | 33 const uint64_t kUSBMicId = 10004; |
33 const uint64_t kBluetoothHeadsetId = 10005; | 34 const uint64_t kBluetoothHeadsetId = 10005; |
34 const uint64_t kHDMIOutputId = 10006; | 35 const uint64_t kHDMIOutputId = 10006; |
35 const uint64_t kUSBHeadphoneId1 = 10007; | 36 const uint64_t kUSBHeadphoneId1 = 10007; |
36 const uint64_t kUSBHeadphoneId2 = 10008; | 37 const uint64_t kUSBHeadphoneId2 = 10008; |
37 const uint64_t kMicJackId = 10009; | 38 const uint64_t kMicJackId = 10009; |
38 const uint64_t kKeyboardMicId = 10010; | 39 const uint64_t kKeyboardMicId = 10010; |
| 40 const uint64_t kFrontMicId = 10011; |
| 41 const uint64_t kRearMicId = 10012; |
39 const uint64_t kOtherTypeOutputId = 90001; | 42 const uint64_t kOtherTypeOutputId = 90001; |
40 const uint64_t kOtherTypeInputId = 90002; | 43 const uint64_t kOtherTypeInputId = 90002; |
41 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; | 44 const uint64_t kUSBJabraSpeakerOutputId1 = 90003; |
42 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; | 45 const uint64_t kUSBJabraSpeakerOutputId2 = 90004; |
43 const uint64_t kUSBJabraSpeakerInputId1 = 90005; | 46 const uint64_t kUSBJabraSpeakerInputId1 = 90005; |
44 const uint64_t kUSBJabraSpeakerInputId2 = 90006; | 47 const uint64_t kUSBJabraSpeakerInputId2 = 90006; |
45 const uint64_t kUSBCameraInputId = 90007; | 48 const uint64_t kUSBCameraInputId = 90007; |
46 | 49 |
47 struct AudioNodeInfo { | 50 struct AudioNodeInfo { |
48 bool is_input; | 51 bool is_input; |
(...skipping 15 matching lines...) Expand all Loading... |
64 const AudioNodeInfo kMicJack[] = { | 67 const AudioNodeInfo kMicJack[] = { |
65 {true, kMicJackId, "Fake Mic Jack", "MIC", "Mic Jack"}}; | 68 {true, kMicJackId, "Fake Mic Jack", "MIC", "Mic Jack"}}; |
66 | 69 |
67 const AudioNodeInfo kUSBMic[] = { | 70 const AudioNodeInfo kUSBMic[] = { |
68 {true, kUSBMicId, "Fake USB Mic", "USB", "USB Microphone"}}; | 71 {true, kUSBMicId, "Fake USB Mic", "USB", "USB Microphone"}}; |
69 | 72 |
70 const AudioNodeInfo kKeyboardMic[] = {{true, kKeyboardMicId, | 73 const AudioNodeInfo kKeyboardMic[] = {{true, kKeyboardMicId, |
71 "Fake Keyboard Mic", "KEYBOARD_MIC", | 74 "Fake Keyboard Mic", "KEYBOARD_MIC", |
72 "Keyboard Mic"}}; | 75 "Keyboard Mic"}}; |
73 | 76 |
| 77 const AudioNodeInfo kFrontMic[] = { |
| 78 {true, kFrontMicId, "Fake Front Mic", "FRONT_MIC", "Front Mic"}}; |
| 79 |
| 80 const AudioNodeInfo kRearMic[] = { |
| 81 {true, kRearMicId, "Fake Rear Mic", "REAR_MIC", "Rear Mic"}}; |
| 82 |
74 const AudioNodeInfo kOtherTypeOutput[] = {{false, kOtherTypeOutputId, | 83 const AudioNodeInfo kOtherTypeOutput[] = {{false, kOtherTypeOutputId, |
75 "Output Device", "SOME_OTHER_TYPE", | 84 "Output Device", "SOME_OTHER_TYPE", |
76 "Other Type Output Device"}}; | 85 "Other Type Output Device"}}; |
77 | 86 |
78 const AudioNodeInfo kOtherTypeInput[] = {{true, kOtherTypeInputId, | 87 const AudioNodeInfo kOtherTypeInput[] = {{true, kOtherTypeInputId, |
79 "Input Device", "SOME_OTHER_TYPE", | 88 "Input Device", "SOME_OTHER_TYPE", |
80 "Other Type Input Device"}}; | 89 "Other Type Input Device"}}; |
81 | 90 |
82 const AudioNodeInfo kBluetoothHeadset[] = {{false, kBluetoothHeadsetId, | 91 const AudioNodeInfo kBluetoothHeadset[] = {{false, kBluetoothHeadsetId, |
83 "Bluetooth Headset", "BLUETOOTH", | 92 "Bluetooth Headset", "BLUETOOTH", |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 int output_mute_changed_count_ = 0; | 213 int output_mute_changed_count_ = 0; |
205 int input_mute_changed_count_ = 0; | 214 int input_mute_changed_count_ = 0; |
206 int output_volume_changed_count_ = 0; | 215 int output_volume_changed_count_ = 0; |
207 int input_gain_changed_count_ = 0; | 216 int input_gain_changed_count_ = 0; |
208 bool output_mute_by_system_ = false; // output mute state adjusted by system. | 217 bool output_mute_by_system_ = false; // output mute state adjusted by system. |
209 int output_channel_remixing_changed_count_ = 0; | 218 int output_channel_remixing_changed_count_ = 0; |
210 | 219 |
211 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 220 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
212 }; | 221 }; |
213 | 222 |
| 223 class FakeVideoCaptureManager { |
| 224 public: |
| 225 FakeVideoCaptureManager() {} |
| 226 virtual ~FakeVideoCaptureManager() {} |
| 227 |
| 228 void AddObserver(media::VideoCaptureObserver* observer) { |
| 229 observers_.AddObserver(observer); |
| 230 } |
| 231 |
| 232 void RemoveAllObservers() { observers_.Clear(); } |
| 233 |
| 234 void NotifyVideoCaptureStarted(media::VideoFacingMode facing) { |
| 235 for (auto& observer : observers_) |
| 236 observer.OnVideoCaptureStarted(facing); |
| 237 } |
| 238 |
| 239 void NotifyVideoCaptureStopped(media::VideoFacingMode facing) { |
| 240 for (auto& observer : observers_) |
| 241 observer.OnVideoCaptureStopped(facing); |
| 242 } |
| 243 |
| 244 private: |
| 245 base::ObserverList<media::VideoCaptureObserver> observers_; |
| 246 DISALLOW_COPY_AND_ASSIGN(FakeVideoCaptureManager); |
| 247 }; |
| 248 |
214 } // namespace | 249 } // namespace |
215 | 250 |
216 // Test param is the version of stabel device id used by audio node. | 251 // Test param is the version of stabel device id used by audio node. |
217 class CrasAudioHandlerTest : public testing::TestWithParam<int> { | 252 class CrasAudioHandlerTest : public testing::TestWithParam<int> { |
218 public: | 253 public: |
219 CrasAudioHandlerTest() {} | 254 CrasAudioHandlerTest() {} |
220 ~CrasAudioHandlerTest() override {} | 255 ~CrasAudioHandlerTest() override {} |
221 | 256 |
222 void SetUp() override {} | 257 void SetUp() override { |
| 258 video_capture_manager_.reset(new FakeVideoCaptureManager); |
| 259 } |
223 | 260 |
224 void TearDown() override { | 261 void TearDown() override { |
225 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); | 262 cras_audio_handler_->RemoveAudioObserver(test_observer_.get()); |
226 test_observer_.reset(); | 263 test_observer_.reset(); |
| 264 video_capture_manager_->RemoveAllObservers(); |
| 265 video_capture_manager_.reset(); |
227 CrasAudioHandler::Shutdown(); | 266 CrasAudioHandler::Shutdown(); |
228 audio_pref_handler_ = nullptr; | 267 audio_pref_handler_ = nullptr; |
229 DBusThreadManager::Shutdown(); | 268 DBusThreadManager::Shutdown(); |
230 } | 269 } |
231 | 270 |
232 AudioNode GenerateAudioNode(const AudioNodeInfo* node_info) { | 271 AudioNode GenerateAudioNode(const AudioNodeInfo* node_info) { |
233 uint64_t stable_device_id_v2 = GetParam() == 1 ? 0 : (node_info->id ^ 0xFF); | 272 uint64_t stable_device_id_v2 = GetParam() == 1 ? 0 : (node_info->id ^ 0xFF); |
234 uint64_t stable_device_id_v1 = node_info->id; | 273 uint64_t stable_device_id_v1 = node_info->id; |
235 return AudioNode(node_info->is_input, node_info->id, GetParam() == 2, | 274 return AudioNode(node_info->is_input, node_info->id, GetParam() == 2, |
236 stable_device_id_v1, stable_device_id_v2, | 275 stable_device_id_v1, stable_device_id_v2, |
(...skipping 13 matching lines...) Expand all Loading... |
250 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) { | 289 void SetUpCrasAudioHandler(const AudioNodeList& audio_nodes) { |
251 DBusThreadManager::Initialize(); | 290 DBusThreadManager::Initialize(); |
252 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>( | 291 fake_cras_audio_client_ = static_cast<FakeCrasAudioClient*>( |
253 DBusThreadManager::Get()->GetCrasAudioClient()); | 292 DBusThreadManager::Get()->GetCrasAudioClient()); |
254 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); | 293 fake_cras_audio_client_->SetAudioNodesForTesting(audio_nodes); |
255 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); | 294 audio_pref_handler_ = new AudioDevicesPrefHandlerStub(); |
256 CrasAudioHandler::Initialize(audio_pref_handler_); | 295 CrasAudioHandler::Initialize(audio_pref_handler_); |
257 cras_audio_handler_ = CrasAudioHandler::Get(); | 296 cras_audio_handler_ = CrasAudioHandler::Get(); |
258 test_observer_.reset(new TestObserver); | 297 test_observer_.reset(new TestObserver); |
259 cras_audio_handler_->AddAudioObserver(test_observer_.get()); | 298 cras_audio_handler_->AddAudioObserver(test_observer_.get()); |
| 299 video_capture_manager_->AddObserver(cras_audio_handler_); |
260 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
261 } | 301 } |
262 | 302 |
263 // Set up cras audio handlers with |audio_nodes| and set the active state of | 303 // Set up cras audio handlers with |audio_nodes| and set the active state of |
264 // |active_device_in_pref| as active and |activate_by_user| in the pref, | 304 // |active_device_in_pref| as active and |activate_by_user| in the pref, |
265 // and rest of nodes in |audio_nodes_in_pref| as inactive. | 305 // and rest of nodes in |audio_nodes_in_pref| as inactive. |
266 void SetupCrasAudioHandlerWithActiveNodeInPref( | 306 void SetupCrasAudioHandlerWithActiveNodeInPref( |
267 const AudioNodeList& audio_nodes, | 307 const AudioNodeList& audio_nodes, |
268 const AudioNodeList& audio_nodes_in_pref, | 308 const AudioNodeList& audio_nodes_in_pref, |
269 const AudioDevice& active_device_in_pref, | 309 const AudioDevice& active_device_in_pref, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 381 |
342 bool IsDuringHDMIRediscoverGracePeriod() { | 382 bool IsDuringHDMIRediscoverGracePeriod() { |
343 return cras_audio_handler_->hdmi_rediscovering(); | 383 return cras_audio_handler_->hdmi_rediscovering(); |
344 } | 384 } |
345 | 385 |
346 void RestartAudioClient() { | 386 void RestartAudioClient() { |
347 cras_audio_handler_->AudioClientRestarted(); | 387 cras_audio_handler_->AudioClientRestarted(); |
348 base::RunLoop().RunUntilIdle(); | 388 base::RunLoop().RunUntilIdle(); |
349 } | 389 } |
350 | 390 |
| 391 void StartFrontFacingCamera() { |
| 392 video_capture_manager_->NotifyVideoCaptureStarted( |
| 393 media::MEDIA_VIDEO_FACING_USER); |
| 394 } |
| 395 |
| 396 void StopFrontFacingCamera() { |
| 397 video_capture_manager_->NotifyVideoCaptureStopped( |
| 398 media::MEDIA_VIDEO_FACING_USER); |
| 399 } |
| 400 |
| 401 void StartRearFacingCamera() { |
| 402 video_capture_manager_->NotifyVideoCaptureStarted( |
| 403 media::MEDIA_VIDEO_FACING_ENVIRONMENT); |
| 404 } |
| 405 |
| 406 void StopRearFacingCamera() { |
| 407 video_capture_manager_->NotifyVideoCaptureStopped( |
| 408 media::MEDIA_VIDEO_FACING_ENVIRONMENT); |
| 409 } |
| 410 |
351 protected: | 411 protected: |
352 base::MessageLoopForUI message_loop_; | 412 base::MessageLoopForUI message_loop_; |
353 CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. | 413 CrasAudioHandler* cras_audio_handler_ = nullptr; // Not owned. |
354 FakeCrasAudioClient* fake_cras_audio_client_ = nullptr; // Not owned. | 414 FakeCrasAudioClient* fake_cras_audio_client_ = nullptr; // Not owned. |
355 std::unique_ptr<TestObserver> test_observer_; | 415 std::unique_ptr<TestObserver> test_observer_; |
356 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; | 416 scoped_refptr<AudioDevicesPrefHandlerStub> audio_pref_handler_; |
| 417 std::unique_ptr<FakeVideoCaptureManager> video_capture_manager_; |
357 | 418 |
358 private: | 419 private: |
359 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); | 420 DISALLOW_COPY_AND_ASSIGN(CrasAudioHandlerTest); |
360 }; | 421 }; |
361 | 422 |
362 class HDMIRediscoverWaiter { | 423 class HDMIRediscoverWaiter { |
363 public: | 424 public: |
364 HDMIRediscoverWaiter(CrasAudioHandlerTest* cras_audio_handler_test, | 425 HDMIRediscoverWaiter(CrasAudioHandlerTest* cras_audio_handler_test, |
365 int grace_period_duration_in_ms) | 426 int grace_period_duration_in_ms) |
366 : cras_audio_handler_test_(cras_audio_handler_test), | 427 : cras_audio_handler_test_(cras_audio_handler_test), |
(...skipping 3306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3673 EXPECT_TRUE( | 3734 EXPECT_TRUE( |
3674 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); | 3735 cras_audio_handler_->GetPrimaryActiveOutputDevice(&active_output)); |
3675 EXPECT_EQ(kInternalSpeaker->id, active_output.id); | 3736 EXPECT_EQ(kInternalSpeaker->id, active_output.id); |
3676 EXPECT_EQ(kInternalSpeaker->id, | 3737 EXPECT_EQ(kInternalSpeaker->id, |
3677 cras_audio_handler_->GetPrimaryActiveOutputNode()); | 3738 cras_audio_handler_->GetPrimaryActiveOutputNode()); |
3678 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); | 3739 EXPECT_FALSE(cras_audio_handler_->IsOutputMuted()); |
3679 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); | 3740 EXPECT_EQ(1, test_observer_->output_mute_changed_count()); |
3680 EXPECT_TRUE(test_observer_->output_mute_by_system()); | 3741 EXPECT_TRUE(test_observer_->output_mute_by_system()); |
3681 } | 3742 } |
3682 | 3743 |
| 3744 TEST_P(CrasAudioHandlerTest, FrontCameraStartStop) { |
| 3745 AudioNodeList audio_nodes = GenerateAudioNodeList({kFrontMic, kRearMic}); |
| 3746 SetUpCrasAudioHandler(audio_nodes); |
| 3747 |
| 3748 // Verify the audio devices size. |
| 3749 AudioDeviceList audio_devices; |
| 3750 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3751 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3752 |
| 3753 // Verify the front mic has been selected as the active input. |
| 3754 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3755 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3756 |
| 3757 // Start the front facing camera. |
| 3758 StartFrontFacingCamera(); |
| 3759 // Verify the front mic has been selected as the active input. |
| 3760 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3761 |
| 3762 // Stop the front facing camera. |
| 3763 StopFrontFacingCamera(); |
| 3764 // Verify the front mic has been selected as the active input. |
| 3765 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3766 } |
| 3767 |
| 3768 TEST_P(CrasAudioHandlerTest, RearCameraStartStop) { |
| 3769 AudioNodeList audio_nodes = GenerateAudioNodeList({kFrontMic, kRearMic}); |
| 3770 SetUpCrasAudioHandler(audio_nodes); |
| 3771 |
| 3772 // Verify the audio devices size. |
| 3773 AudioDeviceList audio_devices; |
| 3774 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3775 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3776 |
| 3777 // Verify the front mic has been selected as the active input. |
| 3778 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3779 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3780 |
| 3781 // Start the rear facing camera. |
| 3782 StartRearFacingCamera(); |
| 3783 // Verify the active input is switched to the rear mic. |
| 3784 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3785 |
| 3786 // Stop the rear facing camera. |
| 3787 StopRearFacingCamera(); |
| 3788 // Verify the active input is switched back to front mic. |
| 3789 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3790 } |
| 3791 |
| 3792 TEST_P(CrasAudioHandlerTest, SwitchFrontRearCamera) { |
| 3793 AudioNodeList audio_nodes = GenerateAudioNodeList({kFrontMic, kRearMic}); |
| 3794 SetUpCrasAudioHandler(audio_nodes); |
| 3795 |
| 3796 // Verify the audio devices size. |
| 3797 AudioDeviceList audio_devices; |
| 3798 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3799 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3800 |
| 3801 // Verify the front mic has been selected as the active input. |
| 3802 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3803 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3804 |
| 3805 // Start the front facing camera. |
| 3806 StartFrontFacingCamera(); |
| 3807 // Verify the front mic has been selected as the active input. |
| 3808 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3809 |
| 3810 // Simulates the camera app switching from front camera to rear camera. |
| 3811 StopFrontFacingCamera(); |
| 3812 StartRearFacingCamera(); |
| 3813 |
| 3814 // Verify the rear mic has been selected as the active input. |
| 3815 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3816 } |
| 3817 |
| 3818 TEST_P(CrasAudioHandlerTest, StartFrontCameraWithActiveExternalInput) { |
| 3819 AudioNodeList audio_nodes = |
| 3820 GenerateAudioNodeList({kFrontMic, kRearMic, kMicJack}); |
| 3821 SetUpCrasAudioHandler(audio_nodes); |
| 3822 |
| 3823 // Verify the audio devices size. |
| 3824 AudioDeviceList audio_devices; |
| 3825 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3826 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3827 |
| 3828 // Verify the mic Jack has been selected as the active input. |
| 3829 EXPECT_EQ(kMicJackId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3830 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3831 |
| 3832 // Start the front facing camera. |
| 3833 StartFrontFacingCamera(); |
| 3834 // Verify the mic Jack has been selected as the active input. |
| 3835 EXPECT_EQ(kMicJackId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3836 |
| 3837 // Stop the front facing camera. |
| 3838 StopFrontFacingCamera(); |
| 3839 // Verify the mic Jack remains as the active input. |
| 3840 EXPECT_EQ(kMicJackId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3841 } |
| 3842 |
| 3843 TEST_P(CrasAudioHandlerTest, StartFrontCameraWithInactiveExternalInput) { |
| 3844 AudioNodeList audio_nodes = |
| 3845 GenerateAudioNodeList({kFrontMic, kRearMic, kMicJack}); |
| 3846 SetUpCrasAudioHandler(audio_nodes); |
| 3847 |
| 3848 // Verify the audio devices size. |
| 3849 AudioDeviceList audio_devices; |
| 3850 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3851 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3852 |
| 3853 // Verify the mic Jack has been selected as the active input. |
| 3854 EXPECT_EQ(kMicJackId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3855 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3856 |
| 3857 // Change the active input to internal mic. |
| 3858 cras_audio_handler_->SwitchToFrontOrRearMic(); |
| 3859 // Verify the active input has been switched to front mic. |
| 3860 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3861 |
| 3862 // Start the front facing camera. |
| 3863 StartFrontFacingCamera(); |
| 3864 // Verify the front mic has been selected as the active input. |
| 3865 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3866 |
| 3867 // Stop the front facing camera. |
| 3868 StopFrontFacingCamera(); |
| 3869 // Verify the active input remains as front mic. |
| 3870 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3871 } |
| 3872 |
| 3873 TEST_P(CrasAudioHandlerTest, StartFrontCameraWithoutDualMic) { |
| 3874 AudioNodeList audio_nodes = GenerateAudioNodeList({kInternalMic}); |
| 3875 SetUpCrasAudioHandler(audio_nodes); |
| 3876 |
| 3877 // Verify the audio devices size. |
| 3878 AudioDeviceList audio_devices; |
| 3879 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3880 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3881 |
| 3882 // Verify the mic Jack has been selected as the active input. |
| 3883 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3884 EXPECT_FALSE(cras_audio_handler_->HasDualInternalMic()); |
| 3885 |
| 3886 // Start the front facing camera. |
| 3887 StartFrontFacingCamera(); |
| 3888 // Verify the internal mic has been selected as the active input. |
| 3889 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3890 |
| 3891 // Stop the front facing camera. |
| 3892 StopFrontFacingCamera(); |
| 3893 // Verify the active input remains as interanl mic. |
| 3894 EXPECT_EQ(kInternalMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3895 } |
| 3896 |
| 3897 TEST_P(CrasAudioHandlerTest, FrontRearCameraBothOn) { |
| 3898 AudioNodeList audio_nodes = GenerateAudioNodeList({kFrontMic, kRearMic}); |
| 3899 SetUpCrasAudioHandler(audio_nodes); |
| 3900 |
| 3901 // Verify the audio devices size. |
| 3902 AudioDeviceList audio_devices; |
| 3903 cras_audio_handler_->GetAudioDevices(&audio_devices); |
| 3904 EXPECT_EQ(audio_nodes.size(), audio_devices.size()); |
| 3905 |
| 3906 // Verify the front mic has been selected as the active input. |
| 3907 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3908 EXPECT_TRUE(cras_audio_handler_->HasDualInternalMic()); |
| 3909 |
| 3910 // Start the rear facing camera. |
| 3911 StartRearFacingCamera(); |
| 3912 // Verify the rear mic has been selected as the active input. |
| 3913 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3914 |
| 3915 // Start front camera without stopping the front camera. |
| 3916 StartFrontFacingCamera(); |
| 3917 // Verify the active microphone does not change. |
| 3918 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3919 |
| 3920 // Stop the front mic. |
| 3921 StopFrontFacingCamera(); |
| 3922 // Verity the active mic does not change when there is still camera on. |
| 3923 EXPECT_EQ(kRearMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3924 |
| 3925 // Stop the rear mic. |
| 3926 StopRearFacingCamera(); |
| 3927 // Verify the actice mic changes to front mic after both cameras stop. |
| 3928 EXPECT_EQ(kFrontMicId, cras_audio_handler_->GetPrimaryActiveInputNode()); |
| 3929 } |
| 3930 |
3683 } // namespace chromeos | 3931 } // namespace chromeos |
OLD | NEW |