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

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

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

Powered by Google App Engine
This is Rietveld 408576698