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

Side by Side Diff: media/audio/win/audio_output_win_unittest.cc

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
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 <windows.h> 5 #include <windows.h>
6 #include <mmsystem.h> 6 #include <mmsystem.h>
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
11 #include "base/memory/aligned_memory.h" 11 #include "base/memory/aligned_memory.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/sync_socket.h" 13 #include "base/sync_socket.h"
13 #include "base/win/scoped_com_initializer.h" 14 #include "base/win/scoped_com_initializer.h"
14 #include "base/win/windows_version.h" 15 #include "base/win/windows_version.h"
15 #include "media/audio/audio_io.h" 16 #include "media/audio/audio_io.h"
16 #include "media/audio/audio_manager.h" 17 #include "media/audio/audio_manager.h"
17 #include "media/audio/audio_unittest_util.h" 18 #include "media/audio/audio_unittest_util.h"
18 #include "media/audio/mock_audio_source_callback.h" 19 #include "media/audio/mock_audio_source_callback.h"
19 #include "media/audio/simple_sources.h" 20 #include "media/audio/simple_sources.h"
20 #include "media/base/limits.h" 21 #include "media/base/limits.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 // =========================================================================== 147 // ===========================================================================
147 // Validation of AudioManager::AUDIO_PCM_LINEAR 148 // Validation of AudioManager::AUDIO_PCM_LINEAR
148 // 149 //
149 // NOTE: 150 // NOTE:
150 // The tests can fail on the build bots when somebody connects to them via 151 // The tests can fail on the build bots when somebody connects to them via
151 // remote-desktop and the rdp client installs an audio device that fails to open 152 // remote-desktop and the rdp client installs an audio device that fails to open
152 // at some point, possibly when the connection goes idle. 153 // at some point, possibly when the connection goes idle.
153 154
154 // Test that can it be created and closed. 155 // Test that can it be created and closed.
155 TEST(WinAudioTest, PCMWaveStreamGetAndClose) { 156 TEST(WinAudioTest, PCMWaveStreamGetAndClose) {
DaleCurtis 2016/03/31 22:55:54 Might be easier to make these TEST_F with an audio
alokp 2016/04/01 03:40:53 Right. It would prefer to do this in a separate pa
156 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 157 base::MessageLoop loop;
158 ScopedAudioManagerPtr audio_man(
159 AudioManager::CreateForTesting(loop.task_runner()));
157 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 160 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
158 161
159 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 162 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
160 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 163 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
161 8000, 16, 256), 164 8000, 16, 256),
162 std::string()); 165 std::string());
163 ASSERT_TRUE(NULL != oas); 166 ASSERT_TRUE(NULL != oas);
164 oas->Close(); 167 oas->Close();
165 } 168 }
166 169
167 // Test that can it be cannot be created with invalid parameters. 170 // Test that can it be cannot be created with invalid parameters.
168 TEST(WinAudioTest, SanityOnMakeParams) { 171 TEST(WinAudioTest, SanityOnMakeParams) {
169 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 172 base::MessageLoop loop;
173 ScopedAudioManagerPtr audio_man(
174 AudioManager::CreateForTesting(loop.task_runner()));
170 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 175 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
171 176
172 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR; 177 AudioParameters::Format fmt = AudioParameters::AUDIO_PCM_LINEAR;
173 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( 178 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(
174 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256), 179 AudioParameters(fmt, CHANNEL_LAYOUT_UNSUPPORTED, 8000, 16, 256),
175 std::string())); 180 std::string()));
176 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( 181 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(
177 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256), 182 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 1024 * 1024, 16, 256),
178 std::string())); 183 std::string()));
179 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( 184 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(
(...skipping 12 matching lines...) Expand all
192 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0), 197 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 0),
193 std::string())); 198 std::string()));
194 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream( 199 EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(
195 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16, 200 AudioParameters(fmt, CHANNEL_LAYOUT_MONO, 8000, 16,
196 media::limits::kMaxSamplesPerPacket + 1), 201 media::limits::kMaxSamplesPerPacket + 1),
197 std::string())); 202 std::string()));
198 } 203 }
199 204
200 // Test that it can be opened and closed. 205 // Test that it can be opened and closed.
201 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { 206 TEST(WinAudioTest, PCMWaveStreamOpenAndClose) {
202 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 207 base::MessageLoop loop;
208 ScopedAudioManagerPtr audio_man(
209 AudioManager::CreateForTesting(loop.task_runner()));
203 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 210 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
204 211
205 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 212 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
206 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 213 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
207 8000, 16, 256), 214 8000, 16, 256),
208 std::string()); 215 std::string());
209 ASSERT_TRUE(NULL != oas); 216 ASSERT_TRUE(NULL != oas);
210 EXPECT_TRUE(oas->Open()); 217 EXPECT_TRUE(oas->Open());
211 oas->Close(); 218 oas->Close();
212 } 219 }
213 220
214 // Test that it has a maximum packet size. 221 // Test that it has a maximum packet size.
215 TEST(WinAudioTest, PCMWaveStreamOpenLimit) { 222 TEST(WinAudioTest, PCMWaveStreamOpenLimit) {
216 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 223 base::MessageLoop loop;
224 ScopedAudioManagerPtr audio_man(
225 AudioManager::CreateForTesting(loop.task_runner()));
217 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 226 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
218 227
219 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 228 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
220 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO, 229 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
221 8000, 16, 1024 * 1024 * 1024), 230 8000, 16, 1024 * 1024 * 1024),
222 std::string()); 231 std::string());
223 EXPECT_TRUE(NULL == oas); 232 EXPECT_TRUE(NULL == oas);
224 if (oas) 233 if (oas)
225 oas->Close(); 234 oas->Close();
226 } 235 }
227 236
228 // Test potential deadlock situation if the source is slow or blocks for some 237 // Test potential deadlock situation if the source is slow or blocks for some
229 // time. The actual EXPECT_GT are mostly meaningless and the real test is that 238 // time. The actual EXPECT_GT are mostly meaningless and the real test is that
230 // the test completes in reasonable time. 239 // the test completes in reasonable time.
231 TEST(WinAudioTest, PCMWaveSlowSource) { 240 TEST(WinAudioTest, PCMWaveSlowSource) {
232 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 241 base::MessageLoop loop;
242 ScopedAudioManagerPtr audio_man(
243 AudioManager::CreateForTesting(loop.task_runner()));
233 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 244 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
234 245
235 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 246 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
236 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 247 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
237 16000, 16, 256), 248 16000, 16, 256),
238 std::string()); 249 std::string());
239 ASSERT_TRUE(NULL != oas); 250 ASSERT_TRUE(NULL != oas);
240 TestSourceLaggy test_laggy(90); 251 TestSourceLaggy test_laggy(90);
241 EXPECT_TRUE(oas->Open()); 252 EXPECT_TRUE(oas->Open());
242 // The test parameters cause a callback every 32 ms and the source is 253 // The test parameters cause a callback every 32 ms and the source is
243 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. 254 // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers.
244 oas->Start(&test_laggy); 255 oas->Start(&test_laggy);
245 ::Sleep(500); 256 ::Sleep(500);
246 EXPECT_GT(test_laggy.callback_count(), 2); 257 EXPECT_GT(test_laggy.callback_count(), 2);
247 EXPECT_FALSE(test_laggy.had_error()); 258 EXPECT_FALSE(test_laggy.had_error());
248 oas->Stop(); 259 oas->Stop();
249 ::Sleep(500); 260 ::Sleep(500);
250 oas->Close(); 261 oas->Close();
251 } 262 }
252 263
253 // Test another potential deadlock situation if the thread that calls Start() 264 // Test another potential deadlock situation if the thread that calls Start()
254 // gets paused. This test is best when run over RDP with audio enabled. See 265 // gets paused. This test is best when run over RDP with audio enabled. See
255 // bug 19276 for more details. 266 // bug 19276 for more details.
256 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { 267 TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) {
257 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 268 base::MessageLoop loop;
269 ScopedAudioManagerPtr audio_man(
270 AudioManager::CreateForTesting(loop.task_runner()));
258 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 271 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
259 272
260 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 273 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
261 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 274 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
262 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 275 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
263 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 276 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
264 std::string()); 277 std::string());
265 ASSERT_TRUE(NULL != oas); 278 ASSERT_TRUE(NULL != oas);
266 279
267 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 280 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
268 281
269 EXPECT_TRUE(oas->Open()); 282 EXPECT_TRUE(oas->Open());
270 oas->SetVolume(1.0); 283 oas->SetVolume(1.0);
271 284
272 for (int ix = 0; ix != 5; ++ix) { 285 for (int ix = 0; ix != 5; ++ix) {
273 oas->Start(&source); 286 oas->Start(&source);
274 ::Sleep(10); 287 ::Sleep(10);
275 oas->Stop(); 288 oas->Stop();
276 } 289 }
277 oas->Close(); 290 oas->Close();
278 } 291 }
279 292
280 293
281 // This test produces actual audio for .5 seconds on the default wave 294 // This test produces actual audio for .5 seconds on the default wave
282 // device at 44.1K s/sec. Parameters have been chosen carefully so you should 295 // device at 44.1K s/sec. Parameters have been chosen carefully so you should
283 // not hear pops or noises while the sound is playing. 296 // not hear pops or noises while the sound is playing.
284 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { 297 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) {
285 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 298 base::MessageLoop loop;
299 ScopedAudioManagerPtr audio_man(
300 AudioManager::CreateForTesting(loop.task_runner()));
286 if (!audio_man->HasAudioOutputDevices()) { 301 if (!audio_man->HasAudioOutputDevices()) {
287 LOG(WARNING) << "No output device detected."; 302 LOG(WARNING) << "No output device detected.";
288 return; 303 return;
289 } 304 }
290 305
291 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 306 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
292 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 307 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
293 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 308 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
294 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 309 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
295 std::string()); 310 std::string());
296 ASSERT_TRUE(NULL != oas); 311 ASSERT_TRUE(NULL != oas);
297 312
298 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 313 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
299 314
300 EXPECT_TRUE(oas->Open()); 315 EXPECT_TRUE(oas->Open());
301 oas->SetVolume(1.0); 316 oas->SetVolume(1.0);
302 oas->Start(&source); 317 oas->Start(&source);
303 ::Sleep(500); 318 ::Sleep(500);
304 oas->Stop(); 319 oas->Stop();
305 oas->Close(); 320 oas->Close();
306 } 321 }
307 322
308 // This test produces actual audio for for .5 seconds on the default wave 323 // This test produces actual audio for for .5 seconds on the default wave
309 // device at 22K s/sec. Parameters have been chosen carefully so you should 324 // device at 22K s/sec. Parameters have been chosen carefully so you should
310 // not hear pops or noises while the sound is playing. The audio also should 325 // not hear pops or noises while the sound is playing. The audio also should
311 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. 326 // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss.
312 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { 327 TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) {
313 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 328 base::MessageLoop loop;
329 ScopedAudioManagerPtr audio_man(
330 AudioManager::CreateForTesting(loop.task_runner()));
314 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 331 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
315 332
316 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20; 333 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 20;
317 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 334 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
318 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 335 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
319 AudioParameters::kAudioCDSampleRate / 2, 16, 336 AudioParameters::kAudioCDSampleRate / 2, 16,
320 samples_100_ms), 337 samples_100_ms),
321 std::string()); 338 std::string());
322 ASSERT_TRUE(NULL != oas); 339 ASSERT_TRUE(NULL != oas);
323 340
(...skipping 11 matching lines...) Expand all
335 EXPECT_LT(volume, 0.51); 352 EXPECT_LT(volume, 0.51);
336 EXPECT_GT(volume, 0.49); 353 EXPECT_GT(volume, 0.49);
337 oas->Stop(); 354 oas->Stop();
338 oas->Close(); 355 oas->Close();
339 } 356 }
340 357
341 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We 358 // Uses a restricted source to play ~2 seconds of audio for about 5 seconds. We
342 // try hard to generate situation where the two threads are accessing the 359 // try hard to generate situation where the two threads are accessing the
343 // object roughly at the same time. 360 // object roughly at the same time.
344 TEST(WinAudioTest, PushSourceFile16KHz) { 361 TEST(WinAudioTest, PushSourceFile16KHz) {
345 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 362 base::MessageLoop loop;
363 ScopedAudioManagerPtr audio_man(
364 AudioManager::CreateForTesting(loop.task_runner()));
346 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 365 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
347 366
348 static const int kSampleRate = 16000; 367 static const int kSampleRate = 16000;
349 SineWaveAudioSource source(1, 200.0, kSampleRate); 368 SineWaveAudioSource source(1, 200.0, kSampleRate);
350 // Compute buffer size for 100ms of audio. 369 // Compute buffer size for 100ms of audio.
351 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100; 370 const uint32_t kSamples100ms = (kSampleRate / 1000) * 100;
352 // Restrict SineWaveAudioSource to 100ms of samples. 371 // Restrict SineWaveAudioSource to 100ms of samples.
353 source.CapSamples(kSamples100ms); 372 source.CapSamples(kSamples100ms);
354 373
355 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 374 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
(...skipping 19 matching lines...) Expand all
375 ::Sleep(500); 394 ::Sleep(500);
376 395
377 oas->Stop(); 396 oas->Stop();
378 oas->Close(); 397 oas->Close();
379 } 398 }
380 399
381 // This test is to make sure an AudioOutputStream can be started after it was 400 // This test is to make sure an AudioOutputStream can be started after it was
382 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds 401 // stopped. You will here two .5 seconds wave signal separated by 0.5 seconds
383 // of silence. 402 // of silence.
384 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { 403 TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) {
385 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 404 base::MessageLoop loop;
405 ScopedAudioManagerPtr audio_man(
406 AudioManager::CreateForTesting(loop.task_runner()));
386 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 407 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
387 408
388 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 409 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
389 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 410 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
390 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 411 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
391 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 412 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
392 std::string()); 413 std::string());
393 ASSERT_TRUE(NULL != oas); 414 ASSERT_TRUE(NULL != oas);
394 415
395 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate); 416 SineWaveAudioSource source(1, 200.0, AudioParameters::kAudioCDSampleRate);
(...skipping 13 matching lines...) Expand all
409 ::Sleep(500); 430 ::Sleep(500);
410 oas->Stop(); 431 oas->Stop();
411 432
412 oas->Close(); 433 oas->Close();
413 } 434 }
414 435
415 // With the low latency mode, WASAPI is utilized by default for Vista and 436 // With the low latency mode, WASAPI is utilized by default for Vista and
416 // higher and Wave is used for XP and lower. It is possible to utilize a 437 // higher and Wave is used for XP and lower. It is possible to utilize a
417 // smaller buffer size for WASAPI than for Wave. 438 // smaller buffer size for WASAPI than for Wave.
418 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { 439 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) {
419 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 440 base::MessageLoop loop;
441 ScopedAudioManagerPtr audio_man(
442 AudioManager::CreateForTesting(loop.task_runner()));
420 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 443 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
421 444
422 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. 445 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave.
423 // Take the existing native sample rate into account. 446 // Take the existing native sample rate into account.
424 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); 447 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters();
425 int sample_rate = params.sample_rate(); 448 int sample_rate = params.sample_rate();
426 uint32_t samples_10_ms = sample_rate / 100; 449 uint32_t samples_10_ms = sample_rate / 100;
427 int n = 1; 450 int n = 1;
428 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; 451 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1;
429 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 452 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
(...skipping 17 matching lines...) Expand all
447 470
448 // Play the wave for .8 seconds. 471 // Play the wave for .8 seconds.
449 oas->Start(&source); 472 oas->Start(&source);
450 ::Sleep(800); 473 ::Sleep(800);
451 oas->Stop(); 474 oas->Stop();
452 oas->Close(); 475 oas->Close();
453 } 476 }
454 477
455 // Check that the pending bytes value is correct what the stream starts. 478 // Check that the pending bytes value is correct what the stream starts.
456 TEST(WinAudioTest, PCMWaveStreamPendingBytes) { 479 TEST(WinAudioTest, PCMWaveStreamPendingBytes) {
457 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 480 base::MessageLoop loop;
481 ScopedAudioManagerPtr audio_man(
482 AudioManager::CreateForTesting(loop.task_runner()));
458 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 483 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
459 484
460 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10; 485 uint32_t samples_100_ms = AudioParameters::kAudioCDSampleRate / 10;
461 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( 486 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(
462 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, 487 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
463 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms), 488 AudioParameters::kAudioCDSampleRate, 16, samples_100_ms),
464 std::string()); 489 std::string());
465 ASSERT_TRUE(NULL != oas); 490 ASSERT_TRUE(NULL != oas);
466 491
467 NiceMock<MockAudioSourceCallback> source; 492 NiceMock<MockAudioSourceCallback> source;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 604
580 // Test the basic operation of AudioOutputStream used with a SyncSocket. 605 // Test the basic operation of AudioOutputStream used with a SyncSocket.
581 // The emphasis is to verify that it is possible to feed data to the audio 606 // The emphasis is to verify that it is possible to feed data to the audio
582 // layer using a source based on SyncSocket. In a real situation we would 607 // layer using a source based on SyncSocket. In a real situation we would
583 // go for the low-latency version in combination with SyncSocket, but to keep 608 // go for the low-latency version in combination with SyncSocket, but to keep
584 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main 609 // the test more simple, AUDIO_PCM_LINEAR is utilized instead. The main
585 // principle of the test still remains and we avoid the additional complexity 610 // principle of the test still remains and we avoid the additional complexity
586 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY. 611 // related to the two different audio-layers for AUDIO_PCM_LOW_LATENCY.
587 // In this test you should hear a continuous 200Hz tone for 2 seconds. 612 // In this test you should hear a continuous 200Hz tone for 2 seconds.
588 TEST(WinAudioTest, SyncSocketBasic) { 613 TEST(WinAudioTest, SyncSocketBasic) {
589 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); 614 base::MessageLoop loop;
615 ScopedAudioManagerPtr audio_man(
616 AudioManager::CreateForTesting(loop.task_runner()));
590 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); 617 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices());
591 618
592 static const int sample_rate = AudioParameters::kAudioCDSampleRate; 619 static const int sample_rate = AudioParameters::kAudioCDSampleRate;
593 static const uint32_t kSamples20ms = sample_rate / 50; 620 static const uint32_t kSamples20ms = sample_rate / 50;
594 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 621 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
595 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms); 622 CHANNEL_LAYOUT_MONO, sample_rate, 16, kSamples20ms);
596 623
597 624
598 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params, 625 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params,
599 std::string()); 626 std::string());
(...skipping 20 matching lines...) Expand all
620 oas->Start(&source); 647 oas->Start(&source);
621 648
622 ::WaitForSingleObject(thread, INFINITE); 649 ::WaitForSingleObject(thread, INFINITE);
623 ::CloseHandle(thread); 650 ::CloseHandle(thread);
624 651
625 oas->Stop(); 652 oas->Stop();
626 oas->Close(); 653 oas->Close();
627 } 654 }
628 655
629 } // namespace media 656 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698