Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(276)

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/send_time_history_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698