| 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/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/test/test_message_loop.h" | 16 #include "base/test/test_message_loop.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "media/audio/audio_device_description.h" | 19 #include "media/audio/audio_device_description.h" |
| 20 #include "media/audio/audio_device_name.h" | 20 #include "media/audio/audio_device_name.h" |
| 21 #include "media/audio/audio_output_proxy.h" | 21 #include "media/audio/audio_output_proxy.h" |
| 22 #include "media/audio/audio_unittest_util.h" | 22 #include "media/audio/audio_unittest_util.h" |
| 23 #include "media/audio/fake_audio_file_writer.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" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 #if defined(USE_ALSA) | 28 #if defined(USE_ALSA) |
| 28 #include "media/audio/alsa/audio_manager_alsa.h" | 29 #include "media/audio/alsa/audio_manager_alsa.h" |
| 29 #endif // defined(USE_ALSA) | 30 #endif // defined(USE_ALSA) |
| 30 | 31 |
| 31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
| 32 #include "base/win/scoped_com_initializer.h" | 33 #include "base/win/scoped_com_initializer.h" |
| 33 #include "media/audio/win/audio_manager_win.h" | 34 #include "media/audio/win/audio_manager_win.h" |
| 34 #include "media/audio/win/wavein_input_win.h" | 35 #include "media/audio/win/wavein_input_win.h" |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 #if defined(USE_PULSEAUDIO) | 38 #if defined(USE_PULSEAUDIO) |
| 38 #include "media/audio/pulse/audio_manager_pulse.h" | 39 #include "media/audio/pulse/audio_manager_pulse.h" |
| 39 #endif // defined(USE_PULSEAUDIO) | 40 #endif // defined(USE_PULSEAUDIO) |
| 40 | 41 |
| 41 #if defined(USE_CRAS) | 42 #if defined(USE_CRAS) |
| 42 #include "chromeos/audio/audio_devices_pref_handler_stub.h" | 43 #include "chromeos/audio/audio_devices_pref_handler_stub.h" |
| 43 #include "chromeos/audio/cras_audio_handler.h" | 44 #include "chromeos/audio/cras_audio_handler.h" |
| 44 #include "chromeos/dbus/dbus_thread_manager.h" | 45 #include "chromeos/dbus/dbus_thread_manager.h" |
| 45 #include "chromeos/dbus/fake_cras_audio_client.h" | 46 #include "chromeos/dbus/fake_cras_audio_client.h" |
| 46 #include "media/audio/cras/audio_manager_cras.h" | 47 #include "media/audio/cras/audio_manager_cras.h" |
| 47 #endif // defined(USE_CRAS) | 48 #endif // defined(USE_CRAS) |
| 48 | 49 |
| 49 namespace media { | 50 namespace media { |
| 50 | 51 |
| 51 namespace { | 52 namespace { |
| 53 |
| 52 template <typename T> | 54 template <typename T> |
| 53 struct TestAudioManagerFactory { | 55 struct TestAudioManagerFactory { |
| 54 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 56 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { |
| 55 return ScopedAudioManagerPtr(new T(base::ThreadTaskRunnerHandle::Get(), | 57 return ScopedAudioManagerPtr( |
| 56 base::ThreadTaskRunnerHandle::Get(), | 58 new T(base::ThreadTaskRunnerHandle::Get(), |
| 57 audio_log_factory)); | 59 base::ThreadTaskRunnerHandle::Get(), audio_log_factory, |
| 60 base::Bind(&FakeAudioFileWriter::Create))); |
| 58 } | 61 } |
| 59 }; | 62 }; |
| 60 | 63 |
| 61 #if defined(USE_PULSEAUDIO) | 64 #if defined(USE_PULSEAUDIO) |
| 62 template <> | 65 template <> |
| 63 struct TestAudioManagerFactory<AudioManagerPulse> { | 66 struct TestAudioManagerFactory<AudioManagerPulse> { |
| 64 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 67 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { |
| 65 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager( | 68 std::unique_ptr<AudioManagerPulse, AudioManagerDeleter> manager( |
| 66 new AudioManagerPulse(base::ThreadTaskRunnerHandle::Get(), | 69 new AudioManagerPulse(base::ThreadTaskRunnerHandle::Get(), |
| 67 base::ThreadTaskRunnerHandle::Get(), | 70 base::ThreadTaskRunnerHandle::Get(), |
| 68 audio_log_factory)); | 71 audio_log_factory, |
| 72 base::Bind(&FakeAudioFileWriter::Create))); |
| 69 if (!manager->Init()) | 73 if (!manager->Init()) |
| 70 manager.reset(); | 74 manager.reset(); |
| 71 return std::move(manager); | 75 return std::move(manager); |
| 72 } | 76 } |
| 73 }; | 77 }; |
| 74 #endif // defined(USE_PULSEAUDIO) | 78 #endif // defined(USE_PULSEAUDIO) |
| 75 | 79 |
| 76 template <> | 80 template <> |
| 77 struct TestAudioManagerFactory<std::nullptr_t> { | 81 struct TestAudioManagerFactory<std::nullptr_t> { |
| 78 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { | 82 static ScopedAudioManagerPtr Create(AudioLogFactory* audio_log_factory) { |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 665 |
| 662 class TestAudioManager : public FakeAudioManager { | 666 class TestAudioManager : public FakeAudioManager { |
| 663 // For testing the default implementation of GetGroupId(Input|Output) | 667 // For testing the default implementation of GetGroupId(Input|Output) |
| 664 // input$i is associated to output$i, if both exist. | 668 // input$i is associated to output$i, if both exist. |
| 665 // Default input is input1. | 669 // Default input is input1. |
| 666 // Default output is output2. | 670 // Default output is output2. |
| 667 public: | 671 public: |
| 668 TestAudioManager( | 672 TestAudioManager( |
| 669 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 673 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 670 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 674 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 671 AudioLogFactory* audio_log_factory) | 675 AudioLogFactory* audio_log_factory, |
| 672 : FakeAudioManager(task_runner, worker_task_runner, audio_log_factory) {} | 676 CreateAudioFileWriterCallback create_audio_file_writer_callback) |
| 677 : FakeAudioManager(task_runner, |
| 678 worker_task_runner, |
| 679 audio_log_factory, |
| 680 create_audio_file_writer_callback) {} |
| 673 | 681 |
| 674 std::string GetDefaultOutputDeviceID() override { return "output4"; } | 682 std::string GetDefaultOutputDeviceID() override { return "output4"; } |
| 675 | 683 |
| 676 std::string GetAssociatedOutputDeviceID( | 684 std::string GetAssociatedOutputDeviceID( |
| 677 const std::string& input_id) override { | 685 const std::string& input_id) override { |
| 678 if (input_id == "input1") | 686 if (input_id == "input1") |
| 679 return "output1"; | 687 return "output1"; |
| 680 if (input_id == "input2") | 688 if (input_id == "input2") |
| 681 return "output2"; | 689 return "output2"; |
| 682 if (input_id == "default") | 690 if (input_id == "default") |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); | 726 EXPECT_EQ(inputs[2].group_id, outputs[2].group_id); |
| 719 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); | 727 EXPECT_NE(inputs[3].group_id, outputs[3].group_id); |
| 720 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); | 728 EXPECT_EQ(outputs[4].group_id, outputs[0].group_id); |
| 721 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); | 729 EXPECT_NE(inputs[0].group_id, outputs[0].group_id); |
| 722 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); | 730 EXPECT_NE(inputs[1].group_id, outputs[2].group_id); |
| 723 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); | 731 EXPECT_NE(inputs[2].group_id, outputs[3].group_id); |
| 724 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); | 732 EXPECT_NE(inputs[1].group_id, outputs[3].group_id); |
| 725 } | 733 } |
| 726 | 734 |
| 727 } // namespace media | 735 } // namespace media |
| OLD | NEW |