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

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

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

Powered by Google App Engine
This is Rietveld 408576698