OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 <string.h> | 11 #include <string.h> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "webrtc/base/md5digest.h" | 15 #include "webrtc/base/md5digest.h" |
16 #include "webrtc/base/scoped_ptr.h" | 16 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/base/thread_annotations.h" | 17 #include "webrtc/base/thread_annotations.h" |
18 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 18 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
19 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" | 19 #include "webrtc/modules/audio_coding/codecs/g711/include/audio_encoder_pcm.h" |
| 20 #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_i
sac.h" |
20 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" | 21 #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_encoder.h" |
21 #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test_oldapi.h" | 22 #include "webrtc/modules/audio_coding/main/acm2/acm_receive_test_oldapi.h" |
22 #include "webrtc/modules/audio_coding/main/acm2/acm_send_test_oldapi.h" | 23 #include "webrtc/modules/audio_coding/main/acm2/acm_send_test_oldapi.h" |
23 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" | 24 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
24 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedef
s.h" | 25 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module_typedef
s.h" |
25 #include "webrtc/modules/audio_coding/neteq/tools/audio_checksum.h" | 26 #include "webrtc/modules/audio_coding/neteq/tools/audio_checksum.h" |
26 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" | 27 #include "webrtc/modules/audio_coding/neteq/tools/audio_loop.h" |
27 #include "webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.h" | 28 #include "webrtc/modules/audio_coding/neteq/tools/constant_pcm_packet_source.h" |
28 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" | 29 #include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h" |
29 #include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h" | 30 #include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 | 693 |
693 int last_packet_number_; | 694 int last_packet_number_; |
694 std::vector<uint8_t> last_payload_vec_; | 695 std::vector<uint8_t> last_payload_vec_; |
695 test::AudioLoop audio_loop_; | 696 test::AudioLoop audio_loop_; |
696 }; | 697 }; |
697 | 698 |
698 TEST_F(AcmIsacMtTestOldApi, DISABLED_ON_IOS(DoTest)) { | 699 TEST_F(AcmIsacMtTestOldApi, DISABLED_ON_IOS(DoTest)) { |
699 EXPECT_EQ(kEventSignaled, RunTest()); | 700 EXPECT_EQ(kEventSignaled, RunTest()); |
700 } | 701 } |
701 | 702 |
| 703 class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { |
| 704 protected: |
| 705 static const int kRegisterAfterNumPackets = 5; |
| 706 static const int kNumPackets = 10; |
| 707 static const int kPacketSizeMs = 30; |
| 708 static const int kPacketSizeSamples = kPacketSizeMs * 16; |
| 709 |
| 710 AcmReRegisterIsacMtTestOldApi() |
| 711 : AudioCodingModuleTestOldApi(), |
| 712 receive_thread_( |
| 713 ThreadWrapper::CreateThread(CbReceiveThread, this, "receive")), |
| 714 codec_registration_thread_( |
| 715 ThreadWrapper::CreateThread(CbCodecRegistrationThread, |
| 716 this, |
| 717 "codec_registration")), |
| 718 test_complete_(EventWrapper::Create()), |
| 719 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 720 codec_registered_(false), |
| 721 receive_packet_count_(0), |
| 722 next_insert_packet_time_ms_(0), |
| 723 fake_clock_(new SimulatedClock(0)) { |
| 724 AudioEncoderDecoderIsac::Config config; |
| 725 config.payload_type = kPayloadType; |
| 726 isac_encoder_.reset(new AudioEncoderDecoderIsac(config)); |
| 727 clock_ = fake_clock_.get(); |
| 728 } |
| 729 |
| 730 void SetUp() { |
| 731 AudioCodingModuleTestOldApi::SetUp(); |
| 732 // Set up input audio source to read from specified file, loop after 5 |
| 733 // seconds, and deliver blocks of 10 ms. |
| 734 const std::string input_file_name = |
| 735 webrtc::test::ResourcePath("audio_coding/speech_mono_16kHz", "pcm"); |
| 736 audio_loop_.Init(input_file_name, 5 * kSampleRateHz, kNumSamples10ms); |
| 737 RegisterCodec(); // Must be called before the threads start below. |
| 738 StartThreads(); |
| 739 } |
| 740 |
| 741 void RegisterCodec() override { |
| 742 static_assert(kSampleRateHz == 16000, "test designed for iSAC 16 kHz"); |
| 743 AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); |
| 744 codec_.pltype = kPayloadType; |
| 745 |
| 746 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec |
| 747 // registered in AudioCodingModuleTestOldApi::SetUp(); |
| 748 // Only register the decoder for now. The encoder is registered later. |
| 749 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); |
| 750 } |
| 751 |
| 752 void StartThreads() { |
| 753 ASSERT_TRUE(receive_thread_->Start()); |
| 754 receive_thread_->SetPriority(kRealtimePriority); |
| 755 ASSERT_TRUE(codec_registration_thread_->Start()); |
| 756 codec_registration_thread_->SetPriority(kRealtimePriority); |
| 757 } |
| 758 |
| 759 void TearDown() { |
| 760 AudioCodingModuleTestOldApi::TearDown(); |
| 761 receive_thread_->Stop(); |
| 762 codec_registration_thread_->Stop(); |
| 763 } |
| 764 |
| 765 EventTypeWrapper RunTest() { |
| 766 return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. |
| 767 } |
| 768 |
| 769 static bool CbReceiveThread(void* context) { |
| 770 return reinterpret_cast<AcmReRegisterIsacMtTestOldApi*>(context) |
| 771 ->CbReceiveImpl(); |
| 772 } |
| 773 |
| 774 bool CbReceiveImpl() { |
| 775 SleepMs(1); |
| 776 const size_t max_encoded_bytes = isac_encoder_->MaxEncodedBytes(); |
| 777 rtc::scoped_ptr<uint8_t[]> encoded(new uint8_t[max_encoded_bytes]); |
| 778 AudioEncoder::EncodedInfo info; |
| 779 { |
| 780 CriticalSectionScoped lock(crit_sect_.get()); |
| 781 if (clock_->TimeInMilliseconds() < next_insert_packet_time_ms_) { |
| 782 return true; |
| 783 } |
| 784 next_insert_packet_time_ms_ += kPacketSizeMs; |
| 785 ++receive_packet_count_; |
| 786 |
| 787 // Encode new frame. |
| 788 uint32_t input_timestamp = rtp_header_.header.timestamp; |
| 789 while (info.encoded_bytes == 0) { |
| 790 info = isac_encoder_->Encode( |
| 791 input_timestamp, audio_loop_.GetNextBlock(), kNumSamples10ms, |
| 792 max_encoded_bytes, encoded.get()); |
| 793 input_timestamp += 160; // 10 ms at 16 kHz. |
| 794 } |
| 795 EXPECT_EQ(rtp_header_.header.timestamp + kPacketSizeSamples, |
| 796 input_timestamp); |
| 797 EXPECT_EQ(rtp_header_.header.timestamp, info.encoded_timestamp); |
| 798 EXPECT_EQ(rtp_header_.header.payloadType, info.payload_type); |
| 799 } |
| 800 // Now we're not holding the crit sect when calling ACM. |
| 801 |
| 802 // Insert into ACM. |
| 803 EXPECT_EQ(0, acm_->IncomingPacket(encoded.get(), info.encoded_bytes, |
| 804 rtp_header_)); |
| 805 |
| 806 // Pull audio. |
| 807 for (int i = 0; i < rtc::CheckedDivExact(kPacketSizeMs, 10); ++i) { |
| 808 AudioFrame audio_frame; |
| 809 EXPECT_EQ(0, acm_->PlayoutData10Ms(-1 /* default output frequency */, |
| 810 &audio_frame)); |
| 811 fake_clock_->AdvanceTimeMilliseconds(10); |
| 812 } |
| 813 rtp_utility_->Forward(&rtp_header_); |
| 814 return true; |
| 815 } |
| 816 |
| 817 static bool CbCodecRegistrationThread(void* context) { |
| 818 return reinterpret_cast<AcmReRegisterIsacMtTestOldApi*>(context) |
| 819 ->CbCodecRegistrationImpl(); |
| 820 } |
| 821 |
| 822 bool CbCodecRegistrationImpl() { |
| 823 SleepMs(1); |
| 824 if (HasFatalFailure()) { |
| 825 // End the test early if a fatal failure (ASSERT_*) has occurred. |
| 826 test_complete_->Set(); |
| 827 } |
| 828 CriticalSectionScoped lock(crit_sect_.get()); |
| 829 if (!codec_registered_ && |
| 830 receive_packet_count_ > kRegisterAfterNumPackets) { |
| 831 // Register the iSAC encoder. |
| 832 EXPECT_EQ(0, acm_->RegisterSendCodec(codec_)); |
| 833 codec_registered_ = true; |
| 834 } |
| 835 if (codec_registered_ && receive_packet_count_ > kNumPackets) { |
| 836 test_complete_->Set(); |
| 837 } |
| 838 return true; |
| 839 } |
| 840 |
| 841 rtc::scoped_ptr<ThreadWrapper> receive_thread_; |
| 842 rtc::scoped_ptr<ThreadWrapper> codec_registration_thread_; |
| 843 const rtc::scoped_ptr<EventWrapper> test_complete_; |
| 844 const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; |
| 845 bool codec_registered_ GUARDED_BY(crit_sect_); |
| 846 int receive_packet_count_ GUARDED_BY(crit_sect_); |
| 847 int64_t next_insert_packet_time_ms_ GUARDED_BY(crit_sect_); |
| 848 rtc::scoped_ptr<AudioEncoderDecoderIsac> isac_encoder_; |
| 849 rtc::scoped_ptr<SimulatedClock> fake_clock_; |
| 850 test::AudioLoop audio_loop_; |
| 851 }; |
| 852 |
| 853 TEST_F(AcmReRegisterIsacMtTestOldApi, DISABLED_ON_IOS(DoTest)) { |
| 854 EXPECT_EQ(kEventSignaled, RunTest()); |
| 855 } |
| 856 |
702 // Disabling all of these tests on iOS until file support has been added. | 857 // Disabling all of these tests on iOS until file support has been added. |
703 // See https://code.google.com/p/webrtc/issues/detail?id=4752 for details. | 858 // See https://code.google.com/p/webrtc/issues/detail?id=4752 for details. |
704 #if !defined(WEBRTC_IOS) | 859 #if !defined(WEBRTC_IOS) |
705 | 860 |
706 class AcmReceiverBitExactnessOldApi : public ::testing::Test { | 861 class AcmReceiverBitExactnessOldApi : public ::testing::Test { |
707 public: | 862 public: |
708 static std::string PlatformChecksum(std::string win64, | 863 static std::string PlatformChecksum(std::string win64, |
709 std::string android, | 864 std::string android, |
710 std::string others) { | 865 std::string others) { |
711 #if defined(_WIN32) && defined(WEBRTC_ARCH_64_BITS) | 866 #if defined(_WIN32) && defined(WEBRTC_ARCH_64_BITS) |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 Run(16000, 8000, 1000); | 1680 Run(16000, 8000, 1000); |
1526 } | 1681 } |
1527 | 1682 |
1528 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { | 1683 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { |
1529 Run(8000, 16000, 1000); | 1684 Run(8000, 16000, 1000); |
1530 } | 1685 } |
1531 | 1686 |
1532 #endif | 1687 #endif |
1533 | 1688 |
1534 } // namespace webrtc | 1689 } // namespace webrtc |
OLD | NEW |