| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // which will require a new call to InitPlayout(). This test does not call | 629 // which will require a new call to InitPlayout(). This test does not call |
| 630 // StartPlayout() while being uninitialized since doing so will hit a | 630 // StartPlayout() while being uninitialized since doing so will hit a |
| 631 // RTC_DCHECK. | 631 // RTC_DCHECK. |
| 632 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) { | 632 TEST_F(AudioDeviceTest, StopPlayoutRequiresInitToRestart) { |
| 633 EXPECT_EQ(0, audio_device()->InitPlayout()); | 633 EXPECT_EQ(0, audio_device()->InitPlayout()); |
| 634 EXPECT_EQ(0, audio_device()->StartPlayout()); | 634 EXPECT_EQ(0, audio_device()->StartPlayout()); |
| 635 EXPECT_EQ(0, audio_device()->StopPlayout()); | 635 EXPECT_EQ(0, audio_device()->StopPlayout()); |
| 636 EXPECT_FALSE(audio_device()->PlayoutIsInitialized()); | 636 EXPECT_FALSE(audio_device()->PlayoutIsInitialized()); |
| 637 } | 637 } |
| 638 | 638 |
| 639 // 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 |
| 641 // last active instace shall deactivate the audio session. |
| 642 TEST_F(AudioDeviceTest, StartPlayoutOnTwoInstances) { |
| 643 // Create and initialize a second/extra ADM instance. The default ADM is |
| 644 // created by the test harness. |
| 645 rtc::scoped_refptr<AudioDeviceModule> second_audio_device = |
| 646 CreateAudioDevice(AudioDeviceModule::kPlatformDefaultAudio); |
| 647 EXPECT_NE(second_audio_device.get(), nullptr); |
| 648 EXPECT_EQ(0, second_audio_device->Init()); |
| 649 |
| 650 // Start playout for the default ADM. Ignore the callback sequence. |
| 651 NiceMock<MockAudioTransport> mock(kPlayout); |
| 652 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
| 653 StartPlayout(); |
| 654 |
| 655 // 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. |
| 657 // 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 |
| 659 // details). |
| 660 EXPECT_EQ(0, second_audio_device->InitPlayout()); |
| 661 EXPECT_TRUE(second_audio_device->PlayoutIsInitialized()); |
| 662 |
| 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. |
| 668 // Passing this test ensures that initialization of the second audio unit |
| 669 // has been done successfully. |
| 670 MockAudioTransport mock2(kPlayout); |
| 671 mock2.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
| 672 EXPECT_CALL( |
| 673 mock2, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, |
| 674 playout_channels(), playout_sample_rate(), |
| 675 NotNull(), _, _, _)) |
| 676 .Times(AtLeast(kNumCallbacks)); |
| 677 EXPECT_EQ(0, second_audio_device->RegisterAudioCallback(&mock2)); |
| 678 EXPECT_EQ(0, second_audio_device->StartPlayout()); |
| 679 EXPECT_TRUE(second_audio_device->Playing()); |
| 680 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
| 681 EXPECT_EQ(0, second_audio_device->StopPlayout()); |
| 682 EXPECT_FALSE(second_audio_device->Playing()); |
| 683 EXPECT_FALSE(second_audio_device->PlayoutIsInitialized()); |
| 684 |
| 685 EXPECT_EQ(0, second_audio_device->Terminate()); |
| 686 } |
| 687 |
| 639 // Start playout and verify that the native audio layer starts asking for real | 688 // Start playout and verify that the native audio layer starts asking for real |
| 640 // audio samples to play out using the NeedMorePlayData callback. | 689 // audio samples to play out using the NeedMorePlayData callback. |
| 641 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { | 690 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { |
| 642 MockAudioTransport mock(kPlayout); | 691 MockAudioTransport mock(kPlayout); |
| 643 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 692 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
| 644 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), | 693 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), |
| 645 kBytesPerSample, playout_channels(), | 694 kBytesPerSample, playout_channels(), |
| 646 playout_sample_rate(), NotNull(), _, _, _)) | 695 playout_sample_rate(), NotNull(), _, _, _)) |
| 647 .Times(AtLeast(kNumCallbacks)); | 696 .Times(AtLeast(kNumCallbacks)); |
| 648 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 697 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 StopPlayout(); | 827 StopPlayout(); |
| 779 StopRecording(); | 828 StopRecording(); |
| 780 // Verify that the correct number of transmitted impulses are detected. | 829 // Verify that the correct number of transmitted impulses are detected. |
| 781 EXPECT_EQ(latency_audio_stream->num_latency_values(), | 830 EXPECT_EQ(latency_audio_stream->num_latency_values(), |
| 782 static_cast<size_t>( | 831 static_cast<size_t>( |
| 783 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); | 832 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); |
| 784 latency_audio_stream->PrintResults(); | 833 latency_audio_stream->PrintResults(); |
| 785 } | 834 } |
| 786 | 835 |
| 787 } // namespace webrtc | 836 } // namespace webrtc |
| OLD | NEW |