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