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 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 webrtc::SimulatedClock clock_; | 43 webrtc::SimulatedClock clock_; |
44 SendTimeHistory history_; | 44 SendTimeHistory history_; |
45 }; | 45 }; |
46 | 46 |
47 TEST_F(SendTimeHistoryTest, AddRemoveOne) { | 47 TEST_F(SendTimeHistoryTest, AddRemoveOne) { |
48 const uint16_t kSeqNo = 10; | 48 const uint16_t kSeqNo = 10; |
49 // TODO(philipel): Fix PacedPacketInfo constructor? | 49 // TODO(philipel): Fix PacedPacketInfo constructor? |
50 const PacedPacketInfo kPacingInfo(0, 5, 1200); | 50 const PacedPacketInfo kPacingInfo(0, 5, 1200); |
51 const PacketInfo kSentPacket(0, 1, kSeqNo, 1, kPacingInfo); | 51 const PacketFeedback kSentPacket(0, 1, kSeqNo, 1, kPacingInfo); |
52 AddPacketWithSendTime(kSeqNo, 1, 1, kPacingInfo); | 52 AddPacketWithSendTime(kSeqNo, 1, 1, kPacingInfo); |
53 | 53 |
54 PacketInfo received_packet(0, 0, kSeqNo, 0, kPacingInfo); | 54 PacketFeedback received_packet(0, 0, kSeqNo, 0, kPacingInfo); |
55 EXPECT_TRUE(history_.GetInfo(&received_packet, false)); | 55 EXPECT_TRUE(history_.GetFeedback(&received_packet, false)); |
56 EXPECT_EQ(kSentPacket, received_packet); | 56 EXPECT_EQ(kSentPacket, received_packet); |
57 | 57 |
58 PacketInfo received_packet2(0, 0, kSeqNo, 0, kPacingInfo); | 58 PacketFeedback received_packet2(0, 0, kSeqNo, 0, kPacingInfo); |
59 EXPECT_TRUE(history_.GetInfo(&received_packet2, true)); | 59 EXPECT_TRUE(history_.GetFeedback(&received_packet2, true)); |
60 EXPECT_EQ(kSentPacket, received_packet2); | 60 EXPECT_EQ(kSentPacket, received_packet2); |
61 | 61 |
62 PacketInfo received_packet3(0, 0, kSeqNo, 0, kPacingInfo); | 62 PacketFeedback received_packet3(0, 0, kSeqNo, 0, kPacingInfo); |
63 EXPECT_FALSE(history_.GetInfo(&received_packet3, true)); | 63 EXPECT_FALSE(history_.GetFeedback(&received_packet3, true)); |
64 } | 64 } |
65 | 65 |
66 TEST_F(SendTimeHistoryTest, PopulatesExpectedFields) { | 66 TEST_F(SendTimeHistoryTest, PopulatesExpectedFields) { |
67 const uint16_t kSeqNo = 10; | 67 const uint16_t kSeqNo = 10; |
68 const int64_t kSendTime = 1000; | 68 const int64_t kSendTime = 1000; |
69 const int64_t kReceiveTime = 2000; | 69 const int64_t kReceiveTime = 2000; |
70 const size_t kPayloadSize = 42; | 70 const size_t kPayloadSize = 42; |
71 const PacedPacketInfo kPacingInfo(3, 10, 1212); | 71 const PacedPacketInfo kPacingInfo(3, 10, 1212); |
72 | 72 |
73 AddPacketWithSendTime(kSeqNo, kPayloadSize, kSendTime, kPacingInfo); | 73 AddPacketWithSendTime(kSeqNo, kPayloadSize, kSendTime, kPacingInfo); |
74 | 74 |
75 PacketInfo info(kReceiveTime, kSeqNo); | 75 PacketFeedback packet_feedback(kReceiveTime, kSeqNo); |
76 EXPECT_TRUE(history_.GetInfo(&info, true)); | 76 EXPECT_TRUE(history_.GetFeedback(&packet_feedback, true)); |
77 EXPECT_EQ(kReceiveTime, info.arrival_time_ms); | 77 EXPECT_EQ(kReceiveTime, packet_feedback.arrival_time_ms); |
78 EXPECT_EQ(kSendTime, info.send_time_ms); | 78 EXPECT_EQ(kSendTime, packet_feedback.send_time_ms); |
79 EXPECT_EQ(kSeqNo, info.sequence_number); | 79 EXPECT_EQ(kSeqNo, packet_feedback.sequence_number); |
80 EXPECT_EQ(kPayloadSize, info.payload_size); | 80 EXPECT_EQ(kPayloadSize, packet_feedback.payload_size); |
81 EXPECT_EQ(kPacingInfo, info.pacing_info); | 81 EXPECT_EQ(kPacingInfo, packet_feedback.pacing_info); |
82 } | 82 } |
83 | 83 |
84 TEST_F(SendTimeHistoryTest, AddThenRemoveOutOfOrder) { | 84 TEST_F(SendTimeHistoryTest, AddThenRemoveOutOfOrder) { |
85 std::vector<PacketInfo> sent_packets; | 85 std::vector<PacketFeedback> sent_packets; |
86 std::vector<PacketInfo> received_packets; | 86 std::vector<PacketFeedback> received_packets; |
87 const size_t num_items = 100; | 87 const size_t num_items = 100; |
88 const size_t kPacketSize = 400; | 88 const size_t kPacketSize = 400; |
89 const size_t kTransmissionTime = 1234; | 89 const size_t kTransmissionTime = 1234; |
90 const PacedPacketInfo kPacingInfo(1, 2, 200); | 90 const PacedPacketInfo kPacingInfo(1, 2, 200); |
91 for (size_t i = 0; i < num_items; ++i) { | 91 for (size_t i = 0; i < num_items; ++i) { |
92 sent_packets.push_back(PacketInfo(0, static_cast<int64_t>(i), | 92 sent_packets.push_back(PacketFeedback(0, static_cast<int64_t>(i), |
93 static_cast<uint16_t>(i), kPacketSize, | 93 static_cast<uint16_t>(i), kPacketSize, |
94 kPacingInfo)); | 94 kPacingInfo)); |
95 received_packets.push_back( | 95 received_packets.push_back(PacketFeedback( |
96 PacketInfo(static_cast<int64_t>(i) + kTransmissionTime, 0, | 96 static_cast<int64_t>(i) + kTransmissionTime, 0, |
97 static_cast<uint16_t>(i), kPacketSize, PacedPacketInfo())); | 97 static_cast<uint16_t>(i), kPacketSize, PacedPacketInfo())); |
98 } | 98 } |
99 for (size_t i = 0; i < num_items; ++i) { | 99 for (size_t i = 0; i < num_items; ++i) { |
100 history_.AddAndRemoveOld(sent_packets[i].sequence_number, | 100 history_.AddAndRemoveOld(sent_packets[i].sequence_number, |
101 sent_packets[i].payload_size, | 101 sent_packets[i].payload_size, |
102 PacedPacketInfo(1, 2, 200)); | 102 PacedPacketInfo(1, 2, 200)); |
103 } | 103 } |
104 for (size_t i = 0; i < num_items; ++i) | 104 for (size_t i = 0; i < num_items; ++i) |
105 history_.OnSentPacket(sent_packets[i].sequence_number, | 105 history_.OnSentPacket(sent_packets[i].sequence_number, |
106 sent_packets[i].send_time_ms); | 106 sent_packets[i].send_time_ms); |
107 std::random_shuffle(received_packets.begin(), received_packets.end()); | 107 std::random_shuffle(received_packets.begin(), received_packets.end()); |
108 for (size_t i = 0; i < num_items; ++i) { | 108 for (size_t i = 0; i < num_items; ++i) { |
109 PacketInfo packet = received_packets[i]; | 109 PacketFeedback packet = received_packets[i]; |
110 EXPECT_TRUE(history_.GetInfo(&packet, false)); | 110 EXPECT_TRUE(history_.GetFeedback(&packet, false)); |
111 PacketInfo sent_packet = sent_packets[packet.sequence_number]; | 111 PacketFeedback sent_packet = sent_packets[packet.sequence_number]; |
112 sent_packet.arrival_time_ms = packet.arrival_time_ms; | 112 sent_packet.arrival_time_ms = packet.arrival_time_ms; |
113 EXPECT_EQ(sent_packet, packet); | 113 EXPECT_EQ(sent_packet, packet); |
114 EXPECT_TRUE(history_.GetInfo(&packet, true)); | 114 EXPECT_TRUE(history_.GetFeedback(&packet, true)); |
115 } | 115 } |
116 for (PacketInfo packet : sent_packets) | 116 for (PacketFeedback packet : sent_packets) |
117 EXPECT_FALSE(history_.GetInfo(&packet, false)); | 117 EXPECT_FALSE(history_.GetFeedback(&packet, false)); |
118 } | 118 } |
119 | 119 |
120 TEST_F(SendTimeHistoryTest, HistorySize) { | 120 TEST_F(SendTimeHistoryTest, HistorySize) { |
121 const int kItems = kDefaultHistoryLengthMs / 100; | 121 const int kItems = kDefaultHistoryLengthMs / 100; |
122 for (int i = 0; i < kItems; ++i) { | 122 for (int i = 0; i < kItems; ++i) { |
123 clock_.AdvanceTimeMilliseconds(100); | 123 clock_.AdvanceTimeMilliseconds(100); |
124 AddPacketWithSendTime(i, 0, i * 100, PacedPacketInfo()); | 124 AddPacketWithSendTime(i, 0, i * 100, PacedPacketInfo()); |
125 } | 125 } |
126 for (int i = 0; i < kItems; ++i) { | 126 for (int i = 0; i < kItems; ++i) { |
127 PacketInfo info(0, 0, static_cast<uint16_t>(i), 0, PacedPacketInfo()); | 127 PacketFeedback packet(0, 0, static_cast<uint16_t>(i), 0, PacedPacketInfo()); |
128 EXPECT_TRUE(history_.GetInfo(&info, false)); | 128 EXPECT_TRUE(history_.GetFeedback(&packet, false)); |
129 EXPECT_EQ(i * 100, info.send_time_ms); | 129 EXPECT_EQ(i * 100, packet.send_time_ms); |
130 } | 130 } |
131 clock_.AdvanceTimeMilliseconds(101); | 131 clock_.AdvanceTimeMilliseconds(101); |
132 AddPacketWithSendTime(kItems, 0, kItems * 101, PacedPacketInfo()); | 132 AddPacketWithSendTime(kItems, 0, kItems * 101, PacedPacketInfo()); |
133 PacketInfo info(0, 0, 0, 0, PacedPacketInfo()); | 133 PacketFeedback packet(0, 0, 0, 0, PacedPacketInfo()); |
134 EXPECT_FALSE(history_.GetInfo(&info, false)); | 134 EXPECT_FALSE(history_.GetFeedback(&packet, false)); |
135 for (int i = 1; i < (kItems + 1); ++i) { | 135 for (int i = 1; i < (kItems + 1); ++i) { |
136 PacketInfo info2(0, 0, static_cast<uint16_t>(i), 0, PacedPacketInfo()); | 136 PacketFeedback packet2(0, 0, static_cast<uint16_t>(i), 0, |
137 EXPECT_TRUE(history_.GetInfo(&info2, false)); | 137 PacedPacketInfo()); |
| 138 EXPECT_TRUE(history_.GetFeedback(&packet2, false)); |
138 int64_t expected_time_ms = (i == kItems) ? i * 101 : i * 100; | 139 int64_t expected_time_ms = (i == kItems) ? i * 101 : i * 100; |
139 EXPECT_EQ(expected_time_ms, info2.send_time_ms); | 140 EXPECT_EQ(expected_time_ms, packet2.send_time_ms); |
140 } | 141 } |
141 } | 142 } |
142 | 143 |
143 TEST_F(SendTimeHistoryTest, HistorySizeWithWraparound) { | 144 TEST_F(SendTimeHistoryTest, HistorySizeWithWraparound) { |
144 const uint16_t kMaxSeqNo = std::numeric_limits<uint16_t>::max(); | 145 const uint16_t kMaxSeqNo = std::numeric_limits<uint16_t>::max(); |
145 AddPacketWithSendTime(kMaxSeqNo - 2, 0, 0, PacedPacketInfo()); | 146 AddPacketWithSendTime(kMaxSeqNo - 2, 0, 0, PacedPacketInfo()); |
146 | 147 |
147 clock_.AdvanceTimeMilliseconds(100); | 148 clock_.AdvanceTimeMilliseconds(100); |
148 AddPacketWithSendTime(kMaxSeqNo - 1, 1, 100, PacedPacketInfo()); | 149 AddPacketWithSendTime(kMaxSeqNo - 1, 1, 100, PacedPacketInfo()); |
149 | 150 |
150 clock_.AdvanceTimeMilliseconds(100); | 151 clock_.AdvanceTimeMilliseconds(100); |
151 AddPacketWithSendTime(kMaxSeqNo, 0, 200, PacedPacketInfo()); | 152 AddPacketWithSendTime(kMaxSeqNo, 0, 200, PacedPacketInfo()); |
152 | 153 |
153 clock_.AdvanceTimeMilliseconds(kDefaultHistoryLengthMs - 200 + 1); | 154 clock_.AdvanceTimeMilliseconds(kDefaultHistoryLengthMs - 200 + 1); |
154 AddPacketWithSendTime(0, 0, kDefaultHistoryLengthMs, PacedPacketInfo()); | 155 AddPacketWithSendTime(0, 0, kDefaultHistoryLengthMs, PacedPacketInfo()); |
155 | 156 |
156 PacketInfo info(0, static_cast<uint16_t>(kMaxSeqNo - 2)); | 157 PacketFeedback packet(0, static_cast<uint16_t>(kMaxSeqNo - 2)); |
157 EXPECT_FALSE(history_.GetInfo(&info, false)); | 158 EXPECT_FALSE(history_.GetFeedback(&packet, false)); |
158 PacketInfo info2(0, static_cast<uint16_t>(kMaxSeqNo - 1)); | 159 PacketFeedback packet2(0, static_cast<uint16_t>(kMaxSeqNo - 1)); |
159 EXPECT_TRUE(history_.GetInfo(&info2, false)); | 160 EXPECT_TRUE(history_.GetFeedback(&packet2, false)); |
160 PacketInfo info3(0, static_cast<uint16_t>(kMaxSeqNo)); | 161 PacketFeedback packet3(0, static_cast<uint16_t>(kMaxSeqNo)); |
161 EXPECT_TRUE(history_.GetInfo(&info3, false)); | 162 EXPECT_TRUE(history_.GetFeedback(&packet3, false)); |
162 PacketInfo info4(0, 0); | 163 PacketFeedback packet4(0, 0); |
163 EXPECT_TRUE(history_.GetInfo(&info4, false)); | 164 EXPECT_TRUE(history_.GetFeedback(&packet4, false)); |
164 | 165 |
165 // Create a gap (kMaxSeqNo - 1) -> 0. | 166 // Create a gap (kMaxSeqNo - 1) -> 0. |
166 PacketInfo info5(0, kMaxSeqNo); | 167 PacketFeedback packet5(0, kMaxSeqNo); |
167 EXPECT_TRUE(history_.GetInfo(&info5, true)); | 168 EXPECT_TRUE(history_.GetFeedback(&packet5, true)); |
168 | 169 |
169 clock_.AdvanceTimeMilliseconds(100); | 170 clock_.AdvanceTimeMilliseconds(100); |
170 AddPacketWithSendTime(1, 0, 1100, PacedPacketInfo()); | 171 AddPacketWithSendTime(1, 0, 1100, PacedPacketInfo()); |
171 | 172 |
172 PacketInfo info6(0, static_cast<uint16_t>(kMaxSeqNo - 2)); | 173 PacketFeedback packet6(0, static_cast<uint16_t>(kMaxSeqNo - 2)); |
173 EXPECT_FALSE(history_.GetInfo(&info6, false)); | 174 EXPECT_FALSE(history_.GetFeedback(&packet6, false)); |
174 PacketInfo info7(0, static_cast<uint16_t>(kMaxSeqNo - 1)); | 175 PacketFeedback packet7(0, static_cast<uint16_t>(kMaxSeqNo - 1)); |
175 EXPECT_FALSE(history_.GetInfo(&info7, false)); | 176 EXPECT_FALSE(history_.GetFeedback(&packet7, false)); |
176 PacketInfo info8(0, kMaxSeqNo); | 177 PacketFeedback packet8(0, kMaxSeqNo); |
177 EXPECT_FALSE(history_.GetInfo(&info8, false)); | 178 EXPECT_FALSE(history_.GetFeedback(&packet8, false)); |
178 PacketInfo info9(0, 0); | 179 PacketFeedback packet9(0, 0); |
179 EXPECT_TRUE(history_.GetInfo(&info9, false)); | 180 EXPECT_TRUE(history_.GetFeedback(&packet9, false)); |
180 PacketInfo info10(0, 1); | 181 PacketFeedback packet10(0, 1); |
181 EXPECT_TRUE(history_.GetInfo(&info10, false)); | 182 EXPECT_TRUE(history_.GetFeedback(&packet10, false)); |
182 } | 183 } |
183 | 184 |
184 TEST_F(SendTimeHistoryTest, InterlievedGetAndRemove) { | 185 TEST_F(SendTimeHistoryTest, InterlievedGetAndRemove) { |
185 const uint16_t kSeqNo = 1; | 186 const uint16_t kSeqNo = 1; |
186 const int64_t kTimestamp = 2; | 187 const int64_t kTimestamp = 2; |
187 const PacedPacketInfo kPacingInfo1(1, 1, 100); | 188 const PacedPacketInfo kPacingInfo1(1, 1, 100); |
188 const PacedPacketInfo kPacingInfo2(2, 2, 200); | 189 const PacedPacketInfo kPacingInfo2(2, 2, 200); |
189 const PacedPacketInfo kPacingInfo3(3, 3, 300); | 190 const PacedPacketInfo kPacingInfo3(3, 3, 300); |
190 PacketInfo packets[3] = {{0, kTimestamp, kSeqNo, 0, kPacingInfo1}, | 191 PacketFeedback packets[3] = { |
191 {0, kTimestamp + 1, kSeqNo + 1, 0, kPacingInfo2}, | 192 {0, kTimestamp, kSeqNo, 0, kPacingInfo1}, |
192 {0, kTimestamp + 2, kSeqNo + 2, 0, kPacingInfo3}}; | 193 {0, kTimestamp + 1, kSeqNo + 1, 0, kPacingInfo2}, |
| 194 {0, kTimestamp + 2, kSeqNo + 2, 0, kPacingInfo3}}; |
193 | 195 |
194 AddPacketWithSendTime(packets[0].sequence_number, packets[0].payload_size, | 196 AddPacketWithSendTime(packets[0].sequence_number, packets[0].payload_size, |
195 packets[0].send_time_ms, packets[0].pacing_info); | 197 packets[0].send_time_ms, packets[0].pacing_info); |
196 AddPacketWithSendTime(packets[1].sequence_number, packets[1].payload_size, | 198 AddPacketWithSendTime(packets[1].sequence_number, packets[1].payload_size, |
197 packets[1].send_time_ms, packets[1].pacing_info); | 199 packets[1].send_time_ms, packets[1].pacing_info); |
198 PacketInfo info(0, 0, packets[0].sequence_number, 0, PacedPacketInfo()); | 200 PacketFeedback packet(0, 0, packets[0].sequence_number, 0, PacedPacketInfo()); |
199 EXPECT_TRUE(history_.GetInfo(&info, true)); | 201 EXPECT_TRUE(history_.GetFeedback(&packet, true)); |
200 EXPECT_EQ(packets[0], info); | 202 EXPECT_EQ(packets[0], packet); |
201 | 203 |
202 AddPacketWithSendTime(packets[2].sequence_number, packets[2].payload_size, | 204 AddPacketWithSendTime(packets[2].sequence_number, packets[2].payload_size, |
203 packets[2].send_time_ms, packets[2].pacing_info); | 205 packets[2].send_time_ms, packets[2].pacing_info); |
204 | 206 |
205 PacketInfo info2(0, 0, packets[1].sequence_number, 0, kPacingInfo1); | 207 PacketFeedback packet2(0, 0, packets[1].sequence_number, 0, kPacingInfo1); |
206 EXPECT_TRUE(history_.GetInfo(&info2, true)); | 208 EXPECT_TRUE(history_.GetFeedback(&packet2, true)); |
207 EXPECT_EQ(packets[1], info2); | 209 EXPECT_EQ(packets[1], packet2); |
208 | 210 |
209 PacketInfo info3(0, 0, packets[2].sequence_number, 0, kPacingInfo2); | 211 PacketFeedback packet3(0, 0, packets[2].sequence_number, 0, kPacingInfo2); |
210 EXPECT_TRUE(history_.GetInfo(&info3, true)); | 212 EXPECT_TRUE(history_.GetFeedback(&packet3, true)); |
211 EXPECT_EQ(packets[2], info3); | 213 EXPECT_EQ(packets[2], packet3); |
212 } | 214 } |
213 | 215 |
214 } // namespace test | 216 } // namespace test |
215 } // namespace webrtc | 217 } // namespace webrtc |
OLD | NEW |