Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: media/audio/audio_low_latency_input_output_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698