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

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

Issue 1111503003: Revert of Switch to STA mode for audio thread and WASAPI I/O streams. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.cc ('k') | media/audio/win/audio_manager_win.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 <windows.h> 5 #include <windows.h>
6 #include <mmsystem.h> 6 #include <mmsystem.h>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h"
10 #include "base/environment.h" 9 #include "base/environment.h"
11 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
12 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
14 #include "base/path_service.h" 13 #include "base/path_service.h"
15 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
16 #include "base/time/time.h" 15 #include "base/time/time.h"
17 #include "base/win/scoped_com_initializer.h" 16 #include "base/win/scoped_com_initializer.h"
18 #include "media/audio/audio_io.h" 17 #include "media/audio/audio_io.h"
19 #include "media/audio/audio_manager.h" 18 #include "media/audio/audio_manager.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 }; 219 };
221 220
222 // Convenience method which creates a default AudioOutputStream object. 221 // Convenience method which creates a default AudioOutputStream object.
223 static AudioOutputStream* CreateDefaultAudioOutputStream( 222 static AudioOutputStream* CreateDefaultAudioOutputStream(
224 AudioManager* audio_manager) { 223 AudioManager* audio_manager) {
225 AudioOutputStreamWrapper aosw(audio_manager); 224 AudioOutputStreamWrapper aosw(audio_manager);
226 AudioOutputStream* aos = aosw.Create(); 225 AudioOutputStream* aos = aosw.Create();
227 return aos; 226 return aos;
228 } 227 }
229 228
230 class WASAPIAudioOutputStreamTest : public testing::Test {
231 public:
232 WASAPIAudioOutputStreamTest()
233 : audio_manager_(AudioManager::CreateForTesting()) {}
234 ~WASAPIAudioOutputStreamTest() override {}
235
236 protected:
237 ScopedCOMInitializer com_init_;
238 scoped_ptr<AudioManager> audio_manager_;
239 };
240
241 // Verify that we can retrieve the current hardware/mixing sample rate 229 // Verify that we can retrieve the current hardware/mixing sample rate
242 // for the default audio device. 230 // for the default audio device.
243 // TODO(henrika): modify this test when we support full device enumeration. 231 // TODO(henrika): modify this test when we support full device enumeration.
244 TEST_F(WASAPIAudioOutputStreamTest, HardwareSampleRate) { 232 TEST(WASAPIAudioOutputStreamTest, HardwareSampleRate) {
245 // Skip this test in exclusive mode since the resulting rate is only utilized 233 // Skip this test in exclusive mode since the resulting rate is only utilized
246 // for shared mode streams. 234 // for shared mode streams.
247 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get()) && 235 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
236 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) &&
248 ExclusiveModeIsEnabled()); 237 ExclusiveModeIsEnabled());
249 238
250 // Default device intended for games, system notification sounds, 239 // Default device intended for games, system notification sounds,
251 // and voice commands. 240 // and voice commands.
252 int fs = static_cast<int>( 241 int fs = static_cast<int>(
253 WASAPIAudioOutputStream::HardwareSampleRate(std::string())); 242 WASAPIAudioOutputStream::HardwareSampleRate(std::string()));
254 EXPECT_GE(fs, 0); 243 EXPECT_GE(fs, 0);
255 } 244 }
256 245
257 // Test Create(), Close() calling sequence. 246 // Test Create(), Close() calling sequence.
258 TEST_F(WASAPIAudioOutputStreamTest, CreateAndClose) { 247 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) {
259 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 248 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
260 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 249 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
250 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
261 aos->Close(); 251 aos->Close();
262 } 252 }
263 253
264 // Test Open(), Close() calling sequence. 254 // Test Open(), Close() calling sequence.
265 TEST_F(WASAPIAudioOutputStreamTest, OpenAndClose) { 255 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) {
266 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 256 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
267 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 257 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
258 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
268 EXPECT_TRUE(aos->Open()); 259 EXPECT_TRUE(aos->Open());
269 aos->Close(); 260 aos->Close();
270 } 261 }
271 262
272 // Test Open(), Start(), Close() calling sequence. 263 // Test Open(), Start(), Close() calling sequence.
273 TEST_F(WASAPIAudioOutputStreamTest, OpenStartAndClose) { 264 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) {
274 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 265 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
275 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 266 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
267 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
276 EXPECT_TRUE(aos->Open()); 268 EXPECT_TRUE(aos->Open());
277 MockAudioSourceCallback source; 269 MockAudioSourceCallback source;
278 EXPECT_CALL(source, OnError(aos)) 270 EXPECT_CALL(source, OnError(aos))
279 .Times(0); 271 .Times(0);
280 aos->Start(&source); 272 aos->Start(&source);
281 aos->Close(); 273 aos->Close();
282 } 274 }
283 275
284 // Test Open(), Start(), Stop(), Close() calling sequence. 276 // Test Open(), Start(), Stop(), Close() calling sequence.
285 TEST_F(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { 277 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) {
286 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 278 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
287 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 279 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
280 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
288 EXPECT_TRUE(aos->Open()); 281 EXPECT_TRUE(aos->Open());
289 MockAudioSourceCallback source; 282 MockAudioSourceCallback source;
290 EXPECT_CALL(source, OnError(aos)) 283 EXPECT_CALL(source, OnError(aos))
291 .Times(0); 284 .Times(0);
292 aos->Start(&source); 285 aos->Start(&source);
293 aos->Stop(); 286 aos->Stop();
294 aos->Close(); 287 aos->Close();
295 } 288 }
296 289
297 // Test SetVolume(), GetVolume() 290 // Test SetVolume(), GetVolume()
298 TEST_F(WASAPIAudioOutputStreamTest, Volume) { 291 TEST(WASAPIAudioOutputStreamTest, Volume) {
299 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 292 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
300 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 293 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
294 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
301 295
302 // Initial volume should be full volume (1.0). 296 // Initial volume should be full volume (1.0).
303 double volume = 0.0; 297 double volume = 0.0;
304 aos->GetVolume(&volume); 298 aos->GetVolume(&volume);
305 EXPECT_EQ(1.0, volume); 299 EXPECT_EQ(1.0, volume);
306 300
307 // Verify some valid volume settings. 301 // Verify some valid volume settings.
308 aos->SetVolume(0.0); 302 aos->SetVolume(0.0);
309 aos->GetVolume(&volume); 303 aos->GetVolume(&volume);
310 EXPECT_EQ(0.0, volume); 304 EXPECT_EQ(0.0, volume);
(...skipping 12 matching lines...) Expand all
323 EXPECT_EQ(1.0, volume); 317 EXPECT_EQ(1.0, volume);
324 318
325 aos->SetVolume(-0.5); 319 aos->SetVolume(-0.5);
326 aos->GetVolume(&volume); 320 aos->GetVolume(&volume);
327 EXPECT_EQ(1.0, volume); 321 EXPECT_EQ(1.0, volume);
328 322
329 aos->Close(); 323 aos->Close();
330 } 324 }
331 325
332 // Test some additional calling sequences. 326 // Test some additional calling sequences.
333 TEST_F(WASAPIAudioOutputStreamTest, MiscCallingSequences) { 327 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) {
334 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 328 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
329 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
335 330
336 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager_.get()); 331 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get());
337 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); 332 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos);
338 333
339 // Open(), Open() is a valid calling sequence (second call does nothing). 334 // Open(), Open() is a valid calling sequence (second call does nothing).
340 EXPECT_TRUE(aos->Open()); 335 EXPECT_TRUE(aos->Open());
341 EXPECT_TRUE(aos->Open()); 336 EXPECT_TRUE(aos->Open());
342 337
343 MockAudioSourceCallback source; 338 MockAudioSourceCallback source;
344 339
345 // Start(), Start() is a valid calling sequence (second call does nothing). 340 // Start(), Start() is a valid calling sequence (second call does nothing).
346 aos->Start(&source); 341 aos->Start(&source);
(...skipping 14 matching lines...) Expand all
361 EXPECT_FALSE(waos->started()); 356 EXPECT_FALSE(waos->started());
362 aos->Start(&source); 357 aos->Start(&source);
363 EXPECT_TRUE(waos->started()); 358 EXPECT_TRUE(waos->started());
364 aos->Stop(); 359 aos->Stop();
365 EXPECT_FALSE(waos->started()); 360 EXPECT_FALSE(waos->started());
366 361
367 aos->Close(); 362 aos->Close();
368 } 363 }
369 364
370 // Use preferred packet size and verify that rendering starts. 365 // Use preferred packet size and verify that rendering starts.
371 TEST_F(WASAPIAudioOutputStreamTest, ValidPacketSize) { 366 TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) {
372 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 367 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
368 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
373 369
374 base::MessageLoopForUI loop; 370 base::MessageLoopForUI loop;
375 MockAudioSourceCallback source; 371 MockAudioSourceCallback source;
376 372
377 // Create default WASAPI output stream which plays out in stereo using 373 // Create default WASAPI output stream which plays out in stereo using
378 // the shared mixing rate. The default buffer size is 10ms. 374 // the shared mixing rate. The default buffer size is 10ms.
379 AudioOutputStreamWrapper aosw(audio_manager_.get()); 375 AudioOutputStreamWrapper aosw(audio_manager.get());
380 AudioOutputStream* aos = aosw.Create(); 376 AudioOutputStream* aos = aosw.Create();
381 EXPECT_TRUE(aos->Open()); 377 EXPECT_TRUE(aos->Open());
382 378
383 // Derive the expected size in bytes of each packet. 379 // Derive the expected size in bytes of each packet.
384 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * 380 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() *
385 (aosw.bits_per_sample() / 8); 381 (aosw.bits_per_sample() / 8);
386 382
387 // Wait for the first callback and verify its parameters. 383 // Wait for the first callback and verify its parameters.
388 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) 384 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet)))
389 .WillOnce(DoAll( 385 .WillOnce(DoAll(
390 QuitLoop(loop.message_loop_proxy()), 386 QuitLoop(loop.message_loop_proxy()),
391 Return(aosw.samples_per_packet()))); 387 Return(aosw.samples_per_packet())));
392 388
393 aos->Start(&source); 389 aos->Start(&source);
394 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), 390 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(),
395 TestTimeouts::action_timeout()); 391 TestTimeouts::action_timeout());
396 loop.Run(); 392 loop.Run();
397 aos->Stop(); 393 aos->Stop();
398 aos->Close(); 394 aos->Close();
399 } 395 }
400 396
401 // This test is intended for manual tests and should only be enabled 397 // This test is intended for manual tests and should only be enabled
402 // when it is required to play out data from a local PCM file. 398 // when it is required to play out data from a local PCM file.
403 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. 399 // By default, GTest will print out YOU HAVE 1 DISABLED TEST.
404 // To include disabled tests in test execution, just invoke the test program 400 // To include disabled tests in test execution, just invoke the test program
405 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS 401 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS
406 // environment variable to a value greater than 0. 402 // environment variable to a value greater than 0.
407 // The test files are approximately 20 seconds long. 403 // The test files are approximately 20 seconds long.
408 TEST_F(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { 404 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) {
409 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get())); 405 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
406 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()));
410 407
411 AudioOutputStreamWrapper aosw(audio_manager_.get()); 408 AudioOutputStreamWrapper aosw(audio_manager.get());
412 AudioOutputStream* aos = aosw.Create(); 409 AudioOutputStream* aos = aosw.Create();
413 EXPECT_TRUE(aos->Open()); 410 EXPECT_TRUE(aos->Open());
414 411
415 std::string file_name; 412 std::string file_name;
416 if (aosw.sample_rate() == 48000) { 413 if (aosw.sample_rate() == 48000) {
417 file_name = kSpeechFile_16b_s_48k; 414 file_name = kSpeechFile_16b_s_48k;
418 } else if (aosw.sample_rate() == 44100) { 415 } else if (aosw.sample_rate() == 44100) {
419 file_name = kSpeechFile_16b_s_44k; 416 file_name = kSpeechFile_16b_s_44k;
420 } else if (aosw.sample_rate() == 96000) { 417 } else if (aosw.sample_rate() == 96000) {
421 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. 418 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck.
(...skipping 24 matching lines...) Expand all
446 } 443 }
447 444
448 DVLOG(0) << ">> Stereo file playout has stopped."; 445 DVLOG(0) << ">> Stereo file playout has stopped.";
449 aos->Close(); 446 aos->Close();
450 } 447 }
451 448
452 // Verify that we can open the output stream in exclusive mode using a 449 // Verify that we can open the output stream in exclusive mode using a
453 // certain set of audio parameters and a sample rate of 48kHz. 450 // certain set of audio parameters and a sample rate of 48kHz.
454 // The expected outcomes of each setting in this test has been derived 451 // The expected outcomes of each setting in this test has been derived
455 // manually using log outputs (--v=1). 452 // manually using log outputs (--v=1).
456 TEST_F(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) { 453 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) {
457 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get()) && 454 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
455 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) &&
458 ExclusiveModeIsEnabled()); 456 ExclusiveModeIsEnabled());
459 457
460 AudioOutputStreamWrapper aosw(audio_manager_.get()); 458 AudioOutputStreamWrapper aosw(audio_manager.get());
461 459
462 // 10ms @ 48kHz shall work. 460 // 10ms @ 48kHz shall work.
463 // Note that, this is the same size as we can use for shared-mode streaming 461 // Note that, this is the same size as we can use for shared-mode streaming
464 // but here the endpoint buffer delay is only 10ms instead of 20ms. 462 // but here the endpoint buffer delay is only 10ms instead of 20ms.
465 AudioOutputStream* aos = aosw.Create(48000, 480); 463 AudioOutputStream* aos = aosw.Create(48000, 480);
466 EXPECT_TRUE(aos->Open()); 464 EXPECT_TRUE(aos->Open());
467 aos->Close(); 465 aos->Close();
468 466
469 // 5ms @ 48kHz does not work due to misalignment. 467 // 5ms @ 48kHz does not work due to misalignment.
470 // This test will propose an aligned buffer size of 5.3333ms. 468 // This test will propose an aligned buffer size of 5.3333ms.
(...skipping 22 matching lines...) Expand all
493 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use. 491 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use.
494 aos = aosw.Create(48000, 160); 492 aos = aosw.Create(48000, 160);
495 EXPECT_TRUE(aos->Open()); 493 EXPECT_TRUE(aos->Open());
496 aos->Close(); 494 aos->Close();
497 } 495 }
498 496
499 // Verify that we can open the output stream in exclusive mode using a 497 // Verify that we can open the output stream in exclusive mode using a
500 // certain set of audio parameters and a sample rate of 44.1kHz. 498 // certain set of audio parameters and a sample rate of 44.1kHz.
501 // The expected outcomes of each setting in this test has been derived 499 // The expected outcomes of each setting in this test has been derived
502 // manually using log outputs (--v=1). 500 // manually using log outputs (--v=1).
503 TEST_F(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) { 501 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) {
504 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get()) && 502 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
503 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) &&
505 ExclusiveModeIsEnabled()); 504 ExclusiveModeIsEnabled());
506 505
507 AudioOutputStreamWrapper aosw(audio_manager_.get()); 506 AudioOutputStreamWrapper aosw(audio_manager.get());
508 507
509 // 10ms @ 44.1kHz does not work due to misalignment. 508 // 10ms @ 44.1kHz does not work due to misalignment.
510 // This test will propose an aligned buffer size of 10.1587ms. 509 // This test will propose an aligned buffer size of 10.1587ms.
511 AudioOutputStream* aos = aosw.Create(44100, 441); 510 AudioOutputStream* aos = aosw.Create(44100, 441);
512 EXPECT_FALSE(aos->Open()); 511 EXPECT_FALSE(aos->Open());
513 aos->Close(); 512 aos->Close();
514 513
515 // 10.1587ms @ 44.1kHz shall work (see test above). 514 // 10.1587ms @ 44.1kHz shall work (see test above).
516 aos = aosw.Create(44100, 448); 515 aos = aosw.Create(44100, 448);
517 EXPECT_TRUE(aos->Open()); 516 EXPECT_TRUE(aos->Open());
(...skipping 29 matching lines...) Expand all
547 aos->Close(); 546 aos->Close();
548 547
549 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. 548 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use.
550 aos = aosw.Create(44100, 160); 549 aos = aosw.Create(44100, 160);
551 EXPECT_TRUE(aos->Open()); 550 EXPECT_TRUE(aos->Open());
552 aos->Close(); 551 aos->Close();
553 } 552 }
554 553
555 // Verify that we can open and start the output stream in exclusive mode at 554 // Verify that we can open and start the output stream in exclusive mode at
556 // the lowest possible delay at 48kHz. 555 // the lowest possible delay at 48kHz.
557 TEST_F(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { 556 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) {
558 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager_.get()) && 557 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
558 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndOutputDevices(audio_manager.get()) &&
559 ExclusiveModeIsEnabled()); 559 ExclusiveModeIsEnabled());
560 560
561 base::MessageLoopForUI loop; 561 base::MessageLoopForUI loop;
562 MockAudioSourceCallback source; 562 MockAudioSourceCallback source;
563 563
564 // Create exclusive-mode WASAPI output stream which plays out in stereo 564 // Create exclusive-mode WASAPI output stream which plays out in stereo
565 // using the minimum buffer size at 48kHz sample rate. 565 // using the minimum buffer size at 48kHz sample rate.
566 AudioOutputStreamWrapper aosw(audio_manager_.get()); 566 AudioOutputStreamWrapper aosw(audio_manager.get());
567 AudioOutputStream* aos = aosw.Create(48000, 160); 567 AudioOutputStream* aos = aosw.Create(48000, 160);
568 EXPECT_TRUE(aos->Open()); 568 EXPECT_TRUE(aos->Open());
569 569
570 // Derive the expected size in bytes of each packet. 570 // Derive the expected size in bytes of each packet.
571 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * 571 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() *
572 (aosw.bits_per_sample() / 8); 572 (aosw.bits_per_sample() / 8);
573 573
574 // Wait for the first callback and verify its parameters. 574 // Wait for the first callback and verify its parameters.
575 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) 575 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet)))
576 .WillOnce(DoAll( 576 .WillOnce(DoAll(
577 QuitLoop(loop.message_loop_proxy()), 577 QuitLoop(loop.message_loop_proxy()),
578 Return(aosw.samples_per_packet()))) 578 Return(aosw.samples_per_packet())))
579 .WillRepeatedly(Return(aosw.samples_per_packet())); 579 .WillRepeatedly(Return(aosw.samples_per_packet()));
580 580
581 aos->Start(&source); 581 aos->Start(&source);
582 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), 582 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(),
583 TestTimeouts::action_timeout()); 583 TestTimeouts::action_timeout());
584 loop.Run(); 584 loop.Run();
585 aos->Stop(); 585 aos->Stop();
586 aos->Close(); 586 aos->Close();
587 } 587 }
588 588
589 // Verify that we can open and start the output stream in exclusive mode at 589 // Verify that we can open and start the output stream in exclusive mode at
590 // the lowest possible delay at 44.1kHz. 590 // the lowest possible delay at 44.1kHz.
591 TEST_F(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { 591 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) {
592 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); 592 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled());
593 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting());
593 594
594 base::MessageLoopForUI loop; 595 base::MessageLoopForUI loop;
595 MockAudioSourceCallback source; 596 MockAudioSourceCallback source;
596 597
597 // Create exclusive-mode WASAPI output stream which plays out in stereo 598 // Create exclusive-mode WASAPI output stream which plays out in stereo
598 // using the minimum buffer size at 44.1kHz sample rate. 599 // using the minimum buffer size at 44.1kHz sample rate.
599 AudioOutputStreamWrapper aosw(audio_manager_.get()); 600 AudioOutputStreamWrapper aosw(audio_manager.get());
600 AudioOutputStream* aos = aosw.Create(44100, 160); 601 AudioOutputStream* aos = aosw.Create(44100, 160);
601 EXPECT_TRUE(aos->Open()); 602 EXPECT_TRUE(aos->Open());
602 603
603 // Derive the expected size in bytes of each packet. 604 // Derive the expected size in bytes of each packet.
604 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * 605 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() *
605 (aosw.bits_per_sample() / 8); 606 (aosw.bits_per_sample() / 8);
606 607
607 // Wait for the first callback and verify its parameters. 608 // Wait for the first callback and verify its parameters.
608 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet))) 609 EXPECT_CALL(source, OnMoreData(NotNull(), HasValidDelay(bytes_per_packet)))
609 .WillOnce(DoAll( 610 .WillOnce(DoAll(
610 QuitLoop(loop.message_loop_proxy()), 611 QuitLoop(loop.message_loop_proxy()),
611 Return(aosw.samples_per_packet()))) 612 Return(aosw.samples_per_packet())))
612 .WillRepeatedly(Return(aosw.samples_per_packet())); 613 .WillRepeatedly(Return(aosw.samples_per_packet()));
613 614
614 aos->Start(&source); 615 aos->Start(&source);
615 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), 616 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(),
616 TestTimeouts::action_timeout()); 617 TestTimeouts::action_timeout());
617 loop.Run(); 618 loop.Run();
618 aos->Stop(); 619 aos->Stop();
619 aos->Close(); 620 aos->Close();
620 } 621 }
621 622
622 } // namespace media 623 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/win/audio_low_latency_output_win.cc ('k') | media/audio/win/audio_manager_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698