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

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

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

Powered by Google App Engine
This is Rietveld 408576698