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 "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" |
| 12 |
| 13 #include <memory> |
| 14 |
11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
12 | |
13 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
14 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_history.h" | 17 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
15 #include "webrtc/system_wrappers/include/clock.h" | 18 #include "webrtc/system_wrappers/include/clock.h" |
16 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
17 | 20 |
18 namespace webrtc { | 21 namespace webrtc { |
19 | 22 |
20 class RtpPacketHistoryTest : public ::testing::Test { | 23 class RtpPacketHistoryTest : public ::testing::Test { |
21 protected: | 24 protected: |
22 RtpPacketHistoryTest() | 25 static constexpr uint16_t kSeqNum = 88; |
23 : fake_clock_(123456), | 26 |
24 hist_(new RTPPacketHistory(&fake_clock_)) { | 27 RtpPacketHistoryTest() : fake_clock_(123456), hist_(&fake_clock_) {} |
25 } | |
26 ~RtpPacketHistoryTest() { | |
27 delete hist_; | |
28 } | |
29 | 28 |
30 SimulatedClock fake_clock_; | 29 SimulatedClock fake_clock_; |
31 RTPPacketHistory* hist_; | 30 RtpPacketHistory hist_; |
32 enum {kPayload = 127}; | |
33 enum {kSsrc = 12345678}; | |
34 enum {kSeqNum = 88}; | |
35 enum {kTimestamp = 127}; | |
36 enum {kMaxPacketLength = 1500}; | |
37 uint8_t packet_[kMaxPacketLength]; | |
38 uint8_t packet_out_[kMaxPacketLength]; | |
39 | 31 |
40 void CreateRtpPacket(uint16_t seq_num, uint32_t ssrc, uint8_t payload, | 32 std::unique_ptr<RtpPacketToSend> CreateRtpPacket(uint16_t seq_num) { |
41 uint32_t timestamp, uint8_t* array, size_t* cur_pos) { | 33 // Payload, ssrc, timestamp and extensions are irrelevant for this tests. |
42 array[(*cur_pos)++] = 0x80; | 34 std::unique_ptr<RtpPacketToSend> packet(new RtpPacketToSend(nullptr)); |
43 array[(*cur_pos)++] = payload; | 35 packet->SetSequenceNumber(seq_num); |
44 array[(*cur_pos)++] = seq_num >> 8; | 36 packet->set_capture_time_ms(fake_clock_.TimeInMilliseconds()); |
45 array[(*cur_pos)++] = seq_num; | 37 return packet; |
46 array[(*cur_pos)++] = timestamp >> 24; | |
47 array[(*cur_pos)++] = timestamp >> 16; | |
48 array[(*cur_pos)++] = timestamp >> 8; | |
49 array[(*cur_pos)++] = timestamp; | |
50 array[(*cur_pos)++] = ssrc >> 24; | |
51 array[(*cur_pos)++] = ssrc >> 16; | |
52 array[(*cur_pos)++] = ssrc >> 8; | |
53 array[(*cur_pos)++] = ssrc; | |
54 } | 38 } |
55 }; | 39 }; |
56 | 40 |
57 TEST_F(RtpPacketHistoryTest, SetStoreStatus) { | 41 TEST_F(RtpPacketHistoryTest, SetStoreStatus) { |
58 EXPECT_FALSE(hist_->StorePackets()); | 42 EXPECT_FALSE(hist_.StorePackets()); |
59 hist_->SetStorePacketsStatus(true, 10); | 43 hist_.SetStorePacketsStatus(true, 10); |
60 EXPECT_TRUE(hist_->StorePackets()); | 44 EXPECT_TRUE(hist_.StorePackets()); |
61 hist_->SetStorePacketsStatus(false, 0); | 45 hist_.SetStorePacketsStatus(false, 0); |
62 EXPECT_FALSE(hist_->StorePackets()); | 46 EXPECT_FALSE(hist_.StorePackets()); |
63 } | 47 } |
64 | 48 |
65 TEST_F(RtpPacketHistoryTest, NoStoreStatus) { | 49 TEST_F(RtpPacketHistoryTest, NoStoreStatus) { |
66 EXPECT_FALSE(hist_->StorePackets()); | 50 EXPECT_FALSE(hist_.StorePackets()); |
67 size_t len = 0; | 51 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
68 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 52 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
69 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | |
70 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | |
71 kAllowRetransmission)); | |
72 // Packet should not be stored. | 53 // Packet should not be stored. |
73 len = kMaxPacketLength; | 54 EXPECT_FALSE(hist_.GetPacketAndSetSendTime(kSeqNum, 0, false)); |
74 int64_t time; | |
75 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, | |
76 &time)); | |
77 } | |
78 | |
79 TEST_F(RtpPacketHistoryTest, PutRtpPacket_TooLargePacketLength) { | |
80 hist_->SetStorePacketsStatus(true, 10); | |
81 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | |
82 EXPECT_EQ(-1, hist_->PutRTPPacket(packet_, kMaxPacketLength + 1, | |
83 capture_time_ms, kAllowRetransmission)); | |
84 } | 55 } |
85 | 56 |
86 TEST_F(RtpPacketHistoryTest, GetRtpPacket_NotStored) { | 57 TEST_F(RtpPacketHistoryTest, GetRtpPacket_NotStored) { |
87 hist_->SetStorePacketsStatus(true, 10); | 58 hist_.SetStorePacketsStatus(true, 10); |
88 size_t len = kMaxPacketLength; | 59 EXPECT_FALSE(hist_.GetPacketAndSetSendTime(0, 0, false)); |
89 int64_t time; | |
90 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(0, 0, false, packet_, &len, | |
91 &time)); | |
92 } | 60 } |
93 | 61 |
94 TEST_F(RtpPacketHistoryTest, PutRtpPacket) { | 62 TEST_F(RtpPacketHistoryTest, PutRtpPacket) { |
95 hist_->SetStorePacketsStatus(true, 10); | 63 hist_.SetStorePacketsStatus(true, 10); |
96 size_t len = 0; | 64 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
97 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | |
98 | 65 |
99 EXPECT_FALSE(hist_->HasRTPPacket(kSeqNum)); | 66 EXPECT_FALSE(hist_.HasRtpPacket(kSeqNum)); |
100 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 67 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
101 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | 68 EXPECT_TRUE(hist_.HasRtpPacket(kSeqNum)); |
102 kAllowRetransmission)); | |
103 EXPECT_TRUE(hist_->HasRTPPacket(kSeqNum)); | |
104 } | 69 } |
105 | 70 |
106 TEST_F(RtpPacketHistoryTest, GetRtpPacket) { | 71 TEST_F(RtpPacketHistoryTest, GetRtpPacket) { |
107 hist_->SetStorePacketsStatus(true, 10); | 72 hist_.SetStorePacketsStatus(true, 10); |
108 size_t len = 0; | |
109 int64_t capture_time_ms = 1; | 73 int64_t capture_time_ms = 1; |
110 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 74 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
111 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | 75 packet->set_capture_time_ms(capture_time_ms); |
112 kAllowRetransmission)); | 76 rtc::CopyOnWriteBuffer buffer = packet->Buffer(); |
| 77 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
113 | 78 |
114 size_t len_out = kMaxPacketLength; | 79 std::unique_ptr<RtpPacketToSend> packet_out = |
115 int64_t time; | 80 hist_.GetPacketAndSetSendTime(kSeqNum, 0, false); |
116 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 81 EXPECT_TRUE(packet_out); |
117 &len_out, &time)); | 82 EXPECT_EQ(buffer, packet_out->Buffer()); |
118 EXPECT_EQ(len, len_out); | 83 EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); |
119 EXPECT_EQ(capture_time_ms, time); | |
120 for (size_t i = 0; i < len; i++) { | |
121 EXPECT_EQ(packet_[i], packet_out_[i]); | |
122 } | |
123 } | 84 } |
124 | 85 |
125 TEST_F(RtpPacketHistoryTest, NoCaptureTime) { | 86 TEST_F(RtpPacketHistoryTest, NoCaptureTime) { |
126 hist_->SetStorePacketsStatus(true, 10); | 87 hist_.SetStorePacketsStatus(true, 10); |
127 size_t len = 0; | |
128 fake_clock_.AdvanceTimeMilliseconds(1); | 88 fake_clock_.AdvanceTimeMilliseconds(1); |
129 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 89 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
130 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 90 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
131 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, -1, kAllowRetransmission)); | 91 packet->set_capture_time_ms(-1); |
| 92 rtc::CopyOnWriteBuffer buffer = packet->Buffer(); |
| 93 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
132 | 94 |
133 size_t len_out = kMaxPacketLength; | 95 std::unique_ptr<RtpPacketToSend> packet_out = |
134 int64_t time; | 96 hist_.GetPacketAndSetSendTime(kSeqNum, 0, false); |
135 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 97 EXPECT_TRUE(packet_out); |
136 &len_out, &time)); | 98 EXPECT_EQ(buffer, packet_out->Buffer()); |
137 EXPECT_EQ(len, len_out); | 99 EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); |
138 EXPECT_EQ(capture_time_ms, time); | |
139 for (size_t i = 0; i < len; i++) { | |
140 EXPECT_EQ(packet_[i], packet_out_[i]); | |
141 } | |
142 } | 100 } |
143 | 101 |
144 TEST_F(RtpPacketHistoryTest, DontRetransmit) { | 102 TEST_F(RtpPacketHistoryTest, DontRetransmit) { |
145 hist_->SetStorePacketsStatus(true, 10); | 103 hist_.SetStorePacketsStatus(true, 10); |
146 size_t len = 0; | |
147 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 104 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
148 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 105 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
149 EXPECT_EQ( | 106 rtc::CopyOnWriteBuffer buffer = packet->Buffer(); |
150 0, hist_->PutRTPPacket(packet_, len, capture_time_ms, kDontRetransmit)); | 107 hist_.PutRtpPacket(std::move(packet), kDontRetransmit, false); |
151 | 108 |
152 size_t len_out = kMaxPacketLength; | 109 std::unique_ptr<RtpPacketToSend> packet_out = |
153 int64_t time; | 110 hist_.GetPacketAndSetSendTime(kSeqNum, 0, false); |
154 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 111 EXPECT_TRUE(packet_out); |
155 &len_out, &time)); | 112 |
156 EXPECT_EQ(len, len_out); | 113 EXPECT_EQ(buffer.size(), packet_out->size()); |
157 EXPECT_EQ(capture_time_ms, time); | 114 EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); |
158 } | 115 } |
159 | 116 |
160 TEST_F(RtpPacketHistoryTest, MinResendTime) { | 117 TEST_F(RtpPacketHistoryTest, MinResendTime) { |
161 static const int64_t kMinRetransmitIntervalMs = 100; | 118 static const int64_t kMinRetransmitIntervalMs = 100; |
162 | 119 |
163 hist_->SetStorePacketsStatus(true, 10); | 120 hist_.SetStorePacketsStatus(true, 10); |
164 size_t len = 0; | |
165 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 121 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
166 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 122 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
167 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | 123 size_t len = packet->size(); |
168 kAllowRetransmission)); | 124 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
169 | 125 |
170 // First transmission: TimeToSendPacket() call from pacer. | 126 // First transmission: TimeToSendPacket() call from pacer. |
171 int64_t time; | 127 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum, 0, false)); |
172 len = kMaxPacketLength; | |
173 EXPECT_TRUE( | |
174 hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, &time)); | |
175 | 128 |
176 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs); | 129 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs); |
177 // Time has elapsed. | 130 // Time has elapsed. |
178 len = kMaxPacketLength; | 131 std::unique_ptr<RtpPacketToSend> packet_out = |
179 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, | 132 hist_.GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, true); |
180 true, packet_, &len, &time)); | 133 EXPECT_TRUE(packet_out); |
181 EXPECT_GT(len, 0u); | 134 EXPECT_EQ(len, packet_out->size()); |
182 EXPECT_EQ(capture_time_ms, time); | 135 EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); |
183 | 136 |
184 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); | 137 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
185 // Time has not elapsed. Packet should be found, but no bytes copied. | 138 // Time has not elapsed. Packet should be found, but no bytes copied. |
186 len = kMaxPacketLength; | 139 EXPECT_TRUE(hist_.HasRtpPacket(kSeqNum)); |
187 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, | 140 EXPECT_FALSE( |
188 true, packet_, &len, &time)); | 141 hist_.GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, true)); |
189 } | 142 } |
190 | 143 |
191 TEST_F(RtpPacketHistoryTest, EarlyFirstResend) { | 144 TEST_F(RtpPacketHistoryTest, EarlyFirstResend) { |
192 static const int64_t kMinRetransmitIntervalMs = 100; | 145 static const int64_t kMinRetransmitIntervalMs = 100; |
193 | 146 |
194 hist_->SetStorePacketsStatus(true, 10); | 147 hist_.SetStorePacketsStatus(true, 10); |
195 size_t len = 0; | |
196 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 148 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
197 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 149 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum); |
198 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | 150 rtc::CopyOnWriteBuffer buffer = packet->Buffer(); |
199 kAllowRetransmission)); | 151 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
200 | 152 |
201 // First transmission: TimeToSendPacket() call from pacer. | 153 // First transmission: TimeToSendPacket() call from pacer. |
202 int64_t time; | 154 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum, 0, false)); |
203 len = kMaxPacketLength; | |
204 EXPECT_TRUE( | |
205 hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, &time)); | |
206 | 155 |
207 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); | 156 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
208 // Time has not elapsed, but this is the first retransmission request so | 157 // Time has not elapsed, but this is the first retransmission request so |
209 // allow anyway. | 158 // allow anyway. |
210 len = kMaxPacketLength; | 159 std::unique_ptr<RtpPacketToSend> packet_out = |
211 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, | 160 hist_.GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, true); |
212 true, packet_, &len, &time)); | 161 EXPECT_TRUE(packet_out); |
213 EXPECT_GT(len, 0u); | 162 EXPECT_EQ(buffer, packet_out->Buffer()); |
214 EXPECT_EQ(capture_time_ms, time); | 163 EXPECT_EQ(capture_time_ms, packet_out->capture_time_ms()); |
215 | 164 |
216 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); | 165 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
217 // Time has not elapsed. Packet should be found, but no bytes copied. | 166 // Time has not elapsed. Packet should be found, but no bytes copied. |
218 len = kMaxPacketLength; | 167 EXPECT_TRUE(hist_.HasRtpPacket(kSeqNum)); |
219 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, | 168 EXPECT_FALSE( |
220 true, packet_, &len, &time)); | 169 hist_.GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, true)); |
221 } | 170 } |
222 | 171 |
223 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { | 172 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { |
224 hist_->SetStorePacketsStatus(true, 10); | 173 hist_.SetStorePacketsStatus(true, 10); |
225 size_t len; | |
226 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | |
227 int64_t time; | |
228 | 174 |
229 // Add 4 packets, and then send them. | 175 // Add 4 packets, and then send them. |
230 for (int i = 0; i < 4; ++i) { | 176 for (int i = 0; i < 4; ++i) { |
231 len = 0; | 177 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum + i); |
232 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | 178 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
233 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | |
234 kAllowRetransmission)); | |
235 } | 179 } |
236 for (int i = 0; i < 4; ++i) { | 180 for (int i = 0; i < 4; ++i) { |
237 len = kMaxPacketLength; | 181 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); |
238 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | |
239 &len, &time)); | |
240 } | 182 } |
241 capture_time_ms += 33; | 183 fake_clock_.AdvanceTimeMilliseconds(33); |
242 | 184 |
243 // Add 16 packets, and then send them. History should expand to make this | 185 // Add 16 packets, and then send them. History should expand to make this |
244 // work. | 186 // work. |
245 for (int i = 4; i < 20; ++i) { | 187 for (int i = 4; i < 20; ++i) { |
246 len = 0; | 188 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum + i); |
247 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | 189 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
248 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | |
249 kAllowRetransmission)); | |
250 } | 190 } |
251 for (int i = 4; i < 20; ++i) { | 191 for (int i = 4; i < 20; ++i) { |
252 len = kMaxPacketLength; | 192 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); |
253 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | |
254 &len, &time)); | |
255 } | 193 } |
256 | 194 |
257 fake_clock_.AdvanceTimeMilliseconds(100); | 195 fake_clock_.AdvanceTimeMilliseconds(100); |
258 | 196 |
259 // Retransmit last 16 packets. | 197 // Retransmit last 16 packets. |
260 for (int i = 4; i < 20; ++i) { | 198 for (int i = 4; i < 20; ++i) { |
261 len = kMaxPacketLength; | 199 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); |
262 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | |
263 &len, &time)); | |
264 } | 200 } |
265 } | 201 } |
266 | 202 |
267 TEST_F(RtpPacketHistoryTest, FullExpansion) { | 203 TEST_F(RtpPacketHistoryTest, FullExpansion) { |
268 static const int kSendSidePacketHistorySize = 600; | 204 static const int kSendSidePacketHistorySize = 600; |
269 hist_->SetStorePacketsStatus(true, kSendSidePacketHistorySize); | 205 hist_.SetStorePacketsStatus(true, kSendSidePacketHistorySize); |
270 size_t len; | 206 for (size_t i = 0; i < RtpPacketHistory::kMaxCapacity + 1; ++i) { |
271 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 207 std::unique_ptr<RtpPacketToSend> packet = CreateRtpPacket(kSeqNum + i); |
272 int64_t time; | 208 hist_.PutRtpPacket(std::move(packet), kAllowRetransmission, false); |
273 for (size_t i = 0; i < kMaxHistoryCapacity + 1; ++i) { | |
274 len = 0; | |
275 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | |
276 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | |
277 kAllowRetransmission)); | |
278 } | 209 } |
279 | 210 |
280 fake_clock_.AdvanceTimeMilliseconds(100); | 211 fake_clock_.AdvanceTimeMilliseconds(100); |
281 | 212 |
282 // Retransmit all packets currently in buffer. | 213 // Retransmit all packets currently in buffer. |
283 for (size_t i = 1; i < kMaxHistoryCapacity + 1; ++i) { | 214 for (size_t i = 1; i < RtpPacketHistory::kMaxCapacity + 1; ++i) { |
284 len = kMaxPacketLength; | 215 EXPECT_TRUE(hist_.GetPacketAndSetSendTime(kSeqNum + i, 100, false)); |
285 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | |
286 &len, &time)); | |
287 } | 216 } |
288 } | 217 } |
289 | 218 |
290 } // namespace webrtc | 219 } // namespace webrtc |
OLD | NEW |