blob: 193505f676a723f7fb013c1510619fc2841f5af8 [file] [log] [blame]
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +00001/*
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 */
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +000010#include <algorithm> // max
kwiberg27f982b2016-03-01 11:52:33 -080011#include <memory>
magjed@webrtc.org2d2a30c2015-03-24 12:37:36 +000012#include <vector>
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "call/call.h"
15#include "call/rtp_transport_controller_send.h"
16#include "common_video/include/frame_callback.h"
17#include "common_video/include/video_frame.h"
18#include "modules/rtp_rtcp/include/rtp_header_parser.h"
19#include "modules/rtp_rtcp/include/rtp_rtcp.h"
20#include "modules/rtp_rtcp/source/rtcp_sender.h"
21#include "modules/rtp_rtcp/source/rtp_format_vp9.h"
22#include "modules/video_coding/codecs/vp8/include/vp8.h"
23#include "modules/video_coding/codecs/vp9/include/vp9.h"
24#include "rtc_base/bind.h"
25#include "rtc_base/checks.h"
26#include "rtc_base/criticalsection.h"
27#include "rtc_base/event.h"
Sebastian Janssoncabe3832018-01-12 10:54:18 +010028#include "rtc_base/experiments/alr_experiment.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/logging.h"
30#include "rtc_base/platform_thread.h"
31#include "rtc_base/rate_limiter.h"
32#include "rtc_base/timeutils.h"
33#include "system_wrappers/include/sleep.h"
34#include "test/call_test.h"
35#include "test/configurable_frame_size_encoder.h"
36#include "test/fake_texture_frame.h"
37#include "test/field_trial.h"
38#include "test/frame_generator.h"
39#include "test/frame_generator_capturer.h"
40#include "test/frame_utils.h"
Danil Chapovalov45d725d2018-02-19 19:09:53 +010041#include "test/gmock.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "test/gtest.h"
43#include "test/null_transport.h"
44#include "test/rtcp_packet_parser.h"
45#include "test/testsupport/perf_test.h"
perkjfa10b552016-10-02 23:45:26 -070046
Sebastian Janssona45c8da2018-01-16 10:55:29 +010047#include "call/video_send_stream.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020048#include "video/send_statistics_proxy.h"
49#include "video/transport_adapter.h"
Sebastian Janssona45c8da2018-01-16 10:55:29 +010050#include "video/video_send_stream.h"
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000051
52namespace webrtc {
Sebastian Janssona45c8da2018-01-16 10:55:29 +010053namespace test {
54class VideoSendStreamPeer {
55 public:
56 explicit VideoSendStreamPeer(webrtc::VideoSendStream* base_class_stream)
57 : internal_stream_(
58 static_cast<internal::VideoSendStream*>(base_class_stream)) {}
59 rtc::Optional<float> GetPacingFactorOverride() const {
60 return internal_stream_->GetPacingFactorOverride();
61 }
62
63 private:
64 internal::VideoSendStream const* const internal_stream_;
65};
66} // namespace test
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +000067
sprang@webrtc.org346094c2014-02-18 08:40:33 +000068enum VideoFormat { kGeneric, kVP8, };
69
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -070070void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1,
71 const std::vector<VideoFrame>& frames2);
72VideoFrame CreateVideoFrame(int width, int height, uint8_t data);
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +000073
pbos@webrtc.org994d0b72014-06-27 08:47:52 +000074class VideoSendStreamTest : public test::CallTest {
pbos@webrtc.org013d9942013-08-22 09:42:17 +000075 protected:
stefan@webrtc.org69969e22013-11-15 12:32:15 +000076 void TestNackRetransmission(uint32_t retransmit_ssrc,
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +000077 uint8_t retransmit_payload_type);
sprang@webrtc.org346094c2014-02-18 08:40:33 +000078 void TestPacketFragmentationSize(VideoFormat format, bool with_fec);
Åsa Perssonff24c042015-12-04 10:58:08 +010079
80 void TestVp9NonFlexMode(uint8_t num_temporal_layers,
81 uint8_t num_spatial_layers);
perkj803d97f2016-11-01 11:45:46 -070082
83 void TestRequestSourceRotateVideo(bool support_orientation_ext);
pbos@webrtc.org013d9942013-08-22 09:42:17 +000084};
85
pbos@webrtc.orgf777cf22014-01-10 18:47:32 +000086TEST_F(VideoSendStreamTest, CanStartStartedStream) {
eladalon413ee9a2017-08-22 04:02:52 -070087 task_queue_.SendTask([this]() {
88 CreateSenderCall(Call::Config(event_log_.get()));
pbos@webrtc.orgf777cf22014-01-10 18:47:32 +000089
eladalon413ee9a2017-08-22 04:02:52 -070090 test::NullTransport transport;
91 CreateSendConfig(1, 0, 0, &transport);
92 CreateVideoStreams();
93 video_send_stream_->Start();
94 video_send_stream_->Start();
95 DestroyStreams();
96 DestroyCalls();
97 });
pbos@webrtc.orgf777cf22014-01-10 18:47:32 +000098}
99
100TEST_F(VideoSendStreamTest, CanStopStoppedStream) {
eladalon413ee9a2017-08-22 04:02:52 -0700101 task_queue_.SendTask([this]() {
102 CreateSenderCall(Call::Config(event_log_.get()));
pbos@webrtc.orgf777cf22014-01-10 18:47:32 +0000103
eladalon413ee9a2017-08-22 04:02:52 -0700104 test::NullTransport transport;
105 CreateSendConfig(1, 0, 0, &transport);
106 CreateVideoStreams();
107 video_send_stream_->Stop();
108 video_send_stream_->Stop();
109 DestroyStreams();
110 DestroyCalls();
111 });
pbos@webrtc.orgf777cf22014-01-10 18:47:32 +0000112}
113
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000114TEST_F(VideoSendStreamTest, SupportsCName) {
115 static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000116 class CNameObserver : public test::SendTest {
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000117 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000118 CNameObserver() : SendTest(kDefaultTimeoutMs) {}
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000119
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000120 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000121 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
danilchap3dc929e2016-11-02 08:21:59 -0700122 test::RtcpPacketParser parser;
123 EXPECT_TRUE(parser.Parse(packet, length));
124 if (parser.sdes()->num_packets() > 0) {
125 EXPECT_EQ(1u, parser.sdes()->chunks().size());
126 EXPECT_EQ(kCName, parser.sdes()->chunks()[0].cname);
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000127
danilchap3dc929e2016-11-02 08:21:59 -0700128 observation_complete_.Set();
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000129 }
130
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000131 return SEND_PACKET;
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000132 }
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000133
stefanff483612015-12-21 03:14:00 -0800134 void ModifyVideoConfigs(
135 VideoSendStream::Config* send_config,
136 std::vector<VideoReceiveStream::Config>* receive_configs,
137 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000138 send_config->rtp.c_name = kCName;
139 }
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000140
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000141 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100142 EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP with CNAME.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000143 }
144 } test;
pbos@webrtc.org013d9942013-08-22 09:42:17 +0000145
stefane74eef12016-01-08 06:47:13 -0800146 RunBaseTest(&test);
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +0000147}
148
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000149TEST_F(VideoSendStreamTest, SupportsAbsoluteSendTime) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000150 class AbsoluteSendTimeObserver : public test::SendTest {
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000151 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000152 AbsoluteSendTimeObserver() : SendTest(kDefaultTimeoutMs) {
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000153 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
Stefan Holmer4654d202015-12-08 09:10:43 +0100154 kRtpExtensionAbsoluteSendTime, test::kAbsSendTimeExtensionId));
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000155 }
156
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000157 Action OnSendRtp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000158 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000159 EXPECT_TRUE(parser_->Parse(packet, length, &header));
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000160
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000161 EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
162 EXPECT_TRUE(header.extension.hasAbsoluteSendTime);
163 EXPECT_EQ(header.extension.transmissionTimeOffset, 0);
skvladc3f35152016-09-02 13:23:46 -0700164 if (header.extension.absoluteSendTime != 0) {
165 // Wait for at least one packet with a non-zero send time. The send time
166 // is a 16-bit value derived from the system clock, and it is valid
167 // for a packet to have a zero send time. To tell that from an
168 // unpopulated value we'll wait for a packet with non-zero send time.
169 observation_complete_.Set();
170 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100171 RTC_LOG(LS_WARNING)
172 << "Got a packet with zero absoluteSendTime, waiting"
173 " for another packet...";
skvladc3f35152016-09-02 13:23:46 -0700174 }
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000175
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000176 return SEND_PACKET;
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000177 }
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000178
stefanff483612015-12-21 03:14:00 -0800179 void ModifyVideoConfigs(
180 VideoSendStream::Config* send_config,
181 std::vector<VideoReceiveStream::Config>* receive_configs,
182 VideoEncoderConfig* encoder_config) override {
Erik Språng95261872015-04-10 11:58:49 +0200183 send_config->rtp.extensions.clear();
Stefan Holmer4654d202015-12-08 09:10:43 +0100184 send_config->rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -0700185 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000186 }
pbos@webrtc.orgdde16f12014-08-05 23:35:43 +0000187
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000188 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100189 EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000190 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000191 } test;
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000192
stefane74eef12016-01-08 06:47:13 -0800193 RunBaseTest(&test);
pbos@webrtc.org5c678ea2013-09-11 19:00:39 +0000194}
195
pbos@webrtc.org29023282013-09-11 10:14:56 +0000196TEST_F(VideoSendStreamTest, SupportsTransmissionTimeOffset) {
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000197 static const int kEncodeDelayMs = 5;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000198 class TransmissionTimeOffsetObserver : public test::SendTest {
pbos@webrtc.org29023282013-09-11 10:14:56 +0000199 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000200 TransmissionTimeOffsetObserver()
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000201 : SendTest(kDefaultTimeoutMs),
202 encoder_(Clock::GetRealTimeClock(), kEncodeDelayMs) {
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000203 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
Stefan Holmer12952972015-10-29 15:13:24 +0100204 kRtpExtensionTransmissionTimeOffset, test::kTOffsetExtensionId));
pbos@webrtc.org29023282013-09-11 10:14:56 +0000205 }
206
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000207 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000208 Action OnSendRtp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org29023282013-09-11 10:14:56 +0000209 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000210 EXPECT_TRUE(parser_->Parse(packet, length, &header));
pbos@webrtc.org29023282013-09-11 10:14:56 +0000211
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000212 EXPECT_TRUE(header.extension.hasTransmissionTimeOffset);
213 EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
pbos@webrtc.org29023282013-09-11 10:14:56 +0000214 EXPECT_GT(header.extension.transmissionTimeOffset, 0);
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000215 EXPECT_EQ(header.extension.absoluteSendTime, 0u);
Peter Boström5811a392015-12-10 13:02:50 +0100216 observation_complete_.Set();
pbos@webrtc.org29023282013-09-11 10:14:56 +0000217
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000218 return SEND_PACKET;
pbos@webrtc.org29023282013-09-11 10:14:56 +0000219 }
pbos@webrtc.org29023282013-09-11 10:14:56 +0000220
stefanff483612015-12-21 03:14:00 -0800221 void ModifyVideoConfigs(
222 VideoSendStream::Config* send_config,
223 std::vector<VideoReceiveStream::Config>* receive_configs,
224 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000225 send_config->encoder_settings.encoder = &encoder_;
Stefan Holmer12952972015-10-29 15:13:24 +0100226 send_config->rtp.extensions.clear();
isheriff6f8d6862016-05-26 11:24:55 -0700227 send_config->rtp.extensions.push_back(RtpExtension(
228 RtpExtension::kTimestampOffsetUri, test::kTOffsetExtensionId));
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000229 }
pbos@webrtc.org29023282013-09-11 10:14:56 +0000230
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000231 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100232 EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000233 }
pbos@webrtc.org29023282013-09-11 10:14:56 +0000234
asapersson@webrtc.org049e4ec2014-11-20 10:19:46 +0000235 test::DelayedEncoder encoder_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000236 } test;
237
stefane74eef12016-01-08 06:47:13 -0800238 RunBaseTest(&test);
pbos@webrtc.org29023282013-09-11 10:14:56 +0000239}
240
sprang867fb522015-08-03 04:38:41 -0700241TEST_F(VideoSendStreamTest, SupportsTransportWideSequenceNumbers) {
danilchap42ca68a2016-10-31 03:34:40 -0700242 static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId;
sprang867fb522015-08-03 04:38:41 -0700243 class TransportWideSequenceNumberObserver : public test::SendTest {
244 public:
245 TransportWideSequenceNumberObserver()
246 : SendTest(kDefaultTimeoutMs), encoder_(Clock::GetRealTimeClock()) {
247 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
248 kRtpExtensionTransportSequenceNumber, kExtensionId));
249 }
250
251 private:
252 Action OnSendRtp(const uint8_t* packet, size_t length) override {
253 RTPHeader header;
254 EXPECT_TRUE(parser_->Parse(packet, length, &header));
255
256 EXPECT_TRUE(header.extension.hasTransportSequenceNumber);
257 EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
258 EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
259
Peter Boström5811a392015-12-10 13:02:50 +0100260 observation_complete_.Set();
sprang867fb522015-08-03 04:38:41 -0700261
262 return SEND_PACKET;
263 }
264
stefanff483612015-12-21 03:14:00 -0800265 void ModifyVideoConfigs(
266 VideoSendStream::Config* send_config,
267 std::vector<VideoReceiveStream::Config>* receive_configs,
268 VideoEncoderConfig* encoder_config) override {
sprang867fb522015-08-03 04:38:41 -0700269 send_config->encoder_settings.encoder = &encoder_;
sprang867fb522015-08-03 04:38:41 -0700270 }
271
272 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100273 EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
sprang867fb522015-08-03 04:38:41 -0700274 }
275
276 test::FakeEncoder encoder_;
277 } test;
278
stefane74eef12016-01-08 06:47:13 -0800279 RunBaseTest(&test);
sprang867fb522015-08-03 04:38:41 -0700280}
281
perkj803d97f2016-11-01 11:45:46 -0700282TEST_F(VideoSendStreamTest, SupportsVideoRotation) {
283 class VideoRotationObserver : public test::SendTest {
284 public:
285 VideoRotationObserver() : SendTest(kDefaultTimeoutMs) {
286 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
287 kRtpExtensionVideoRotation, test::kVideoRotationExtensionId));
288 }
289
290 Action OnSendRtp(const uint8_t* packet, size_t length) override {
291 RTPHeader header;
292 EXPECT_TRUE(parser_->Parse(packet, length, &header));
ilnik7a3006b2017-05-23 09:34:21 -0700293 // Only the last packet of the frame is required to have the extension.
294 if (!header.markerBit)
295 return SEND_PACKET;
perkj803d97f2016-11-01 11:45:46 -0700296 EXPECT_TRUE(header.extension.hasVideoRotation);
297 EXPECT_EQ(kVideoRotation_90, header.extension.videoRotation);
298 observation_complete_.Set();
299 return SEND_PACKET;
300 }
301
302 void ModifyVideoConfigs(
303 VideoSendStream::Config* send_config,
304 std::vector<VideoReceiveStream::Config>* receive_configs,
305 VideoEncoderConfig* encoder_config) override {
306 send_config->rtp.extensions.clear();
307 send_config->rtp.extensions.push_back(RtpExtension(
308 RtpExtension::kVideoRotationUri, test::kVideoRotationExtensionId));
309 }
310
311 void OnFrameGeneratorCapturerCreated(
312 test::FrameGeneratorCapturer* frame_generator_capturer) override {
313 frame_generator_capturer->SetFakeRotation(kVideoRotation_90);
314 }
315
316 void PerformTest() override {
317 EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet.";
318 }
319 } test;
320
321 RunBaseTest(&test);
322}
323
ilnik00d802b2017-04-11 10:34:31 -0700324TEST_F(VideoSendStreamTest, SupportsVideoContentType) {
ilnik10894992017-06-21 08:23:19 -0700325 class VideoContentTypeObserver : public test::SendTest {
ilnik00d802b2017-04-11 10:34:31 -0700326 public:
ilnik10894992017-06-21 08:23:19 -0700327 VideoContentTypeObserver() : SendTest(kDefaultTimeoutMs) {
ilnik00d802b2017-04-11 10:34:31 -0700328 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
329 kRtpExtensionVideoContentType, test::kVideoContentTypeExtensionId));
330 }
331
332 Action OnSendRtp(const uint8_t* packet, size_t length) override {
333 RTPHeader header;
334 EXPECT_TRUE(parser_->Parse(packet, length, &header));
ilnik7a3006b2017-05-23 09:34:21 -0700335 // Only the last packet of the frame must have extension.
336 if (!header.markerBit)
337 return SEND_PACKET;
ilnik00d802b2017-04-11 10:34:31 -0700338 EXPECT_TRUE(header.extension.hasVideoContentType);
ilnik6d5b4d62017-08-30 03:32:14 -0700339 EXPECT_TRUE(videocontenttypehelpers::IsScreenshare(
340 header.extension.videoContentType));
ilnik00d802b2017-04-11 10:34:31 -0700341 observation_complete_.Set();
342 return SEND_PACKET;
343 }
344
345 void ModifyVideoConfigs(
346 VideoSendStream::Config* send_config,
347 std::vector<VideoReceiveStream::Config>* receive_configs,
348 VideoEncoderConfig* encoder_config) override {
349 send_config->rtp.extensions.clear();
350 send_config->rtp.extensions.push_back(
351 RtpExtension(RtpExtension::kVideoContentTypeUri,
352 test::kVideoContentTypeExtensionId));
353 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
354 }
355
356 void PerformTest() override {
357 EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet.";
358 }
359 } test;
360
361 RunBaseTest(&test);
362}
363
ilnik04f4d122017-06-19 07:18:55 -0700364TEST_F(VideoSendStreamTest, SupportsVideoTimingFrames) {
ilnik10894992017-06-21 08:23:19 -0700365 class VideoTimingObserver : public test::SendTest {
ilnik04f4d122017-06-19 07:18:55 -0700366 public:
ilnik10894992017-06-21 08:23:19 -0700367 VideoTimingObserver() : SendTest(kDefaultTimeoutMs) {
ilnik04f4d122017-06-19 07:18:55 -0700368 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
369 kRtpExtensionVideoTiming, test::kVideoTimingExtensionId));
370 }
371
372 Action OnSendRtp(const uint8_t* packet, size_t length) override {
373 RTPHeader header;
374 EXPECT_TRUE(parser_->Parse(packet, length, &header));
ilnik10894992017-06-21 08:23:19 -0700375 // Only the last packet of the frame must have extension.
376 if (!header.markerBit)
377 return SEND_PACKET;
378 EXPECT_TRUE(header.extension.has_video_timing);
379 observation_complete_.Set();
ilnik04f4d122017-06-19 07:18:55 -0700380 return SEND_PACKET;
381 }
382
383 void ModifyVideoConfigs(
384 VideoSendStream::Config* send_config,
385 std::vector<VideoReceiveStream::Config>* receive_configs,
386 VideoEncoderConfig* encoder_config) override {
387 send_config->rtp.extensions.clear();
388 send_config->rtp.extensions.push_back(RtpExtension(
389 RtpExtension::kVideoTimingUri, test::kVideoTimingExtensionId));
390 }
391
392 void PerformTest() override {
393 EXPECT_TRUE(Wait()) << "Timed out while waiting for timing frames.";
394 }
395 } test;
396
397 RunBaseTest(&test);
398}
399
danilchap901b2df2017-07-28 08:56:04 -0700400class FakeReceiveStatistics : public ReceiveStatisticsProvider {
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000401 public:
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +0000402 FakeReceiveStatistics(uint32_t send_ssrc,
403 uint32_t last_sequence_number,
404 uint32_t cumulative_lost,
danilchap901b2df2017-07-28 08:56:04 -0700405 uint8_t fraction_lost) {
406 stat_.SetMediaSsrc(send_ssrc);
407 stat_.SetExtHighestSeqNum(last_sequence_number);
408 stat_.SetCumulativeLost(cumulative_lost);
409 stat_.SetFractionLost(fraction_lost);
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000410 }
411
danilchap901b2df2017-07-28 08:56:04 -0700412 std::vector<rtcp::ReportBlock> RtcpReportBlocks(size_t max_blocks) override {
413 EXPECT_GE(max_blocks, 1u);
414 return {stat_};
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000415 }
416
417 private:
danilchap901b2df2017-07-28 08:56:04 -0700418 rtcp::ReportBlock stat_;
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000419};
420
brandtre602f0a2016-10-31 03:40:49 -0700421class UlpfecObserver : public test::EndToEndTest {
Stefan Holmer4654d202015-12-08 09:10:43 +0100422 public:
brandtre602f0a2016-10-31 03:40:49 -0700423 UlpfecObserver(bool header_extensions_enabled,
brandtr65a1e772016-12-12 01:54:58 -0800424 bool use_nack,
425 bool expect_red,
426 bool expect_ulpfec,
brandtr696c9c62016-12-19 05:47:28 -0800427 const std::string& codec,
428 VideoEncoder* encoder)
brandtr20d45472017-01-02 00:34:27 -0800429 : EndToEndTest(kTimeoutMs),
brandtr696c9c62016-12-19 05:47:28 -0800430 encoder_(encoder),
Peter Boström39593972016-02-15 11:27:15 +0100431 payload_name_(codec),
432 use_nack_(use_nack),
433 expect_red_(expect_red),
brandtre602f0a2016-10-31 03:40:49 -0700434 expect_ulpfec_(expect_ulpfec),
brandtr65a1e772016-12-12 01:54:58 -0800435 sent_media_(false),
436 sent_ulpfec_(false),
brandtr696c9c62016-12-19 05:47:28 -0800437 header_extensions_enabled_(header_extensions_enabled) {}
Stefan Holmer4654d202015-12-08 09:10:43 +0100438
brandtr20d45472017-01-02 00:34:27 -0800439 // Some of the test cases are expected to time out and thus we are using
440 // a shorter timeout window than the default here.
441 static constexpr size_t kTimeoutMs = 10000;
442
Stefan Holmer4654d202015-12-08 09:10:43 +0100443 private:
444 Action OnSendRtp(const uint8_t* packet, size_t length) override {
445 RTPHeader header;
446 EXPECT_TRUE(parser_->Parse(packet, length, &header));
447
Stefan Holmer4654d202015-12-08 09:10:43 +0100448 int encapsulated_payload_type = -1;
449 if (header.payloadType == VideoSendStreamTest::kRedPayloadType) {
Peter Boström39593972016-02-15 11:27:15 +0100450 EXPECT_TRUE(expect_red_);
Stefan Holmer4654d202015-12-08 09:10:43 +0100451 encapsulated_payload_type = static_cast<int>(packet[header.headerLength]);
452 if (encapsulated_payload_type !=
Peter Boström39593972016-02-15 11:27:15 +0100453 VideoSendStreamTest::kFakeVideoSendPayloadType) {
Stefan Holmer4654d202015-12-08 09:10:43 +0100454 EXPECT_EQ(VideoSendStreamTest::kUlpfecPayloadType,
455 encapsulated_payload_type);
Peter Boström39593972016-02-15 11:27:15 +0100456 }
Stefan Holmer4654d202015-12-08 09:10:43 +0100457 } else {
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100458 EXPECT_EQ(VideoSendStreamTest::kFakeVideoSendPayloadType,
459 header.payloadType);
Peter Boström39593972016-02-15 11:27:15 +0100460 if (static_cast<size_t>(header.headerLength + header.paddingLength) <
461 length) {
462 // Not padding-only, media received outside of RED.
463 EXPECT_FALSE(expect_red_);
brandtr65a1e772016-12-12 01:54:58 -0800464 sent_media_ = true;
Peter Boström39593972016-02-15 11:27:15 +0100465 }
Stefan Holmer4654d202015-12-08 09:10:43 +0100466 }
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000467
Stefan Holmer4654d202015-12-08 09:10:43 +0100468 if (header_extensions_enabled_) {
469 EXPECT_TRUE(header.extension.hasAbsoluteSendTime);
470 uint32_t kHalf24BitsSpace = 0xFFFFFF / 2;
471 if (header.extension.absoluteSendTime <= kHalf24BitsSpace &&
472 prev_header_.extension.absoluteSendTime > kHalf24BitsSpace) {
473 // 24 bits wrap.
474 EXPECT_GT(prev_header_.extension.absoluteSendTime,
475 header.extension.absoluteSendTime);
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000476 } else {
Stefan Holmer4654d202015-12-08 09:10:43 +0100477 EXPECT_GE(header.extension.absoluteSendTime,
478 prev_header_.extension.absoluteSendTime);
Stefan Holmer01b48882015-05-05 10:21:24 +0200479 }
Stefan Holmer4654d202015-12-08 09:10:43 +0100480 EXPECT_TRUE(header.extension.hasTransportSequenceNumber);
481 uint16_t seq_num_diff = header.extension.transportSequenceNumber -
482 prev_header_.extension.transportSequenceNumber;
483 EXPECT_EQ(1, seq_num_diff);
484 }
Stefan Holmer01b48882015-05-05 10:21:24 +0200485
Stefan Holmer4654d202015-12-08 09:10:43 +0100486 if (encapsulated_payload_type != -1) {
487 if (encapsulated_payload_type ==
488 VideoSendStreamTest::kUlpfecPayloadType) {
brandtre602f0a2016-10-31 03:40:49 -0700489 EXPECT_TRUE(expect_ulpfec_);
brandtr65a1e772016-12-12 01:54:58 -0800490 sent_ulpfec_ = true;
Stefan Holmer4654d202015-12-08 09:10:43 +0100491 } else {
brandtr65a1e772016-12-12 01:54:58 -0800492 sent_media_ = true;
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000493 }
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000494 }
495
brandtr20d45472017-01-02 00:34:27 -0800496 if (sent_media_ && sent_ulpfec_) {
497 observation_complete_.Set();
Peter Boström39593972016-02-15 11:27:15 +0100498 }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000499
Stefan Holmer4654d202015-12-08 09:10:43 +0100500 prev_header_ = header;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000501
Stefan Holmer4654d202015-12-08 09:10:43 +0100502 return SEND_PACKET;
503 }
504
eladalon413ee9a2017-08-22 04:02:52 -0700505 test::PacketTransport* CreateSendTransport(
506 test::SingleThreadedTaskQueueForTesting* task_queue,
507 Call* sender_call) override {
Peter Boström39593972016-02-15 11:27:15 +0100508 // At low RTT (< kLowRttNackMs) -> NACK only, no FEC.
509 // Configure some network delay.
510 const int kNetworkDelayMs = 100;
511 FakeNetworkPipe::Config config;
brandtr65a1e772016-12-12 01:54:58 -0800512 config.loss_percent = 5;
Peter Boström39593972016-02-15 11:27:15 +0100513 config.queue_delay_ms = kNetworkDelayMs;
minyue20c84cc2017-04-10 16:57:57 -0700514 return new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -0700515 task_queue, sender_call, this, test::PacketTransport::kSender,
minyue20c84cc2017-04-10 16:57:57 -0700516 VideoSendStreamTest::payload_type_map_, config);
Peter Boström39593972016-02-15 11:27:15 +0100517 }
518
stefanff483612015-12-21 03:14:00 -0800519 void ModifyVideoConfigs(
520 VideoSendStream::Config* send_config,
521 std::vector<VideoReceiveStream::Config>* receive_configs,
522 VideoEncoderConfig* encoder_config) override {
Peter Boström39593972016-02-15 11:27:15 +0100523 if (use_nack_) {
524 send_config->rtp.nack.rtp_history_ms =
525 (*receive_configs)[0].rtp.nack.rtp_history_ms =
526 VideoSendStreamTest::kNackRtpHistoryMs;
527 }
brandtr696c9c62016-12-19 05:47:28 -0800528 send_config->encoder_settings.encoder = encoder_;
Peter Boström39593972016-02-15 11:27:15 +0100529 send_config->encoder_settings.payload_name = payload_name_;
brandtrb5f2c3f2016-10-04 23:28:39 -0700530 send_config->rtp.ulpfec.red_payload_type =
531 VideoSendStreamTest::kRedPayloadType;
532 send_config->rtp.ulpfec.ulpfec_payload_type =
533 VideoSendStreamTest::kUlpfecPayloadType;
stefanb77c7162017-02-06 06:29:38 -0800534 EXPECT_FALSE(send_config->rtp.extensions.empty());
535 if (!header_extensions_enabled_) {
536 send_config->rtp.extensions.clear();
537 } else {
Stefan Holmer4654d202015-12-08 09:10:43 +0100538 send_config->rtp.extensions.push_back(RtpExtension(
isheriff6f8d6862016-05-26 11:24:55 -0700539 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
Stefan Holmer4654d202015-12-08 09:10:43 +0100540 }
nisse3b3622f2017-09-26 02:49:21 -0700541 (*receive_configs)[0].rtp.red_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700542 send_config->rtp.ulpfec.red_payload_type;
nisse3b3622f2017-09-26 02:49:21 -0700543 (*receive_configs)[0].rtp.ulpfec_payload_type =
brandtrb5f2c3f2016-10-04 23:28:39 -0700544 send_config->rtp.ulpfec.ulpfec_payload_type;
Stefan Holmer4654d202015-12-08 09:10:43 +0100545 }
546
547 void PerformTest() override {
brandtr20d45472017-01-02 00:34:27 -0800548 EXPECT_EQ(expect_ulpfec_, Wait())
549 << "Timed out waiting for ULPFEC and/or media packets.";
Stefan Holmer4654d202015-12-08 09:10:43 +0100550 }
551
brandtr696c9c62016-12-19 05:47:28 -0800552 VideoEncoder* const encoder_;
553 std::string payload_name_;
Peter Boström39593972016-02-15 11:27:15 +0100554 const bool use_nack_;
555 const bool expect_red_;
brandtre602f0a2016-10-31 03:40:49 -0700556 const bool expect_ulpfec_;
brandtr65a1e772016-12-12 01:54:58 -0800557 bool sent_media_;
558 bool sent_ulpfec_;
Stefan Holmer4654d202015-12-08 09:10:43 +0100559 bool header_extensions_enabled_;
560 RTPHeader prev_header_;
561};
562
brandtre602f0a2016-10-31 03:40:49 -0700563TEST_F(VideoSendStreamTest, SupportsUlpfecWithExtensions) {
brandtr696c9c62016-12-19 05:47:28 -0800564 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
565 UlpfecObserver test(true, false, true, true, "VP8", encoder.get());
stefane74eef12016-01-08 06:47:13 -0800566 RunBaseTest(&test);
Stefan Holmer4654d202015-12-08 09:10:43 +0100567}
568
brandtre602f0a2016-10-31 03:40:49 -0700569TEST_F(VideoSendStreamTest, SupportsUlpfecWithoutExtensions) {
brandtr696c9c62016-12-19 05:47:28 -0800570 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
571 UlpfecObserver test(false, false, true, true, "VP8", encoder.get());
Peter Boström39593972016-02-15 11:27:15 +0100572 RunBaseTest(&test);
573}
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000574
stefan60e10c72017-08-23 10:40:00 -0700575class VideoSendStreamWithoutUlpfecTest : public VideoSendStreamTest {
576 protected:
577 VideoSendStreamWithoutUlpfecTest()
578 : field_trial_("WebRTC-DisableUlpFecExperiment/Enabled/") {}
579
580 test::ScopedFieldTrials field_trial_;
581};
582
583TEST_F(VideoSendStreamWithoutUlpfecTest, NoUlpfecIfDisabledThroughFieldTrial) {
584 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
585 UlpfecObserver test(false, false, true, false, "VP8", encoder.get());
586 RunBaseTest(&test);
587}
588
Peter Boström39593972016-02-15 11:27:15 +0100589// The FEC scheme used is not efficient for H264, so we should not use RED/FEC
590// since we'll still have to re-request FEC packets, effectively wasting
591// bandwidth since the receiver has to wait for FEC retransmissions to determine
592// that the received state is actually decodable.
brandtre602f0a2016-10-31 03:40:49 -0700593TEST_F(VideoSendStreamTest, DoesNotUtilizeUlpfecForH264WithNackEnabled) {
brandtr696c9c62016-12-19 05:47:28 -0800594 std::unique_ptr<VideoEncoder> encoder(
595 new test::FakeH264Encoder(Clock::GetRealTimeClock()));
596 UlpfecObserver test(false, true, true, false, "H264", encoder.get());
Peter Boström39593972016-02-15 11:27:15 +0100597 RunBaseTest(&test);
598}
599
600// Without retransmissions FEC for H264 is fine.
brandtre6f98c72016-11-11 03:28:30 -0800601TEST_F(VideoSendStreamTest, DoesUtilizeUlpfecForH264WithoutNackEnabled) {
brandtr696c9c62016-12-19 05:47:28 -0800602 std::unique_ptr<VideoEncoder> encoder(
603 new test::FakeH264Encoder(Clock::GetRealTimeClock()));
604 UlpfecObserver test(false, false, true, true, "H264", encoder.get());
Peter Boström39593972016-02-15 11:27:15 +0100605 RunBaseTest(&test);
606}
607
danilchap9f5b6222017-03-02 06:22:21 -0800608// Disabled as flaky, see https://crbug.com/webrtc/7285 for details.
609TEST_F(VideoSendStreamTest, DISABLED_DoesUtilizeUlpfecForVp8WithNackEnabled) {
brandtr696c9c62016-12-19 05:47:28 -0800610 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
611 UlpfecObserver test(false, true, true, true, "VP8", encoder.get());
Peter Boström39593972016-02-15 11:27:15 +0100612 RunBaseTest(&test);
613}
614
Peter Boström12996152016-05-14 02:03:18 +0200615#if !defined(RTC_DISABLE_VP9)
danilchap9f5b6222017-03-02 06:22:21 -0800616// Disabled as flaky, see https://crbug.com/webrtc/7285 for details.
617TEST_F(VideoSendStreamTest, DISABLED_DoesUtilizeUlpfecForVp9WithNackEnabled) {
brandtr696c9c62016-12-19 05:47:28 -0800618 std::unique_ptr<VideoEncoder> encoder(VP9Encoder::Create());
619 UlpfecObserver test(false, true, true, true, "VP9", encoder.get());
stefane74eef12016-01-08 06:47:13 -0800620 RunBaseTest(&test);
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000621}
Peter Boström12996152016-05-14 02:03:18 +0200622#endif // !defined(RTC_DISABLE_VP9)
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000623
brandtre78d2662017-01-16 05:57:16 -0800624TEST_F(VideoSendStreamTest, SupportsUlpfecWithMultithreadedH264) {
brandtr696c9c62016-12-19 05:47:28 -0800625 std::unique_ptr<VideoEncoder> encoder(
brandtre78d2662017-01-16 05:57:16 -0800626 new test::MultithreadedFakeH264Encoder(Clock::GetRealTimeClock()));
brandtr696c9c62016-12-19 05:47:28 -0800627 UlpfecObserver test(false, false, true, true, "H264", encoder.get());
628 RunBaseTest(&test);
629}
630
brandtr39f97292016-11-16 22:57:50 -0800631// TODO(brandtr): Move these FlexFEC tests when we have created
632// FlexfecSendStream.
633class FlexfecObserver : public test::EndToEndTest {
634 public:
635 FlexfecObserver(bool header_extensions_enabled,
636 bool use_nack,
brandtr696c9c62016-12-19 05:47:28 -0800637 const std::string& codec,
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100638 VideoEncoder* encoder,
639 size_t num_video_streams)
brandtr39f97292016-11-16 22:57:50 -0800640 : EndToEndTest(VideoSendStreamTest::kDefaultTimeoutMs),
brandtr696c9c62016-12-19 05:47:28 -0800641 encoder_(encoder),
brandtr39f97292016-11-16 22:57:50 -0800642 payload_name_(codec),
643 use_nack_(use_nack),
brandtr39f97292016-11-16 22:57:50 -0800644 sent_media_(false),
645 sent_flexfec_(false),
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100646 header_extensions_enabled_(header_extensions_enabled),
647 num_video_streams_(num_video_streams) {}
brandtr39f97292016-11-16 22:57:50 -0800648
649 size_t GetNumFlexfecStreams() const override { return 1; }
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100650 size_t GetNumVideoStreams() const override { return num_video_streams_; }
brandtr39f97292016-11-16 22:57:50 -0800651
652 private:
653 Action OnSendRtp(const uint8_t* packet, size_t length) override {
654 RTPHeader header;
655 EXPECT_TRUE(parser_->Parse(packet, length, &header));
656
brandtr39f97292016-11-16 22:57:50 -0800657 if (header.payloadType == VideoSendStreamTest::kFlexfecPayloadType) {
658 EXPECT_EQ(VideoSendStreamTest::kFlexfecSendSsrc, header.ssrc);
659 sent_flexfec_ = true;
660 } else {
661 EXPECT_EQ(VideoSendStreamTest::kFakeVideoSendPayloadType,
662 header.payloadType);
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100663 EXPECT_THAT(testing::make_tuple(VideoSendStreamTest::kVideoSendSsrcs,
664 num_video_streams_),
665 testing::Contains(header.ssrc));
brandtr39f97292016-11-16 22:57:50 -0800666 sent_media_ = true;
667 }
668
669 if (header_extensions_enabled_) {
670 EXPECT_TRUE(header.extension.hasAbsoluteSendTime);
671 EXPECT_TRUE(header.extension.hasTransmissionTimeOffset);
672 EXPECT_TRUE(header.extension.hasTransportSequenceNumber);
673 }
674
brandtr0c5a1542016-11-23 04:42:26 -0800675 if (sent_media_ && sent_flexfec_) {
brandtr39f97292016-11-16 22:57:50 -0800676 observation_complete_.Set();
677 }
678
679 return SEND_PACKET;
680 }
681
eladalon413ee9a2017-08-22 04:02:52 -0700682 test::PacketTransport* CreateSendTransport(
683 test::SingleThreadedTaskQueueForTesting* task_queue,
684 Call* sender_call) override {
brandtr39f97292016-11-16 22:57:50 -0800685 // At low RTT (< kLowRttNackMs) -> NACK only, no FEC.
686 // Therefore we need some network delay.
687 const int kNetworkDelayMs = 100;
688 FakeNetworkPipe::Config config;
brandtrd654a9b2016-12-05 05:38:19 -0800689 config.loss_percent = 5;
brandtr39f97292016-11-16 22:57:50 -0800690 config.queue_delay_ms = kNetworkDelayMs;
minyue20c84cc2017-04-10 16:57:57 -0700691 return new test::PacketTransport(
eladalon413ee9a2017-08-22 04:02:52 -0700692 task_queue, sender_call, this, test::PacketTransport::kSender,
minyue20c84cc2017-04-10 16:57:57 -0700693 VideoSendStreamTest::payload_type_map_, config);
brandtr39f97292016-11-16 22:57:50 -0800694 }
695
696 void ModifyVideoConfigs(
697 VideoSendStream::Config* send_config,
698 std::vector<VideoReceiveStream::Config>* receive_configs,
699 VideoEncoderConfig* encoder_config) override {
brandtr39f97292016-11-16 22:57:50 -0800700 if (use_nack_) {
701 send_config->rtp.nack.rtp_history_ms =
702 (*receive_configs)[0].rtp.nack.rtp_history_ms =
703 VideoSendStreamTest::kNackRtpHistoryMs;
704 }
brandtr696c9c62016-12-19 05:47:28 -0800705 send_config->encoder_settings.encoder = encoder_;
brandtr39f97292016-11-16 22:57:50 -0800706 send_config->encoder_settings.payload_name = payload_name_;
707 if (header_extensions_enabled_) {
708 send_config->rtp.extensions.push_back(RtpExtension(
709 RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId));
710 send_config->rtp.extensions.push_back(RtpExtension(
711 RtpExtension::kTimestampOffsetUri, test::kTOffsetExtensionId));
stefanb77c7162017-02-06 06:29:38 -0800712 } else {
713 send_config->rtp.extensions.clear();
brandtr39f97292016-11-16 22:57:50 -0800714 }
715 }
716
717 void PerformTest() override {
718 EXPECT_TRUE(Wait())
719 << "Timed out waiting for FlexFEC and/or media packets.";
720 }
721
brandtr696c9c62016-12-19 05:47:28 -0800722 VideoEncoder* const encoder_;
723 std::string payload_name_;
brandtr39f97292016-11-16 22:57:50 -0800724 const bool use_nack_;
brandtr39f97292016-11-16 22:57:50 -0800725 bool sent_media_;
726 bool sent_flexfec_;
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100727 const bool header_extensions_enabled_;
728 const size_t num_video_streams_;
brandtr39f97292016-11-16 22:57:50 -0800729};
730
brandtrd654a9b2016-12-05 05:38:19 -0800731TEST_F(VideoSendStreamTest, SupportsFlexfecVp8) {
brandtr696c9c62016-12-19 05:47:28 -0800732 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100733 FlexfecObserver test(false, false, "VP8", encoder.get(), 1);
734 RunBaseTest(&test);
735}
736
737TEST_F(VideoSendStreamTest, SupportsFlexfecSimulcastVp8) {
738 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
739 FlexfecObserver test(false, false, "VP8", encoder.get(), 2);
brandtrd654a9b2016-12-05 05:38:19 -0800740 RunBaseTest(&test);
741}
742
743TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackVp8) {
brandtr696c9c62016-12-19 05:47:28 -0800744 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100745 FlexfecObserver test(false, true, "VP8", encoder.get(), 1);
brandtrd654a9b2016-12-05 05:38:19 -0800746 RunBaseTest(&test);
747}
748
brandtr39f97292016-11-16 22:57:50 -0800749TEST_F(VideoSendStreamTest, SupportsFlexfecWithRtpExtensionsVp8) {
brandtr696c9c62016-12-19 05:47:28 -0800750 std::unique_ptr<VideoEncoder> encoder(VP8Encoder::Create());
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100751 FlexfecObserver test(true, false, "VP8", encoder.get(), 1);
brandtr39f97292016-11-16 22:57:50 -0800752 RunBaseTest(&test);
753}
754
brandtr39f97292016-11-16 22:57:50 -0800755#if !defined(RTC_DISABLE_VP9)
brandtrd654a9b2016-12-05 05:38:19 -0800756TEST_F(VideoSendStreamTest, SupportsFlexfecVp9) {
brandtr696c9c62016-12-19 05:47:28 -0800757 std::unique_ptr<VideoEncoder> encoder(VP9Encoder::Create());
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100758 FlexfecObserver test(false, false, "VP9", encoder.get(), 1);
brandtr39f97292016-11-16 22:57:50 -0800759 RunBaseTest(&test);
760}
761
brandtrd654a9b2016-12-05 05:38:19 -0800762TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackVp9) {
brandtr696c9c62016-12-19 05:47:28 -0800763 std::unique_ptr<VideoEncoder> encoder(VP9Encoder::Create());
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100764 FlexfecObserver test(false, true, "VP9", encoder.get(), 1);
brandtr39f97292016-11-16 22:57:50 -0800765 RunBaseTest(&test);
766}
767#endif // defined(RTC_DISABLE_VP9)
768
brandtrd654a9b2016-12-05 05:38:19 -0800769TEST_F(VideoSendStreamTest, SupportsFlexfecH264) {
brandtr696c9c62016-12-19 05:47:28 -0800770 std::unique_ptr<VideoEncoder> encoder(
771 new test::FakeH264Encoder(Clock::GetRealTimeClock()));
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100772 FlexfecObserver test(false, false, "H264", encoder.get(), 1);
brandtr39f97292016-11-16 22:57:50 -0800773 RunBaseTest(&test);
774}
775
brandtrd654a9b2016-12-05 05:38:19 -0800776TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackH264) {
brandtr696c9c62016-12-19 05:47:28 -0800777 std::unique_ptr<VideoEncoder> encoder(
778 new test::FakeH264Encoder(Clock::GetRealTimeClock()));
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100779 FlexfecObserver test(false, true, "H264", encoder.get(), 1);
brandtr696c9c62016-12-19 05:47:28 -0800780 RunBaseTest(&test);
781}
782
brandtre78d2662017-01-16 05:57:16 -0800783TEST_F(VideoSendStreamTest, SupportsFlexfecWithMultithreadedH264) {
brandtr696c9c62016-12-19 05:47:28 -0800784 std::unique_ptr<VideoEncoder> encoder(
brandtre78d2662017-01-16 05:57:16 -0800785 new test::MultithreadedFakeH264Encoder(Clock::GetRealTimeClock()));
Danil Chapovalov45d725d2018-02-19 19:09:53 +0100786 FlexfecObserver test(false, false, "H264", encoder.get(), 1);
brandtr39f97292016-11-16 22:57:50 -0800787 RunBaseTest(&test);
788}
789
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000790void VideoSendStreamTest::TestNackRetransmission(
791 uint32_t retransmit_ssrc,
stefan@webrtc.orgcb254aa2014-06-12 15:12:25 +0000792 uint8_t retransmit_payload_type) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000793 class NackObserver : public test::SendTest {
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000794 public:
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000795 explicit NackObserver(uint32_t retransmit_ssrc,
796 uint8_t retransmit_payload_type)
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000797 : SendTest(kDefaultTimeoutMs),
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000798 send_count_(0),
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000799 retransmit_ssrc_(retransmit_ssrc),
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000800 retransmit_payload_type_(retransmit_payload_type),
sprang@webrtc.orgd9b95602014-01-27 13:03:02 +0000801 nacked_sequence_number_(-1) {
sprang@webrtc.orgd9b95602014-01-27 13:03:02 +0000802 }
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000803
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000804 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000805 Action OnSendRtp(const uint8_t* packet, size_t length) override {
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000806 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +0000807 EXPECT_TRUE(parser_->Parse(packet, length, &header));
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000808
809 // Nack second packet after receiving the third one.
810 if (++send_count_ == 3) {
pbos@webrtc.orge7223e72014-01-23 16:14:34 +0000811 uint16_t nack_sequence_number = header.sequenceNumber - 1;
812 nacked_sequence_number_ = nack_sequence_number;
danilchap8a1d2a32017-08-01 03:21:37 -0700813 RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(), nullptr,
Jiawei Ou3587b832018-01-31 22:08:26 -0800814 nullptr, nullptr, transport_adapter_.get(),
815 RtcpIntervalConfig{});
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000816
pbosda903ea2015-10-02 02:36:56 -0700817 rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize);
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100818 rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]);
pbos@webrtc.org0e63e762013-09-20 11:56:26 +0000819
820 RTCPSender::FeedbackState feedback_state;
821
822 EXPECT_EQ(0,
823 rtcp_sender.SendRTCP(
pbos@webrtc.orge7223e72014-01-23 16:14:34 +0000824 feedback_state, kRtcpNack, 1, &nack_sequence_number));
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000825 }
826
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000827 uint16_t sequence_number = header.sequenceNumber;
828
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000829 if (header.ssrc == retransmit_ssrc_ &&
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100830 retransmit_ssrc_ != kVideoSendSsrcs[0]) {
831 // Not kVideoSendSsrcs[0], assume correct RTX packet. Extract sequence
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000832 // number.
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000833 const uint8_t* rtx_header = packet + header.headerLength;
834 sequence_number = (rtx_header[0] << 8) + rtx_header[1];
835 }
836
837 if (sequence_number == nacked_sequence_number_) {
838 EXPECT_EQ(retransmit_ssrc_, header.ssrc);
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000839 EXPECT_EQ(retransmit_payload_type_, header.payloadType);
Peter Boström5811a392015-12-10 13:02:50 +0100840 observation_complete_.Set();
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000841 }
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000842
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000843 return SEND_PACKET;
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000844 }
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +0000845
stefanff483612015-12-21 03:14:00 -0800846 void ModifyVideoConfigs(
847 VideoSendStream::Config* send_config,
848 std::vector<VideoReceiveStream::Config>* receive_configs,
849 VideoEncoderConfig* encoder_config) override {
stefanf116bd02015-10-27 08:29:42 -0700850 transport_adapter_.reset(
851 new internal::TransportAdapter(send_config->send_transport));
852 transport_adapter_->Enable();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +0000853 send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000854 send_config->rtp.rtx.payload_type = retransmit_payload_type_;
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100855 if (retransmit_ssrc_ != kVideoSendSsrcs[0])
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000856 send_config->rtp.rtx.ssrcs.push_back(retransmit_ssrc_);
857 }
858
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000859 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +0100860 EXPECT_TRUE(Wait()) << "Timed out while waiting for NACK retransmission.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000861 }
862
kwiberg27f982b2016-03-01 11:52:33 -0800863 std::unique_ptr<internal::TransportAdapter> transport_adapter_;
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000864 int send_count_;
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000865 uint32_t retransmit_ssrc_;
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000866 uint8_t retransmit_payload_type_;
pbos@webrtc.orge7223e72014-01-23 16:14:34 +0000867 int nacked_sequence_number_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000868 } test(retransmit_ssrc, retransmit_payload_type);
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000869
stefane74eef12016-01-08 06:47:13 -0800870 RunBaseTest(&test);
pbos@webrtc.orgdf531a22013-09-10 14:56:33 +0000871}
872
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000873TEST_F(VideoSendStreamTest, RetransmitsNack) {
874 // Normal NACKs should use the send SSRC.
Stefan Holmer9fea80f2016-01-07 17:43:18 +0100875 TestNackRetransmission(kVideoSendSsrcs[0], kFakeVideoSendPayloadType);
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000876}
877
878TEST_F(VideoSendStreamTest, RetransmitsNackOverRtx) {
879 // NACKs over RTX should use a separate SSRC.
pbos@webrtc.org2bb1bda2014-07-07 13:06:48 +0000880 TestNackRetransmission(kSendRtxSsrcs[0], kSendRtxPayloadType);
pbos@webrtc.org5860de02013-09-16 13:01:47 +0000881}
882
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000883void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format,
884 bool with_fec) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000885 // Use a fake encoder to output a frame of every size in the range [90, 290],
886 // for each size making sure that the exact number of payload bytes received
887 // is correct and that packets are fragmented to respect max packet size.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000888 static const size_t kMaxPacketSize = 128;
889 static const size_t start = 90;
890 static const size_t stop = 290;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000891
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000892 // Observer that verifies that the expected number of packets and bytes
893 // arrive for each frame size, from start_size to stop_size.
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000894 class FrameFragmentationTest : public test::SendTest,
895 public EncodedFrameObserver {
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000896 public:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000897 FrameFragmentationTest(size_t max_packet_size,
898 size_t start_size,
899 size_t stop_size,
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000900 bool test_generic_packetization,
901 bool use_fec)
902 : SendTest(kLongTimeoutMs),
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000903 encoder_(stop),
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000904 max_packet_size_(max_packet_size),
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000905 stop_size_(stop_size),
906 test_generic_packetization_(test_generic_packetization),
907 use_fec_(use_fec),
908 packet_count_(0),
Sebastian Jansson56fa0502018-02-01 13:00:57 +0100909 packets_lost_(0),
910 last_packet_count_(0),
911 last_packets_lost_(0),
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000912 accumulated_size_(0),
913 accumulated_payload_(0),
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000914 fec_packet_received_(false),
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000915 current_size_rtp_(start_size),
Yuwei Huangd9f99c12017-10-24 15:40:52 -0700916 current_size_frame_(static_cast<int>(start_size)) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000917 // Fragmentation required, this test doesn't make sense without it.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000918 encoder_.SetFrameSize(start_size);
henrikg91d6ede2015-09-17 00:24:34 -0700919 RTC_DCHECK_GT(stop_size, max_packet_size);
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000920 }
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000921
pbos@webrtc.org994d0b72014-06-27 08:47:52 +0000922 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000923 Action OnSendRtp(const uint8_t* packet, size_t size) override {
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000924 size_t length = size;
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000925 RTPHeader header;
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000926 EXPECT_TRUE(parser_->Parse(packet, length, &header));
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000927
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000928 EXPECT_LE(length, max_packet_size_);
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000929
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000930 if (use_fec_) {
931 uint8_t payload_type = packet[header.headerLength];
932 bool is_fec = header.payloadType == kRedPayloadType &&
933 payload_type == kUlpfecPayloadType;
934 if (is_fec) {
935 fec_packet_received_ = true;
936 return SEND_PACKET;
937 }
938 }
939
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000940 accumulated_size_ += length;
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000941
942 if (use_fec_)
943 TriggerLossReport(header);
944
945 if (test_generic_packetization_) {
Stefan Holmer586b19b2015-09-18 11:14:31 +0200946 size_t overhead = header.headerLength + header.paddingLength;
947 // Only remove payload header and RED header if the packet actually
948 // contains payload.
949 if (length > overhead) {
950 overhead += (1 /* Generic header */);
951 if (use_fec_)
952 overhead += 1; // RED for FEC header.
953 }
954 EXPECT_GE(length, overhead);
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000955 accumulated_payload_ += length - overhead;
956 }
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000957
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000958 // Marker bit set indicates last packet of a frame.
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000959 if (header.markerBit) {
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000960 if (use_fec_ && accumulated_payload_ == current_size_rtp_ - 1) {
961 // With FEC enabled, frame size is incremented asynchronously, so
962 // "old" frames one byte too small may arrive. Accept, but don't
963 // increase expected frame size.
964 accumulated_size_ = 0;
965 accumulated_payload_ = 0;
966 return SEND_PACKET;
967 }
968
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000969 EXPECT_GE(accumulated_size_, current_size_rtp_);
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000970 if (test_generic_packetization_) {
971 EXPECT_EQ(current_size_rtp_, accumulated_payload_);
972 }
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000973
974 // Last packet of frame; reset counters.
975 accumulated_size_ = 0;
976 accumulated_payload_ = 0;
977 if (current_size_rtp_ == stop_size_) {
978 // Done! (Don't increase size again, might arrive more @ stop_size).
Peter Boström5811a392015-12-10 13:02:50 +0100979 observation_complete_.Set();
sprang@webrtc.org8b881922013-12-10 10:05:17 +0000980 } else {
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000981 // Increase next expected frame size. If testing with FEC, make sure
982 // a FEC packet has been received for this frame size before
983 // proceeding, to make sure that redundancy packets don't exceed
984 // size limit.
985 if (!use_fec_) {
986 ++current_size_rtp_;
987 } else if (fec_packet_received_) {
988 fec_packet_received_ = false;
989 ++current_size_rtp_;
Yuwei Huangd9f99c12017-10-24 15:40:52 -0700990
991 rtc::CritScope lock(&mutex_);
sprang@webrtc.org346094c2014-02-18 08:40:33 +0000992 ++current_size_frame_;
993 }
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000994 }
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000995 }
996
stefan@webrtc.org69969e22013-11-15 12:32:15 +0000997 return SEND_PACKET;
sprang@webrtc.org5d957e22013-10-16 11:37:54 +0000998 }
999
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001000 void TriggerLossReport(const RTPHeader& header) {
1001 // Send lossy receive reports to trigger FEC enabling.
sprang4847ae62017-06-27 07:06:52 -07001002 const int kLossPercent = 5;
Sebastian Jansson56fa0502018-02-01 13:00:57 +01001003 if (++packet_count_ % (100 / kLossPercent) == 0) {
1004 packets_lost_++;
1005 int loss_delta = packets_lost_ - last_packets_lost_;
1006 int packets_delta = packet_count_ - last_packet_count_;
1007 last_packet_count_ = packet_count_;
1008 last_packets_lost_ = packets_lost_;
1009 uint8_t loss_ratio =
1010 static_cast<uint8_t>(loss_delta * 255 / packets_delta);
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001011 FakeReceiveStatistics lossy_receive_stats(
sprang4847ae62017-06-27 07:06:52 -07001012 kVideoSendSsrcs[0], header.sequenceNumber,
Sebastian Jansson56fa0502018-02-01 13:00:57 +01001013 packets_lost_, // Cumulative lost.
1014 loss_ratio); // Loss percent.
Peter Boströmac547a62015-09-17 23:03:57 +02001015 RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(),
terelius429c3452016-01-21 05:42:04 -08001016 &lossy_receive_stats, nullptr, nullptr,
Jiawei Ou3587b832018-01-31 22:08:26 -08001017 transport_adapter_.get(), RtcpIntervalConfig{});
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001018
pbosda903ea2015-10-02 02:36:56 -07001019 rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize);
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001020 rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]);
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001021
1022 RTCPSender::FeedbackState feedback_state;
1023
1024 EXPECT_EQ(0, rtcp_sender.SendRTCP(feedback_state, kRtcpRr));
1025 }
1026 }
1027
nisseef8b61e2016-04-29 06:09:15 -07001028 void EncodedFrameCallback(const EncodedFrame& encoded_frame) override {
Yuwei Huangd9f99c12017-10-24 15:40:52 -07001029 rtc::CritScope lock(&mutex_);
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001030 // Increase frame size for next encoded frame, in the context of the
1031 // encoder thread.
Yuwei Huangd9f99c12017-10-24 15:40:52 -07001032 if (!use_fec_ && current_size_frame_ < static_cast<int32_t>(stop_size_)) {
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001033 ++current_size_frame_;
1034 }
Yuwei Huangd9f99c12017-10-24 15:40:52 -07001035 encoder_.SetFrameSize(static_cast<size_t>(current_size_frame_));
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001036 }
1037
Stefan Holmere5904162015-03-26 11:11:06 +01001038 Call::Config GetSenderCallConfig() override {
philipel4fb651d2017-04-10 03:54:05 -07001039 Call::Config config(event_log_.get());
Stefan Holmere5904162015-03-26 11:11:06 +01001040 const int kMinBitrateBps = 30000;
1041 config.bitrate_config.min_bitrate_bps = kMinBitrateBps;
1042 return config;
1043 }
1044
stefanff483612015-12-21 03:14:00 -08001045 void ModifyVideoConfigs(
1046 VideoSendStream::Config* send_config,
1047 std::vector<VideoReceiveStream::Config>* receive_configs,
1048 VideoEncoderConfig* encoder_config) override {
stefanf116bd02015-10-27 08:29:42 -07001049 transport_adapter_.reset(
1050 new internal::TransportAdapter(send_config->send_transport));
1051 transport_adapter_->Enable();
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001052 if (use_fec_) {
brandtrb5f2c3f2016-10-04 23:28:39 -07001053 send_config->rtp.ulpfec.red_payload_type = kRedPayloadType;
1054 send_config->rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001055 }
1056
1057 if (!test_generic_packetization_)
1058 send_config->encoder_settings.payload_name = "VP8";
1059
1060 send_config->encoder_settings.encoder = &encoder_;
1061 send_config->rtp.max_packet_size = kMaxPacketSize;
1062 send_config->post_encode_callback = this;
1063
Erik Språng95261872015-04-10 11:58:49 +02001064 // Make sure there is at least one extension header, to make the RTP
1065 // header larger than the base length of 12 bytes.
1066 EXPECT_FALSE(send_config->rtp.extensions.empty());
sprang4847ae62017-06-27 07:06:52 -07001067
1068 // Setup screen content disables frame dropping which makes this easier.
1069 class VideoStreamFactory
1070 : public VideoEncoderConfig::VideoStreamFactoryInterface {
1071 public:
1072 explicit VideoStreamFactory(size_t num_temporal_layers)
1073 : num_temporal_layers_(num_temporal_layers) {
1074 EXPECT_GT(num_temporal_layers, 0u);
1075 }
1076
1077 private:
1078 std::vector<VideoStream> CreateEncoderStreams(
1079 int width,
1080 int height,
1081 const VideoEncoderConfig& encoder_config) override {
1082 std::vector<VideoStream> streams =
1083 test::CreateVideoStreams(width, height, encoder_config);
1084 for (VideoStream& stream : streams) {
1085 stream.temporal_layer_thresholds_bps.resize(num_temporal_layers_ -
1086 1);
1087 }
1088 return streams;
1089 }
1090 const size_t num_temporal_layers_;
1091 };
1092
1093 encoder_config->video_stream_factory =
1094 new rtc::RefCountedObject<VideoStreamFactory>(2);
1095 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001096 }
1097
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001098 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01001099 EXPECT_TRUE(Wait()) << "Timed out while observing incoming RTP packets.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001100 }
1101
kwiberg27f982b2016-03-01 11:52:33 -08001102 std::unique_ptr<internal::TransportAdapter> transport_adapter_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001103 test::ConfigurableFrameSizeEncoder encoder_;
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001104
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001105 const size_t max_packet_size_;
1106 const size_t stop_size_;
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001107 const bool test_generic_packetization_;
1108 const bool use_fec_;
1109
1110 uint32_t packet_count_;
Sebastian Jansson56fa0502018-02-01 13:00:57 +01001111 uint32_t packets_lost_;
1112 uint32_t last_packet_count_;
1113 uint32_t last_packets_lost_;
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001114 size_t accumulated_size_;
1115 size_t accumulated_payload_;
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001116 bool fec_packet_received_;
1117
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +00001118 size_t current_size_rtp_;
Yuwei Huangd9f99c12017-10-24 15:40:52 -07001119 rtc::CriticalSection mutex_;
1120 int current_size_frame_ RTC_GUARDED_BY(mutex_);
sprang@webrtc.org5d957e22013-10-16 11:37:54 +00001121 };
1122
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001123 // Don't auto increment if FEC is used; continue sending frame size until
1124 // a FEC packet has been received.
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001125 FrameFragmentationTest test(
1126 kMaxPacketSize, start, stop, format == kGeneric, with_fec);
sprang@webrtc.org8b881922013-12-10 10:05:17 +00001127
stefane74eef12016-01-08 06:47:13 -08001128 RunBaseTest(&test);
sprang@webrtc.org5d957e22013-10-16 11:37:54 +00001129}
1130
sprang@webrtc.org346094c2014-02-18 08:40:33 +00001131// TODO(sprang): Is there any way of speeding up these tests?
1132TEST_F(VideoSendStreamTest, FragmentsGenericAccordingToMaxPacketSize) {
1133 TestPacketFragmentationSize(kGeneric, false);
1134}
1135
1136TEST_F(VideoSendStreamTest, FragmentsGenericAccordingToMaxPacketSizeWithFec) {
1137 TestPacketFragmentationSize(kGeneric, true);
1138}
1139
1140TEST_F(VideoSendStreamTest, FragmentsVp8AccordingToMaxPacketSize) {
1141 TestPacketFragmentationSize(kVP8, false);
1142}
1143
1144TEST_F(VideoSendStreamTest, FragmentsVp8AccordingToMaxPacketSizeWithFec) {
1145 TestPacketFragmentationSize(kVP8, true);
1146}
1147
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001148// The test will go through a number of phases.
1149// 1. Start sending packets.
1150// 2. As soon as the RTP stream has been detected, signal a low REMB value to
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001151// suspend the stream.
1152// 3. Wait until |kSuspendTimeFrames| have been captured without seeing any RTP
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001153// packets.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001154// 4. Signal a high REMB and then wait for the RTP stream to start again.
henrik.lundin@webrtc.orged8b2812014-03-18 08:43:29 +00001155// When the stream is detected again, and the stats show that the stream
1156// is no longer suspended, the test ends.
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001157TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) {
1158 static const int kSuspendTimeFrames = 60; // Suspend for 2 seconds @ 30 fps.
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001159
nissed30a1112016-04-18 05:15:22 -07001160 class RembObserver : public test::SendTest,
1161 public rtc::VideoSinkInterface<VideoFrame> {
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001162 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001163 RembObserver()
1164 : SendTest(kDefaultTimeoutMs),
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001165 clock_(Clock::GetRealTimeClock()),
Erik Språng737336d2016-07-29 12:59:36 +02001166 stream_(nullptr),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001167 test_state_(kBeforeSuspend),
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001168 rtp_count_(0),
1169 last_sequence_number_(0),
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001170 suspended_frame_count_(0),
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +00001171 low_remb_bps_(0),
Erik Språng737336d2016-07-29 12:59:36 +02001172 high_remb_bps_(0) {}
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001173
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001174 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001175 Action OnSendRtp(const uint8_t* packet, size_t length) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02001176 rtc::CritScope lock(&crit_);
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001177 ++rtp_count_;
1178 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +00001179 EXPECT_TRUE(parser_->Parse(packet, length, &header));
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001180 last_sequence_number_ = header.sequenceNumber;
1181
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001182 if (test_state_ == kBeforeSuspend) {
1183 // The stream has started. Try to suspend it.
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +00001184 SendRtcpFeedback(low_remb_bps_);
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001185 test_state_ = kDuringSuspend;
1186 } else if (test_state_ == kDuringSuspend) {
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +00001187 if (header.paddingLength == 0) {
1188 // Received non-padding packet during suspension period. Reset the
1189 // counter.
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +00001190 suspended_frame_count_ = 0;
1191 }
stefanf116bd02015-10-27 08:29:42 -07001192 SendRtcpFeedback(0); // REMB is only sent if value is > 0.
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001193 } else if (test_state_ == kWaitingForPacket) {
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +00001194 if (header.paddingLength == 0) {
henrik.lundin@webrtc.orged8b2812014-03-18 08:43:29 +00001195 // Non-padding packet observed. Test is almost complete. Will just
1196 // have to wait for the stats to change.
1197 test_state_ = kWaitingForStats;
1198 }
stefanf116bd02015-10-27 08:29:42 -07001199 SendRtcpFeedback(0); // REMB is only sent if value is > 0.
henrik.lundin@webrtc.orged8b2812014-03-18 08:43:29 +00001200 } else if (test_state_ == kWaitingForStats) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001201 VideoSendStream::Stats stats = stream_->GetStats();
henrik.lundin@webrtc.orged8b2812014-03-18 08:43:29 +00001202 if (stats.suspended == false) {
1203 // Stats flipped to false. Test is complete.
Peter Boström5811a392015-12-10 13:02:50 +01001204 observation_complete_.Set();
henrik.lundin@webrtc.org331d4402013-11-21 14:05:40 +00001205 }
stefanf116bd02015-10-27 08:29:42 -07001206 SendRtcpFeedback(0); // REMB is only sent if value is > 0.
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001207 }
1208
stefan@webrtc.org69969e22013-11-15 12:32:15 +00001209 return SEND_PACKET;
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001210 }
1211
perkj26091b12016-09-01 01:17:40 -07001212 // This method implements the rtc::VideoSinkInterface. This is called when
1213 // a frame is provided to the VideoSendStream.
nissed30a1112016-04-18 05:15:22 -07001214 void OnFrame(const VideoFrame& video_frame) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02001215 rtc::CritScope lock(&crit_);
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001216 if (test_state_ == kDuringSuspend &&
1217 ++suspended_frame_count_ > kSuspendTimeFrames) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001218 VideoSendStream::Stats stats = stream_->GetStats();
henrik.lundin@webrtc.orgb10363f2014-03-13 13:31:21 +00001219 EXPECT_TRUE(stats.suspended);
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +00001220 SendRtcpFeedback(high_remb_bps_);
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001221 test_state_ = kWaitingForPacket;
1222 }
1223 }
1224
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001225 void set_low_remb_bps(int value) {
Peter Boströmf2f82832015-05-01 13:00:41 +02001226 rtc::CritScope lock(&crit_);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001227 low_remb_bps_ = value;
1228 }
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +00001229
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001230 void set_high_remb_bps(int value) {
Peter Boströmf2f82832015-05-01 13:00:41 +02001231 rtc::CritScope lock(&crit_);
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001232 high_remb_bps_ = value;
1233 }
henrik.lundin@webrtc.org1a3a6e52013-10-28 10:16:14 +00001234
stefanff483612015-12-21 03:14:00 -08001235 void OnVideoStreamsCreated(
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +00001236 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001237 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001238 stream_ = send_stream;
1239 }
1240
stefanff483612015-12-21 03:14:00 -08001241 void ModifyVideoConfigs(
1242 VideoSendStream::Config* send_config,
1243 std::vector<VideoReceiveStream::Config>* receive_configs,
1244 VideoEncoderConfig* encoder_config) override {
kwibergaf476c72016-11-28 15:21:39 -08001245 RTC_DCHECK_EQ(1, encoder_config->number_of_streams);
stefanf116bd02015-10-27 08:29:42 -07001246 transport_adapter_.reset(
1247 new internal::TransportAdapter(send_config->send_transport));
1248 transport_adapter_->Enable();
pbos@webrtc.orgbe9d2a42014-06-30 13:19:09 +00001249 send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001250 send_config->pre_encode_callback = this;
1251 send_config->suspend_below_min_bitrate = true;
perkjfa10b552016-10-02 23:45:26 -07001252 int min_bitrate_bps =
1253 test::DefaultVideoStreamFactory::kDefaultMinBitratePerStream[0];
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001254 set_low_remb_bps(min_bitrate_bps - 10000);
mflodman101f2502016-06-09 17:21:19 +02001255 int threshold_window = std::max(min_bitrate_bps / 10, 20000);
perkjfa10b552016-10-02 23:45:26 -07001256 ASSERT_GT(encoder_config->max_bitrate_bps,
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001257 min_bitrate_bps + threshold_window + 5000);
1258 set_high_remb_bps(min_bitrate_bps + threshold_window + 5000);
1259 }
1260
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001261 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01001262 EXPECT_TRUE(Wait()) << "Timed out during suspend-below-min-bitrate test.";
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001263 }
1264
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001265 enum TestState {
henrik.lundin@webrtc.orgce8e0932013-11-18 12:18:43 +00001266 kBeforeSuspend,
1267 kDuringSuspend,
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001268 kWaitingForPacket,
henrik.lundin@webrtc.orged8b2812014-03-18 08:43:29 +00001269 kWaitingForStats
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001270 };
1271
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001272 virtual void SendRtcpFeedback(int remb_value)
danilchapa37de392017-09-09 04:17:22 -07001273 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) {
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001274 FakeReceiveStatistics receive_stats(kVideoSendSsrcs[0],
1275 last_sequence_number_, rtp_count_, 0);
terelius429c3452016-01-21 05:42:04 -08001276 RTCPSender rtcp_sender(false, clock_, &receive_stats, nullptr, nullptr,
Jiawei Ou3587b832018-01-31 22:08:26 -08001277 transport_adapter_.get(), RtcpIntervalConfig{});
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001278
pbosda903ea2015-10-02 02:36:56 -07001279 rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize);
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001280 rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]);
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001281 if (remb_value > 0) {
Danil Chapovalovf74d6412017-10-18 13:32:57 +02001282 rtcp_sender.SetRemb(remb_value, std::vector<uint32_t>());
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001283 }
1284 RTCPSender::FeedbackState feedback_state;
1285 EXPECT_EQ(0, rtcp_sender.SendRTCP(feedback_state, kRtcpRr));
1286 }
1287
kwiberg27f982b2016-03-01 11:52:33 -08001288 std::unique_ptr<internal::TransportAdapter> transport_adapter_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001289 Clock* const clock_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001290 VideoSendStream* stream_;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001291
Peter Boströmf2f82832015-05-01 13:00:41 +02001292 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07001293 TestState test_state_ RTC_GUARDED_BY(crit_);
1294 int rtp_count_ RTC_GUARDED_BY(crit_);
1295 int last_sequence_number_ RTC_GUARDED_BY(crit_);
1296 int suspended_frame_count_ RTC_GUARDED_BY(crit_);
1297 int low_remb_bps_ RTC_GUARDED_BY(crit_);
1298 int high_remb_bps_ RTC_GUARDED_BY(crit_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001299 } test;
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001300
stefane74eef12016-01-08 06:47:13 -08001301 RunBaseTest(&test);
henrik.lundin@webrtc.orgba975e22013-10-23 11:04:57 +00001302}
1303
perkj71ee44c2016-06-15 00:47:53 -07001304// This test that padding stops being send after a while if the Camera stops
1305// producing video frames and that padding resumes if the camera restarts.
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001306TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) {
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001307 class NoPaddingWhenVideoIsMuted : public test::SendTest {
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001308 public:
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001309 NoPaddingWhenVideoIsMuted()
1310 : SendTest(kDefaultTimeoutMs),
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001311 clock_(Clock::GetRealTimeClock()),
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001312 last_packet_time_ms_(-1),
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24 +00001313 capturer_(nullptr) {
sprang@webrtc.orgd9b95602014-01-27 13:03:02 +00001314 }
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001315
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001316 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001317 Action OnSendRtp(const uint8_t* packet, size_t length) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02001318 rtc::CritScope lock(&crit_);
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001319 last_packet_time_ms_ = clock_->TimeInMilliseconds();
perkj71ee44c2016-06-15 00:47:53 -07001320
1321 RTPHeader header;
1322 parser_->Parse(packet, length, &header);
1323 const bool only_padding =
1324 header.headerLength + header.paddingLength == length;
1325
1326 if (test_state_ == kBeforeStopCapture) {
1327 capturer_->Stop();
1328 test_state_ = kWaitingForPadding;
1329 } else if (test_state_ == kWaitingForPadding && only_padding) {
1330 test_state_ = kWaitingForNoPackets;
1331 } else if (test_state_ == kWaitingForPaddingAfterCameraRestart &&
1332 only_padding) {
1333 observation_complete_.Set();
1334 }
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001335 return SEND_PACKET;
1336 }
1337
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001338 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02001339 rtc::CritScope lock(&crit_);
perkj71ee44c2016-06-15 00:47:53 -07001340 const int kNoPacketsThresholdMs = 2000;
1341 if (test_state_ == kWaitingForNoPackets &&
1342 (last_packet_time_ms_ > 0 &&
1343 clock_->TimeInMilliseconds() - last_packet_time_ms_ >
1344 kNoPacketsThresholdMs)) {
1345 capturer_->Start();
1346 test_state_ = kWaitingForPaddingAfterCameraRestart;
1347 }
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001348 return SEND_PACKET;
1349 }
1350
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001351 size_t GetNumVideoStreams() const override { return 3; }
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001352
nisseef8b61e2016-04-29 06:09:15 -07001353 void OnFrameGeneratorCapturerCreated(
1354 test::FrameGeneratorCapturer* frame_generator_capturer) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02001355 rtc::CritScope lock(&crit_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001356 capturer_ = frame_generator_capturer;
1357 }
1358
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001359 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01001360 EXPECT_TRUE(Wait())
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001361 << "Timed out while waiting for RTP packets to stop being sent.";
1362 }
1363
perkj71ee44c2016-06-15 00:47:53 -07001364 enum TestState {
1365 kBeforeStopCapture,
1366 kWaitingForPadding,
1367 kWaitingForNoPackets,
1368 kWaitingForPaddingAfterCameraRestart
1369 };
1370
1371 TestState test_state_ = kBeforeStopCapture;
pbos@webrtc.orgde1429e2014-04-28 13:00:21 +00001372 Clock* const clock_;
kwiberg27f982b2016-03-01 11:52:33 -08001373 std::unique_ptr<internal::TransportAdapter> transport_adapter_;
Peter Boströmf2f82832015-05-01 13:00:41 +02001374 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07001375 int64_t last_packet_time_ms_ RTC_GUARDED_BY(crit_);
1376 test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(crit_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001377 } test;
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001378
stefane74eef12016-01-08 06:47:13 -08001379 RunBaseTest(&test);
stefan@webrtc.org4ab4fc02013-11-25 11:54:24 +00001380}
1381
isheriffcc5903e2016-10-04 08:29:38 -07001382TEST_F(VideoSendStreamTest, PaddingIsPrimarilyRetransmissions) {
1383 const int kCapacityKbps = 10000; // 10 Mbps
1384 class PaddingIsPrimarilyRetransmissions : public test::EndToEndTest {
1385 public:
1386 PaddingIsPrimarilyRetransmissions()
1387 : EndToEndTest(kDefaultTimeoutMs),
1388 clock_(Clock::GetRealTimeClock()),
1389 padding_length_(0),
1390 total_length_(0),
1391 call_(nullptr) {}
1392
1393 private:
1394 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1395 call_ = sender_call;
1396 }
1397
1398 Action OnSendRtp(const uint8_t* packet, size_t length) override {
1399 rtc::CritScope lock(&crit_);
1400
1401 RTPHeader header;
1402 parser_->Parse(packet, length, &header);
1403 padding_length_ += header.paddingLength;
1404 total_length_ += length;
1405 return SEND_PACKET;
1406 }
1407
eladalon413ee9a2017-08-22 04:02:52 -07001408 test::PacketTransport* CreateSendTransport(
1409 test::SingleThreadedTaskQueueForTesting* task_queue,
1410 Call* sender_call) override {
isheriffcc5903e2016-10-04 08:29:38 -07001411 const int kNetworkDelayMs = 50;
1412 FakeNetworkPipe::Config config;
1413 config.loss_percent = 10;
1414 config.link_capacity_kbps = kCapacityKbps;
1415 config.queue_delay_ms = kNetworkDelayMs;
eladalon413ee9a2017-08-22 04:02:52 -07001416 return new test::PacketTransport(task_queue, sender_call, this,
nissee5ad5ca2017-03-29 23:57:43 -07001417 test::PacketTransport::kSender,
minyue20c84cc2017-04-10 16:57:57 -07001418 payload_type_map_, config);
isheriffcc5903e2016-10-04 08:29:38 -07001419 }
1420
1421 void ModifyVideoConfigs(
1422 VideoSendStream::Config* send_config,
1423 std::vector<VideoReceiveStream::Config>* receive_configs,
1424 VideoEncoderConfig* encoder_config) override {
isheriffcc5903e2016-10-04 08:29:38 -07001425 // Turn on RTX.
1426 send_config->rtp.rtx.payload_type = kFakeVideoSendPayloadType;
1427 send_config->rtp.rtx.ssrcs.push_back(kVideoSendSsrcs[0]);
isheriffcc5903e2016-10-04 08:29:38 -07001428 }
1429
1430 void PerformTest() override {
1431 // TODO(isheriff): Some platforms do not ramp up as expected to full
1432 // capacity due to packet scheduling delays. Fix that before getting
1433 // rid of this.
1434 SleepMs(5000);
1435 {
1436 rtc::CritScope lock(&crit_);
1437 // Expect padding to be a small percentage of total bytes sent.
1438 EXPECT_LT(padding_length_, .1 * total_length_);
1439 }
1440 }
1441
1442 rtc::CriticalSection crit_;
1443 Clock* const clock_;
danilchapa37de392017-09-09 04:17:22 -07001444 size_t padding_length_ RTC_GUARDED_BY(crit_);
1445 size_t total_length_ RTC_GUARDED_BY(crit_);
isheriffcc5903e2016-10-04 08:29:38 -07001446 Call* call_;
1447 } test;
1448
1449 RunBaseTest(&test);
1450}
1451
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001452// This test first observes "high" bitrate use at which point it sends a REMB to
1453// indicate that it should be lowered significantly. The test then observes that
1454// the bitrate observed is sinking well below the min-transmit-bitrate threshold
1455// to verify that the min-transmit bitrate respects incoming REMB.
andresp@webrtc.org44caf012014-03-26 21:00:21 +00001456//
1457// Note that the test starts at "high" bitrate and does not ramp up to "higher"
1458// bitrate since no receiver block or remb is sent in the initial phase.
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001459TEST_F(VideoSendStreamTest, MinTransmitBitrateRespectsRemb) {
1460 static const int kMinTransmitBitrateBps = 400000;
andresp@webrtc.org44caf012014-03-26 21:00:21 +00001461 static const int kHighBitrateBps = 150000;
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001462 static const int kRembBitrateBps = 80000;
1463 static const int kRembRespectedBitrateBps = 100000;
stefanf116bd02015-10-27 08:29:42 -07001464 class BitrateObserver : public test::SendTest {
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001465 public:
1466 BitrateObserver()
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001467 : SendTest(kDefaultTimeoutMs),
Erik Språng737336d2016-07-29 12:59:36 +02001468 retranmission_rate_limiter_(Clock::GetRealTimeClock(), 1000),
1469 stream_(nullptr),
1470 bitrate_capped_(false) {}
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001471
1472 private:
nisseef8b61e2016-04-29 06:09:15 -07001473 Action OnSendRtp(const uint8_t* packet, size_t length) override {
pbos@webrtc.org62bafae2014-07-08 12:10:51 +00001474 if (RtpHeaderParser::IsRtcp(packet, length))
stefanf116bd02015-10-27 08:29:42 -07001475 return DROP_PACKET;
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001476
1477 RTPHeader header;
pbos@webrtc.org62bafae2014-07-08 12:10:51 +00001478 if (!parser_->Parse(packet, length, &header))
stefanf116bd02015-10-27 08:29:42 -07001479 return DROP_PACKET;
Peter Boström74f6e9e2016-04-04 17:56:10 +02001480 RTC_DCHECK(stream_);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001481 VideoSendStream::Stats stats = stream_->GetStats();
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001482 if (!stats.substreams.empty()) {
1483 EXPECT_EQ(1u, stats.substreams.size());
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +00001484 int total_bitrate_bps =
1485 stats.substreams.begin()->second.total_bitrate_bps;
1486 test::PrintResult("bitrate_stats_",
1487 "min_transmit_bitrate_low_remb",
1488 "bitrate_bps",
1489 static_cast<size_t>(total_bitrate_bps),
1490 "bps",
1491 false);
1492 if (total_bitrate_bps > kHighBitrateBps) {
Danil Chapovalov51e21aa2017-10-10 17:46:26 +02001493 rtp_rtcp_->SetRemb(kRembBitrateBps,
1494 std::vector<uint32_t>(1, header.ssrc));
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001495 rtp_rtcp_->Process();
1496 bitrate_capped_ = true;
1497 } else if (bitrate_capped_ &&
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +00001498 total_bitrate_bps < kRembRespectedBitrateBps) {
Peter Boström5811a392015-12-10 13:02:50 +01001499 observation_complete_.Set();
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001500 }
1501 }
stefanf116bd02015-10-27 08:29:42 -07001502 // Packets don't have to be delivered since the test is the receiver.
1503 return DROP_PACKET;
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001504 }
1505
stefanff483612015-12-21 03:14:00 -08001506 void OnVideoStreamsCreated(
stefanf116bd02015-10-27 08:29:42 -07001507 VideoSendStream* send_stream,
1508 const std::vector<VideoReceiveStream*>& receive_streams) override {
1509 stream_ = send_stream;
1510 RtpRtcp::Configuration config;
1511 config.outgoing_transport = feedback_transport_.get();
Erik Språng737336d2016-07-29 12:59:36 +02001512 config.retransmission_rate_limiter = &retranmission_rate_limiter_;
stefanf116bd02015-10-27 08:29:42 -07001513 rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config));
stefanf116bd02015-10-27 08:29:42 -07001514 rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize);
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001515 }
1516
stefanff483612015-12-21 03:14:00 -08001517 void ModifyVideoConfigs(
1518 VideoSendStream::Config* send_config,
1519 std::vector<VideoReceiveStream::Config>* receive_configs,
1520 VideoEncoderConfig* encoder_config) override {
stefanf116bd02015-10-27 08:29:42 -07001521 feedback_transport_.reset(
1522 new internal::TransportAdapter(send_config->send_transport));
1523 feedback_transport_->Enable();
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +00001524 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001525 }
1526
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00001527 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01001528 EXPECT_TRUE(Wait())
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001529 << "Timeout while waiting for low bitrate stats after REMB.";
1530 }
1531
kwiberg27f982b2016-03-01 11:52:33 -08001532 std::unique_ptr<RtpRtcp> rtp_rtcp_;
1533 std::unique_ptr<internal::TransportAdapter> feedback_transport_;
Erik Språng737336d2016-07-29 12:59:36 +02001534 RateLimiter retranmission_rate_limiter_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001535 VideoSendStream* stream_;
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001536 bool bitrate_capped_;
pbos@webrtc.org994d0b72014-06-27 08:47:52 +00001537 } test;
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001538
stefane74eef12016-01-08 06:47:13 -08001539 RunBaseTest(&test);
pbos@webrtc.org709e2972014-03-19 10:59:52 +00001540}
1541
Stefan Holmer280de9e2016-09-30 10:06:51 +02001542TEST_F(VideoSendStreamTest, ChangingNetworkRoute) {
1543 static const int kStartBitrateBps = 300000;
1544 static const int kNewMaxBitrateBps = 1234567;
danilchap42ca68a2016-10-31 03:34:40 -07001545 static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId;
Stefan Holmerbe402962016-07-08 16:16:41 +02001546 class ChangingNetworkRouteTest : public test::EndToEndTest {
1547 public:
eladalon413ee9a2017-08-22 04:02:52 -07001548 explicit ChangingNetworkRouteTest(
1549 test::SingleThreadedTaskQueueForTesting* task_queue)
1550 : EndToEndTest(test::CallTest::kDefaultTimeoutMs),
1551 task_queue_(task_queue),
1552 call_(nullptr) {
Stefan Holmer280de9e2016-09-30 10:06:51 +02001553 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
1554 kRtpExtensionTransportSequenceNumber, kExtensionId));
1555 }
Stefan Holmerbe402962016-07-08 16:16:41 +02001556
1557 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1558 call_ = sender_call;
1559 }
1560
Stefan Holmer280de9e2016-09-30 10:06:51 +02001561 void ModifyVideoConfigs(
1562 VideoSendStream::Config* send_config,
1563 std::vector<VideoReceiveStream::Config>* receive_configs,
1564 VideoEncoderConfig* encoder_config) override {
1565 send_config->rtp.extensions.clear();
1566 send_config->rtp.extensions.push_back(RtpExtension(
1567 RtpExtension::kTransportSequenceNumberUri, kExtensionId));
1568 (*receive_configs)[0].rtp.extensions = send_config->rtp.extensions;
1569 (*receive_configs)[0].rtp.transport_cc = true;
1570 }
1571
1572 void ModifyAudioConfigs(
1573 AudioSendStream::Config* send_config,
1574 std::vector<AudioReceiveStream::Config>* receive_configs) override {
1575 send_config->rtp.extensions.clear();
1576 send_config->rtp.extensions.push_back(RtpExtension(
1577 RtpExtension::kTransportSequenceNumberUri, kExtensionId));
1578 (*receive_configs)[0].rtp.extensions.clear();
1579 (*receive_configs)[0].rtp.extensions = send_config->rtp.extensions;
1580 (*receive_configs)[0].rtp.transport_cc = true;
1581 }
1582
Stefan Holmerbe402962016-07-08 16:16:41 +02001583 Action OnSendRtp(const uint8_t* packet, size_t length) override {
1584 if (call_->GetStats().send_bandwidth_bps > kStartBitrateBps) {
1585 observation_complete_.Set();
1586 }
1587
1588 return SEND_PACKET;
1589 }
1590
1591 void PerformTest() override {
1592 rtc::NetworkRoute new_route(true, 10, 20, -1);
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01001593 BitrateConstraints bitrate_config;
eladalon413ee9a2017-08-22 04:02:52 -07001594
1595 task_queue_->SendTask([this, &new_route, &bitrate_config]() {
1596 call_->OnNetworkRouteChanged("transport", new_route);
1597 bitrate_config.start_bitrate_bps = kStartBitrateBps;
1598 call_->SetBitrateConfig(bitrate_config);
1599 });
1600
Stefan Holmerbe402962016-07-08 16:16:41 +02001601 EXPECT_TRUE(Wait())
1602 << "Timed out while waiting for start bitrate to be exceeded.";
1603
eladalon413ee9a2017-08-22 04:02:52 -07001604 task_queue_->SendTask([this, &new_route, &bitrate_config]() {
1605 bitrate_config.start_bitrate_bps = -1;
1606 bitrate_config.max_bitrate_bps = kNewMaxBitrateBps;
1607 call_->SetBitrateConfig(bitrate_config);
1608 // TODO(holmer): We should set the last sent packet id here and verify
1609 // that we correctly ignore any packet loss reported prior to that id.
1610 ++new_route.local_network_id;
1611 call_->OnNetworkRouteChanged("transport", new_route);
1612 EXPECT_GE(call_->GetStats().send_bandwidth_bps, kStartBitrateBps);
1613 });
Stefan Holmerbe402962016-07-08 16:16:41 +02001614 }
1615
1616 private:
eladalon413ee9a2017-08-22 04:02:52 -07001617 test::SingleThreadedTaskQueueForTesting* const task_queue_;
Stefan Holmerbe402962016-07-08 16:16:41 +02001618 Call* call_;
eladalon413ee9a2017-08-22 04:02:52 -07001619 } test(&task_queue_);
Stefan Holmerbe402962016-07-08 16:16:41 +02001620
1621 RunBaseTest(&test);
1622}
1623
michaelt79e05882016-11-08 02:50:09 -08001624TEST_F(VideoSendStreamTest, ChangingTransportOverhead) {
1625 class ChangingTransportOverheadTest : public test::EndToEndTest {
1626 public:
eladalon413ee9a2017-08-22 04:02:52 -07001627 explicit ChangingTransportOverheadTest(
1628 test::SingleThreadedTaskQueueForTesting* task_queue)
michaelt79e05882016-11-08 02:50:09 -08001629 : EndToEndTest(test::CallTest::kDefaultTimeoutMs),
eladalon413ee9a2017-08-22 04:02:52 -07001630 task_queue_(task_queue),
michaelt79e05882016-11-08 02:50:09 -08001631 call_(nullptr),
Erik Språng08127a92016-11-16 16:41:30 +01001632 packets_sent_(0),
1633 transport_overhead_(0) {}
michaelt79e05882016-11-08 02:50:09 -08001634
1635 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1636 call_ = sender_call;
1637 }
1638
1639 Action OnSendRtp(const uint8_t* packet, size_t length) override {
michaelta3328772016-11-29 09:25:03 -08001640 EXPECT_LE(length, kMaxRtpPacketSize);
sprang21253fc2017-02-27 03:35:47 -08001641 rtc::CritScope cs(&lock_);
michaelt79e05882016-11-08 02:50:09 -08001642 if (++packets_sent_ < 100)
1643 return SEND_PACKET;
1644 observation_complete_.Set();
1645 return SEND_PACKET;
1646 }
1647
michaelta3328772016-11-29 09:25:03 -08001648 void ModifyVideoConfigs(
1649 VideoSendStream::Config* send_config,
1650 std::vector<VideoReceiveStream::Config>* receive_configs,
1651 VideoEncoderConfig* encoder_config) override {
1652 send_config->rtp.max_packet_size = kMaxRtpPacketSize;
1653 }
1654
michaelt79e05882016-11-08 02:50:09 -08001655 void PerformTest() override {
eladalon413ee9a2017-08-22 04:02:52 -07001656 task_queue_->SendTask([this]() {
1657 transport_overhead_ = 100;
1658 call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO,
1659 transport_overhead_);
1660 });
1661
michaelt79e05882016-11-08 02:50:09 -08001662 EXPECT_TRUE(Wait());
eladalon413ee9a2017-08-22 04:02:52 -07001663
sprang21253fc2017-02-27 03:35:47 -08001664 {
1665 rtc::CritScope cs(&lock_);
1666 packets_sent_ = 0;
1667 }
eladalon413ee9a2017-08-22 04:02:52 -07001668
1669 task_queue_->SendTask([this]() {
1670 transport_overhead_ = 500;
1671 call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO,
1672 transport_overhead_);
1673 });
1674
michaelt79e05882016-11-08 02:50:09 -08001675 EXPECT_TRUE(Wait());
1676 }
1677
1678 private:
eladalon413ee9a2017-08-22 04:02:52 -07001679 test::SingleThreadedTaskQueueForTesting* const task_queue_;
michaelt79e05882016-11-08 02:50:09 -08001680 Call* call_;
sprang21253fc2017-02-27 03:35:47 -08001681 rtc::CriticalSection lock_;
danilchapa37de392017-09-09 04:17:22 -07001682 int packets_sent_ RTC_GUARDED_BY(lock_);
michaelt79e05882016-11-08 02:50:09 -08001683 int transport_overhead_;
michaelta3328772016-11-29 09:25:03 -08001684 const size_t kMaxRtpPacketSize = 1000;
eladalon413ee9a2017-08-22 04:02:52 -07001685 } test(&task_queue_);
michaelt79e05882016-11-08 02:50:09 -08001686
1687 RunBaseTest(&test);
1688}
1689
sprangf24a0642017-02-28 13:23:26 -08001690// Test class takes takes as argument a switch selecting if type switch should
1691// occur and a function pointer to reset the send stream. This is necessary
1692// since you cannot change the content type of a VideoSendStream, you need to
1693// recreate it. Stopping and recreating the stream can only be done on the main
1694// thread and in the context of VideoSendStreamTest (not BaseTest).
1695template <typename T>
sprang9c0b5512016-07-06 00:54:28 -07001696class MaxPaddingSetTest : public test::SendTest {
1697 public:
1698 static const uint32_t kMinTransmitBitrateBps = 400000;
1699 static const uint32_t kActualEncodeBitrateBps = 40000;
1700 static const uint32_t kMinPacketsToSend = 50;
1701
sprangf24a0642017-02-28 13:23:26 -08001702 explicit MaxPaddingSetTest(bool test_switch_content_type, T* stream_reset_fun)
sprang9c0b5512016-07-06 00:54:28 -07001703 : SendTest(test::CallTest::kDefaultTimeoutMs),
sprangf24a0642017-02-28 13:23:26 -08001704 content_switch_event_(false, false),
sprang9c0b5512016-07-06 00:54:28 -07001705 call_(nullptr),
1706 send_stream_(nullptr),
sprangf24a0642017-02-28 13:23:26 -08001707 send_stream_config_(nullptr),
sprang9c0b5512016-07-06 00:54:28 -07001708 packets_sent_(0),
sprangf24a0642017-02-28 13:23:26 -08001709 running_without_padding_(test_switch_content_type),
tommi39e12892017-03-13 05:15:14 -07001710 stream_resetter_(stream_reset_fun) {
1711 RTC_DCHECK(stream_resetter_);
1712 }
sprang9c0b5512016-07-06 00:54:28 -07001713
1714 void OnVideoStreamsCreated(
1715 VideoSendStream* send_stream,
1716 const std::vector<VideoReceiveStream*>& receive_streams) override {
sprangf24a0642017-02-28 13:23:26 -08001717 rtc::CritScope lock(&crit_);
sprang9c0b5512016-07-06 00:54:28 -07001718 send_stream_ = send_stream;
1719 }
1720
1721 void ModifyVideoConfigs(
1722 VideoSendStream::Config* send_config,
1723 std::vector<VideoReceiveStream::Config>* receive_configs,
1724 VideoEncoderConfig* encoder_config) override {
kwibergaf476c72016-11-28 15:21:39 -08001725 RTC_DCHECK_EQ(1, encoder_config->number_of_streams);
sprangf24a0642017-02-28 13:23:26 -08001726 if (RunningWithoutPadding()) {
sprang9c0b5512016-07-06 00:54:28 -07001727 encoder_config->min_transmit_bitrate_bps = 0;
1728 encoder_config->content_type =
1729 VideoEncoderConfig::ContentType::kRealtimeVideo;
1730 } else {
1731 encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps;
1732 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
1733 }
sprangf24a0642017-02-28 13:23:26 -08001734 send_stream_config_ = send_config->Copy();
perkj26091b12016-09-01 01:17:40 -07001735 encoder_config_ = encoder_config->Copy();
sprang9c0b5512016-07-06 00:54:28 -07001736 }
1737
1738 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
1739 call_ = sender_call;
1740 }
1741
1742 Action OnSendRtp(const uint8_t* packet, size_t length) override {
1743 rtc::CritScope lock(&crit_);
sprang9c0b5512016-07-06 00:54:28 -07001744 if (running_without_padding_)
1745 EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps);
1746
1747 // Wait until at least kMinPacketsToSend frames have been encoded, so that
1748 // we have reliable data.
1749 if (++packets_sent_ < kMinPacketsToSend)
1750 return SEND_PACKET;
1751
1752 if (running_without_padding_) {
1753 // We've sent kMinPacketsToSend packets with default configuration, switch
1754 // to enabling screen content and setting min transmit bitrate.
sprangf24a0642017-02-28 13:23:26 -08001755 // Note that we need to recreate the stream if changing content type.
sprang9c0b5512016-07-06 00:54:28 -07001756 packets_sent_ = 0;
1757 encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps;
1758 encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen;
sprang9c0b5512016-07-06 00:54:28 -07001759 running_without_padding_ = false;
sprangf24a0642017-02-28 13:23:26 -08001760 content_switch_event_.Set();
sprang9c0b5512016-07-06 00:54:28 -07001761 return SEND_PACKET;
1762 }
1763
1764 // Make sure the pacer has been configured with a min transmit bitrate.
1765 if (call_->GetStats().max_padding_bitrate_bps > 0)
1766 observation_complete_.Set();
1767
1768 return SEND_PACKET;
1769 }
1770
1771 void PerformTest() override {
sprangf24a0642017-02-28 13:23:26 -08001772 if (RunningWithoutPadding()) {
1773 ASSERT_TRUE(
1774 content_switch_event_.Wait(test::CallTest::kDefaultTimeoutMs));
sprangf24a0642017-02-28 13:23:26 -08001775 (*stream_resetter_)(send_stream_config_, encoder_config_);
1776 }
1777
sprang9c0b5512016-07-06 00:54:28 -07001778 ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate.";
1779 }
1780
1781 private:
sprangf24a0642017-02-28 13:23:26 -08001782 bool RunningWithoutPadding() const {
1783 rtc::CritScope lock(&crit_);
1784 return running_without_padding_;
1785 }
1786
sprang9c0b5512016-07-06 00:54:28 -07001787 rtc::CriticalSection crit_;
sprangf24a0642017-02-28 13:23:26 -08001788 rtc::Event content_switch_event_;
sprang9c0b5512016-07-06 00:54:28 -07001789 Call* call_;
danilchapa37de392017-09-09 04:17:22 -07001790 VideoSendStream* send_stream_ RTC_GUARDED_BY(crit_);
sprangf24a0642017-02-28 13:23:26 -08001791 VideoSendStream::Config send_stream_config_;
sprang9c0b5512016-07-06 00:54:28 -07001792 VideoEncoderConfig encoder_config_;
danilchapa37de392017-09-09 04:17:22 -07001793 uint32_t packets_sent_ RTC_GUARDED_BY(crit_);
sprang9c0b5512016-07-06 00:54:28 -07001794 bool running_without_padding_;
sprangf24a0642017-02-28 13:23:26 -08001795 T* const stream_resetter_;
sprang9c0b5512016-07-06 00:54:28 -07001796};
1797
1798TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) {
sprangf24a0642017-02-28 13:23:26 -08001799 auto reset_fun = [](const VideoSendStream::Config& send_stream_config,
1800 const VideoEncoderConfig& encoder_config) {};
1801 MaxPaddingSetTest<decltype(reset_fun)> test(false, &reset_fun);
sprang9c0b5512016-07-06 00:54:28 -07001802 RunBaseTest(&test);
1803}
1804
1805TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) {
sprangf24a0642017-02-28 13:23:26 -08001806 // Function for removing and recreating the send stream with a new config.
1807 auto reset_fun = [this](const VideoSendStream::Config& send_stream_config,
1808 const VideoEncoderConfig& encoder_config) {
eladalon413ee9a2017-08-22 04:02:52 -07001809 task_queue_.SendTask([this, &send_stream_config, &encoder_config]() {
1810 Stop();
1811 sender_call_->DestroyVideoSendStream(video_send_stream_);
1812 video_send_config_ = send_stream_config.Copy();
1813 video_encoder_config_ = encoder_config.Copy();
1814 video_send_stream_ = sender_call_->CreateVideoSendStream(
1815 video_send_config_.Copy(), video_encoder_config_.Copy());
1816 video_send_stream_->SetSource(
1817 frame_generator_capturer_.get(),
1818 VideoSendStream::DegradationPreference::kMaintainResolution);
1819 Start();
1820 });
sprangf24a0642017-02-28 13:23:26 -08001821 };
1822 MaxPaddingSetTest<decltype(reset_fun)> test(true, &reset_fun);
sprang9c0b5512016-07-06 00:54:28 -07001823 RunBaseTest(&test);
1824}
1825
perkjfa10b552016-10-02 23:45:26 -07001826// This test verifies that new frame sizes reconfigures encoders even though not
1827// (yet) sending. The purpose of this is to permit encoding as quickly as
1828// possible once we start sending. Likely the frames being input are from the
1829// same source that will be sent later, which just means that we're ready
1830// earlier.
1831TEST_F(VideoSendStreamTest,
1832 EncoderReconfigureOnResolutionChangeWhenNotSending) {
1833 class EncoderObserver : public test::FakeEncoder {
1834 public:
1835 EncoderObserver()
1836 : FakeEncoder(Clock::GetRealTimeClock()),
1837 init_encode_called_(false, false),
1838 number_of_initializations_(0),
1839 last_initialized_frame_width_(0),
1840 last_initialized_frame_height_(0) {}
1841
1842 void WaitForResolution(int width, int height) {
1843 {
1844 rtc::CritScope lock(&crit_);
1845 if (last_initialized_frame_width_ == width &&
1846 last_initialized_frame_height_ == height) {
1847 return;
1848 }
1849 }
Erik Språng08127a92016-11-16 16:41:30 +01001850 EXPECT_TRUE(
1851 init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
perkjfa10b552016-10-02 23:45:26 -07001852 {
1853 rtc::CritScope lock(&crit_);
1854 EXPECT_EQ(width, last_initialized_frame_width_);
1855 EXPECT_EQ(height, last_initialized_frame_height_);
1856 }
1857 }
1858
1859 private:
1860 int32_t InitEncode(const VideoCodec* config,
1861 int32_t number_of_cores,
1862 size_t max_payload_size) override {
1863 rtc::CritScope lock(&crit_);
1864 last_initialized_frame_width_ = config->width;
1865 last_initialized_frame_height_ = config->height;
1866 ++number_of_initializations_;
Erik Språng08127a92016-11-16 16:41:30 +01001867 init_encode_called_.Set();
perkjfa10b552016-10-02 23:45:26 -07001868 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1869 }
1870
1871 int32_t Encode(const VideoFrame& input_image,
1872 const CodecSpecificInfo* codec_specific_info,
1873 const std::vector<FrameType>* frame_types) override {
1874 ADD_FAILURE()
1875 << "Unexpected Encode call since the send stream is not started";
1876 return 0;
1877 }
1878
1879 rtc::CriticalSection crit_;
1880 rtc::Event init_encode_called_;
danilchapa37de392017-09-09 04:17:22 -07001881 size_t number_of_initializations_ RTC_GUARDED_BY(&crit_);
1882 int last_initialized_frame_width_ RTC_GUARDED_BY(&crit_);
1883 int last_initialized_frame_height_ RTC_GUARDED_BY(&crit_);
perkjfa10b552016-10-02 23:45:26 -07001884 };
1885
perkjfa10b552016-10-02 23:45:26 -07001886 test::NullTransport transport;
perkjfa10b552016-10-02 23:45:26 -07001887 EncoderObserver encoder;
eladalon413ee9a2017-08-22 04:02:52 -07001888
1889 task_queue_.SendTask([this, &transport, &encoder]() {
1890 CreateSenderCall(Call::Config(event_log_.get()));
1891 CreateSendConfig(1, 0, 0, &transport);
1892 video_send_config_.encoder_settings.encoder = &encoder;
1893 CreateVideoStreams();
1894 CreateFrameGeneratorCapturer(kDefaultFramerate, kDefaultWidth,
1895 kDefaultHeight);
1896 frame_generator_capturer_->Start();
1897 });
perkjfa10b552016-10-02 23:45:26 -07001898
1899 encoder.WaitForResolution(kDefaultWidth, kDefaultHeight);
eladalon413ee9a2017-08-22 04:02:52 -07001900
1901 task_queue_.SendTask([this]() {
1902 frame_generator_capturer_->ChangeResolution(kDefaultWidth * 2,
1903 kDefaultHeight * 2);
1904 });
1905
perkjfa10b552016-10-02 23:45:26 -07001906 encoder.WaitForResolution(kDefaultWidth * 2, kDefaultHeight * 2);
eladalon413ee9a2017-08-22 04:02:52 -07001907
1908 task_queue_.SendTask([this]() {
1909 DestroyStreams();
1910 DestroyCalls();
1911 });
perkjfa10b552016-10-02 23:45:26 -07001912}
1913
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001914TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) {
1915 class StartBitrateObserver : public test::FakeEncoder {
1916 public:
1917 StartBitrateObserver()
pbos14fe7082016-04-20 06:35:56 -07001918 : FakeEncoder(Clock::GetRealTimeClock()),
1919 start_bitrate_changed_(false, false),
1920 start_bitrate_kbps_(0) {}
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001921 int32_t InitEncode(const VideoCodec* config,
1922 int32_t number_of_cores,
1923 size_t max_payload_size) override {
1924 rtc::CritScope lock(&crit_);
1925 start_bitrate_kbps_ = config->startBitrate;
pbos14fe7082016-04-20 06:35:56 -07001926 start_bitrate_changed_.Set();
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001927 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1928 }
1929
1930 int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override {
1931 rtc::CritScope lock(&crit_);
1932 start_bitrate_kbps_ = new_target_bitrate;
pbos14fe7082016-04-20 06:35:56 -07001933 start_bitrate_changed_.Set();
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001934 return FakeEncoder::SetRates(new_target_bitrate, framerate);
1935 }
1936
1937 int GetStartBitrateKbps() const {
1938 rtc::CritScope lock(&crit_);
1939 return start_bitrate_kbps_;
1940 }
1941
pbos14fe7082016-04-20 06:35:56 -07001942 bool WaitForStartBitrate() {
1943 return start_bitrate_changed_.Wait(
1944 VideoSendStreamTest::kDefaultTimeoutMs);
1945 }
1946
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001947 private:
pbos5ad935c2016-01-25 03:52:44 -08001948 rtc::CriticalSection crit_;
pbos14fe7082016-04-20 06:35:56 -07001949 rtc::Event start_bitrate_changed_;
danilchapa37de392017-09-09 04:17:22 -07001950 int start_bitrate_kbps_ RTC_GUARDED_BY(crit_);
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001951 };
1952
philipel4fb651d2017-04-10 03:54:05 -07001953 CreateSenderCall(Call::Config(event_log_.get()));
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001954
solenberg4fbae2b2015-08-28 04:07:10 -07001955 test::NullTransport transport;
brandtr841de6a2016-11-15 07:10:52 -08001956 CreateSendConfig(1, 0, 0, &transport);
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001957
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01001958 BitrateConstraints bitrate_config;
perkjfa10b552016-10-02 23:45:26 -07001959 bitrate_config.start_bitrate_bps = 2 * video_encoder_config_.max_bitrate_bps;
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001960 sender_call_->SetBitrateConfig(bitrate_config);
1961
1962 StartBitrateObserver encoder;
stefanff483612015-12-21 03:14:00 -08001963 video_send_config_.encoder_settings.encoder = &encoder;
perkjfa10b552016-10-02 23:45:26 -07001964 // Since this test does not use a capturer, set |internal_source| = true.
1965 // Encoder configuration is otherwise updated on the next video frame.
1966 video_send_config_.encoder_settings.internal_source = true;
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001967
Stefan Holmer9fea80f2016-01-07 17:43:18 +01001968 CreateVideoStreams();
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001969
pbos14fe7082016-04-20 06:35:56 -07001970 EXPECT_TRUE(encoder.WaitForStartBitrate());
perkjfa10b552016-10-02 23:45:26 -07001971 EXPECT_EQ(video_encoder_config_.max_bitrate_bps / 1000,
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001972 encoder.GetStartBitrateKbps());
1973
perkjfa10b552016-10-02 23:45:26 -07001974 video_encoder_config_.max_bitrate_bps = 2 * bitrate_config.start_bitrate_bps;
perkj26091b12016-09-01 01:17:40 -07001975 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy());
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001976
1977 // New bitrate should be reconfigured above the previous max. As there's no
1978 // network connection this shouldn't be flaky, as no bitrate should've been
1979 // reported in between.
pbos14fe7082016-04-20 06:35:56 -07001980 EXPECT_TRUE(encoder.WaitForStartBitrate());
pbos@webrtc.org143451d2015-03-18 14:40:03 +00001981 EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000,
1982 encoder.GetStartBitrateKbps());
1983
1984 DestroyStreams();
1985}
1986
Seth Hampsoncc7125f2018-02-02 08:46:16 -08001987class StartStopBitrateObserver : public test::FakeEncoder {
1988 public:
1989 StartStopBitrateObserver()
1990 : FakeEncoder(Clock::GetRealTimeClock()),
1991 encoder_init_(false, false),
1992 bitrate_changed_(false, false) {}
1993 int32_t InitEncode(const VideoCodec* config,
1994 int32_t number_of_cores,
1995 size_t max_payload_size) override {
1996 rtc::CritScope lock(&crit_);
1997 encoder_init_.Set();
1998 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
1999 }
2000
2001 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
2002 uint32_t framerate) override {
2003 rtc::CritScope lock(&crit_);
2004 bitrate_kbps_ = bitrate.get_sum_kbps();
2005 bitrate_changed_.Set();
2006 return FakeEncoder::SetRateAllocation(bitrate, framerate);
2007 }
2008
2009 bool WaitForEncoderInit() {
2010 return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs);
2011 }
2012
2013 bool WaitBitrateChanged(bool non_zero) {
2014 do {
2015 rtc::Optional<int> bitrate_kbps;
2016 {
2017 rtc::CritScope lock(&crit_);
2018 bitrate_kbps = bitrate_kbps_;
2019 }
2020 if (!bitrate_kbps)
2021 continue;
2022
2023 if ((non_zero && *bitrate_kbps > 0) ||
2024 (!non_zero && *bitrate_kbps == 0)) {
2025 return true;
2026 }
2027 } while (bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
2028 return false;
2029 }
2030
2031 private:
2032 rtc::CriticalSection crit_;
2033 rtc::Event encoder_init_;
2034 rtc::Event bitrate_changed_;
2035 rtc::Optional<int> bitrate_kbps_ RTC_GUARDED_BY(crit_);
2036};
2037
perkj57c21f92016-06-17 07:27:16 -07002038// This test that if the encoder use an internal source, VideoEncoder::SetRates
2039// will be called with zero bitrate during initialization and that
2040// VideoSendStream::Stop also triggers VideoEncoder::SetRates Start to be called
2041// with zero bitrate.
2042TEST_F(VideoSendStreamTest, VideoSendStreamStopSetEncoderRateToZero) {
perkj57c21f92016-06-17 07:27:16 -07002043 test::NullTransport transport;
perkj57c21f92016-06-17 07:27:16 -07002044 StartStopBitrateObserver encoder;
perkj57c21f92016-06-17 07:27:16 -07002045
eladalon413ee9a2017-08-22 04:02:52 -07002046 task_queue_.SendTask([this, &transport, &encoder]() {
2047 CreateSenderCall(Call::Config(event_log_.get()));
2048 CreateSendConfig(1, 0, 0, &transport);
2049
2050 sender_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp);
2051
2052 video_send_config_.encoder_settings.encoder = &encoder;
2053 video_send_config_.encoder_settings.internal_source = true;
2054
2055 CreateVideoStreams();
2056 });
perkj57c21f92016-06-17 07:27:16 -07002057
2058 EXPECT_TRUE(encoder.WaitForEncoderInit());
Erik Språng08127a92016-11-16 16:41:30 +01002059
eladalon413ee9a2017-08-22 04:02:52 -07002060 task_queue_.SendTask([this]() {
2061 video_send_stream_->Start();
2062 });
Erik Språng08127a92016-11-16 16:41:30 +01002063 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
2064
eladalon413ee9a2017-08-22 04:02:52 -07002065 task_queue_.SendTask([this]() {
2066 video_send_stream_->Stop();
2067 });
Erik Språng08127a92016-11-16 16:41:30 +01002068 EXPECT_TRUE(encoder.WaitBitrateChanged(false));
2069
eladalon413ee9a2017-08-22 04:02:52 -07002070 task_queue_.SendTask([this]() {
2071 video_send_stream_->Start();
2072 });
Erik Språng08127a92016-11-16 16:41:30 +01002073 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
perkj57c21f92016-06-17 07:27:16 -07002074
eladalon413ee9a2017-08-22 04:02:52 -07002075 task_queue_.SendTask([this]() {
2076 DestroyStreams();
2077 DestroyCalls();
2078 });
perkj57c21f92016-06-17 07:27:16 -07002079}
2080
Seth Hampsoncc7125f2018-02-02 08:46:16 -08002081// Tests that when the encoder uses an internal source, the VideoEncoder will
2082// be updated with a new bitrate when turning the VideoSendStream on/off with
2083// VideoSendStream::UpdateActiveSimulcastLayers, and when the VideoStreamEncoder
2084// is reconfigured with new active layers.
2085TEST_F(VideoSendStreamTest, VideoSendStreamUpdateActiveSimulcastLayers) {
2086 test::NullTransport transport;
2087 StartStopBitrateObserver encoder;
2088
2089 task_queue_.SendTask([this, &transport, &encoder]() {
2090 CreateSenderCall(Call::Config(event_log_.get()));
2091 // Create two simulcast streams.
2092 CreateSendConfig(2, 0, 0, &transport);
2093
2094 sender_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp);
2095
2096 video_send_config_.encoder_settings.encoder = &encoder;
2097 video_send_config_.encoder_settings.internal_source = true;
2098 video_send_config_.encoder_settings.payload_name = "VP8";
2099
2100 CreateVideoStreams();
2101 });
2102
2103 EXPECT_TRUE(encoder.WaitForEncoderInit());
2104
2105 // When we turn on the simulcast layers it will update the BitrateAllocator,
2106 // which in turn updates the VideoEncoder's bitrate.
2107 task_queue_.SendTask([this]() {
2108 video_send_stream_->UpdateActiveSimulcastLayers({true, true});
2109 });
2110 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
2111
2112 video_encoder_config_.simulcast_layers[0].active = true;
2113 video_encoder_config_.simulcast_layers[1].active = false;
2114 task_queue_.SendTask([this]() {
2115 video_send_stream_->ReconfigureVideoEncoder(video_encoder_config_.Copy());
2116 });
2117 // TODO(bugs.webrtc.org/8807): Currently we require a hard reconfiguration to
2118 // update the VideoBitrateAllocator and BitrateAllocator of which layers are
2119 // active. Once the change is made for a "soft" reconfiguration we can remove
2120 // the expecation for an encoder init. We can also test that bitrate changes
2121 // when just updating individual active layers, which should change the
2122 // bitrate set to the video encoder.
2123 EXPECT_TRUE(encoder.WaitForEncoderInit());
2124 EXPECT_TRUE(encoder.WaitBitrateChanged(true));
2125
2126 // Turning off both simulcast layers should trigger a bitrate change of 0.
2127 video_encoder_config_.simulcast_layers[0].active = false;
2128 video_encoder_config_.simulcast_layers[1].active = false;
2129 task_queue_.SendTask([this]() {
2130 video_send_stream_->UpdateActiveSimulcastLayers({false, false});
2131 });
2132 EXPECT_TRUE(encoder.WaitBitrateChanged(false));
2133
2134 task_queue_.SendTask([this]() {
2135 DestroyStreams();
2136 DestroyCalls();
2137 });
2138}
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002139TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) {
nissed30a1112016-04-18 05:15:22 -07002140 class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> {
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002141 public:
Peter Boström5811a392015-12-10 13:02:50 +01002142 FrameObserver() : output_frame_event_(false, false) {}
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002143
nissed30a1112016-04-18 05:15:22 -07002144 void OnFrame(const VideoFrame& video_frame) override {
2145 output_frames_.push_back(video_frame);
Peter Boström5811a392015-12-10 13:02:50 +01002146 output_frame_event_.Set();
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002147 }
2148
2149 void WaitOutputFrame() {
Peter Boström5811a392015-12-10 13:02:50 +01002150 const int kWaitFrameTimeoutMs = 3000;
2151 EXPECT_TRUE(output_frame_event_.Wait(kWaitFrameTimeoutMs))
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002152 << "Timeout while waiting for output frames.";
2153 }
2154
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002155 const std::vector<VideoFrame>& output_frames() const {
magjed@webrtc.org2d2a30c2015-03-24 12:37:36 +00002156 return output_frames_;
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002157 }
2158
2159 private:
2160 // Delivered output frames.
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002161 std::vector<VideoFrame> output_frames_;
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002162
2163 // Indicate an output frame has arrived.
Peter Boström5811a392015-12-10 13:02:50 +01002164 rtc::Event output_frame_event_;
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002165 };
2166
solenberg4fbae2b2015-08-28 04:07:10 -07002167 test::NullTransport transport;
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002168 FrameObserver observer;
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002169 std::vector<VideoFrame> input_frames;
perkjfa10b552016-10-02 23:45:26 -07002170
eladalon413ee9a2017-08-22 04:02:52 -07002171 task_queue_.SendTask([this, &transport, &observer, &input_frames]() {
2172 // Initialize send stream.
2173 CreateSenderCall(Call::Config(event_log_.get()));
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002174
eladalon413ee9a2017-08-22 04:02:52 -07002175 CreateSendConfig(1, 0, 0, &transport);
2176 video_send_config_.pre_encode_callback = &observer;
2177 CreateVideoStreams();
2178
2179 // Prepare five input frames. Send ordinary VideoFrame and texture frames
2180 // alternatively.
2181 int width = 168;
2182 int height = 132;
2183
2184 input_frames.push_back(test::FakeNativeBuffer::CreateFrame(
2185 width, height, 1, 1, kVideoRotation_0));
2186 input_frames.push_back(test::FakeNativeBuffer::CreateFrame(
2187 width, height, 2, 2, kVideoRotation_0));
2188 input_frames.push_back(CreateVideoFrame(width, height, 3));
2189 input_frames.push_back(CreateVideoFrame(width, height, 4));
2190 input_frames.push_back(test::FakeNativeBuffer::CreateFrame(
2191 width, height, 5, 5, kVideoRotation_0));
2192
2193 video_send_stream_->Start();
2194 test::FrameForwarder forwarder;
2195 video_send_stream_->SetSource(
2196 &forwarder, VideoSendStream::DegradationPreference::kMaintainFramerate);
2197 for (size_t i = 0; i < input_frames.size(); i++) {
2198 forwarder.IncomingCapturedFrame(input_frames[i]);
2199 // Wait until the output frame is received before sending the next input
2200 // frame. Or the previous input frame may be replaced without delivering.
2201 observer.WaitOutputFrame();
2202 }
2203 video_send_stream_->Stop();
2204 video_send_stream_->SetSource(
2205 nullptr, VideoSendStream::DegradationPreference::kMaintainFramerate);
2206 });
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002207
2208 // Test if the input and output frames are the same. render_time_ms and
2209 // timestamp are not compared because capturer sets those values.
magjed@webrtc.org2d2a30c2015-03-24 12:37:36 +00002210 ExpectEqualFramesVector(input_frames, observer.output_frames());
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002211
eladalon413ee9a2017-08-22 04:02:52 -07002212 task_queue_.SendTask([this]() {
2213 DestroyStreams();
2214 DestroyCalls();
2215 });
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002216}
2217
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002218void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1,
2219 const std::vector<VideoFrame>& frames2) {
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002220 EXPECT_EQ(frames1.size(), frames2.size());
2221 for (size_t i = 0; i < std::min(frames1.size(), frames2.size()); ++i)
nisse26acec42016-04-15 03:43:39 -07002222 // Compare frame buffers, since we don't care about differing timestamps.
2223 EXPECT_TRUE(test::FrameBufsEqual(frames1[i].video_frame_buffer(),
2224 frames2[i].video_frame_buffer()));
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002225}
2226
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002227VideoFrame CreateVideoFrame(int width, int height, uint8_t data) {
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002228 const int kSizeY = width * height * 2;
kwiberg27f982b2016-03-01 11:52:33 -08002229 std::unique_ptr<uint8_t[]> buffer(new uint8_t[kSizeY]);
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002230 memset(buffer.get(), data, kSizeY);
Magnus Jedvert90e31902017-06-07 11:32:50 +02002231 VideoFrame frame(I420Buffer::Create(width, height), kVideoRotation_0, data);
magjed@webrtc.org2d2a30c2015-03-24 12:37:36 +00002232 frame.set_timestamp(data);
nisse1c0dea82017-01-30 02:43:18 -08002233 // Use data as a ms timestamp.
2234 frame.set_timestamp_us(data * rtc::kNumMicrosecsPerMillisec);
wuchengli@chromium.orgf425b552014-06-20 12:04:05 +00002235 return frame;
2236}
2237
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002238TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) {
2239 class EncoderStateObserver : public test::SendTest, public VideoEncoder {
2240 public:
eladalon413ee9a2017-08-22 04:02:52 -07002241 explicit EncoderStateObserver(
2242 test::SingleThreadedTaskQueueForTesting* task_queue)
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002243 : SendTest(kDefaultTimeoutMs),
eladalon413ee9a2017-08-22 04:02:52 -07002244 task_queue_(task_queue),
Erik Språng737336d2016-07-29 12:59:36 +02002245 stream_(nullptr),
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002246 initialized_(false),
2247 callback_registered_(false),
2248 num_releases_(0),
2249 released_(false) {}
2250
2251 bool IsReleased() {
Peter Boströmf2f82832015-05-01 13:00:41 +02002252 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002253 return released_;
2254 }
2255
2256 bool IsReadyForEncode() {
Peter Boströmf2f82832015-05-01 13:00:41 +02002257 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002258 return initialized_ && callback_registered_;
2259 }
2260
2261 size_t num_releases() {
Peter Boströmf2f82832015-05-01 13:00:41 +02002262 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002263 return num_releases_;
2264 }
2265
2266 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002267 int32_t InitEncode(const VideoCodec* codecSettings,
2268 int32_t numberOfCores,
2269 size_t maxPayloadSize) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02002270 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002271 EXPECT_FALSE(initialized_);
2272 initialized_ = true;
2273 released_ = false;
2274 return 0;
2275 }
2276
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002277 int32_t Encode(const VideoFrame& inputImage,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002278 const CodecSpecificInfo* codecSpecificInfo,
pbos22993e12015-10-19 02:39:06 -07002279 const std::vector<FrameType>* frame_types) override {
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002280 EXPECT_TRUE(IsReadyForEncode());
2281
Peter Boström5811a392015-12-10 13:02:50 +01002282 observation_complete_.Set();
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002283 return 0;
2284 }
2285
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002286 int32_t RegisterEncodeCompleteCallback(
2287 EncodedImageCallback* callback) override {
Peter Boströmf2f82832015-05-01 13:00:41 +02002288 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002289 EXPECT_TRUE(initialized_);
2290 callback_registered_ = true;
2291 return 0;
2292 }
2293
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002294 int32_t Release() override {
Peter Boströmf2f82832015-05-01 13:00:41 +02002295 rtc::CritScope lock(&crit_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002296 EXPECT_TRUE(IsReadyForEncode());
2297 EXPECT_FALSE(released_);
2298 initialized_ = false;
2299 callback_registered_ = false;
2300 released_ = true;
2301 ++num_releases_;
2302 return 0;
2303 }
2304
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002305 int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) override {
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002306 EXPECT_TRUE(IsReadyForEncode());
2307 return 0;
2308 }
2309
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002310 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override {
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002311 EXPECT_TRUE(IsReadyForEncode());
2312 return 0;
2313 }
2314
stefanff483612015-12-21 03:14:00 -08002315 void OnVideoStreamsCreated(
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002316 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002317 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002318 stream_ = send_stream;
2319 }
2320
stefanff483612015-12-21 03:14:00 -08002321 void ModifyVideoConfigs(
2322 VideoSendStream::Config* send_config,
2323 std::vector<VideoReceiveStream::Config>* receive_configs,
2324 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002325 send_config->encoder_settings.encoder = this;
perkj26091b12016-09-01 01:17:40 -07002326 encoder_config_ = encoder_config->Copy();
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002327 }
2328
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002329 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01002330 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode.";
eladalon413ee9a2017-08-22 04:02:52 -07002331
2332 task_queue_->SendTask([this]() {
2333 EXPECT_EQ(0u, num_releases());
2334 stream_->ReconfigureVideoEncoder(std::move(encoder_config_));
2335 EXPECT_EQ(0u, num_releases());
2336 stream_->Stop();
2337 // Encoder should not be released before destroying the VideoSendStream.
2338 EXPECT_FALSE(IsReleased());
2339 EXPECT_TRUE(IsReadyForEncode());
2340 stream_->Start();
2341 });
2342
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002343 // Sanity check, make sure we still encode frames with this encoder.
Peter Boström5811a392015-12-10 13:02:50 +01002344 EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode.";
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002345 }
2346
eladalon413ee9a2017-08-22 04:02:52 -07002347 test::SingleThreadedTaskQueueForTesting* const task_queue_;
Peter Boströmf2f82832015-05-01 13:00:41 +02002348 rtc::CriticalSection crit_;
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002349 VideoSendStream* stream_;
danilchapa37de392017-09-09 04:17:22 -07002350 bool initialized_ RTC_GUARDED_BY(crit_);
2351 bool callback_registered_ RTC_GUARDED_BY(crit_);
2352 size_t num_releases_ RTC_GUARDED_BY(crit_);
2353 bool released_ RTC_GUARDED_BY(crit_);
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002354 VideoEncoderConfig encoder_config_;
eladalon413ee9a2017-08-22 04:02:52 -07002355 } test_encoder(&task_queue_);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002356
stefane74eef12016-01-08 06:47:13 -08002357 RunBaseTest(&test_encoder);
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002358
2359 EXPECT_TRUE(test_encoder.IsReleased());
Per21d45d22016-10-30 21:37:57 +01002360 EXPECT_EQ(1u, test_encoder.num_releases());
pbos@webrtc.org161f8082014-07-07 14:22:35 +00002361}
2362
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002363TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) {
2364 class VideoCodecConfigObserver : public test::SendTest,
2365 public test::FakeEncoder {
2366 public:
2367 VideoCodecConfigObserver()
2368 : SendTest(kDefaultTimeoutMs),
2369 FakeEncoder(Clock::GetRealTimeClock()),
pbos14fe7082016-04-20 06:35:56 -07002370 init_encode_event_(false, false),
Erik Språng737336d2016-07-29 12:59:36 +02002371 num_initializations_(0),
2372 stream_(nullptr) {}
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002373
2374 private:
stefanff483612015-12-21 03:14:00 -08002375 void ModifyVideoConfigs(
2376 VideoSendStream::Config* send_config,
2377 std::vector<VideoReceiveStream::Config>* receive_configs,
2378 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002379 send_config->encoder_settings.encoder = this;
sprangf24a0642017-02-28 13:23:26 -08002380 encoder_config->max_bitrate_bps = kFirstMaxBitrateBps;
perkj26091b12016-09-01 01:17:40 -07002381 encoder_config_ = encoder_config->Copy();
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002382 }
2383
stefanff483612015-12-21 03:14:00 -08002384 void OnVideoStreamsCreated(
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002385 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002386 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002387 stream_ = send_stream;
2388 }
2389
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002390 int32_t InitEncode(const VideoCodec* config,
2391 int32_t number_of_cores,
2392 size_t max_payload_size) override {
Per21d45d22016-10-30 21:37:57 +01002393 if (num_initializations_ == 0) {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002394 // Verify default values.
sprangf24a0642017-02-28 13:23:26 -08002395 EXPECT_EQ(kFirstMaxBitrateBps / 1000, config->maxBitrate);
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002396 } else {
2397 // Verify that changed values are propagated.
sprangf24a0642017-02-28 13:23:26 -08002398 EXPECT_EQ(kSecondMaxBitrateBps / 1000, config->maxBitrate);
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002399 }
2400 ++num_initializations_;
Per21d45d22016-10-30 21:37:57 +01002401 init_encode_event_.Set();
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002402 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
2403 }
2404
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002405 void PerformTest() override {
pbos14fe7082016-04-20 06:35:56 -07002406 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002407 EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized.";
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002408
sprangf24a0642017-02-28 13:23:26 -08002409 encoder_config_.max_bitrate_bps = kSecondMaxBitrateBps;
perkj26091b12016-09-01 01:17:40 -07002410 stream_->ReconfigureVideoEncoder(std::move(encoder_config_));
pbos14fe7082016-04-20 06:35:56 -07002411 EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002412 EXPECT_EQ(2u, num_initializations_)
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002413 << "ReconfigureVideoEncoder did not reinitialize the encoder with "
2414 "new encoder settings.";
2415 }
2416
sprangf24a0642017-02-28 13:23:26 -08002417 const uint32_t kFirstMaxBitrateBps = 1000000;
2418 const uint32_t kSecondMaxBitrateBps = 2000000;
2419
pbos14fe7082016-04-20 06:35:56 -07002420 rtc::Event init_encode_event_;
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002421 size_t num_initializations_;
2422 VideoSendStream* stream_;
2423 VideoEncoderConfig encoder_config_;
2424 } test;
2425
stefane74eef12016-01-08 06:47:13 -08002426 RunBaseTest(&test);
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +00002427}
2428
Peter Boström53eda3d2015-03-27 15:53:18 +01002429static const size_t kVideoCodecConfigObserverNumberOfTemporalLayers = 4;
2430template <typename T>
2431class VideoCodecConfigObserver : public test::SendTest,
2432 public test::FakeEncoder {
Peter Boström53eda3d2015-03-27 15:53:18 +01002433 public:
2434 VideoCodecConfigObserver(VideoCodecType video_codec_type,
2435 const char* codec_name)
2436 : SendTest(VideoSendStreamTest::kDefaultTimeoutMs),
2437 FakeEncoder(Clock::GetRealTimeClock()),
2438 video_codec_type_(video_codec_type),
2439 codec_name_(codec_name),
pbos14fe7082016-04-20 06:35:56 -07002440 init_encode_event_(false, false),
Erik Språng737336d2016-07-29 12:59:36 +02002441 num_initializations_(0),
2442 stream_(nullptr) {
Peter Boström53eda3d2015-03-27 15:53:18 +01002443 memset(&encoder_settings_, 0, sizeof(encoder_settings_));
2444 }
2445
2446 private:
perkjfa10b552016-10-02 23:45:26 -07002447 class VideoStreamFactory
2448 : public VideoEncoderConfig::VideoStreamFactoryInterface {
2449 public:
2450 VideoStreamFactory() {}
2451
2452 private:
2453 std::vector<VideoStream> CreateEncoderStreams(
2454 int width,
2455 int height,
2456 const VideoEncoderConfig& encoder_config) override {
2457 std::vector<VideoStream> streams =
2458 test::CreateVideoStreams(width, height, encoder_config);
2459 for (size_t i = 0; i < streams.size(); ++i) {
2460 streams[i].temporal_layer_thresholds_bps.resize(
2461 kVideoCodecConfigObserverNumberOfTemporalLayers - 1);
2462 }
2463 return streams;
2464 }
2465 };
2466
stefanff483612015-12-21 03:14:00 -08002467 void ModifyVideoConfigs(
2468 VideoSendStream::Config* send_config,
2469 std::vector<VideoReceiveStream::Config>* receive_configs,
2470 VideoEncoderConfig* encoder_config) override {
Peter Boström53eda3d2015-03-27 15:53:18 +01002471 send_config->encoder_settings.encoder = this;
2472 send_config->encoder_settings.payload_name = codec_name_;
2473
kthelgason29a44e32016-09-27 03:52:02 -07002474 encoder_config->encoder_specific_settings = GetEncoderSpecificSettings();
perkjfa10b552016-10-02 23:45:26 -07002475 encoder_config->video_stream_factory =
2476 new rtc::RefCountedObject<VideoStreamFactory>();
perkj26091b12016-09-01 01:17:40 -07002477 encoder_config_ = encoder_config->Copy();
Peter Boström53eda3d2015-03-27 15:53:18 +01002478 }
2479
stefanff483612015-12-21 03:14:00 -08002480 void OnVideoStreamsCreated(
Peter Boström53eda3d2015-03-27 15:53:18 +01002481 VideoSendStream* send_stream,
2482 const std::vector<VideoReceiveStream*>& receive_streams) override {
2483 stream_ = send_stream;
2484 }
2485
2486 int32_t InitEncode(const VideoCodec* config,
2487 int32_t number_of_cores,
2488 size_t max_payload_size) override {
2489 EXPECT_EQ(video_codec_type_, config->codecType);
2490 VerifyCodecSpecifics(*config);
2491 ++num_initializations_;
Per21d45d22016-10-30 21:37:57 +01002492 init_encode_event_.Set();
Peter Boström53eda3d2015-03-27 15:53:18 +01002493 return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size);
2494 }
2495
2496 void VerifyCodecSpecifics(const VideoCodec& config) const;
kthelgason29a44e32016-09-27 03:52:02 -07002497 rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2498 GetEncoderSpecificSettings() const;
Peter Boström53eda3d2015-03-27 15:53:18 +01002499
2500 void PerformTest() override {
pbos14fe7082016-04-20 06:35:56 -07002501 EXPECT_TRUE(
2502 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002503 ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized.";
Peter Boström53eda3d2015-03-27 15:53:18 +01002504
2505 encoder_settings_.frameDroppingOn = true;
kthelgason29a44e32016-09-27 03:52:02 -07002506 encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings();
perkj26091b12016-09-01 01:17:40 -07002507 stream_->ReconfigureVideoEncoder(std::move(encoder_config_));
pbos14fe7082016-04-20 06:35:56 -07002508 ASSERT_TRUE(
2509 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002510 EXPECT_EQ(2u, num_initializations_)
Peter Boström53eda3d2015-03-27 15:53:18 +01002511 << "ReconfigureVideoEncoder did not reinitialize the encoder with "
2512 "new encoder settings.";
2513 }
2514
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002515 int32_t Encode(const VideoFrame& input_image,
Peter Boström53eda3d2015-03-27 15:53:18 +01002516 const CodecSpecificInfo* codec_specific_info,
pbos22993e12015-10-19 02:39:06 -07002517 const std::vector<FrameType>* frame_types) override {
Peter Boström53eda3d2015-03-27 15:53:18 +01002518 // Silently skip the encode, FakeEncoder::Encode doesn't produce VP8.
2519 return 0;
2520 }
2521
2522 T encoder_settings_;
2523 const VideoCodecType video_codec_type_;
2524 const char* const codec_name_;
pbos14fe7082016-04-20 06:35:56 -07002525 rtc::Event init_encode_event_;
Peter Boström53eda3d2015-03-27 15:53:18 +01002526 size_t num_initializations_;
2527 VideoSendStream* stream_;
2528 VideoEncoderConfig encoder_config_;
2529};
2530
2531template <>
2532void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics(
2533 const VideoCodec& config) const {
hta257dc392016-10-25 09:05:06 -07002534 EXPECT_EQ(
2535 0, memcmp(&config.H264(), &encoder_settings_, sizeof(encoder_settings_)));
Peter Boström53eda3d2015-03-27 15:53:18 +01002536}
kthelgason29a44e32016-09-27 03:52:02 -07002537
2538template <>
2539rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2540VideoCodecConfigObserver<VideoCodecH264>::GetEncoderSpecificSettings() const {
2541 return new rtc::RefCountedObject<
2542 VideoEncoderConfig::H264EncoderSpecificSettings>(encoder_settings_);
2543}
2544
Peter Boström53eda3d2015-03-27 15:53:18 +01002545template <>
2546void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics(
2547 const VideoCodec& config) const {
2548 // Check that the number of temporal layers has propagated properly to
2549 // VideoCodec.
2550 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
hta257dc392016-10-25 09:05:06 -07002551 config.VP8().numberOfTemporalLayers);
Peter Boström53eda3d2015-03-27 15:53:18 +01002552
2553 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) {
2554 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2555 config.simulcastStream[i].numberOfTemporalLayers);
2556 }
2557
2558 // Set expected temporal layers as they should have been set when
Erik Språng08127a92016-11-16 16:41:30 +01002559 // reconfiguring the encoder and not match the set config. Also copy the
mflodmancc3d4422017-08-03 08:27:51 -07002560 // TemporalLayersFactory pointer that has been injected by VideoStreamEncoder.
Peter Boström53eda3d2015-03-27 15:53:18 +01002561 VideoCodecVP8 encoder_settings = encoder_settings_;
2562 encoder_settings.numberOfTemporalLayers =
2563 kVideoCodecConfigObserverNumberOfTemporalLayers;
Erik Språng08127a92016-11-16 16:41:30 +01002564 encoder_settings.tl_factory = config.VP8().tl_factory;
hta257dc392016-10-25 09:05:06 -07002565 EXPECT_EQ(
2566 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_)));
Peter Boström53eda3d2015-03-27 15:53:18 +01002567}
kthelgason29a44e32016-09-27 03:52:02 -07002568
2569template <>
2570rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2571VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const {
2572 return new rtc::RefCountedObject<
2573 VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_);
2574}
2575
Peter Boström53eda3d2015-03-27 15:53:18 +01002576template <>
2577void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics(
2578 const VideoCodec& config) const {
2579 // Check that the number of temporal layers has propagated properly to
2580 // VideoCodec.
2581 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
hta257dc392016-10-25 09:05:06 -07002582 config.VP9().numberOfTemporalLayers);
Peter Boström53eda3d2015-03-27 15:53:18 +01002583
2584 for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) {
2585 EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers,
2586 config.simulcastStream[i].numberOfTemporalLayers);
2587 }
2588
2589 // Set expected temporal layers as they should have been set when
2590 // reconfiguring the encoder and not match the set config.
2591 VideoCodecVP9 encoder_settings = encoder_settings_;
2592 encoder_settings.numberOfTemporalLayers =
2593 kVideoCodecConfigObserverNumberOfTemporalLayers;
hta257dc392016-10-25 09:05:06 -07002594 EXPECT_EQ(
2595 0, memcmp(&(config.VP9()), &encoder_settings, sizeof(encoder_settings_)));
Peter Boström53eda3d2015-03-27 15:53:18 +01002596}
2597
kthelgason29a44e32016-09-27 03:52:02 -07002598template <>
2599rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings>
2600VideoCodecConfigObserver<VideoCodecVP9>::GetEncoderSpecificSettings() const {
2601 return new rtc::RefCountedObject<
2602 VideoEncoderConfig::Vp9EncoderSpecificSettings>(encoder_settings_);
2603}
2604
pbos@webrtc.org91f17522014-07-10 10:13:37 +00002605TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) {
Peter Boström53eda3d2015-03-27 15:53:18 +01002606 VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8");
stefane74eef12016-01-08 06:47:13 -08002607 RunBaseTest(&test);
Peter Boström53eda3d2015-03-27 15:53:18 +01002608}
pbos@webrtc.org91f17522014-07-10 10:13:37 +00002609
Peter Boström53eda3d2015-03-27 15:53:18 +01002610TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) {
2611 VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9");
stefane74eef12016-01-08 06:47:13 -08002612 RunBaseTest(&test);
Peter Boström53eda3d2015-03-27 15:53:18 +01002613}
pbos@webrtc.org91f17522014-07-10 10:13:37 +00002614
Peter Boström53eda3d2015-03-27 15:53:18 +01002615TEST_F(VideoSendStreamTest, EncoderSetupPropagatesH264Config) {
2616 VideoCodecConfigObserver<VideoCodecH264> test(kVideoCodecH264, "H264");
stefane74eef12016-01-08 06:47:13 -08002617 RunBaseTest(&test);
pbos@webrtc.org91f17522014-07-10 10:13:37 +00002618}
2619
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002620TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) {
asapersson@webrtc.org14674212015-02-23 08:14:07 +00002621 class RtcpSenderReportTest : public test::SendTest {
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002622 public:
asapersson@webrtc.org14674212015-02-23 08:14:07 +00002623 RtcpSenderReportTest() : SendTest(kDefaultTimeoutMs),
2624 rtp_packets_sent_(0),
2625 media_bytes_sent_(0) {}
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002626
2627 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002628 Action OnSendRtp(const uint8_t* packet, size_t length) override {
stefan4b569042015-11-11 06:39:57 -08002629 rtc::CritScope lock(&crit_);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002630 RTPHeader header;
2631 EXPECT_TRUE(parser_->Parse(packet, length, &header));
asapersson@webrtc.org14674212015-02-23 08:14:07 +00002632 ++rtp_packets_sent_;
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002633 media_bytes_sent_ += length - header.headerLength - header.paddingLength;
2634 return SEND_PACKET;
2635 }
2636
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002637 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
stefan4b569042015-11-11 06:39:57 -08002638 rtc::CritScope lock(&crit_);
danilchap3dc929e2016-11-02 08:21:59 -07002639 test::RtcpPacketParser parser;
2640 EXPECT_TRUE(parser.Parse(packet, length));
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002641
danilchap3dc929e2016-11-02 08:21:59 -07002642 if (parser.sender_report()->num_packets() > 0) {
2643 // Only compare sent media bytes if SenderPacketCount matches the
2644 // number of sent rtp packets (a new rtp packet could be sent before
2645 // the rtcp packet).
2646 if (parser.sender_report()->sender_octet_count() > 0 &&
2647 parser.sender_report()->sender_packet_count() ==
2648 rtp_packets_sent_) {
2649 EXPECT_EQ(media_bytes_sent_,
2650 parser.sender_report()->sender_octet_count());
2651 observation_complete_.Set();
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002652 }
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002653 }
2654
2655 return SEND_PACKET;
2656 }
2657
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002658 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01002659 EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP sender report.";
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002660 }
2661
stefan4b569042015-11-11 06:39:57 -08002662 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07002663 size_t rtp_packets_sent_ RTC_GUARDED_BY(&crit_);
2664 size_t media_bytes_sent_ RTC_GUARDED_BY(&crit_);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002665 } test;
2666
stefane74eef12016-01-08 06:47:13 -08002667 RunBaseTest(&test);
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +00002668}
2669
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002670TEST_F(VideoSendStreamTest, TranslatesTwoLayerScreencastToTargetBitrate) {
2671 static const int kScreencastTargetBitrateKbps = 200;
perkjfa10b552016-10-02 23:45:26 -07002672
2673 class VideoStreamFactory
2674 : public VideoEncoderConfig::VideoStreamFactoryInterface {
2675 public:
2676 VideoStreamFactory() {}
2677
2678 private:
2679 std::vector<VideoStream> CreateEncoderStreams(
2680 int width,
2681 int height,
2682 const VideoEncoderConfig& encoder_config) override {
2683 std::vector<VideoStream> streams =
2684 test::CreateVideoStreams(width, height, encoder_config);
2685 EXPECT_TRUE(streams[0].temporal_layer_thresholds_bps.empty());
2686 streams[0].temporal_layer_thresholds_bps.push_back(
2687 kScreencastTargetBitrateKbps * 1000);
2688 return streams;
2689 }
2690 };
2691
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002692 class ScreencastTargetBitrateTest : public test::SendTest,
2693 public test::FakeEncoder {
2694 public:
2695 ScreencastTargetBitrateTest()
2696 : SendTest(kDefaultTimeoutMs),
2697 test::FakeEncoder(Clock::GetRealTimeClock()) {}
2698
2699 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002700 int32_t InitEncode(const VideoCodec* config,
2701 int32_t number_of_cores,
2702 size_t max_payload_size) override {
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002703 EXPECT_EQ(static_cast<unsigned int>(kScreencastTargetBitrateKbps),
2704 config->targetBitrate);
Peter Boström5811a392015-12-10 13:02:50 +01002705 observation_complete_.Set();
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002706 return test::FakeEncoder::InitEncode(
2707 config, number_of_cores, max_payload_size);
2708 }
stefanff483612015-12-21 03:14:00 -08002709 void ModifyVideoConfigs(
2710 VideoSendStream::Config* send_config,
2711 std::vector<VideoReceiveStream::Config>* receive_configs,
2712 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002713 send_config->encoder_settings.encoder = this;
perkjfa10b552016-10-02 23:45:26 -07002714 EXPECT_EQ(1u, encoder_config->number_of_streams);
2715 encoder_config->video_stream_factory =
2716 new rtc::RefCountedObject<VideoStreamFactory>();
Erik Språng143cec12015-04-28 10:01:41 +02002717 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002718 }
2719
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002720 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01002721 EXPECT_TRUE(Wait())
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002722 << "Timed out while waiting for the encoder to be initialized.";
2723 }
2724 } test;
2725
stefane74eef12016-01-08 06:47:13 -08002726 RunBaseTest(&test);
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +00002727}
pbos@webrtc.org00873182014-11-25 14:03:34 +00002728
philipelc6957c72016-04-28 15:52:49 +02002729TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002730 // These are chosen to be "kind of odd" to not be accidentally checked against
2731 // default values.
2732 static const int kMinBitrateKbps = 137;
2733 static const int kStartBitrateKbps = 345;
2734 static const int kLowerMaxBitrateKbps = 312;
2735 static const int kMaxBitrateKbps = 413;
2736 static const int kIncreasedStartBitrateKbps = 451;
2737 static const int kIncreasedMaxBitrateKbps = 597;
2738 class EncoderBitrateThresholdObserver : public test::SendTest,
2739 public test::FakeEncoder {
2740 public:
eladalon413ee9a2017-08-22 04:02:52 -07002741 explicit EncoderBitrateThresholdObserver(
2742 test::SingleThreadedTaskQueueForTesting* task_queue)
pbos@webrtc.org00873182014-11-25 14:03:34 +00002743 : SendTest(kDefaultTimeoutMs),
2744 FakeEncoder(Clock::GetRealTimeClock()),
eladalon413ee9a2017-08-22 04:02:52 -07002745 task_queue_(task_queue),
pbos14fe7082016-04-20 06:35:56 -07002746 init_encode_event_(false, false),
perkj26091b12016-09-01 01:17:40 -07002747 bitrate_changed_event_(false, false),
2748 target_bitrate_(0),
Erik Språng737336d2016-07-29 12:59:36 +02002749 num_initializations_(0),
2750 call_(nullptr),
2751 send_stream_(nullptr) {}
pbos@webrtc.org00873182014-11-25 14:03:34 +00002752
2753 private:
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002754 int32_t InitEncode(const VideoCodec* codecSettings,
2755 int32_t numberOfCores,
2756 size_t maxPayloadSize) override {
perkj26091b12016-09-01 01:17:40 -07002757 EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate);
2758 EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate);
Per21d45d22016-10-30 21:37:57 +01002759 if (num_initializations_ == 0) {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002760 EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps),
2761 codecSettings->minBitrate);
2762 EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps),
2763 codecSettings->startBitrate);
2764 EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps),
2765 codecSettings->maxBitrate);
Peter Boström5811a392015-12-10 13:02:50 +01002766 observation_complete_.Set();
Per21d45d22016-10-30 21:37:57 +01002767 } else if (num_initializations_ == 1) {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002768 EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps),
2769 codecSettings->maxBitrate);
2770 // The start bitrate should be kept (-1) and capped to the max bitrate.
2771 // Since this is not an end-to-end call no receiver should have been
2772 // returning a REMB that could lower this estimate.
2773 EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate);
Per21d45d22016-10-30 21:37:57 +01002774 } else if (num_initializations_ == 2) {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002775 EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps),
2776 codecSettings->maxBitrate);
perkj26091b12016-09-01 01:17:40 -07002777 // The start bitrate will be whatever the rate BitRateController
2778 // has currently configured but in the span of the set max and min
2779 // bitrate.
pbos@webrtc.org00873182014-11-25 14:03:34 +00002780 }
2781 ++num_initializations_;
Per21d45d22016-10-30 21:37:57 +01002782 init_encode_event_.Set();
2783
pbos@webrtc.org00873182014-11-25 14:03:34 +00002784 return FakeEncoder::InitEncode(codecSettings, numberOfCores,
2785 maxPayloadSize);
2786 }
2787
Erik Språng08127a92016-11-16 16:41:30 +01002788 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
2789 uint32_t frameRate) override {
perkj26091b12016-09-01 01:17:40 -07002790 {
2791 rtc::CritScope lock(&crit_);
Erik Språng08127a92016-11-16 16:41:30 +01002792 if (target_bitrate_ == bitrate.get_sum_kbps()) {
2793 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
perkjfa10b552016-10-02 23:45:26 -07002794 }
Erik Språng08127a92016-11-16 16:41:30 +01002795 target_bitrate_ = bitrate.get_sum_kbps();
perkj26091b12016-09-01 01:17:40 -07002796 }
2797 bitrate_changed_event_.Set();
Erik Språng08127a92016-11-16 16:41:30 +01002798 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
perkj26091b12016-09-01 01:17:40 -07002799 }
2800
2801 void WaitForSetRates(uint32_t expected_bitrate) {
2802 EXPECT_TRUE(
2803 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs))
2804 << "Timed out while waiting encoder rate to be set.";
2805 rtc::CritScope lock(&crit_);
2806 EXPECT_EQ(expected_bitrate, target_bitrate_);
2807 }
2808
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002809 Call::Config GetSenderCallConfig() override {
philipel4fb651d2017-04-10 03:54:05 -07002810 Call::Config config(event_log_.get());
Stefan Holmere5904162015-03-26 11:11:06 +01002811 config.bitrate_config.min_bitrate_bps = kMinBitrateKbps * 1000;
2812 config.bitrate_config.start_bitrate_bps = kStartBitrateKbps * 1000;
2813 config.bitrate_config.max_bitrate_bps = kMaxBitrateKbps * 1000;
pbos@webrtc.org00873182014-11-25 14:03:34 +00002814 return config;
2815 }
2816
perkjfa10b552016-10-02 23:45:26 -07002817 class VideoStreamFactory
2818 : public VideoEncoderConfig::VideoStreamFactoryInterface {
2819 public:
2820 explicit VideoStreamFactory(int min_bitrate_bps)
2821 : min_bitrate_bps_(min_bitrate_bps) {}
2822
2823 private:
2824 std::vector<VideoStream> CreateEncoderStreams(
2825 int width,
2826 int height,
2827 const VideoEncoderConfig& encoder_config) override {
2828 std::vector<VideoStream> streams =
2829 test::CreateVideoStreams(width, height, encoder_config);
2830 streams[0].min_bitrate_bps = min_bitrate_bps_;
2831 return streams;
2832 }
2833
2834 const int min_bitrate_bps_;
2835 };
2836
stefanff483612015-12-21 03:14:00 -08002837 void ModifyVideoConfigs(
2838 VideoSendStream::Config* send_config,
2839 std::vector<VideoReceiveStream::Config>* receive_configs,
2840 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002841 send_config->encoder_settings.encoder = this;
2842 // Set bitrates lower/higher than min/max to make sure they are properly
2843 // capped.
perkjfa10b552016-10-02 23:45:26 -07002844 encoder_config->max_bitrate_bps = kMaxBitrateKbps * 1000;
2845 // Create a new StreamFactory to be able to set
2846 // |VideoStream.min_bitrate_bps|.
2847 encoder_config->video_stream_factory =
2848 new rtc::RefCountedObject<VideoStreamFactory>(kMinBitrateKbps * 1000);
perkj26091b12016-09-01 01:17:40 -07002849 encoder_config_ = encoder_config->Copy();
pbos@webrtc.org00873182014-11-25 14:03:34 +00002850 }
2851
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002852 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
pbos@webrtc.org00873182014-11-25 14:03:34 +00002853 call_ = sender_call;
2854 }
2855
stefanff483612015-12-21 03:14:00 -08002856 void OnVideoStreamsCreated(
Stefan Holmere5904162015-03-26 11:11:06 +01002857 VideoSendStream* send_stream,
2858 const std::vector<VideoReceiveStream*>& receive_streams) override {
2859 send_stream_ = send_stream;
2860 }
2861
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002862 void PerformTest() override {
pbos14fe7082016-04-20 06:35:56 -07002863 ASSERT_TRUE(
2864 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs))
perkj26091b12016-09-01 01:17:40 -07002865 << "Timed out while waiting for encoder to be configured.";
2866 WaitForSetRates(kStartBitrateKbps);
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01002867 BitrateConstraints bitrate_config;
pbos@webrtc.org00873182014-11-25 14:03:34 +00002868 bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000;
2869 bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000;
eladalon413ee9a2017-08-22 04:02:52 -07002870 task_queue_->SendTask([this, &bitrate_config]() {
2871 call_->SetBitrateConfig(bitrate_config);
2872 });
perkj26091b12016-09-01 01:17:40 -07002873 // Encoder rate is capped by EncoderConfig max_bitrate_bps.
2874 WaitForSetRates(kMaxBitrateKbps);
perkjfa10b552016-10-02 23:45:26 -07002875 encoder_config_.max_bitrate_bps = kLowerMaxBitrateKbps * 1000;
perkj26091b12016-09-01 01:17:40 -07002876 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
pbos14fe7082016-04-20 06:35:56 -07002877 ASSERT_TRUE(
2878 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002879 EXPECT_EQ(2, num_initializations_)
pbos@webrtc.org00873182014-11-25 14:03:34 +00002880 << "Encoder should have been reconfigured with the new value.";
perkjfa10b552016-10-02 23:45:26 -07002881 WaitForSetRates(kLowerMaxBitrateKbps);
2882
2883 encoder_config_.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000;
2884 send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy());
2885 ASSERT_TRUE(
2886 init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs));
Per21d45d22016-10-30 21:37:57 +01002887 EXPECT_EQ(3, num_initializations_)
perkjfa10b552016-10-02 23:45:26 -07002888 << "Encoder should have been reconfigured with the new value.";
perkj26091b12016-09-01 01:17:40 -07002889 // Expected target bitrate is the start bitrate set in the call to
2890 // call_->SetBitrateConfig.
2891 WaitForSetRates(kIncreasedStartBitrateKbps);
pbos@webrtc.org00873182014-11-25 14:03:34 +00002892 }
2893
eladalon413ee9a2017-08-22 04:02:52 -07002894 test::SingleThreadedTaskQueueForTesting* const task_queue_;
pbos14fe7082016-04-20 06:35:56 -07002895 rtc::Event init_encode_event_;
perkj26091b12016-09-01 01:17:40 -07002896 rtc::Event bitrate_changed_event_;
2897 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07002898 uint32_t target_bitrate_ RTC_GUARDED_BY(&crit_);
perkjfa10b552016-10-02 23:45:26 -07002899
pbos@webrtc.org00873182014-11-25 14:03:34 +00002900 int num_initializations_;
2901 webrtc::Call* call_;
Stefan Holmere5904162015-03-26 11:11:06 +01002902 webrtc::VideoSendStream* send_stream_;
2903 webrtc::VideoEncoderConfig encoder_config_;
eladalon413ee9a2017-08-22 04:02:52 -07002904 } test(&task_queue_);
pbos@webrtc.org00873182014-11-25 14:03:34 +00002905
stefane74eef12016-01-08 06:47:13 -08002906 RunBaseTest(&test);
pbos@webrtc.org00873182014-11-25 14:03:34 +00002907}
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002908
2909TEST_F(VideoSendStreamTest, ReportsSentResolution) {
2910 static const size_t kNumStreams = 3;
2911 // Unusual resolutions to make sure that they are the ones being reported.
2912 static const struct {
2913 int width;
2914 int height;
2915 } kEncodedResolution[kNumStreams] = {
2916 {241, 181}, {300, 121}, {121, 221}};
2917 class ScreencastTargetBitrateTest : public test::SendTest,
2918 public test::FakeEncoder {
2919 public:
2920 ScreencastTargetBitrateTest()
2921 : SendTest(kDefaultTimeoutMs),
Erik Språng737336d2016-07-29 12:59:36 +02002922 test::FakeEncoder(Clock::GetRealTimeClock()),
2923 send_stream_(nullptr) {}
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002924
2925 private:
Miguel Casas-Sanchez47650702015-05-29 17:21:40 -07002926 int32_t Encode(const VideoFrame& input_image,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002927 const CodecSpecificInfo* codecSpecificInfo,
pbos22993e12015-10-19 02:39:06 -07002928 const std::vector<FrameType>* frame_types) override {
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002929 CodecSpecificInfo specifics;
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002930 specifics.codecType = kVideoCodecGeneric;
2931
2932 uint8_t buffer[16] = {0};
2933 EncodedImage encoded(buffer, sizeof(buffer), sizeof(buffer));
2934 encoded._timeStamp = input_image.timestamp();
2935 encoded.capture_time_ms_ = input_image.render_time_ms();
2936
2937 for (size_t i = 0; i < kNumStreams; ++i) {
2938 specifics.codecSpecific.generic.simulcast_idx = static_cast<uint8_t>(i);
2939 encoded._frameType = (*frame_types)[i];
2940 encoded._encodedWidth = kEncodedResolution[i].width;
2941 encoded._encodedHeight = kEncodedResolution[i].height;
brandtre78d2662017-01-16 05:57:16 -08002942 EncodedImageCallback* callback;
2943 {
2944 rtc::CritScope cs(&crit_sect_);
2945 callback = callback_;
2946 }
2947 RTC_DCHECK(callback);
2948 if (callback->OnEncodedImage(encoded, &specifics, nullptr).error !=
sergeyu2cb155a2016-11-04 11:39:29 -07002949 EncodedImageCallback::Result::OK) {
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002950 return -1;
sergeyu2cb155a2016-11-04 11:39:29 -07002951 }
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002952 }
2953
Peter Boström5811a392015-12-10 13:02:50 +01002954 observation_complete_.Set();
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002955 return 0;
2956 }
stefanff483612015-12-21 03:14:00 -08002957 void ModifyVideoConfigs(
2958 VideoSendStream::Config* send_config,
2959 std::vector<VideoReceiveStream::Config>* receive_configs,
2960 VideoEncoderConfig* encoder_config) override {
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002961 send_config->encoder_settings.encoder = this;
perkjfa10b552016-10-02 23:45:26 -07002962 EXPECT_EQ(kNumStreams, encoder_config->number_of_streams);
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002963 }
2964
Stefan Holmer9fea80f2016-01-07 17:43:18 +01002965 size_t GetNumVideoStreams() const override { return kNumStreams; }
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002966
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002967 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01002968 EXPECT_TRUE(Wait())
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002969 << "Timed out while waiting for the encoder to send one frame.";
2970 VideoSendStream::Stats stats = send_stream_->GetStats();
2971
2972 for (size_t i = 0; i < kNumStreams; ++i) {
Stefan Holmer9fea80f2016-01-07 17:43:18 +01002973 ASSERT_TRUE(stats.substreams.find(kVideoSendSsrcs[i]) !=
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002974 stats.substreams.end())
Stefan Holmer9fea80f2016-01-07 17:43:18 +01002975 << "No stats for SSRC: " << kVideoSendSsrcs[i]
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002976 << ", stats should exist as soon as frames have been encoded.";
pbos@webrtc.org09c77b92015-02-25 10:42:16 +00002977 VideoSendStream::StreamStats ssrc_stats =
Stefan Holmer9fea80f2016-01-07 17:43:18 +01002978 stats.substreams[kVideoSendSsrcs[i]];
pbos@webrtc.org09c77b92015-02-25 10:42:16 +00002979 EXPECT_EQ(kEncodedResolution[i].width, ssrc_stats.width);
2980 EXPECT_EQ(kEncodedResolution[i].height, ssrc_stats.height);
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002981 }
2982 }
2983
stefanff483612015-12-21 03:14:00 -08002984 void OnVideoStreamsCreated(
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002985 VideoSendStream* send_stream,
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +00002986 const std::vector<VideoReceiveStream*>& receive_streams) override {
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002987 send_stream_ = send_stream;
2988 }
2989
2990 VideoSendStream* send_stream_;
2991 } test;
2992
stefane74eef12016-01-08 06:47:13 -08002993 RunBaseTest(&test);
pbos@webrtc.org273a4142014-12-01 15:23:21 +00002994}
philipel0f9af012015-09-01 07:01:51 -07002995
Peter Boström12996152016-05-14 02:03:18 +02002996#if !defined(RTC_DISABLE_VP9)
Åsa Perssonff24c042015-12-04 10:58:08 +01002997class Vp9HeaderObserver : public test::SendTest {
philipel0f9af012015-09-01 07:01:51 -07002998 public:
Åsa Perssonff24c042015-12-04 10:58:08 +01002999 Vp9HeaderObserver()
3000 : SendTest(VideoSendStreamTest::kLongTimeoutMs),
philipel7fabd462015-09-03 04:42:32 -07003001 vp9_encoder_(VP9Encoder::Create()),
Åsa Perssonff24c042015-12-04 10:58:08 +01003002 vp9_settings_(VideoEncoder::GetDefaultVp9Settings()),
3003 packets_sent_(0),
perkjfa10b552016-10-02 23:45:26 -07003004 frames_sent_(0),
3005 expected_width_(0),
3006 expected_height_(0) {}
philipel7fabd462015-09-03 04:42:32 -07003007
stefanff483612015-12-21 03:14:00 -08003008 virtual void ModifyVideoConfigsHook(
philipel0f9af012015-09-01 07:01:51 -07003009 VideoSendStream::Config* send_config,
3010 std::vector<VideoReceiveStream::Config>* receive_configs,
3011 VideoEncoderConfig* encoder_config) {}
3012
Åsa Perssonff24c042015-12-04 10:58:08 +01003013 virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0;
philipel0f9af012015-09-01 07:01:51 -07003014
3015 private:
minyue20c84cc2017-04-10 16:57:57 -07003016 const int kVp9PayloadType = test::CallTest::kVideoSendPayloadType;
philipel0f9af012015-09-01 07:01:51 -07003017
perkjfa10b552016-10-02 23:45:26 -07003018 class VideoStreamFactory
3019 : public VideoEncoderConfig::VideoStreamFactoryInterface {
3020 public:
3021 explicit VideoStreamFactory(size_t number_of_temporal_layers)
3022 : number_of_temporal_layers_(number_of_temporal_layers) {}
3023
3024 private:
3025 std::vector<VideoStream> CreateEncoderStreams(
3026 int width,
3027 int height,
3028 const VideoEncoderConfig& encoder_config) override {
3029 std::vector<VideoStream> streams =
3030 test::CreateVideoStreams(width, height, encoder_config);
3031 streams[0].temporal_layer_thresholds_bps.resize(
3032 number_of_temporal_layers_ - 1);
3033 return streams;
3034 }
3035
3036 const size_t number_of_temporal_layers_;
3037 };
3038
stefanff483612015-12-21 03:14:00 -08003039 void ModifyVideoConfigs(
3040 VideoSendStream::Config* send_config,
3041 std::vector<VideoReceiveStream::Config>* receive_configs,
3042 VideoEncoderConfig* encoder_config) override {
philipel7fabd462015-09-03 04:42:32 -07003043 send_config->encoder_settings.encoder = vp9_encoder_.get();
philipel0f9af012015-09-01 07:01:51 -07003044 send_config->encoder_settings.payload_name = "VP9";
3045 send_config->encoder_settings.payload_type = kVp9PayloadType;
stefanff483612015-12-21 03:14:00 -08003046 ModifyVideoConfigsHook(send_config, receive_configs, encoder_config);
kthelgason29a44e32016-09-27 03:52:02 -07003047 encoder_config->encoder_specific_settings = new rtc::RefCountedObject<
3048 VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings_);
perkjfa10b552016-10-02 23:45:26 -07003049 EXPECT_EQ(1u, encoder_config->number_of_streams);
3050 encoder_config->video_stream_factory =
3051 new rtc::RefCountedObject<VideoStreamFactory>(
3052 vp9_settings_.numberOfTemporalLayers);
perkj26091b12016-09-01 01:17:40 -07003053 encoder_config_ = encoder_config->Copy();
philipel0f9af012015-09-01 07:01:51 -07003054 }
3055
perkjfa10b552016-10-02 23:45:26 -07003056 void ModifyVideoCaptureStartResolution(int* width,
3057 int* height,
3058 int* frame_rate) override {
3059 expected_width_ = *width;
3060 expected_height_ = *height;
3061 }
3062
philipel0f9af012015-09-01 07:01:51 -07003063 void PerformTest() override {
Peter Boström5811a392015-12-10 13:02:50 +01003064 EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames "
3065 << frames_sent_;
philipel0f9af012015-09-01 07:01:51 -07003066 }
3067
3068 Action OnSendRtp(const uint8_t* packet, size_t length) override {
3069 RTPHeader header;
3070 EXPECT_TRUE(parser_->Parse(packet, length, &header));
3071
Åsa Perssonff24c042015-12-04 10:58:08 +01003072 EXPECT_EQ(kVp9PayloadType, header.payloadType);
3073 const uint8_t* payload = packet + header.headerLength;
3074 size_t payload_length = length - header.headerLength - header.paddingLength;
philipel0f9af012015-09-01 07:01:51 -07003075
Åsa Perssonff24c042015-12-04 10:58:08 +01003076 bool new_packet = packets_sent_ == 0 ||
3077 IsNewerSequenceNumber(header.sequenceNumber,
3078 last_header_.sequenceNumber);
3079 if (payload_length > 0 && new_packet) {
3080 RtpDepacketizer::ParsedPayload parsed;
3081 RtpDepacketizerVp9 depacketizer;
3082 EXPECT_TRUE(depacketizer.Parse(&parsed, payload, payload_length));
3083 EXPECT_EQ(RtpVideoCodecTypes::kRtpVideoVp9, parsed.type.Video.codec);
3084 // Verify common fields for all configurations.
3085 VerifyCommonHeader(parsed.type.Video.codecHeader.VP9);
3086 CompareConsecutiveFrames(header, parsed.type.Video);
3087 // Verify configuration specific settings.
3088 InspectHeader(parsed.type.Video.codecHeader.VP9);
philipel0f9af012015-09-01 07:01:51 -07003089
Åsa Perssonff24c042015-12-04 10:58:08 +01003090 ++packets_sent_;
3091 if (header.markerBit) {
3092 ++frames_sent_;
philipel0f9af012015-09-01 07:01:51 -07003093 }
Åsa Perssonff24c042015-12-04 10:58:08 +01003094 last_header_ = header;
3095 last_vp9_ = parsed.type.Video.codecHeader.VP9;
philipel0f9af012015-09-01 07:01:51 -07003096 }
philipel0f9af012015-09-01 07:01:51 -07003097 return SEND_PACKET;
3098 }
3099
philipel7fabd462015-09-03 04:42:32 -07003100 protected:
Åsa Perssonff24c042015-12-04 10:58:08 +01003101 bool ContinuousPictureId(const RTPVideoHeaderVP9& vp9) const {
3102 if (last_vp9_.picture_id > vp9.picture_id) {
3103 return vp9.picture_id == 0; // Wrap.
3104 } else {
3105 return vp9.picture_id == last_vp9_.picture_id + 1;
3106 }
3107 }
3108
3109 void VerifySpatialIdxWithinFrame(const RTPVideoHeaderVP9& vp9) const {
Åsa Perssonff24c042015-12-04 10:58:08 +01003110 bool new_layer = vp9.spatial_idx != last_vp9_.spatial_idx;
3111 EXPECT_EQ(new_layer, vp9.beginning_of_frame);
3112 EXPECT_EQ(new_layer, last_vp9_.end_of_frame);
3113 EXPECT_EQ(new_layer ? last_vp9_.spatial_idx + 1 : last_vp9_.spatial_idx,
3114 vp9.spatial_idx);
3115 }
3116
3117 void VerifyFixedTemporalLayerStructure(const RTPVideoHeaderVP9& vp9,
3118 uint8_t num_layers) const {
3119 switch (num_layers) {
3120 case 0:
3121 VerifyTemporalLayerStructure0(vp9);
3122 break;
3123 case 1:
3124 VerifyTemporalLayerStructure1(vp9);
3125 break;
3126 case 2:
3127 VerifyTemporalLayerStructure2(vp9);
3128 break;
3129 case 3:
3130 VerifyTemporalLayerStructure3(vp9);
3131 break;
3132 default:
3133 RTC_NOTREACHED();
3134 }
3135 }
3136
3137 void VerifyTemporalLayerStructure0(const RTPVideoHeaderVP9& vp9) const {
3138 EXPECT_EQ(kNoTl0PicIdx, vp9.tl0_pic_idx);
3139 EXPECT_EQ(kNoTemporalIdx, vp9.temporal_idx); // no tid
3140 EXPECT_FALSE(vp9.temporal_up_switch);
3141 }
3142
3143 void VerifyTemporalLayerStructure1(const RTPVideoHeaderVP9& vp9) const {
3144 EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx);
3145 EXPECT_EQ(0, vp9.temporal_idx); // 0,0,0,...
3146 EXPECT_FALSE(vp9.temporal_up_switch);
3147 }
3148
3149 void VerifyTemporalLayerStructure2(const RTPVideoHeaderVP9& vp9) const {
3150 EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx);
3151 EXPECT_GE(vp9.temporal_idx, 0); // 0,1,0,1,... (tid reset on I-frames).
3152 EXPECT_LE(vp9.temporal_idx, 1);
3153 EXPECT_EQ(vp9.temporal_idx > 0, vp9.temporal_up_switch);
3154 if (IsNewPictureId(vp9)) {
3155 uint8_t expected_tid =
3156 (!vp9.inter_pic_predicted || last_vp9_.temporal_idx == 1) ? 0 : 1;
3157 EXPECT_EQ(expected_tid, vp9.temporal_idx);
3158 }
3159 }
3160
3161 void VerifyTemporalLayerStructure3(const RTPVideoHeaderVP9& vp9) const {
3162 EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx);
3163 EXPECT_GE(vp9.temporal_idx, 0); // 0,2,1,2,... (tid reset on I-frames).
3164 EXPECT_LE(vp9.temporal_idx, 2);
3165 if (IsNewPictureId(vp9) && vp9.inter_pic_predicted) {
3166 EXPECT_NE(vp9.temporal_idx, last_vp9_.temporal_idx);
3167 switch (vp9.temporal_idx) {
3168 case 0:
3169 EXPECT_EQ(2, last_vp9_.temporal_idx);
3170 EXPECT_FALSE(vp9.temporal_up_switch);
3171 break;
3172 case 1:
3173 EXPECT_EQ(2, last_vp9_.temporal_idx);
3174 EXPECT_TRUE(vp9.temporal_up_switch);
3175 break;
3176 case 2:
3177 EXPECT_EQ(last_vp9_.temporal_idx == 0, vp9.temporal_up_switch);
3178 break;
3179 }
3180 }
3181 }
3182
3183 void VerifyTl0Idx(const RTPVideoHeaderVP9& vp9) const {
3184 if (vp9.tl0_pic_idx == kNoTl0PicIdx)
3185 return;
3186
3187 uint8_t expected_tl0_idx = last_vp9_.tl0_pic_idx;
3188 if (vp9.temporal_idx == 0)
3189 ++expected_tl0_idx;
3190 EXPECT_EQ(expected_tl0_idx, vp9.tl0_pic_idx);
3191 }
3192
3193 bool IsNewPictureId(const RTPVideoHeaderVP9& vp9) const {
3194 return frames_sent_ > 0 && (vp9.picture_id != last_vp9_.picture_id);
3195 }
3196
3197 // Flexible mode (F=1): Non-flexible mode (F=0):
3198 //
3199 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3200 // |I|P|L|F|B|E|V|-| |I|P|L|F|B|E|V|-|
3201 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3202 // I: |M| PICTURE ID | I: |M| PICTURE ID |
3203 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3204 // M: | EXTENDED PID | M: | EXTENDED PID |
3205 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3206 // L: | T |U| S |D| L: | T |U| S |D|
3207 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3208 // P,F: | P_DIFF |X|N| | TL0PICIDX |
3209 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3210 // X: |EXTENDED P_DIFF| V: | SS .. |
3211 // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
3212 // V: | SS .. |
3213 // +-+-+-+-+-+-+-+-+
3214 void VerifyCommonHeader(const RTPVideoHeaderVP9& vp9) const {
3215 EXPECT_EQ(kMaxTwoBytePictureId, vp9.max_picture_id); // M:1
3216 EXPECT_NE(kNoPictureId, vp9.picture_id); // I:1
3217 EXPECT_EQ(vp9_settings_.flexibleMode, vp9.flexible_mode); // F
Sergey Silkin3f2634e2017-11-06 11:49:19 +01003218
3219 if (vp9_settings_.numberOfSpatialLayers > 1) {
3220 EXPECT_LT(vp9.spatial_idx, vp9_settings_.numberOfSpatialLayers);
3221 } else if (vp9_settings_.numberOfTemporalLayers > 1) {
3222 EXPECT_EQ(vp9.spatial_idx, 0);
3223 } else {
3224 EXPECT_EQ(vp9.spatial_idx, kNoSpatialIdx);
3225 }
3226
3227 if (vp9_settings_.numberOfTemporalLayers > 1) {
3228 EXPECT_LT(vp9.temporal_idx, vp9_settings_.numberOfTemporalLayers);
3229 } else if (vp9_settings_.numberOfSpatialLayers > 1) {
3230 EXPECT_EQ(vp9.temporal_idx, 0);
3231 } else {
3232 EXPECT_EQ(vp9.temporal_idx, kNoTemporalIdx);
3233 }
3234
Åsa Perssonff24c042015-12-04 10:58:08 +01003235 if (vp9.ss_data_available) // V
3236 VerifySsData(vp9);
3237
3238 if (frames_sent_ == 0)
3239 EXPECT_FALSE(vp9.inter_pic_predicted); // P
3240
3241 if (!vp9.inter_pic_predicted) {
3242 EXPECT_TRUE(vp9.temporal_idx == 0 || vp9.temporal_idx == kNoTemporalIdx);
3243 EXPECT_FALSE(vp9.temporal_up_switch);
3244 }
3245 }
3246
3247 // Scalability structure (SS).
3248 //
3249 // +-+-+-+-+-+-+-+-+
3250 // V: | N_S |Y|G|-|-|-|
3251 // +-+-+-+-+-+-+-+-+
3252 // Y: | WIDTH | N_S + 1 times
3253 // +-+-+-+-+-+-+-+-+
3254 // | HEIGHT |
3255 // +-+-+-+-+-+-+-+-+
3256 // G: | N_G |
3257 // +-+-+-+-+-+-+-+-+
3258 // N_G: | T |U| R |-|-| N_G times
3259 // +-+-+-+-+-+-+-+-+
3260 // | P_DIFF | R times
3261 // +-+-+-+-+-+-+-+-+
3262 void VerifySsData(const RTPVideoHeaderVP9& vp9) const {
3263 EXPECT_TRUE(vp9.ss_data_available); // V
3264 EXPECT_EQ(vp9_settings_.numberOfSpatialLayers, // N_S + 1
3265 vp9.num_spatial_layers);
3266 EXPECT_TRUE(vp9.spatial_layer_resolution_present); // Y:1
perkjfa10b552016-10-02 23:45:26 -07003267 int expected_width = expected_width_;
3268 int expected_height = expected_height_;
Peter Boström02083222016-06-14 12:52:54 +02003269 for (int i = static_cast<int>(vp9.num_spatial_layers) - 1; i >= 0; --i) {
Åsa Perssonff24c042015-12-04 10:58:08 +01003270 EXPECT_EQ(expected_width, vp9.width[i]); // WIDTH
3271 EXPECT_EQ(expected_height, vp9.height[i]); // HEIGHT
3272 expected_width /= 2;
3273 expected_height /= 2;
3274 }
3275 }
3276
3277 void CompareConsecutiveFrames(const RTPHeader& header,
3278 const RTPVideoHeader& video) const {
3279 const RTPVideoHeaderVP9& vp9 = video.codecHeader.VP9;
3280
3281 bool new_frame = packets_sent_ == 0 ||
3282 IsNewerTimestamp(header.timestamp, last_header_.timestamp);
johan0d1b2b62017-01-10 04:21:35 -08003283 EXPECT_EQ(new_frame, video.is_first_packet_in_frame);
Åsa Perssonff24c042015-12-04 10:58:08 +01003284 if (!new_frame) {
3285 EXPECT_FALSE(last_header_.markerBit);
3286 EXPECT_EQ(last_header_.timestamp, header.timestamp);
3287 EXPECT_EQ(last_vp9_.picture_id, vp9.picture_id);
3288 EXPECT_EQ(last_vp9_.temporal_idx, vp9.temporal_idx);
3289 EXPECT_EQ(last_vp9_.tl0_pic_idx, vp9.tl0_pic_idx);
3290 VerifySpatialIdxWithinFrame(vp9);
3291 return;
3292 }
3293 // New frame.
3294 EXPECT_TRUE(vp9.beginning_of_frame);
3295
3296 // Compare with last packet in previous frame.
3297 if (frames_sent_ == 0)
3298 return;
3299 EXPECT_TRUE(last_vp9_.end_of_frame);
3300 EXPECT_TRUE(last_header_.markerBit);
3301 EXPECT_TRUE(ContinuousPictureId(vp9));
3302 VerifyTl0Idx(vp9);
3303 }
3304
kwiberg27f982b2016-03-01 11:52:33 -08003305 std::unique_ptr<VP9Encoder> vp9_encoder_;
philipel0f9af012015-09-01 07:01:51 -07003306 VideoCodecVP9 vp9_settings_;
Åsa Perssonff24c042015-12-04 10:58:08 +01003307 webrtc::VideoEncoderConfig encoder_config_;
3308 RTPHeader last_header_;
3309 RTPVideoHeaderVP9 last_vp9_;
3310 size_t packets_sent_;
3311 size_t frames_sent_;
perkjfa10b552016-10-02 23:45:26 -07003312 int expected_width_;
3313 int expected_height_;
philipel0f9af012015-09-01 07:01:51 -07003314};
3315
Åsa Perssonff24c042015-12-04 10:58:08 +01003316TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl1SLayers) {
3317 const uint8_t kNumTemporalLayers = 1;
3318 const uint8_t kNumSpatialLayers = 1;
3319 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3320}
3321
3322TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl1SLayers) {
3323 const uint8_t kNumTemporalLayers = 2;
3324 const uint8_t kNumSpatialLayers = 1;
3325 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3326}
3327
3328TEST_F(VideoSendStreamTest, Vp9NonFlexMode_3Tl1SLayers) {
3329 const uint8_t kNumTemporalLayers = 3;
3330 const uint8_t kNumSpatialLayers = 1;
3331 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3332}
3333
3334TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl2SLayers) {
3335 const uint8_t kNumTemporalLayers = 1;
3336 const uint8_t kNumSpatialLayers = 2;
3337 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3338}
3339
3340TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl2SLayers) {
3341 const uint8_t kNumTemporalLayers = 2;
3342 const uint8_t kNumSpatialLayers = 2;
3343 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3344}
3345
3346TEST_F(VideoSendStreamTest, Vp9NonFlexMode_3Tl2SLayers) {
3347 const uint8_t kNumTemporalLayers = 3;
3348 const uint8_t kNumSpatialLayers = 2;
3349 TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers);
3350}
3351
3352void VideoSendStreamTest::TestVp9NonFlexMode(uint8_t num_temporal_layers,
3353 uint8_t num_spatial_layers) {
3354 static const size_t kNumFramesToSend = 100;
3355 // Set to < kNumFramesToSend and coprime to length of temporal layer
3356 // structures to verify temporal id reset on key frame.
3357 static const int kKeyFrameInterval = 31;
3358 class NonFlexibleMode : public Vp9HeaderObserver {
3359 public:
3360 NonFlexibleMode(uint8_t num_temporal_layers, uint8_t num_spatial_layers)
3361 : num_temporal_layers_(num_temporal_layers),
3362 num_spatial_layers_(num_spatial_layers),
3363 l_field_(num_temporal_layers > 1 || num_spatial_layers > 1) {}
stefanff483612015-12-21 03:14:00 -08003364 void ModifyVideoConfigsHook(
philipel0f9af012015-09-01 07:01:51 -07003365 VideoSendStream::Config* send_config,
3366 std::vector<VideoReceiveStream::Config>* receive_configs,
3367 VideoEncoderConfig* encoder_config) override {
Åsa Perssonff24c042015-12-04 10:58:08 +01003368 vp9_settings_.flexibleMode = false;
3369 vp9_settings_.frameDroppingOn = false;
3370 vp9_settings_.keyFrameInterval = kKeyFrameInterval;
3371 vp9_settings_.numberOfTemporalLayers = num_temporal_layers_;
3372 vp9_settings_.numberOfSpatialLayers = num_spatial_layers_;
philipel0f9af012015-09-01 07:01:51 -07003373 }
3374
Åsa Perssonff24c042015-12-04 10:58:08 +01003375 void InspectHeader(const RTPVideoHeaderVP9& vp9) override {
Sergey Silkin3f2634e2017-11-06 11:49:19 +01003376 bool ss_data_expected =
3377 !vp9.inter_pic_predicted && vp9.beginning_of_frame &&
3378 (vp9.spatial_idx == 0 || vp9.spatial_idx == kNoSpatialIdx);
Åsa Perssonff24c042015-12-04 10:58:08 +01003379 EXPECT_EQ(ss_data_expected, vp9.ss_data_available);
Sergey Silkin3f2634e2017-11-06 11:49:19 +01003380 if (num_spatial_layers_ > 1) {
3381 EXPECT_EQ(vp9.spatial_idx > 0, vp9.inter_layer_predicted);
3382 } else {
3383 EXPECT_FALSE(vp9.inter_layer_predicted);
3384 }
3385
asapersson38bb8ad2015-12-14 01:41:19 -08003386 EXPECT_EQ(!vp9.inter_pic_predicted,
3387 frames_sent_ % kKeyFrameInterval == 0);
Åsa Perssonff24c042015-12-04 10:58:08 +01003388
3389 if (IsNewPictureId(vp9)) {
Sergey Silkin3f2634e2017-11-06 11:49:19 +01003390 if (num_temporal_layers_ == 1 && num_spatial_layers_ == 1) {
3391 EXPECT_EQ(kNoSpatialIdx, vp9.spatial_idx);
3392 } else {
3393 EXPECT_EQ(0, vp9.spatial_idx);
3394 }
3395 if (num_spatial_layers_ > 1)
3396 EXPECT_EQ(num_spatial_layers_ - 1, last_vp9_.spatial_idx);
Åsa Perssonff24c042015-12-04 10:58:08 +01003397 }
3398
3399 VerifyFixedTemporalLayerStructure(vp9,
3400 l_field_ ? num_temporal_layers_ : 0);
3401
3402 if (frames_sent_ > kNumFramesToSend)
Peter Boström5811a392015-12-10 13:02:50 +01003403 observation_complete_.Set();
philipel0f9af012015-09-01 07:01:51 -07003404 }
Åsa Perssonff24c042015-12-04 10:58:08 +01003405 const uint8_t num_temporal_layers_;
3406 const uint8_t num_spatial_layers_;
3407 const bool l_field_;
3408 } test(num_temporal_layers, num_spatial_layers);
philipelcfc319b2015-11-10 07:17:23 -08003409
stefane74eef12016-01-08 06:47:13 -08003410 RunBaseTest(&test);
philipelcfc319b2015-11-10 07:17:23 -08003411}
3412
asaperssond9f641e2016-01-21 01:11:35 -08003413TEST_F(VideoSendStreamTest, Vp9NonFlexModeSmallResolution) {
3414 static const size_t kNumFramesToSend = 50;
3415 static const int kWidth = 4;
3416 static const int kHeight = 4;
3417 class NonFlexibleModeResolution : public Vp9HeaderObserver {
3418 void ModifyVideoConfigsHook(
3419 VideoSendStream::Config* send_config,
3420 std::vector<VideoReceiveStream::Config>* receive_configs,
3421 VideoEncoderConfig* encoder_config) override {
3422 vp9_settings_.flexibleMode = false;
3423 vp9_settings_.numberOfTemporalLayers = 1;
3424 vp9_settings_.numberOfSpatialLayers = 1;
3425
perkjfa10b552016-10-02 23:45:26 -07003426 EXPECT_EQ(1u, encoder_config->number_of_streams);
asaperssond9f641e2016-01-21 01:11:35 -08003427 }
3428
3429 void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override {
3430 if (frames_sent_ > kNumFramesToSend)
3431 observation_complete_.Set();
3432 }
perkjfa10b552016-10-02 23:45:26 -07003433
3434 void ModifyVideoCaptureStartResolution(int* width,
3435 int* height,
3436 int* frame_rate) override {
3437 expected_width_ = kWidth;
3438 expected_height_ = kHeight;
3439 *width = kWidth;
3440 *height = kHeight;
3441 }
asaperssond9f641e2016-01-21 01:11:35 -08003442 } test;
3443
3444 RunBaseTest(&test);
3445}
3446
kjellanderf9e2a362017-03-24 12:17:33 -07003447#if defined(WEBRTC_ANDROID)
3448// Crashes on Android; bugs.webrtc.org/7401
3449#define MAYBE_Vp9FlexModeRefCount DISABLED_Vp9FlexModeRefCount
3450#else
3451#define MAYBE_Vp9FlexModeRefCount Vp9FlexModeRefCount
3452#endif
3453TEST_F(VideoSendStreamTest, MAYBE_Vp9FlexModeRefCount) {
Åsa Perssonff24c042015-12-04 10:58:08 +01003454 class FlexibleMode : public Vp9HeaderObserver {
stefanff483612015-12-21 03:14:00 -08003455 void ModifyVideoConfigsHook(
philipelcfc319b2015-11-10 07:17:23 -08003456 VideoSendStream::Config* send_config,
3457 std::vector<VideoReceiveStream::Config>* receive_configs,
3458 VideoEncoderConfig* encoder_config) override {
Åsa Perssonff24c042015-12-04 10:58:08 +01003459 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
philipelcfc319b2015-11-10 07:17:23 -08003460 vp9_settings_.flexibleMode = true;
Åsa Perssonff24c042015-12-04 10:58:08 +01003461 vp9_settings_.numberOfTemporalLayers = 1;
3462 vp9_settings_.numberOfSpatialLayers = 2;
philipelcfc319b2015-11-10 07:17:23 -08003463 }
3464
Åsa Perssonff24c042015-12-04 10:58:08 +01003465 void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override {
3466 EXPECT_TRUE(vp9_header.flexible_mode);
3467 EXPECT_EQ(kNoTl0PicIdx, vp9_header.tl0_pic_idx);
3468 if (vp9_header.inter_pic_predicted) {
3469 EXPECT_GT(vp9_header.num_ref_pics, 0u);
Peter Boström5811a392015-12-10 13:02:50 +01003470 observation_complete_.Set();
philipelcfc319b2015-11-10 07:17:23 -08003471 }
3472 }
3473 } test;
3474
stefane74eef12016-01-08 06:47:13 -08003475 RunBaseTest(&test);
philipelcfc319b2015-11-10 07:17:23 -08003476}
Peter Boström12996152016-05-14 02:03:18 +02003477#endif // !defined(RTC_DISABLE_VP9)
philipelcfc319b2015-11-10 07:17:23 -08003478
perkj803d97f2016-11-01 11:45:46 -07003479void VideoSendStreamTest::TestRequestSourceRotateVideo(
3480 bool support_orientation_ext) {
philipel4fb651d2017-04-10 03:54:05 -07003481 CreateSenderCall(Call::Config(event_log_.get()));
perkj803d97f2016-11-01 11:45:46 -07003482
3483 test::NullTransport transport;
brandtr841de6a2016-11-15 07:10:52 -08003484 CreateSendConfig(1, 0, 0, &transport);
perkj803d97f2016-11-01 11:45:46 -07003485 video_send_config_.rtp.extensions.clear();
3486 if (support_orientation_ext) {
3487 video_send_config_.rtp.extensions.push_back(
3488 RtpExtension(RtpExtension::kVideoRotationUri, 1));
3489 }
3490
3491 CreateVideoStreams();
3492 test::FrameForwarder forwarder;
3493 video_send_stream_->SetSource(
sprangc5d62e22017-04-02 23:53:04 -07003494 &forwarder, VideoSendStream::DegradationPreference::kMaintainFramerate);
perkj803d97f2016-11-01 11:45:46 -07003495
3496 EXPECT_TRUE(forwarder.sink_wants().rotation_applied !=
3497 support_orientation_ext);
3498
3499 DestroyStreams();
3500}
3501
3502TEST_F(VideoSendStreamTest,
3503 RequestSourceRotateIfVideoOrientationExtensionNotSupported) {
3504 TestRequestSourceRotateVideo(false);
3505}
3506
3507TEST_F(VideoSendStreamTest,
3508 DoNotRequestsRotationIfVideoOrientationExtensionSupported) {
3509 TestRequestSourceRotateVideo(true);
3510}
3511
michaelta3328772016-11-29 09:25:03 -08003512// This test verifies that overhead is removed from the bandwidth estimate by
3513// testing that the maximum possible target payload rate is smaller than the
3514// maximum bandwidth estimate by the overhead rate.
michaelt273f31b2017-02-08 08:21:52 -08003515TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) {
michaelta3328772016-11-29 09:25:03 -08003516 test::ScopedFieldTrials override_field_trials(
3517 "WebRTC-SendSideBwe-WithOverhead/Enabled/");
3518 class RemoveOverheadFromBandwidthTest : public test::EndToEndTest,
3519 public test::FakeEncoder {
3520 public:
eladalon413ee9a2017-08-22 04:02:52 -07003521 explicit RemoveOverheadFromBandwidthTest(
3522 test::SingleThreadedTaskQueueForTesting* task_queue)
michaelta3328772016-11-29 09:25:03 -08003523 : EndToEndTest(test::CallTest::kDefaultTimeoutMs),
3524 FakeEncoder(Clock::GetRealTimeClock()),
eladalon413ee9a2017-08-22 04:02:52 -07003525 task_queue_(task_queue),
michaelta3328772016-11-29 09:25:03 -08003526 call_(nullptr),
michaelt192132e2017-01-26 09:05:27 -08003527 max_bitrate_bps_(0),
3528 first_packet_sent_(false),
3529 bitrate_changed_event_(false, false) {}
michaelta3328772016-11-29 09:25:03 -08003530
3531 int32_t SetRateAllocation(const BitrateAllocation& bitrate,
3532 uint32_t frameRate) override {
3533 rtc::CritScope lock(&crit_);
michaelt192132e2017-01-26 09:05:27 -08003534 // Wait for the first sent packet so that videosendstream knows
3535 // rtp_overhead.
3536 if (first_packet_sent_) {
3537 max_bitrate_bps_ = bitrate.get_sum_bps();
3538 bitrate_changed_event_.Set();
3539 }
michaelta3328772016-11-29 09:25:03 -08003540 return FakeEncoder::SetRateAllocation(bitrate, frameRate);
3541 }
3542
3543 void OnCallsCreated(Call* sender_call, Call* receiver_call) override {
3544 call_ = sender_call;
3545 }
3546
3547 void ModifyVideoConfigs(
3548 VideoSendStream::Config* send_config,
3549 std::vector<VideoReceiveStream::Config>* receive_configs,
3550 VideoEncoderConfig* encoder_config) override {
3551 send_config->rtp.max_packet_size = 1200;
3552 send_config->encoder_settings.encoder = this;
3553 EXPECT_FALSE(send_config->rtp.extensions.empty());
3554 }
3555
michaelt192132e2017-01-26 09:05:27 -08003556 Action OnSendRtp(const uint8_t* packet, size_t length) override {
3557 rtc::CritScope lock(&crit_);
3558 first_packet_sent_ = true;
3559 return SEND_PACKET;
3560 }
3561
michaelta3328772016-11-29 09:25:03 -08003562 void PerformTest() override {
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003563 BitrateConstraints bitrate_config;
michaelt192132e2017-01-26 09:05:27 -08003564 constexpr int kStartBitrateBps = 60000;
michaelta3328772016-11-29 09:25:03 -08003565 constexpr int kMaxBitrateBps = 60000;
michaelt192132e2017-01-26 09:05:27 -08003566 constexpr int kMinBitrateBps = 10000;
michaelta3328772016-11-29 09:25:03 -08003567 bitrate_config.start_bitrate_bps = kStartBitrateBps;
3568 bitrate_config.max_bitrate_bps = kMaxBitrateBps;
michaelt192132e2017-01-26 09:05:27 -08003569 bitrate_config.min_bitrate_bps = kMinBitrateBps;
eladalon413ee9a2017-08-22 04:02:52 -07003570 task_queue_->SendTask([this, &bitrate_config]() {
3571 call_->SetBitrateConfig(bitrate_config);
3572 call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO, 40);
3573 });
michaelta3328772016-11-29 09:25:03 -08003574
3575 // At a bitrate of 60kbps with a packet size of 1200B video and an
michaelt192132e2017-01-26 09:05:27 -08003576 // overhead of 40B per packet video produces 2240bps overhead.
3577 // So the encoder BW should be set to 57760bps.
3578 bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs);
michaelta3328772016-11-29 09:25:03 -08003579 {
3580 rtc::CritScope lock(&crit_);
michaelt273f31b2017-02-08 08:21:52 -08003581 EXPECT_LE(max_bitrate_bps_, 57760u);
michaelta3328772016-11-29 09:25:03 -08003582 }
3583 }
3584
3585 private:
eladalon413ee9a2017-08-22 04:02:52 -07003586 test::SingleThreadedTaskQueueForTesting* const task_queue_;
michaelta3328772016-11-29 09:25:03 -08003587 Call* call_;
3588 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -07003589 uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&crit_);
3590 bool first_packet_sent_ RTC_GUARDED_BY(&crit_);
michaelt192132e2017-01-26 09:05:27 -08003591 rtc::Event bitrate_changed_event_;
eladalon413ee9a2017-08-22 04:02:52 -07003592 } test(&task_queue_);
michaelta3328772016-11-29 09:25:03 -08003593 RunBaseTest(&test);
3594}
3595
sprang168794c2017-07-06 04:38:06 -07003596TEST_F(VideoSendStreamTest, SendsKeepAlive) {
3597 const int kTimeoutMs = 50; // Really short timeout for testing.
sprang168794c2017-07-06 04:38:06 -07003598
3599 class KeepaliveObserver : public test::SendTest {
3600 public:
3601 KeepaliveObserver() : SendTest(kDefaultTimeoutMs) {}
3602
sprangdb2a9fc2017-08-09 06:42:32 -07003603 void OnRtpTransportControllerSendCreated(
3604 RtpTransportControllerSend* controller) override {
3605 RtpKeepAliveConfig config;
3606 config.timeout_interval_ms = kTimeoutMs;
3607 config.payload_type = CallTest::kDefaultKeepalivePayloadType;
3608 controller->SetKeepAliveConfig(config);
sprange5c4a812017-07-11 03:44:17 -07003609 }
3610
sprang168794c2017-07-06 04:38:06 -07003611 private:
3612 Action OnSendRtp(const uint8_t* packet, size_t length) override {
3613 RTPHeader header;
3614 EXPECT_TRUE(parser_->Parse(packet, length, &header));
3615
sprangd2702ef2017-07-10 08:41:10 -07003616 if (header.payloadType != CallTest::kDefaultKeepalivePayloadType) {
sprang168794c2017-07-06 04:38:06 -07003617 // The video stream has started. Stop it now.
3618 if (capturer_)
3619 capturer_->Stop();
3620 } else {
3621 observation_complete_.Set();
3622 }
3623
3624 return SEND_PACKET;
3625 }
3626
sprang168794c2017-07-06 04:38:06 -07003627 void PerformTest() override {
3628 EXPECT_TRUE(Wait()) << "Timed out while waiting for keep-alive packet.";
3629 }
3630
3631 void OnFrameGeneratorCapturerCreated(
3632 test::FrameGeneratorCapturer* frame_generator_capturer) override {
3633 capturer_ = frame_generator_capturer;
3634 }
3635
3636 test::FrameGeneratorCapturer* capturer_ = nullptr;
3637 } test;
3638
3639 RunBaseTest(&test);
3640}
3641
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003642class PacingFactorObserver : public test::SendTest {
3643 public:
3644 PacingFactorObserver(bool configure_send_side,
3645 rtc::Optional<float> expected_pacing_factor)
3646 : test::SendTest(VideoSendStreamTest::kDefaultTimeoutMs),
3647 configure_send_side_(configure_send_side),
3648 expected_pacing_factor_(expected_pacing_factor) {}
Erik Språng7c8cca32017-10-24 17:05:18 +02003649
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003650 void ModifyVideoConfigs(
3651 VideoSendStream::Config* send_config,
3652 std::vector<VideoReceiveStream::Config>* receive_configs,
3653 VideoEncoderConfig* encoder_config) override {
3654 // Check if send-side bwe extension is already present, and remove it if
3655 // it is not desired.
3656 bool has_send_side = false;
3657 for (auto it = send_config->rtp.extensions.begin();
3658 it != send_config->rtp.extensions.end(); ++it) {
3659 if (it->uri == RtpExtension::kTransportSequenceNumberUri) {
3660 if (configure_send_side_) {
3661 has_send_side = true;
3662 } else {
3663 send_config->rtp.extensions.erase(it);
Erik Språng7c8cca32017-10-24 17:05:18 +02003664 }
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003665 break;
Erik Språng7c8cca32017-10-24 17:05:18 +02003666 }
Erik Språng7c8cca32017-10-24 17:05:18 +02003667 }
3668
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003669 if (configure_send_side_ && !has_send_side) {
3670 // Want send side, not present by default, so add it.
3671 send_config->rtp.extensions.emplace_back(
3672 RtpExtension::kTransportSequenceNumberUri,
3673 RtpExtension::kTransportSequenceNumberDefaultId);
Erik Språng7c8cca32017-10-24 17:05:18 +02003674 }
3675
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003676 // ALR only enabled for screenshare.
3677 encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen;
3678 }
Erik Språng7c8cca32017-10-24 17:05:18 +02003679
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003680 void OnVideoStreamsCreated(
3681 VideoSendStream* send_stream,
3682 const std::vector<VideoReceiveStream*>& receive_streams) override {
3683 auto internal_send_peer = test::VideoSendStreamPeer(send_stream);
3684 // Video streams created, check that pacing factor is correctly configured.
3685 EXPECT_EQ(expected_pacing_factor_,
3686 internal_send_peer.GetPacingFactorOverride());
3687 observation_complete_.Set();
3688 }
Erik Språng7c8cca32017-10-24 17:05:18 +02003689
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003690 void PerformTest() override {
3691 EXPECT_TRUE(Wait()) << "Timed out while waiting for stream creation.";
3692 }
Erik Språng7c8cca32017-10-24 17:05:18 +02003693
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003694 private:
3695 const bool configure_send_side_;
3696 const rtc::Optional<float> expected_pacing_factor_;
3697};
3698
3699std::string GetAlrProbingExperimentString() {
3700 return std::string(
3701 AlrExperimentSettings::kScreenshareProbingBweExperimentName) +
3702 "/1.0,2875,80,40,-60,3/";
3703}
3704const float kAlrProbingExperimentPaceMultiplier = 1.0f;
3705
3706TEST_F(VideoSendStreamTest, AlrConfiguredWhenSendSideOn) {
3707 test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString());
Erik Språng7c8cca32017-10-24 17:05:18 +02003708 // Send-side bwe on, use pacing factor from |kAlrProbingExperiment| above.
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003709 PacingFactorObserver test_with_send_side(true,
3710 kAlrProbingExperimentPaceMultiplier);
Erik Språng7c8cca32017-10-24 17:05:18 +02003711 RunBaseTest(&test_with_send_side);
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003712}
Erik Språng7c8cca32017-10-24 17:05:18 +02003713
Sebastian Janssona45c8da2018-01-16 10:55:29 +01003714TEST_F(VideoSendStreamTest, AlrNotConfiguredWhenSendSideOff) {
3715 test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString());
3716 // Send-side bwe off, use configuration should not be overridden.
3717 PacingFactorObserver test_without_send_side(false, rtc::nullopt);
Erik Språng7c8cca32017-10-24 17:05:18 +02003718 RunBaseTest(&test_without_send_side);
3719}
3720
pbos@webrtc.org119a1cc2013-08-20 13:14:07 +00003721} // namespace webrtc