OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 const bool keyPressed, | 421 const bool keyPressed, |
422 uint32_t& newMicLevel) { | 422 uint32_t& newMicLevel) { |
423 EXPECT_TRUE(rec_mode()) << "No test is expecting these callbacks."; | 423 EXPECT_TRUE(rec_mode()) << "No test is expecting these callbacks."; |
424 rec_count_++; | 424 rec_count_++; |
425 // Process the recorded audio stream if an AudioStreamInterface | 425 // Process the recorded audio stream if an AudioStreamInterface |
426 // implementation exists. | 426 // implementation exists. |
427 if (audio_stream_) { | 427 if (audio_stream_) { |
428 audio_stream_->Write(audioSamples, nSamples); | 428 audio_stream_->Write(audioSamples, nSamples); |
429 } | 429 } |
430 if (ReceivedEnoughCallbacks()) { | 430 if (ReceivedEnoughCallbacks()) { |
431 test_is_done_->Set(); | 431 if (test_is_done_) { |
| 432 test_is_done_->Set(); |
| 433 } |
432 } | 434 } |
433 return 0; | 435 return 0; |
434 } | 436 } |
435 | 437 |
436 int32_t RealNeedMorePlayData(const size_t nSamples, | 438 int32_t RealNeedMorePlayData(const size_t nSamples, |
437 const size_t nBytesPerSample, | 439 const size_t nBytesPerSample, |
438 const uint8_t nChannels, | 440 const uint8_t nChannels, |
439 const uint32_t samplesPerSec, | 441 const uint32_t samplesPerSec, |
440 void* audioSamples, | 442 void* audioSamples, |
441 size_t& nSamplesOut, | 443 size_t& nSamplesOut, |
442 int64_t* elapsed_time_ms, | 444 int64_t* elapsed_time_ms, |
443 int64_t* ntp_time_ms) { | 445 int64_t* ntp_time_ms) { |
444 EXPECT_TRUE(play_mode()) << "No test is expecting these callbacks."; | 446 EXPECT_TRUE(play_mode()) << "No test is expecting these callbacks."; |
445 play_count_++; | 447 play_count_++; |
446 nSamplesOut = nSamples; | 448 nSamplesOut = nSamples; |
447 // Read (possibly processed) audio stream samples to be played out if an | 449 // Read (possibly processed) audio stream samples to be played out if an |
448 // AudioStreamInterface implementation exists. | 450 // AudioStreamInterface implementation exists. |
449 if (audio_stream_) { | 451 if (audio_stream_) { |
450 audio_stream_->Read(audioSamples, nSamples); | 452 audio_stream_->Read(audioSamples, nSamples); |
451 } | 453 } |
452 if (ReceivedEnoughCallbacks()) { | 454 if (ReceivedEnoughCallbacks()) { |
453 test_is_done_->Set(); | 455 if (test_is_done_) { |
| 456 test_is_done_->Set(); |
| 457 } |
454 } | 458 } |
455 return 0; | 459 return 0; |
456 } | 460 } |
457 | 461 |
458 bool ReceivedEnoughCallbacks() { | 462 bool ReceivedEnoughCallbacks() { |
459 bool recording_done = false; | 463 bool recording_done = false; |
460 if (rec_mode()) | 464 if (rec_mode()) |
461 recording_done = rec_count_ >= num_callbacks_; | 465 recording_done = rec_count_ >= num_callbacks_; |
462 else | 466 else |
463 recording_done = true; | 467 recording_done = true; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 // RTC_DCHECK. | 635 // RTC_DCHECK. |
632 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) { | 636 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) { |
633 EXPECT_EQ(0, audio_device()->InitPlayout()); | 637 EXPECT_EQ(0, audio_device()->InitPlayout()); |
634 EXPECT_EQ(0, audio_device()->StartPlayout()); | 638 EXPECT_EQ(0, audio_device()->StartPlayout()); |
635 EXPECT_EQ(0, audio_device()->StopPlayout()); | 639 EXPECT_EQ(0, audio_device()->StopPlayout()); |
636 EXPECT_FALSE(audio_device()->PlayoutIsInitialized()); | 640 EXPECT_FALSE(audio_device()->PlayoutIsInitialized()); |
637 } | 641 } |
638 | 642 |
639 // Verify that we can create two ADMs and start playing on the second ADM. | 643 // Verify that we can create two ADMs and start playing on the second ADM. |
640 // Only the first active instance shall activate an audio session and the | 644 // Only the first active instance shall activate an audio session and the |
641 // last active instace shall deactivate the audio session. | 645 // last active instance shall deactivate the audio session. The test does not |
| 646 // explicitly verify correct audio session calls but instead focuses on |
| 647 // ensuring that audio starts for both ADMs. |
642 TEST_F(AudioDeviceTest, StartPlayoutOnTwoInstances) { | 648 TEST_F(AudioDeviceTest, StartPlayoutOnTwoInstances) { |
643 // Create and initialize a second/extra ADM instance. The default ADM is | 649 // Create and initialize a second/extra ADM instance. The default ADM is |
644 // created by the test harness. | 650 // created by the test harness. |
645 rtc::scoped_refptr<AudioDeviceModule> second_audio_device = | 651 rtc::scoped_refptr<AudioDeviceModule> second_audio_device = |
646 CreateAudioDevice(AudioDeviceModule::kPlatformDefaultAudio); | 652 CreateAudioDevice(AudioDeviceModule::kPlatformDefaultAudio); |
647 EXPECT_NE(second_audio_device.get(), nullptr); | 653 EXPECT_NE(second_audio_device.get(), nullptr); |
648 EXPECT_EQ(0, second_audio_device->Init()); | 654 EXPECT_EQ(0, second_audio_device->Init()); |
649 | 655 |
650 // Start playout for the default ADM. Ignore the callback sequence. | 656 // Start playout for the default ADM but don't wait here. Instead use the |
| 657 // upcoming second stream for that. We set the same expectation on number |
| 658 // of callbacks as for the second stream. |
651 NiceMock<MockAudioTransport> mock(kPlayout); | 659 NiceMock<MockAudioTransport> mock(kPlayout); |
| 660 mock.HandleCallbacks(nullptr, nullptr, 0); |
| 661 EXPECT_CALL( |
| 662 mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, |
| 663 playout_channels(), playout_sample_rate(), |
| 664 NotNull(), _, _, _)) |
| 665 .Times(AtLeast(kNumCallbacks)); |
652 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 666 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
653 StartPlayout(); | 667 StartPlayout(); |
654 | 668 |
655 // Initialize playout for the second ADM. If all is OK, the second ADM shall | 669 // Initialize playout for the second ADM. If all is OK, the second ADM shall |
656 // reuse the audio session activated when the first ADM started playing. | 670 // reuse the audio session activated when the first ADM started playing. |
657 // This call will also ensure that we avoid a problem related to initializing | 671 // This call will also ensure that we avoid a problem related to initializing |
658 // two different audio unit instances back to back (see webrtc:5166 for | 672 // two different audio unit instances back to back (see webrtc:5166 for |
659 // details). | 673 // details). |
660 EXPECT_EQ(0, second_audio_device->InitPlayout()); | 674 EXPECT_EQ(0, second_audio_device->InitPlayout()); |
661 EXPECT_TRUE(second_audio_device->PlayoutIsInitialized()); | 675 EXPECT_TRUE(second_audio_device->PlayoutIsInitialized()); |
662 | 676 |
663 // Stop playout for the default ADM. The audio session shall not be | |
664 // deactivated since it is used by the second ADM. | |
665 StopPlayout(); | |
666 | |
667 // Start playout for the second ADM and verify that it starts as intended. | 677 // Start playout for the second ADM and verify that it starts as intended. |
668 // Passing this test ensures that initialization of the second audio unit | 678 // Passing this test ensures that initialization of the second audio unit |
669 // has been done successfully. | 679 // has been done successfully and that there is no conflict with the already |
| 680 // playing first ADM. |
670 MockAudioTransport mock2(kPlayout); | 681 MockAudioTransport mock2(kPlayout); |
671 mock2.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 682 mock2.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
672 EXPECT_CALL( | 683 EXPECT_CALL( |
673 mock2, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, | 684 mock2, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, |
674 playout_channels(), playout_sample_rate(), | 685 playout_channels(), playout_sample_rate(), |
675 NotNull(), _, _, _)) | 686 NotNull(), _, _, _)) |
676 .Times(AtLeast(kNumCallbacks)); | 687 .Times(AtLeast(kNumCallbacks)); |
677 EXPECT_EQ(0, second_audio_device->RegisterAudioCallback(&mock2)); | 688 EXPECT_EQ(0, second_audio_device->RegisterAudioCallback(&mock2)); |
678 EXPECT_EQ(0, second_audio_device->StartPlayout()); | 689 EXPECT_EQ(0, second_audio_device->StartPlayout()); |
679 EXPECT_TRUE(second_audio_device->Playing()); | 690 EXPECT_TRUE(second_audio_device->Playing()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 StopPlayout(); | 838 StopPlayout(); |
828 StopRecording(); | 839 StopRecording(); |
829 // Verify that the correct number of transmitted impulses are detected. | 840 // Verify that the correct number of transmitted impulses are detected. |
830 EXPECT_EQ(latency_audio_stream->num_latency_values(), | 841 EXPECT_EQ(latency_audio_stream->num_latency_values(), |
831 static_cast<size_t>( | 842 static_cast<size_t>( |
832 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); | 843 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); |
833 latency_audio_stream->PrintResults(); | 844 latency_audio_stream->PrintResults(); |
834 } | 845 } |
835 | 846 |
836 } // namespace webrtc | 847 } // namespace webrtc |
OLD | NEW |