OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "media/audio/audio_manager.h" | 5 #include "media/audio/audio_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/test_message_loop.h" | 17 #include "base/test/test_message_loop.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "media/audio/audio_device_description.h" | 20 #include "media/audio/audio_device_description.h" |
20 #include "media/audio/audio_device_name.h" | 21 #include "media/audio/audio_device_name.h" |
21 #include "media/audio/audio_output_proxy.h" | 22 #include "media/audio/audio_output_proxy.h" |
22 #include "media/audio/audio_unittest_util.h" | 23 #include "media/audio/audio_unittest_util.h" |
23 #include "media/audio/fake_audio_log_factory.h" | 24 #include "media/audio/fake_audio_log_factory.h" |
24 #include "media/audio/fake_audio_manager.h" | 25 #include "media/audio/fake_audio_manager.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
26 | 28 |
27 #if defined(USE_ALSA) | 29 #if defined(USE_ALSA) |
28 #include "media/audio/alsa/audio_manager_alsa.h" | 30 #include "media/audio/alsa/audio_manager_alsa.h" |
29 #endif // defined(USE_ALSA) | 31 #endif // defined(USE_ALSA) |
30 | 32 |
31 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
32 #include "base/win/scoped_com_initializer.h" | 34 #include "base/win/scoped_com_initializer.h" |
33 #include "media/audio/win/audio_manager_win.h" | 35 #include "media/audio/win/audio_manager_win.h" |
34 #endif | 36 #endif |
35 | 37 |
36 #if defined(USE_PULSEAUDIO) | 38 #if defined(USE_PULSEAUDIO) |
37 #include "media/audio/pulse/audio_manager_pulse.h" | 39 #include "media/audio/pulse/audio_manager_pulse.h" |
38 #endif // defined(USE_PULSEAUDIO) | 40 #endif // defined(USE_PULSEAUDIO) |
39 | 41 |
40 #if defined(USE_CRAS) | 42 #if defined(USE_CRAS) |
41 #include "chromeos/audio/audio_devices_pref_handler_stub.h" | 43 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
42 #include "chromeos/audio/cras_audio_handler.h" | 44 #include "chromeos/audio/cras_audio_handler.h" |
43 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
44 #include "chromeos/dbus/fake_cras_audio_client.h" | 46 #include "chromeos/dbus/fake_cras_audio_client.h" |
45 #include "media/audio/cras/audio_manager_cras.h" | 47 #include "media/audio/cras/audio_manager_cras.h" |
46 #endif // defined(USE_CRAS) | 48 #endif // defined(USE_CRAS) |
47 | 49 |
48 namespace media { | 50 namespace media { |
49 | 51 |
50 namespace { | 52 namespace { |
| 53 |
51 template <typename T> | 54 template <typename T> |
52 struct TestAudioManagerFactory { | 55 struct TestAudioManagerFactory { |
53 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 56 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { |
54 return ScopedAudioManagerPtr(new T(base::ThreadTaskRunnerHandle::Get(), | 57 return ScopedAudioManagerPtr(new T(base::ThreadTaskRunnerHandle::Get(), |
55 base::ThreadTaskRunnerHandle::Get(), | 58 base::ThreadTaskRunnerHandle::Get(), |
56 audio_log_factory)); | 59 audio_log_factory)); |
57 } | 60 } |
58 }; | 61 }; |
59 | 62 |
60 #if defined(USE_PULSEAUDIO) | 63 #if defined(USE_PULSEAUDIO) |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 DVLOG(2) << description.unique_id << " matches with " << output_device_id; | 548 DVLOG(2) << description.unique_id << " matches with " << output_device_id; |
546 found_an_associated_device = true; | 549 found_an_associated_device = true; |
547 } | 550 } |
548 } | 551 } |
549 | 552 |
550 EXPECT_TRUE(found_an_associated_device); | 553 EXPECT_TRUE(found_an_associated_device); |
551 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 554 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
552 } | 555 } |
553 #endif // defined(USE_CRAS) | 556 #endif // defined(USE_CRAS) |
554 | 557 |
| 558 // Mock class to verify enable and disable debug recording calls. |
| 559 class MockAudioDebugRecordingManager : public AudioDebugRecordingManager { |
| 560 public: |
| 561 MockAudioDebugRecordingManager( |
| 562 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 563 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) |
| 564 : AudioDebugRecordingManager(std::move(task_runner), |
| 565 std::move(file_task_runner)) {} |
| 566 |
| 567 ~MockAudioDebugRecordingManager() override {} |
| 568 |
| 569 MOCK_METHOD1(EnableDebugRecording, void(const base::FilePath&)); |
| 570 MOCK_METHOD0(DisableDebugRecording, void()); |
| 571 |
| 572 private: |
| 573 DISALLOW_COPY_AND_ASSIGN(MockAudioDebugRecordingManager); |
| 574 }; |
| 575 |
555 class TestAudioManager : public FakeAudioManager { | 576 class TestAudioManager : public FakeAudioManager { |
556 // For testing the default implementation of GetGroupId(Input|Output) | 577 // For testing the default implementation of GetGroupId(Input|Output) |
557 // input$i is associated to output$i, if both exist. | 578 // input$i is associated to output$i, if both exist. |
558 // Default input is input1. | 579 // Default input is input1. |
559 // Default output is output2. | 580 // Default output is output2. |
560 public: | 581 public: |
561 TestAudioManager( | 582 TestAudioManager( |
562 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 583 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
563 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 584 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
564 AudioLogFactory* audio_log_factory) | 585 AudioLogFactory* audio_log_factory) |
(...skipping 20 matching lines...) Expand all Loading... |
585 device_names->push_front(AudioDeviceName::CreateDefault()); | 606 device_names->push_front(AudioDeviceName::CreateDefault()); |
586 } | 607 } |
587 | 608 |
588 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { | 609 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { |
589 device_names->emplace_back("Output 1", "output1"); | 610 device_names->emplace_back("Output 1", "output1"); |
590 device_names->emplace_back("Output 2", "output2"); | 611 device_names->emplace_back("Output 2", "output2"); |
591 device_names->emplace_back("Output 3", "output3"); | 612 device_names->emplace_back("Output 3", "output3"); |
592 device_names->emplace_back("Output 4", "output4"); | 613 device_names->emplace_back("Output 4", "output4"); |
593 device_names->push_front(AudioDeviceName::CreateDefault()); | 614 device_names->push_front(AudioDeviceName::CreateDefault()); |
594 } | 615 } |
| 616 |
| 617 std::unique_ptr<AudioDebugRecordingManager> CreateAudioDebugRecordingManager( |
| 618 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 619 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) override { |
| 620 return base::MakeUnique<MockAudioDebugRecordingManager>( |
| 621 std::move(task_runner), std::move(file_task_runner)); |
| 622 } |
595 }; | 623 }; |
596 | 624 |
597 TEST_F(AudioManagerTest, GroupId) { | 625 TEST_F(AudioManagerTest, GroupId) { |
598 CreateAudioManagerForTesting<TestAudioManager>(); | 626 CreateAudioManagerForTesting<TestAudioManager>(); |
599 // Groups: | 627 // Groups: |
600 // input1, output1, default input | 628 // input1, output1, default input |
601 // input2, output2 | 629 // input2, output2 |
602 // input3, | 630 // input3, |
603 // output3 | 631 // output3 |
604 // output4, default output | 632 // output4, default output |
605 AudioDeviceDescriptions inputs; | 633 AudioDeviceDescriptions inputs; |
606 audio_manager_->GetAudioInputDeviceDescriptions(&inputs); | 634 audio_manager_->GetAudioInputDeviceDescriptions(&inputs); |
607 AudioDeviceDescriptions outputs; | 635 AudioDeviceDescriptions outputs; |
608 audio_manager_->GetAudioOutputDeviceDescriptions(&outputs); | 636 audio_manager_->GetAudioOutputDeviceDescriptions(&outputs); |
609 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id); | 637 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id); |
610 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id); | 638 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id); |
611 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); | 639 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); |
612 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); | 640 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); |
613 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); | 641 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); |
614 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); | 642 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); |
615 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); | 643 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); |
616 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); | 644 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); |
617 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); | 645 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); |
618 } | 646 } |
619 | 647 |
| 648 TEST_F(AudioManagerTest, AudioDebugRecording) { |
| 649 CreateAudioManagerForTesting<TestAudioManager>(); |
| 650 |
| 651 AudioManagerBase* audio_manager_base = |
| 652 static_cast<AudioManagerBase*>(audio_manager_.get()); |
| 653 |
| 654 // Initialize is normally done in AudioManager::Create(), but since we don't |
| 655 // use that in this test, we need to initialize here. |
| 656 audio_manager_->InitializeOutputDebugRecording( |
| 657 audio_manager_->GetTaskRunner()); |
| 658 |
| 659 MockAudioDebugRecordingManager* mock_debug_recording_manager = |
| 660 static_cast<MockAudioDebugRecordingManager*>( |
| 661 audio_manager_base->debug_recording_manager_.get()); |
| 662 ASSERT_TRUE(mock_debug_recording_manager); |
| 663 |
| 664 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
| 665 audio_manager_->DisableOutputDebugRecording(); |
| 666 |
| 667 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
| 668 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
| 669 audio_manager_->EnableOutputDebugRecording(file_path); |
| 670 |
| 671 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
| 672 audio_manager_->DisableOutputDebugRecording(); |
| 673 } |
| 674 |
620 } // namespace media | 675 } // namespace media |
OLD | NEW |