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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 true, | 159 true, |
157 kWebcamMicStableDeviceId, | 160 kWebcamMicStableDeviceId, |
158 kWebcamMicStableDeviceId ^ 0xFF, | 161 kWebcamMicStableDeviceId ^ 0xFF, |
159 "Webcam Mic", | 162 "Webcam Mic", |
160 "USB", | 163 "USB", |
161 "Logitech Webcam", | 164 "Logitech Webcam", |
162 false, | 165 false, |
163 0); | 166 0); |
164 #endif // defined(USE_CRAS) | 167 #endif // defined(USE_CRAS) |
165 | 168 |
| 169 // Dummy function that should never be called. |
| 170 std::unique_ptr<AudioFileWriter> CreateAudioFileWriterDummy( |
| 171 const AudioParameters& params) { |
| 172 NOTREACHED(); |
| 173 return nullptr; |
| 174 } |
| 175 |
166 } // namespace | 176 } // namespace |
167 | 177 |
168 // Test fixture which allows us to override the default enumeration API on | 178 // Test fixture which allows us to override the default enumeration API on |
169 // Windows. | 179 // Windows. |
170 class AudioManagerTest : public ::testing::Test { | 180 class AudioManagerTest : public ::testing::Test { |
171 public: | 181 public: |
172 void HandleDefaultDeviceIDsTest() { | 182 void HandleDefaultDeviceIDsTest() { |
173 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 183 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
174 CHANNEL_LAYOUT_STEREO, 48000, 16, 2048); | 184 CHANNEL_LAYOUT_STEREO, 48000, 16, 2048); |
175 | 185 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 DVLOG(2) << description.unique_id << " matches with " << output_device_id; | 555 DVLOG(2) << description.unique_id << " matches with " << output_device_id; |
546 found_an_associated_device = true; | 556 found_an_associated_device = true; |
547 } | 557 } |
548 } | 558 } |
549 | 559 |
550 EXPECT_TRUE(found_an_associated_device); | 560 EXPECT_TRUE(found_an_associated_device); |
551 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 561 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
552 } | 562 } |
553 #endif // defined(USE_CRAS) | 563 #endif // defined(USE_CRAS) |
554 | 564 |
| 565 // Mock class to verify enable and disable calls. |
| 566 class MockAudioDebugRecordingManager : public AudioDebugRecordingManager { |
| 567 public: |
| 568 MockAudioDebugRecordingManager( |
| 569 AudioFileWriter::CreateCallback create_audio_file_writer_callback, |
| 570 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 571 : AudioDebugRecordingManager(std::move(create_audio_file_writer_callback), |
| 572 std::move(task_runner)) {} |
| 573 |
| 574 ~MockAudioDebugRecordingManager() override {} |
| 575 |
| 576 MOCK_METHOD1(EnableDebugRecording, void(const base::FilePath&)); |
| 577 MOCK_METHOD0(DisableDebugRecording, void()); |
| 578 |
| 579 private: |
| 580 DISALLOW_COPY_AND_ASSIGN(MockAudioDebugRecordingManager); |
| 581 }; |
| 582 |
555 class TestAudioManager : public FakeAudioManager { | 583 class TestAudioManager : public FakeAudioManager { |
556 // For testing the default implementation of GetGroupId(Input|Output) | 584 // For testing the default implementation of GetGroupId(Input|Output) |
557 // input$i is associated to output$i, if both exist. | 585 // input$i is associated to output$i, if both exist. |
558 // Default input is input1. | 586 // Default input is input1. |
559 // Default output is output2. | 587 // Default output is output2. |
560 public: | 588 public: |
561 TestAudioManager( | 589 TestAudioManager( |
562 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 590 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
563 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 591 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
564 AudioLogFactory* audio_log_factory) | 592 AudioLogFactory* audio_log_factory) |
(...skipping 20 matching lines...) Expand all Loading... |
585 device_names->push_front(AudioDeviceName::CreateDefault()); | 613 device_names->push_front(AudioDeviceName::CreateDefault()); |
586 } | 614 } |
587 | 615 |
588 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { | 616 void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) override { |
589 device_names->emplace_back("Output 1", "output1"); | 617 device_names->emplace_back("Output 1", "output1"); |
590 device_names->emplace_back("Output 2", "output2"); | 618 device_names->emplace_back("Output 2", "output2"); |
591 device_names->emplace_back("Output 3", "output3"); | 619 device_names->emplace_back("Output 3", "output3"); |
592 device_names->emplace_back("Output 4", "output4"); | 620 device_names->emplace_back("Output 4", "output4"); |
593 device_names->push_front(AudioDeviceName::CreateDefault()); | 621 device_names->push_front(AudioDeviceName::CreateDefault()); |
594 } | 622 } |
| 623 |
| 624 std::unique_ptr<AudioDebugRecordingManager> CreateAudioDebugRecordingManager( |
| 625 AudioFileWriter::CreateCallback create_audio_file_writer_callback, |
| 626 scoped_refptr<base::SingleThreadTaskRunner> task_runner) override { |
| 627 return base::MakeUnique<MockAudioDebugRecordingManager>( |
| 628 std::move(create_audio_file_writer_callback), std::move(task_runner)); |
| 629 } |
595 }; | 630 }; |
596 | 631 |
597 TEST_F(AudioManagerTest, GroupId) { | 632 TEST_F(AudioManagerTest, GroupId) { |
598 CreateAudioManagerForTesting<TestAudioManager>(); | 633 CreateAudioManagerForTesting<TestAudioManager>(); |
599 // Groups: | 634 // Groups: |
600 // input1, output1, default input | 635 // input1, output1, default input |
601 // input2, output2 | 636 // input2, output2 |
602 // input3, | 637 // input3, |
603 // output3 | 638 // output3 |
604 // output4, default output | 639 // output4, default output |
605 AudioDeviceDescriptions inputs; | 640 AudioDeviceDescriptions inputs; |
606 audio_manager_->GetAudioInputDeviceDescriptions(&inputs); | 641 audio_manager_->GetAudioInputDeviceDescriptions(&inputs); |
607 AudioDeviceDescriptions outputs; | 642 AudioDeviceDescriptions outputs; |
608 audio_manager_->GetAudioOutputDeviceDescriptions(&outputs); | 643 audio_manager_->GetAudioOutputDeviceDescriptions(&outputs); |
609 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id); | 644 EXPECT_EQ(inputs[0].group_id, outputs[1].group_id); |
610 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id); | 645 EXPECT_EQ(inputs[1].group_id, outputs[1].group_id); |
611 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); | 646 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); |
612 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); | 647 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); |
613 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); | 648 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); |
614 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); | 649 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); |
615 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); | 650 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); |
616 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); | 651 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); |
617 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); | 652 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); |
618 } | 653 } |
619 | 654 |
| 655 TEST_F(AudioManagerTest, AudioDebugRecording) { |
| 656 CreateAudioManagerForTesting<TestAudioManager>(); |
| 657 |
| 658 AudioManagerBase* audio_manager_base = |
| 659 static_cast<AudioManagerBase*>(audio_manager_.get()); |
| 660 |
| 661 // Should be OK to disable without initializing. |
| 662 audio_manager_->DisableOutputDebugRecording(); |
| 663 |
| 664 audio_manager_->InitializeOutputDebugRecording( |
| 665 base::BindRepeating(&CreateAudioFileWriterDummy)); |
| 666 |
| 667 MockAudioDebugRecordingManager* mock_debug_recording_manager = |
| 668 static_cast<MockAudioDebugRecordingManager*>( |
| 669 audio_manager_base->debug_recording_manager_.get()); |
| 670 ASSERT_TRUE(mock_debug_recording_manager); |
| 671 |
| 672 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
| 673 audio_manager_->DisableOutputDebugRecording(); |
| 674 |
| 675 base::FilePath file_path(FILE_PATH_LITERAL("path")); |
| 676 EXPECT_CALL(*mock_debug_recording_manager, EnableDebugRecording(file_path)); |
| 677 audio_manager_->EnableOutputDebugRecording(file_path); |
| 678 |
| 679 EXPECT_CALL(*mock_debug_recording_manager, DisableDebugRecording()); |
| 680 audio_manager_->DisableOutputDebugRecording(); |
| 681 } |
| 682 |
620 } // namespace media | 683 } // namespace media |
OLD | NEW |