| 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/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "base/win/scoped_com_initializer.h" | 16 #include "base/win/scoped_com_initializer.h" |
| 17 #include "media/audio/audio_io.h" | 17 #include "media/audio/audio_io.h" |
| 18 #include "media/audio/audio_manager.h" | 18 #include "media/audio/audio_manager.h" |
| 19 #include "media/audio/audio_unittest_utils.h" |
| 19 #include "media/audio/mock_audio_source_callback.h" | 20 #include "media/audio/mock_audio_source_callback.h" |
| 20 #include "media/audio/win/audio_low_latency_output_win.h" | 21 #include "media/audio/win/audio_low_latency_output_win.h" |
| 21 #include "media/audio/win/core_audio_util_win.h" | 22 #include "media/audio/win/core_audio_util_win.h" |
| 22 #include "media/base/decoder_buffer.h" | 23 #include "media/base/decoder_buffer.h" |
| 23 #include "media/base/seekable_buffer.h" | 24 #include "media/base/seekable_buffer.h" |
| 24 #include "media/base/test_data_util.h" | 25 #include "media/base/test_data_util.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gmock_mutant.h" | 27 #include "testing/gmock_mutant.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 29 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 base::TimeTicks previous_call_time_; | 142 base::TimeTicks previous_call_time_; |
| 142 FILE* text_file_; | 143 FILE* text_file_; |
| 143 size_t elements_to_write_; | 144 size_t elements_to_write_; |
| 144 }; | 145 }; |
| 145 | 146 |
| 146 static bool ExclusiveModeIsEnabled() { | 147 static bool ExclusiveModeIsEnabled() { |
| 147 return (WASAPIAudioOutputStream::GetShareMode() == | 148 return (WASAPIAudioOutputStream::GetShareMode() == |
| 148 AUDCLNT_SHAREMODE_EXCLUSIVE); | 149 AUDCLNT_SHAREMODE_EXCLUSIVE); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Convenience method which ensures that we are not running on the build | 152 static bool HasCoreAudioAndInputDevices(AudioManager* audio_man) { |
| 152 // bots and that at least one valid output device can be found. We also | 153 // The low-latency (WASAPI-based) version requires Windows Vista or higher. |
| 153 // verify that we are not running on XP since the low-latency (WASAPI- | |
| 154 // based) version requires Windows Vista or higher. | |
| 155 static bool CanRunAudioTests(AudioManager* audio_man) { | |
| 156 if (!CoreAudioUtil::IsSupported()) { | |
| 157 LOG(WARNING) << "This test requires Windows Vista or higher."; | |
| 158 return false; | |
| 159 } | |
| 160 | |
| 161 // TODO(henrika): note that we use Wave today to query the number of | 154 // TODO(henrika): note that we use Wave today to query the number of |
| 162 // existing output devices. | 155 // existing output devices. |
| 163 if (!audio_man->HasAudioOutputDevices()) { | 156 return CoreAudioUtil::IsSupported() && audio_man->HasAudioOutputDevices(); |
| 164 LOG(WARNING) << "No output devices detected."; | |
| 165 return false; | |
| 166 } | |
| 167 | |
| 168 return true; | |
| 169 } | 157 } |
| 170 | 158 |
| 171 // Convenience method which creates a default AudioOutputStream object but | 159 // Convenience method which creates a default AudioOutputStream object but |
| 172 // also allows the user to modify the default settings. | 160 // also allows the user to modify the default settings. |
| 173 class AudioOutputStreamWrapper { | 161 class AudioOutputStreamWrapper { |
| 174 public: | 162 public: |
| 175 explicit AudioOutputStreamWrapper(AudioManager* audio_manager) | 163 explicit AudioOutputStreamWrapper(AudioManager* audio_manager) |
| 176 : audio_man_(audio_manager), | 164 : audio_man_(audio_manager), |
| 177 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), | 165 format_(AudioParameters::AUDIO_PCM_LOW_LATENCY), |
| 178 bits_per_sample_(kBitsPerSample) { | 166 bits_per_sample_(kBitsPerSample) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 return aos; | 226 return aos; |
| 239 } | 227 } |
| 240 | 228 |
| 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(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 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 235 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 248 if (!CanRunAudioTests(audio_manager.get()) || ExclusiveModeIsEnabled()) | 236 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager) && |
| 249 return; | 237 ExclusiveModeIsEnabled()) |
| 250 | 238 |
| 251 // Default device intended for games, system notification sounds, | 239 // Default device intended for games, system notification sounds, |
| 252 // and voice commands. | 240 // and voice commands. |
| 253 int fs = static_cast<int>( | 241 int fs = static_cast<int>( |
| 254 WASAPIAudioOutputStream::HardwareSampleRate(std::string())); | 242 WASAPIAudioOutputStream::HardwareSampleRate(std::string())); |
| 255 EXPECT_GE(fs, 0); | 243 EXPECT_GE(fs, 0); |
| 256 } | 244 } |
| 257 | 245 |
| 258 // Test Create(), Close() calling sequence. | 246 // Test Create(), Close() calling sequence. |
| 259 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { | 247 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { |
| 260 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 248 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 261 if (!CanRunAudioTests(audio_manager.get())) | 249 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 262 return; | |
| 263 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 250 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 264 aos->Close(); | 251 aos->Close(); |
| 265 } | 252 } |
| 266 | 253 |
| 267 // Test Open(), Close() calling sequence. | 254 // Test Open(), Close() calling sequence. |
| 268 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { | 255 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { |
| 269 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 256 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 270 if (!CanRunAudioTests(audio_manager.get())) | 257 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 271 return; | |
| 272 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 258 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 273 EXPECT_TRUE(aos->Open()); | 259 EXPECT_TRUE(aos->Open()); |
| 274 aos->Close(); | 260 aos->Close(); |
| 275 } | 261 } |
| 276 | 262 |
| 277 // Test Open(), Start(), Close() calling sequence. | 263 // Test Open(), Start(), Close() calling sequence. |
| 278 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { | 264 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { |
| 279 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 265 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 280 if (!CanRunAudioTests(audio_manager.get())) | 266 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 281 return; | |
| 282 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 267 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 283 EXPECT_TRUE(aos->Open()); | 268 EXPECT_TRUE(aos->Open()); |
| 284 MockAudioSourceCallback source; | 269 MockAudioSourceCallback source; |
| 285 EXPECT_CALL(source, OnError(aos)) | 270 EXPECT_CALL(source, OnError(aos)) |
| 286 .Times(0); | 271 .Times(0); |
| 287 aos->Start(&source); | 272 aos->Start(&source); |
| 288 aos->Close(); | 273 aos->Close(); |
| 289 } | 274 } |
| 290 | 275 |
| 291 // Test Open(), Start(), Stop(), Close() calling sequence. | 276 // Test Open(), Start(), Stop(), Close() calling sequence. |
| 292 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { | 277 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { |
| 293 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 278 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 294 if (!CanRunAudioTests(audio_manager.get())) | 279 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 295 return; | |
| 296 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 280 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 297 EXPECT_TRUE(aos->Open()); | 281 EXPECT_TRUE(aos->Open()); |
| 298 MockAudioSourceCallback source; | 282 MockAudioSourceCallback source; |
| 299 EXPECT_CALL(source, OnError(aos)) | 283 EXPECT_CALL(source, OnError(aos)) |
| 300 .Times(0); | 284 .Times(0); |
| 301 aos->Start(&source); | 285 aos->Start(&source); |
| 302 aos->Stop(); | 286 aos->Stop(); |
| 303 aos->Close(); | 287 aos->Close(); |
| 304 } | 288 } |
| 305 | 289 |
| 306 // Test SetVolume(), GetVolume() | 290 // Test SetVolume(), GetVolume() |
| 307 TEST(WASAPIAudioOutputStreamTest, Volume) { | 291 TEST(WASAPIAudioOutputStreamTest, Volume) { |
| 308 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 292 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 309 if (!CanRunAudioTests(audio_manager.get())) | 293 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 310 return; | |
| 311 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 294 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 312 | 295 |
| 313 // Initial volume should be full volume (1.0). | 296 // Initial volume should be full volume (1.0). |
| 314 double volume = 0.0; | 297 double volume = 0.0; |
| 315 aos->GetVolume(&volume); | 298 aos->GetVolume(&volume); |
| 316 EXPECT_EQ(1.0, volume); | 299 EXPECT_EQ(1.0, volume); |
| 317 | 300 |
| 318 // Verify some valid volume settings. | 301 // Verify some valid volume settings. |
| 319 aos->SetVolume(0.0); | 302 aos->SetVolume(0.0); |
| 320 aos->GetVolume(&volume); | 303 aos->GetVolume(&volume); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 336 aos->SetVolume(-0.5); | 319 aos->SetVolume(-0.5); |
| 337 aos->GetVolume(&volume); | 320 aos->GetVolume(&volume); |
| 338 EXPECT_EQ(1.0, volume); | 321 EXPECT_EQ(1.0, volume); |
| 339 | 322 |
| 340 aos->Close(); | 323 aos->Close(); |
| 341 } | 324 } |
| 342 | 325 |
| 343 // Test some additional calling sequences. | 326 // Test some additional calling sequences. |
| 344 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { | 327 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { |
| 345 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 328 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 346 if (!CanRunAudioTests(audio_manager.get())) | 329 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 347 return; | |
| 348 | 330 |
| 349 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 331 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 350 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); | 332 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); |
| 351 | 333 |
| 352 // Open(), Open() is a valid calling sequence (second call does nothing). | 334 // Open(), Open() is a valid calling sequence (second call does nothing). |
| 353 EXPECT_TRUE(aos->Open()); | 335 EXPECT_TRUE(aos->Open()); |
| 354 EXPECT_TRUE(aos->Open()); | 336 EXPECT_TRUE(aos->Open()); |
| 355 | 337 |
| 356 MockAudioSourceCallback source; | 338 MockAudioSourceCallback source; |
| 357 | 339 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 376 EXPECT_TRUE(waos->started()); | 358 EXPECT_TRUE(waos->started()); |
| 377 aos->Stop(); | 359 aos->Stop(); |
| 378 EXPECT_FALSE(waos->started()); | 360 EXPECT_FALSE(waos->started()); |
| 379 | 361 |
| 380 aos->Close(); | 362 aos->Close(); |
| 381 } | 363 } |
| 382 | 364 |
| 383 // Use preferred packet size and verify that rendering starts. | 365 // Use preferred packet size and verify that rendering starts. |
| 384 TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) { | 366 TEST(WASAPIAudioOutputStreamTest, ValidPacketSize) { |
| 385 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 367 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 386 if (!CanRunAudioTests(audio_manager.get())) | 368 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 387 return; | |
| 388 | 369 |
| 389 base::MessageLoopForUI loop; | 370 base::MessageLoopForUI loop; |
| 390 MockAudioSourceCallback source; | 371 MockAudioSourceCallback source; |
| 391 | 372 |
| 392 // Create default WASAPI output stream which plays out in stereo using | 373 // Create default WASAPI output stream which plays out in stereo using |
| 393 // the shared mixing rate. The default buffer size is 10ms. | 374 // the shared mixing rate. The default buffer size is 10ms. |
| 394 AudioOutputStreamWrapper aosw(audio_manager.get()); | 375 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 395 AudioOutputStream* aos = aosw.Create(); | 376 AudioOutputStream* aos = aosw.Create(); |
| 396 EXPECT_TRUE(aos->Open()); | 377 EXPECT_TRUE(aos->Open()); |
| 397 | 378 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 415 | 396 |
| 416 // 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 |
| 417 // 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. |
| 418 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 399 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
| 419 // 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 |
| 420 // 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 |
| 421 // environment variable to a value greater than 0. | 402 // environment variable to a value greater than 0. |
| 422 // The test files are approximately 20 seconds long. | 403 // The test files are approximately 20 seconds long. |
| 423 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { | 404 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { |
| 424 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 405 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 425 if (!CanRunAudioTests(audio_manager.get())) | 406 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager)); |
| 426 return; | |
| 427 | 407 |
| 428 AudioOutputStreamWrapper aosw(audio_manager.get()); | 408 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 429 AudioOutputStream* aos = aosw.Create(); | 409 AudioOutputStream* aos = aosw.Create(); |
| 430 EXPECT_TRUE(aos->Open()); | 410 EXPECT_TRUE(aos->Open()); |
| 431 | 411 |
| 432 std::string file_name; | 412 std::string file_name; |
| 433 if (aosw.sample_rate() == 48000) { | 413 if (aosw.sample_rate() == 48000) { |
| 434 file_name = kSpeechFile_16b_s_48k; | 414 file_name = kSpeechFile_16b_s_48k; |
| 435 } else if (aosw.sample_rate() == 44100) { | 415 } else if (aosw.sample_rate() == 44100) { |
| 436 file_name = kSpeechFile_16b_s_44k; | 416 file_name = kSpeechFile_16b_s_44k; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 464 | 444 |
| 465 DVLOG(0) << ">> Stereo file playout has stopped."; | 445 DVLOG(0) << ">> Stereo file playout has stopped."; |
| 466 aos->Close(); | 446 aos->Close(); |
| 467 } | 447 } |
| 468 | 448 |
| 469 // 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 |
| 470 // certain set of audio parameters and a sample rate of 48kHz. | 450 // certain set of audio parameters and a sample rate of 48kHz. |
| 471 // 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 |
| 472 // manually using log outputs (--v=1). | 452 // manually using log outputs (--v=1). |
| 473 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) { | 453 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) { |
| 474 if (!ExclusiveModeIsEnabled()) | |
| 475 return; | |
| 476 | |
| 477 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 454 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 478 if (!CanRunAudioTests(audio_manager.get())) | 455 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager) && |
| 479 return; | 456 ExclusiveModeIsEnabled()); |
| 480 | 457 |
| 481 AudioOutputStreamWrapper aosw(audio_manager.get()); | 458 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 482 | 459 |
| 483 // 10ms @ 48kHz shall work. | 460 // 10ms @ 48kHz shall work. |
| 484 // 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 |
| 485 // 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. |
| 486 AudioOutputStream* aos = aosw.Create(48000, 480); | 463 AudioOutputStream* aos = aosw.Create(48000, 480); |
| 487 EXPECT_TRUE(aos->Open()); | 464 EXPECT_TRUE(aos->Open()); |
| 488 aos->Close(); | 465 aos->Close(); |
| 489 | 466 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 515 aos = aosw.Create(48000, 160); | 492 aos = aosw.Create(48000, 160); |
| 516 EXPECT_TRUE(aos->Open()); | 493 EXPECT_TRUE(aos->Open()); |
| 517 aos->Close(); | 494 aos->Close(); |
| 518 } | 495 } |
| 519 | 496 |
| 520 // 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 |
| 521 // 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. |
| 522 // 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 |
| 523 // manually using log outputs (--v=1). | 500 // manually using log outputs (--v=1). |
| 524 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) { | 501 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) { |
| 525 if (!ExclusiveModeIsEnabled()) | |
| 526 return; | |
| 527 | |
| 528 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 502 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 529 if (!CanRunAudioTests(audio_manager.get())) | 503 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager) && |
| 530 return; | 504 ExclusiveModeIsEnabled()); |
| 531 | 505 |
| 532 AudioOutputStreamWrapper aosw(audio_manager.get()); | 506 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 533 | 507 |
| 534 // 10ms @ 44.1kHz does not work due to misalignment. | 508 // 10ms @ 44.1kHz does not work due to misalignment. |
| 535 // This test will propose an aligned buffer size of 10.1587ms. | 509 // This test will propose an aligned buffer size of 10.1587ms. |
| 536 AudioOutputStream* aos = aosw.Create(44100, 441); | 510 AudioOutputStream* aos = aosw.Create(44100, 441); |
| 537 EXPECT_FALSE(aos->Open()); | 511 EXPECT_FALSE(aos->Open()); |
| 538 aos->Close(); | 512 aos->Close(); |
| 539 | 513 |
| 540 // 10.1587ms @ 44.1kHz shall work (see test above). | 514 // 10.1587ms @ 44.1kHz shall work (see test above). |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 547 |
| 574 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. | 548 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. |
| 575 aos = aosw.Create(44100, 160); | 549 aos = aosw.Create(44100, 160); |
| 576 EXPECT_TRUE(aos->Open()); | 550 EXPECT_TRUE(aos->Open()); |
| 577 aos->Close(); | 551 aos->Close(); |
| 578 } | 552 } |
| 579 | 553 |
| 580 // 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 |
| 581 // the lowest possible delay at 48kHz. | 555 // the lowest possible delay at 48kHz. |
| 582 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { | 556 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { |
| 583 if (!ExclusiveModeIsEnabled()) | |
| 584 return; | |
| 585 | |
| 586 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 557 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 587 if (!CanRunAudioTests(audio_manager.get())) | 558 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager) && |
| 588 return; | 559 ExclusiveModeIsEnabled()); |
| 589 | 560 |
| 590 base::MessageLoopForUI loop; | 561 base::MessageLoopForUI loop; |
| 591 MockAudioSourceCallback source; | 562 MockAudioSourceCallback source; |
| 592 | 563 |
| 593 // Create exclusive-mode WASAPI output stream which plays out in stereo | 564 // Create exclusive-mode WASAPI output stream which plays out in stereo |
| 594 // using the minimum buffer size at 48kHz sample rate. | 565 // using the minimum buffer size at 48kHz sample rate. |
| 595 AudioOutputStreamWrapper aosw(audio_manager.get()); | 566 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 596 AudioOutputStream* aos = aosw.Create(48000, 160); | 567 AudioOutputStream* aos = aosw.Create(48000, 160); |
| 597 EXPECT_TRUE(aos->Open()); | 568 EXPECT_TRUE(aos->Open()); |
| 598 | 569 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 611 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 582 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 612 TestTimeouts::action_timeout()); | 583 TestTimeouts::action_timeout()); |
| 613 loop.Run(); | 584 loop.Run(); |
| 614 aos->Stop(); | 585 aos->Stop(); |
| 615 aos->Close(); | 586 aos->Close(); |
| 616 } | 587 } |
| 617 | 588 |
| 618 // 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 |
| 619 // the lowest possible delay at 44.1kHz. | 590 // the lowest possible delay at 44.1kHz. |
| 620 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { | 591 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { |
| 621 if (!ExclusiveModeIsEnabled()) | 592 ABORT_AUDIO_TEST_IF_NOT(ExclusiveModeIsEnabled()); |
| 622 return; | |
| 623 | |
| 624 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); | 593 scoped_ptr<AudioManager> audio_manager(AudioManager::CreateForTesting()); |
| 625 if (!CanRunAudioTests(audio_manager.get())) | |
| 626 return; | |
| 627 | 594 |
| 628 base::MessageLoopForUI loop; | 595 base::MessageLoopForUI loop; |
| 629 MockAudioSourceCallback source; | 596 MockAudioSourceCallback source; |
| 630 | 597 |
| 631 // Create exclusive-mode WASAPI output stream which plays out in stereo | 598 // Create exclusive-mode WASAPI output stream which plays out in stereo |
| 632 // using the minimum buffer size at 44.1kHz sample rate. | 599 // using the minimum buffer size at 44.1kHz sample rate. |
| 633 AudioOutputStreamWrapper aosw(audio_manager.get()); | 600 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 634 AudioOutputStream* aos = aosw.Create(44100, 160); | 601 AudioOutputStream* aos = aosw.Create(44100, 160); |
| 635 EXPECT_TRUE(aos->Open()); | 602 EXPECT_TRUE(aos->Open()); |
| 636 | 603 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 647 | 614 |
| 648 aos->Start(&source); | 615 aos->Start(&source); |
| 649 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), | 616 loop.PostDelayedTask(FROM_HERE, base::MessageLoop::QuitClosure(), |
| 650 TestTimeouts::action_timeout()); | 617 TestTimeouts::action_timeout()); |
| 651 loop.Run(); | 618 loop.Run(); |
| 652 aos->Stop(); | 619 aos->Stop(); |
| 653 aos->Close(); | 620 aos->Close(); |
| 654 } | 621 } |
| 655 | 622 |
| 656 } // namespace media | 623 } // namespace media |
| OLD | NEW |