OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 <list> | 11 #include <list> |
12 #include <memory> | 12 #include <memory> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" |
| 18 #include "webrtc/base/rate_limiter.h" |
18 #include "webrtc/call/mock/mock_rtc_event_log.h" | 19 #include "webrtc/call/mock/mock_rtc_event_log.h" |
19 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_cvo.h" |
20 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 21 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 22 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
22 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtp_format_video_generic.h" |
23 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtp_sender_video.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" |
27 #include "webrtc/system_wrappers/include/stl_util.h" | 28 #include "webrtc/system_wrappers/include/stl_util.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 public: | 127 public: |
127 MOCK_METHOD3(OnSendPacket, void(uint16_t, int64_t, uint32_t)); | 128 MOCK_METHOD3(OnSendPacket, void(uint16_t, int64_t, uint32_t)); |
128 }; | 129 }; |
129 | 130 |
130 class RtpSenderTest : public ::testing::Test { | 131 class RtpSenderTest : public ::testing::Test { |
131 protected: | 132 protected: |
132 RtpSenderTest() | 133 RtpSenderTest() |
133 : fake_clock_(kStartTime), | 134 : fake_clock_(kStartTime), |
134 mock_rtc_event_log_(), | 135 mock_rtc_event_log_(), |
135 mock_paced_sender_(), | 136 mock_paced_sender_(), |
| 137 retransmission_rate_limiter_(&fake_clock_, 1000), |
136 rtp_sender_(), | 138 rtp_sender_(), |
137 payload_(kPayload), | 139 payload_(kPayload), |
138 transport_(), | 140 transport_(), |
139 kMarkerBit(true) { | 141 kMarkerBit(true) {} |
140 } | |
141 | 142 |
142 void SetUp() override { SetUpRtpSender(true); } | 143 void SetUp() override { SetUpRtpSender(true); } |
143 | 144 |
144 void SetUpRtpSender(bool pacer) { | 145 void SetUpRtpSender(bool pacer) { |
145 rtp_sender_.reset(new RTPSender( | 146 rtp_sender_.reset(new RTPSender( |
146 false, &fake_clock_, &transport_, pacer ? &mock_paced_sender_ : nullptr, | 147 false, &fake_clock_, &transport_, pacer ? &mock_paced_sender_ : nullptr, |
147 &seq_num_allocator_, nullptr, nullptr, nullptr, nullptr, | 148 &seq_num_allocator_, nullptr, nullptr, nullptr, nullptr, |
148 &mock_rtc_event_log_, &send_packet_observer_)); | 149 &mock_rtc_event_log_, &send_packet_observer_, |
| 150 &retransmission_rate_limiter_)); |
149 rtp_sender_->SetSequenceNumber(kSeqNum); | 151 rtp_sender_->SetSequenceNumber(kSeqNum); |
150 } | 152 } |
151 | 153 |
152 SimulatedClock fake_clock_; | 154 SimulatedClock fake_clock_; |
153 MockRtcEventLog mock_rtc_event_log_; | 155 MockRtcEventLog mock_rtc_event_log_; |
154 MockRtpPacketSender mock_paced_sender_; | 156 MockRtpPacketSender mock_paced_sender_; |
155 MockTransportSequenceNumberAllocator seq_num_allocator_; | 157 MockTransportSequenceNumberAllocator seq_num_allocator_; |
156 MockSendPacketObserver send_packet_observer_; | 158 MockSendPacketObserver send_packet_observer_; |
| 159 RateLimiter retransmission_rate_limiter_; |
157 std::unique_ptr<RTPSender> rtp_sender_; | 160 std::unique_ptr<RTPSender> rtp_sender_; |
158 int payload_; | 161 int payload_; |
159 LoopbackTransportTest transport_; | 162 LoopbackTransportTest transport_; |
160 const bool kMarkerBit; | 163 const bool kMarkerBit; |
161 uint8_t packet_[kMaxPacketLength]; | 164 uint8_t packet_[kMaxPacketLength]; |
162 | 165 |
163 void VerifyRTPHeaderCommon(const RTPHeader& rtp_header) { | 166 void VerifyRTPHeaderCommon(const RTPHeader& rtp_header) { |
164 VerifyRTPHeaderCommon(rtp_header, kMarkerBit, 0); | 167 VerifyRTPHeaderCommon(rtp_header, kMarkerBit, 0); |
165 } | 168 } |
166 | 169 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 EXPECT_CALL(mock_rtc_event_log_, | 739 EXPECT_CALL(mock_rtc_event_log_, |
737 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)); | 740 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)); |
738 | 741 |
739 rtp_sender_->SetStorePacketsStatus(true, 10); | 742 rtp_sender_->SetStorePacketsStatus(true, 10); |
740 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( | 743 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( |
741 kRtpExtensionTransmissionTimeOffset, | 744 kRtpExtensionTransmissionTimeOffset, |
742 kTransmissionTimeOffsetExtensionId)); | 745 kTransmissionTimeOffsetExtensionId)); |
743 EXPECT_EQ( | 746 EXPECT_EQ( |
744 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 747 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
745 kAbsoluteSendTimeExtensionId)); | 748 kAbsoluteSendTimeExtensionId)); |
746 rtp_sender_->SetTargetBitrate(300000); | |
747 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 749 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
748 int rtp_length_int = rtp_sender_->BuildRTPheader( | 750 int rtp_length_int = rtp_sender_->BuildRTPheader( |
749 packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms); | 751 packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms); |
750 ASSERT_NE(-1, rtp_length_int); | 752 ASSERT_NE(-1, rtp_length_int); |
751 size_t rtp_length = static_cast<size_t>(rtp_length_int); | 753 size_t rtp_length = static_cast<size_t>(rtp_length_int); |
752 | 754 |
753 // Packet should be stored in a send bucket. | 755 // Packet should be stored in a send bucket. |
754 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, | 756 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, |
755 capture_time_ms, kAllowRetransmission, | 757 capture_time_ms, kAllowRetransmission, |
756 RtpPacketSender::kNormalPriority)); | 758 RtpPacketSender::kNormalPriority)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 EXPECT_CALL(mock_rtc_event_log_, | 792 EXPECT_CALL(mock_rtc_event_log_, |
791 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)); | 793 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)); |
792 | 794 |
793 rtp_sender_->SetStorePacketsStatus(true, 10); | 795 rtp_sender_->SetStorePacketsStatus(true, 10); |
794 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( | 796 EXPECT_EQ(0, rtp_sender_->RegisterRtpHeaderExtension( |
795 kRtpExtensionTransmissionTimeOffset, | 797 kRtpExtensionTransmissionTimeOffset, |
796 kTransmissionTimeOffsetExtensionId)); | 798 kTransmissionTimeOffsetExtensionId)); |
797 EXPECT_EQ( | 799 EXPECT_EQ( |
798 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 800 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
799 kAbsoluteSendTimeExtensionId)); | 801 kAbsoluteSendTimeExtensionId)); |
800 rtp_sender_->SetTargetBitrate(300000); | |
801 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 802 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
802 int rtp_length_int = rtp_sender_->BuildRTPheader( | 803 int rtp_length_int = rtp_sender_->BuildRTPheader( |
803 packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms); | 804 packet_, kPayload, kMarkerBit, kTimestamp, capture_time_ms); |
804 ASSERT_NE(-1, rtp_length_int); | 805 ASSERT_NE(-1, rtp_length_int); |
805 size_t rtp_length = static_cast<size_t>(rtp_length_int); | 806 size_t rtp_length = static_cast<size_t>(rtp_length_int); |
806 | 807 |
807 // Packet should be stored in a send bucket. | 808 // Packet should be stored in a send bucket. |
808 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, | 809 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, |
809 capture_time_ms, kAllowRetransmission, | 810 capture_time_ms, kAllowRetransmission, |
810 RtpPacketSender::kNormalPriority)); | 811 RtpPacketSender::kNormalPriority)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Create and set up parser. | 873 // Create and set up parser. |
873 std::unique_ptr<webrtc::RtpHeaderParser> rtp_parser( | 874 std::unique_ptr<webrtc::RtpHeaderParser> rtp_parser( |
874 webrtc::RtpHeaderParser::Create()); | 875 webrtc::RtpHeaderParser::Create()); |
875 ASSERT_TRUE(rtp_parser.get() != nullptr); | 876 ASSERT_TRUE(rtp_parser.get() != nullptr); |
876 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, | 877 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
877 kTransmissionTimeOffsetExtensionId); | 878 kTransmissionTimeOffsetExtensionId); |
878 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 879 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
879 kAbsoluteSendTimeExtensionId); | 880 kAbsoluteSendTimeExtensionId); |
880 webrtc::RTPHeader rtp_header; | 881 webrtc::RTPHeader rtp_header; |
881 | 882 |
882 rtp_sender_->SetTargetBitrate(300000); | |
883 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 883 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
884 int rtp_length_int = rtp_sender_->BuildRTPheader( | 884 int rtp_length_int = rtp_sender_->BuildRTPheader( |
885 packet_, kPayload, kMarkerBit, timestamp, capture_time_ms); | 885 packet_, kPayload, kMarkerBit, timestamp, capture_time_ms); |
886 const uint32_t media_packet_timestamp = timestamp; | 886 const uint32_t media_packet_timestamp = timestamp; |
887 ASSERT_NE(-1, rtp_length_int); | 887 ASSERT_NE(-1, rtp_length_int); |
888 size_t rtp_length = static_cast<size_t>(rtp_length_int); | 888 size_t rtp_length = static_cast<size_t>(rtp_length_int); |
889 | 889 |
890 // Packet should be stored in a send bucket. | 890 // Packet should be stored in a send bucket. |
891 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, | 891 EXPECT_EQ(0, rtp_sender_->SendToNetwork(packet_, 0, rtp_length, |
892 capture_time_ms, kAllowRetransmission, | 892 capture_time_ms, kAllowRetransmission, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1004 const bool kIsRetransmit = true; | 1004 const bool kIsRetransmit = true; |
1005 rtp_sender_->TimeToSendPacket(kSeqNum, fake_clock_.TimeInMilliseconds(), | 1005 rtp_sender_->TimeToSendPacket(kSeqNum, fake_clock_.TimeInMilliseconds(), |
1006 kIsRetransmit, PacketInfo::kNotAProbe); | 1006 kIsRetransmit, PacketInfo::kNotAProbe); |
1007 EXPECT_EQ(1, transport_.packets_sent_); | 1007 EXPECT_EQ(1, transport_.packets_sent_); |
1008 } | 1008 } |
1009 | 1009 |
1010 TEST_F(RtpSenderTest, OnSendPacketNotUpdatedWithoutSeqNumAllocator) { | 1010 TEST_F(RtpSenderTest, OnSendPacketNotUpdatedWithoutSeqNumAllocator) { |
1011 rtp_sender_.reset(new RTPSender( | 1011 rtp_sender_.reset(new RTPSender( |
1012 false, &fake_clock_, &transport_, &mock_paced_sender_, | 1012 false, &fake_clock_, &transport_, &mock_paced_sender_, |
1013 nullptr /* TransportSequenceNumberAllocator */, nullptr, nullptr, nullptr, | 1013 nullptr /* TransportSequenceNumberAllocator */, nullptr, nullptr, nullptr, |
1014 nullptr, nullptr, &send_packet_observer_)); | 1014 nullptr, nullptr, &send_packet_observer_, nullptr)); |
1015 rtp_sender_->SetSequenceNumber(kSeqNum); | 1015 rtp_sender_->SetSequenceNumber(kSeqNum); |
1016 rtp_sender_->SetStorePacketsStatus(true, 10); | 1016 rtp_sender_->SetStorePacketsStatus(true, 10); |
1017 | 1017 |
1018 EXPECT_CALL(send_packet_observer_, OnSendPacket(_, _, _)).Times(0); | 1018 EXPECT_CALL(send_packet_observer_, OnSendPacket(_, _, _)).Times(0); |
1019 EXPECT_CALL(mock_paced_sender_, InsertPacket(_, _, _, _, _, _)).Times(1); | 1019 EXPECT_CALL(mock_paced_sender_, InsertPacket(_, _, _, _, _, _)).Times(1); |
1020 | 1020 |
1021 SendGenericPayload(); // Packet passed to pacer. | 1021 SendGenericPayload(); // Packet passed to pacer. |
1022 const bool kIsRetransmit = false; | 1022 const bool kIsRetransmit = false; |
1023 rtp_sender_->TimeToSendPacket(kSeqNum, fake_clock_.TimeInMilliseconds(), | 1023 rtp_sender_->TimeToSendPacket(kSeqNum, fake_clock_.TimeInMilliseconds(), |
1024 kIsRetransmit, PacketInfo::kNotAProbe); | 1024 kIsRetransmit, PacketInfo::kNotAProbe); |
1025 EXPECT_EQ(1, transport_.packets_sent_); | 1025 EXPECT_EQ(1, transport_.packets_sent_); |
1026 } | 1026 } |
1027 | 1027 |
1028 TEST_F(RtpSenderTest, SendRedundantPayloads) { | 1028 TEST_F(RtpSenderTest, SendRedundantPayloads) { |
1029 MockTransport transport; | 1029 MockTransport transport; |
1030 rtp_sender_.reset(new RTPSender( | 1030 rtp_sender_.reset(new RTPSender( |
1031 false, &fake_clock_, &transport, &mock_paced_sender_, nullptr, nullptr, | 1031 false, &fake_clock_, &transport, &mock_paced_sender_, nullptr, nullptr, |
1032 nullptr, nullptr, nullptr, &mock_rtc_event_log_, nullptr)); | 1032 nullptr, nullptr, nullptr, &mock_rtc_event_log_, nullptr, nullptr)); |
1033 | 1033 |
1034 rtp_sender_->SetSequenceNumber(kSeqNum); | 1034 rtp_sender_->SetSequenceNumber(kSeqNum); |
1035 rtp_sender_->SetRtxPayloadType(kRtxPayload, kPayload); | 1035 rtp_sender_->SetRtxPayloadType(kRtxPayload, kPayload); |
1036 | 1036 |
1037 uint16_t seq_num = kSeqNum; | 1037 uint16_t seq_num = kSeqNum; |
1038 rtp_sender_->SetStorePacketsStatus(true, 10); | 1038 rtp_sender_->SetStorePacketsStatus(true, 10); |
1039 int32_t rtp_header_len = kRtpHeaderSize; | 1039 int32_t rtp_header_len = kRtpHeaderSize; |
1040 EXPECT_EQ( | 1040 EXPECT_EQ( |
1041 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 1041 0, rtp_sender_->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
1042 kAbsoluteSendTimeExtensionId)); | 1042 kAbsoluteSendTimeExtensionId)); |
1043 rtp_header_len += 4; // 4 bytes extension. | 1043 rtp_header_len += 4; // 4 bytes extension. |
1044 rtp_header_len += 4; // 4 extra bytes common to all extension headers. | 1044 rtp_header_len += 4; // 4 extra bytes common to all extension headers. |
1045 | 1045 |
1046 rtp_sender_->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads); | 1046 rtp_sender_->SetRtxStatus(kRtxRetransmitted | kRtxRedundantPayloads); |
1047 rtp_sender_->SetRtxSsrc(1234); | 1047 rtp_sender_->SetRtxSsrc(1234); |
1048 | 1048 |
1049 // Create and set up parser. | 1049 // Create and set up parser. |
1050 std::unique_ptr<webrtc::RtpHeaderParser> rtp_parser( | 1050 std::unique_ptr<webrtc::RtpHeaderParser> rtp_parser( |
1051 webrtc::RtpHeaderParser::Create()); | 1051 webrtc::RtpHeaderParser::Create()); |
1052 ASSERT_TRUE(rtp_parser.get() != nullptr); | 1052 ASSERT_TRUE(rtp_parser.get() != nullptr); |
1053 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, | 1053 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionTransmissionTimeOffset, |
1054 kTransmissionTimeOffsetExtensionId); | 1054 kTransmissionTimeOffsetExtensionId); |
1055 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, | 1055 rtp_parser->RegisterRtpHeaderExtension(kRtpExtensionAbsoluteSendTime, |
1056 kAbsoluteSendTimeExtensionId); | 1056 kAbsoluteSendTimeExtensionId); |
1057 rtp_sender_->SetTargetBitrate(300000); | |
1058 const size_t kNumPayloadSizes = 10; | 1057 const size_t kNumPayloadSizes = 10; |
1059 const size_t kPayloadSizes[kNumPayloadSizes] = {500, 550, 600, 650, 700, | 1058 const size_t kPayloadSizes[kNumPayloadSizes] = {500, 550, 600, 650, 700, |
1060 750, 800, 850, 900, 950}; | 1059 750, 800, 850, 900, 950}; |
1061 // Expect all packets go through the pacer. | 1060 // Expect all packets go through the pacer. |
1062 EXPECT_CALL(mock_paced_sender_, | 1061 EXPECT_CALL(mock_paced_sender_, |
1063 InsertPacket(RtpPacketSender::kNormalPriority, _, _, _, _, _)) | 1062 InsertPacket(RtpPacketSender::kNormalPriority, _, _, _, _, _)) |
1064 .Times(kNumPayloadSizes); | 1063 .Times(kNumPayloadSizes); |
1065 EXPECT_CALL(mock_rtc_event_log_, | 1064 EXPECT_CALL(mock_rtc_event_log_, |
1066 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)) | 1065 LogRtpHeader(PacketDirection::kOutgoingPacket, _, _, _)) |
1067 .Times(kNumPayloadSizes); | 1066 .Times(kNumPayloadSizes); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 frame_counts_ = frame_counts; | 1168 frame_counts_ = frame_counts; |
1170 } | 1169 } |
1171 | 1170 |
1172 uint32_t num_calls_; | 1171 uint32_t num_calls_; |
1173 uint32_t ssrc_; | 1172 uint32_t ssrc_; |
1174 FrameCounts frame_counts_; | 1173 FrameCounts frame_counts_; |
1175 } callback; | 1174 } callback; |
1176 | 1175 |
1177 rtp_sender_.reset(new RTPSender( | 1176 rtp_sender_.reset(new RTPSender( |
1178 false, &fake_clock_, &transport_, &mock_paced_sender_, nullptr, nullptr, | 1177 false, &fake_clock_, &transport_, &mock_paced_sender_, nullptr, nullptr, |
1179 nullptr, &callback, nullptr, nullptr, nullptr)); | 1178 nullptr, &callback, nullptr, nullptr, nullptr, nullptr)); |
1180 | 1179 |
1181 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; | 1180 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; |
1182 const uint8_t payload_type = 127; | 1181 const uint8_t payload_type = 127; |
1183 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, | 1182 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, |
1184 0, 1500)); | 1183 0, 1500)); |
1185 uint8_t payload[] = {47, 11, 32, 93, 89}; | 1184 uint8_t payload[] = {47, 11, 32, 93, 89}; |
1186 rtp_sender_->SetStorePacketsStatus(true, 1); | 1185 rtp_sender_->SetStorePacketsStatus(true, 1); |
1187 uint32_t ssrc = rtp_sender_->SSRC(); | 1186 uint32_t ssrc = rtp_sender_->SSRC(); |
1188 | 1187 |
1189 EXPECT_CALL(mock_paced_sender_, InsertPacket(_, _, _, _, _, _)) | 1188 EXPECT_CALL(mock_paced_sender_, InsertPacket(_, _, _, _, _, _)) |
(...skipping 16 matching lines...) Expand all Loading... |
1206 EXPECT_EQ(ssrc, callback.ssrc_); | 1205 EXPECT_EQ(ssrc, callback.ssrc_); |
1207 EXPECT_EQ(1, callback.frame_counts_.key_frames); | 1206 EXPECT_EQ(1, callback.frame_counts_.key_frames); |
1208 EXPECT_EQ(1, callback.frame_counts_.delta_frames); | 1207 EXPECT_EQ(1, callback.frame_counts_.delta_frames); |
1209 | 1208 |
1210 rtp_sender_.reset(); | 1209 rtp_sender_.reset(); |
1211 } | 1210 } |
1212 | 1211 |
1213 TEST_F(RtpSenderTest, BitrateCallbacks) { | 1212 TEST_F(RtpSenderTest, BitrateCallbacks) { |
1214 class TestCallback : public BitrateStatisticsObserver { | 1213 class TestCallback : public BitrateStatisticsObserver { |
1215 public: | 1214 public: |
1216 TestCallback() : BitrateStatisticsObserver(), num_calls_(0), ssrc_(0) {} | 1215 TestCallback() |
| 1216 : BitrateStatisticsObserver(), |
| 1217 num_calls_(0), |
| 1218 ssrc_(0), |
| 1219 total_bitrate_(0), |
| 1220 retransmit_bitrate_(0) {} |
1217 virtual ~TestCallback() {} | 1221 virtual ~TestCallback() {} |
1218 | 1222 |
1219 void Notify(const BitrateStatistics& total_stats, | 1223 void Notify(uint32_t total_bitrate, |
1220 const BitrateStatistics& retransmit_stats, | 1224 uint32_t retransmit_bitrate, |
1221 uint32_t ssrc) override { | 1225 uint32_t ssrc) override { |
1222 ++num_calls_; | 1226 ++num_calls_; |
1223 ssrc_ = ssrc; | 1227 ssrc_ = ssrc; |
1224 total_stats_ = total_stats; | 1228 total_bitrate_ = total_bitrate; |
1225 retransmit_stats_ = retransmit_stats; | 1229 retransmit_bitrate_ = retransmit_bitrate; |
1226 } | 1230 } |
1227 | 1231 |
1228 uint32_t num_calls_; | 1232 uint32_t num_calls_; |
1229 uint32_t ssrc_; | 1233 uint32_t ssrc_; |
1230 BitrateStatistics total_stats_; | 1234 uint32_t total_bitrate_; |
1231 BitrateStatistics retransmit_stats_; | 1235 uint32_t retransmit_bitrate_; |
1232 } callback; | 1236 } callback; |
1233 rtp_sender_.reset(new RTPSender(false, &fake_clock_, &transport_, nullptr, | 1237 rtp_sender_.reset(new RTPSender(false, &fake_clock_, &transport_, nullptr, |
1234 nullptr, nullptr, &callback, nullptr, nullptr, | 1238 nullptr, nullptr, &callback, nullptr, nullptr, |
1235 nullptr, nullptr)); | 1239 nullptr, nullptr, nullptr)); |
1236 | 1240 |
1237 // Simulate kNumPackets sent with kPacketInterval ms intervals. | 1241 // Simulate kNumPackets sent with kPacketInterval ms intervals, with the |
1238 const uint32_t kNumPackets = 15; | 1242 // number of packets selected so that we fill (but don't overflow) the one |
| 1243 // second averaging window. |
| 1244 const uint32_t kWindowSizeMs = 1000; |
1239 const uint32_t kPacketInterval = 20; | 1245 const uint32_t kPacketInterval = 20; |
| 1246 const uint32_t kNumPackets = |
| 1247 (kWindowSizeMs - kPacketInterval) / kPacketInterval; |
1240 // Overhead = 12 bytes RTP header + 1 byte generic header. | 1248 // Overhead = 12 bytes RTP header + 1 byte generic header. |
1241 const uint32_t kPacketOverhead = 13; | 1249 const uint32_t kPacketOverhead = 13; |
1242 | 1250 |
1243 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; | 1251 char payload_name[RTP_PAYLOAD_NAME_SIZE] = "GENERIC"; |
1244 const uint8_t payload_type = 127; | 1252 const uint8_t payload_type = 127; |
1245 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, | 1253 ASSERT_EQ(0, rtp_sender_->RegisterPayload(payload_name, payload_type, 90000, |
1246 0, 1500)); | 1254 0, 1500)); |
1247 uint8_t payload[] = {47, 11, 32, 93, 89}; | 1255 uint8_t payload[] = {47, 11, 32, 93, 89}; |
1248 rtp_sender_->SetStorePacketsStatus(true, 1); | 1256 rtp_sender_->SetStorePacketsStatus(true, 1); |
1249 uint32_t ssrc = rtp_sender_->SSRC(); | 1257 uint32_t ssrc = rtp_sender_->SSRC(); |
1250 | 1258 |
1251 // Initial process call so we get a new time window. | 1259 // Initial process call so we get a new time window. |
1252 rtp_sender_->ProcessBitrate(); | 1260 rtp_sender_->ProcessBitrate(); |
1253 uint64_t start_time = fake_clock_.CurrentNtpInMilliseconds(); | |
1254 | 1261 |
1255 // Send a few frames. | 1262 // Send a few frames. |
1256 for (uint32_t i = 0; i < kNumPackets; ++i) { | 1263 for (uint32_t i = 0; i < kNumPackets; ++i) { |
1257 ASSERT_EQ(0, | 1264 ASSERT_EQ(0, |
1258 rtp_sender_->SendOutgoingData(kVideoFrameKey, payload_type, 1234, | 1265 rtp_sender_->SendOutgoingData(kVideoFrameKey, payload_type, 1234, |
1259 4321, payload, sizeof(payload), 0)); | 1266 4321, payload, sizeof(payload), 0)); |
1260 fake_clock_.AdvanceTimeMilliseconds(kPacketInterval); | 1267 fake_clock_.AdvanceTimeMilliseconds(kPacketInterval); |
1261 } | 1268 } |
1262 | 1269 |
1263 rtp_sender_->ProcessBitrate(); | 1270 rtp_sender_->ProcessBitrate(); |
1264 | 1271 |
1265 const uint32_t expected_packet_rate = 1000 / kPacketInterval; | |
1266 | |
1267 // We get one call for every stats updated, thus two calls since both the | 1272 // We get one call for every stats updated, thus two calls since both the |
1268 // stream stats and the retransmit stats are updated once. | 1273 // stream stats and the retransmit stats are updated once. |
1269 EXPECT_EQ(2u, callback.num_calls_); | 1274 EXPECT_EQ(2u, callback.num_calls_); |
1270 EXPECT_EQ(ssrc, callback.ssrc_); | 1275 EXPECT_EQ(ssrc, callback.ssrc_); |
1271 EXPECT_EQ(start_time + (kNumPackets * kPacketInterval), | 1276 const uint32_t kTotalPacketSize = kPacketOverhead + sizeof(payload); |
1272 callback.total_stats_.timestamp_ms); | 1277 // Bitrate measured over delta between last and first timestamp, plus one. |
1273 EXPECT_EQ(expected_packet_rate, callback.total_stats_.packet_rate); | 1278 const uint32_t kExpectedWindowMs = kNumPackets * kPacketInterval + 1; |
1274 EXPECT_EQ((kPacketOverhead + sizeof(payload)) * 8 * expected_packet_rate, | 1279 const uint32_t kExpectedBitsAccumulated = kTotalPacketSize * kNumPackets * 8; |
1275 callback.total_stats_.bitrate_bps); | 1280 const uint32_t kExpectedRateBps = |
| 1281 (kExpectedBitsAccumulated * 1000 + (kExpectedWindowMs / 2)) / |
| 1282 kExpectedWindowMs; |
| 1283 EXPECT_EQ(kExpectedRateBps, callback.total_bitrate_); |
1276 | 1284 |
1277 rtp_sender_.reset(); | 1285 rtp_sender_.reset(); |
1278 } | 1286 } |
1279 | 1287 |
1280 class RtpSenderAudioTest : public RtpSenderTest { | 1288 class RtpSenderAudioTest : public RtpSenderTest { |
1281 protected: | 1289 protected: |
1282 RtpSenderAudioTest() {} | 1290 RtpSenderAudioTest() {} |
1283 | 1291 |
1284 void SetUp() override { | 1292 void SetUp() override { |
1285 payload_ = kAudioPayload; | 1293 payload_ = kAudioPayload; |
1286 rtp_sender_.reset(new RTPSender(true, &fake_clock_, &transport_, nullptr, | 1294 rtp_sender_.reset(new RTPSender(true, &fake_clock_, &transport_, nullptr, |
1287 nullptr, nullptr, nullptr, nullptr, nullptr, | 1295 nullptr, nullptr, nullptr, nullptr, nullptr, |
1288 nullptr, nullptr)); | 1296 nullptr, nullptr, nullptr)); |
1289 rtp_sender_->SetSequenceNumber(kSeqNum); | 1297 rtp_sender_->SetSequenceNumber(kSeqNum); |
1290 } | 1298 } |
1291 }; | 1299 }; |
1292 | 1300 |
1293 TEST_F(RtpSenderTestWithoutPacer, StreamDataCountersCallbacks) { | 1301 TEST_F(RtpSenderTestWithoutPacer, StreamDataCountersCallbacks) { |
1294 class TestCallback : public StreamDataCountersCallback { | 1302 class TestCallback : public StreamDataCountersCallback { |
1295 public: | 1303 public: |
1296 TestCallback() : StreamDataCountersCallback(), ssrc_(0), counters_() {} | 1304 TestCallback() : StreamDataCountersCallback(), ssrc_(0), counters_() {} |
1297 virtual ~TestCallback() {} | 1305 virtual ~TestCallback() {} |
1298 | 1306 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 | 1554 |
1547 EXPECT_EQ( | 1555 EXPECT_EQ( |
1548 transport_.total_bytes_sent_, | 1556 transport_.total_bytes_sent_, |
1549 rtp_stats.transmitted.TotalBytes() + rtx_stats.transmitted.TotalBytes()); | 1557 rtp_stats.transmitted.TotalBytes() + rtx_stats.transmitted.TotalBytes()); |
1550 } | 1558 } |
1551 | 1559 |
1552 TEST_F(RtpSenderTestWithoutPacer, RespectsNackBitrateLimit) { | 1560 TEST_F(RtpSenderTestWithoutPacer, RespectsNackBitrateLimit) { |
1553 const int32_t kPacketSize = 1400; | 1561 const int32_t kPacketSize = 1400; |
1554 const int32_t kNumPackets = 30; | 1562 const int32_t kNumPackets = 30; |
1555 | 1563 |
| 1564 retransmission_rate_limiter_.SetMaxRate(kPacketSize * kNumPackets * 8); |
| 1565 |
1556 rtp_sender_->SetStorePacketsStatus(true, kNumPackets); | 1566 rtp_sender_->SetStorePacketsStatus(true, kNumPackets); |
1557 // Set bitrate (in kbps) to fit kNumPackets รก kPacketSize bytes in one second. | |
1558 rtp_sender_->SetTargetBitrate(kNumPackets * kPacketSize * 8); | |
1559 const uint16_t kStartSequenceNumber = rtp_sender_->SequenceNumber(); | 1567 const uint16_t kStartSequenceNumber = rtp_sender_->SequenceNumber(); |
1560 std::list<uint16_t> sequence_numbers; | 1568 std::list<uint16_t> sequence_numbers; |
1561 for (int32_t i = 0; i < kNumPackets; ++i) { | 1569 for (int32_t i = 0; i < kNumPackets; ++i) { |
1562 sequence_numbers.push_back(kStartSequenceNumber + i); | 1570 sequence_numbers.push_back(kStartSequenceNumber + i); |
1563 fake_clock_.AdvanceTimeMilliseconds(1); | 1571 fake_clock_.AdvanceTimeMilliseconds(1); |
1564 SendPacket(fake_clock_.TimeInMilliseconds(), kPacketSize); | 1572 SendPacket(fake_clock_.TimeInMilliseconds(), kPacketSize); |
1565 } | 1573 } |
1566 EXPECT_EQ(kNumPackets, transport_.packets_sent_); | 1574 EXPECT_EQ(kNumPackets, transport_.packets_sent_); |
1567 | 1575 |
1568 fake_clock_.AdvanceTimeMilliseconds(1000 - kNumPackets); | 1576 fake_clock_.AdvanceTimeMilliseconds(1000 - kNumPackets); |
1569 | 1577 |
1570 // Resending should work - brings the bandwidth up to the limit. | 1578 // Resending should work - brings the bandwidth up to the limit. |
1571 // NACK bitrate is capped to the same bitrate as the encoder, since the max | 1579 // NACK bitrate is capped to the same bitrate as the encoder, since the max |
1572 // protection overhead is 50% (see MediaOptimization::SetTargetRates). | 1580 // protection overhead is 50% (see MediaOptimization::SetTargetRates). |
1573 rtp_sender_->OnReceivedNACK(sequence_numbers, 0); | 1581 rtp_sender_->OnReceivedNACK(sequence_numbers, 0); |
1574 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); | 1582 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); |
1575 | 1583 |
| 1584 // Must be at least 5ms in between retransmission attempts. |
| 1585 fake_clock_.AdvanceTimeMilliseconds(5); |
| 1586 |
1576 // Resending should not work, bandwidth exceeded. | 1587 // Resending should not work, bandwidth exceeded. |
1577 rtp_sender_->OnReceivedNACK(sequence_numbers, 0); | 1588 rtp_sender_->OnReceivedNACK(sequence_numbers, 0); |
1578 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); | 1589 EXPECT_EQ(kNumPackets * 2, transport_.packets_sent_); |
1579 } | 1590 } |
1580 | 1591 |
1581 // Verify that all packets of a frame have CVO byte set. | 1592 // Verify that all packets of a frame have CVO byte set. |
1582 TEST_F(RtpSenderVideoTest, SendVideoWithCVO) { | 1593 TEST_F(RtpSenderVideoTest, SendVideoWithCVO) { |
1583 RTPVideoHeader hdr = {0}; | 1594 RTPVideoHeader hdr = {0}; |
1584 hdr.rotation = kVideoRotation_90; | 1595 hdr.rotation = kVideoRotation_90; |
1585 | 1596 |
(...skipping 17 matching lines...) Expand all Loading... |
1603 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), | 1614 reinterpret_cast<uint8_t*>(transport_.sent_packets_[0]->data()), |
1604 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); | 1615 transport_.sent_packets_[0]->size(), true, &map, kSeqNum, hdr.rotation); |
1605 | 1616 |
1606 // Verify that this packet does have CVO byte. | 1617 // Verify that this packet does have CVO byte. |
1607 VerifyCVOPacket( | 1618 VerifyCVOPacket( |
1608 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), | 1619 reinterpret_cast<uint8_t*>(transport_.sent_packets_[1]->data()), |
1609 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, | 1620 transport_.sent_packets_[1]->size(), true, &map, kSeqNum + 1, |
1610 hdr.rotation); | 1621 hdr.rotation); |
1611 } | 1622 } |
1612 } // namespace webrtc | 1623 } // namespace webrtc |
OLD | NEW |