| 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/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 using ::testing::Gt; | 33 using ::testing::Gt; |
| 34 using ::testing::InvokeWithoutArgs; | 34 using ::testing::InvokeWithoutArgs; |
| 35 using ::testing::NotNull; | 35 using ::testing::NotNull; |
| 36 using ::testing::Return; | 36 using ::testing::Return; |
| 37 using base::win::ScopedCOMInitializer; | 37 using base::win::ScopedCOMInitializer; |
| 38 | 38 |
| 39 namespace media { | 39 namespace media { |
| 40 | 40 |
| 41 static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; | 41 static const char kSpeechFile_16b_s_48k[] = "speech_16b_stereo_48kHz.raw"; |
| 42 static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; | 42 static const char kSpeechFile_16b_s_44k[] = "speech_16b_stereo_44kHz.raw"; |
| 43 static const char kSpeechFile_16b_m_48k[] = "speech_16b_mono_48kHz.raw"; |
| 44 static const char kSpeechFile_16b_m_44k[] = "speech_16b_mono_44kHz.raw"; |
| 43 static const size_t kFileDurationMs = 20000; | 45 static const size_t kFileDurationMs = 20000; |
| 44 static const size_t kNumFileSegments = 2; | 46 static const size_t kNumFileSegments = 2; |
| 45 | 47 |
| 46 static const size_t kMaxDeltaSamples = 1000; | 48 static const size_t kMaxDeltaSamples = 1000; |
| 47 static const char* kDeltaTimeMsFileName = "delta_times_ms.txt"; | 49 static const char* kDeltaTimeMsFileName = "delta_times_ms.txt"; |
| 48 | 50 |
| 49 MATCHER_P(HasValidDelay, value, "") { | 51 MATCHER_P(HasValidDelay, value, "") { |
| 50 // It is difficult to come up with a perfect test condition for the delay | 52 // It is difficult to come up with a perfect test condition for the delay |
| 51 // estimation. For now, verify that the produced output delay is always | 53 // estimation. For now, verify that the produced output delay is always |
| 52 // larger than the selected buffer size. | 54 // larger than the selected buffer size. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 AudioOutputStreamWrapper aosw(audio_manager); | 243 AudioOutputStreamWrapper aosw(audio_manager); |
| 242 AudioOutputStream* aos = aosw.Create(); | 244 AudioOutputStream* aos = aosw.Create(); |
| 243 return aos; | 245 return aos; |
| 244 } | 246 } |
| 245 | 247 |
| 246 // Verify that we can retrieve the current hardware/mixing sample rate | 248 // Verify that we can retrieve the current hardware/mixing sample rate |
| 247 // for all supported device roles. The ERole enumeration defines constants | 249 // for all supported device roles. The ERole enumeration defines constants |
| 248 // that indicate the role that the system/user has assigned to an audio | 250 // that indicate the role that the system/user has assigned to an audio |
| 249 // endpoint device. | 251 // endpoint device. |
| 250 // TODO(henrika): modify this test when we support full device enumeration. | 252 // TODO(henrika): modify this test when we support full device enumeration. |
| 251 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestHardwareSampleRate) { | 253 TEST(WASAPIAudioOutputStreamTest, HardwareSampleRate) { |
| 252 // Skip this test in exclusive mode since the resulting rate is only utilized | 254 // Skip this test in exclusive mode since the resulting rate is only utilized |
| 253 // for shared mode streams. | 255 // for shared mode streams. |
| 254 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 256 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 255 if (!CanRunAudioTests(audio_manager.get()) || ExclusiveModeIsEnabled()) | 257 if (!CanRunAudioTests(audio_manager.get()) || ExclusiveModeIsEnabled()) |
| 256 return; | 258 return; |
| 257 | 259 |
| 258 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | 260 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| 259 | 261 |
| 260 // Default device intended for games, system notification sounds, | 262 // Default device intended for games, system notification sounds, |
| 261 // and voice commands. | 263 // and voice commands. |
| 262 int fs = static_cast<int>( | 264 int fs = static_cast<int>( |
| 263 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 265 WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); |
| 264 EXPECT_GE(fs, 0); | 266 EXPECT_GE(fs, 0); |
| 265 | 267 |
| 266 // Default communication device intended for e.g. VoIP communication. | 268 // Default communication device intended for e.g. VoIP communication. |
| 267 fs = static_cast<int>( | 269 fs = static_cast<int>( |
| 268 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); | 270 WASAPIAudioOutputStream::HardwareSampleRate(eCommunications)); |
| 269 EXPECT_GE(fs, 0); | 271 EXPECT_GE(fs, 0); |
| 270 | 272 |
| 271 // Multimedia device for music, movies and live music recording. | 273 // Multimedia device for music, movies and live music recording. |
| 272 fs = static_cast<int>( | 274 fs = static_cast<int>( |
| 273 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); | 275 WASAPIAudioOutputStream::HardwareSampleRate(eMultimedia)); |
| 274 EXPECT_GE(fs, 0); | 276 EXPECT_GE(fs, 0); |
| 275 } | 277 } |
| 276 | 278 |
| 277 // Test Create(), Close() calling sequence. | 279 // Test Create(), Close() calling sequence. |
| 278 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestCreateAndClose) { | 280 TEST(WASAPIAudioOutputStreamTest, CreateAndClose) { |
| 279 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 281 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 280 if (!CanRunAudioTests(audio_manager.get())) | 282 if (!CanRunAudioTests(audio_manager.get())) |
| 281 return; | 283 return; |
| 282 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 284 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 283 aos->Close(); | 285 aos->Close(); |
| 284 } | 286 } |
| 285 | 287 |
| 288 // Verify that the created object is configured to use the same number of |
| 289 // audio channels as is reported by the static HardwareChannelCount() method. |
| 290 TEST(WASAPIAudioOutputStreamTest, HardwareChannelCount) { |
| 291 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 292 if (!CanRunAudioTests(audio_manager.get())) |
| 293 return; |
| 294 |
| 295 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); |
| 296 |
| 297 // First, verify that we can read a valid native/hardware channel-count. |
| 298 int hardware_channel_count = WASAPIAudioOutputStream::HardwareChannelCount(); |
| 299 EXPECT_GE(hardware_channel_count, 1); |
| 300 |
| 301 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 302 WASAPIAudioOutputStream* aosw = static_cast<WASAPIAudioOutputStream*>(aos); |
| 303 |
| 304 // Next, ensure that the created output stream object is really using the |
| 305 // hardware channel-count. |
| 306 EXPECT_EQ(hardware_channel_count, aosw->endpoint_channel_count()); |
| 307 aos->Close(); |
| 308 } |
| 309 |
| 286 // Test Open(), Close() calling sequence. | 310 // Test Open(), Close() calling sequence. |
| 287 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenAndClose) { | 311 TEST(WASAPIAudioOutputStreamTest, OpenAndClose) { |
| 288 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 312 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 289 if (!CanRunAudioTests(audio_manager.get())) | 313 if (!CanRunAudioTests(audio_manager.get())) |
| 290 return; | 314 return; |
| 291 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 315 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 292 EXPECT_TRUE(aos->Open()); | 316 EXPECT_TRUE(aos->Open()); |
| 293 aos->Close(); | 317 aos->Close(); |
| 294 } | 318 } |
| 295 | 319 |
| 296 // Test Open(), Start(), Close() calling sequence. | 320 // Test Open(), Start(), Close() calling sequence. |
| 297 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartAndClose) { | 321 TEST(WASAPIAudioOutputStreamTest, OpenStartAndClose) { |
| 298 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 322 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 299 if (!CanRunAudioTests(audio_manager.get())) | 323 if (!CanRunAudioTests(audio_manager.get())) |
| 300 return; | 324 return; |
| 301 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 325 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 302 EXPECT_TRUE(aos->Open()); | 326 EXPECT_TRUE(aos->Open()); |
| 303 MockAudioSourceCallback source; | 327 MockAudioSourceCallback source; |
| 304 EXPECT_CALL(source, OnError(aos, _)) | 328 EXPECT_CALL(source, OnError(aos, _)) |
| 305 .Times(0); | 329 .Times(0); |
| 306 aos->Start(&source); | 330 aos->Start(&source); |
| 307 aos->Close(); | 331 aos->Close(); |
| 308 } | 332 } |
| 309 | 333 |
| 310 // Test Open(), Start(), Stop(), Close() calling sequence. | 334 // Test Open(), Start(), Stop(), Close() calling sequence. |
| 311 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestOpenStartStopAndClose) { | 335 TEST(WASAPIAudioOutputStreamTest, OpenStartStopAndClose) { |
| 312 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 336 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 313 if (!CanRunAudioTests(audio_manager.get())) | 337 if (!CanRunAudioTests(audio_manager.get())) |
| 314 return; | 338 return; |
| 315 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 339 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 316 EXPECT_TRUE(aos->Open()); | 340 EXPECT_TRUE(aos->Open()); |
| 317 MockAudioSourceCallback source; | 341 MockAudioSourceCallback source; |
| 318 EXPECT_CALL(source, OnError(aos, _)) | 342 EXPECT_CALL(source, OnError(aos, _)) |
| 319 .Times(0); | 343 .Times(0); |
| 320 aos->Start(&source); | 344 aos->Start(&source); |
| 321 aos->Stop(); | 345 aos->Stop(); |
| 322 aos->Close(); | 346 aos->Close(); |
| 323 } | 347 } |
| 324 | 348 |
| 325 // Test SetVolume(), GetVolume() | 349 // Test SetVolume(), GetVolume() |
| 326 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestVolume) { | 350 TEST(WASAPIAudioOutputStreamTest, Volume) { |
| 327 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 351 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 328 if (!CanRunAudioTests(audio_manager.get())) | 352 if (!CanRunAudioTests(audio_manager.get())) |
| 329 return; | 353 return; |
| 330 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 354 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 331 | 355 |
| 332 // Initial volume should be full volume (1.0). | 356 // Initial volume should be full volume (1.0). |
| 333 double volume = 0.0; | 357 double volume = 0.0; |
| 334 aos->GetVolume(&volume); | 358 aos->GetVolume(&volume); |
| 335 EXPECT_EQ(1.0, volume); | 359 EXPECT_EQ(1.0, volume); |
| 336 | 360 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 353 EXPECT_EQ(1.0, volume); | 377 EXPECT_EQ(1.0, volume); |
| 354 | 378 |
| 355 aos->SetVolume(-0.5); | 379 aos->SetVolume(-0.5); |
| 356 aos->GetVolume(&volume); | 380 aos->GetVolume(&volume); |
| 357 EXPECT_EQ(1.0, volume); | 381 EXPECT_EQ(1.0, volume); |
| 358 | 382 |
| 359 aos->Close(); | 383 aos->Close(); |
| 360 } | 384 } |
| 361 | 385 |
| 362 // Test some additional calling sequences. | 386 // Test some additional calling sequences. |
| 363 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMiscCallingSequences) { | 387 TEST(WASAPIAudioOutputStreamTest, MiscCallingSequences) { |
| 364 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 388 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 365 if (!CanRunAudioTests(audio_manager.get())) | 389 if (!CanRunAudioTests(audio_manager.get())) |
| 366 return; | 390 return; |
| 367 | 391 |
| 368 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); | 392 AudioOutputStream* aos = CreateDefaultAudioOutputStream(audio_manager.get()); |
| 369 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); | 393 WASAPIAudioOutputStream* waos = static_cast<WASAPIAudioOutputStream*>(aos); |
| 370 | 394 |
| 371 // Open(), Open() is a valid calling sequence (second call does nothing). | 395 // Open(), Open() is a valid calling sequence (second call does nothing). |
| 372 EXPECT_TRUE(aos->Open()); | 396 EXPECT_TRUE(aos->Open()); |
| 373 EXPECT_TRUE(aos->Open()); | 397 EXPECT_TRUE(aos->Open()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 393 EXPECT_FALSE(waos->started()); | 417 EXPECT_FALSE(waos->started()); |
| 394 aos->Start(&source); | 418 aos->Start(&source); |
| 395 EXPECT_TRUE(waos->started()); | 419 EXPECT_TRUE(waos->started()); |
| 396 aos->Stop(); | 420 aos->Stop(); |
| 397 EXPECT_FALSE(waos->started()); | 421 EXPECT_FALSE(waos->started()); |
| 398 | 422 |
| 399 aos->Close(); | 423 aos->Close(); |
| 400 } | 424 } |
| 401 | 425 |
| 402 // Use default packet size (10ms) and verify that rendering starts. | 426 // Use default packet size (10ms) and verify that rendering starts. |
| 403 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInMilliseconds) { | 427 TEST(WASAPIAudioOutputStreamTest, PacketSizeInMilliseconds) { |
| 404 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 428 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 405 if (!CanRunAudioTests(audio_manager.get())) | 429 if (!CanRunAudioTests(audio_manager.get())) |
| 406 return; | 430 return; |
| 407 | 431 |
| 408 MessageLoopForUI loop; | 432 MessageLoopForUI loop; |
| 409 MockAudioSourceCallback source; | 433 MockAudioSourceCallback source; |
| 410 | 434 |
| 411 // Create default WASAPI output stream which plays out in stereo using | 435 // Create default WASAPI output stream which plays out in stereo using |
| 412 // the shared mixing rate. The default buffer size is 10ms. | 436 // the shared mixing rate. The default buffer size is 10ms. |
| 413 AudioOutputStreamWrapper aosw(audio_manager.get()); | 437 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 431 aos->Start(&source); | 455 aos->Start(&source); |
| 432 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 456 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 433 TestTimeouts::action_timeout()); | 457 TestTimeouts::action_timeout()); |
| 434 loop.Run(); | 458 loop.Run(); |
| 435 aos->Stop(); | 459 aos->Stop(); |
| 436 aos->Close(); | 460 aos->Close(); |
| 437 } | 461 } |
| 438 | 462 |
| 439 // Use a fixed packets size (independent of sample rate) and verify | 463 // Use a fixed packets size (independent of sample rate) and verify |
| 440 // that rendering starts. | 464 // that rendering starts. |
| 441 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestPacketSizeInSamples) { | 465 TEST(WASAPIAudioOutputStreamTest, PacketSizeInSamples) { |
| 442 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 466 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 443 if (!CanRunAudioTests(audio_manager.get())) | 467 if (!CanRunAudioTests(audio_manager.get())) |
| 444 return; | 468 return; |
| 445 | 469 |
| 446 MessageLoopForUI loop; | 470 MessageLoopForUI loop; |
| 447 MockAudioSourceCallback source; | 471 MockAudioSourceCallback source; |
| 448 | 472 |
| 449 // Create default WASAPI output stream which plays out in stereo using | 473 // Create default WASAPI output stream which reads data in stereo using |
| 450 // the shared mixing rate. The buffer size is set to 1024 samples. | 474 // the native mixing rate and channel count. The buffer size is set to |
| 475 // 1024 samples. |
| 451 AudioOutputStreamWrapper aosw(audio_manager.get()); | 476 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 452 AudioOutputStream* aos = aosw.Create(1024); | 477 AudioOutputStream* aos = aosw.Create(1024); |
| 453 EXPECT_TRUE(aos->Open()); | 478 EXPECT_TRUE(aos->Open()); |
| 454 | 479 |
| 455 // Derive the expected size in bytes of each packet. | 480 // Derive the expected size in bytes of each packet. |
| 456 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 481 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 457 (aosw.bits_per_sample() / 8); | 482 (aosw.bits_per_sample() / 8); |
| 458 | 483 |
| 459 // Set up expected minimum delay estimation. | 484 // Set up expected minimum delay estimation. |
| 460 AudioBuffersState state(0, bytes_per_packet); | 485 AudioBuffersState state(0, bytes_per_packet); |
| 461 | 486 |
| 462 // Ensure that callbacks start correctly. | 487 // Ensure that callbacks start correctly. |
| 463 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, | 488 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, |
| 464 HasValidDelay(state))) | 489 HasValidDelay(state))) |
| 465 .WillOnce(DoAll( | 490 .WillOnce(DoAll( |
| 466 QuitLoop(loop.message_loop_proxy()), | 491 QuitLoop(loop.message_loop_proxy()), |
| 467 Return(bytes_per_packet))) | 492 Return(bytes_per_packet))) |
| 468 .WillRepeatedly(Return(bytes_per_packet)); | 493 .WillRepeatedly(Return(bytes_per_packet)); |
| 469 | 494 |
| 470 aos->Start(&source); | 495 aos->Start(&source); |
| 471 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 496 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 472 TestTimeouts::action_timeout()); | 497 TestTimeouts::action_timeout()); |
| 473 loop.Run(); | 498 loop.Run(); |
| 474 aos->Stop(); | 499 aos->Stop(); |
| 475 aos->Close(); | 500 aos->Close(); |
| 476 } | 501 } |
| 477 | 502 |
| 478 TEST(WinAudioOutputTest, WASAPIAudioOutputStreamTestMono) { | 503 TEST(WASAPIAudioOutputStreamTest, Mono) { |
| 479 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 504 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 480 if (!CanRunAudioTests(audio_manager.get())) | 505 if (!CanRunAudioTests(audio_manager.get())) |
| 481 return; | 506 return; |
| 482 | 507 |
| 483 MessageLoopForUI loop; | 508 MessageLoopForUI loop; |
| 484 MockAudioSourceCallback source; | 509 MockAudioSourceCallback source; |
| 485 | 510 |
| 486 // Create default WASAPI output stream which plays out in *mono* using | 511 // Create default WASAPI output stream which reads data *mono* using |
| 487 // the shared mixing rate. The default buffer size is 10ms. | 512 // the native mixing rate and channel count. The default buffer size is 10ms. |
| 488 AudioOutputStreamWrapper aosw(audio_manager.get()); | 513 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 489 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); | 514 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); |
| 515 EXPECT_TRUE(aos->Open()); |
| 490 | 516 |
| 491 bool opened = aos->Open(); | |
| 492 if (!opened) { | |
| 493 // It was not possible to open this audio device in mono. | |
| 494 // No point in continuing the test so let's break here. | |
| 495 LOG(WARNING) << "Mono is not supported. Skipping test."; | |
| 496 aos->Close(); | |
| 497 return; | |
| 498 } | |
| 499 // Derive the expected size in bytes of each packet. | 517 // Derive the expected size in bytes of each packet. |
| 500 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * | 518 uint32 bytes_per_packet = aosw.channels() * aosw.samples_per_packet() * |
| 501 (aosw.bits_per_sample() / 8); | 519 (aosw.bits_per_sample() / 8); |
| 502 | 520 |
| 503 // Set up expected minimum delay estimation. | 521 // Set up expected minimum delay estimation. |
| 504 AudioBuffersState state(0, bytes_per_packet); | 522 AudioBuffersState state(0, bytes_per_packet); |
| 505 | 523 |
| 506 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, | 524 EXPECT_CALL(source, OnMoreData(NotNull(), bytes_per_packet, |
| 507 HasValidDelay(state))) | 525 HasValidDelay(state))) |
| 508 .WillOnce(DoAll( | 526 .WillOnce(DoAll( |
| 509 QuitLoop(loop.message_loop_proxy()), | 527 QuitLoop(loop.message_loop_proxy()), |
| 510 Return(bytes_per_packet))) | 528 Return(bytes_per_packet))) |
| 511 .WillRepeatedly(Return(bytes_per_packet)); | 529 .WillRepeatedly(Return(bytes_per_packet)); |
| 512 | 530 |
| 513 aos->Start(&source); | 531 aos->Start(&source); |
| 514 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 532 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 515 TestTimeouts::action_timeout()); | 533 TestTimeouts::action_timeout()); |
| 516 loop.Run(); | 534 loop.Run(); |
| 517 aos->Stop(); | 535 aos->Stop(); |
| 518 aos->Close(); | 536 aos->Close(); |
| 519 } | 537 } |
| 520 | 538 |
| 521 // This test is intended for manual tests and should only be enabled | 539 // This test is intended for manual tests and should only be enabled |
| 522 // when it is required to store the captured data on a local file. | 540 // when it is required to play out data from a local PCM file. |
| 523 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 541 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. |
| 524 // To include disabled tests in test execution, just invoke the test program | 542 // To include disabled tests in test execution, just invoke the test program |
| 525 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 543 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS |
| 526 // environment variable to a value greater than 0. | 544 // environment variable to a value greater than 0. |
| 527 // The test files are approximately 20 seconds long. | 545 // The test files are approximately 20 seconds long. |
| 528 TEST(WinAudioOutputTest, DISABLED_WASAPIAudioOutputStreamReadFromFile) { | 546 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromStereoFile) { |
| 529 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 547 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 530 if (!CanRunAudioTests(audio_manager.get())) | 548 if (!CanRunAudioTests(audio_manager.get())) |
| 531 return; | 549 return; |
| 532 | 550 |
| 533 AudioOutputStreamWrapper aosw(audio_manager.get()); | 551 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 534 AudioOutputStream* aos = aosw.Create(); | 552 AudioOutputStream* aos = aosw.Create(); |
| 535 EXPECT_TRUE(aos->Open()); | 553 EXPECT_TRUE(aos->Open()); |
| 536 | 554 |
| 537 std::string file_name; | 555 std::string file_name; |
| 538 if (aosw.sample_rate() == 48000) { | 556 if (aosw.sample_rate() == 48000) { |
| 539 file_name = kSpeechFile_16b_s_48k; | 557 file_name = kSpeechFile_16b_s_48k; |
| 540 } else if (aosw.sample_rate() == 44100) { | 558 } else if (aosw.sample_rate() == 44100) { |
| 541 file_name = kSpeechFile_16b_s_44k; | 559 file_name = kSpeechFile_16b_s_44k; |
| 542 } else if (aosw.sample_rate() == 96000) { | 560 } else if (aosw.sample_rate() == 96000) { |
| 543 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. | 561 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. |
| 544 file_name = kSpeechFile_16b_s_48k; | 562 file_name = kSpeechFile_16b_s_48k; |
| 545 } else { | 563 } else { |
| 546 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; | 564 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; |
| 547 return; | 565 return; |
| 548 } | 566 } |
| 549 ReadFromFileAudioSource file_source(file_name); | 567 ReadFromFileAudioSource file_source(file_name); |
| 550 | 568 |
| 551 LOG(INFO) << "File name : " << file_name.c_str(); | 569 LOG(INFO) << "File name : " << file_name.c_str(); |
| 552 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); | 570 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); |
| 571 LOG(INFO) << "#channels : " << aosw.channels(); |
| 553 LOG(INFO) << "File size : " << file_source.file_size(); | 572 LOG(INFO) << "File size : " << file_source.file_size(); |
| 554 LOG(INFO) << "#file segments: " << kNumFileSegments; | 573 LOG(INFO) << "#file segments: " << kNumFileSegments; |
| 555 LOG(INFO) << ">> Listen to the file while playing..."; | 574 LOG(INFO) << ">> Listen to the stereo file while playing..."; |
| 556 | 575 |
| 557 for (int i = 0; i < kNumFileSegments; i++) { | 576 for (int i = 0; i < kNumFileSegments; i++) { |
| 558 // Each segment will start with a short (~20ms) block of zeros, hence | 577 // Each segment will start with a short (~20ms) block of zeros, hence |
| 559 // some short glitches might be heard in this test if kNumFileSegments | 578 // some short glitches might be heard in this test if kNumFileSegments |
| 560 // is larger than one. The exact length of the silence period depends on | 579 // is larger than one. The exact length of the silence period depends on |
| 561 // the selected sample rate. | 580 // the selected sample rate. |
| 562 aos->Start(&file_source); | 581 aos->Start(&file_source); |
| 563 base::PlatformThread::Sleep( | 582 base::PlatformThread::Sleep( |
| 564 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); | 583 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); |
| 565 aos->Stop(); | 584 aos->Stop(); |
| 566 } | 585 } |
| 567 | 586 |
| 568 LOG(INFO) << ">> File playout has stopped."; | 587 LOG(INFO) << ">> Stereo file playout has stopped."; |
| 569 aos->Close(); | 588 aos->Close(); |
| 570 } | 589 } |
| 571 | 590 |
| 591 // Same as the stereo test but reading and playing out a mono file instead. |
| 592 // It means that most likely a 1->2 channel up-mix will be performed. |
| 593 TEST(WASAPIAudioOutputStreamTest, DISABLED_ReadFromMonoFile) { |
| 594 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 595 if (!CanRunAudioTests(audio_manager.get())) |
| 596 return; |
| 597 |
| 598 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 599 AudioOutputStream* aos = aosw.Create(CHANNEL_LAYOUT_MONO); |
| 600 EXPECT_TRUE(aos->Open()); |
| 601 |
| 602 std::string file_name; |
| 603 if (aosw.sample_rate() == 48000) { |
| 604 file_name = kSpeechFile_16b_m_48k; |
| 605 } else if (aosw.sample_rate() == 44100) { |
| 606 file_name = kSpeechFile_16b_m_44k; |
| 607 } else if (aosw.sample_rate() == 96000) { |
| 608 // Use 48kHz file at 96kHz as well. Will sound like Donald Duck. |
| 609 file_name = kSpeechFile_16b_m_48k; |
| 610 } else { |
| 611 FAIL() << "This test supports 44.1, 48kHz and 96kHz only."; |
| 612 return; |
| 613 } |
| 614 ReadFromFileAudioSource file_source(file_name); |
| 615 |
| 616 LOG(INFO) << "File name : " << file_name.c_str(); |
| 617 LOG(INFO) << "Sample rate : " << aosw.sample_rate(); |
| 618 LOG(INFO) << "#channels : " << aosw.channels(); |
| 619 LOG(INFO) << "File size : " << file_source.file_size(); |
| 620 LOG(INFO) << "#file segments: " << kNumFileSegments; |
| 621 LOG(INFO) << ">> Listen to the mono file while playing..."; |
| 622 |
| 623 for (int i = 0; i < kNumFileSegments; i++) { |
| 624 // Each segment will start with a short (~20ms) block of zeros, hence |
| 625 // some short glitches might be heard in this test if kNumFileSegments |
| 626 // is larger than one. The exact length of the silence period depends on |
| 627 // the selected sample rate. |
| 628 aos->Start(&file_source); |
| 629 base::PlatformThread::Sleep( |
| 630 base::TimeDelta::FromMilliseconds(kFileDurationMs / kNumFileSegments)); |
| 631 aos->Stop(); |
| 632 } |
| 633 |
| 634 LOG(INFO) << ">> Mono file playout has stopped."; |
| 635 aos->Close(); |
| 636 } |
| 637 |
| 572 // Verify that we can open the output stream in exclusive mode using a | 638 // Verify that we can open the output stream in exclusive mode using a |
| 573 // certain set of audio parameters and a sample rate of 48kHz. | 639 // certain set of audio parameters and a sample rate of 48kHz. |
| 574 // The expected outcomes of each setting in this test has been derived | 640 // The expected outcomes of each setting in this test has been derived |
| 575 // manually using log outputs (--v=1). | 641 // manually using log outputs (--v=1). |
| 576 TEST(WinAudioOutputTest, WASAPIExclusiveModeBufferSizesAt48kHz) { | 642 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt48kHz) { |
| 577 if (!ExclusiveModeIsEnabled()) | 643 if (!ExclusiveModeIsEnabled()) |
| 578 return; | 644 return; |
| 579 | 645 |
| 580 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 646 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 581 if (!CanRunAudioTests(audio_manager.get())) | 647 if (!CanRunAudioTests(audio_manager.get())) |
| 582 return; | 648 return; |
| 583 | 649 |
| 584 AudioOutputStreamWrapper aosw(audio_manager.get()); | 650 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 585 | 651 |
| 586 // 10ms @ 48kHz shall work. | 652 // 10ms @ 48kHz shall work. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 617 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use. | 683 // 3.3333ms @ 48kHz <=> smallest possible buffer size we can use. |
| 618 aos = aosw.Create(48000, 160); | 684 aos = aosw.Create(48000, 160); |
| 619 EXPECT_TRUE(aos->Open()); | 685 EXPECT_TRUE(aos->Open()); |
| 620 aos->Close(); | 686 aos->Close(); |
| 621 } | 687 } |
| 622 | 688 |
| 623 // Verify that we can open the output stream in exclusive mode using a | 689 // Verify that we can open the output stream in exclusive mode using a |
| 624 // certain set of audio parameters and a sample rate of 44.1kHz. | 690 // certain set of audio parameters and a sample rate of 44.1kHz. |
| 625 // The expected outcomes of each setting in this test has been derived | 691 // The expected outcomes of each setting in this test has been derived |
| 626 // manually using log outputs (--v=1). | 692 // manually using log outputs (--v=1). |
| 627 TEST(WinAudioOutputTest, WASAPIExclusiveModeBufferSizesAt44kHz) { | 693 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeBufferSizesAt44kHz) { |
| 628 if (!ExclusiveModeIsEnabled()) | 694 if (!ExclusiveModeIsEnabled()) |
| 629 return; | 695 return; |
| 630 | 696 |
| 631 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 697 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 632 if (!CanRunAudioTests(audio_manager.get())) | 698 if (!CanRunAudioTests(audio_manager.get())) |
| 633 return; | 699 return; |
| 634 | 700 |
| 635 AudioOutputStreamWrapper aosw(audio_manager.get()); | 701 AudioOutputStreamWrapper aosw(audio_manager.get()); |
| 636 | 702 |
| 637 // 10ms @ 44.1kHz does not work due to misalignment. | 703 // 10ms @ 44.1kHz does not work due to misalignment. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 aos->Close(); | 741 aos->Close(); |
| 676 | 742 |
| 677 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. | 743 // 3.6281ms @ 44.1kHz <=> smallest possible buffer size we can use. |
| 678 aos = aosw.Create(44100, 160); | 744 aos = aosw.Create(44100, 160); |
| 679 EXPECT_TRUE(aos->Open()); | 745 EXPECT_TRUE(aos->Open()); |
| 680 aos->Close(); | 746 aos->Close(); |
| 681 } | 747 } |
| 682 | 748 |
| 683 // Verify that we can open and start the output stream in exclusive mode at | 749 // Verify that we can open and start the output stream in exclusive mode at |
| 684 // the lowest possible delay at 48kHz. | 750 // the lowest possible delay at 48kHz. |
| 685 TEST(WinAudioOutputTest, WASAPIExclusiveModeMinBufferSizeAt48kHz) { | 751 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt48kHz) { |
| 686 if (!ExclusiveModeIsEnabled()) | 752 if (!ExclusiveModeIsEnabled()) |
| 687 return; | 753 return; |
| 688 | 754 |
| 689 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 755 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 690 if (!CanRunAudioTests(audio_manager.get())) | 756 if (!CanRunAudioTests(audio_manager.get())) |
| 691 return; | 757 return; |
| 692 | 758 |
| 693 MessageLoopForUI loop; | 759 MessageLoopForUI loop; |
| 694 MockAudioSourceCallback source; | 760 MockAudioSourceCallback source; |
| 695 | 761 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 717 aos->Start(&source); | 783 aos->Start(&source); |
| 718 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 784 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 719 TestTimeouts::action_timeout()); | 785 TestTimeouts::action_timeout()); |
| 720 loop.Run(); | 786 loop.Run(); |
| 721 aos->Stop(); | 787 aos->Stop(); |
| 722 aos->Close(); | 788 aos->Close(); |
| 723 } | 789 } |
| 724 | 790 |
| 725 // Verify that we can open and start the output stream in exclusive mode at | 791 // Verify that we can open and start the output stream in exclusive mode at |
| 726 // the lowest possible delay at 44.1kHz. | 792 // the lowest possible delay at 44.1kHz. |
| 727 TEST(WinAudioOutputTest, WASAPIExclusiveModeMinBufferSizeAt44kHz) { | 793 TEST(WASAPIAudioOutputStreamTest, ExclusiveModeMinBufferSizeAt44kHz) { |
| 728 if (!ExclusiveModeIsEnabled()) | 794 if (!ExclusiveModeIsEnabled()) |
| 729 return; | 795 return; |
| 730 | 796 |
| 731 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 797 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 732 if (!CanRunAudioTests(audio_manager.get())) | 798 if (!CanRunAudioTests(audio_manager.get())) |
| 733 return; | 799 return; |
| 734 | 800 |
| 735 MessageLoopForUI loop; | 801 MessageLoopForUI loop; |
| 736 MockAudioSourceCallback source; | 802 MockAudioSourceCallback source; |
| 737 | 803 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 758 | 824 |
| 759 aos->Start(&source); | 825 aos->Start(&source); |
| 760 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 826 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 761 TestTimeouts::action_timeout()); | 827 TestTimeouts::action_timeout()); |
| 762 loop.Run(); | 828 loop.Run(); |
| 763 aos->Stop(); | 829 aos->Stop(); |
| 764 aos->Close(); | 830 aos->Close(); |
| 765 } | 831 } |
| 766 | 832 |
| 767 } // namespace media | 833 } // namespace media |
| OLD | NEW |