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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <limits> | 12 #include <limits> |
13 #include <list> | 13 #include <list> |
14 #include <memory> | 14 #include <memory> |
15 #include <numeric> | 15 #include <numeric> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/base/arraysize.h" | 19 #include "webrtc/base/arraysize.h" |
20 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
21 #include "webrtc/base/format_macros.h" | 21 #include "webrtc/base/format_macros.h" |
22 #include "webrtc/base/logging.h" | 22 #include "webrtc/base/logging.h" |
23 #include "webrtc/base/scoped_ref_ptr.h" | 23 #include "webrtc/base/scoped_ref_ptr.h" |
24 #include "webrtc/modules/audio_device/audio_device_impl.h" | 24 #include "webrtc/modules/audio_device/audio_device_impl.h" |
25 #include "webrtc/modules/audio_device/include/audio_device.h" | 25 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 26 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" |
26 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" | 27 #include "webrtc/modules/audio_device/ios/audio_device_ios.h" |
27 #include "webrtc/system_wrappers/include/clock.h" | 28 #include "webrtc/system_wrappers/include/clock.h" |
28 #include "webrtc/system_wrappers/include/event_wrapper.h" | 29 #include "webrtc/system_wrappers/include/event_wrapper.h" |
29 #include "webrtc/system_wrappers/include/sleep.h" | 30 #include "webrtc/system_wrappers/include/sleep.h" |
30 #include "webrtc/test/gmock.h" | 31 #include "webrtc/test/gmock.h" |
31 #include "webrtc/test/gtest.h" | 32 #include "webrtc/test/gtest.h" |
32 #include "webrtc/test/testsupport/fileutils.h" | 33 #include "webrtc/test/testsupport/fileutils.h" |
33 | 34 |
34 using std::cout; | 35 using std::cout; |
35 using std::endl; | 36 using std::endl; |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 const size_t frames_per_buffer_; | 352 const size_t frames_per_buffer_; |
352 const size_t bytes_per_buffer_; | 353 const size_t bytes_per_buffer_; |
353 size_t play_count_; | 354 size_t play_count_; |
354 size_t rec_count_; | 355 size_t rec_count_; |
355 int64_t pulse_time_; | 356 int64_t pulse_time_; |
356 std::vector<int> latencies_; | 357 std::vector<int> latencies_; |
357 }; | 358 }; |
358 // Mocks the AudioTransport object and proxies actions for the two callbacks | 359 // Mocks the AudioTransport object and proxies actions for the two callbacks |
359 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations | 360 // (RecordedDataIsAvailable and NeedMorePlayData) to different implementations |
360 // of AudioStreamInterface. | 361 // of AudioStreamInterface. |
361 class MockAudioTransport : public AudioTransport { | 362 class MockAudioTransportIOS : public test::MockAudioTransport { |
362 public: | 363 public: |
363 explicit MockAudioTransport(int type) | 364 explicit MockAudioTransportIOS(int type) |
364 : num_callbacks_(0), | 365 : num_callbacks_(0), |
365 type_(type), | 366 type_(type), |
366 play_count_(0), | 367 play_count_(0), |
367 rec_count_(0), | 368 rec_count_(0), |
368 audio_stream_(nullptr) {} | 369 audio_stream_(nullptr) {} |
369 | 370 |
370 virtual ~MockAudioTransport() {} | 371 virtual ~MockAudioTransportIOS() {} |
371 | |
372 MOCK_METHOD10(RecordedDataIsAvailable, | |
373 int32_t(const void* audioSamples, | |
374 const size_t nSamples, | |
375 const size_t nBytesPerSample, | |
376 const size_t nChannels, | |
377 const uint32_t samplesPerSec, | |
378 const uint32_t totalDelayMS, | |
379 const int32_t clockDrift, | |
380 const uint32_t currentMicLevel, | |
381 const bool keyPressed, | |
382 uint32_t& newMicLevel)); | |
383 | |
384 MOCK_METHOD8(NeedMorePlayData, | |
385 int32_t(const size_t nSamples, | |
386 const size_t nBytesPerSample, | |
387 const size_t nChannels, | |
388 const uint32_t samplesPerSec, | |
389 void* audioSamples, | |
390 size_t& nSamplesOut, | |
391 int64_t* elapsed_time_ms, | |
392 int64_t* ntp_time_ms)); | |
393 | |
394 MOCK_METHOD6(PushCaptureData, | |
395 void(int voe_channel, | |
396 const void* audio_data, | |
397 int bits_per_sample, | |
398 int sample_rate, | |
399 size_t number_of_channels, | |
400 size_t number_of_frames)); | |
401 | |
402 MOCK_METHOD7(PullRenderData, | |
403 void(int bits_per_sample, | |
404 int sample_rate, | |
405 size_t number_of_channels, | |
406 size_t number_of_frames, | |
407 void* audio_data, | |
408 int64_t* elapsed_time_ms, | |
409 int64_t* ntp_time_ms)); | |
410 | 372 |
411 // Set default actions of the mock object. We are delegating to fake | 373 // Set default actions of the mock object. We are delegating to fake |
412 // implementations (of AudioStreamInterface) here. | 374 // implementations (of AudioStreamInterface) here. |
413 void HandleCallbacks(EventWrapper* test_is_done, | 375 void HandleCallbacks(EventWrapper* test_is_done, |
414 AudioStreamInterface* audio_stream, | 376 AudioStreamInterface* audio_stream, |
415 size_t num_callbacks) { | 377 size_t num_callbacks) { |
416 test_is_done_ = test_is_done; | 378 test_is_done_ = test_is_done; |
417 audio_stream_ = audio_stream; | 379 audio_stream_ = audio_stream; |
418 num_callbacks_ = num_callbacks; | 380 num_callbacks_ = num_callbacks; |
419 if (play_mode()) { | 381 if (play_mode()) { |
420 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) | 382 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) |
421 .WillByDefault( | 383 .WillByDefault( |
422 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); | 384 Invoke(this, &MockAudioTransportIOS::RealNeedMorePlayData)); |
423 } | 385 } |
424 if (rec_mode()) { | 386 if (rec_mode()) { |
425 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) | 387 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) |
426 .WillByDefault( | 388 .WillByDefault(Invoke( |
427 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); | 389 this, &MockAudioTransportIOS::RealRecordedDataIsAvailable)); |
428 } | 390 } |
429 } | 391 } |
430 | 392 |
431 int32_t RealRecordedDataIsAvailable(const void* audioSamples, | 393 int32_t RealRecordedDataIsAvailable(const void* audioSamples, |
432 const size_t nSamples, | 394 const size_t nSamples, |
433 const size_t nBytesPerSample, | 395 const size_t nBytesPerSample, |
434 const size_t nChannels, | 396 const size_t nChannels, |
435 const uint32_t samplesPerSec, | 397 const uint32_t samplesPerSec, |
436 const uint32_t totalDelayMS, | 398 const uint32_t totalDelayMS, |
437 const int32_t clockDrift, | 399 const int32_t clockDrift, |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 // Create and initialize a second/extra ADM instance. The default ADM is | 626 // Create and initialize a second/extra ADM instance. The default ADM is |
665 // created by the test harness. | 627 // created by the test harness. |
666 rtc::scoped_refptr<AudioDeviceModule> second_audio_device = | 628 rtc::scoped_refptr<AudioDeviceModule> second_audio_device = |
667 CreateAudioDevice(AudioDeviceModule::kPlatformDefaultAudio); | 629 CreateAudioDevice(AudioDeviceModule::kPlatformDefaultAudio); |
668 EXPECT_NE(second_audio_device.get(), nullptr); | 630 EXPECT_NE(second_audio_device.get(), nullptr); |
669 EXPECT_EQ(0, second_audio_device->Init()); | 631 EXPECT_EQ(0, second_audio_device->Init()); |
670 | 632 |
671 // Start playout for the default ADM but don't wait here. Instead use the | 633 // Start playout for the default ADM but don't wait here. Instead use the |
672 // upcoming second stream for that. We set the same expectation on number | 634 // upcoming second stream for that. We set the same expectation on number |
673 // of callbacks as for the second stream. | 635 // of callbacks as for the second stream. |
674 NiceMock<MockAudioTransport> mock(kPlayout); | 636 NiceMock<MockAudioTransportIOS> mock(kPlayout); |
675 mock.HandleCallbacks(nullptr, nullptr, 0); | 637 mock.HandleCallbacks(nullptr, nullptr, 0); |
676 EXPECT_CALL( | 638 EXPECT_CALL( |
677 mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, | 639 mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, |
678 playout_channels(), playout_sample_rate(), | 640 playout_channels(), playout_sample_rate(), |
679 NotNull(), _, _, _)) | 641 NotNull(), _, _, _)) |
680 .Times(AtLeast(kNumCallbacks)); | 642 .Times(AtLeast(kNumCallbacks)); |
681 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 643 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
682 StartPlayout(); | 644 StartPlayout(); |
683 | 645 |
684 // Initialize playout for the second ADM. If all is OK, the second ADM shall | 646 // Initialize playout for the second ADM. If all is OK, the second ADM shall |
685 // reuse the audio session activated when the first ADM started playing. | 647 // reuse the audio session activated when the first ADM started playing. |
686 // This call will also ensure that we avoid a problem related to initializing | 648 // This call will also ensure that we avoid a problem related to initializing |
687 // two different audio unit instances back to back (see webrtc:5166 for | 649 // two different audio unit instances back to back (see webrtc:5166 for |
688 // details). | 650 // details). |
689 EXPECT_EQ(0, second_audio_device->InitPlayout()); | 651 EXPECT_EQ(0, second_audio_device->InitPlayout()); |
690 EXPECT_TRUE(second_audio_device->PlayoutIsInitialized()); | 652 EXPECT_TRUE(second_audio_device->PlayoutIsInitialized()); |
691 | 653 |
692 // Start playout for the second ADM and verify that it starts as intended. | 654 // Start playout for the second ADM and verify that it starts as intended. |
693 // Passing this test ensures that initialization of the second audio unit | 655 // Passing this test ensures that initialization of the second audio unit |
694 // has been done successfully and that there is no conflict with the already | 656 // has been done successfully and that there is no conflict with the already |
695 // playing first ADM. | 657 // playing first ADM. |
696 MockAudioTransport mock2(kPlayout); | 658 MockAudioTransportIOS mock2(kPlayout); |
697 mock2.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 659 mock2.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
698 EXPECT_CALL( | 660 EXPECT_CALL( |
699 mock2, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, | 661 mock2, NeedMorePlayData(playout_frames_per_10ms_buffer(), kBytesPerSample, |
700 playout_channels(), playout_sample_rate(), | 662 playout_channels(), playout_sample_rate(), |
701 NotNull(), _, _, _)) | 663 NotNull(), _, _, _)) |
702 .Times(AtLeast(kNumCallbacks)); | 664 .Times(AtLeast(kNumCallbacks)); |
703 EXPECT_EQ(0, second_audio_device->RegisterAudioCallback(&mock2)); | 665 EXPECT_EQ(0, second_audio_device->RegisterAudioCallback(&mock2)); |
704 EXPECT_EQ(0, second_audio_device->StartPlayout()); | 666 EXPECT_EQ(0, second_audio_device->StartPlayout()); |
705 EXPECT_TRUE(second_audio_device->Playing()); | 667 EXPECT_TRUE(second_audio_device->Playing()); |
706 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 668 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
707 EXPECT_EQ(0, second_audio_device->StopPlayout()); | 669 EXPECT_EQ(0, second_audio_device->StopPlayout()); |
708 EXPECT_FALSE(second_audio_device->Playing()); | 670 EXPECT_FALSE(second_audio_device->Playing()); |
709 EXPECT_FALSE(second_audio_device->PlayoutIsInitialized()); | 671 EXPECT_FALSE(second_audio_device->PlayoutIsInitialized()); |
710 | 672 |
711 EXPECT_EQ(0, second_audio_device->Terminate()); | 673 EXPECT_EQ(0, second_audio_device->Terminate()); |
712 } | 674 } |
713 | 675 |
714 // Start playout and verify that the native audio layer starts asking for real | 676 // Start playout and verify that the native audio layer starts asking for real |
715 // audio samples to play out using the NeedMorePlayData callback. | 677 // audio samples to play out using the NeedMorePlayData callback. |
716 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { | 678 TEST_F(AudioDeviceTest, StartPlayoutVerifyCallbacks) { |
717 MockAudioTransport mock(kPlayout); | 679 MockAudioTransportIOS mock(kPlayout); |
718 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 680 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
719 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), | 681 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), |
720 kBytesPerSample, playout_channels(), | 682 kBytesPerSample, playout_channels(), |
721 playout_sample_rate(), NotNull(), _, _, _)) | 683 playout_sample_rate(), NotNull(), _, _, _)) |
722 .Times(AtLeast(kNumCallbacks)); | 684 .Times(AtLeast(kNumCallbacks)); |
723 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 685 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
724 StartPlayout(); | 686 StartPlayout(); |
725 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 687 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
726 StopPlayout(); | 688 StopPlayout(); |
727 } | 689 } |
728 | 690 |
729 // Start recording and verify that the native audio layer starts feeding real | 691 // Start recording and verify that the native audio layer starts feeding real |
730 // audio samples via the RecordedDataIsAvailable callback. | 692 // audio samples via the RecordedDataIsAvailable callback. |
731 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { | 693 TEST_F(AudioDeviceTest, StartRecordingVerifyCallbacks) { |
732 MockAudioTransport mock(kRecording); | 694 MockAudioTransportIOS mock(kRecording); |
733 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 695 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
734 EXPECT_CALL(mock, | 696 EXPECT_CALL(mock, |
735 RecordedDataIsAvailable( | 697 RecordedDataIsAvailable( |
736 NotNull(), record_frames_per_10ms_buffer(), kBytesPerSample, | 698 NotNull(), record_frames_per_10ms_buffer(), kBytesPerSample, |
737 record_channels(), record_sample_rate(), | 699 record_channels(), record_sample_rate(), |
738 _, // TODO(henrika): fix delay | 700 _, // TODO(henrika): fix delay |
739 0, 0, false, _)).Times(AtLeast(kNumCallbacks)); | 701 0, 0, false, _)).Times(AtLeast(kNumCallbacks)); |
740 | 702 |
741 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 703 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
742 StartRecording(); | 704 StartRecording(); |
743 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 705 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
744 StopRecording(); | 706 StopRecording(); |
745 } | 707 } |
746 | 708 |
747 // Start playout and recording (full-duplex audio) and verify that audio is | 709 // Start playout and recording (full-duplex audio) and verify that audio is |
748 // active in both directions. | 710 // active in both directions. |
749 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { | 711 TEST_F(AudioDeviceTest, StartPlayoutAndRecordingVerifyCallbacks) { |
750 MockAudioTransport mock(kPlayout | kRecording); | 712 MockAudioTransportIOS mock(kPlayout | kRecording); |
751 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); | 713 mock.HandleCallbacks(test_is_done_.get(), nullptr, kNumCallbacks); |
752 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), | 714 EXPECT_CALL(mock, NeedMorePlayData(playout_frames_per_10ms_buffer(), |
753 kBytesPerSample, playout_channels(), | 715 kBytesPerSample, playout_channels(), |
754 playout_sample_rate(), NotNull(), _, _, _)) | 716 playout_sample_rate(), NotNull(), _, _, _)) |
755 .Times(AtLeast(kNumCallbacks)); | 717 .Times(AtLeast(kNumCallbacks)); |
756 EXPECT_CALL(mock, | 718 EXPECT_CALL(mock, |
757 RecordedDataIsAvailable( | 719 RecordedDataIsAvailable( |
758 NotNull(), record_frames_per_10ms_buffer(), kBytesPerSample, | 720 NotNull(), record_frames_per_10ms_buffer(), kBytesPerSample, |
759 record_channels(), record_sample_rate(), | 721 record_channels(), record_sample_rate(), |
760 _, // TODO(henrika): fix delay | 722 _, // TODO(henrika): fix delay |
761 0, 0, false, _)).Times(AtLeast(kNumCallbacks)); | 723 0, 0, false, _)).Times(AtLeast(kNumCallbacks)); |
762 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 724 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
763 StartPlayout(); | 725 StartPlayout(); |
764 StartRecording(); | 726 StartRecording(); |
765 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 727 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
766 StopRecording(); | 728 StopRecording(); |
767 StopPlayout(); | 729 StopPlayout(); |
768 } | 730 } |
769 | 731 |
770 // Start playout and read audio from an external PCM file when the audio layer | 732 // Start playout and read audio from an external PCM file when the audio layer |
771 // asks for data to play out. Real audio is played out in this test but it does | 733 // asks for data to play out. Real audio is played out in this test but it does |
772 // not contain any explicit verification that the audio quality is perfect. | 734 // not contain any explicit verification that the audio quality is perfect. |
773 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) { | 735 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) { |
774 // TODO(henrika): extend test when mono output is supported. | 736 // TODO(henrika): extend test when mono output is supported. |
775 EXPECT_EQ(1, playout_channels()); | 737 EXPECT_EQ(1, playout_channels()); |
776 NiceMock<MockAudioTransport> mock(kPlayout); | 738 NiceMock<MockAudioTransportIOS> mock(kPlayout); |
777 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond; | 739 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond; |
778 std::string file_name = GetFileName(playout_sample_rate()); | 740 std::string file_name = GetFileName(playout_sample_rate()); |
779 std::unique_ptr<FileAudioStream> file_audio_stream( | 741 std::unique_ptr<FileAudioStream> file_audio_stream( |
780 new FileAudioStream(num_callbacks, file_name, playout_sample_rate())); | 742 new FileAudioStream(num_callbacks, file_name, playout_sample_rate())); |
781 mock.HandleCallbacks(test_is_done_.get(), file_audio_stream.get(), | 743 mock.HandleCallbacks(test_is_done_.get(), file_audio_stream.get(), |
782 num_callbacks); | 744 num_callbacks); |
783 // SetMaxPlayoutVolume(); | 745 // SetMaxPlayoutVolume(); |
784 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 746 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
785 StartPlayout(); | 747 StartPlayout(); |
786 test_is_done_->Wait(kTestTimeOutInMilliseconds); | 748 test_is_done_->Wait(kTestTimeOutInMilliseconds); |
(...skipping 15 matching lines...) Expand all Loading... |
802 // of the FIFO will vary more due to an unbalance between the two sides. | 764 // of the FIFO will vary more due to an unbalance between the two sides. |
803 // This test tries to verify that the device maintains a balanced callback- | 765 // This test tries to verify that the device maintains a balanced callback- |
804 // sequence by running in loopback for ten seconds while measuring the size | 766 // sequence by running in loopback for ten seconds while measuring the size |
805 // (max and average) of the FIFO. The size of the FIFO is increased by the | 767 // (max and average) of the FIFO. The size of the FIFO is increased by the |
806 // recording side and decreased by the playout side. | 768 // recording side and decreased by the playout side. |
807 // TODO(henrika): tune the final test parameters after running tests on several | 769 // TODO(henrika): tune the final test parameters after running tests on several |
808 // different devices. | 770 // different devices. |
809 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { | 771 TEST_F(AudioDeviceTest, RunPlayoutAndRecordingInFullDuplex) { |
810 EXPECT_EQ(record_channels(), playout_channels()); | 772 EXPECT_EQ(record_channels(), playout_channels()); |
811 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); | 773 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); |
812 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); | 774 NiceMock<MockAudioTransportIOS> mock(kPlayout | kRecording); |
813 std::unique_ptr<FifoAudioStream> fifo_audio_stream( | 775 std::unique_ptr<FifoAudioStream> fifo_audio_stream( |
814 new FifoAudioStream(playout_frames_per_10ms_buffer())); | 776 new FifoAudioStream(playout_frames_per_10ms_buffer())); |
815 mock.HandleCallbacks(test_is_done_.get(), fifo_audio_stream.get(), | 777 mock.HandleCallbacks(test_is_done_.get(), fifo_audio_stream.get(), |
816 kFullDuplexTimeInSec * kNumCallbacksPerSecond); | 778 kFullDuplexTimeInSec * kNumCallbacksPerSecond); |
817 // SetMaxPlayoutVolume(); | 779 // SetMaxPlayoutVolume(); |
818 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 780 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
819 StartRecording(); | 781 StartRecording(); |
820 StartPlayout(); | 782 StartPlayout(); |
821 test_is_done_->Wait( | 783 test_is_done_->Wait( |
822 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); | 784 std::max(kTestTimeOutInMilliseconds, 1000 * kFullDuplexTimeInSec)); |
823 StopPlayout(); | 785 StopPlayout(); |
824 StopRecording(); | 786 StopRecording(); |
825 EXPECT_LE(fifo_audio_stream->average_size(), 10u); | 787 EXPECT_LE(fifo_audio_stream->average_size(), 10u); |
826 EXPECT_LE(fifo_audio_stream->largest_size(), 20u); | 788 EXPECT_LE(fifo_audio_stream->largest_size(), 20u); |
827 } | 789 } |
828 | 790 |
829 // Measures loopback latency and reports the min, max and average values for | 791 // Measures loopback latency and reports the min, max and average values for |
830 // a full duplex audio session. | 792 // a full duplex audio session. |
831 // The latency is measured like so: | 793 // The latency is measured like so: |
832 // - Insert impulses periodically on the output side. | 794 // - Insert impulses periodically on the output side. |
833 // - Detect the impulses on the input side. | 795 // - Detect the impulses on the input side. |
834 // - Measure the time difference between the transmit time and receive time. | 796 // - Measure the time difference between the transmit time and receive time. |
835 // - Store time differences in a vector and calculate min, max and average. | 797 // - Store time differences in a vector and calculate min, max and average. |
836 // This test requires a special hardware called Audio Loopback Dongle. | 798 // This test requires a special hardware called Audio Loopback Dongle. |
837 // See http://source.android.com/devices/audio/loopback.html for details. | 799 // See http://source.android.com/devices/audio/loopback.html for details. |
838 TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) { | 800 TEST_F(AudioDeviceTest, DISABLED_MeasureLoopbackLatency) { |
839 EXPECT_EQ(record_channels(), playout_channels()); | 801 EXPECT_EQ(record_channels(), playout_channels()); |
840 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); | 802 EXPECT_EQ(record_sample_rate(), playout_sample_rate()); |
841 NiceMock<MockAudioTransport> mock(kPlayout | kRecording); | 803 NiceMock<MockAudioTransportIOS> mock(kPlayout | kRecording); |
842 std::unique_ptr<LatencyMeasuringAudioStream> latency_audio_stream( | 804 std::unique_ptr<LatencyMeasuringAudioStream> latency_audio_stream( |
843 new LatencyMeasuringAudioStream(playout_frames_per_10ms_buffer())); | 805 new LatencyMeasuringAudioStream(playout_frames_per_10ms_buffer())); |
844 mock.HandleCallbacks(test_is_done_.get(), latency_audio_stream.get(), | 806 mock.HandleCallbacks(test_is_done_.get(), latency_audio_stream.get(), |
845 kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); | 807 kMeasureLatencyTimeInSec * kNumCallbacksPerSecond); |
846 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); | 808 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); |
847 // SetMaxPlayoutVolume(); | 809 // SetMaxPlayoutVolume(); |
848 // DisableBuiltInAECIfAvailable(); | 810 // DisableBuiltInAECIfAvailable(); |
849 StartRecording(); | 811 StartRecording(); |
850 StartPlayout(); | 812 StartPlayout(); |
851 test_is_done_->Wait( | 813 test_is_done_->Wait( |
852 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); | 814 std::max(kTestTimeOutInMilliseconds, 1000 * kMeasureLatencyTimeInSec)); |
853 StopPlayout(); | 815 StopPlayout(); |
854 StopRecording(); | 816 StopRecording(); |
855 // Verify that the correct number of transmitted impulses are detected. | 817 // Verify that the correct number of transmitted impulses are detected. |
856 EXPECT_EQ(latency_audio_stream->num_latency_values(), | 818 EXPECT_EQ(latency_audio_stream->num_latency_values(), |
857 static_cast<size_t>( | 819 static_cast<size_t>( |
858 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); | 820 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); |
859 latency_audio_stream->PrintResults(); | 821 latency_audio_stream->PrintResults(); |
860 } | 822 } |
861 | 823 |
862 } // namespace webrtc | 824 } // namespace webrtc |
OLD | NEW |