Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_sender_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698