OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 SendTimeHistoryTest() | 26 SendTimeHistoryTest() |
27 : clock_(0), history_(&clock_, kDefaultHistoryLengthMs) {} | 27 : clock_(0), history_(&clock_, kDefaultHistoryLengthMs) {} |
28 ~SendTimeHistoryTest() {} | 28 ~SendTimeHistoryTest() {} |
29 | 29 |
30 virtual void SetUp() {} | 30 virtual void SetUp() {} |
31 | 31 |
32 virtual void TearDown() {} | 32 virtual void TearDown() {} |
33 | 33 |
34 void AddPacketWithSendTime(uint16_t sequence_number, | 34 void AddPacketWithSendTime(uint16_t sequence_number, |
35 size_t length, | 35 size_t length, |
36 bool was_paced, | |
37 int64_t send_time_ms, | 36 int64_t send_time_ms, |
38 int probe_cluster_id) { | 37 int probe_cluster_id) { |
39 history_.AddAndRemoveOld(sequence_number, length, was_paced, | 38 history_.AddAndRemoveOld(sequence_number, length, probe_cluster_id); |
40 probe_cluster_id); | |
41 history_.OnSentPacket(sequence_number, send_time_ms); | 39 history_.OnSentPacket(sequence_number, send_time_ms); |
42 } | 40 } |
43 | 41 |
44 webrtc::SimulatedClock clock_; | 42 webrtc::SimulatedClock clock_; |
45 SendTimeHistory history_; | 43 SendTimeHistory history_; |
46 }; | 44 }; |
47 | 45 |
48 // Help class extended so we can do EXPECT_EQ and collections. | 46 // Help class extended so we can do EXPECT_EQ and collections. |
49 class PacketInfo : public webrtc::PacketInfo { | 47 class PacketInfo : public webrtc::PacketInfo { |
50 public: | 48 public: |
51 PacketInfo() | |
52 : webrtc::PacketInfo(-1, | |
53 0, | |
54 0, | |
55 0, | |
56 0, | |
57 false, | |
58 webrtc::PacketInfo::kNotAProbe) {} | |
59 PacketInfo(int64_t arrival_time_ms, uint16_t sequence_number) | 49 PacketInfo(int64_t arrival_time_ms, uint16_t sequence_number) |
60 : PacketInfo(arrival_time_ms, | 50 : PacketInfo(arrival_time_ms, |
61 0, | 51 0, |
62 sequence_number, | 52 sequence_number, |
63 0, | 53 0, |
64 false, | |
65 PacketInfo::kNotAProbe) {} | 54 PacketInfo::kNotAProbe) {} |
66 PacketInfo(int64_t arrival_time_ms, | 55 PacketInfo(int64_t arrival_time_ms, |
67 int64_t send_time_ms, | 56 int64_t send_time_ms, |
68 uint16_t sequence_number, | 57 uint16_t sequence_number, |
69 size_t payload_size, | 58 size_t payload_size, |
70 bool was_paced, | |
71 int probe_cluster_id) | 59 int probe_cluster_id) |
72 : webrtc::PacketInfo(-1, | 60 : webrtc::PacketInfo(-1, |
73 arrival_time_ms, | 61 arrival_time_ms, |
74 send_time_ms, | 62 send_time_ms, |
75 sequence_number, | 63 sequence_number, |
76 payload_size, | 64 payload_size, |
77 was_paced, | |
78 probe_cluster_id) {} | 65 probe_cluster_id) {} |
79 bool operator==(const PacketInfo& other) const { | 66 bool operator==(const PacketInfo& other) const { |
80 return arrival_time_ms == other.arrival_time_ms && | 67 return arrival_time_ms == other.arrival_time_ms && |
81 send_time_ms == other.send_time_ms && | 68 send_time_ms == other.send_time_ms && |
82 sequence_number == other.sequence_number && | 69 sequence_number == other.sequence_number && |
83 payload_size == other.payload_size && was_paced == other.was_paced && | 70 payload_size == other.payload_size && |
84 probe_cluster_id == other.probe_cluster_id; | 71 probe_cluster_id == other.probe_cluster_id; |
85 } | 72 } |
86 }; | 73 }; |
87 | 74 |
88 TEST_F(SendTimeHistoryTest, AddRemoveOne) { | 75 TEST_F(SendTimeHistoryTest, AddRemoveOne) { |
89 const uint16_t kSeqNo = 10; | 76 const uint16_t kSeqNo = 10; |
90 const int kProbeClusterId = 0; | 77 const int kProbeClusterId = 0; |
91 const PacketInfo kSentPacket(0, 1, kSeqNo, 1, true, kProbeClusterId); | 78 const PacketInfo kSentPacket(0, 1, kSeqNo, 1, kProbeClusterId); |
92 AddPacketWithSendTime(kSeqNo, 1, true, 1, kProbeClusterId); | 79 AddPacketWithSendTime(kSeqNo, 1, 1, kProbeClusterId); |
93 | 80 |
94 PacketInfo received_packet(0, 0, kSeqNo, 0, false, kProbeClusterId); | 81 PacketInfo received_packet(0, 0, kSeqNo, 0, kProbeClusterId); |
95 EXPECT_TRUE(history_.GetInfo(&received_packet, false)); | 82 EXPECT_TRUE(history_.GetInfo(&received_packet, false)); |
96 EXPECT_EQ(kSentPacket, received_packet); | 83 EXPECT_EQ(kSentPacket, received_packet); |
97 | 84 |
98 PacketInfo received_packet2(0, 0, kSeqNo, 0, false, kProbeClusterId); | 85 PacketInfo received_packet2(0, 0, kSeqNo, 0, kProbeClusterId); |
99 EXPECT_TRUE(history_.GetInfo(&received_packet2, true)); | 86 EXPECT_TRUE(history_.GetInfo(&received_packet2, true)); |
100 EXPECT_EQ(kSentPacket, received_packet2); | 87 EXPECT_EQ(kSentPacket, received_packet2); |
101 | 88 |
102 PacketInfo received_packet3(0, 0, kSeqNo, 0, false, kProbeClusterId); | 89 PacketInfo received_packet3(0, 0, kSeqNo, 0, kProbeClusterId); |
103 EXPECT_FALSE(history_.GetInfo(&received_packet3, true)); | 90 EXPECT_FALSE(history_.GetInfo(&received_packet3, true)); |
104 } | 91 } |
105 | 92 |
106 TEST_F(SendTimeHistoryTest, PopulatesExpectedFields) { | 93 TEST_F(SendTimeHistoryTest, PopulatesExpectedFields) { |
107 const uint16_t kSeqNo = 10; | 94 const uint16_t kSeqNo = 10; |
108 const int64_t kSendTime = 1000; | 95 const int64_t kSendTime = 1000; |
109 const int64_t kReceiveTime = 2000; | 96 const int64_t kReceiveTime = 2000; |
110 const size_t kPayloadSize = 42; | 97 const size_t kPayloadSize = 42; |
111 const bool kPaced = true; | |
112 | 98 |
113 AddPacketWithSendTime(kSeqNo, kPayloadSize, kPaced, kSendTime, | 99 AddPacketWithSendTime(kSeqNo, kPayloadSize, kSendTime, |
114 PacketInfo::kNotAProbe); | 100 PacketInfo::kNotAProbe); |
115 | 101 |
116 PacketInfo info(kReceiveTime, kSeqNo); | 102 PacketInfo info(kReceiveTime, kSeqNo); |
117 EXPECT_TRUE(history_.GetInfo(&info, true)); | 103 EXPECT_TRUE(history_.GetInfo(&info, true)); |
118 EXPECT_EQ(kReceiveTime, info.arrival_time_ms); | 104 EXPECT_EQ(kReceiveTime, info.arrival_time_ms); |
119 EXPECT_EQ(kSendTime, info.send_time_ms); | 105 EXPECT_EQ(kSendTime, info.send_time_ms); |
120 EXPECT_EQ(kSeqNo, info.sequence_number); | 106 EXPECT_EQ(kSeqNo, info.sequence_number); |
121 EXPECT_EQ(kPayloadSize, info.payload_size); | 107 EXPECT_EQ(kPayloadSize, info.payload_size); |
122 EXPECT_EQ(kPaced, info.was_paced); | |
123 } | 108 } |
124 | 109 |
125 TEST_F(SendTimeHistoryTest, AddThenRemoveOutOfOrder) { | 110 TEST_F(SendTimeHistoryTest, AddThenRemoveOutOfOrder) { |
126 std::vector<PacketInfo> sent_packets; | 111 std::vector<PacketInfo> sent_packets; |
127 std::vector<PacketInfo> received_packets; | 112 std::vector<PacketInfo> received_packets; |
128 const size_t num_items = 100; | 113 const size_t num_items = 100; |
129 const size_t kPacketSize = 400; | 114 const size_t kPacketSize = 400; |
130 const size_t kTransmissionTime = 1234; | 115 const size_t kTransmissionTime = 1234; |
131 const bool kPaced = true; | |
132 const int kProbeClusterId = 1; | 116 const int kProbeClusterId = 1; |
133 for (size_t i = 0; i < num_items; ++i) { | 117 for (size_t i = 0; i < num_items; ++i) { |
134 sent_packets.push_back(PacketInfo(0, static_cast<int64_t>(i), | 118 sent_packets.push_back(PacketInfo(0, static_cast<int64_t>(i), |
135 static_cast<uint16_t>(i), kPacketSize, | 119 static_cast<uint16_t>(i), kPacketSize, |
136 kPaced, kProbeClusterId)); | 120 kProbeClusterId)); |
137 received_packets.push_back(PacketInfo( | 121 received_packets.push_back(PacketInfo( |
138 static_cast<int64_t>(i) + kTransmissionTime, 0, | 122 static_cast<int64_t>(i) + kTransmissionTime, 0, |
139 static_cast<uint16_t>(i), kPacketSize, false, PacketInfo::kNotAProbe)); | 123 static_cast<uint16_t>(i), kPacketSize, PacketInfo::kNotAProbe)); |
140 } | 124 } |
141 for (size_t i = 0; i < num_items; ++i) { | 125 for (size_t i = 0; i < num_items; ++i) { |
142 history_.AddAndRemoveOld( | 126 history_.AddAndRemoveOld(sent_packets[i].sequence_number, |
143 sent_packets[i].sequence_number, sent_packets[i].payload_size, | 127 sent_packets[i].payload_size, |
144 sent_packets[i].was_paced, sent_packets[i].probe_cluster_id); | 128 sent_packets[i].probe_cluster_id); |
145 } | 129 } |
146 for (size_t i = 0; i < num_items; ++i) | 130 for (size_t i = 0; i < num_items; ++i) |
147 history_.OnSentPacket(sent_packets[i].sequence_number, | 131 history_.OnSentPacket(sent_packets[i].sequence_number, |
148 sent_packets[i].send_time_ms); | 132 sent_packets[i].send_time_ms); |
149 std::random_shuffle(received_packets.begin(), received_packets.end()); | 133 std::random_shuffle(received_packets.begin(), received_packets.end()); |
150 for (size_t i = 0; i < num_items; ++i) { | 134 for (size_t i = 0; i < num_items; ++i) { |
151 PacketInfo packet = received_packets[i]; | 135 PacketInfo packet = received_packets[i]; |
152 EXPECT_TRUE(history_.GetInfo(&packet, false)); | 136 EXPECT_TRUE(history_.GetInfo(&packet, false)); |
153 PacketInfo sent_packet = sent_packets[packet.sequence_number]; | 137 PacketInfo sent_packet = sent_packets[packet.sequence_number]; |
154 sent_packet.arrival_time_ms = packet.arrival_time_ms; | 138 sent_packet.arrival_time_ms = packet.arrival_time_ms; |
155 EXPECT_EQ(sent_packet, packet); | 139 EXPECT_EQ(sent_packet, packet); |
156 EXPECT_TRUE(history_.GetInfo(&packet, true)); | 140 EXPECT_TRUE(history_.GetInfo(&packet, true)); |
157 } | 141 } |
158 for (PacketInfo packet : sent_packets) | 142 for (PacketInfo packet : sent_packets) |
159 EXPECT_FALSE(history_.GetInfo(&packet, false)); | 143 EXPECT_FALSE(history_.GetInfo(&packet, false)); |
160 } | 144 } |
161 | 145 |
162 TEST_F(SendTimeHistoryTest, HistorySize) { | 146 TEST_F(SendTimeHistoryTest, HistorySize) { |
163 const int kItems = kDefaultHistoryLengthMs / 100; | 147 const int kItems = kDefaultHistoryLengthMs / 100; |
164 for (int i = 0; i < kItems; ++i) { | 148 for (int i = 0; i < kItems; ++i) { |
165 clock_.AdvanceTimeMilliseconds(100); | 149 clock_.AdvanceTimeMilliseconds(100); |
166 AddPacketWithSendTime(i, 0, false, i * 100, PacketInfo::kNotAProbe); | 150 AddPacketWithSendTime(i, 0, i * 100, PacketInfo::kNotAProbe); |
167 } | 151 } |
168 for (int i = 0; i < kItems; ++i) { | 152 for (int i = 0; i < kItems; ++i) { |
169 PacketInfo info(0, 0, static_cast<uint16_t>(i), 0, false, | 153 PacketInfo info(0, 0, static_cast<uint16_t>(i), 0, PacketInfo::kNotAProbe); |
170 PacketInfo::kNotAProbe); | |
171 EXPECT_TRUE(history_.GetInfo(&info, false)); | 154 EXPECT_TRUE(history_.GetInfo(&info, false)); |
172 EXPECT_EQ(i * 100, info.send_time_ms); | 155 EXPECT_EQ(i * 100, info.send_time_ms); |
173 } | 156 } |
174 clock_.AdvanceTimeMilliseconds(101); | 157 clock_.AdvanceTimeMilliseconds(101); |
175 AddPacketWithSendTime(kItems, 0, false, kItems * 101, PacketInfo::kNotAProbe); | 158 AddPacketWithSendTime(kItems, 0, kItems * 101, PacketInfo::kNotAProbe); |
176 PacketInfo info(0, 0, 0, 0, false, PacketInfo::kNotAProbe); | 159 PacketInfo info(0, 0, 0, 0, PacketInfo::kNotAProbe); |
177 EXPECT_FALSE(history_.GetInfo(&info, false)); | 160 EXPECT_FALSE(history_.GetInfo(&info, false)); |
178 for (int i = 1; i < (kItems + 1); ++i) { | 161 for (int i = 1; i < (kItems + 1); ++i) { |
179 PacketInfo info2(0, 0, static_cast<uint16_t>(i), 0, false, | 162 PacketInfo info2(0, 0, static_cast<uint16_t>(i), 0, PacketInfo::kNotAProbe); |
180 PacketInfo::kNotAProbe); | |
181 EXPECT_TRUE(history_.GetInfo(&info2, false)); | 163 EXPECT_TRUE(history_.GetInfo(&info2, false)); |
182 int64_t expected_time_ms = (i == kItems) ? i * 101 : i * 100; | 164 int64_t expected_time_ms = (i == kItems) ? i * 101 : i * 100; |
183 EXPECT_EQ(expected_time_ms, info2.send_time_ms); | 165 EXPECT_EQ(expected_time_ms, info2.send_time_ms); |
184 } | 166 } |
185 } | 167 } |
186 | 168 |
187 TEST_F(SendTimeHistoryTest, HistorySizeWithWraparound) { | 169 TEST_F(SendTimeHistoryTest, HistorySizeWithWraparound) { |
188 const uint16_t kMaxSeqNo = std::numeric_limits<uint16_t>::max(); | 170 const uint16_t kMaxSeqNo = std::numeric_limits<uint16_t>::max(); |
189 AddPacketWithSendTime(kMaxSeqNo - 2, 0, false, 0, PacketInfo::kNotAProbe); | 171 AddPacketWithSendTime(kMaxSeqNo - 2, 0, 0, PacketInfo::kNotAProbe); |
190 | 172 |
191 clock_.AdvanceTimeMilliseconds(100); | 173 clock_.AdvanceTimeMilliseconds(100); |
192 AddPacketWithSendTime(kMaxSeqNo - 1, 1, false, 100, PacketInfo::kNotAProbe); | 174 AddPacketWithSendTime(kMaxSeqNo - 1, 1, 100, PacketInfo::kNotAProbe); |
193 | 175 |
194 clock_.AdvanceTimeMilliseconds(100); | 176 clock_.AdvanceTimeMilliseconds(100); |
195 AddPacketWithSendTime(kMaxSeqNo, 0, false, 200, PacketInfo::kNotAProbe); | 177 AddPacketWithSendTime(kMaxSeqNo, 0, 200, PacketInfo::kNotAProbe); |
196 | 178 |
197 clock_.AdvanceTimeMilliseconds(kDefaultHistoryLengthMs - 200 + 1); | 179 clock_.AdvanceTimeMilliseconds(kDefaultHistoryLengthMs - 200 + 1); |
198 AddPacketWithSendTime(0, 0, false, kDefaultHistoryLengthMs, | 180 AddPacketWithSendTime(0, 0, kDefaultHistoryLengthMs, PacketInfo::kNotAProbe); |
199 PacketInfo::kNotAProbe); | |
200 | 181 |
201 PacketInfo info(0, static_cast<uint16_t>(kMaxSeqNo - 2)); | 182 PacketInfo info(0, static_cast<uint16_t>(kMaxSeqNo - 2)); |
202 EXPECT_FALSE(history_.GetInfo(&info, false)); | 183 EXPECT_FALSE(history_.GetInfo(&info, false)); |
203 PacketInfo info2(0, static_cast<uint16_t>(kMaxSeqNo - 1)); | 184 PacketInfo info2(0, static_cast<uint16_t>(kMaxSeqNo - 1)); |
204 EXPECT_TRUE(history_.GetInfo(&info2, false)); | 185 EXPECT_TRUE(history_.GetInfo(&info2, false)); |
205 PacketInfo info3(0, static_cast<uint16_t>(kMaxSeqNo)); | 186 PacketInfo info3(0, static_cast<uint16_t>(kMaxSeqNo)); |
206 EXPECT_TRUE(history_.GetInfo(&info3, false)); | 187 EXPECT_TRUE(history_.GetInfo(&info3, false)); |
207 PacketInfo info4(0, 0); | 188 PacketInfo info4(0, 0); |
208 EXPECT_TRUE(history_.GetInfo(&info4, false)); | 189 EXPECT_TRUE(history_.GetInfo(&info4, false)); |
209 | 190 |
210 // Create a gap (kMaxSeqNo - 1) -> 0. | 191 // Create a gap (kMaxSeqNo - 1) -> 0. |
211 PacketInfo info5(0, kMaxSeqNo); | 192 PacketInfo info5(0, kMaxSeqNo); |
212 EXPECT_TRUE(history_.GetInfo(&info5, true)); | 193 EXPECT_TRUE(history_.GetInfo(&info5, true)); |
213 | 194 |
214 clock_.AdvanceTimeMilliseconds(100); | 195 clock_.AdvanceTimeMilliseconds(100); |
215 AddPacketWithSendTime(1, 0, false, 1100, PacketInfo::kNotAProbe); | 196 AddPacketWithSendTime(1, 0, 1100, PacketInfo::kNotAProbe); |
216 | 197 |
217 PacketInfo info6(0, static_cast<uint16_t>(kMaxSeqNo - 2)); | 198 PacketInfo info6(0, static_cast<uint16_t>(kMaxSeqNo - 2)); |
218 EXPECT_FALSE(history_.GetInfo(&info6, false)); | 199 EXPECT_FALSE(history_.GetInfo(&info6, false)); |
219 PacketInfo info7(0, static_cast<uint16_t>(kMaxSeqNo - 1)); | 200 PacketInfo info7(0, static_cast<uint16_t>(kMaxSeqNo - 1)); |
220 EXPECT_FALSE(history_.GetInfo(&info7, false)); | 201 EXPECT_FALSE(history_.GetInfo(&info7, false)); |
221 PacketInfo info8(0, kMaxSeqNo); | 202 PacketInfo info8(0, kMaxSeqNo); |
222 EXPECT_FALSE(history_.GetInfo(&info8, false)); | 203 EXPECT_FALSE(history_.GetInfo(&info8, false)); |
223 PacketInfo info9(0, 0); | 204 PacketInfo info9(0, 0); |
224 EXPECT_TRUE(history_.GetInfo(&info9, false)); | 205 EXPECT_TRUE(history_.GetInfo(&info9, false)); |
225 PacketInfo info10(0, 1); | 206 PacketInfo info10(0, 1); |
226 EXPECT_TRUE(history_.GetInfo(&info10, false)); | 207 EXPECT_TRUE(history_.GetInfo(&info10, false)); |
227 } | 208 } |
228 | 209 |
229 TEST_F(SendTimeHistoryTest, InterlievedGetAndRemove) { | 210 TEST_F(SendTimeHistoryTest, InterlievedGetAndRemove) { |
230 const uint16_t kSeqNo = 1; | 211 const uint16_t kSeqNo = 1; |
231 const int64_t kTimestamp = 2; | 212 const int64_t kTimestamp = 2; |
232 PacketInfo packets[3] = {{0, kTimestamp, kSeqNo, 0, false, 0}, | 213 PacketInfo packets[3] = {{0, kTimestamp, kSeqNo, 0, 0}, |
233 {0, kTimestamp + 1, kSeqNo + 1, 0, false, 1}, | 214 {0, kTimestamp + 1, kSeqNo + 1, 0, 1}, |
234 {0, kTimestamp + 2, kSeqNo + 2, 0, false, 2}}; | 215 {0, kTimestamp + 2, kSeqNo + 2, 0, 2}}; |
235 | 216 |
236 AddPacketWithSendTime(packets[0].sequence_number, packets[0].payload_size, | 217 AddPacketWithSendTime(packets[0].sequence_number, packets[0].payload_size, |
237 packets[0].was_paced, packets[0].send_time_ms, 0); | 218 packets[0].send_time_ms, 0); |
238 AddPacketWithSendTime(packets[1].sequence_number, packets[1].payload_size, | 219 AddPacketWithSendTime(packets[1].sequence_number, packets[1].payload_size, |
239 packets[1].was_paced, packets[1].send_time_ms, 1); | 220 packets[1].send_time_ms, 1); |
240 PacketInfo info(0, 0, packets[0].sequence_number, 0, false, 0); | 221 PacketInfo info(0, 0, packets[0].sequence_number, 0, 0); |
241 EXPECT_TRUE(history_.GetInfo(&info, true)); | 222 EXPECT_TRUE(history_.GetInfo(&info, true)); |
242 EXPECT_EQ(packets[0], info); | 223 EXPECT_EQ(packets[0], info); |
243 | 224 |
244 AddPacketWithSendTime(packets[2].sequence_number, packets[2].payload_size, | 225 AddPacketWithSendTime(packets[2].sequence_number, packets[2].payload_size, |
245 packets[2].was_paced, packets[2].send_time_ms, 2); | 226 packets[2].send_time_ms, 2); |
246 | 227 |
247 PacketInfo info2(0, 0, packets[1].sequence_number, 0, false, 1); | 228 PacketInfo info2(0, 0, packets[1].sequence_number, 0, 1); |
248 EXPECT_TRUE(history_.GetInfo(&info2, true)); | 229 EXPECT_TRUE(history_.GetInfo(&info2, true)); |
249 EXPECT_EQ(packets[1], info2); | 230 EXPECT_EQ(packets[1], info2); |
250 | 231 |
251 PacketInfo info3(0, 0, packets[2].sequence_number, 0, false, 2); | 232 PacketInfo info3(0, 0, packets[2].sequence_number, 0, 2); |
252 EXPECT_TRUE(history_.GetInfo(&info3, true)); | 233 EXPECT_TRUE(history_.GetInfo(&info3, true)); |
253 EXPECT_EQ(packets[2], info3); | 234 EXPECT_EQ(packets[2], info3); |
254 } | 235 } |
255 | 236 |
256 } // namespace test | 237 } // namespace test |
257 } // namespace webrtc | 238 } // namespace webrtc |
OLD | NEW |