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 * This file includes unit tests for the RTPPacketHistory. | 10 * This file includes unit tests for the RTPPacketHistory. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 size_t len_out = kMaxPacketLength; | 155 size_t len_out = kMaxPacketLength; |
156 int64_t time; | 156 int64_t time; |
157 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 157 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, |
158 &len_out, &time)); | 158 &len_out, &time)); |
159 EXPECT_EQ(len, len_out); | 159 EXPECT_EQ(len, len_out); |
160 EXPECT_EQ(capture_time_ms, time); | 160 EXPECT_EQ(capture_time_ms, time); |
161 } | 161 } |
162 | 162 |
163 TEST_F(RtpPacketHistoryTest, MinResendTime) { | 163 TEST_F(RtpPacketHistoryTest, MinResendTime) { |
| 164 static const int64_t kMinRetransmitIntervalMs = 100; |
| 165 |
164 hist_->SetStorePacketsStatus(true, 10); | 166 hist_->SetStorePacketsStatus(true, 10); |
165 size_t len = 0; | 167 size_t len = 0; |
166 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 168 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
167 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 169 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
168 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, | 170 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
169 kAllowRetransmission)); | 171 kAllowRetransmission)); |
170 | 172 |
| 173 // First transmission: TimeToSendPacket() call from pacer. |
171 int64_t time; | 174 int64_t time; |
172 len = kMaxPacketLength; | 175 len = kMaxPacketLength; |
173 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, | 176 EXPECT_TRUE( |
174 &time)); | 177 hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, &time)); |
175 fake_clock_.AdvanceTimeMilliseconds(100); | 178 |
| 179 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs); |
176 // Time has elapsed. | 180 // Time has elapsed. |
177 len = kMaxPacketLength; | 181 len = kMaxPacketLength; |
178 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, | 182 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, |
179 &time)); | 183 true, packet_, &len, &time)); |
180 EXPECT_GT(len, 0u); | 184 EXPECT_GT(len, 0u); |
181 EXPECT_EQ(capture_time_ms, time); | 185 EXPECT_EQ(capture_time_ms, time); |
182 | 186 |
| 187 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
183 // Time has not elapsed. Packet should be found, but no bytes copied. | 188 // Time has not elapsed. Packet should be found, but no bytes copied. |
184 len = kMaxPacketLength; | 189 len = kMaxPacketLength; |
185 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 101, false, packet_, | 190 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, |
186 &len, &time)); | 191 true, packet_, &len, &time)); |
| 192 } |
| 193 |
| 194 TEST_F(RtpPacketHistoryTest, EarlyFirstResend) { |
| 195 static const int64_t kMinRetransmitIntervalMs = 100; |
| 196 |
| 197 hist_->SetStorePacketsStatus(true, 10); |
| 198 size_t len = 0; |
| 199 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 200 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 201 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 202 kAllowRetransmission)); |
| 203 |
| 204 // First transmission: TimeToSendPacket() call from pacer. |
| 205 int64_t time; |
| 206 len = kMaxPacketLength; |
| 207 EXPECT_TRUE( |
| 208 hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, &time)); |
| 209 |
| 210 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
| 211 // Time has not elapsed, but this is the first retransmission request so |
| 212 // allow anyway. |
| 213 len = kMaxPacketLength; |
| 214 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, |
| 215 true, packet_, &len, &time)); |
| 216 EXPECT_GT(len, 0u); |
| 217 EXPECT_EQ(capture_time_ms, time); |
| 218 |
| 219 fake_clock_.AdvanceTimeMilliseconds(kMinRetransmitIntervalMs - 1); |
| 220 // Time has not elapsed. Packet should be found, but no bytes copied. |
| 221 len = kMaxPacketLength; |
| 222 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, kMinRetransmitIntervalMs, |
| 223 true, packet_, &len, &time)); |
187 } | 224 } |
188 | 225 |
189 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { | 226 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { |
190 hist_->SetStorePacketsStatus(true, 10); | 227 hist_->SetStorePacketsStatus(true, 10); |
191 size_t len; | 228 size_t len; |
192 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 229 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
193 int64_t time; | 230 int64_t time; |
194 | 231 |
195 // Add 4 packets, and then send them. | 232 // Add 4 packets, and then send them. |
196 for (int i = 0; i < 4; ++i) { | 233 for (int i = 0; i < 4; ++i) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 283 |
247 // Retransmit all packets currently in buffer. | 284 // Retransmit all packets currently in buffer. |
248 for (size_t i = 1; i < kMaxHistoryCapacity + 1; ++i) { | 285 for (size_t i = 1; i < kMaxHistoryCapacity + 1; ++i) { |
249 len = kMaxPacketLength; | 286 len = kMaxPacketLength; |
250 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | 287 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, |
251 &len, &time)); | 288 &len, &time)); |
252 } | 289 } |
253 } | 290 } |
254 | 291 |
255 } // namespace webrtc | 292 } // namespace webrtc |
OLD | NEW |