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