| 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 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 450 |
| 451 // A multi-threaded test for ACM. This base class is using the PCM16b 16 kHz | 451 // A multi-threaded test for ACM. This base class is using the PCM16b 16 kHz |
| 452 // codec, while the derive class AcmIsacMtTest is using iSAC. | 452 // codec, while the derive class AcmIsacMtTest is using iSAC. |
| 453 class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi { | 453 class AudioCodingModuleMtTestOldApi : public AudioCodingModuleTestOldApi { |
| 454 protected: | 454 protected: |
| 455 static const int kNumPackets = 500; | 455 static const int kNumPackets = 500; |
| 456 static const int kNumPullCalls = 500; | 456 static const int kNumPullCalls = 500; |
| 457 | 457 |
| 458 AudioCodingModuleMtTestOldApi() | 458 AudioCodingModuleMtTestOldApi() |
| 459 : AudioCodingModuleTestOldApi(), | 459 : AudioCodingModuleTestOldApi(), |
| 460 send_thread_(PlatformThread::CreateThread(CbSendThread, this, "send")), | 460 send_thread_(CbSendThread, this, "send"), |
| 461 insert_packet_thread_(PlatformThread::CreateThread(CbInsertPacketThread, | 461 insert_packet_thread_(CbInsertPacketThread, this, "insert_packet"), |
| 462 this, | 462 pull_audio_thread_(CbPullAudioThread, this, "pull_audio"), |
| 463 "insert_packet")), | |
| 464 pull_audio_thread_(PlatformThread::CreateThread(CbPullAudioThread, | |
| 465 this, | |
| 466 "pull_audio")), | |
| 467 test_complete_(EventWrapper::Create()), | 463 test_complete_(EventWrapper::Create()), |
| 468 send_count_(0), | 464 send_count_(0), |
| 469 insert_packet_count_(0), | 465 insert_packet_count_(0), |
| 470 pull_audio_count_(0), | 466 pull_audio_count_(0), |
| 471 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 467 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 472 next_insert_packet_time_ms_(0), | 468 next_insert_packet_time_ms_(0), |
| 473 fake_clock_(new SimulatedClock(0)) { | 469 fake_clock_(new SimulatedClock(0)) { |
| 474 clock_ = fake_clock_.get(); | 470 clock_ = fake_clock_.get(); |
| 475 } | 471 } |
| 476 | 472 |
| 477 void SetUp() { | 473 void SetUp() { |
| 478 AudioCodingModuleTestOldApi::SetUp(); | 474 AudioCodingModuleTestOldApi::SetUp(); |
| 479 RegisterCodec(); // Must be called before the threads start below. | 475 RegisterCodec(); // Must be called before the threads start below. |
| 480 StartThreads(); | 476 StartThreads(); |
| 481 } | 477 } |
| 482 | 478 |
| 483 void StartThreads() { | 479 void StartThreads() { |
| 484 ASSERT_TRUE(send_thread_->Start()); | 480 send_thread_.Start(); |
| 485 send_thread_->SetPriority(kRealtimePriority); | 481 send_thread_.SetPriority(rtc::kRealtimePriority); |
| 486 ASSERT_TRUE(insert_packet_thread_->Start()); | 482 insert_packet_thread_.Start(); |
| 487 insert_packet_thread_->SetPriority(kRealtimePriority); | 483 insert_packet_thread_.SetPriority(rtc::kRealtimePriority); |
| 488 ASSERT_TRUE(pull_audio_thread_->Start()); | 484 pull_audio_thread_.Start(); |
| 489 pull_audio_thread_->SetPriority(kRealtimePriority); | 485 pull_audio_thread_.SetPriority(rtc::kRealtimePriority); |
| 490 } | 486 } |
| 491 | 487 |
| 492 void TearDown() { | 488 void TearDown() { |
| 493 AudioCodingModuleTestOldApi::TearDown(); | 489 AudioCodingModuleTestOldApi::TearDown(); |
| 494 pull_audio_thread_->Stop(); | 490 pull_audio_thread_.Stop(); |
| 495 send_thread_->Stop(); | 491 send_thread_.Stop(); |
| 496 insert_packet_thread_->Stop(); | 492 insert_packet_thread_.Stop(); |
| 497 } | 493 } |
| 498 | 494 |
| 499 EventTypeWrapper RunTest() { | 495 EventTypeWrapper RunTest() { |
| 500 return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. | 496 return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. |
| 501 } | 497 } |
| 502 | 498 |
| 503 virtual bool TestDone() { | 499 virtual bool TestDone() { |
| 504 if (packet_cb_.num_calls() > kNumPackets) { | 500 if (packet_cb_.num_calls() > kNumPackets) { |
| 505 CriticalSectionScoped lock(crit_sect_.get()); | 501 CriticalSectionScoped lock(crit_sect_.get()); |
| 506 if (pull_audio_count_ > kNumPullCalls) { | 502 if (pull_audio_count_ > kNumPullCalls) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return true; | 562 return true; |
| 567 } | 563 } |
| 568 ++pull_audio_count_; | 564 ++pull_audio_count_; |
| 569 } | 565 } |
| 570 // Now we're not holding the crit sect when calling ACM. | 566 // Now we're not holding the crit sect when calling ACM. |
| 571 PullAudio(); | 567 PullAudio(); |
| 572 fake_clock_->AdvanceTimeMilliseconds(10); | 568 fake_clock_->AdvanceTimeMilliseconds(10); |
| 573 return true; | 569 return true; |
| 574 } | 570 } |
| 575 | 571 |
| 576 rtc::scoped_ptr<PlatformThread> send_thread_; | 572 rtc::PlatformThread send_thread_; |
| 577 rtc::scoped_ptr<PlatformThread> insert_packet_thread_; | 573 rtc::PlatformThread insert_packet_thread_; |
| 578 rtc::scoped_ptr<PlatformThread> pull_audio_thread_; | 574 rtc::PlatformThread pull_audio_thread_; |
| 579 const rtc::scoped_ptr<EventWrapper> test_complete_; | 575 const rtc::scoped_ptr<EventWrapper> test_complete_; |
| 580 int send_count_; | 576 int send_count_; |
| 581 int insert_packet_count_; | 577 int insert_packet_count_; |
| 582 int pull_audio_count_ GUARDED_BY(crit_sect_); | 578 int pull_audio_count_ GUARDED_BY(crit_sect_); |
| 583 const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; | 579 const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; |
| 584 int64_t next_insert_packet_time_ms_ GUARDED_BY(crit_sect_); | 580 int64_t next_insert_packet_time_ms_ GUARDED_BY(crit_sect_); |
| 585 rtc::scoped_ptr<SimulatedClock> fake_clock_; | 581 rtc::scoped_ptr<SimulatedClock> fake_clock_; |
| 586 }; | 582 }; |
| 587 | 583 |
| 588 TEST_F(AudioCodingModuleMtTestOldApi, DISABLED_ON_IOS(DoTest)) { | 584 TEST_F(AudioCodingModuleMtTestOldApi, DISABLED_ON_IOS(DoTest)) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 691 |
| 696 class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { | 692 class AcmReRegisterIsacMtTestOldApi : public AudioCodingModuleTestOldApi { |
| 697 protected: | 693 protected: |
| 698 static const int kRegisterAfterNumPackets = 5; | 694 static const int kRegisterAfterNumPackets = 5; |
| 699 static const int kNumPackets = 10; | 695 static const int kNumPackets = 10; |
| 700 static const int kPacketSizeMs = 30; | 696 static const int kPacketSizeMs = 30; |
| 701 static const int kPacketSizeSamples = kPacketSizeMs * 16; | 697 static const int kPacketSizeSamples = kPacketSizeMs * 16; |
| 702 | 698 |
| 703 AcmReRegisterIsacMtTestOldApi() | 699 AcmReRegisterIsacMtTestOldApi() |
| 704 : AudioCodingModuleTestOldApi(), | 700 : AudioCodingModuleTestOldApi(), |
| 705 receive_thread_( | 701 receive_thread_(CbReceiveThread, this, "receive"), |
| 706 PlatformThread::CreateThread(CbReceiveThread, this, "receive")), | 702 codec_registration_thread_(CbCodecRegistrationThread, |
| 707 codec_registration_thread_( | 703 this, |
| 708 PlatformThread::CreateThread(CbCodecRegistrationThread, | 704 "codec_registration"), |
| 709 this, | |
| 710 "codec_registration")), | |
| 711 test_complete_(EventWrapper::Create()), | 705 test_complete_(EventWrapper::Create()), |
| 712 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), | 706 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()), |
| 713 codec_registered_(false), | 707 codec_registered_(false), |
| 714 receive_packet_count_(0), | 708 receive_packet_count_(0), |
| 715 next_insert_packet_time_ms_(0), | 709 next_insert_packet_time_ms_(0), |
| 716 fake_clock_(new SimulatedClock(0)) { | 710 fake_clock_(new SimulatedClock(0)) { |
| 717 AudioEncoderIsac::Config config; | 711 AudioEncoderIsac::Config config; |
| 718 config.payload_type = kPayloadType; | 712 config.payload_type = kPayloadType; |
| 719 isac_encoder_.reset(new AudioEncoderIsac(config)); | 713 isac_encoder_.reset(new AudioEncoderIsac(config)); |
| 720 clock_ = fake_clock_.get(); | 714 clock_ = fake_clock_.get(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 736 AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); | 730 AudioCodingModule::Codec("ISAC", &codec_, kSampleRateHz, 1); |
| 737 codec_.pltype = kPayloadType; | 731 codec_.pltype = kPayloadType; |
| 738 | 732 |
| 739 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec | 733 // Register iSAC codec in ACM, effectively unregistering the PCM16B codec |
| 740 // registered in AudioCodingModuleTestOldApi::SetUp(); | 734 // registered in AudioCodingModuleTestOldApi::SetUp(); |
| 741 // Only register the decoder for now. The encoder is registered later. | 735 // Only register the decoder for now. The encoder is registered later. |
| 742 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); | 736 ASSERT_EQ(0, acm_->RegisterReceiveCodec(codec_)); |
| 743 } | 737 } |
| 744 | 738 |
| 745 void StartThreads() { | 739 void StartThreads() { |
| 746 ASSERT_TRUE(receive_thread_->Start()); | 740 receive_thread_.Start(); |
| 747 receive_thread_->SetPriority(kRealtimePriority); | 741 receive_thread_.SetPriority(rtc::kRealtimePriority); |
| 748 ASSERT_TRUE(codec_registration_thread_->Start()); | 742 codec_registration_thread_.Start(); |
| 749 codec_registration_thread_->SetPriority(kRealtimePriority); | 743 codec_registration_thread_.SetPriority(rtc::kRealtimePriority); |
| 750 } | 744 } |
| 751 | 745 |
| 752 void TearDown() { | 746 void TearDown() { |
| 753 AudioCodingModuleTestOldApi::TearDown(); | 747 AudioCodingModuleTestOldApi::TearDown(); |
| 754 receive_thread_->Stop(); | 748 receive_thread_.Stop(); |
| 755 codec_registration_thread_->Stop(); | 749 codec_registration_thread_.Stop(); |
| 756 } | 750 } |
| 757 | 751 |
| 758 EventTypeWrapper RunTest() { | 752 EventTypeWrapper RunTest() { |
| 759 return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. | 753 return test_complete_->Wait(10 * 60 * 1000); // 10 minutes' timeout. |
| 760 } | 754 } |
| 761 | 755 |
| 762 static bool CbReceiveThread(void* context) { | 756 static bool CbReceiveThread(void* context) { |
| 763 return reinterpret_cast<AcmReRegisterIsacMtTestOldApi*>(context) | 757 return reinterpret_cast<AcmReRegisterIsacMtTestOldApi*>(context) |
| 764 ->CbReceiveImpl(); | 758 ->CbReceiveImpl(); |
| 765 } | 759 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 // Register the iSAC encoder. | 818 // Register the iSAC encoder. |
| 825 EXPECT_EQ(0, acm_->RegisterSendCodec(codec_)); | 819 EXPECT_EQ(0, acm_->RegisterSendCodec(codec_)); |
| 826 codec_registered_ = true; | 820 codec_registered_ = true; |
| 827 } | 821 } |
| 828 if (codec_registered_ && receive_packet_count_ > kNumPackets) { | 822 if (codec_registered_ && receive_packet_count_ > kNumPackets) { |
| 829 test_complete_->Set(); | 823 test_complete_->Set(); |
| 830 } | 824 } |
| 831 return true; | 825 return true; |
| 832 } | 826 } |
| 833 | 827 |
| 834 rtc::scoped_ptr<PlatformThread> receive_thread_; | 828 rtc::PlatformThread receive_thread_; |
| 835 rtc::scoped_ptr<PlatformThread> codec_registration_thread_; | 829 rtc::PlatformThread codec_registration_thread_; |
| 836 const rtc::scoped_ptr<EventWrapper> test_complete_; | 830 const rtc::scoped_ptr<EventWrapper> test_complete_; |
| 837 const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; | 831 const rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; |
| 838 bool codec_registered_ GUARDED_BY(crit_sect_); | 832 bool codec_registered_ GUARDED_BY(crit_sect_); |
| 839 int receive_packet_count_ GUARDED_BY(crit_sect_); | 833 int receive_packet_count_ GUARDED_BY(crit_sect_); |
| 840 int64_t next_insert_packet_time_ms_ GUARDED_BY(crit_sect_); | 834 int64_t next_insert_packet_time_ms_ GUARDED_BY(crit_sect_); |
| 841 rtc::scoped_ptr<AudioEncoderIsac> isac_encoder_; | 835 rtc::scoped_ptr<AudioEncoderIsac> isac_encoder_; |
| 842 rtc::scoped_ptr<SimulatedClock> fake_clock_; | 836 rtc::scoped_ptr<SimulatedClock> fake_clock_; |
| 843 test::AudioLoop audio_loop_; | 837 test::AudioLoop audio_loop_; |
| 844 }; | 838 }; |
| 845 | 839 |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 Run(16000, 8000, 1000); | 1762 Run(16000, 8000, 1000); |
| 1769 } | 1763 } |
| 1770 | 1764 |
| 1771 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { | 1765 TEST_F(AcmSwitchingOutputFrequencyOldApi, Toggle8KhzTo16Khz) { |
| 1772 Run(8000, 16000, 1000); | 1766 Run(8000, 16000, 1000); |
| 1773 } | 1767 } |
| 1774 | 1768 |
| 1775 #endif | 1769 #endif |
| 1776 | 1770 |
| 1777 } // namespace webrtc | 1771 } // namespace webrtc |
| OLD | NEW |