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

Side by Side Diff: media/cast/transport/pacing/paced_sender_unittest.cc

Issue 248493002: Cast: Deduplicate packets in paced sender and always send older packets first (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-upping to trick build system Created 6 years, 8 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
« no previous file with comments | « media/cast/transport/pacing/paced_sender.cc ('k') | media/cast/transport/rtcp/rtcp_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/big_endian.h" 7 #include "base/big_endian.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "media/cast/logging/simple_event_subscriber.h" 9 #include "media/cast/logging/simple_event_subscriber.h"
10 #include "media/cast/test/fake_single_thread_task_runner.h" 10 #include "media/cast/test/fake_single_thread_task_runner.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 virtual ~PacedSenderTest() { 67 virtual ~PacedSenderTest() {
68 logging_.RemoveRawEventSubscriber(&subscriber_); 68 logging_.RemoveRawEventSubscriber(&subscriber_);
69 } 69 }
70 70
71 static void UpdateCastTransportStatus(transport::CastTransportStatus status) { 71 static void UpdateCastTransportStatus(transport::CastTransportStatus status) {
72 NOTREACHED(); 72 NOTREACHED();
73 } 73 }
74 74
75 PacketList CreatePacketList(size_t packet_size, 75 SendPacketVector CreateSendPacketVector(size_t packet_size,
76 int num_of_packets_in_frame, 76 int num_of_packets_in_frame,
77 bool audio) { 77 bool audio) {
78 DCHECK_GE(packet_size, 12u); 78 DCHECK_GE(packet_size, 12u);
79 PacketList packets; 79 SendPacketVector packets;
80 base::TimeTicks frame_tick = testing_clock_.NowTicks();
81 // Advance the clock so that we don't get the same frame_tick
82 // next time this function is called.
83 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(1));
80 for (int i = 0; i < num_of_packets_in_frame; ++i) { 84 for (int i = 0; i < num_of_packets_in_frame; ++i) {
85 PacketKey key = PacedPacketSender::MakePacketKey(
86 frame_tick,
87 audio ? kAudioSsrc : kVideoSsrc, // ssrc
88 i);
89
81 PacketRef packet(new base::RefCountedData<Packet>); 90 PacketRef packet(new base::RefCountedData<Packet>);
82 packet->data.resize(packet_size, kValue); 91 packet->data.resize(packet_size, kValue);
83 // Write ssrc to packet so that it can be recognized as a 92 // Write ssrc to packet so that it can be recognized as a
84 // "video frame" for logging purposes. 93 // "video frame" for logging purposes.
85 base::BigEndianWriter writer( 94 base::BigEndianWriter writer(
86 reinterpret_cast<char*>(&packet->data[8]), 4); 95 reinterpret_cast<char*>(&packet->data[8]), 4);
87 bool success = writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc); 96 bool success = writer.WriteU32(audio ? kAudioSsrc : kVideoSsrc);
88 DCHECK(success); 97 DCHECK(success);
89 packets.push_back(packet); 98 packets.push_back(std::make_pair(key, packet));
90 } 99 }
91 return packets; 100 return packets;
92 } 101 }
93 102
94 // Use this function to drain the packet list in PacedSender without having 103 // Use this function to drain the packet list in PacedSender without having
95 // to test the pacing implementation details. 104 // to test the pacing implementation details.
96 bool RunUntilEmpty(int max_tries) { 105 bool RunUntilEmpty(int max_tries) {
97 for (int i = 0; i < max_tries; i++) { 106 for (int i = 0; i < max_tries; i++) {
98 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10)); 107 testing_clock_.Advance(base::TimeDelta::FromMilliseconds(10));
99 task_runner_->RunTasks(); 108 task_runner_->RunTasks();
(...skipping 10 matching lines...) Expand all
110 base::SimpleTestTickClock testing_clock_; 119 base::SimpleTestTickClock testing_clock_;
111 TestPacketSender mock_transport_; 120 TestPacketSender mock_transport_;
112 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; 121 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_;
113 scoped_ptr<PacedSender> paced_sender_; 122 scoped_ptr<PacedSender> paced_sender_;
114 123
115 DISALLOW_COPY_AND_ASSIGN(PacedSenderTest); 124 DISALLOW_COPY_AND_ASSIGN(PacedSenderTest);
116 }; 125 };
117 126
118 TEST_F(PacedSenderTest, PassThroughRtcp) { 127 TEST_F(PacedSenderTest, PassThroughRtcp) {
119 mock_transport_.AddExpectedSize(kSize1, 2); 128 mock_transport_.AddExpectedSize(kSize1, 2);
120 PacketList packets = CreatePacketList(kSize1, 1, true); 129 SendPacketVector packets = CreateSendPacketVector(kSize1, 1, true);
121 130
122 EXPECT_TRUE(paced_sender_->SendPackets(packets)); 131 EXPECT_TRUE(paced_sender_->SendPackets(packets));
123 EXPECT_TRUE(paced_sender_->ResendPackets(packets)); 132 EXPECT_TRUE(paced_sender_->ResendPackets(packets));
124 133
125 mock_transport_.AddExpectedSize(kSize2, 1); 134 mock_transport_.AddExpectedSize(kSize2, 1);
126 Packet tmp(kSize2, kValue); 135 Packet tmp(kSize2, kValue);
127 EXPECT_TRUE(paced_sender_->SendRtcpPacket( 136 EXPECT_TRUE(paced_sender_->SendRtcpPacket(
137 1,
128 new base::RefCountedData<Packet>(tmp))); 138 new base::RefCountedData<Packet>(tmp)));
129 } 139 }
130 140
131 TEST_F(PacedSenderTest, BasicPace) { 141 TEST_F(PacedSenderTest, BasicPace) {
132 int num_of_packets = 27; 142 int num_of_packets = 27;
133 PacketList packets = CreatePacketList(kSize1, num_of_packets, false); 143 SendPacketVector packets = CreateSendPacketVector(kSize1,
144 num_of_packets,
145 false);
134 146
135 mock_transport_.AddExpectedSize(kSize1, 10); 147 mock_transport_.AddExpectedSize(kSize1, 10);
136 EXPECT_TRUE(paced_sender_->SendPackets(packets)); 148 EXPECT_TRUE(paced_sender_->SendPackets(packets));
137 149
138 // Check that we get the next burst. 150 // Check that we get the next burst.
139 mock_transport_.AddExpectedSize(kSize1, 10); 151 mock_transport_.AddExpectedSize(kSize1, 10);
140 152
141 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10); 153 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10);
142 testing_clock_.Advance(timeout); 154 testing_clock_.Advance(timeout);
143 task_runner_->RunTasks(); 155 task_runner_->RunTasks();
(...skipping 25 matching lines...) Expand all
169 } 181 }
170 EXPECT_EQ(num_of_packets, sent_to_network_event_count); 182 EXPECT_EQ(num_of_packets, sent_to_network_event_count);
171 } 183 }
172 184
173 TEST_F(PacedSenderTest, PaceWithNack) { 185 TEST_F(PacedSenderTest, PaceWithNack) {
174 // Testing what happen when we get multiple NACK requests for a fully lost 186 // Testing what happen when we get multiple NACK requests for a fully lost
175 // frames just as we sent the first packets in a frame. 187 // frames just as we sent the first packets in a frame.
176 int num_of_packets_in_frame = 12; 188 int num_of_packets_in_frame = 12;
177 int num_of_packets_in_nack = 12; 189 int num_of_packets_in_nack = 12;
178 190
179 PacketList first_frame_packets = 191 SendPacketVector nack_packets =
180 CreatePacketList(kSize1, num_of_packets_in_frame, false); 192 CreateSendPacketVector(kNackSize, num_of_packets_in_nack, false);
181 193
182 PacketList second_frame_packets = 194 SendPacketVector first_frame_packets =
183 CreatePacketList(kSize2, num_of_packets_in_frame, true); 195 CreateSendPacketVector(kSize1, num_of_packets_in_frame, false);
184 196
185 PacketList nack_packets = 197 SendPacketVector second_frame_packets =
186 CreatePacketList(kNackSize, num_of_packets_in_nack, false); 198 CreateSendPacketVector(kSize2, num_of_packets_in_frame, true);
187 199
188 // Check that the first burst of the frame go out on the wire. 200 // Check that the first burst of the frame go out on the wire.
189 mock_transport_.AddExpectedSize(kSize1, 10); 201 mock_transport_.AddExpectedSize(kSize1, 10);
190 EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets)); 202 EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets));
191 203
192 // Add first NACK request. 204 // Add first NACK request.
193 EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets)); 205 EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets));
194 206
195 // Check that we get the first NACK burst. 207 // Check that we get the first NACK burst.
196 mock_transport_.AddExpectedSize(kNackSize, 10); 208 mock_transport_.AddExpectedSize(kNackSize, 10);
197 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10); 209 base::TimeDelta timeout = base::TimeDelta::FromMilliseconds(10);
198 testing_clock_.Advance(timeout); 210 testing_clock_.Advance(timeout);
199 task_runner_->RunTasks(); 211 task_runner_->RunTasks();
200 212
201 // Add second NACK request. 213 // Add second NACK request.
202 EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets)); 214 EXPECT_TRUE(paced_sender_->ResendPackets(nack_packets));
203 215
204 // Check that we get the next NACK burst. 216 // Check that we get the next NACK burst.
205 mock_transport_.AddExpectedSize(kNackSize, 10); 217 mock_transport_.AddExpectedSize(kNackSize, 10);
206 testing_clock_.Advance(timeout); 218 testing_clock_.Advance(timeout);
207 task_runner_->RunTasks(); 219 task_runner_->RunTasks();
208 220
209 // End of NACK plus two packets from the oldest frame. 221 // End of NACK plus two packets from the oldest frame.
210 mock_transport_.AddExpectedSize(kNackSize, 4); 222 // Note that two of the NACKs have been de-duped.
223 mock_transport_.AddExpectedSize(kNackSize, 2);
211 mock_transport_.AddExpectedSize(kSize1, 2); 224 mock_transport_.AddExpectedSize(kSize1, 2);
212 testing_clock_.Advance(timeout); 225 testing_clock_.Advance(timeout);
213 task_runner_->RunTasks(); 226 task_runner_->RunTasks();
214 227
215 // Add second frame. 228 // Add second frame.
216 // Make sure we don't delay the second frame due to the previous packets. 229 // Make sure we don't delay the second frame due to the previous packets.
217 mock_transport_.AddExpectedSize(kSize2, 10); 230 mock_transport_.AddExpectedSize(kSize2, 10);
218 EXPECT_TRUE(paced_sender_->SendPackets(second_frame_packets)); 231 EXPECT_TRUE(paced_sender_->SendPackets(second_frame_packets));
219 232
220 // Last packets of frame 2. 233 // Last packets of frame 2.
221 mock_transport_.AddExpectedSize(kSize2, 2); 234 mock_transport_.AddExpectedSize(kSize2, 2);
222 testing_clock_.Advance(timeout); 235 testing_clock_.Advance(timeout);
223 task_runner_->RunTasks(); 236 task_runner_->RunTasks();
224 237
225 // No more packets. 238 // No more packets.
226 EXPECT_TRUE(RunUntilEmpty(5)); 239 EXPECT_TRUE(RunUntilEmpty(5));
227 240
228 std::vector<PacketEvent> packet_events; 241 std::vector<PacketEvent> packet_events;
229 subscriber_.GetPacketEventsAndReset(&packet_events); 242 subscriber_.GetPacketEventsAndReset(&packet_events);
230 int expected_video_network_event_count = num_of_packets_in_frame; 243 int expected_video_network_event_count = num_of_packets_in_frame;
231 int expected_video_retransmitted_event_count = 2 * num_of_packets_in_nack; 244 int expected_video_retransmitted_event_count = 2 * num_of_packets_in_nack;
245 expected_video_retransmitted_event_count -= 2; // 2 packets deduped
232 int expected_audio_network_event_count = num_of_packets_in_frame; 246 int expected_audio_network_event_count = num_of_packets_in_frame;
233 EXPECT_EQ(expected_video_network_event_count + 247 EXPECT_EQ(expected_video_network_event_count +
234 expected_video_retransmitted_event_count + 248 expected_video_retransmitted_event_count +
235 expected_audio_network_event_count, 249 expected_audio_network_event_count,
236 static_cast<int>(packet_events.size())); 250 static_cast<int>(packet_events.size()));
237 int audio_network_event_count = 0; 251 int audio_network_event_count = 0;
238 int video_network_event_count = 0; 252 int video_network_event_count = 0;
239 int video_retransmitted_event_count = 0; 253 int video_retransmitted_event_count = 0;
240 for (std::vector<PacketEvent>::iterator it = packet_events.begin(); 254 for (std::vector<PacketEvent>::iterator it = packet_events.begin();
241 it != packet_events.end(); 255 it != packet_events.end();
242 ++it) { 256 ++it) {
243 if (it->type == kVideoPacketSentToNetwork) 257 if (it->type == kVideoPacketSentToNetwork)
244 video_network_event_count++; 258 video_network_event_count++;
245 else if (it->type == kVideoPacketRetransmitted) 259 else if (it->type == kVideoPacketRetransmitted)
246 video_retransmitted_event_count++; 260 video_retransmitted_event_count++;
247 else if (it->type == kAudioPacketSentToNetwork) 261 else if (it->type == kAudioPacketSentToNetwork)
248 audio_network_event_count++; 262 audio_network_event_count++;
249 else 263 else
250 FAIL() << "Got unexpected event type " << CastLoggingToString(it->type); 264 FAIL() << "Got unexpected event type " << CastLoggingToString(it->type);
251 } 265 }
252 EXPECT_EQ(expected_audio_network_event_count, audio_network_event_count); 266 EXPECT_EQ(expected_audio_network_event_count, audio_network_event_count);
253 EXPECT_EQ(expected_video_network_event_count, video_network_event_count); 267 EXPECT_EQ(expected_video_network_event_count, video_network_event_count);
254 EXPECT_EQ(expected_video_retransmitted_event_count, 268 EXPECT_EQ(expected_video_retransmitted_event_count,
255 video_retransmitted_event_count); 269 video_retransmitted_event_count);
256 } 270 }
257 271
258 TEST_F(PacedSenderTest, PaceWith60fps) { 272 TEST_F(PacedSenderTest, PaceWith60fps) {
259 // Testing what happen when we get multiple NACK requests for a fully lost 273 // Testing what happen when we get multiple NACK requests for a fully lost
260 // frames just as we sent the first packets in a frame. 274 // frames just as we sent the first packets in a frame.
261 int num_of_packets_in_frame = 17; 275 int num_of_packets_in_frame = 17;
262 276
263 PacketList first_frame_packets = 277 SendPacketVector first_frame_packets =
264 CreatePacketList(kSize1, num_of_packets_in_frame, false); 278 CreateSendPacketVector(kSize1, num_of_packets_in_frame, false);
265 279
266 PacketList second_frame_packets = 280 SendPacketVector second_frame_packets =
267 CreatePacketList(kSize2, num_of_packets_in_frame, false); 281 CreateSendPacketVector(kSize2, num_of_packets_in_frame, false);
268 282
269 PacketList third_frame_packets = 283 SendPacketVector third_frame_packets =
270 CreatePacketList(kSize3, num_of_packets_in_frame, false); 284 CreateSendPacketVector(kSize3, num_of_packets_in_frame, false);
271 285
272 PacketList fourth_frame_packets = 286 SendPacketVector fourth_frame_packets =
273 CreatePacketList(kSize4, num_of_packets_in_frame, false); 287 CreateSendPacketVector(kSize4, num_of_packets_in_frame, false);
274 288
275 base::TimeDelta timeout_10ms = base::TimeDelta::FromMilliseconds(10); 289 base::TimeDelta timeout_10ms = base::TimeDelta::FromMilliseconds(10);
276 290
277 // Check that the first burst of the frame go out on the wire. 291 // Check that the first burst of the frame go out on the wire.
278 mock_transport_.AddExpectedSize(kSize1, 10); 292 mock_transport_.AddExpectedSize(kSize1, 10);
279 EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets)); 293 EXPECT_TRUE(paced_sender_->SendPackets(first_frame_packets));
280 294
281 mock_transport_.AddExpectedSize(kSize1, 7); 295 mock_transport_.AddExpectedSize(kSize1, 7);
282 testing_clock_.Advance(timeout_10ms); 296 testing_clock_.Advance(timeout_10ms);
283 task_runner_->RunTasks(); 297 task_runner_->RunTasks();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 testing_clock_.Advance(timeout_10ms); 339 testing_clock_.Advance(timeout_10ms);
326 task_runner_->RunTasks(); 340 task_runner_->RunTasks();
327 341
328 // No more packets. 342 // No more packets.
329 EXPECT_TRUE(RunUntilEmpty(5)); 343 EXPECT_TRUE(RunUntilEmpty(5));
330 } 344 }
331 345
332 } // namespace transport 346 } // namespace transport
333 } // namespace cast 347 } // namespace cast
334 } // namespace media 348 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/transport/pacing/paced_sender.cc ('k') | media/cast/transport/rtcp/rtcp_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698