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