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

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from patch 48 Created 4 years, 8 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
« no previous file with comments | « media/audio/mac/audio_auhal_mac_unittest.cc ('k') | media/audio/mac/audio_manager_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 private: 100 private:
101 media::SeekableBuffer buffer_; 101 media::SeekableBuffer buffer_;
102 FILE* file_; 102 FILE* file_;
103 int bytes_to_write_; 103 int bytes_to_write_;
104 }; 104 };
105 105
106 class MacAudioInputTest : public testing::Test { 106 class MacAudioInputTest : public testing::Test {
107 protected: 107 protected:
108 MacAudioInputTest() 108 MacAudioInputTest()
109 : message_loop_(base::MessageLoop::TYPE_UI), 109 : message_loop_(base::MessageLoop::TYPE_UI),
110 audio_manager_(AudioManager::CreateForTesting()) { 110 audio_manager_(
111 AudioManager::CreateForTesting(message_loop_.task_runner())) {
111 // Wait for the AudioManager to finish any initialization on the audio loop. 112 // Wait for the AudioManager to finish any initialization on the audio loop.
112 base::RunLoop().RunUntilIdle(); 113 base::RunLoop().RunUntilIdle();
113 } 114 }
114 115
115 ~MacAudioInputTest() override { base::RunLoop().RunUntilIdle(); } 116 ~MacAudioInputTest() override {
117 audio_manager_.reset();
118 base::RunLoop().RunUntilIdle();
119 }
116 120
117 bool InputDevicesAvailable() { 121 bool InputDevicesAvailable() {
118 return audio_manager_->HasAudioInputDevices(); 122 return audio_manager_->HasAudioInputDevices();
119 } 123 }
120 124
121 // Convenience method which creates a default AudioInputStream object using 125 // Convenience method which creates a default AudioInputStream object using
122 // a 10ms frame size and a sample rate which is set to the hardware sample 126 // a 10ms frame size and a sample rate which is set to the hardware sample
123 // rate. 127 // rate.
124 AudioInputStream* CreateDefaultAudioInputStream() { 128 AudioInputStream* CreateDefaultAudioInputStream() {
125 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); 129 int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate());
(...skipping 13 matching lines...) Expand all
139 int samples_per_packet = fs / 100; 143 int samples_per_packet = fs / 100;
140 AudioInputStream* ais = audio_manager_->MakeAudioInputStream( 144 AudioInputStream* ais = audio_manager_->MakeAudioInputStream(
141 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, 145 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
142 channel_layout, fs, 16, samples_per_packet), 146 channel_layout, fs, 16, samples_per_packet),
143 AudioManagerBase::kDefaultDeviceId); 147 AudioManagerBase::kDefaultDeviceId);
144 EXPECT_TRUE(ais); 148 EXPECT_TRUE(ais);
145 return ais; 149 return ais;
146 } 150 }
147 151
148 base::MessageLoop message_loop_; 152 base::MessageLoop message_loop_;
149 scoped_ptr<AudioManager> audio_manager_; 153 ScopedAudioManagerPtr audio_manager_;
150 }; 154 };
151 155
152 // Test Create(), Close(). 156 // Test Create(), Close().
153 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { 157 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) {
154 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); 158 ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable());
155 AudioInputStream* ais = CreateDefaultAudioInputStream(); 159 AudioInputStream* ais = CreateDefaultAudioInputStream();
156 ais->Close(); 160 ais->Close();
157 } 161 }
158 162
159 // Test Open(), Close(). 163 // Test Open(), Close().
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 WriteToFileAudioSink file_sink(file_name); 267 WriteToFileAudioSink file_sink(file_name);
264 fprintf(stderr, " >> Speak into the mic while recording...\n"); 268 fprintf(stderr, " >> Speak into the mic while recording...\n");
265 ais->Start(&file_sink); 269 ais->Start(&file_sink);
266 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 270 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
267 ais->Stop(); 271 ais->Stop();
268 fprintf(stderr, " >> Recording has stopped.\n"); 272 fprintf(stderr, " >> Recording has stopped.\n");
269 ais->Close(); 273 ais->Close();
270 } 274 }
271 275
272 } // namespace media 276 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_auhal_mac_unittest.cc ('k') | media/audio/mac/audio_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698