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

Side by Side Diff: webrtc/video/rampup_tests.cc

Issue 1537273003: Step 1 to prepare call_test.* for combined audio/video tests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Cleanups Created 5 years 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 | « webrtc/video/rampup_tests.h ('k') | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webrtc/base/checks.h"
13 #include "webrtc/base/common.h"
14 #include "webrtc/base/event.h"
15 #include "webrtc/base/platform_thread.h"
16 #include "webrtc/modules/pacing/packet_router.h"
17 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h"
18 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h"
19 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
20 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
21 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
22 #include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
26 #include "webrtc/test/testsupport/perf_test.h"
27 #include "webrtc/video/rampup_tests.h"
28
29 namespace webrtc {
30 namespace {
31
32 static const int64_t kPollIntervalMs = 20;
33
34 std::vector<uint32_t> GenerateSsrcs(size_t num_streams,
35 uint32_t ssrc_offset) {
36 std::vector<uint32_t> ssrcs;
37 for (size_t i = 0; i != num_streams; ++i)
38 ssrcs.push_back(static_cast<uint32_t>(ssrc_offset + i));
39 return ssrcs;
40 }
41 } // namespace
42
43 RampUpTester::RampUpTester(size_t num_streams,
44 unsigned int start_bitrate_bps,
45 const std::string& extension_type,
46 bool rtx,
47 bool red)
48 : EndToEndTest(test::CallTest::kLongTimeoutMs),
49 event_(false, false),
50 clock_(Clock::GetRealTimeClock()),
51 num_streams_(num_streams),
52 rtx_(rtx),
53 red_(red),
54 send_stream_(nullptr),
55 start_bitrate_bps_(start_bitrate_bps),
56 start_bitrate_verified_(false),
57 expected_bitrate_bps_(0),
58 test_start_ms_(-1),
59 ramp_up_finished_ms_(-1),
60 extension_type_(extension_type),
61 ssrcs_(GenerateSsrcs(num_streams, 100)),
62 rtx_ssrcs_(GenerateSsrcs(num_streams, 200)),
63 poller_thread_(&BitrateStatsPollingThread,
64 this,
65 "BitrateStatsPollingThread"),
66 sender_call_(nullptr) {
67 if (rtx_) {
68 for (size_t i = 0; i < ssrcs_.size(); ++i)
69 rtx_ssrc_map_[rtx_ssrcs_[i]] = ssrcs_[i];
70 }
71 }
72
73 RampUpTester::~RampUpTester() {
74 event_.Set();
75 }
76
77 Call::Config RampUpTester::GetSenderCallConfig() {
78 Call::Config call_config;
79 if (start_bitrate_bps_ != 0) {
80 call_config.bitrate_config.start_bitrate_bps = start_bitrate_bps_;
81 }
82 call_config.bitrate_config.min_bitrate_bps = 10000;
83 return call_config;
84 }
85
86 void RampUpTester::OnStreamsCreated(
87 VideoSendStream* send_stream,
88 const std::vector<VideoReceiveStream*>& receive_streams) {
89 send_stream_ = send_stream;
90 }
91
92 void RampUpTester::OnTransportsCreated(
93 test::PacketTransport* send_transport,
94 test::PacketTransport* receive_transport) {
95 send_transport_ = send_transport;
96 send_transport_->SetConfig(forward_transport_config_);
97 }
98
99 size_t RampUpTester::GetNumStreams() const {
100 return num_streams_;
101 }
102
103 void RampUpTester::ModifyConfigs(
104 VideoSendStream::Config* send_config,
105 std::vector<VideoReceiveStream::Config>* receive_configs,
106 VideoEncoderConfig* encoder_config) {
107 send_config->suspend_below_min_bitrate = true;
108
109 if (num_streams_ == 1) {
110 encoder_config->streams[0].target_bitrate_bps =
111 encoder_config->streams[0].max_bitrate_bps = 2000000;
112 // For single stream rampup until 1mbps
113 expected_bitrate_bps_ = kSingleStreamTargetBps;
114 } else {
115 // For multi stream rampup until all streams are being sent. That means
116 // enough birate to send all the target streams plus the min bitrate of
117 // the last one.
118 expected_bitrate_bps_ = encoder_config->streams.back().min_bitrate_bps;
119 for (size_t i = 0; i < encoder_config->streams.size() - 1; ++i) {
120 expected_bitrate_bps_ += encoder_config->streams[i].target_bitrate_bps;
121 }
122 }
123
124 send_config->rtp.extensions.clear();
125
126 bool remb;
127 bool transport_cc;
128 if (extension_type_ == RtpExtension::kAbsSendTime) {
129 remb = true;
130 transport_cc = false;
131 send_config->rtp.extensions.push_back(
132 RtpExtension(extension_type_.c_str(), kAbsSendTimeExtensionId));
133 } else if (extension_type_ == RtpExtension::kTransportSequenceNumber) {
134 remb = false;
135 transport_cc = true;
136 send_config->rtp.extensions.push_back(RtpExtension(
137 extension_type_.c_str(), kTransportSequenceNumberExtensionId));
138 } else {
139 remb = true;
140 transport_cc = false;
141 send_config->rtp.extensions.push_back(RtpExtension(
142 extension_type_.c_str(), kTransmissionTimeOffsetExtensionId));
143 }
144
145 send_config->rtp.nack.rtp_history_ms = test::CallTest::kNackRtpHistoryMs;
146 send_config->rtp.ssrcs = ssrcs_;
147 if (rtx_) {
148 send_config->rtp.rtx.payload_type = test::CallTest::kSendRtxPayloadType;
149 send_config->rtp.rtx.ssrcs = rtx_ssrcs_;
150 }
151 if (red_) {
152 send_config->rtp.fec.ulpfec_payload_type =
153 test::CallTest::kUlpfecPayloadType;
154 send_config->rtp.fec.red_payload_type = test::CallTest::kRedPayloadType;
155 }
156
157 size_t i = 0;
158 for (VideoReceiveStream::Config& recv_config : *receive_configs) {
159 recv_config.rtp.remb = remb;
160 recv_config.rtp.transport_cc = transport_cc;
161 recv_config.rtp.extensions = send_config->rtp.extensions;
162
163 recv_config.rtp.remote_ssrc = ssrcs_[i];
164 recv_config.rtp.nack.rtp_history_ms = send_config->rtp.nack.rtp_history_ms;
165
166 if (red_) {
167 recv_config.rtp.fec.red_payload_type =
168 send_config->rtp.fec.red_payload_type;
169 recv_config.rtp.fec.ulpfec_payload_type =
170 send_config->rtp.fec.ulpfec_payload_type;
171 }
172
173 if (rtx_) {
174 recv_config.rtp.rtx[send_config->encoder_settings.payload_type].ssrc =
175 rtx_ssrcs_[i];
176 recv_config.rtp.rtx[send_config->encoder_settings.payload_type]
177 .payload_type = send_config->rtp.rtx.payload_type;
178 }
179 ++i;
180 }
181 }
182
183 void RampUpTester::OnCallsCreated(Call* sender_call, Call* receiver_call) {
184 sender_call_ = sender_call;
185 }
186
187 bool RampUpTester::BitrateStatsPollingThread(void* obj) {
188 return static_cast<RampUpTester*>(obj)->PollStats();
189 }
190
191 bool RampUpTester::PollStats() {
192 if (sender_call_) {
193 Call::Stats stats = sender_call_->GetStats();
194
195 RTC_DCHECK_GT(expected_bitrate_bps_, 0);
196 if (!start_bitrate_verified_ && start_bitrate_bps_ != 0) {
197 // For tests with an explicitly set start bitrate, verify the first
198 // bitrate estimate is close to the start bitrate and lower than the
199 // test target bitrate. This is to verify a call respects the configured
200 // start bitrate, but due to the BWE implementation we can't guarantee the
201 // first estimate really is as high as the start bitrate.
202 EXPECT_GT(stats.send_bandwidth_bps, 0.9 * start_bitrate_bps_);
203 start_bitrate_verified_ = true;
204 }
205 if (stats.send_bandwidth_bps >= expected_bitrate_bps_) {
206 ramp_up_finished_ms_ = clock_->TimeInMilliseconds();
207 observation_complete_.Set();
208 }
209 }
210
211 return !event_.Wait(kPollIntervalMs);
212 }
213
214 void RampUpTester::ReportResult(const std::string& measurement,
215 size_t value,
216 const std::string& units) const {
217 webrtc::test::PrintResult(
218 measurement, "",
219 ::testing::UnitTest::GetInstance()->current_test_info()->name(),
220 value, units, false);
221 }
222
223 void RampUpTester::AccumulateStats(const VideoSendStream::StreamStats& stream,
224 size_t* total_packets_sent,
225 size_t* total_sent,
226 size_t* padding_sent,
227 size_t* media_sent) const {
228 *total_packets_sent += stream.rtp_stats.transmitted.packets +
229 stream.rtp_stats.retransmitted.packets +
230 stream.rtp_stats.fec.packets;
231 *total_sent += stream.rtp_stats.transmitted.TotalBytes() +
232 stream.rtp_stats.retransmitted.TotalBytes() +
233 stream.rtp_stats.fec.TotalBytes();
234 *padding_sent += stream.rtp_stats.transmitted.padding_bytes +
235 stream.rtp_stats.retransmitted.padding_bytes +
236 stream.rtp_stats.fec.padding_bytes;
237 *media_sent += stream.rtp_stats.MediaPayloadBytes();
238 }
239
240 void RampUpTester::TriggerTestDone() {
241 RTC_DCHECK_GE(test_start_ms_, 0);
242
243 VideoSendStream::Stats send_stats = send_stream_->GetStats();
244
245 size_t total_packets_sent = 0;
246 size_t total_sent = 0;
247 size_t padding_sent = 0;
248 size_t media_sent = 0;
249 for (uint32_t ssrc : ssrcs_) {
250 AccumulateStats(send_stats.substreams[ssrc], &total_packets_sent,
251 &total_sent, &padding_sent, &media_sent);
252 }
253
254 size_t rtx_total_packets_sent = 0;
255 size_t rtx_total_sent = 0;
256 size_t rtx_padding_sent = 0;
257 size_t rtx_media_sent = 0;
258 for (uint32_t rtx_ssrc : rtx_ssrcs_) {
259 AccumulateStats(send_stats.substreams[rtx_ssrc], &rtx_total_packets_sent,
260 &rtx_total_sent, &rtx_padding_sent, &rtx_media_sent);
261 }
262
263 ReportResult("ramp-up-total-packets-sent", total_packets_sent, "packets");
264 ReportResult("ramp-up-total-sent", total_sent, "bytes");
265 ReportResult("ramp-up-media-sent", media_sent, "bytes");
266 ReportResult("ramp-up-padding-sent", padding_sent, "bytes");
267 ReportResult("ramp-up-rtx-total-packets-sent", rtx_total_packets_sent,
268 "packets");
269 ReportResult("ramp-up-rtx-total-sent", rtx_total_sent, "bytes");
270 ReportResult("ramp-up-rtx-media-sent", rtx_media_sent, "bytes");
271 ReportResult("ramp-up-rtx-padding-sent", rtx_padding_sent, "bytes");
272 if (ramp_up_finished_ms_ >= 0) {
273 ReportResult("ramp-up-time", ramp_up_finished_ms_ - test_start_ms_,
274 "milliseconds");
275 }
276 }
277
278 void RampUpTester::PerformTest() {
279 test_start_ms_ = clock_->TimeInMilliseconds();
280 poller_thread_.Start();
281 EXPECT_TRUE(Wait()) << "Timed out while waiting for ramp-up to complete.";
282 TriggerTestDone();
283 poller_thread_.Stop();
284 }
285
286 RampUpDownUpTester::RampUpDownUpTester(size_t num_streams,
287 unsigned int start_bitrate_bps,
288 const std::string& extension_type,
289 bool rtx,
290 bool red)
291 : RampUpTester(num_streams, start_bitrate_bps, extension_type, rtx, red),
292 test_state_(kFirstRampup),
293 state_start_ms_(clock_->TimeInMilliseconds()),
294 interval_start_ms_(clock_->TimeInMilliseconds()),
295 sent_bytes_(0) {
296 forward_transport_config_.link_capacity_kbps =
297 kHighBandwidthLimitBps / 1000;
298 }
299
300 RampUpDownUpTester::~RampUpDownUpTester() {}
301
302 bool RampUpDownUpTester::PollStats() {
303 if (send_stream_) {
304 webrtc::VideoSendStream::Stats stats = send_stream_->GetStats();
305 int transmit_bitrate_bps = 0;
306 for (auto it : stats.substreams) {
307 transmit_bitrate_bps += it.second.total_bitrate_bps;
308 }
309
310 EvolveTestState(transmit_bitrate_bps, stats.suspended);
311 }
312
313 return !event_.Wait(kPollIntervalMs);
314 }
315
316 Call::Config RampUpDownUpTester::GetReceiverCallConfig() {
317 Call::Config config;
318 config.bitrate_config.min_bitrate_bps = 10000;
319 return config;
320 }
321
322 std::string RampUpDownUpTester::GetModifierString() const {
323 std::string str("_");
324 std::ostringstream s;
325 s << num_streams_;
326 str += s.str();
327 str += "stream";
328 str += (num_streams_ > 1 ? "s" : "");
329 str += "_";
330 str += (rtx_ ? "" : "no");
331 str += "rtx";
332 return str;
333 }
334
335 void RampUpDownUpTester::EvolveTestState(int bitrate_bps, bool suspended) {
336 int64_t now = clock_->TimeInMilliseconds();
337 switch (test_state_) {
338 case kFirstRampup: {
339 EXPECT_FALSE(suspended);
340 if (bitrate_bps > kExpectedHighBitrateBps) {
341 // The first ramp-up has reached the target bitrate. Change the
342 // channel limit, and move to the next test state.
343 forward_transport_config_.link_capacity_kbps =
344 kLowBandwidthLimitBps / 1000;
345 send_transport_->SetConfig(forward_transport_config_);
346 test_state_ = kLowRate;
347 webrtc::test::PrintResult("ramp_up_down_up",
348 GetModifierString(),
349 "first_rampup",
350 now - state_start_ms_,
351 "ms",
352 false);
353 state_start_ms_ = now;
354 interval_start_ms_ = now;
355 sent_bytes_ = 0;
356 }
357 break;
358 }
359 case kLowRate: {
360 if (bitrate_bps < kExpectedLowBitrateBps && suspended) {
361 // The ramp-down was successful. Change the channel limit back to a
362 // high value, and move to the next test state.
363 forward_transport_config_.link_capacity_kbps =
364 kHighBandwidthLimitBps / 1000;
365 send_transport_->SetConfig(forward_transport_config_);
366 test_state_ = kSecondRampup;
367 webrtc::test::PrintResult("ramp_up_down_up",
368 GetModifierString(),
369 "rampdown",
370 now - state_start_ms_,
371 "ms",
372 false);
373 state_start_ms_ = now;
374 interval_start_ms_ = now;
375 sent_bytes_ = 0;
376 }
377 break;
378 }
379 case kSecondRampup: {
380 if (bitrate_bps > kExpectedHighBitrateBps && !suspended) {
381 webrtc::test::PrintResult("ramp_up_down_up",
382 GetModifierString(),
383 "second_rampup",
384 now - state_start_ms_,
385 "ms",
386 false);
387 observation_complete_.Set();
388 }
389 break;
390 }
391 }
392 }
393
394 class RampUpTest : public test::CallTest {
395 public:
396 RampUpTest() {}
397
398 virtual ~RampUpTest() {
399 EXPECT_EQ(nullptr, send_stream_);
400 EXPECT_TRUE(receive_streams_.empty());
401 }
402 };
403
404 TEST_F(RampUpTest, SingleStream) {
405 RampUpTester test(1, 0, RtpExtension::kTOffset, false, false);
406 RunBaseTest(&test, FakeNetworkPipe::Config());
407 }
408
409 TEST_F(RampUpTest, Simulcast) {
410 RampUpTester test(3, 0, RtpExtension::kTOffset, false, false);
411 RunBaseTest(&test, FakeNetworkPipe::Config());
412 }
413
414 TEST_F(RampUpTest, SimulcastWithRtx) {
415 RampUpTester test(3, 0, RtpExtension::kTOffset, true, false);
416 RunBaseTest(&test, FakeNetworkPipe::Config());
417 }
418
419 TEST_F(RampUpTest, SimulcastByRedWithRtx) {
420 RampUpTester test(3, 0, RtpExtension::kTOffset, true, true);
421 RunBaseTest(&test, FakeNetworkPipe::Config());
422 }
423
424 TEST_F(RampUpTest, SingleStreamWithHighStartBitrate) {
425 RampUpTester test(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kTOffset,
426 false, false);
427 RunBaseTest(&test, FakeNetworkPipe::Config());
428 }
429
430 TEST_F(RampUpTest, UpDownUpOneStream) {
431 RampUpDownUpTester test(1, 60000, RtpExtension::kAbsSendTime, false, false);
432 RunBaseTest(&test, FakeNetworkPipe::Config());
433 }
434
435 TEST_F(RampUpTest, UpDownUpThreeStreams) {
436 RampUpDownUpTester test(3, 60000, RtpExtension::kAbsSendTime, false, false);
437 RunBaseTest(&test, FakeNetworkPipe::Config());
438 }
439
440 TEST_F(RampUpTest, UpDownUpOneStreamRtx) {
441 RampUpDownUpTester test(1, 60000, RtpExtension::kAbsSendTime, true, false);
442 RunBaseTest(&test, FakeNetworkPipe::Config());
443 }
444
445 TEST_F(RampUpTest, UpDownUpThreeStreamsRtx) {
446 RampUpDownUpTester test(3, 60000, RtpExtension::kAbsSendTime, true, false);
447 RunBaseTest(&test, FakeNetworkPipe::Config());
448 }
449
450 TEST_F(RampUpTest, UpDownUpOneStreamByRedRtx) {
451 RampUpDownUpTester test(1, 60000, RtpExtension::kAbsSendTime, true, true);
452 RunBaseTest(&test, FakeNetworkPipe::Config());
453 }
454
455 TEST_F(RampUpTest, UpDownUpThreeStreamsByRedRtx) {
456 RampUpDownUpTester test(3, 60000, RtpExtension::kAbsSendTime, true, true);
457 RunBaseTest(&test, FakeNetworkPipe::Config());
458 }
459
460 TEST_F(RampUpTest, AbsSendTimeSingleStream) {
461 RampUpTester test(1, 0, RtpExtension::kAbsSendTime, false, false);
462 RunBaseTest(&test, FakeNetworkPipe::Config());
463 }
464
465 TEST_F(RampUpTest, AbsSendTimeSimulcast) {
466 RampUpTester test(3, 0, RtpExtension::kAbsSendTime, false, false);
467 RunBaseTest(&test, FakeNetworkPipe::Config());
468 }
469
470 TEST_F(RampUpTest, AbsSendTimeSimulcastWithRtx) {
471 RampUpTester test(3, 0, RtpExtension::kAbsSendTime, true, false);
472 RunBaseTest(&test, FakeNetworkPipe::Config());
473 }
474
475 TEST_F(RampUpTest, AbsSendTimeSimulcastByRedWithRtx) {
476 RampUpTester test(3, 0, RtpExtension::kAbsSendTime, true, true);
477 RunBaseTest(&test, FakeNetworkPipe::Config());
478 }
479
480 TEST_F(RampUpTest, AbsSendTimeSingleStreamWithHighStartBitrate) {
481 RampUpTester test(1, 0.9 * kSingleStreamTargetBps, RtpExtension::kAbsSendTime,
482 false, false);
483 RunBaseTest(&test, FakeNetworkPipe::Config());
484 }
485
486 TEST_F(RampUpTest, TransportSequenceNumberSingleStream) {
487 RampUpTester test(1, 0, RtpExtension::kTransportSequenceNumber, false, false);
488 RunBaseTest(&test, FakeNetworkPipe::Config());
489 }
490
491 TEST_F(RampUpTest, TransportSequenceNumberSimulcast) {
492 RampUpTester test(3, 0, RtpExtension::kTransportSequenceNumber, false, false);
493 RunBaseTest(&test, FakeNetworkPipe::Config());
494 }
495
496 TEST_F(RampUpTest, TransportSequenceNumberSimulcastWithRtx) {
497 RampUpTester test(3, 0, RtpExtension::kTransportSequenceNumber, true, false);
498 RunBaseTest(&test, FakeNetworkPipe::Config());
499 }
500
501 TEST_F(RampUpTest, TransportSequenceNumberSimulcastByRedWithRtx) {
502 RampUpTester test(3, 0, RtpExtension::kTransportSequenceNumber, true, true);
503 RunBaseTest(&test, FakeNetworkPipe::Config());
504 }
505
506 TEST_F(RampUpTest, TransportSequenceNumberSingleStreamWithHighStartBitrate) {
507 RampUpTester test(1, 0.9 * kSingleStreamTargetBps,
508 RtpExtension::kTransportSequenceNumber, false, false);
509 RunBaseTest(&test, FakeNetworkPipe::Config());
510 }
511 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/rampup_tests.h ('k') | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698