OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/environment.h" | 12 #include "base/environment.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
20 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/time/time.h" | 22 #include "base/time/time.h" |
23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
24 #include "media/audio/audio_device_description.h" | 24 #include "media/audio/audio_device_description.h" |
25 #include "media/audio/audio_device_info_accessor_for_tests.h" | 25 #include "media/audio/audio_device_info_accessor_for_tests.h" |
26 #include "media/audio/audio_io.h" | 26 #include "media/audio/audio_io.h" |
| 27 #include "media/audio/audio_manager.h" |
27 #include "media/audio/audio_unittest_util.h" | 28 #include "media/audio/audio_unittest_util.h" |
28 #include "media/audio/fake_audio_log_factory.h" | 29 #include "media/audio/test_audio_thread.h" |
29 #include "media/base/seekable_buffer.h" | 30 #include "media/base/seekable_buffer.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
32 | 33 |
33 #if defined(USE_PULSEAUDIO) | |
34 #include "media/audio/pulse/audio_manager_pulse.h" | |
35 #elif defined(USE_ALSA) | |
36 #include "media/audio/alsa/audio_manager_alsa.h" | |
37 #elif defined(USE_CRAS) | |
38 #include "media/audio/cras/audio_manager_cras.h" | |
39 #elif defined(OS_MACOSX) | |
40 #include "media/audio/mac/audio_manager_mac.h" | |
41 #elif defined(OS_WIN) | |
42 #include "media/audio/win/audio_manager_win.h" | |
43 #include "media/audio/win/core_audio_util_win.h" | |
44 #elif defined(OS_ANDROID) | |
45 #include "media/audio/android/audio_manager_android.h" | |
46 #else | |
47 #include "media/audio/fake_audio_manager.h" | |
48 #endif | |
49 | |
50 namespace media { | 34 namespace media { |
51 | 35 |
52 namespace { | 36 namespace { |
53 | 37 |
54 #if defined(USE_PULSEAUDIO) | |
55 typedef AudioManagerPulse AudioManagerAnyPlatform; | |
56 #elif defined(USE_ALSA) | |
57 typedef AudioManagerAlsa AudioManagerAnyPlatform; | |
58 #elif defined(USE_CRAS) | |
59 typedef AudioManagerCras AudioManagerAnyPlatform; | |
60 #elif defined(OS_MACOSX) | |
61 typedef AudioManagerMac AudioManagerAnyPlatform; | |
62 #elif defined(OS_WIN) | |
63 typedef AudioManagerWin AudioManagerAnyPlatform; | |
64 #elif defined(OS_ANDROID) | |
65 typedef AudioManagerAndroid AudioManagerAnyPlatform; | |
66 #else | |
67 typedef FakeAudioManager AudioManagerAnyPlatform; | |
68 #endif | |
69 | |
70 // Limits the number of delay measurements we can store in an array and | 38 // Limits the number of delay measurements we can store in an array and |
71 // then write to file at end of the WASAPIAudioInputOutputFullDuplex test. | 39 // then write to file at end of the WASAPIAudioInputOutputFullDuplex test. |
72 static const size_t kMaxDelayMeasurements = 1000; | 40 static const size_t kMaxDelayMeasurements = 1000; |
73 | 41 |
74 // Name of the output text file. The output file will be stored in the | 42 // Name of the output text file. The output file will be stored in the |
75 // directory containing media_unittests.exe. | 43 // directory containing media_unittests.exe. |
76 // Example: \src\build\Debug\audio_delay_values_ms.txt. | 44 // Example: \src\build\Debug\audio_delay_values_ms.txt. |
77 // See comments for the WASAPIAudioInputOutputFullDuplex test for more details | 45 // See comments for the WASAPIAudioInputOutputFullDuplex test for more details |
78 // about the file format. | 46 // about the file format. |
79 static const char kDelayValuesFileName[] = "audio_delay_values_ms.txt"; | 47 static const char kDelayValuesFileName[] = "audio_delay_values_ms.txt"; |
(...skipping 16 matching lines...) Expand all Loading... |
96 | 64 |
97 // Reported capture/input delay. Typical value is ~10 [ms]. | 65 // Reported capture/input delay. Typical value is ~10 [ms]. |
98 int input_delay_ms; | 66 int input_delay_ms; |
99 | 67 |
100 // Reported render/output delay. Typical value is ~40 [ms]. | 68 // Reported render/output delay. Typical value is ~40 [ms]. |
101 int output_delay_ms; | 69 int output_delay_ms; |
102 }; | 70 }; |
103 | 71 |
104 void OnLogMessage(const std::string& message) {} | 72 void OnLogMessage(const std::string& message) {} |
105 | 73 |
106 // This class mocks the platform specific audio manager and overrides | |
107 // the GetMessageLoop() method to ensure that we can run our tests on | |
108 // the main thread instead of the audio thread. | |
109 class MockAudioManager : public AudioManagerAnyPlatform { | |
110 public: | |
111 MockAudioManager() | |
112 : AudioManagerAnyPlatform(base::ThreadTaskRunnerHandle::Get(), | |
113 base::ThreadTaskRunnerHandle::Get(), | |
114 &fake_audio_log_factory_) {} | |
115 ~MockAudioManager() override {} | |
116 | |
117 private: | |
118 FakeAudioLogFactory fake_audio_log_factory_; | |
119 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); | |
120 }; | |
121 | |
122 // Test fixture class. | 74 // Test fixture class. |
123 class AudioLowLatencyInputOutputTest : public testing::Test { | 75 class AudioLowLatencyInputOutputTest : public testing::Test { |
124 protected: | 76 protected: |
125 AudioLowLatencyInputOutputTest() {} | 77 AudioLowLatencyInputOutputTest() { |
| 78 audio_manager_ = |
| 79 AudioManager::CreateForTesting(base::MakeUnique<TestAudioThread>()); |
| 80 } |
126 | 81 |
127 ~AudioLowLatencyInputOutputTest() override {} | 82 ~AudioLowLatencyInputOutputTest() override { audio_manager_->Shutdown(); } |
128 | 83 |
129 AudioManager* audio_manager() { return &mock_audio_manager_; } | 84 AudioManager* audio_manager() { return audio_manager_.get(); } |
130 base::MessageLoopForUI* message_loop() { return &message_loop_; } | 85 base::MessageLoopForUI* message_loop() { return &message_loop_; } |
131 | 86 |
132 private: | 87 private: |
133 base::MessageLoopForUI message_loop_; | 88 base::MessageLoopForUI message_loop_; |
134 MockAudioManager mock_audio_manager_; | 89 std::unique_ptr<AudioManager> audio_manager_; |
135 | 90 |
136 DISALLOW_COPY_AND_ASSIGN(AudioLowLatencyInputOutputTest); | 91 DISALLOW_COPY_AND_ASSIGN(AudioLowLatencyInputOutputTest); |
137 }; | 92 }; |
138 | 93 |
139 // This audio source/sink implementation should be used for manual tests | 94 // This audio source/sink implementation should be used for manual tests |
140 // only since delay measurements are stored on an output text file. | 95 // only since delay measurements are stored on an output text file. |
141 // All incoming/recorded audio packets are stored in an intermediate media | 96 // All incoming/recorded audio packets are stored in an intermediate media |
142 // buffer which the renderer reads from when it needs audio for playout. | 97 // buffer which the renderer reads from when it needs audio for playout. |
143 // The total effect is that recorded audio is played out in loop back using | 98 // The total effect is that recorded audio is played out in loop back using |
144 // a sync buffer as temporary storage. | 99 // a sync buffer as temporary storage. |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 // should be synchronous and not post additional close tasks to | 406 // should be synchronous and not post additional close tasks to |
452 // mocked the audio thread. Hence, there is no need to call | 407 // mocked the audio thread. Hence, there is no need to call |
453 // message_loop()->RunUntilIdle() after the Close() methods. | 408 // message_loop()->RunUntilIdle() after the Close() methods. |
454 aos->Close(); | 409 aos->Close(); |
455 ais->Close(); | 410 ais->Close(); |
456 } | 411 } |
457 | 412 |
458 } // namespace | 413 } // namespace |
459 | 414 |
460 } // namespace media | 415 } // namespace media |
OLD | NEW |