| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 EXPECT_TRUE(hist_->StorePackets()); | 63 EXPECT_TRUE(hist_->StorePackets()); |
| 64 hist_->SetStorePacketsStatus(false, 0); | 64 hist_->SetStorePacketsStatus(false, 0); |
| 65 EXPECT_FALSE(hist_->StorePackets()); | 65 EXPECT_FALSE(hist_->StorePackets()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(RtpPacketHistoryTest, NoStoreStatus) { | 68 TEST_F(RtpPacketHistoryTest, NoStoreStatus) { |
| 69 EXPECT_FALSE(hist_->StorePackets()); | 69 EXPECT_FALSE(hist_->StorePackets()); |
| 70 size_t len = 0; | 70 size_t len = 0; |
| 71 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 71 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 72 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 72 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 73 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 73 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 74 capture_time_ms, kAllowRetransmission)); | 74 kAllowRetransmission)); |
| 75 // Packet should not be stored. | 75 // Packet should not be stored. |
| 76 len = kMaxPacketLength; | 76 len = kMaxPacketLength; |
| 77 int64_t time; | 77 int64_t time; |
| 78 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, | 78 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, |
| 79 &time)); | 79 &time)); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(RtpPacketHistoryTest, DontStore) { | 82 TEST_F(RtpPacketHistoryTest, DontStore) { |
| 83 hist_->SetStorePacketsStatus(true, 10); | 83 hist_->SetStorePacketsStatus(true, 10); |
| 84 size_t len = 0; | 84 size_t len = 0; |
| 85 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 85 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 86 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 86 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 87 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 87 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, kDontStore)); |
| 88 capture_time_ms, kDontStore)); | |
| 89 | 88 |
| 90 // Packet should not be stored. | 89 // Packet should not be stored. |
| 91 len = kMaxPacketLength; | 90 len = kMaxPacketLength; |
| 92 int64_t time; | 91 int64_t time; |
| 93 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, | 92 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_, &len, |
| 94 &time)); | 93 &time)); |
| 95 } | 94 } |
| 96 | 95 |
| 97 TEST_F(RtpPacketHistoryTest, PutRtpPacket_TooLargePacketLength) { | 96 TEST_F(RtpPacketHistoryTest, PutRtpPacket_TooLargePacketLength) { |
| 98 hist_->SetStorePacketsStatus(true, 10); | 97 hist_->SetStorePacketsStatus(true, 10); |
| 99 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 98 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 100 EXPECT_EQ(-1, hist_->PutRTPPacket(packet_, | 99 EXPECT_EQ(-1, hist_->PutRTPPacket(packet_, kMaxPacketLength + 1, |
| 101 kMaxPacketLength + 1, | 100 capture_time_ms, kAllowRetransmission)); |
| 102 kMaxPacketLength, | |
| 103 capture_time_ms, | |
| 104 kAllowRetransmission)); | |
| 105 } | 101 } |
| 106 | 102 |
| 107 TEST_F(RtpPacketHistoryTest, GetRtpPacket_NotStored) { | 103 TEST_F(RtpPacketHistoryTest, GetRtpPacket_NotStored) { |
| 108 hist_->SetStorePacketsStatus(true, 10); | 104 hist_->SetStorePacketsStatus(true, 10); |
| 109 size_t len = kMaxPacketLength; | 105 size_t len = kMaxPacketLength; |
| 110 int64_t time; | 106 int64_t time; |
| 111 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(0, 0, false, packet_, &len, | 107 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(0, 0, false, packet_, &len, |
| 112 &time)); | 108 &time)); |
| 113 } | 109 } |
| 114 | 110 |
| 115 TEST_F(RtpPacketHistoryTest, PutRtpPacket) { | 111 TEST_F(RtpPacketHistoryTest, PutRtpPacket) { |
| 116 hist_->SetStorePacketsStatus(true, 10); | 112 hist_->SetStorePacketsStatus(true, 10); |
| 117 size_t len = 0; | 113 size_t len = 0; |
| 118 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 114 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 119 | 115 |
| 120 EXPECT_FALSE(hist_->HasRTPPacket(kSeqNum)); | 116 EXPECT_FALSE(hist_->HasRTPPacket(kSeqNum)); |
| 121 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 117 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 122 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 118 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 123 capture_time_ms, kAllowRetransmission)); | 119 kAllowRetransmission)); |
| 124 EXPECT_TRUE(hist_->HasRTPPacket(kSeqNum)); | 120 EXPECT_TRUE(hist_->HasRTPPacket(kSeqNum)); |
| 125 } | 121 } |
| 126 | 122 |
| 127 TEST_F(RtpPacketHistoryTest, GetRtpPacket) { | 123 TEST_F(RtpPacketHistoryTest, GetRtpPacket) { |
| 128 hist_->SetStorePacketsStatus(true, 10); | 124 hist_->SetStorePacketsStatus(true, 10); |
| 129 size_t len = 0; | 125 size_t len = 0; |
| 130 int64_t capture_time_ms = 1; | 126 int64_t capture_time_ms = 1; |
| 131 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 127 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 132 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 128 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 133 capture_time_ms, kAllowRetransmission)); | 129 kAllowRetransmission)); |
| 134 | 130 |
| 135 size_t len_out = kMaxPacketLength; | 131 size_t len_out = kMaxPacketLength; |
| 136 int64_t time; | 132 int64_t time; |
| 137 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 133 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, |
| 138 &len_out, &time)); | 134 &len_out, &time)); |
| 139 EXPECT_EQ(len, len_out); | 135 EXPECT_EQ(len, len_out); |
| 140 EXPECT_EQ(capture_time_ms, time); | 136 EXPECT_EQ(capture_time_ms, time); |
| 141 for (size_t i = 0; i < len; i++) { | 137 for (size_t i = 0; i < len; i++) { |
| 142 EXPECT_EQ(packet_[i], packet_out_[i]); | 138 EXPECT_EQ(packet_[i], packet_out_[i]); |
| 143 } | 139 } |
| 144 } | 140 } |
| 145 | 141 |
| 146 TEST_F(RtpPacketHistoryTest, NoCaptureTime) { | 142 TEST_F(RtpPacketHistoryTest, NoCaptureTime) { |
| 147 hist_->SetStorePacketsStatus(true, 10); | 143 hist_->SetStorePacketsStatus(true, 10); |
| 148 size_t len = 0; | 144 size_t len = 0; |
| 149 fake_clock_.AdvanceTimeMilliseconds(1); | 145 fake_clock_.AdvanceTimeMilliseconds(1); |
| 150 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 146 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 151 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 147 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 152 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 148 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, -1, kAllowRetransmission)); |
| 153 -1, kAllowRetransmission)); | |
| 154 | 149 |
| 155 size_t len_out = kMaxPacketLength; | 150 size_t len_out = kMaxPacketLength; |
| 156 int64_t time; | 151 int64_t time; |
| 157 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 152 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, |
| 158 &len_out, &time)); | 153 &len_out, &time)); |
| 159 EXPECT_EQ(len, len_out); | 154 EXPECT_EQ(len, len_out); |
| 160 EXPECT_EQ(capture_time_ms, time); | 155 EXPECT_EQ(capture_time_ms, time); |
| 161 for (size_t i = 0; i < len; i++) { | 156 for (size_t i = 0; i < len; i++) { |
| 162 EXPECT_EQ(packet_[i], packet_out_[i]); | 157 EXPECT_EQ(packet_[i], packet_out_[i]); |
| 163 } | 158 } |
| 164 } | 159 } |
| 165 | 160 |
| 166 TEST_F(RtpPacketHistoryTest, DontRetransmit) { | 161 TEST_F(RtpPacketHistoryTest, DontRetransmit) { |
| 167 hist_->SetStorePacketsStatus(true, 10); | 162 hist_->SetStorePacketsStatus(true, 10); |
| 168 size_t len = 0; | 163 size_t len = 0; |
| 169 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 164 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 170 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 165 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 171 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 166 EXPECT_EQ( |
| 172 capture_time_ms, kDontRetransmit)); | 167 0, hist_->PutRTPPacket(packet_, len, capture_time_ms, kDontRetransmit)); |
| 173 | 168 |
| 174 size_t len_out = kMaxPacketLength; | 169 size_t len_out = kMaxPacketLength; |
| 175 int64_t time; | 170 int64_t time; |
| 176 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, | 171 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 0, false, packet_out_, |
| 177 &len_out, &time)); | 172 &len_out, &time)); |
| 178 EXPECT_EQ(len, len_out); | 173 EXPECT_EQ(len, len_out); |
| 179 EXPECT_EQ(capture_time_ms, time); | 174 EXPECT_EQ(capture_time_ms, time); |
| 180 } | 175 } |
| 181 | 176 |
| 182 TEST_F(RtpPacketHistoryTest, MinResendTime) { | 177 TEST_F(RtpPacketHistoryTest, MinResendTime) { |
| 183 hist_->SetStorePacketsStatus(true, 10); | 178 hist_->SetStorePacketsStatus(true, 10); |
| 184 size_t len = 0; | 179 size_t len = 0; |
| 185 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 180 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 186 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); | 181 CreateRtpPacket(kSeqNum, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 187 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 182 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 188 capture_time_ms, kAllowRetransmission)); | 183 kAllowRetransmission)); |
| 189 | 184 |
| 190 int64_t time; | 185 int64_t time; |
| 191 len = kMaxPacketLength; | 186 len = kMaxPacketLength; |
| 192 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, | 187 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, |
| 193 &time)); | 188 &time)); |
| 194 fake_clock_.AdvanceTimeMilliseconds(100); | 189 fake_clock_.AdvanceTimeMilliseconds(100); |
| 195 // Time has elapsed. | 190 // Time has elapsed. |
| 196 len = kMaxPacketLength; | 191 len = kMaxPacketLength; |
| 197 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, | 192 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum, 100, false, packet_, &len, |
| 198 &time)); | 193 &time)); |
| 199 EXPECT_GT(len, 0u); | 194 EXPECT_GT(len, 0u); |
| 200 EXPECT_EQ(capture_time_ms, time); | 195 EXPECT_EQ(capture_time_ms, time); |
| 201 | 196 |
| 202 // Time has not elapsed. Packet should be found, but no bytes copied. | 197 // Time has not elapsed. Packet should be found, but no bytes copied. |
| 203 len = kMaxPacketLength; | 198 len = kMaxPacketLength; |
| 204 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 101, false, packet_, | 199 EXPECT_FALSE(hist_->GetPacketAndSetSendTime(kSeqNum, 101, false, packet_, |
| 205 &len, &time)); | 200 &len, &time)); |
| 206 } | 201 } |
| 207 | 202 |
| 208 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { | 203 TEST_F(RtpPacketHistoryTest, DynamicExpansion) { |
| 209 hist_->SetStorePacketsStatus(true, 10); | 204 hist_->SetStorePacketsStatus(true, 10); |
| 210 size_t len; | 205 size_t len; |
| 211 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 206 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 212 int64_t time; | 207 int64_t time; |
| 213 | 208 |
| 214 // Add 4 packets, and then send them. | 209 // Add 4 packets, and then send them. |
| 215 for (int i = 0; i < 4; ++i) { | 210 for (int i = 0; i < 4; ++i) { |
| 216 len = 0; | 211 len = 0; |
| 217 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | 212 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 218 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 213 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 219 capture_time_ms, kAllowRetransmission)); | 214 kAllowRetransmission)); |
| 220 } | 215 } |
| 221 for (int i = 0; i < 4; ++i) { | 216 for (int i = 0; i < 4; ++i) { |
| 222 len = kMaxPacketLength; | 217 len = kMaxPacketLength; |
| 223 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | 218 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, |
| 224 &len, &time)); | 219 &len, &time)); |
| 225 } | 220 } |
| 226 capture_time_ms += 33; | 221 capture_time_ms += 33; |
| 227 | 222 |
| 228 // Add 16 packets, and then send them. History should expand to make this | 223 // Add 16 packets, and then send them. History should expand to make this |
| 229 // work. | 224 // work. |
| 230 for (int i = 4; i < 20; ++i) { | 225 for (int i = 4; i < 20; ++i) { |
| 231 len = 0; | 226 len = 0; |
| 232 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | 227 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 233 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 228 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 234 capture_time_ms, kAllowRetransmission)); | 229 kAllowRetransmission)); |
| 235 } | 230 } |
| 236 for (int i = 4; i < 20; ++i) { | 231 for (int i = 4; i < 20; ++i) { |
| 237 len = kMaxPacketLength; | 232 len = kMaxPacketLength; |
| 238 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | 233 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, |
| 239 &len, &time)); | 234 &len, &time)); |
| 240 } | 235 } |
| 241 | 236 |
| 242 fake_clock_.AdvanceTimeMilliseconds(100); | 237 fake_clock_.AdvanceTimeMilliseconds(100); |
| 243 | 238 |
| 244 // Retransmit last 16 packets. | 239 // Retransmit last 16 packets. |
| 245 for (int i = 4; i < 20; ++i) { | 240 for (int i = 4; i < 20; ++i) { |
| 246 len = kMaxPacketLength; | 241 len = kMaxPacketLength; |
| 247 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | 242 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, |
| 248 &len, &time)); | 243 &len, &time)); |
| 249 } | 244 } |
| 250 } | 245 } |
| 251 | 246 |
| 252 TEST_F(RtpPacketHistoryTest, FullExpansion) { | 247 TEST_F(RtpPacketHistoryTest, FullExpansion) { |
| 253 hist_->SetStorePacketsStatus(true, kSendSidePacketHistorySize); | 248 hist_->SetStorePacketsStatus(true, kSendSidePacketHistorySize); |
| 254 size_t len; | 249 size_t len; |
| 255 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); | 250 int64_t capture_time_ms = fake_clock_.TimeInMilliseconds(); |
| 256 int64_t time; | 251 int64_t time; |
| 257 for (size_t i = 0; i < kMaxHistoryCapacity + 1; ++i) { | 252 for (size_t i = 0; i < kMaxHistoryCapacity + 1; ++i) { |
| 258 len = 0; | 253 len = 0; |
| 259 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); | 254 CreateRtpPacket(kSeqNum + i, kSsrc, kPayload, kTimestamp, packet_, &len); |
| 260 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, kMaxPacketLength, | 255 EXPECT_EQ(0, hist_->PutRTPPacket(packet_, len, capture_time_ms, |
| 261 capture_time_ms, kAllowRetransmission)); | 256 kAllowRetransmission)); |
| 262 } | 257 } |
| 263 | 258 |
| 264 fake_clock_.AdvanceTimeMilliseconds(100); | 259 fake_clock_.AdvanceTimeMilliseconds(100); |
| 265 | 260 |
| 266 // Retransmit all packets currently in buffer. | 261 // Retransmit all packets currently in buffer. |
| 267 for (size_t i = 1; i < kMaxHistoryCapacity + 1; ++i) { | 262 for (size_t i = 1; i < kMaxHistoryCapacity + 1; ++i) { |
| 268 len = kMaxPacketLength; | 263 len = kMaxPacketLength; |
| 269 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, | 264 EXPECT_TRUE(hist_->GetPacketAndSetSendTime(kSeqNum + i, 100, false, packet_, |
| 270 &len, &time)); | 265 &len, &time)); |
| 271 } | 266 } |
| 272 } | 267 } |
| 273 | 268 |
| 274 } // namespace webrtc | 269 } // namespace webrtc |
| OLD | NEW |