OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include <algorithm> | 10 #include <algorithm> |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
659 } | 659 } |
660 | 660 |
661 rtc::CriticalSection crit_; | 661 rtc::CriticalSection crit_; |
662 std::set<uint32_t> protected_sequence_numbers_ GUARDED_BY(crit_); | 662 std::set<uint32_t> protected_sequence_numbers_ GUARDED_BY(crit_); |
663 std::set<uint32_t> protected_timestamps_ GUARDED_BY(crit_); | 663 std::set<uint32_t> protected_timestamps_ GUARDED_BY(crit_); |
664 } test; | 664 } test; |
665 | 665 |
666 RunBaseTest(&test); | 666 RunBaseTest(&test); |
667 } | 667 } |
668 | 668 |
669 TEST_F(EndToEndTest, CanReceiveFlexfec) { | |
670 class FlexfecRenderObserver : public test::EndToEndTest, | |
671 public rtc::VideoSinkInterface<VideoFrame> { | |
672 public: | |
673 FlexfecRenderObserver() | |
674 : EndToEndTest(kDefaultTimeoutMs), state_(kFirstPacket) {} | |
675 | |
676 size_t GetNumFlexfecStreams() const override { return 1; } | |
677 | |
678 private: | |
679 Action OnSendRtp(const uint8_t* packet, size_t length) override { | |
680 rtc::CritScope lock(&crit_); | |
681 RTPHeader header; | |
682 EXPECT_TRUE(parser_->Parse(packet, length, &header)); | |
683 | |
684 uint8_t payload_type = header.payloadType; | |
685 if (payload_type != kFakeVideoSendPayloadType) { | |
686 EXPECT_EQ(kFlexfecPayloadType, payload_type); | |
687 } | |
688 | |
689 if (protected_sequence_numbers_.count(header.sequenceNumber) != 0) { | |
stefan-webrtc
2016/11/15 14:21:44
I prefer find() over count as it's cheaper.
brandtr
2016/11/15 14:29:47
Done.
| |
690 // Retransmitted packet, should not count. | |
691 protected_sequence_numbers_.erase(header.sequenceNumber); | |
stefan-webrtc
2016/11/15 14:21:44
And then you can erase what you found here.
brandtr
2016/11/15 14:29:47
Done.
| |
692 EXPECT_GT(protected_timestamps_.count(header.timestamp), 0u); | |
693 protected_timestamps_.erase(header.timestamp); | |
694 return SEND_PACKET; | |
695 } | |
696 | |
697 switch (state_) { | |
698 case kFirstPacket: | |
699 state_ = kDropEveryOtherPacketUntilFlexfec; | |
700 break; | |
701 case kDropEveryOtherPacketUntilFlexfec: | |
702 if (payload_type == kFlexfecPayloadType) { | |
703 state_ = kDropNextMediaPacket; | |
704 return SEND_PACKET; | |
705 } | |
706 if (header.sequenceNumber % 2 == 0) | |
707 return DROP_PACKET; | |
708 break; | |
709 case kDropNextMediaPacket: | |
710 if (payload_type == kFakeVideoSendPayloadType) { | |
711 protected_sequence_numbers_.insert(header.sequenceNumber); | |
712 protected_timestamps_.insert(header.timestamp); | |
713 state_ = kDropEveryOtherPacketUntilFlexfec; | |
714 return DROP_PACKET; | |
715 } | |
716 break; | |
717 } | |
718 | |
719 return SEND_PACKET; | |
720 } | |
721 | |
722 void OnFrame(const VideoFrame& video_frame) override { | |
723 rtc::CritScope lock(&crit_); | |
724 // Rendering frame with timestamp of packet that was dropped -> FEC | |
725 // protection worked. | |
726 if (protected_timestamps_.count(video_frame.timestamp()) != 0) | |
727 observation_complete_.Set(); | |
728 } | |
729 | |
730 enum { | |
731 kFirstPacket, | |
732 kDropEveryOtherPacketUntilFlexfec, | |
733 kDropNextMediaPacket, | |
734 } state_; | |
735 | |
736 void ModifyVideoConfigs( | |
737 VideoSendStream::Config* send_config, | |
738 std::vector<VideoReceiveStream::Config>* receive_configs, | |
739 VideoEncoderConfig* encoder_config) override { | |
740 (*receive_configs)[0].renderer = this; | |
741 } | |
742 | |
743 void PerformTest() override { | |
744 EXPECT_TRUE(Wait()) | |
745 << "Timed out waiting for dropped frames frames to be rendered."; | |
746 } | |
747 | |
748 rtc::CriticalSection crit_; | |
749 std::set<uint32_t> protected_sequence_numbers_ GUARDED_BY(crit_); | |
750 std::set<uint32_t> protected_timestamps_ GUARDED_BY(crit_); | |
751 } test; | |
752 | |
753 RunBaseTest(&test); | |
754 } | |
755 | |
669 TEST_F(EndToEndTest, ReceivedUlpfecPacketsNotNacked) { | 756 TEST_F(EndToEndTest, ReceivedUlpfecPacketsNotNacked) { |
670 class UlpfecNackObserver : public test::EndToEndTest { | 757 class UlpfecNackObserver : public test::EndToEndTest { |
671 public: | 758 public: |
672 UlpfecNackObserver() | 759 UlpfecNackObserver() |
673 : EndToEndTest(kDefaultTimeoutMs), | 760 : EndToEndTest(kDefaultTimeoutMs), |
674 state_(kFirstPacket), | 761 state_(kFirstPacket), |
675 ulpfec_sequence_number_(0), | 762 ulpfec_sequence_number_(0), |
676 has_last_sequence_number_(false), | 763 has_last_sequence_number_(false), |
677 last_sequence_number_(0), | 764 last_sequence_number_(0), |
678 encoder_(VideoEncoder::Create(VideoEncoder::EncoderType::kVp8)), | 765 encoder_(VideoEncoder::Create(VideoEncoder::EncoderType::kVp8)), |
(...skipping 3023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3702 | 3789 |
3703 void VerifyEmptyUlpfecConfig(const UlpfecConfig& config) { | 3790 void VerifyEmptyUlpfecConfig(const UlpfecConfig& config) { |
3704 EXPECT_EQ(-1, config.ulpfec_payload_type) | 3791 EXPECT_EQ(-1, config.ulpfec_payload_type) |
3705 << "Enabling ULPFEC requires rtpmap: ulpfec negotiation."; | 3792 << "Enabling ULPFEC requires rtpmap: ulpfec negotiation."; |
3706 EXPECT_EQ(-1, config.red_payload_type) | 3793 EXPECT_EQ(-1, config.red_payload_type) |
3707 << "Enabling ULPFEC requires rtpmap: red negotiation."; | 3794 << "Enabling ULPFEC requires rtpmap: red negotiation."; |
3708 EXPECT_EQ(-1, config.red_rtx_payload_type) | 3795 EXPECT_EQ(-1, config.red_rtx_payload_type) |
3709 << "Enabling RTX in ULPFEC requires rtpmap: rtx negotiation."; | 3796 << "Enabling RTX in ULPFEC requires rtpmap: rtx negotiation."; |
3710 } | 3797 } |
3711 | 3798 |
3799 void VerifyEmptyFlexfecConfig(const FlexfecConfig& config) { | |
3800 EXPECT_EQ(-1, config.flexfec_payload_type) | |
3801 << "Enabling FlexFEC requires rtpmap: flexfec negotiation."; | |
3802 EXPECT_TRUE(config.protected_media_ssrcs.empty()) | |
3803 << "Enabling FlexFEC requires ssrc-group: FEC-FR negotiation."; | |
3804 } | |
3805 | |
3712 TEST_F(EndToEndTest, VerifyDefaultSendConfigParameters) { | 3806 TEST_F(EndToEndTest, VerifyDefaultSendConfigParameters) { |
3713 VideoSendStream::Config default_send_config(nullptr); | 3807 VideoSendStream::Config default_send_config(nullptr); |
3714 EXPECT_EQ(0, default_send_config.rtp.nack.rtp_history_ms) | 3808 EXPECT_EQ(0, default_send_config.rtp.nack.rtp_history_ms) |
3715 << "Enabling NACK require rtcp-fb: nack negotiation."; | 3809 << "Enabling NACK require rtcp-fb: nack negotiation."; |
3716 EXPECT_TRUE(default_send_config.rtp.rtx.ssrcs.empty()) | 3810 EXPECT_TRUE(default_send_config.rtp.rtx.ssrcs.empty()) |
3717 << "Enabling RTX requires rtpmap: rtx negotiation."; | 3811 << "Enabling RTX requires rtpmap: rtx negotiation."; |
3718 EXPECT_TRUE(default_send_config.rtp.extensions.empty()) | 3812 EXPECT_TRUE(default_send_config.rtp.extensions.empty()) |
3719 << "Enabling RTP extensions require negotiation."; | 3813 << "Enabling RTP extensions require negotiation."; |
3720 | 3814 |
3721 VerifyEmptyNackConfig(default_send_config.rtp.nack); | 3815 VerifyEmptyNackConfig(default_send_config.rtp.nack); |
3722 VerifyEmptyUlpfecConfig(default_send_config.rtp.ulpfec); | 3816 VerifyEmptyUlpfecConfig(default_send_config.rtp.ulpfec); |
3817 VerifyEmptyFlexfecConfig(default_send_config.rtp.flexfec); | |
3723 } | 3818 } |
3724 | 3819 |
3725 TEST_F(EndToEndTest, VerifyDefaultReceiveConfigParameters) { | 3820 TEST_F(EndToEndTest, VerifyDefaultVideoReceiveConfigParameters) { |
3726 VideoReceiveStream::Config default_receive_config(nullptr); | 3821 VideoReceiveStream::Config default_receive_config(nullptr); |
3727 EXPECT_EQ(RtcpMode::kCompound, default_receive_config.rtp.rtcp_mode) | 3822 EXPECT_EQ(RtcpMode::kCompound, default_receive_config.rtp.rtcp_mode) |
3728 << "Reduced-size RTCP require rtcp-rsize to be negotiated."; | 3823 << "Reduced-size RTCP require rtcp-rsize to be negotiated."; |
3729 EXPECT_FALSE(default_receive_config.rtp.remb) | 3824 EXPECT_FALSE(default_receive_config.rtp.remb) |
3730 << "REMB require rtcp-fb: goog-remb to be negotiated."; | 3825 << "REMB require rtcp-fb: goog-remb to be negotiated."; |
3731 EXPECT_FALSE( | 3826 EXPECT_FALSE( |
3732 default_receive_config.rtp.rtcp_xr.receiver_reference_time_report) | 3827 default_receive_config.rtp.rtcp_xr.receiver_reference_time_report) |
3733 << "RTCP XR settings require rtcp-xr to be negotiated."; | 3828 << "RTCP XR settings require rtcp-xr to be negotiated."; |
3734 EXPECT_TRUE(default_receive_config.rtp.rtx.empty()) | 3829 EXPECT_TRUE(default_receive_config.rtp.rtx.empty()) |
3735 << "Enabling RTX requires rtpmap: rtx negotiation."; | 3830 << "Enabling RTX requires rtpmap: rtx negotiation."; |
3736 EXPECT_TRUE(default_receive_config.rtp.extensions.empty()) | 3831 EXPECT_TRUE(default_receive_config.rtp.extensions.empty()) |
3737 << "Enabling RTP extensions require negotiation."; | 3832 << "Enabling RTP extensions require negotiation."; |
3738 | 3833 |
3739 VerifyEmptyNackConfig(default_receive_config.rtp.nack); | 3834 VerifyEmptyNackConfig(default_receive_config.rtp.nack); |
3740 VerifyEmptyUlpfecConfig(default_receive_config.rtp.ulpfec); | 3835 VerifyEmptyUlpfecConfig(default_receive_config.rtp.ulpfec); |
3741 } | 3836 } |
3742 | 3837 |
3838 TEST_F(EndToEndTest, VerifyDefaultFlexfecReceiveConfigParameters) { | |
3839 FlexfecReceiveStream::Config default_receive_config; | |
3840 VerifyEmptyFlexfecConfig(default_receive_config); | |
3841 } | |
3842 | |
3743 TEST_F(EndToEndTest, TransportSeqNumOnAudioAndVideo) { | 3843 TEST_F(EndToEndTest, TransportSeqNumOnAudioAndVideo) { |
3744 static const int kExtensionId = 8; | 3844 static const int kExtensionId = 8; |
3745 class TransportSequenceNumberTest : public test::EndToEndTest { | 3845 class TransportSequenceNumberTest : public test::EndToEndTest { |
3746 public: | 3846 public: |
3747 TransportSequenceNumberTest() | 3847 TransportSequenceNumberTest() |
3748 : EndToEndTest(kDefaultTimeoutMs), | 3848 : EndToEndTest(kDefaultTimeoutMs), |
3749 video_observed_(false), | 3849 video_observed_(false), |
3750 audio_observed_(false) { | 3850 audio_observed_(false) { |
3751 parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber, | 3851 parser_->RegisterRtpHeaderExtension(kRtpExtensionTransportSequenceNumber, |
3752 kExtensionId); | 3852 kExtensionId); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3907 std::unique_ptr<VideoEncoder> encoder_; | 4007 std::unique_ptr<VideoEncoder> encoder_; |
3908 std::unique_ptr<VideoDecoder> decoder_; | 4008 std::unique_ptr<VideoDecoder> decoder_; |
3909 rtc::CriticalSection crit_; | 4009 rtc::CriticalSection crit_; |
3910 int recorded_frames_ GUARDED_BY(crit_); | 4010 int recorded_frames_ GUARDED_BY(crit_); |
3911 } test(this); | 4011 } test(this); |
3912 | 4012 |
3913 RunBaseTest(&test); | 4013 RunBaseTest(&test); |
3914 } | 4014 } |
3915 | 4015 |
3916 } // namespace webrtc | 4016 } // namespace webrtc |
OLD | NEW |