pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 10 | #include <algorithm> // max |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 11 | #include <memory> |
magjed@webrtc.org | 2d2a30c | 2015-03-24 12:37:36 +0000 | [diff] [blame] | 12 | #include <vector> |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #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 Jansson | cabe383 | 2018-01-12 10:54:18 +0100 | [diff] [blame] | 28 | #include "rtc_base/experiments/alr_experiment.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #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" |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 36 | #include "test/encoder_proxy_factory.h" |
| 37 | #include "test/fake_encoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 38 | #include "test/fake_texture_frame.h" |
| 39 | #include "test/field_trial.h" |
| 40 | #include "test/frame_generator.h" |
| 41 | #include "test/frame_generator_capturer.h" |
| 42 | #include "test/frame_utils.h" |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 43 | #include "test/gmock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 44 | #include "test/gtest.h" |
| 45 | #include "test/null_transport.h" |
| 46 | #include "test/rtcp_packet_parser.h" |
| 47 | #include "test/testsupport/perf_test.h" |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 48 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 49 | #include "call/video_send_stream.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 50 | #include "video/send_statistics_proxy.h" |
| 51 | #include "video/transport_adapter.h" |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 52 | #include "video/video_send_stream.h" |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 53 | |
| 54 | namespace webrtc { |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 55 | namespace test { |
| 56 | class VideoSendStreamPeer { |
| 57 | public: |
| 58 | explicit VideoSendStreamPeer(webrtc::VideoSendStream* base_class_stream) |
| 59 | : internal_stream_( |
| 60 | static_cast<internal::VideoSendStream*>(base_class_stream)) {} |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 61 | absl::optional<float> GetPacingFactorOverride() const { |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 62 | return internal_stream_->GetPacingFactorOverride(); |
| 63 | } |
| 64 | |
| 65 | private: |
| 66 | internal::VideoSendStream const* const internal_stream_; |
| 67 | }; |
| 68 | } // namespace test |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 69 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 70 | enum VideoFormat { |
| 71 | kGeneric, |
| 72 | kVP8, |
| 73 | }; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 74 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 75 | void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1, |
| 76 | const std::vector<VideoFrame>& frames2); |
| 77 | VideoFrame CreateVideoFrame(int width, int height, uint8_t data); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 78 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 79 | class VideoSendStreamTest : public test::CallTest { |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 80 | protected: |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 81 | void TestNackRetransmission(uint32_t retransmit_ssrc, |
stefan@webrtc.org | cb254aa | 2014-06-12 15:12:25 +0000 | [diff] [blame] | 82 | uint8_t retransmit_payload_type); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 83 | void TestPacketFragmentationSize(VideoFormat format, bool with_fec); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 84 | |
| 85 | void TestVp9NonFlexMode(uint8_t num_temporal_layers, |
| 86 | uint8_t num_spatial_layers); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 87 | |
| 88 | void TestRequestSourceRotateVideo(bool support_orientation_ext); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
pbos@webrtc.org | f777cf2 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 91 | TEST_F(VideoSendStreamTest, CanStartStartedStream) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 92 | task_queue_.SendTask([this]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 93 | CreateSenderCall(); |
pbos@webrtc.org | f777cf2 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 94 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 95 | test::NullTransport transport; |
| 96 | CreateSendConfig(1, 0, 0, &transport); |
| 97 | CreateVideoStreams(); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 98 | GetVideoSendStream()->Start(); |
| 99 | GetVideoSendStream()->Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 100 | DestroyStreams(); |
| 101 | DestroyCalls(); |
| 102 | }); |
pbos@webrtc.org | f777cf2 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | TEST_F(VideoSendStreamTest, CanStopStoppedStream) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 106 | task_queue_.SendTask([this]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 107 | CreateSenderCall(); |
pbos@webrtc.org | f777cf2 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 108 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 109 | test::NullTransport transport; |
| 110 | CreateSendConfig(1, 0, 0, &transport); |
| 111 | CreateVideoStreams(); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 112 | GetVideoSendStream()->Stop(); |
| 113 | GetVideoSendStream()->Stop(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 114 | DestroyStreams(); |
| 115 | DestroyCalls(); |
| 116 | }); |
pbos@webrtc.org | f777cf2 | 2014-01-10 18:47:32 +0000 | [diff] [blame] | 117 | } |
| 118 | |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 119 | TEST_F(VideoSendStreamTest, SupportsCName) { |
| 120 | static std::string kCName = "PjQatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo="; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 121 | class CNameObserver : public test::SendTest { |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 122 | public: |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 123 | CNameObserver() : SendTest(kDefaultTimeoutMs) {} |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 124 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 125 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 126 | Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 127 | test::RtcpPacketParser parser; |
| 128 | EXPECT_TRUE(parser.Parse(packet, length)); |
| 129 | if (parser.sdes()->num_packets() > 0) { |
| 130 | EXPECT_EQ(1u, parser.sdes()->chunks().size()); |
| 131 | EXPECT_EQ(kCName, parser.sdes()->chunks()[0].cname); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 132 | |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 133 | observation_complete_.Set(); |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 134 | } |
| 135 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 136 | return SEND_PACKET; |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 137 | } |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 138 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 139 | void ModifyVideoConfigs( |
| 140 | VideoSendStream::Config* send_config, |
| 141 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 142 | VideoEncoderConfig* encoder_config) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 143 | send_config->rtp.c_name = kCName; |
| 144 | } |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 145 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 146 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 147 | EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP with CNAME."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 148 | } |
| 149 | } test; |
pbos@webrtc.org | 013d994 | 2013-08-22 09:42:17 +0000 | [diff] [blame] | 150 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 151 | RunBaseTest(&test); |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 152 | } |
| 153 | |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 154 | TEST_F(VideoSendStreamTest, SupportsAbsoluteSendTime) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 155 | class AbsoluteSendTimeObserver : public test::SendTest { |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 156 | public: |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 157 | AbsoluteSendTimeObserver() : SendTest(kDefaultTimeoutMs) { |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 158 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 159 | kRtpExtensionAbsoluteSendTime, test::kAbsSendTimeExtensionId)); |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 160 | } |
| 161 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 162 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 163 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 164 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 165 | |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 166 | EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); |
| 167 | EXPECT_TRUE(header.extension.hasAbsoluteSendTime); |
| 168 | EXPECT_EQ(header.extension.transmissionTimeOffset, 0); |
skvlad | c3f3515 | 2016-09-02 13:23:46 -0700 | [diff] [blame] | 169 | if (header.extension.absoluteSendTime != 0) { |
| 170 | // Wait for at least one packet with a non-zero send time. The send time |
| 171 | // is a 16-bit value derived from the system clock, and it is valid |
| 172 | // for a packet to have a zero send time. To tell that from an |
| 173 | // unpopulated value we'll wait for a packet with non-zero send time. |
| 174 | observation_complete_.Set(); |
| 175 | } else { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 176 | RTC_LOG(LS_WARNING) |
| 177 | << "Got a packet with zero absoluteSendTime, waiting" |
| 178 | " for another packet..."; |
skvlad | c3f3515 | 2016-09-02 13:23:46 -0700 | [diff] [blame] | 179 | } |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 180 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 181 | return SEND_PACKET; |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 182 | } |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 183 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 184 | void ModifyVideoConfigs( |
| 185 | VideoSendStream::Config* send_config, |
| 186 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 187 | VideoEncoderConfig* encoder_config) override { |
Erik Språng | 9526187 | 2015-04-10 11:58:49 +0200 | [diff] [blame] | 188 | send_config->rtp.extensions.clear(); |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 189 | send_config->rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 190 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 191 | } |
pbos@webrtc.org | dde16f1 | 2014-08-05 23:35:43 +0000 | [diff] [blame] | 192 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 193 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 194 | EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 195 | } |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 196 | } test; |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 197 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 198 | RunBaseTest(&test); |
pbos@webrtc.org | 5c678ea | 2013-09-11 19:00:39 +0000 | [diff] [blame] | 199 | } |
| 200 | |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 201 | TEST_F(VideoSendStreamTest, SupportsTransmissionTimeOffset) { |
asapersson@webrtc.org | 049e4ec | 2014-11-20 10:19:46 +0000 | [diff] [blame] | 202 | static const int kEncodeDelayMs = 5; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 203 | class TransmissionTimeOffsetObserver : public test::SendTest { |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 204 | public: |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 205 | TransmissionTimeOffsetObserver() |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 206 | : SendTest(kDefaultTimeoutMs), encoder_factory_([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 207 | return absl::make_unique<test::DelayedEncoder>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 208 | Clock::GetRealTimeClock(), kEncodeDelayMs); |
| 209 | }) { |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 210 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 211 | kRtpExtensionTransmissionTimeOffset, test::kTOffsetExtensionId)); |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 212 | } |
| 213 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 214 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 215 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 216 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 217 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 218 | |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 219 | EXPECT_TRUE(header.extension.hasTransmissionTimeOffset); |
| 220 | EXPECT_FALSE(header.extension.hasAbsoluteSendTime); |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 221 | EXPECT_GT(header.extension.transmissionTimeOffset, 0); |
pbos@webrtc.org | 5ab7567 | 2013-12-16 12:24:44 +0000 | [diff] [blame] | 222 | EXPECT_EQ(header.extension.absoluteSendTime, 0u); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 223 | observation_complete_.Set(); |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 224 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 225 | return SEND_PACKET; |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 226 | } |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 227 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 228 | void ModifyVideoConfigs( |
| 229 | VideoSendStream::Config* send_config, |
| 230 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 231 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 232 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
Stefan Holmer | 1295297 | 2015-10-29 15:13:24 +0100 | [diff] [blame] | 233 | send_config->rtp.extensions.clear(); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 234 | send_config->rtp.extensions.push_back(RtpExtension( |
| 235 | RtpExtension::kTimestampOffsetUri, test::kTOffsetExtensionId)); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 236 | } |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 237 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 238 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 239 | EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 240 | } |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 241 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 242 | test::FunctionVideoEncoderFactory encoder_factory_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 243 | } test; |
| 244 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 245 | RunBaseTest(&test); |
pbos@webrtc.org | 2902328 | 2013-09-11 10:14:56 +0000 | [diff] [blame] | 246 | } |
| 247 | |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 248 | TEST_F(VideoSendStreamTest, SupportsTransportWideSequenceNumbers) { |
danilchap | 42ca68a | 2016-10-31 03:34:40 -0700 | [diff] [blame] | 249 | static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId; |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 250 | class TransportWideSequenceNumberObserver : public test::SendTest { |
| 251 | public: |
| 252 | TransportWideSequenceNumberObserver() |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 253 | : SendTest(kDefaultTimeoutMs), encoder_factory_([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 254 | return absl::make_unique<test::FakeEncoder>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 255 | Clock::GetRealTimeClock()); |
| 256 | }) { |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 257 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 258 | kRtpExtensionTransportSequenceNumber, kExtensionId)); |
| 259 | } |
| 260 | |
| 261 | private: |
| 262 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 263 | RTPHeader header; |
| 264 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 265 | |
| 266 | EXPECT_TRUE(header.extension.hasTransportSequenceNumber); |
| 267 | EXPECT_FALSE(header.extension.hasTransmissionTimeOffset); |
| 268 | EXPECT_FALSE(header.extension.hasAbsoluteSendTime); |
| 269 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 270 | observation_complete_.Set(); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 271 | |
| 272 | return SEND_PACKET; |
| 273 | } |
| 274 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 275 | void ModifyVideoConfigs( |
| 276 | VideoSendStream::Config* send_config, |
| 277 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 278 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 279 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 283 | EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet."; |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 286 | test::FunctionVideoEncoderFactory encoder_factory_; |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 287 | } test; |
| 288 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 289 | RunBaseTest(&test); |
sprang | 867fb52 | 2015-08-03 04:38:41 -0700 | [diff] [blame] | 290 | } |
| 291 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 292 | TEST_F(VideoSendStreamTest, SupportsVideoRotation) { |
| 293 | class VideoRotationObserver : public test::SendTest { |
| 294 | public: |
| 295 | VideoRotationObserver() : SendTest(kDefaultTimeoutMs) { |
| 296 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 297 | kRtpExtensionVideoRotation, test::kVideoRotationExtensionId)); |
| 298 | } |
| 299 | |
| 300 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 301 | RTPHeader header; |
| 302 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
ilnik | 7a3006b | 2017-05-23 09:34:21 -0700 | [diff] [blame] | 303 | // Only the last packet of the frame is required to have the extension. |
| 304 | if (!header.markerBit) |
| 305 | return SEND_PACKET; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 306 | EXPECT_TRUE(header.extension.hasVideoRotation); |
| 307 | EXPECT_EQ(kVideoRotation_90, header.extension.videoRotation); |
| 308 | observation_complete_.Set(); |
| 309 | return SEND_PACKET; |
| 310 | } |
| 311 | |
| 312 | void ModifyVideoConfigs( |
| 313 | VideoSendStream::Config* send_config, |
| 314 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 315 | VideoEncoderConfig* encoder_config) override { |
| 316 | send_config->rtp.extensions.clear(); |
| 317 | send_config->rtp.extensions.push_back(RtpExtension( |
| 318 | RtpExtension::kVideoRotationUri, test::kVideoRotationExtensionId)); |
| 319 | } |
| 320 | |
| 321 | void OnFrameGeneratorCapturerCreated( |
| 322 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 323 | frame_generator_capturer->SetFakeRotation(kVideoRotation_90); |
| 324 | } |
| 325 | |
| 326 | void PerformTest() override { |
| 327 | EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet."; |
| 328 | } |
| 329 | } test; |
| 330 | |
| 331 | RunBaseTest(&test); |
| 332 | } |
| 333 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 334 | TEST_F(VideoSendStreamTest, SupportsVideoContentType) { |
ilnik | 1089499 | 2017-06-21 08:23:19 -0700 | [diff] [blame] | 335 | class VideoContentTypeObserver : public test::SendTest { |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 336 | public: |
Ilya Nikolaevskiy | efbb978 | 2018-03-12 10:42:08 +0100 | [diff] [blame] | 337 | VideoContentTypeObserver() |
| 338 | : SendTest(kDefaultTimeoutMs), first_frame_sent_(false) { |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 339 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 340 | kRtpExtensionVideoContentType, test::kVideoContentTypeExtensionId)); |
| 341 | } |
| 342 | |
| 343 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 344 | RTPHeader header; |
| 345 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
Ilya Nikolaevskiy | efbb978 | 2018-03-12 10:42:08 +0100 | [diff] [blame] | 346 | // Only the last packet of the key-frame must have extension. |
| 347 | if (!header.markerBit || first_frame_sent_) |
ilnik | 7a3006b | 2017-05-23 09:34:21 -0700 | [diff] [blame] | 348 | return SEND_PACKET; |
Ilya Nikolaevskiy | efbb978 | 2018-03-12 10:42:08 +0100 | [diff] [blame] | 349 | // First marker bit seen means that the first frame is sent. |
| 350 | first_frame_sent_ = true; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 351 | EXPECT_TRUE(header.extension.hasVideoContentType); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 352 | EXPECT_TRUE(videocontenttypehelpers::IsScreenshare( |
| 353 | header.extension.videoContentType)); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 354 | observation_complete_.Set(); |
| 355 | return SEND_PACKET; |
| 356 | } |
| 357 | |
| 358 | void ModifyVideoConfigs( |
| 359 | VideoSendStream::Config* send_config, |
| 360 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 361 | VideoEncoderConfig* encoder_config) override { |
| 362 | send_config->rtp.extensions.clear(); |
| 363 | send_config->rtp.extensions.push_back( |
| 364 | RtpExtension(RtpExtension::kVideoContentTypeUri, |
| 365 | test::kVideoContentTypeExtensionId)); |
| 366 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
| 367 | } |
| 368 | |
| 369 | void PerformTest() override { |
| 370 | EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet."; |
| 371 | } |
Ilya Nikolaevskiy | efbb978 | 2018-03-12 10:42:08 +0100 | [diff] [blame] | 372 | |
| 373 | private: |
| 374 | bool first_frame_sent_; |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 375 | } test; |
| 376 | |
| 377 | RunBaseTest(&test); |
| 378 | } |
| 379 | |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 380 | TEST_F(VideoSendStreamTest, SupportsVideoTimingFrames) { |
ilnik | 1089499 | 2017-06-21 08:23:19 -0700 | [diff] [blame] | 381 | class VideoTimingObserver : public test::SendTest { |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 382 | public: |
ilnik | 1089499 | 2017-06-21 08:23:19 -0700 | [diff] [blame] | 383 | VideoTimingObserver() : SendTest(kDefaultTimeoutMs) { |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 384 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 385 | kRtpExtensionVideoTiming, test::kVideoTimingExtensionId)); |
| 386 | } |
| 387 | |
| 388 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 389 | RTPHeader header; |
| 390 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
ilnik | 1089499 | 2017-06-21 08:23:19 -0700 | [diff] [blame] | 391 | // Only the last packet of the frame must have extension. |
| 392 | if (!header.markerBit) |
| 393 | return SEND_PACKET; |
| 394 | EXPECT_TRUE(header.extension.has_video_timing); |
| 395 | observation_complete_.Set(); |
ilnik | 04f4d12 | 2017-06-19 07:18:55 -0700 | [diff] [blame] | 396 | return SEND_PACKET; |
| 397 | } |
| 398 | |
| 399 | void ModifyVideoConfigs( |
| 400 | VideoSendStream::Config* send_config, |
| 401 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 402 | VideoEncoderConfig* encoder_config) override { |
| 403 | send_config->rtp.extensions.clear(); |
| 404 | send_config->rtp.extensions.push_back(RtpExtension( |
| 405 | RtpExtension::kVideoTimingUri, test::kVideoTimingExtensionId)); |
| 406 | } |
| 407 | |
| 408 | void PerformTest() override { |
| 409 | EXPECT_TRUE(Wait()) << "Timed out while waiting for timing frames."; |
| 410 | } |
| 411 | } test; |
| 412 | |
| 413 | RunBaseTest(&test); |
| 414 | } |
| 415 | |
danilchap | 901b2df | 2017-07-28 08:56:04 -0700 | [diff] [blame] | 416 | class FakeReceiveStatistics : public ReceiveStatisticsProvider { |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 417 | public: |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 418 | FakeReceiveStatistics(uint32_t send_ssrc, |
| 419 | uint32_t last_sequence_number, |
| 420 | uint32_t cumulative_lost, |
danilchap | 901b2df | 2017-07-28 08:56:04 -0700 | [diff] [blame] | 421 | uint8_t fraction_lost) { |
| 422 | stat_.SetMediaSsrc(send_ssrc); |
| 423 | stat_.SetExtHighestSeqNum(last_sequence_number); |
| 424 | stat_.SetCumulativeLost(cumulative_lost); |
| 425 | stat_.SetFractionLost(fraction_lost); |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 426 | } |
| 427 | |
danilchap | 901b2df | 2017-07-28 08:56:04 -0700 | [diff] [blame] | 428 | std::vector<rtcp::ReportBlock> RtcpReportBlocks(size_t max_blocks) override { |
| 429 | EXPECT_GE(max_blocks, 1u); |
| 430 | return {stat_}; |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | private: |
danilchap | 901b2df | 2017-07-28 08:56:04 -0700 | [diff] [blame] | 434 | rtcp::ReportBlock stat_; |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 435 | }; |
| 436 | |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 437 | class UlpfecObserver : public test::EndToEndTest { |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 438 | public: |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 439 | UlpfecObserver(bool header_extensions_enabled, |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 440 | bool use_nack, |
| 441 | bool expect_red, |
| 442 | bool expect_ulpfec, |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 443 | const std::string& codec, |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 444 | VideoEncoderFactory* encoder_factory) |
brandtr | 20d4547 | 2017-01-02 00:34:27 -0800 | [diff] [blame] | 445 | : EndToEndTest(kTimeoutMs), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 446 | encoder_factory_(encoder_factory), |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 447 | payload_name_(codec), |
| 448 | use_nack_(use_nack), |
| 449 | expect_red_(expect_red), |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 450 | expect_ulpfec_(expect_ulpfec), |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 451 | sent_media_(false), |
| 452 | sent_ulpfec_(false), |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 453 | header_extensions_enabled_(header_extensions_enabled) {} |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 454 | |
brandtr | 20d4547 | 2017-01-02 00:34:27 -0800 | [diff] [blame] | 455 | // Some of the test cases are expected to time out and thus we are using |
| 456 | // a shorter timeout window than the default here. |
| 457 | static constexpr size_t kTimeoutMs = 10000; |
| 458 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 459 | private: |
| 460 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 461 | RTPHeader header; |
| 462 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 463 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 464 | int encapsulated_payload_type = -1; |
| 465 | if (header.payloadType == VideoSendStreamTest::kRedPayloadType) { |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 466 | EXPECT_TRUE(expect_red_); |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 467 | encapsulated_payload_type = static_cast<int>(packet[header.headerLength]); |
| 468 | if (encapsulated_payload_type != |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 469 | VideoSendStreamTest::kFakeVideoSendPayloadType) { |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 470 | EXPECT_EQ(VideoSendStreamTest::kUlpfecPayloadType, |
| 471 | encapsulated_payload_type); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 472 | } |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 473 | } else { |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 474 | EXPECT_EQ(VideoSendStreamTest::kFakeVideoSendPayloadType, |
| 475 | header.payloadType); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 476 | if (static_cast<size_t>(header.headerLength + header.paddingLength) < |
| 477 | length) { |
| 478 | // Not padding-only, media received outside of RED. |
| 479 | EXPECT_FALSE(expect_red_); |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 480 | sent_media_ = true; |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 481 | } |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 482 | } |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 483 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 484 | if (header_extensions_enabled_) { |
| 485 | EXPECT_TRUE(header.extension.hasAbsoluteSendTime); |
| 486 | uint32_t kHalf24BitsSpace = 0xFFFFFF / 2; |
| 487 | if (header.extension.absoluteSendTime <= kHalf24BitsSpace && |
| 488 | prev_header_.extension.absoluteSendTime > kHalf24BitsSpace) { |
| 489 | // 24 bits wrap. |
| 490 | EXPECT_GT(prev_header_.extension.absoluteSendTime, |
| 491 | header.extension.absoluteSendTime); |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 492 | } else { |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 493 | EXPECT_GE(header.extension.absoluteSendTime, |
| 494 | prev_header_.extension.absoluteSendTime); |
Stefan Holmer | 01b4888 | 2015-05-05 10:21:24 +0200 | [diff] [blame] | 495 | } |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 496 | EXPECT_TRUE(header.extension.hasTransportSequenceNumber); |
| 497 | uint16_t seq_num_diff = header.extension.transportSequenceNumber - |
| 498 | prev_header_.extension.transportSequenceNumber; |
| 499 | EXPECT_EQ(1, seq_num_diff); |
| 500 | } |
Stefan Holmer | 01b4888 | 2015-05-05 10:21:24 +0200 | [diff] [blame] | 501 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 502 | if (encapsulated_payload_type != -1) { |
| 503 | if (encapsulated_payload_type == |
| 504 | VideoSendStreamTest::kUlpfecPayloadType) { |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 505 | EXPECT_TRUE(expect_ulpfec_); |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 506 | sent_ulpfec_ = true; |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 507 | } else { |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 508 | sent_media_ = true; |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 509 | } |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 510 | } |
| 511 | |
brandtr | 20d4547 | 2017-01-02 00:34:27 -0800 | [diff] [blame] | 512 | if (sent_media_ && sent_ulpfec_) { |
| 513 | observation_complete_.Set(); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 514 | } |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 515 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 516 | prev_header_ = header; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 517 | |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 518 | return SEND_PACKET; |
| 519 | } |
| 520 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 521 | test::PacketTransport* CreateSendTransport( |
| 522 | test::SingleThreadedTaskQueueForTesting* task_queue, |
| 523 | Call* sender_call) override { |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 524 | // At low RTT (< kLowRttNackMs) -> NACK only, no FEC. |
| 525 | // Configure some network delay. |
| 526 | const int kNetworkDelayMs = 100; |
| 527 | FakeNetworkPipe::Config config; |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 528 | config.loss_percent = 5; |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 529 | config.queue_delay_ms = kNetworkDelayMs; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 530 | return new test::PacketTransport( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 531 | task_queue, sender_call, this, test::PacketTransport::kSender, |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 532 | VideoSendStreamTest::payload_type_map_, config); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 533 | } |
| 534 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 535 | void ModifyVideoConfigs( |
| 536 | VideoSendStream::Config* send_config, |
| 537 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 538 | VideoEncoderConfig* encoder_config) override { |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 539 | if (use_nack_) { |
| 540 | send_config->rtp.nack.rtp_history_ms = |
| 541 | (*receive_configs)[0].rtp.nack.rtp_history_ms = |
| 542 | VideoSendStreamTest::kNackRtpHistoryMs; |
| 543 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 544 | send_config->encoder_settings.encoder_factory = encoder_factory_; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 545 | send_config->rtp.payload_name = payload_name_; |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 546 | send_config->rtp.ulpfec.red_payload_type = |
| 547 | VideoSendStreamTest::kRedPayloadType; |
| 548 | send_config->rtp.ulpfec.ulpfec_payload_type = |
| 549 | VideoSendStreamTest::kUlpfecPayloadType; |
stefan | b77c716 | 2017-02-06 06:29:38 -0800 | [diff] [blame] | 550 | EXPECT_FALSE(send_config->rtp.extensions.empty()); |
| 551 | if (!header_extensions_enabled_) { |
| 552 | send_config->rtp.extensions.clear(); |
| 553 | } else { |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 554 | send_config->rtp.extensions.push_back(RtpExtension( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 555 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 556 | } |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 557 | encoder_config->codec_type = PayloadStringToCodecType(payload_name_); |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 558 | (*receive_configs)[0].rtp.red_payload_type = |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 559 | send_config->rtp.ulpfec.red_payload_type; |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 560 | (*receive_configs)[0].rtp.ulpfec_payload_type = |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 561 | send_config->rtp.ulpfec.ulpfec_payload_type; |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | void PerformTest() override { |
brandtr | 20d4547 | 2017-01-02 00:34:27 -0800 | [diff] [blame] | 565 | EXPECT_EQ(expect_ulpfec_, Wait()) |
| 566 | << "Timed out waiting for ULPFEC and/or media packets."; |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 569 | VideoEncoderFactory* encoder_factory_; |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 570 | std::string payload_name_; |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 571 | const bool use_nack_; |
| 572 | const bool expect_red_; |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 573 | const bool expect_ulpfec_; |
brandtr | 65a1e77 | 2016-12-12 01:54:58 -0800 | [diff] [blame] | 574 | bool sent_media_; |
| 575 | bool sent_ulpfec_; |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 576 | bool header_extensions_enabled_; |
| 577 | RTPHeader prev_header_; |
| 578 | }; |
| 579 | |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 580 | TEST_F(VideoSendStreamTest, SupportsUlpfecWithExtensions) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 581 | test::FunctionVideoEncoderFactory encoder_factory( |
| 582 | []() { return VP8Encoder::Create(); }); |
| 583 | UlpfecObserver test(true, false, true, true, "VP8", &encoder_factory); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 584 | RunBaseTest(&test); |
Stefan Holmer | 4654d20 | 2015-12-08 09:10:43 +0100 | [diff] [blame] | 585 | } |
| 586 | |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 587 | TEST_F(VideoSendStreamTest, SupportsUlpfecWithoutExtensions) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 588 | test::FunctionVideoEncoderFactory encoder_factory( |
| 589 | []() { return VP8Encoder::Create(); }); |
| 590 | UlpfecObserver test(false, false, true, true, "VP8", &encoder_factory); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 591 | RunBaseTest(&test); |
| 592 | } |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 593 | |
stefan | 60e10c7 | 2017-08-23 10:40:00 -0700 | [diff] [blame] | 594 | class VideoSendStreamWithoutUlpfecTest : public VideoSendStreamTest { |
| 595 | protected: |
| 596 | VideoSendStreamWithoutUlpfecTest() |
| 597 | : field_trial_("WebRTC-DisableUlpFecExperiment/Enabled/") {} |
| 598 | |
| 599 | test::ScopedFieldTrials field_trial_; |
| 600 | }; |
| 601 | |
| 602 | TEST_F(VideoSendStreamWithoutUlpfecTest, NoUlpfecIfDisabledThroughFieldTrial) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 603 | test::FunctionVideoEncoderFactory encoder_factory( |
| 604 | []() { return VP8Encoder::Create(); }); |
Kári Tristan Helgason | 798ee75 | 2018-07-11 16:04:57 +0200 | [diff] [blame] | 605 | UlpfecObserver test(false, false, false, false, "VP8", &encoder_factory); |
stefan | 60e10c7 | 2017-08-23 10:40:00 -0700 | [diff] [blame] | 606 | RunBaseTest(&test); |
| 607 | } |
| 608 | |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 609 | // The FEC scheme used is not efficient for H264, so we should not use RED/FEC |
| 610 | // since we'll still have to re-request FEC packets, effectively wasting |
| 611 | // bandwidth since the receiver has to wait for FEC retransmissions to determine |
| 612 | // that the received state is actually decodable. |
brandtr | e602f0a | 2016-10-31 03:40:49 -0700 | [diff] [blame] | 613 | TEST_F(VideoSendStreamTest, DoesNotUtilizeUlpfecForH264WithNackEnabled) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 614 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 615 | return absl::make_unique<test::FakeH264Encoder>(Clock::GetRealTimeClock()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 616 | }); |
Kári Tristan Helgason | 798ee75 | 2018-07-11 16:04:57 +0200 | [diff] [blame] | 617 | UlpfecObserver test(false, true, false, false, "H264", &encoder_factory); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 618 | RunBaseTest(&test); |
| 619 | } |
| 620 | |
| 621 | // Without retransmissions FEC for H264 is fine. |
brandtr | e6f98c7 | 2016-11-11 03:28:30 -0800 | [diff] [blame] | 622 | TEST_F(VideoSendStreamTest, DoesUtilizeUlpfecForH264WithoutNackEnabled) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 623 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 624 | return absl::make_unique<test::FakeH264Encoder>(Clock::GetRealTimeClock()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 625 | }); |
| 626 | UlpfecObserver test(false, false, true, true, "H264", &encoder_factory); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 627 | RunBaseTest(&test); |
| 628 | } |
| 629 | |
danilchap | 9f5b622 | 2017-03-02 06:22:21 -0800 | [diff] [blame] | 630 | // Disabled as flaky, see https://crbug.com/webrtc/7285 for details. |
| 631 | TEST_F(VideoSendStreamTest, DISABLED_DoesUtilizeUlpfecForVp8WithNackEnabled) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 632 | test::FunctionVideoEncoderFactory encoder_factory( |
| 633 | []() { return VP8Encoder::Create(); }); |
| 634 | UlpfecObserver test(false, true, true, true, "VP8", &encoder_factory); |
Peter Boström | 3959397 | 2016-02-15 11:27:15 +0100 | [diff] [blame] | 635 | RunBaseTest(&test); |
| 636 | } |
| 637 | |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 638 | #if !defined(RTC_DISABLE_VP9) |
danilchap | 9f5b622 | 2017-03-02 06:22:21 -0800 | [diff] [blame] | 639 | // Disabled as flaky, see https://crbug.com/webrtc/7285 for details. |
| 640 | TEST_F(VideoSendStreamTest, DISABLED_DoesUtilizeUlpfecForVp9WithNackEnabled) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 641 | test::FunctionVideoEncoderFactory encoder_factory( |
| 642 | []() { return VP9Encoder::Create(); }); |
| 643 | UlpfecObserver test(false, true, true, true, "VP9", &encoder_factory); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 644 | RunBaseTest(&test); |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 645 | } |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 646 | #endif // !defined(RTC_DISABLE_VP9) |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 647 | |
brandtr | e78d266 | 2017-01-16 05:57:16 -0800 | [diff] [blame] | 648 | TEST_F(VideoSendStreamTest, SupportsUlpfecWithMultithreadedH264) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 649 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 650 | return absl::make_unique<test::MultithreadedFakeH264Encoder>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 651 | Clock::GetRealTimeClock()); |
| 652 | }); |
| 653 | UlpfecObserver test(false, false, true, true, "H264", &encoder_factory); |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 654 | RunBaseTest(&test); |
| 655 | } |
| 656 | |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 657 | // TODO(brandtr): Move these FlexFEC tests when we have created |
| 658 | // FlexfecSendStream. |
| 659 | class FlexfecObserver : public test::EndToEndTest { |
| 660 | public: |
| 661 | FlexfecObserver(bool header_extensions_enabled, |
| 662 | bool use_nack, |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 663 | const std::string& codec, |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 664 | VideoEncoderFactory* encoder_factory, |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 665 | size_t num_video_streams) |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 666 | : EndToEndTest(VideoSendStreamTest::kDefaultTimeoutMs), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 667 | encoder_factory_(encoder_factory), |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 668 | payload_name_(codec), |
| 669 | use_nack_(use_nack), |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 670 | sent_media_(false), |
| 671 | sent_flexfec_(false), |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 672 | header_extensions_enabled_(header_extensions_enabled), |
| 673 | num_video_streams_(num_video_streams) {} |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 674 | |
| 675 | size_t GetNumFlexfecStreams() const override { return 1; } |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 676 | size_t GetNumVideoStreams() const override { return num_video_streams_; } |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 677 | |
| 678 | private: |
| 679 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 680 | RTPHeader header; |
| 681 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 682 | |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 683 | if (header.payloadType == VideoSendStreamTest::kFlexfecPayloadType) { |
| 684 | EXPECT_EQ(VideoSendStreamTest::kFlexfecSendSsrc, header.ssrc); |
| 685 | sent_flexfec_ = true; |
| 686 | } else { |
| 687 | EXPECT_EQ(VideoSendStreamTest::kFakeVideoSendPayloadType, |
| 688 | header.payloadType); |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 689 | EXPECT_THAT(testing::make_tuple(VideoSendStreamTest::kVideoSendSsrcs, |
| 690 | num_video_streams_), |
| 691 | testing::Contains(header.ssrc)); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 692 | sent_media_ = true; |
| 693 | } |
| 694 | |
| 695 | if (header_extensions_enabled_) { |
| 696 | EXPECT_TRUE(header.extension.hasAbsoluteSendTime); |
| 697 | EXPECT_TRUE(header.extension.hasTransmissionTimeOffset); |
| 698 | EXPECT_TRUE(header.extension.hasTransportSequenceNumber); |
| 699 | } |
| 700 | |
brandtr | 0c5a154 | 2016-11-23 04:42:26 -0800 | [diff] [blame] | 701 | if (sent_media_ && sent_flexfec_) { |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 702 | observation_complete_.Set(); |
| 703 | } |
| 704 | |
| 705 | return SEND_PACKET; |
| 706 | } |
| 707 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 708 | test::PacketTransport* CreateSendTransport( |
| 709 | test::SingleThreadedTaskQueueForTesting* task_queue, |
| 710 | Call* sender_call) override { |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 711 | // At low RTT (< kLowRttNackMs) -> NACK only, no FEC. |
| 712 | // Therefore we need some network delay. |
| 713 | const int kNetworkDelayMs = 100; |
| 714 | FakeNetworkPipe::Config config; |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 715 | config.loss_percent = 5; |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 716 | config.queue_delay_ms = kNetworkDelayMs; |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 717 | return new test::PacketTransport( |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 718 | task_queue, sender_call, this, test::PacketTransport::kSender, |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 719 | VideoSendStreamTest::payload_type_map_, config); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void ModifyVideoConfigs( |
| 723 | VideoSendStream::Config* send_config, |
| 724 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 725 | VideoEncoderConfig* encoder_config) override { |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 726 | if (use_nack_) { |
| 727 | send_config->rtp.nack.rtp_history_ms = |
| 728 | (*receive_configs)[0].rtp.nack.rtp_history_ms = |
| 729 | VideoSendStreamTest::kNackRtpHistoryMs; |
| 730 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 731 | send_config->encoder_settings.encoder_factory = encoder_factory_; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 732 | send_config->rtp.payload_name = payload_name_; |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 733 | if (header_extensions_enabled_) { |
| 734 | send_config->rtp.extensions.push_back(RtpExtension( |
| 735 | RtpExtension::kAbsSendTimeUri, test::kAbsSendTimeExtensionId)); |
| 736 | send_config->rtp.extensions.push_back(RtpExtension( |
| 737 | RtpExtension::kTimestampOffsetUri, test::kTOffsetExtensionId)); |
stefan | b77c716 | 2017-02-06 06:29:38 -0800 | [diff] [blame] | 738 | } else { |
| 739 | send_config->rtp.extensions.clear(); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 740 | } |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 741 | encoder_config->codec_type = PayloadStringToCodecType(payload_name_); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | void PerformTest() override { |
| 745 | EXPECT_TRUE(Wait()) |
| 746 | << "Timed out waiting for FlexFEC and/or media packets."; |
| 747 | } |
| 748 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 749 | VideoEncoderFactory* encoder_factory_; |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 750 | std::string payload_name_; |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 751 | const bool use_nack_; |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 752 | bool sent_media_; |
| 753 | bool sent_flexfec_; |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 754 | const bool header_extensions_enabled_; |
| 755 | const size_t num_video_streams_; |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 756 | }; |
| 757 | |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 758 | TEST_F(VideoSendStreamTest, SupportsFlexfecVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 759 | test::FunctionVideoEncoderFactory encoder_factory( |
| 760 | []() { return VP8Encoder::Create(); }); |
| 761 | FlexfecObserver test(false, false, "VP8", &encoder_factory, 1); |
Danil Chapovalov | 45d725d | 2018-02-19 19:09:53 +0100 | [diff] [blame] | 762 | RunBaseTest(&test); |
| 763 | } |
| 764 | |
| 765 | TEST_F(VideoSendStreamTest, SupportsFlexfecSimulcastVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 766 | test::FunctionVideoEncoderFactory encoder_factory( |
| 767 | []() { return VP8Encoder::Create(); }); |
| 768 | FlexfecObserver test(false, false, "VP8", &encoder_factory, 2); |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 769 | RunBaseTest(&test); |
| 770 | } |
| 771 | |
| 772 | TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 773 | test::FunctionVideoEncoderFactory encoder_factory( |
| 774 | []() { return VP8Encoder::Create(); }); |
| 775 | FlexfecObserver test(false, true, "VP8", &encoder_factory, 1); |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 776 | RunBaseTest(&test); |
| 777 | } |
| 778 | |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 779 | TEST_F(VideoSendStreamTest, SupportsFlexfecWithRtpExtensionsVp8) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 780 | test::FunctionVideoEncoderFactory encoder_factory( |
| 781 | []() { return VP8Encoder::Create(); }); |
| 782 | FlexfecObserver test(true, false, "VP8", &encoder_factory, 1); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 783 | RunBaseTest(&test); |
| 784 | } |
| 785 | |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 786 | #if !defined(RTC_DISABLE_VP9) |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 787 | TEST_F(VideoSendStreamTest, SupportsFlexfecVp9) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 788 | test::FunctionVideoEncoderFactory encoder_factory( |
| 789 | []() { return VP9Encoder::Create(); }); |
| 790 | FlexfecObserver test(false, false, "VP9", &encoder_factory, 1); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 791 | RunBaseTest(&test); |
| 792 | } |
| 793 | |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 794 | TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackVp9) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 795 | test::FunctionVideoEncoderFactory encoder_factory( |
| 796 | []() { return VP9Encoder::Create(); }); |
| 797 | FlexfecObserver test(false, true, "VP9", &encoder_factory, 1); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 798 | RunBaseTest(&test); |
| 799 | } |
| 800 | #endif // defined(RTC_DISABLE_VP9) |
| 801 | |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 802 | TEST_F(VideoSendStreamTest, SupportsFlexfecH264) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 803 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 804 | return absl::make_unique<test::FakeH264Encoder>(Clock::GetRealTimeClock()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 805 | }); |
| 806 | FlexfecObserver test(false, false, "H264", &encoder_factory, 1); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 807 | RunBaseTest(&test); |
| 808 | } |
| 809 | |
brandtr | d654a9b | 2016-12-05 05:38:19 -0800 | [diff] [blame] | 810 | TEST_F(VideoSendStreamTest, SupportsFlexfecWithNackH264) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 811 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 812 | return absl::make_unique<test::FakeH264Encoder>(Clock::GetRealTimeClock()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 813 | }); |
| 814 | FlexfecObserver test(false, true, "H264", &encoder_factory, 1); |
brandtr | 696c9c6 | 2016-12-19 05:47:28 -0800 | [diff] [blame] | 815 | RunBaseTest(&test); |
| 816 | } |
| 817 | |
brandtr | e78d266 | 2017-01-16 05:57:16 -0800 | [diff] [blame] | 818 | TEST_F(VideoSendStreamTest, SupportsFlexfecWithMultithreadedH264) { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 819 | test::FunctionVideoEncoderFactory encoder_factory([]() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 820 | return absl::make_unique<test::MultithreadedFakeH264Encoder>( |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 821 | Clock::GetRealTimeClock()); |
| 822 | }); |
| 823 | |
| 824 | FlexfecObserver test(false, false, "H264", &encoder_factory, 1); |
brandtr | 39f9729 | 2016-11-16 22:57:50 -0800 | [diff] [blame] | 825 | RunBaseTest(&test); |
| 826 | } |
| 827 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 828 | void VideoSendStreamTest::TestNackRetransmission( |
| 829 | uint32_t retransmit_ssrc, |
stefan@webrtc.org | cb254aa | 2014-06-12 15:12:25 +0000 | [diff] [blame] | 830 | uint8_t retransmit_payload_type) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 831 | class NackObserver : public test::SendTest { |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 832 | public: |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 833 | explicit NackObserver(uint32_t retransmit_ssrc, |
| 834 | uint8_t retransmit_payload_type) |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 835 | : SendTest(kDefaultTimeoutMs), |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 836 | send_count_(0), |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 837 | retransmit_count_(0), |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 838 | retransmit_ssrc_(retransmit_ssrc), |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 839 | retransmit_payload_type_(retransmit_payload_type) {} |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 840 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 841 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 842 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 843 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 844 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 845 | |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 846 | int kRetransmitTarget = 6; |
| 847 | ++send_count_; |
| 848 | if (send_count_ == 5 || send_count_ == 25) { |
| 849 | nacked_sequence_numbers_.push_back( |
| 850 | static_cast<uint16_t>(header.sequenceNumber - 3)); |
| 851 | nacked_sequence_numbers_.push_back( |
| 852 | static_cast<uint16_t>(header.sequenceNumber - 2)); |
| 853 | nacked_sequence_numbers_.push_back( |
| 854 | static_cast<uint16_t>(header.sequenceNumber - 1)); |
| 855 | |
danilchap | 8a1d2a3 | 2017-08-01 03:21:37 -0700 | [diff] [blame] | 856 | RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(), nullptr, |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 857 | nullptr, nullptr, transport_adapter_.get(), |
| 858 | RtcpIntervalConfig{}); |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 859 | |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 860 | rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 861 | rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]); |
pbos@webrtc.org | 0e63e76 | 2013-09-20 11:56:26 +0000 | [diff] [blame] | 862 | |
| 863 | RTCPSender::FeedbackState feedback_state; |
| 864 | |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 865 | EXPECT_EQ(0, rtcp_sender.SendRTCP( |
| 866 | feedback_state, kRtcpNack, |
| 867 | static_cast<int>(nacked_sequence_numbers_.size()), |
| 868 | &nacked_sequence_numbers_.front())); |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 869 | } |
| 870 | |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 871 | uint16_t sequence_number = header.sequenceNumber; |
| 872 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 873 | if (header.ssrc == retransmit_ssrc_ && |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 874 | retransmit_ssrc_ != kVideoSendSsrcs[0]) { |
| 875 | // Not kVideoSendSsrcs[0], assume correct RTX packet. Extract sequence |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 876 | // number. |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 877 | const uint8_t* rtx_header = packet + header.headerLength; |
| 878 | sequence_number = (rtx_header[0] << 8) + rtx_header[1]; |
| 879 | } |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 880 | auto found = std::find(nacked_sequence_numbers_.begin(), |
| 881 | nacked_sequence_numbers_.end(), sequence_number); |
| 882 | if (found != nacked_sequence_numbers_.end()) { |
| 883 | nacked_sequence_numbers_.erase(found); |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 884 | |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 885 | if (++retransmit_count_ == kRetransmitTarget) { |
| 886 | EXPECT_EQ(retransmit_ssrc_, header.ssrc); |
| 887 | EXPECT_EQ(retransmit_payload_type_, header.payloadType); |
| 888 | observation_complete_.Set(); |
| 889 | } |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 890 | } |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 891 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 892 | return SEND_PACKET; |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 893 | } |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 894 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 895 | void ModifyVideoConfigs( |
| 896 | VideoSendStream::Config* send_config, |
| 897 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 898 | VideoEncoderConfig* encoder_config) override { |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 899 | transport_adapter_.reset( |
| 900 | new internal::TransportAdapter(send_config->send_transport)); |
| 901 | transport_adapter_->Enable(); |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 902 | send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 903 | send_config->rtp.rtx.payload_type = retransmit_payload_type_; |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 904 | if (retransmit_ssrc_ != kVideoSendSsrcs[0]) |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 905 | send_config->rtp.rtx.ssrcs.push_back(retransmit_ssrc_); |
| 906 | } |
| 907 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 908 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 909 | EXPECT_TRUE(Wait()) << "Timed out while waiting for NACK retransmission."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 910 | } |
| 911 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 912 | std::unique_ptr<internal::TransportAdapter> transport_adapter_; |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 913 | int send_count_; |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 914 | int retransmit_count_; |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 915 | uint32_t retransmit_ssrc_; |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 916 | uint8_t retransmit_payload_type_; |
Sebastian Jansson | d3f3816 | 2018-02-28 16:14:44 +0100 | [diff] [blame] | 917 | std::vector<uint16_t> nacked_sequence_numbers_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 918 | } test(retransmit_ssrc, retransmit_payload_type); |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 919 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 920 | RunBaseTest(&test); |
pbos@webrtc.org | df531a2 | 2013-09-10 14:56:33 +0000 | [diff] [blame] | 921 | } |
| 922 | |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 923 | TEST_F(VideoSendStreamTest, RetransmitsNack) { |
| 924 | // Normal NACKs should use the send SSRC. |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 925 | TestNackRetransmission(kVideoSendSsrcs[0], kFakeVideoSendPayloadType); |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | TEST_F(VideoSendStreamTest, RetransmitsNackOverRtx) { |
| 929 | // NACKs over RTX should use a separate SSRC. |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 930 | TestNackRetransmission(kSendRtxSsrcs[0], kSendRtxPayloadType); |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 931 | } |
| 932 | |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 933 | void VideoSendStreamTest::TestPacketFragmentationSize(VideoFormat format, |
| 934 | bool with_fec) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 935 | // Use a fake encoder to output a frame of every size in the range [90, 290], |
| 936 | // for each size making sure that the exact number of payload bytes received |
| 937 | // is correct and that packets are fragmented to respect max packet size. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 938 | static const size_t kMaxPacketSize = 128; |
| 939 | static const size_t start = 90; |
| 940 | static const size_t stop = 290; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 941 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 942 | // Observer that verifies that the expected number of packets and bytes |
| 943 | // arrive for each frame size, from start_size to stop_size. |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 944 | class FrameFragmentationTest : public test::SendTest, |
| 945 | public EncodedFrameObserver { |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 946 | public: |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 947 | FrameFragmentationTest(size_t max_packet_size, |
| 948 | size_t start_size, |
| 949 | size_t stop_size, |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 950 | bool test_generic_packetization, |
| 951 | bool use_fec) |
| 952 | : SendTest(kLongTimeoutMs), |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 953 | encoder_(stop), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 954 | encoder_factory_(&encoder_), |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 955 | max_packet_size_(max_packet_size), |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 956 | stop_size_(stop_size), |
| 957 | test_generic_packetization_(test_generic_packetization), |
| 958 | use_fec_(use_fec), |
| 959 | packet_count_(0), |
Sebastian Jansson | 56fa050 | 2018-02-01 13:00:57 +0100 | [diff] [blame] | 960 | packets_lost_(0), |
| 961 | last_packet_count_(0), |
| 962 | last_packets_lost_(0), |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 963 | accumulated_size_(0), |
| 964 | accumulated_payload_(0), |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 965 | fec_packet_received_(false), |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 966 | current_size_rtp_(start_size), |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 967 | current_size_frame_(static_cast<int>(start_size)) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 968 | // Fragmentation required, this test doesn't make sense without it. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 969 | encoder_.SetFrameSize(start_size); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 970 | RTC_DCHECK_GT(stop_size, max_packet_size); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 971 | } |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 972 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 973 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 974 | Action OnSendRtp(const uint8_t* packet, size_t size) override { |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 975 | size_t length = size; |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 976 | RTPHeader header; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 977 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 978 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 979 | EXPECT_LE(length, max_packet_size_); |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 980 | |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 981 | if (use_fec_) { |
| 982 | uint8_t payload_type = packet[header.headerLength]; |
| 983 | bool is_fec = header.payloadType == kRedPayloadType && |
| 984 | payload_type == kUlpfecPayloadType; |
| 985 | if (is_fec) { |
| 986 | fec_packet_received_ = true; |
| 987 | return SEND_PACKET; |
| 988 | } |
| 989 | } |
| 990 | |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 991 | accumulated_size_ += length; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 992 | |
| 993 | if (use_fec_) |
| 994 | TriggerLossReport(header); |
| 995 | |
| 996 | if (test_generic_packetization_) { |
Stefan Holmer | 586b19b | 2015-09-18 11:14:31 +0200 | [diff] [blame] | 997 | size_t overhead = header.headerLength + header.paddingLength; |
| 998 | // Only remove payload header and RED header if the packet actually |
| 999 | // contains payload. |
| 1000 | if (length > overhead) { |
| 1001 | overhead += (1 /* Generic header */); |
| 1002 | if (use_fec_) |
| 1003 | overhead += 1; // RED for FEC header. |
| 1004 | } |
| 1005 | EXPECT_GE(length, overhead); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1006 | accumulated_payload_ += length - overhead; |
| 1007 | } |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1008 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1009 | // Marker bit set indicates last packet of a frame. |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1010 | if (header.markerBit) { |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1011 | if (use_fec_ && accumulated_payload_ == current_size_rtp_ - 1) { |
| 1012 | // With FEC enabled, frame size is incremented asynchronously, so |
| 1013 | // "old" frames one byte too small may arrive. Accept, but don't |
| 1014 | // increase expected frame size. |
| 1015 | accumulated_size_ = 0; |
| 1016 | accumulated_payload_ = 0; |
| 1017 | return SEND_PACKET; |
| 1018 | } |
| 1019 | |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1020 | EXPECT_GE(accumulated_size_, current_size_rtp_); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1021 | if (test_generic_packetization_) { |
| 1022 | EXPECT_EQ(current_size_rtp_, accumulated_payload_); |
| 1023 | } |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1024 | |
| 1025 | // Last packet of frame; reset counters. |
| 1026 | accumulated_size_ = 0; |
| 1027 | accumulated_payload_ = 0; |
| 1028 | if (current_size_rtp_ == stop_size_) { |
| 1029 | // Done! (Don't increase size again, might arrive more @ stop_size). |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1030 | observation_complete_.Set(); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1031 | } else { |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1032 | // Increase next expected frame size. If testing with FEC, make sure |
| 1033 | // a FEC packet has been received for this frame size before |
| 1034 | // proceeding, to make sure that redundancy packets don't exceed |
| 1035 | // size limit. |
| 1036 | if (!use_fec_) { |
| 1037 | ++current_size_rtp_; |
| 1038 | } else if (fec_packet_received_) { |
| 1039 | fec_packet_received_ = false; |
| 1040 | ++current_size_rtp_; |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 1041 | |
| 1042 | rtc::CritScope lock(&mutex_); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1043 | ++current_size_frame_; |
| 1044 | } |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1045 | } |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 1048 | return SEND_PACKET; |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1051 | void TriggerLossReport(const RTPHeader& header) { |
| 1052 | // Send lossy receive reports to trigger FEC enabling. |
sprang | 4847ae6 | 2017-06-27 07:06:52 -0700 | [diff] [blame] | 1053 | const int kLossPercent = 5; |
Sebastian Jansson | 56fa050 | 2018-02-01 13:00:57 +0100 | [diff] [blame] | 1054 | if (++packet_count_ % (100 / kLossPercent) == 0) { |
| 1055 | packets_lost_++; |
| 1056 | int loss_delta = packets_lost_ - last_packets_lost_; |
| 1057 | int packets_delta = packet_count_ - last_packet_count_; |
| 1058 | last_packet_count_ = packet_count_; |
| 1059 | last_packets_lost_ = packets_lost_; |
| 1060 | uint8_t loss_ratio = |
| 1061 | static_cast<uint8_t>(loss_delta * 255 / packets_delta); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1062 | FakeReceiveStatistics lossy_receive_stats( |
sprang | 4847ae6 | 2017-06-27 07:06:52 -0700 | [diff] [blame] | 1063 | kVideoSendSsrcs[0], header.sequenceNumber, |
Sebastian Jansson | 56fa050 | 2018-02-01 13:00:57 +0100 | [diff] [blame] | 1064 | packets_lost_, // Cumulative lost. |
| 1065 | loss_ratio); // Loss percent. |
Peter Boström | ac547a6 | 2015-09-17 23:03:57 +0200 | [diff] [blame] | 1066 | RTCPSender rtcp_sender(false, Clock::GetRealTimeClock(), |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 1067 | &lossy_receive_stats, nullptr, nullptr, |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 1068 | transport_adapter_.get(), RtcpIntervalConfig{}); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1069 | |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 1070 | rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1071 | rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]); |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1072 | |
| 1073 | RTCPSender::FeedbackState feedback_state; |
| 1074 | |
| 1075 | EXPECT_EQ(0, rtcp_sender.SendRTCP(feedback_state, kRtcpRr)); |
| 1076 | } |
| 1077 | } |
| 1078 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 1079 | void EncodedFrameCallback(const EncodedFrame& encoded_frame) override { |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 1080 | rtc::CritScope lock(&mutex_); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1081 | // Increase frame size for next encoded frame, in the context of the |
| 1082 | // encoder thread. |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 1083 | if (!use_fec_ && current_size_frame_ < static_cast<int32_t>(stop_size_)) { |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1084 | ++current_size_frame_; |
| 1085 | } |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 1086 | encoder_.SetFrameSize(static_cast<size_t>(current_size_frame_)); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1087 | } |
Sebastian Jansson | 7258224 | 2018-07-13 13:19:42 +0200 | [diff] [blame] | 1088 | void ModifySenderCallConfig(Call::Config* config) override { |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 1089 | const int kMinBitrateBps = 30000; |
Sebastian Jansson | 7258224 | 2018-07-13 13:19:42 +0200 | [diff] [blame] | 1090 | config->bitrate_config.min_bitrate_bps = kMinBitrateBps; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 1091 | } |
| 1092 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1093 | void ModifyVideoConfigs( |
| 1094 | VideoSendStream::Config* send_config, |
| 1095 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1096 | VideoEncoderConfig* encoder_config) override { |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1097 | transport_adapter_.reset( |
| 1098 | new internal::TransportAdapter(send_config->send_transport)); |
| 1099 | transport_adapter_->Enable(); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1100 | if (use_fec_) { |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 1101 | send_config->rtp.ulpfec.red_payload_type = kRedPayloadType; |
| 1102 | send_config->rtp.ulpfec.ulpfec_payload_type = kUlpfecPayloadType; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | if (!test_generic_packetization_) |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 1106 | send_config->rtp.payload_name = "VP8"; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1107 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1108 | send_config->rtp.max_packet_size = kMaxPacketSize; |
| 1109 | send_config->post_encode_callback = this; |
| 1110 | |
Erik Språng | 9526187 | 2015-04-10 11:58:49 +0200 | [diff] [blame] | 1111 | // Make sure there is at least one extension header, to make the RTP |
| 1112 | // header larger than the base length of 12 bytes. |
| 1113 | EXPECT_FALSE(send_config->rtp.extensions.empty()); |
sprang | 4847ae6 | 2017-06-27 07:06:52 -0700 | [diff] [blame] | 1114 | |
| 1115 | // Setup screen content disables frame dropping which makes this easier. |
| 1116 | class VideoStreamFactory |
| 1117 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 1118 | public: |
| 1119 | explicit VideoStreamFactory(size_t num_temporal_layers) |
| 1120 | : num_temporal_layers_(num_temporal_layers) { |
| 1121 | EXPECT_GT(num_temporal_layers, 0u); |
| 1122 | } |
| 1123 | |
| 1124 | private: |
| 1125 | std::vector<VideoStream> CreateEncoderStreams( |
| 1126 | int width, |
| 1127 | int height, |
| 1128 | const VideoEncoderConfig& encoder_config) override { |
| 1129 | std::vector<VideoStream> streams = |
| 1130 | test::CreateVideoStreams(width, height, encoder_config); |
| 1131 | for (VideoStream& stream : streams) { |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 1132 | stream.num_temporal_layers = num_temporal_layers_; |
sprang | 4847ae6 | 2017-06-27 07:06:52 -0700 | [diff] [blame] | 1133 | } |
| 1134 | return streams; |
| 1135 | } |
| 1136 | const size_t num_temporal_layers_; |
| 1137 | }; |
| 1138 | |
| 1139 | encoder_config->video_stream_factory = |
| 1140 | new rtc::RefCountedObject<VideoStreamFactory>(2); |
| 1141 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1144 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1145 | EXPECT_TRUE(Wait()) << "Timed out while observing incoming RTP packets."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1148 | std::unique_ptr<internal::TransportAdapter> transport_adapter_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1149 | test::ConfigurableFrameSizeEncoder encoder_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1150 | test::EncoderProxyFactory encoder_factory_; |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1151 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1152 | const size_t max_packet_size_; |
| 1153 | const size_t stop_size_; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1154 | const bool test_generic_packetization_; |
| 1155 | const bool use_fec_; |
| 1156 | |
| 1157 | uint32_t packet_count_; |
Sebastian Jansson | 56fa050 | 2018-02-01 13:00:57 +0100 | [diff] [blame] | 1158 | uint32_t packets_lost_; |
| 1159 | uint32_t last_packet_count_; |
| 1160 | uint32_t last_packets_lost_; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1161 | size_t accumulated_size_; |
| 1162 | size_t accumulated_payload_; |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1163 | bool fec_packet_received_; |
| 1164 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 1165 | size_t current_size_rtp_; |
Yuwei Huang | d9f99c1 | 2017-10-24 15:40:52 -0700 | [diff] [blame] | 1166 | rtc::CriticalSection mutex_; |
| 1167 | int current_size_frame_ RTC_GUARDED_BY(mutex_); |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1168 | }; |
| 1169 | |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1170 | // Don't auto increment if FEC is used; continue sending frame size until |
| 1171 | // a FEC packet has been received. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1172 | FrameFragmentationTest test(kMaxPacketSize, start, stop, format == kGeneric, |
| 1173 | with_fec); |
sprang@webrtc.org | 8b88192 | 2013-12-10 10:05:17 +0000 | [diff] [blame] | 1174 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 1175 | RunBaseTest(&test); |
sprang@webrtc.org | 5d957e2 | 2013-10-16 11:37:54 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
sprang@webrtc.org | 346094c | 2014-02-18 08:40:33 +0000 | [diff] [blame] | 1178 | // TODO(sprang): Is there any way of speeding up these tests? |
| 1179 | TEST_F(VideoSendStreamTest, FragmentsGenericAccordingToMaxPacketSize) { |
| 1180 | TestPacketFragmentationSize(kGeneric, false); |
| 1181 | } |
| 1182 | |
| 1183 | TEST_F(VideoSendStreamTest, FragmentsGenericAccordingToMaxPacketSizeWithFec) { |
| 1184 | TestPacketFragmentationSize(kGeneric, true); |
| 1185 | } |
| 1186 | |
| 1187 | TEST_F(VideoSendStreamTest, FragmentsVp8AccordingToMaxPacketSize) { |
| 1188 | TestPacketFragmentationSize(kVP8, false); |
| 1189 | } |
| 1190 | |
| 1191 | TEST_F(VideoSendStreamTest, FragmentsVp8AccordingToMaxPacketSizeWithFec) { |
| 1192 | TestPacketFragmentationSize(kVP8, true); |
| 1193 | } |
| 1194 | |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1195 | // The test will go through a number of phases. |
| 1196 | // 1. Start sending packets. |
| 1197 | // 2. As soon as the RTP stream has been detected, signal a low REMB value to |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1198 | // suspend the stream. |
| 1199 | // 3. Wait until |kSuspendTimeFrames| have been captured without seeing any RTP |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1200 | // packets. |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1201 | // 4. Signal a high REMB and then wait for the RTP stream to start again. |
henrik.lundin@webrtc.org | ed8b281 | 2014-03-18 08:43:29 +0000 | [diff] [blame] | 1202 | // When the stream is detected again, and the stats show that the stream |
| 1203 | // is no longer suspended, the test ends. |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1204 | TEST_F(VideoSendStreamTest, SuspendBelowMinBitrate) { |
| 1205 | static const int kSuspendTimeFrames = 60; // Suspend for 2 seconds @ 30 fps. |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1206 | |
nisse | d30a111 | 2016-04-18 05:15:22 -0700 | [diff] [blame] | 1207 | class RembObserver : public test::SendTest, |
| 1208 | public rtc::VideoSinkInterface<VideoFrame> { |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1209 | public: |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1210 | RembObserver() |
| 1211 | : SendTest(kDefaultTimeoutMs), |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1212 | clock_(Clock::GetRealTimeClock()), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1213 | stream_(nullptr), |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1214 | test_state_(kBeforeSuspend), |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1215 | rtp_count_(0), |
| 1216 | last_sequence_number_(0), |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1217 | suspended_frame_count_(0), |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 1218 | low_remb_bps_(0), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1219 | high_remb_bps_(0) {} |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1220 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1221 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1222 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1223 | rtc::CritScope lock(&crit_); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1224 | ++rtp_count_; |
| 1225 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 1226 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1227 | last_sequence_number_ = header.sequenceNumber; |
| 1228 | |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1229 | if (test_state_ == kBeforeSuspend) { |
| 1230 | // The stream has started. Try to suspend it. |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 1231 | SendRtcpFeedback(low_remb_bps_); |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1232 | test_state_ = kDuringSuspend; |
| 1233 | } else if (test_state_ == kDuringSuspend) { |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 1234 | if (header.paddingLength == 0) { |
| 1235 | // Received non-padding packet during suspension period. Reset the |
| 1236 | // counter. |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 1237 | suspended_frame_count_ = 0; |
| 1238 | } |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1239 | SendRtcpFeedback(0); // REMB is only sent if value is > 0. |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1240 | } else if (test_state_ == kWaitingForPacket) { |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 1241 | if (header.paddingLength == 0) { |
henrik.lundin@webrtc.org | ed8b281 | 2014-03-18 08:43:29 +0000 | [diff] [blame] | 1242 | // Non-padding packet observed. Test is almost complete. Will just |
| 1243 | // have to wait for the stats to change. |
| 1244 | test_state_ = kWaitingForStats; |
| 1245 | } |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1246 | SendRtcpFeedback(0); // REMB is only sent if value is > 0. |
henrik.lundin@webrtc.org | ed8b281 | 2014-03-18 08:43:29 +0000 | [diff] [blame] | 1247 | } else if (test_state_ == kWaitingForStats) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1248 | VideoSendStream::Stats stats = stream_->GetStats(); |
henrik.lundin@webrtc.org | ed8b281 | 2014-03-18 08:43:29 +0000 | [diff] [blame] | 1249 | if (stats.suspended == false) { |
| 1250 | // Stats flipped to false. Test is complete. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1251 | observation_complete_.Set(); |
henrik.lundin@webrtc.org | 331d440 | 2013-11-21 14:05:40 +0000 | [diff] [blame] | 1252 | } |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1253 | SendRtcpFeedback(0); // REMB is only sent if value is > 0. |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
stefan@webrtc.org | 69969e2 | 2013-11-15 12:32:15 +0000 | [diff] [blame] | 1256 | return SEND_PACKET; |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 1259 | // This method implements the rtc::VideoSinkInterface. This is called when |
| 1260 | // a frame is provided to the VideoSendStream. |
nisse | d30a111 | 2016-04-18 05:15:22 -0700 | [diff] [blame] | 1261 | void OnFrame(const VideoFrame& video_frame) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1262 | rtc::CritScope lock(&crit_); |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1263 | if (test_state_ == kDuringSuspend && |
| 1264 | ++suspended_frame_count_ > kSuspendTimeFrames) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1265 | VideoSendStream::Stats stats = stream_->GetStats(); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 1266 | EXPECT_TRUE(stats.suspended); |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 1267 | SendRtcpFeedback(high_remb_bps_); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1268 | test_state_ = kWaitingForPacket; |
| 1269 | } |
| 1270 | } |
| 1271 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1272 | void set_low_remb_bps(int value) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1273 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1274 | low_remb_bps_ = value; |
| 1275 | } |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 1276 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1277 | void set_high_remb_bps(int value) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1278 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1279 | high_remb_bps_ = value; |
| 1280 | } |
henrik.lundin@webrtc.org | 1a3a6e5 | 2013-10-28 10:16:14 +0000 | [diff] [blame] | 1281 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1282 | void OnVideoStreamsCreated( |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 1283 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1284 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1285 | stream_ = send_stream; |
| 1286 | } |
| 1287 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1288 | void ModifyVideoConfigs( |
| 1289 | VideoSendStream::Config* send_config, |
| 1290 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1291 | VideoEncoderConfig* encoder_config) override { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 1292 | RTC_DCHECK_EQ(1, encoder_config->number_of_streams); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1293 | transport_adapter_.reset( |
| 1294 | new internal::TransportAdapter(send_config->send_transport)); |
| 1295 | transport_adapter_->Enable(); |
pbos@webrtc.org | be9d2a4 | 2014-06-30 13:19:09 +0000 | [diff] [blame] | 1296 | send_config->rtp.nack.rtp_history_ms = kNackRtpHistoryMs; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1297 | send_config->pre_encode_callback = this; |
| 1298 | send_config->suspend_below_min_bitrate = true; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1299 | int min_bitrate_bps = |
| 1300 | test::DefaultVideoStreamFactory::kDefaultMinBitratePerStream[0]; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1301 | set_low_remb_bps(min_bitrate_bps - 10000); |
mflodman | 101f250 | 2016-06-09 17:21:19 +0200 | [diff] [blame] | 1302 | int threshold_window = std::max(min_bitrate_bps / 10, 20000); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1303 | ASSERT_GT(encoder_config->max_bitrate_bps, |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1304 | min_bitrate_bps + threshold_window + 5000); |
| 1305 | set_high_remb_bps(min_bitrate_bps + threshold_window + 5000); |
| 1306 | } |
| 1307 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1308 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1309 | EXPECT_TRUE(Wait()) << "Timed out during suspend-below-min-bitrate test."; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1312 | enum TestState { |
henrik.lundin@webrtc.org | ce8e093 | 2013-11-18 12:18:43 +0000 | [diff] [blame] | 1313 | kBeforeSuspend, |
| 1314 | kDuringSuspend, |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1315 | kWaitingForPacket, |
henrik.lundin@webrtc.org | ed8b281 | 2014-03-18 08:43:29 +0000 | [diff] [blame] | 1316 | kWaitingForStats |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1317 | }; |
| 1318 | |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1319 | virtual void SendRtcpFeedback(int remb_value) |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1320 | RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1321 | FakeReceiveStatistics receive_stats(kVideoSendSsrcs[0], |
| 1322 | last_sequence_number_, rtp_count_, 0); |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 1323 | RTCPSender rtcp_sender(false, clock_, &receive_stats, nullptr, nullptr, |
Jiawei Ou | 3587b83 | 2018-01-31 22:08:26 -0800 | [diff] [blame] | 1324 | transport_adapter_.get(), RtcpIntervalConfig{}); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1325 | |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 1326 | rtcp_sender.SetRTCPStatus(RtcpMode::kReducedSize); |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1327 | rtcp_sender.SetRemoteSSRC(kVideoSendSsrcs[0]); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1328 | if (remb_value > 0) { |
Danil Chapovalov | f74d641 | 2017-10-18 13:32:57 +0200 | [diff] [blame] | 1329 | rtcp_sender.SetRemb(remb_value, std::vector<uint32_t>()); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1330 | } |
| 1331 | RTCPSender::FeedbackState feedback_state; |
| 1332 | EXPECT_EQ(0, rtcp_sender.SendRTCP(feedback_state, kRtcpRr)); |
| 1333 | } |
| 1334 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1335 | std::unique_ptr<internal::TransportAdapter> transport_adapter_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1336 | Clock* const clock_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1337 | VideoSendStream* stream_; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1338 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1339 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1340 | TestState test_state_ RTC_GUARDED_BY(crit_); |
| 1341 | int rtp_count_ RTC_GUARDED_BY(crit_); |
| 1342 | int last_sequence_number_ RTC_GUARDED_BY(crit_); |
| 1343 | int suspended_frame_count_ RTC_GUARDED_BY(crit_); |
| 1344 | int low_remb_bps_ RTC_GUARDED_BY(crit_); |
| 1345 | int high_remb_bps_ RTC_GUARDED_BY(crit_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1346 | } test; |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1347 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 1348 | RunBaseTest(&test); |
henrik.lundin@webrtc.org | ba975e2 | 2013-10-23 11:04:57 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
perkj | 71ee44c | 2016-06-15 00:47:53 -0700 | [diff] [blame] | 1351 | // This test that padding stops being send after a while if the Camera stops |
| 1352 | // producing video frames and that padding resumes if the camera restarts. |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1353 | TEST_F(VideoSendStreamTest, NoPaddingWhenVideoIsMuted) { |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1354 | class NoPaddingWhenVideoIsMuted : public test::SendTest { |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1355 | public: |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1356 | NoPaddingWhenVideoIsMuted() |
| 1357 | : SendTest(kDefaultTimeoutMs), |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1358 | clock_(Clock::GetRealTimeClock()), |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1359 | last_packet_time_ms_(-1), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1360 | capturer_(nullptr) {} |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1361 | |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1362 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1363 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1364 | rtc::CritScope lock(&crit_); |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1365 | last_packet_time_ms_ = clock_->TimeInMilliseconds(); |
perkj | 71ee44c | 2016-06-15 00:47:53 -0700 | [diff] [blame] | 1366 | |
| 1367 | RTPHeader header; |
| 1368 | parser_->Parse(packet, length, &header); |
| 1369 | const bool only_padding = |
| 1370 | header.headerLength + header.paddingLength == length; |
| 1371 | |
| 1372 | if (test_state_ == kBeforeStopCapture) { |
| 1373 | capturer_->Stop(); |
| 1374 | test_state_ = kWaitingForPadding; |
| 1375 | } else if (test_state_ == kWaitingForPadding && only_padding) { |
| 1376 | test_state_ = kWaitingForNoPackets; |
| 1377 | } else if (test_state_ == kWaitingForPaddingAfterCameraRestart && |
| 1378 | only_padding) { |
| 1379 | observation_complete_.Set(); |
| 1380 | } |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1381 | return SEND_PACKET; |
| 1382 | } |
| 1383 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1384 | Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1385 | rtc::CritScope lock(&crit_); |
perkj | 71ee44c | 2016-06-15 00:47:53 -0700 | [diff] [blame] | 1386 | const int kNoPacketsThresholdMs = 2000; |
| 1387 | if (test_state_ == kWaitingForNoPackets && |
| 1388 | (last_packet_time_ms_ > 0 && |
| 1389 | clock_->TimeInMilliseconds() - last_packet_time_ms_ > |
| 1390 | kNoPacketsThresholdMs)) { |
| 1391 | capturer_->Start(); |
| 1392 | test_state_ = kWaitingForPaddingAfterCameraRestart; |
| 1393 | } |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1394 | return SEND_PACKET; |
| 1395 | } |
| 1396 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 1397 | size_t GetNumVideoStreams() const override { return 3; } |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1398 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 1399 | void OnFrameGeneratorCapturerCreated( |
| 1400 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1401 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1402 | capturer_ = frame_generator_capturer; |
| 1403 | } |
| 1404 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1405 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1406 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1407 | << "Timed out while waiting for RTP packets to stop being sent."; |
| 1408 | } |
| 1409 | |
perkj | 71ee44c | 2016-06-15 00:47:53 -0700 | [diff] [blame] | 1410 | enum TestState { |
| 1411 | kBeforeStopCapture, |
| 1412 | kWaitingForPadding, |
| 1413 | kWaitingForNoPackets, |
| 1414 | kWaitingForPaddingAfterCameraRestart |
| 1415 | }; |
| 1416 | |
| 1417 | TestState test_state_ = kBeforeStopCapture; |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 1418 | Clock* const clock_; |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1419 | std::unique_ptr<internal::TransportAdapter> transport_adapter_; |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 1420 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1421 | int64_t last_packet_time_ms_ RTC_GUARDED_BY(crit_); |
| 1422 | test::FrameGeneratorCapturer* capturer_ RTC_GUARDED_BY(crit_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1423 | } test; |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1424 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 1425 | RunBaseTest(&test); |
stefan@webrtc.org | 4ab4fc0 | 2013-11-25 11:54:24 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1428 | TEST_F(VideoSendStreamTest, PaddingIsPrimarilyRetransmissions) { |
| 1429 | const int kCapacityKbps = 10000; // 10 Mbps |
| 1430 | class PaddingIsPrimarilyRetransmissions : public test::EndToEndTest { |
| 1431 | public: |
| 1432 | PaddingIsPrimarilyRetransmissions() |
| 1433 | : EndToEndTest(kDefaultTimeoutMs), |
| 1434 | clock_(Clock::GetRealTimeClock()), |
| 1435 | padding_length_(0), |
| 1436 | total_length_(0), |
| 1437 | call_(nullptr) {} |
| 1438 | |
| 1439 | private: |
| 1440 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1441 | call_ = sender_call; |
| 1442 | } |
| 1443 | |
| 1444 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 1445 | rtc::CritScope lock(&crit_); |
| 1446 | |
| 1447 | RTPHeader header; |
| 1448 | parser_->Parse(packet, length, &header); |
| 1449 | padding_length_ += header.paddingLength; |
| 1450 | total_length_ += length; |
| 1451 | return SEND_PACKET; |
| 1452 | } |
| 1453 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1454 | test::PacketTransport* CreateSendTransport( |
| 1455 | test::SingleThreadedTaskQueueForTesting* task_queue, |
| 1456 | Call* sender_call) override { |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1457 | const int kNetworkDelayMs = 50; |
| 1458 | FakeNetworkPipe::Config config; |
| 1459 | config.loss_percent = 10; |
| 1460 | config.link_capacity_kbps = kCapacityKbps; |
| 1461 | config.queue_delay_ms = kNetworkDelayMs; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1462 | return new test::PacketTransport(task_queue, sender_call, this, |
nisse | e5ad5ca | 2017-03-29 23:57:43 -0700 | [diff] [blame] | 1463 | test::PacketTransport::kSender, |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 1464 | payload_type_map_, config); |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | void ModifyVideoConfigs( |
| 1468 | VideoSendStream::Config* send_config, |
| 1469 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1470 | VideoEncoderConfig* encoder_config) override { |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1471 | // Turn on RTX. |
| 1472 | send_config->rtp.rtx.payload_type = kFakeVideoSendPayloadType; |
| 1473 | send_config->rtp.rtx.ssrcs.push_back(kVideoSendSsrcs[0]); |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void PerformTest() override { |
| 1477 | // TODO(isheriff): Some platforms do not ramp up as expected to full |
| 1478 | // capacity due to packet scheduling delays. Fix that before getting |
| 1479 | // rid of this. |
| 1480 | SleepMs(5000); |
| 1481 | { |
| 1482 | rtc::CritScope lock(&crit_); |
| 1483 | // Expect padding to be a small percentage of total bytes sent. |
| 1484 | EXPECT_LT(padding_length_, .1 * total_length_); |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | rtc::CriticalSection crit_; |
| 1489 | Clock* const clock_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1490 | size_t padding_length_ RTC_GUARDED_BY(crit_); |
| 1491 | size_t total_length_ RTC_GUARDED_BY(crit_); |
isheriff | cc5903e | 2016-10-04 08:29:38 -0700 | [diff] [blame] | 1492 | Call* call_; |
| 1493 | } test; |
| 1494 | |
| 1495 | RunBaseTest(&test); |
| 1496 | } |
| 1497 | |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1498 | // This test first observes "high" bitrate use at which point it sends a REMB to |
| 1499 | // indicate that it should be lowered significantly. The test then observes that |
| 1500 | // the bitrate observed is sinking well below the min-transmit-bitrate threshold |
| 1501 | // to verify that the min-transmit bitrate respects incoming REMB. |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 1502 | // |
| 1503 | // Note that the test starts at "high" bitrate and does not ramp up to "higher" |
| 1504 | // bitrate since no receiver block or remb is sent in the initial phase. |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1505 | TEST_F(VideoSendStreamTest, MinTransmitBitrateRespectsRemb) { |
| 1506 | static const int kMinTransmitBitrateBps = 400000; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 1507 | static const int kHighBitrateBps = 150000; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1508 | static const int kRembBitrateBps = 80000; |
| 1509 | static const int kRembRespectedBitrateBps = 100000; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1510 | class BitrateObserver : public test::SendTest { |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1511 | public: |
| 1512 | BitrateObserver() |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1513 | : SendTest(kDefaultTimeoutMs), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1514 | retranmission_rate_limiter_(Clock::GetRealTimeClock(), 1000), |
| 1515 | stream_(nullptr), |
| 1516 | bitrate_capped_(false) {} |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1517 | |
| 1518 | private: |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 1519 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 1520 | if (RtpHeaderParser::IsRtcp(packet, length)) |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1521 | return DROP_PACKET; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1522 | |
| 1523 | RTPHeader header; |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 1524 | if (!parser_->Parse(packet, length, &header)) |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1525 | return DROP_PACKET; |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 1526 | RTC_DCHECK(stream_); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1527 | VideoSendStream::Stats stats = stream_->GetStats(); |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1528 | if (!stats.substreams.empty()) { |
| 1529 | EXPECT_EQ(1u, stats.substreams.size()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1530 | int total_bitrate_bps = |
| 1531 | stats.substreams.begin()->second.total_bitrate_bps; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1532 | test::PrintResult("bitrate_stats_", "min_transmit_bitrate_low_remb", |
| 1533 | "bitrate_bps", static_cast<size_t>(total_bitrate_bps), |
| 1534 | "bps", false); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1535 | if (total_bitrate_bps > kHighBitrateBps) { |
Danil Chapovalov | 51e21aa | 2017-10-10 17:46:26 +0200 | [diff] [blame] | 1536 | rtp_rtcp_->SetRemb(kRembBitrateBps, |
| 1537 | std::vector<uint32_t>(1, header.ssrc)); |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1538 | rtp_rtcp_->Process(); |
| 1539 | bitrate_capped_ = true; |
| 1540 | } else if (bitrate_capped_ && |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1541 | total_bitrate_bps < kRembRespectedBitrateBps) { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1542 | observation_complete_.Set(); |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1545 | // Packets don't have to be delivered since the test is the receiver. |
| 1546 | return DROP_PACKET; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1549 | void OnVideoStreamsCreated( |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1550 | VideoSendStream* send_stream, |
| 1551 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 1552 | stream_ = send_stream; |
| 1553 | RtpRtcp::Configuration config; |
| 1554 | config.outgoing_transport = feedback_transport_.get(); |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1555 | config.retransmission_rate_limiter = &retranmission_rate_limiter_; |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1556 | rtp_rtcp_.reset(RtpRtcp::CreateRtpRtcp(config)); |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1557 | rtp_rtcp_->SetRTCPStatus(RtcpMode::kReducedSize); |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 1560 | void ModifyVideoConfigs( |
| 1561 | VideoSendStream::Config* send_config, |
| 1562 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1563 | VideoEncoderConfig* encoder_config) override { |
stefan | f116bd0 | 2015-10-27 08:29:42 -0700 | [diff] [blame] | 1564 | feedback_transport_.reset( |
| 1565 | new internal::TransportAdapter(send_config->send_transport)); |
| 1566 | feedback_transport_->Enable(); |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 1567 | encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1570 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 1571 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1572 | << "Timeout while waiting for low bitrate stats after REMB."; |
| 1573 | } |
| 1574 | |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 1575 | std::unique_ptr<RtpRtcp> rtp_rtcp_; |
| 1576 | std::unique_ptr<internal::TransportAdapter> feedback_transport_; |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 1577 | RateLimiter retranmission_rate_limiter_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1578 | VideoSendStream* stream_; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1579 | bool bitrate_capped_; |
pbos@webrtc.org | 994d0b7 | 2014-06-27 08:47:52 +0000 | [diff] [blame] | 1580 | } test; |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1581 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 1582 | RunBaseTest(&test); |
pbos@webrtc.org | 709e297 | 2014-03-19 10:59:52 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 1585 | TEST_F(VideoSendStreamTest, ChangingNetworkRoute) { |
| 1586 | static const int kStartBitrateBps = 300000; |
| 1587 | static const int kNewMaxBitrateBps = 1234567; |
danilchap | 42ca68a | 2016-10-31 03:34:40 -0700 | [diff] [blame] | 1588 | static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId; |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1589 | class ChangingNetworkRouteTest : public test::EndToEndTest { |
| 1590 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1591 | explicit ChangingNetworkRouteTest( |
| 1592 | test::SingleThreadedTaskQueueForTesting* task_queue) |
| 1593 | : EndToEndTest(test::CallTest::kDefaultTimeoutMs), |
| 1594 | task_queue_(task_queue), |
| 1595 | call_(nullptr) { |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 1596 | EXPECT_TRUE(parser_->RegisterRtpHeaderExtension( |
| 1597 | kRtpExtensionTransportSequenceNumber, kExtensionId)); |
| 1598 | } |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1599 | |
| 1600 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1601 | call_ = sender_call; |
| 1602 | } |
| 1603 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 1604 | void ModifyVideoConfigs( |
| 1605 | VideoSendStream::Config* send_config, |
| 1606 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1607 | VideoEncoderConfig* encoder_config) override { |
| 1608 | send_config->rtp.extensions.clear(); |
| 1609 | send_config->rtp.extensions.push_back(RtpExtension( |
| 1610 | RtpExtension::kTransportSequenceNumberUri, kExtensionId)); |
| 1611 | (*receive_configs)[0].rtp.extensions = send_config->rtp.extensions; |
| 1612 | (*receive_configs)[0].rtp.transport_cc = true; |
| 1613 | } |
| 1614 | |
| 1615 | void ModifyAudioConfigs( |
| 1616 | AudioSendStream::Config* send_config, |
| 1617 | std::vector<AudioReceiveStream::Config>* receive_configs) override { |
| 1618 | send_config->rtp.extensions.clear(); |
| 1619 | send_config->rtp.extensions.push_back(RtpExtension( |
| 1620 | RtpExtension::kTransportSequenceNumberUri, kExtensionId)); |
| 1621 | (*receive_configs)[0].rtp.extensions.clear(); |
| 1622 | (*receive_configs)[0].rtp.extensions = send_config->rtp.extensions; |
| 1623 | (*receive_configs)[0].rtp.transport_cc = true; |
| 1624 | } |
| 1625 | |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1626 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 1627 | if (call_->GetStats().send_bandwidth_bps > kStartBitrateBps) { |
| 1628 | observation_complete_.Set(); |
| 1629 | } |
| 1630 | |
| 1631 | return SEND_PACKET; |
| 1632 | } |
| 1633 | |
| 1634 | void PerformTest() override { |
Steve Anton | ea1bb35 | 2018-07-23 10:12:37 -0700 | [diff] [blame^] | 1635 | rtc::NetworkRoute new_route; |
| 1636 | new_route.connected = true; |
| 1637 | new_route.local_network_id = 10; |
| 1638 | new_route.remote_network_id = 20; |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 1639 | BitrateConstraints bitrate_config; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1640 | |
| 1641 | task_queue_->SendTask([this, &new_route, &bitrate_config]() { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1642 | call_->GetTransportControllerSend()->OnNetworkRouteChanged("transport", |
| 1643 | new_route); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1644 | bitrate_config.start_bitrate_bps = kStartBitrateBps; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1645 | call_->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 1646 | bitrate_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1647 | }); |
| 1648 | |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1649 | EXPECT_TRUE(Wait()) |
| 1650 | << "Timed out while waiting for start bitrate to be exceeded."; |
| 1651 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1652 | task_queue_->SendTask([this, &new_route, &bitrate_config]() { |
| 1653 | bitrate_config.start_bitrate_bps = -1; |
| 1654 | bitrate_config.max_bitrate_bps = kNewMaxBitrateBps; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1655 | call_->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 1656 | bitrate_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1657 | // TODO(holmer): We should set the last sent packet id here and verify |
| 1658 | // that we correctly ignore any packet loss reported prior to that id. |
| 1659 | ++new_route.local_network_id; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1660 | call_->GetTransportControllerSend()->OnNetworkRouteChanged("transport", |
| 1661 | new_route); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1662 | EXPECT_GE(call_->GetStats().send_bandwidth_bps, kStartBitrateBps); |
| 1663 | }); |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | private: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1667 | test::SingleThreadedTaskQueueForTesting* const task_queue_; |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1668 | Call* call_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1669 | } test(&task_queue_); |
Stefan Holmer | be40296 | 2016-07-08 16:16:41 +0200 | [diff] [blame] | 1670 | |
| 1671 | RunBaseTest(&test); |
| 1672 | } |
| 1673 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1674 | TEST_F(VideoSendStreamTest, ChangingTransportOverhead) { |
| 1675 | class ChangingTransportOverheadTest : public test::EndToEndTest { |
| 1676 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1677 | explicit ChangingTransportOverheadTest( |
| 1678 | test::SingleThreadedTaskQueueForTesting* task_queue) |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1679 | : EndToEndTest(test::CallTest::kDefaultTimeoutMs), |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1680 | task_queue_(task_queue), |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1681 | call_(nullptr), |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 1682 | packets_sent_(0), |
| 1683 | transport_overhead_(0) {} |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1684 | |
| 1685 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1686 | call_ = sender_call; |
| 1687 | } |
| 1688 | |
| 1689 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 1690 | EXPECT_LE(length, kMaxRtpPacketSize); |
sprang | 21253fc | 2017-02-27 03:35:47 -0800 | [diff] [blame] | 1691 | rtc::CritScope cs(&lock_); |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1692 | if (++packets_sent_ < 100) |
| 1693 | return SEND_PACKET; |
| 1694 | observation_complete_.Set(); |
| 1695 | return SEND_PACKET; |
| 1696 | } |
| 1697 | |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 1698 | void ModifyVideoConfigs( |
| 1699 | VideoSendStream::Config* send_config, |
| 1700 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1701 | VideoEncoderConfig* encoder_config) override { |
| 1702 | send_config->rtp.max_packet_size = kMaxRtpPacketSize; |
| 1703 | } |
| 1704 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1705 | void PerformTest() override { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1706 | task_queue_->SendTask([this]() { |
| 1707 | transport_overhead_ = 100; |
| 1708 | call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO, |
| 1709 | transport_overhead_); |
| 1710 | }); |
| 1711 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1712 | EXPECT_TRUE(Wait()); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1713 | |
sprang | 21253fc | 2017-02-27 03:35:47 -0800 | [diff] [blame] | 1714 | { |
| 1715 | rtc::CritScope cs(&lock_); |
| 1716 | packets_sent_ = 0; |
| 1717 | } |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1718 | |
| 1719 | task_queue_->SendTask([this]() { |
| 1720 | transport_overhead_ = 500; |
| 1721 | call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO, |
| 1722 | transport_overhead_); |
| 1723 | }); |
| 1724 | |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1725 | EXPECT_TRUE(Wait()); |
| 1726 | } |
| 1727 | |
| 1728 | private: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1729 | test::SingleThreadedTaskQueueForTesting* const task_queue_; |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1730 | Call* call_; |
sprang | 21253fc | 2017-02-27 03:35:47 -0800 | [diff] [blame] | 1731 | rtc::CriticalSection lock_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1732 | int packets_sent_ RTC_GUARDED_BY(lock_); |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1733 | int transport_overhead_; |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 1734 | const size_t kMaxRtpPacketSize = 1000; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1735 | } test(&task_queue_); |
michaelt | 79e0588 | 2016-11-08 02:50:09 -0800 | [diff] [blame] | 1736 | |
| 1737 | RunBaseTest(&test); |
| 1738 | } |
| 1739 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1740 | // Test class takes takes as argument a switch selecting if type switch should |
| 1741 | // occur and a function pointer to reset the send stream. This is necessary |
| 1742 | // since you cannot change the content type of a VideoSendStream, you need to |
| 1743 | // recreate it. Stopping and recreating the stream can only be done on the main |
| 1744 | // thread and in the context of VideoSendStreamTest (not BaseTest). |
| 1745 | template <typename T> |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1746 | class MaxPaddingSetTest : public test::SendTest { |
| 1747 | public: |
| 1748 | static const uint32_t kMinTransmitBitrateBps = 400000; |
| 1749 | static const uint32_t kActualEncodeBitrateBps = 40000; |
| 1750 | static const uint32_t kMinPacketsToSend = 50; |
| 1751 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1752 | explicit MaxPaddingSetTest(bool test_switch_content_type, T* stream_reset_fun) |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1753 | : SendTest(test::CallTest::kDefaultTimeoutMs), |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1754 | content_switch_event_(false, false), |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1755 | call_(nullptr), |
| 1756 | send_stream_(nullptr), |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1757 | send_stream_config_(nullptr), |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1758 | packets_sent_(0), |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1759 | running_without_padding_(test_switch_content_type), |
tommi | 39e1289 | 2017-03-13 05:15:14 -0700 | [diff] [blame] | 1760 | stream_resetter_(stream_reset_fun) { |
| 1761 | RTC_DCHECK(stream_resetter_); |
| 1762 | } |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1763 | |
| 1764 | void OnVideoStreamsCreated( |
| 1765 | VideoSendStream* send_stream, |
| 1766 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1767 | rtc::CritScope lock(&crit_); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1768 | send_stream_ = send_stream; |
| 1769 | } |
| 1770 | |
| 1771 | void ModifyVideoConfigs( |
| 1772 | VideoSendStream::Config* send_config, |
| 1773 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 1774 | VideoEncoderConfig* encoder_config) override { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 1775 | RTC_DCHECK_EQ(1, encoder_config->number_of_streams); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1776 | if (RunningWithoutPadding()) { |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1777 | encoder_config->min_transmit_bitrate_bps = 0; |
| 1778 | encoder_config->content_type = |
| 1779 | VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 1780 | } else { |
| 1781 | encoder_config->min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
| 1782 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
| 1783 | } |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1784 | send_stream_config_ = send_config->Copy(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 1785 | encoder_config_ = encoder_config->Copy(); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 1789 | call_ = sender_call; |
| 1790 | } |
| 1791 | |
| 1792 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 1793 | rtc::CritScope lock(&crit_); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1794 | if (running_without_padding_) |
| 1795 | EXPECT_EQ(0, call_->GetStats().max_padding_bitrate_bps); |
| 1796 | |
| 1797 | // Wait until at least kMinPacketsToSend frames have been encoded, so that |
| 1798 | // we have reliable data. |
| 1799 | if (++packets_sent_ < kMinPacketsToSend) |
| 1800 | return SEND_PACKET; |
| 1801 | |
| 1802 | if (running_without_padding_) { |
| 1803 | // We've sent kMinPacketsToSend packets with default configuration, switch |
| 1804 | // to enabling screen content and setting min transmit bitrate. |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1805 | // Note that we need to recreate the stream if changing content type. |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1806 | packets_sent_ = 0; |
| 1807 | encoder_config_.min_transmit_bitrate_bps = kMinTransmitBitrateBps; |
| 1808 | encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1809 | running_without_padding_ = false; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1810 | content_switch_event_.Set(); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1811 | return SEND_PACKET; |
| 1812 | } |
| 1813 | |
| 1814 | // Make sure the pacer has been configured with a min transmit bitrate. |
| 1815 | if (call_->GetStats().max_padding_bitrate_bps > 0) |
| 1816 | observation_complete_.Set(); |
| 1817 | |
| 1818 | return SEND_PACKET; |
| 1819 | } |
| 1820 | |
| 1821 | void PerformTest() override { |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1822 | if (RunningWithoutPadding()) { |
| 1823 | ASSERT_TRUE( |
| 1824 | content_switch_event_.Wait(test::CallTest::kDefaultTimeoutMs)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1825 | (*stream_resetter_)(send_stream_config_, encoder_config_); |
| 1826 | } |
| 1827 | |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1828 | ASSERT_TRUE(Wait()) << "Timed out waiting for a valid padding bitrate."; |
| 1829 | } |
| 1830 | |
| 1831 | private: |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1832 | bool RunningWithoutPadding() const { |
| 1833 | rtc::CritScope lock(&crit_); |
| 1834 | return running_without_padding_; |
| 1835 | } |
| 1836 | |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1837 | rtc::CriticalSection crit_; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1838 | rtc::Event content_switch_event_; |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1839 | Call* call_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1840 | VideoSendStream* send_stream_ RTC_GUARDED_BY(crit_); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1841 | VideoSendStream::Config send_stream_config_; |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1842 | VideoEncoderConfig encoder_config_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1843 | uint32_t packets_sent_ RTC_GUARDED_BY(crit_); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1844 | bool running_without_padding_; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1845 | T* const stream_resetter_; |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1846 | }; |
| 1847 | |
| 1848 | TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrate) { |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1849 | auto reset_fun = [](const VideoSendStream::Config& send_stream_config, |
| 1850 | const VideoEncoderConfig& encoder_config) {}; |
| 1851 | MaxPaddingSetTest<decltype(reset_fun)> test(false, &reset_fun); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1852 | RunBaseTest(&test); |
| 1853 | } |
| 1854 | |
| 1855 | TEST_F(VideoSendStreamTest, RespectsMinTransmitBitrateAfterContentSwitch) { |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1856 | // Function for removing and recreating the send stream with a new config. |
| 1857 | auto reset_fun = [this](const VideoSendStream::Config& send_stream_config, |
| 1858 | const VideoEncoderConfig& encoder_config) { |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1859 | task_queue_.SendTask([this, &send_stream_config, &encoder_config]() { |
| 1860 | Stop(); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 1861 | DestroyVideoSendStreams(); |
| 1862 | SetVideoSendConfig(send_stream_config); |
| 1863 | SetVideoEncoderConfig(encoder_config); |
| 1864 | CreateVideoSendStreams(); |
| 1865 | SetVideoDegradation(DegradationPreference::MAINTAIN_RESOLUTION); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1866 | Start(); |
| 1867 | }); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1868 | }; |
| 1869 | MaxPaddingSetTest<decltype(reset_fun)> test(true, &reset_fun); |
sprang | 9c0b551 | 2016-07-06 00:54:28 -0700 | [diff] [blame] | 1870 | RunBaseTest(&test); |
| 1871 | } |
| 1872 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1873 | // This test verifies that new frame sizes reconfigures encoders even though not |
| 1874 | // (yet) sending. The purpose of this is to permit encoding as quickly as |
| 1875 | // possible once we start sending. Likely the frames being input are from the |
| 1876 | // same source that will be sent later, which just means that we're ready |
| 1877 | // earlier. |
| 1878 | TEST_F(VideoSendStreamTest, |
| 1879 | EncoderReconfigureOnResolutionChangeWhenNotSending) { |
| 1880 | class EncoderObserver : public test::FakeEncoder { |
| 1881 | public: |
| 1882 | EncoderObserver() |
| 1883 | : FakeEncoder(Clock::GetRealTimeClock()), |
| 1884 | init_encode_called_(false, false), |
| 1885 | number_of_initializations_(0), |
| 1886 | last_initialized_frame_width_(0), |
| 1887 | last_initialized_frame_height_(0) {} |
| 1888 | |
| 1889 | void WaitForResolution(int width, int height) { |
| 1890 | { |
| 1891 | rtc::CritScope lock(&crit_); |
| 1892 | if (last_initialized_frame_width_ == width && |
| 1893 | last_initialized_frame_height_ == height) { |
| 1894 | return; |
| 1895 | } |
| 1896 | } |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 1897 | EXPECT_TRUE( |
| 1898 | init_encode_called_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1899 | { |
| 1900 | rtc::CritScope lock(&crit_); |
| 1901 | EXPECT_EQ(width, last_initialized_frame_width_); |
| 1902 | EXPECT_EQ(height, last_initialized_frame_height_); |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | private: |
| 1907 | int32_t InitEncode(const VideoCodec* config, |
| 1908 | int32_t number_of_cores, |
| 1909 | size_t max_payload_size) override { |
| 1910 | rtc::CritScope lock(&crit_); |
| 1911 | last_initialized_frame_width_ = config->width; |
| 1912 | last_initialized_frame_height_ = config->height; |
| 1913 | ++number_of_initializations_; |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 1914 | init_encode_called_.Set(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1915 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 1916 | } |
| 1917 | |
| 1918 | int32_t Encode(const VideoFrame& input_image, |
| 1919 | const CodecSpecificInfo* codec_specific_info, |
| 1920 | const std::vector<FrameType>* frame_types) override { |
| 1921 | ADD_FAILURE() |
| 1922 | << "Unexpected Encode call since the send stream is not started"; |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
| 1926 | rtc::CriticalSection crit_; |
| 1927 | rtc::Event init_encode_called_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1928 | size_t number_of_initializations_ RTC_GUARDED_BY(&crit_); |
| 1929 | int last_initialized_frame_width_ RTC_GUARDED_BY(&crit_); |
| 1930 | int last_initialized_frame_height_ RTC_GUARDED_BY(&crit_); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1931 | }; |
| 1932 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1933 | test::NullTransport transport; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1934 | EncoderObserver encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1935 | test::EncoderProxyFactory encoder_factory(&encoder); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1936 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1937 | task_queue_.SendTask([this, &transport, &encoder_factory]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 1938 | CreateSenderCall(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1939 | CreateSendConfig(1, 0, 0, &transport); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 1940 | GetVideoSendConfig()->encoder_settings.encoder_factory = &encoder_factory; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1941 | CreateVideoStreams(); |
| 1942 | CreateFrameGeneratorCapturer(kDefaultFramerate, kDefaultWidth, |
| 1943 | kDefaultHeight); |
| 1944 | frame_generator_capturer_->Start(); |
| 1945 | }); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1946 | |
| 1947 | encoder.WaitForResolution(kDefaultWidth, kDefaultHeight); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1948 | |
| 1949 | task_queue_.SendTask([this]() { |
| 1950 | frame_generator_capturer_->ChangeResolution(kDefaultWidth * 2, |
| 1951 | kDefaultHeight * 2); |
| 1952 | }); |
| 1953 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1954 | encoder.WaitForResolution(kDefaultWidth * 2, kDefaultHeight * 2); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 1955 | |
| 1956 | task_queue_.SendTask([this]() { |
| 1957 | DestroyStreams(); |
| 1958 | DestroyCalls(); |
| 1959 | }); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1962 | TEST_F(VideoSendStreamTest, CanReconfigureToUseStartBitrateAbovePreviousMax) { |
| 1963 | class StartBitrateObserver : public test::FakeEncoder { |
| 1964 | public: |
| 1965 | StartBitrateObserver() |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1966 | : FakeEncoder(Clock::GetRealTimeClock()), |
| 1967 | start_bitrate_changed_(false, false), |
| 1968 | start_bitrate_kbps_(0) {} |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1969 | int32_t InitEncode(const VideoCodec* config, |
| 1970 | int32_t number_of_cores, |
| 1971 | size_t max_payload_size) override { |
| 1972 | rtc::CritScope lock(&crit_); |
| 1973 | start_bitrate_kbps_ = config->startBitrate; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1974 | start_bitrate_changed_.Set(); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1975 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 1976 | } |
| 1977 | |
| 1978 | int32_t SetRates(uint32_t new_target_bitrate, uint32_t framerate) override { |
| 1979 | rtc::CritScope lock(&crit_); |
| 1980 | start_bitrate_kbps_ = new_target_bitrate; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1981 | start_bitrate_changed_.Set(); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1982 | return FakeEncoder::SetRates(new_target_bitrate, framerate); |
| 1983 | } |
| 1984 | |
| 1985 | int GetStartBitrateKbps() const { |
| 1986 | rtc::CritScope lock(&crit_); |
| 1987 | return start_bitrate_kbps_; |
| 1988 | } |
| 1989 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1990 | bool WaitForStartBitrate() { |
| 1991 | return start_bitrate_changed_.Wait( |
| 1992 | VideoSendStreamTest::kDefaultTimeoutMs); |
| 1993 | } |
| 1994 | |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1995 | private: |
pbos | 5ad935c | 2016-01-25 03:52:44 -0800 | [diff] [blame] | 1996 | rtc::CriticalSection crit_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 1997 | rtc::Event start_bitrate_changed_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 1998 | int start_bitrate_kbps_ RTC_GUARDED_BY(crit_); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 1999 | }; |
| 2000 | |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 2001 | CreateSenderCall(); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2002 | |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 2003 | test::NullTransport transport; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 2004 | CreateSendConfig(1, 0, 0, &transport); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2005 | |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 2006 | BitrateConstraints bitrate_config; |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2007 | bitrate_config.start_bitrate_bps = |
| 2008 | 2 * GetVideoEncoderConfig()->max_bitrate_bps; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2009 | sender_call_->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 2010 | bitrate_config); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2011 | |
| 2012 | StartBitrateObserver encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2013 | test::EncoderProxyFactory encoder_factory(&encoder); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2014 | // Since this test does not use a capturer, set |internal_source| = true. |
| 2015 | // Encoder configuration is otherwise updated on the next video frame. |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2016 | encoder_factory.SetHasInternalSource(true); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2017 | GetVideoSendConfig()->encoder_settings.encoder_factory = &encoder_factory; |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2018 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 2019 | CreateVideoStreams(); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2020 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2021 | EXPECT_TRUE(encoder.WaitForStartBitrate()); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2022 | EXPECT_EQ(GetVideoEncoderConfig()->max_bitrate_bps / 1000, |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2023 | encoder.GetStartBitrateKbps()); |
| 2024 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2025 | GetVideoEncoderConfig()->max_bitrate_bps = |
| 2026 | 2 * bitrate_config.start_bitrate_bps; |
| 2027 | GetVideoSendStream()->ReconfigureVideoEncoder( |
| 2028 | GetVideoEncoderConfig()->Copy()); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2029 | |
| 2030 | // New bitrate should be reconfigured above the previous max. As there's no |
| 2031 | // network connection this shouldn't be flaky, as no bitrate should've been |
| 2032 | // reported in between. |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2033 | EXPECT_TRUE(encoder.WaitForStartBitrate()); |
pbos@webrtc.org | 143451d | 2015-03-18 14:40:03 +0000 | [diff] [blame] | 2034 | EXPECT_EQ(bitrate_config.start_bitrate_bps / 1000, |
| 2035 | encoder.GetStartBitrateKbps()); |
| 2036 | |
| 2037 | DestroyStreams(); |
| 2038 | } |
| 2039 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2040 | class StartStopBitrateObserver : public test::FakeEncoder { |
| 2041 | public: |
| 2042 | StartStopBitrateObserver() |
| 2043 | : FakeEncoder(Clock::GetRealTimeClock()), |
| 2044 | encoder_init_(false, false), |
| 2045 | bitrate_changed_(false, false) {} |
| 2046 | int32_t InitEncode(const VideoCodec* config, |
| 2047 | int32_t number_of_cores, |
| 2048 | size_t max_payload_size) override { |
| 2049 | rtc::CritScope lock(&crit_); |
| 2050 | encoder_init_.Set(); |
| 2051 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 2052 | } |
| 2053 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 2054 | int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2055 | uint32_t framerate) override { |
| 2056 | rtc::CritScope lock(&crit_); |
| 2057 | bitrate_kbps_ = bitrate.get_sum_kbps(); |
| 2058 | bitrate_changed_.Set(); |
| 2059 | return FakeEncoder::SetRateAllocation(bitrate, framerate); |
| 2060 | } |
| 2061 | |
| 2062 | bool WaitForEncoderInit() { |
| 2063 | return encoder_init_.Wait(VideoSendStreamTest::kDefaultTimeoutMs); |
| 2064 | } |
| 2065 | |
| 2066 | bool WaitBitrateChanged(bool non_zero) { |
| 2067 | do { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 2068 | absl::optional<int> bitrate_kbps; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2069 | { |
| 2070 | rtc::CritScope lock(&crit_); |
| 2071 | bitrate_kbps = bitrate_kbps_; |
| 2072 | } |
| 2073 | if (!bitrate_kbps) |
| 2074 | continue; |
| 2075 | |
| 2076 | if ((non_zero && *bitrate_kbps > 0) || |
| 2077 | (!non_zero && *bitrate_kbps == 0)) { |
| 2078 | return true; |
| 2079 | } |
| 2080 | } while (bitrate_changed_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
| 2081 | return false; |
| 2082 | } |
| 2083 | |
| 2084 | private: |
| 2085 | rtc::CriticalSection crit_; |
| 2086 | rtc::Event encoder_init_; |
| 2087 | rtc::Event bitrate_changed_; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 2088 | absl::optional<int> bitrate_kbps_ RTC_GUARDED_BY(crit_); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2089 | }; |
| 2090 | |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2091 | // This test that if the encoder use an internal source, VideoEncoder::SetRates |
| 2092 | // will be called with zero bitrate during initialization and that |
| 2093 | // VideoSendStream::Stop also triggers VideoEncoder::SetRates Start to be called |
| 2094 | // with zero bitrate. |
| 2095 | TEST_F(VideoSendStreamTest, VideoSendStreamStopSetEncoderRateToZero) { |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2096 | test::NullTransport transport; |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2097 | StartStopBitrateObserver encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2098 | test::EncoderProxyFactory encoder_factory(&encoder); |
| 2099 | encoder_factory.SetHasInternalSource(true); |
| 2100 | test::FrameForwarder forwarder; |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2101 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2102 | task_queue_.SendTask([this, &transport, &encoder_factory, &forwarder]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 2103 | CreateSenderCall(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2104 | CreateSendConfig(1, 0, 0, &transport); |
| 2105 | |
| 2106 | sender_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2107 | GetVideoSendConfig()->encoder_settings.encoder_factory = &encoder_factory; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2108 | |
| 2109 | CreateVideoStreams(); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2110 | // Inject a frame, to force encoder creation. |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2111 | GetVideoSendStream()->Start(); |
| 2112 | GetVideoSendStream()->SetSource(&forwarder, |
| 2113 | DegradationPreference::DISABLED); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2114 | forwarder.IncomingCapturedFrame(CreateVideoFrame(640, 480, 4)); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2115 | }); |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2116 | |
| 2117 | EXPECT_TRUE(encoder.WaitForEncoderInit()); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2118 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2119 | task_queue_.SendTask([this]() { GetVideoSendStream()->Start(); }); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2120 | EXPECT_TRUE(encoder.WaitBitrateChanged(true)); |
| 2121 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2122 | task_queue_.SendTask([this]() { GetVideoSendStream()->Stop(); }); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2123 | EXPECT_TRUE(encoder.WaitBitrateChanged(false)); |
| 2124 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2125 | task_queue_.SendTask([this]() { GetVideoSendStream()->Start(); }); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2126 | EXPECT_TRUE(encoder.WaitBitrateChanged(true)); |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2127 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2128 | task_queue_.SendTask([this]() { |
| 2129 | DestroyStreams(); |
| 2130 | DestroyCalls(); |
| 2131 | }); |
perkj | 57c21f9 | 2016-06-17 07:27:16 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2134 | // Tests that when the encoder uses an internal source, the VideoEncoder will |
| 2135 | // be updated with a new bitrate when turning the VideoSendStream on/off with |
| 2136 | // VideoSendStream::UpdateActiveSimulcastLayers, and when the VideoStreamEncoder |
| 2137 | // is reconfigured with new active layers. |
| 2138 | TEST_F(VideoSendStreamTest, VideoSendStreamUpdateActiveSimulcastLayers) { |
| 2139 | test::NullTransport transport; |
| 2140 | StartStopBitrateObserver encoder; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2141 | test::EncoderProxyFactory encoder_factory(&encoder); |
| 2142 | encoder_factory.SetHasInternalSource(true); |
| 2143 | test::FrameForwarder forwarder; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2144 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2145 | task_queue_.SendTask([this, &transport, &encoder_factory, &forwarder]() { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 2146 | CreateSenderCall(); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2147 | // Create two simulcast streams. |
| 2148 | CreateSendConfig(2, 0, 0, &transport); |
| 2149 | |
| 2150 | sender_call_->SignalChannelNetworkState(MediaType::VIDEO, kNetworkUp); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2151 | GetVideoSendConfig()->encoder_settings.encoder_factory = &encoder_factory; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2152 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2153 | GetVideoSendConfig()->rtp.payload_name = "VP8"; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2154 | |
| 2155 | CreateVideoStreams(); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2156 | |
| 2157 | // Inject a frame, to force encoder creation. |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2158 | GetVideoSendStream()->Start(); |
| 2159 | GetVideoSendStream()->SetSource(&forwarder, |
| 2160 | DegradationPreference::DISABLED); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2161 | forwarder.IncomingCapturedFrame(CreateVideoFrame(640, 480, 4)); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2162 | }); |
| 2163 | |
| 2164 | EXPECT_TRUE(encoder.WaitForEncoderInit()); |
| 2165 | |
| 2166 | // When we turn on the simulcast layers it will update the BitrateAllocator, |
| 2167 | // which in turn updates the VideoEncoder's bitrate. |
| 2168 | task_queue_.SendTask([this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2169 | GetVideoSendStream()->UpdateActiveSimulcastLayers({true, true}); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2170 | }); |
| 2171 | EXPECT_TRUE(encoder.WaitBitrateChanged(true)); |
| 2172 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2173 | GetVideoEncoderConfig()->simulcast_layers[0].active = true; |
| 2174 | GetVideoEncoderConfig()->simulcast_layers[1].active = false; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2175 | task_queue_.SendTask([this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2176 | GetVideoSendStream()->ReconfigureVideoEncoder( |
| 2177 | GetVideoEncoderConfig()->Copy()); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2178 | }); |
| 2179 | // TODO(bugs.webrtc.org/8807): Currently we require a hard reconfiguration to |
| 2180 | // update the VideoBitrateAllocator and BitrateAllocator of which layers are |
| 2181 | // active. Once the change is made for a "soft" reconfiguration we can remove |
| 2182 | // the expecation for an encoder init. We can also test that bitrate changes |
| 2183 | // when just updating individual active layers, which should change the |
| 2184 | // bitrate set to the video encoder. |
| 2185 | EXPECT_TRUE(encoder.WaitForEncoderInit()); |
| 2186 | EXPECT_TRUE(encoder.WaitBitrateChanged(true)); |
| 2187 | |
| 2188 | // Turning off both simulcast layers should trigger a bitrate change of 0. |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2189 | GetVideoEncoderConfig()->simulcast_layers[0].active = false; |
| 2190 | GetVideoEncoderConfig()->simulcast_layers[1].active = false; |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2191 | task_queue_.SendTask([this]() { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2192 | GetVideoSendStream()->UpdateActiveSimulcastLayers({false, false}); |
Seth Hampson | cc7125f | 2018-02-02 08:46:16 -0800 | [diff] [blame] | 2193 | }); |
| 2194 | EXPECT_TRUE(encoder.WaitBitrateChanged(false)); |
| 2195 | |
| 2196 | task_queue_.SendTask([this]() { |
| 2197 | DestroyStreams(); |
| 2198 | DestroyCalls(); |
| 2199 | }); |
| 2200 | } |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2201 | TEST_F(VideoSendStreamTest, CapturesTextureAndVideoFrames) { |
nisse | d30a111 | 2016-04-18 05:15:22 -0700 | [diff] [blame] | 2202 | class FrameObserver : public rtc::VideoSinkInterface<VideoFrame> { |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2203 | public: |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2204 | FrameObserver() : output_frame_event_(false, false) {} |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2205 | |
nisse | d30a111 | 2016-04-18 05:15:22 -0700 | [diff] [blame] | 2206 | void OnFrame(const VideoFrame& video_frame) override { |
| 2207 | output_frames_.push_back(video_frame); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2208 | output_frame_event_.Set(); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | void WaitOutputFrame() { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2212 | const int kWaitFrameTimeoutMs = 3000; |
| 2213 | EXPECT_TRUE(output_frame_event_.Wait(kWaitFrameTimeoutMs)) |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2214 | << "Timeout while waiting for output frames."; |
| 2215 | } |
| 2216 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2217 | const std::vector<VideoFrame>& output_frames() const { |
magjed@webrtc.org | 2d2a30c | 2015-03-24 12:37:36 +0000 | [diff] [blame] | 2218 | return output_frames_; |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | private: |
| 2222 | // Delivered output frames. |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2223 | std::vector<VideoFrame> output_frames_; |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2224 | |
| 2225 | // Indicate an output frame has arrived. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2226 | rtc::Event output_frame_event_; |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2227 | }; |
| 2228 | |
solenberg | 4fbae2b | 2015-08-28 04:07:10 -0700 | [diff] [blame] | 2229 | test::NullTransport transport; |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2230 | FrameObserver observer; |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2231 | std::vector<VideoFrame> input_frames; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2232 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2233 | task_queue_.SendTask([this, &transport, &observer, &input_frames]() { |
| 2234 | // Initialize send stream. |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 2235 | CreateSenderCall(); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2236 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2237 | CreateSendConfig(1, 0, 0, &transport); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2238 | GetVideoSendConfig()->pre_encode_callback = &observer; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2239 | CreateVideoStreams(); |
| 2240 | |
| 2241 | // Prepare five input frames. Send ordinary VideoFrame and texture frames |
| 2242 | // alternatively. |
| 2243 | int width = 168; |
| 2244 | int height = 132; |
| 2245 | |
| 2246 | input_frames.push_back(test::FakeNativeBuffer::CreateFrame( |
| 2247 | width, height, 1, 1, kVideoRotation_0)); |
| 2248 | input_frames.push_back(test::FakeNativeBuffer::CreateFrame( |
| 2249 | width, height, 2, 2, kVideoRotation_0)); |
| 2250 | input_frames.push_back(CreateVideoFrame(width, height, 3)); |
| 2251 | input_frames.push_back(CreateVideoFrame(width, height, 4)); |
| 2252 | input_frames.push_back(test::FakeNativeBuffer::CreateFrame( |
| 2253 | width, height, 5, 5, kVideoRotation_0)); |
| 2254 | |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2255 | GetVideoSendStream()->Start(); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2256 | test::FrameForwarder forwarder; |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2257 | GetVideoSendStream()->SetSource(&forwarder, |
| 2258 | DegradationPreference::MAINTAIN_FRAMERATE); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2259 | for (size_t i = 0; i < input_frames.size(); i++) { |
| 2260 | forwarder.IncomingCapturedFrame(input_frames[i]); |
| 2261 | // Wait until the output frame is received before sending the next input |
| 2262 | // frame. Or the previous input frame may be replaced without delivering. |
| 2263 | observer.WaitOutputFrame(); |
| 2264 | } |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 2265 | GetVideoSendStream()->Stop(); |
| 2266 | GetVideoSendStream()->SetSource(nullptr, |
| 2267 | DegradationPreference::MAINTAIN_FRAMERATE); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2268 | }); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2269 | |
| 2270 | // Test if the input and output frames are the same. render_time_ms and |
| 2271 | // timestamp are not compared because capturer sets those values. |
magjed@webrtc.org | 2d2a30c | 2015-03-24 12:37:36 +0000 | [diff] [blame] | 2272 | ExpectEqualFramesVector(input_frames, observer.output_frames()); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2273 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2274 | task_queue_.SendTask([this]() { |
| 2275 | DestroyStreams(); |
| 2276 | DestroyCalls(); |
| 2277 | }); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2280 | void ExpectEqualFramesVector(const std::vector<VideoFrame>& frames1, |
| 2281 | const std::vector<VideoFrame>& frames2) { |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2282 | EXPECT_EQ(frames1.size(), frames2.size()); |
| 2283 | for (size_t i = 0; i < std::min(frames1.size(), frames2.size()); ++i) |
nisse | 26acec4 | 2016-04-15 03:43:39 -0700 | [diff] [blame] | 2284 | // Compare frame buffers, since we don't care about differing timestamps. |
| 2285 | EXPECT_TRUE(test::FrameBufsEqual(frames1[i].video_frame_buffer(), |
| 2286 | frames2[i].video_frame_buffer())); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2289 | VideoFrame CreateVideoFrame(int width, int height, uint8_t data) { |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2290 | const int kSizeY = width * height * 2; |
kwiberg | 27f982b | 2016-03-01 11:52:33 -0800 | [diff] [blame] | 2291 | std::unique_ptr<uint8_t[]> buffer(new uint8_t[kSizeY]); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2292 | memset(buffer.get(), data, kSizeY); |
Magnus Jedvert | 90e3190 | 2017-06-07 11:32:50 +0200 | [diff] [blame] | 2293 | VideoFrame frame(I420Buffer::Create(width, height), kVideoRotation_0, data); |
magjed@webrtc.org | 2d2a30c | 2015-03-24 12:37:36 +0000 | [diff] [blame] | 2294 | frame.set_timestamp(data); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 2295 | // Use data as a ms timestamp. |
| 2296 | frame.set_timestamp_us(data * rtc::kNumMicrosecsPerMillisec); |
wuchengli@chromium.org | f425b55 | 2014-06-20 12:04:05 +0000 | [diff] [blame] | 2297 | return frame; |
| 2298 | } |
| 2299 | |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2300 | TEST_F(VideoSendStreamTest, EncoderIsProperlyInitializedAndDestroyed) { |
| 2301 | class EncoderStateObserver : public test::SendTest, public VideoEncoder { |
| 2302 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2303 | explicit EncoderStateObserver( |
| 2304 | test::SingleThreadedTaskQueueForTesting* task_queue) |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2305 | : SendTest(kDefaultTimeoutMs), |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2306 | task_queue_(task_queue), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 2307 | stream_(nullptr), |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2308 | initialized_(false), |
| 2309 | callback_registered_(false), |
| 2310 | num_releases_(0), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2311 | released_(false), |
| 2312 | encoder_factory_(this) {} |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2313 | |
| 2314 | bool IsReleased() { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2315 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2316 | return released_; |
| 2317 | } |
| 2318 | |
| 2319 | bool IsReadyForEncode() { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2320 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2321 | return initialized_ && callback_registered_; |
| 2322 | } |
| 2323 | |
| 2324 | size_t num_releases() { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2325 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2326 | return num_releases_; |
| 2327 | } |
| 2328 | |
| 2329 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2330 | int32_t InitEncode(const VideoCodec* codecSettings, |
| 2331 | int32_t numberOfCores, |
| 2332 | size_t maxPayloadSize) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2333 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2334 | EXPECT_FALSE(initialized_); |
| 2335 | initialized_ = true; |
| 2336 | released_ = false; |
| 2337 | return 0; |
| 2338 | } |
| 2339 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2340 | int32_t Encode(const VideoFrame& inputImage, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2341 | const CodecSpecificInfo* codecSpecificInfo, |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 2342 | const std::vector<FrameType>* frame_types) override { |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2343 | EXPECT_TRUE(IsReadyForEncode()); |
| 2344 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2345 | observation_complete_.Set(); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2346 | return 0; |
| 2347 | } |
| 2348 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2349 | int32_t RegisterEncodeCompleteCallback( |
| 2350 | EncodedImageCallback* callback) override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2351 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2352 | EXPECT_TRUE(initialized_); |
| 2353 | callback_registered_ = true; |
| 2354 | return 0; |
| 2355 | } |
| 2356 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2357 | int32_t Release() override { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2358 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2359 | EXPECT_TRUE(IsReadyForEncode()); |
| 2360 | EXPECT_FALSE(released_); |
| 2361 | initialized_ = false; |
| 2362 | callback_registered_ = false; |
| 2363 | released_ = true; |
| 2364 | ++num_releases_; |
| 2365 | return 0; |
| 2366 | } |
| 2367 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2368 | int32_t SetChannelParameters(uint32_t packetLoss, int64_t rtt) override { |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2369 | EXPECT_TRUE(IsReadyForEncode()); |
| 2370 | return 0; |
| 2371 | } |
| 2372 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2373 | int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) override { |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2374 | EXPECT_TRUE(IsReadyForEncode()); |
| 2375 | return 0; |
| 2376 | } |
| 2377 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2378 | void OnVideoStreamsCreated( |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2379 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2380 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2381 | stream_ = send_stream; |
| 2382 | } |
| 2383 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2384 | void ModifyVideoConfigs( |
| 2385 | VideoSendStream::Config* send_config, |
| 2386 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2387 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2388 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2389 | encoder_config_ = encoder_config->Copy(); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2392 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2393 | EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2394 | |
| 2395 | task_queue_->SendTask([this]() { |
| 2396 | EXPECT_EQ(0u, num_releases()); |
| 2397 | stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
| 2398 | EXPECT_EQ(0u, num_releases()); |
| 2399 | stream_->Stop(); |
| 2400 | // Encoder should not be released before destroying the VideoSendStream. |
| 2401 | EXPECT_FALSE(IsReleased()); |
| 2402 | EXPECT_TRUE(IsReadyForEncode()); |
| 2403 | stream_->Start(); |
| 2404 | }); |
| 2405 | |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2406 | // Sanity check, make sure we still encode frames with this encoder. |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2407 | EXPECT_TRUE(Wait()) << "Timed out while waiting for Encode."; |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2410 | test::SingleThreadedTaskQueueForTesting* const task_queue_; |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 2411 | rtc::CriticalSection crit_; |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2412 | VideoSendStream* stream_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 2413 | bool initialized_ RTC_GUARDED_BY(crit_); |
| 2414 | bool callback_registered_ RTC_GUARDED_BY(crit_); |
| 2415 | size_t num_releases_ RTC_GUARDED_BY(crit_); |
| 2416 | bool released_ RTC_GUARDED_BY(crit_); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2417 | test::EncoderProxyFactory encoder_factory_; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2418 | VideoEncoderConfig encoder_config_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2419 | } test_encoder(&task_queue_); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2420 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2421 | RunBaseTest(&test_encoder); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2422 | |
| 2423 | EXPECT_TRUE(test_encoder.IsReleased()); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2424 | EXPECT_EQ(1u, test_encoder.num_releases()); |
pbos@webrtc.org | 161f808 | 2014-07-07 14:22:35 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2427 | TEST_F(VideoSendStreamTest, EncoderSetupPropagatesCommonEncoderConfigValues) { |
| 2428 | class VideoCodecConfigObserver : public test::SendTest, |
| 2429 | public test::FakeEncoder { |
| 2430 | public: |
| 2431 | VideoCodecConfigObserver() |
| 2432 | : SendTest(kDefaultTimeoutMs), |
| 2433 | FakeEncoder(Clock::GetRealTimeClock()), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2434 | init_encode_event_(false, false), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 2435 | num_initializations_(0), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2436 | stream_(nullptr), |
| 2437 | encoder_factory_(this) {} |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2438 | |
| 2439 | private: |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2440 | void ModifyVideoConfigs( |
| 2441 | VideoSendStream::Config* send_config, |
| 2442 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2443 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2444 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2445 | encoder_config->max_bitrate_bps = kFirstMaxBitrateBps; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2446 | encoder_config_ = encoder_config->Copy(); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2447 | } |
| 2448 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2449 | void OnVideoStreamsCreated( |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2450 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2451 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2452 | stream_ = send_stream; |
| 2453 | } |
| 2454 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2455 | int32_t InitEncode(const VideoCodec* config, |
| 2456 | int32_t number_of_cores, |
| 2457 | size_t max_payload_size) override { |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2458 | if (num_initializations_ == 0) { |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2459 | // Verify default values. |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2460 | EXPECT_EQ(kFirstMaxBitrateBps / 1000, config->maxBitrate); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2461 | } else { |
| 2462 | // Verify that changed values are propagated. |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2463 | EXPECT_EQ(kSecondMaxBitrateBps / 1000, config->maxBitrate); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2464 | } |
| 2465 | ++num_initializations_; |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2466 | init_encode_event_.Set(); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2467 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 2468 | } |
| 2469 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2470 | void PerformTest() override { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2471 | EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2472 | EXPECT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2473 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2474 | encoder_config_.max_bitrate_bps = kSecondMaxBitrateBps; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2475 | stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2476 | EXPECT_TRUE(init_encode_event_.Wait(kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2477 | EXPECT_EQ(2u, num_initializations_) |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2478 | << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
| 2479 | "new encoder settings."; |
| 2480 | } |
| 2481 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2482 | const uint32_t kFirstMaxBitrateBps = 1000000; |
| 2483 | const uint32_t kSecondMaxBitrateBps = 2000000; |
| 2484 | |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2485 | rtc::Event init_encode_event_; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2486 | size_t num_initializations_; |
| 2487 | VideoSendStream* stream_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2488 | test::EncoderProxyFactory encoder_factory_; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2489 | VideoEncoderConfig encoder_config_; |
| 2490 | } test; |
| 2491 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2492 | RunBaseTest(&test); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2493 | } |
| 2494 | |
Sergey Silkin | 571e6c9 | 2018-04-03 10:03:31 +0200 | [diff] [blame] | 2495 | static const size_t kVideoCodecConfigObserverNumberOfTemporalLayers = 3; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2496 | template <typename T> |
| 2497 | class VideoCodecConfigObserver : public test::SendTest, |
| 2498 | public test::FakeEncoder { |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2499 | public: |
| 2500 | VideoCodecConfigObserver(VideoCodecType video_codec_type, |
| 2501 | const char* codec_name) |
| 2502 | : SendTest(VideoSendStreamTest::kDefaultTimeoutMs), |
| 2503 | FakeEncoder(Clock::GetRealTimeClock()), |
| 2504 | video_codec_type_(video_codec_type), |
| 2505 | codec_name_(codec_name), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2506 | init_encode_event_(false, false), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 2507 | num_initializations_(0), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2508 | stream_(nullptr), |
| 2509 | encoder_factory_(this) { |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2510 | InitCodecSpecifics(); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | private: |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2514 | class VideoStreamFactory |
| 2515 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2516 | public: |
| 2517 | VideoStreamFactory() {} |
| 2518 | |
| 2519 | private: |
| 2520 | std::vector<VideoStream> CreateEncoderStreams( |
| 2521 | int width, |
| 2522 | int height, |
| 2523 | const VideoEncoderConfig& encoder_config) override { |
| 2524 | std::vector<VideoStream> streams = |
| 2525 | test::CreateVideoStreams(width, height, encoder_config); |
| 2526 | for (size_t i = 0; i < streams.size(); ++i) { |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2527 | streams[i].num_temporal_layers = |
| 2528 | kVideoCodecConfigObserverNumberOfTemporalLayers; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2529 | } |
| 2530 | return streams; |
| 2531 | } |
| 2532 | }; |
| 2533 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2534 | void ModifyVideoConfigs( |
| 2535 | VideoSendStream::Config* send_config, |
| 2536 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2537 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2538 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 2539 | send_config->rtp.payload_name = codec_name_; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2540 | |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 2541 | encoder_config->codec_type = video_codec_type_; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2542 | encoder_config->encoder_specific_settings = GetEncoderSpecificSettings(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2543 | encoder_config->video_stream_factory = |
| 2544 | new rtc::RefCountedObject<VideoStreamFactory>(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2545 | encoder_config_ = encoder_config->Copy(); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2546 | } |
| 2547 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2548 | void OnVideoStreamsCreated( |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2549 | VideoSendStream* send_stream, |
| 2550 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 2551 | stream_ = send_stream; |
| 2552 | } |
| 2553 | |
| 2554 | int32_t InitEncode(const VideoCodec* config, |
| 2555 | int32_t number_of_cores, |
| 2556 | size_t max_payload_size) override { |
| 2557 | EXPECT_EQ(video_codec_type_, config->codecType); |
| 2558 | VerifyCodecSpecifics(*config); |
| 2559 | ++num_initializations_; |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2560 | init_encode_event_.Set(); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2561 | return FakeEncoder::InitEncode(config, number_of_cores, max_payload_size); |
| 2562 | } |
| 2563 | |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2564 | void InitCodecSpecifics(); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2565 | void VerifyCodecSpecifics(const VideoCodec& config) const; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2566 | rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 2567 | GetEncoderSpecificSettings() const; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2568 | |
| 2569 | void PerformTest() override { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2570 | EXPECT_TRUE( |
| 2571 | init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2572 | ASSERT_EQ(1u, num_initializations_) << "VideoEncoder not initialized."; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2573 | |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2574 | // Change encoder settings to actually trigger reconfiguration. |
| 2575 | encoder_settings_.frameDroppingOn = !encoder_settings_.frameDroppingOn; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2576 | encoder_config_.encoder_specific_settings = GetEncoderSpecificSettings(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2577 | stream_->ReconfigureVideoEncoder(std::move(encoder_config_)); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2578 | ASSERT_TRUE( |
| 2579 | init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2580 | EXPECT_EQ(2u, num_initializations_) |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2581 | << "ReconfigureVideoEncoder did not reinitialize the encoder with " |
| 2582 | "new encoder settings."; |
| 2583 | } |
| 2584 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 2585 | int32_t Encode(const VideoFrame& input_image, |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2586 | const CodecSpecificInfo* codec_specific_info, |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 2587 | const std::vector<FrameType>* frame_types) override { |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2588 | // Silently skip the encode, FakeEncoder::Encode doesn't produce VP8. |
| 2589 | return 0; |
| 2590 | } |
| 2591 | |
| 2592 | T encoder_settings_; |
| 2593 | const VideoCodecType video_codec_type_; |
| 2594 | const char* const codec_name_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2595 | rtc::Event init_encode_event_; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2596 | size_t num_initializations_; |
| 2597 | VideoSendStream* stream_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2598 | test::EncoderProxyFactory encoder_factory_; |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2599 | VideoEncoderConfig encoder_config_; |
| 2600 | }; |
| 2601 | |
| 2602 | template <> |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2603 | void VideoCodecConfigObserver<VideoCodecH264>::InitCodecSpecifics() { |
| 2604 | encoder_settings_ = VideoEncoder::GetDefaultH264Settings(); |
| 2605 | } |
| 2606 | |
| 2607 | template <> |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2608 | void VideoCodecConfigObserver<VideoCodecH264>::VerifyCodecSpecifics( |
| 2609 | const VideoCodec& config) const { |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 2610 | EXPECT_EQ( |
| 2611 | 0, memcmp(&config.H264(), &encoder_settings_, sizeof(encoder_settings_))); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2612 | } |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2613 | |
| 2614 | template <> |
| 2615 | rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 2616 | VideoCodecConfigObserver<VideoCodecH264>::GetEncoderSpecificSettings() const { |
| 2617 | return new rtc::RefCountedObject< |
| 2618 | VideoEncoderConfig::H264EncoderSpecificSettings>(encoder_settings_); |
| 2619 | } |
| 2620 | |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2621 | template <> |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2622 | void VideoCodecConfigObserver<VideoCodecVP8>::InitCodecSpecifics() { |
| 2623 | encoder_settings_ = VideoEncoder::GetDefaultVp8Settings(); |
| 2624 | } |
| 2625 | |
| 2626 | template <> |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2627 | void VideoCodecConfigObserver<VideoCodecVP8>::VerifyCodecSpecifics( |
| 2628 | const VideoCodec& config) const { |
| 2629 | // Check that the number of temporal layers has propagated properly to |
| 2630 | // VideoCodec. |
| 2631 | EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 2632 | config.VP8().numberOfTemporalLayers); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2633 | |
| 2634 | for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 2635 | EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 2636 | config.simulcastStream[i].numberOfTemporalLayers); |
| 2637 | } |
| 2638 | |
| 2639 | // Set expected temporal layers as they should have been set when |
Erik Språng | 82fad3d | 2018-03-21 09:57:23 +0100 | [diff] [blame] | 2640 | // reconfiguring the encoder and not match the set config. |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2641 | VideoCodecVP8 encoder_settings = encoder_settings_; |
| 2642 | encoder_settings.numberOfTemporalLayers = |
| 2643 | kVideoCodecConfigObserverNumberOfTemporalLayers; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 2644 | EXPECT_EQ( |
| 2645 | 0, memcmp(&config.VP8(), &encoder_settings, sizeof(encoder_settings_))); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2646 | } |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2647 | |
| 2648 | template <> |
| 2649 | rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 2650 | VideoCodecConfigObserver<VideoCodecVP8>::GetEncoderSpecificSettings() const { |
| 2651 | return new rtc::RefCountedObject< |
| 2652 | VideoEncoderConfig::Vp8EncoderSpecificSettings>(encoder_settings_); |
| 2653 | } |
| 2654 | |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2655 | template <> |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 2656 | void VideoCodecConfigObserver<VideoCodecVP9>::InitCodecSpecifics() { |
| 2657 | encoder_settings_ = VideoEncoder::GetDefaultVp9Settings(); |
| 2658 | } |
| 2659 | |
| 2660 | template <> |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2661 | void VideoCodecConfigObserver<VideoCodecVP9>::VerifyCodecSpecifics( |
| 2662 | const VideoCodec& config) const { |
| 2663 | // Check that the number of temporal layers has propagated properly to |
| 2664 | // VideoCodec. |
| 2665 | EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 2666 | config.VP9().numberOfTemporalLayers); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2667 | |
| 2668 | for (unsigned char i = 0; i < config.numberOfSimulcastStreams; ++i) { |
| 2669 | EXPECT_EQ(kVideoCodecConfigObserverNumberOfTemporalLayers, |
| 2670 | config.simulcastStream[i].numberOfTemporalLayers); |
| 2671 | } |
| 2672 | |
| 2673 | // Set expected temporal layers as they should have been set when |
| 2674 | // reconfiguring the encoder and not match the set config. |
| 2675 | VideoCodecVP9 encoder_settings = encoder_settings_; |
| 2676 | encoder_settings.numberOfTemporalLayers = |
| 2677 | kVideoCodecConfigObserverNumberOfTemporalLayers; |
hta | 257dc39 | 2016-10-25 09:05:06 -0700 | [diff] [blame] | 2678 | EXPECT_EQ( |
| 2679 | 0, memcmp(&(config.VP9()), &encoder_settings, sizeof(encoder_settings_))); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2680 | } |
| 2681 | |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 2682 | template <> |
| 2683 | rtc::scoped_refptr<VideoEncoderConfig::EncoderSpecificSettings> |
| 2684 | VideoCodecConfigObserver<VideoCodecVP9>::GetEncoderSpecificSettings() const { |
| 2685 | return new rtc::RefCountedObject< |
| 2686 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(encoder_settings_); |
| 2687 | } |
| 2688 | |
pbos@webrtc.org | 91f1752 | 2014-07-10 10:13:37 +0000 | [diff] [blame] | 2689 | TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp8Config) { |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2690 | VideoCodecConfigObserver<VideoCodecVP8> test(kVideoCodecVP8, "VP8"); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2691 | RunBaseTest(&test); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2692 | } |
pbos@webrtc.org | 91f1752 | 2014-07-10 10:13:37 +0000 | [diff] [blame] | 2693 | |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2694 | TEST_F(VideoSendStreamTest, EncoderSetupPropagatesVp9Config) { |
| 2695 | VideoCodecConfigObserver<VideoCodecVP9> test(kVideoCodecVP9, "VP9"); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2696 | RunBaseTest(&test); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2697 | } |
pbos@webrtc.org | 91f1752 | 2014-07-10 10:13:37 +0000 | [diff] [blame] | 2698 | |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 2699 | TEST_F(VideoSendStreamTest, EncoderSetupPropagatesH264Config) { |
| 2700 | VideoCodecConfigObserver<VideoCodecH264> test(kVideoCodecH264, "H264"); |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2701 | RunBaseTest(&test); |
pbos@webrtc.org | 91f1752 | 2014-07-10 10:13:37 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2704 | TEST_F(VideoSendStreamTest, RtcpSenderReportContainsMediaBytesSent) { |
asapersson@webrtc.org | 1467421 | 2015-02-23 08:14:07 +0000 | [diff] [blame] | 2705 | class RtcpSenderReportTest : public test::SendTest { |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2706 | public: |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2707 | RtcpSenderReportTest() |
| 2708 | : SendTest(kDefaultTimeoutMs), |
| 2709 | rtp_packets_sent_(0), |
| 2710 | media_bytes_sent_(0) {} |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2711 | |
| 2712 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2713 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
stefan | 4b56904 | 2015-11-11 06:39:57 -0800 | [diff] [blame] | 2714 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2715 | RTPHeader header; |
| 2716 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
asapersson@webrtc.org | 1467421 | 2015-02-23 08:14:07 +0000 | [diff] [blame] | 2717 | ++rtp_packets_sent_; |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2718 | media_bytes_sent_ += length - header.headerLength - header.paddingLength; |
| 2719 | return SEND_PACKET; |
| 2720 | } |
| 2721 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2722 | Action OnSendRtcp(const uint8_t* packet, size_t length) override { |
stefan | 4b56904 | 2015-11-11 06:39:57 -0800 | [diff] [blame] | 2723 | rtc::CritScope lock(&crit_); |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 2724 | test::RtcpPacketParser parser; |
| 2725 | EXPECT_TRUE(parser.Parse(packet, length)); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2726 | |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 2727 | if (parser.sender_report()->num_packets() > 0) { |
| 2728 | // Only compare sent media bytes if SenderPacketCount matches the |
| 2729 | // number of sent rtp packets (a new rtp packet could be sent before |
| 2730 | // the rtcp packet). |
| 2731 | if (parser.sender_report()->sender_octet_count() > 0 && |
| 2732 | parser.sender_report()->sender_packet_count() == |
| 2733 | rtp_packets_sent_) { |
| 2734 | EXPECT_EQ(media_bytes_sent_, |
| 2735 | parser.sender_report()->sender_octet_count()); |
| 2736 | observation_complete_.Set(); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2737 | } |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | return SEND_PACKET; |
| 2741 | } |
| 2742 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2743 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2744 | EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP sender report."; |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
stefan | 4b56904 | 2015-11-11 06:39:57 -0800 | [diff] [blame] | 2747 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 2748 | size_t rtp_packets_sent_ RTC_GUARDED_BY(&crit_); |
| 2749 | size_t media_bytes_sent_ RTC_GUARDED_BY(&crit_); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2750 | } test; |
| 2751 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2752 | RunBaseTest(&test); |
pbos@webrtc.org | 2f4b14e | 2014-07-15 15:25:39 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2755 | TEST_F(VideoSendStreamTest, TranslatesTwoLayerScreencastToTargetBitrate) { |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2756 | static const int kScreencastMaxTargetBitrateDeltaKbps = 1; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2757 | |
| 2758 | class VideoStreamFactory |
| 2759 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2760 | public: |
| 2761 | VideoStreamFactory() {} |
| 2762 | |
| 2763 | private: |
| 2764 | std::vector<VideoStream> CreateEncoderStreams( |
| 2765 | int width, |
| 2766 | int height, |
| 2767 | const VideoEncoderConfig& encoder_config) override { |
| 2768 | std::vector<VideoStream> streams = |
| 2769 | test::CreateVideoStreams(width, height, encoder_config); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2770 | EXPECT_FALSE(streams[0].num_temporal_layers.has_value()); |
| 2771 | streams[0].num_temporal_layers = 2; |
| 2772 | RTC_CHECK_GT(streams[0].max_bitrate_bps, |
| 2773 | kScreencastMaxTargetBitrateDeltaKbps); |
| 2774 | streams[0].target_bitrate_bps = |
| 2775 | streams[0].max_bitrate_bps - |
| 2776 | kScreencastMaxTargetBitrateDeltaKbps * 1000; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2777 | return streams; |
| 2778 | } |
| 2779 | }; |
| 2780 | |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2781 | class ScreencastTargetBitrateTest : public test::SendTest, |
| 2782 | public test::FakeEncoder { |
| 2783 | public: |
| 2784 | ScreencastTargetBitrateTest() |
| 2785 | : SendTest(kDefaultTimeoutMs), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2786 | test::FakeEncoder(Clock::GetRealTimeClock()), |
| 2787 | encoder_factory_(this) {} |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2788 | |
| 2789 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2790 | int32_t InitEncode(const VideoCodec* config, |
| 2791 | int32_t number_of_cores, |
| 2792 | size_t max_payload_size) override { |
Erik Språng | 5e898d6 | 2018-07-06 16:32:20 +0200 | [diff] [blame] | 2793 | EXPECT_EQ(config->numberOfSimulcastStreams, 1); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2794 | EXPECT_EQ(static_cast<unsigned int>(kScreencastMaxTargetBitrateDeltaKbps), |
Erik Språng | 5e898d6 | 2018-07-06 16:32:20 +0200 | [diff] [blame] | 2795 | config->simulcastStream[0].maxBitrate - |
| 2796 | config->simulcastStream[0].targetBitrate); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2797 | observation_complete_.Set(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2798 | return test::FakeEncoder::InitEncode(config, number_of_cores, |
| 2799 | max_payload_size); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2800 | } |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2801 | void ModifyVideoConfigs( |
| 2802 | VideoSendStream::Config* send_config, |
| 2803 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2804 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2805 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2806 | EXPECT_EQ(1u, encoder_config->number_of_streams); |
| 2807 | encoder_config->video_stream_factory = |
| 2808 | new rtc::RefCountedObject<VideoStreamFactory>(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2809 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2812 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2813 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2814 | << "Timed out while waiting for the encoder to be initialized."; |
| 2815 | } |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2816 | test::EncoderProxyFactory encoder_factory_; |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2817 | } test; |
| 2818 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 2819 | RunBaseTest(&test); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2820 | } |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2821 | |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 2822 | TEST_F(VideoSendStreamTest, ReconfigureBitratesSetsEncoderBitratesCorrectly) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2823 | // These are chosen to be "kind of odd" to not be accidentally checked against |
| 2824 | // default values. |
| 2825 | static const int kMinBitrateKbps = 137; |
| 2826 | static const int kStartBitrateKbps = 345; |
| 2827 | static const int kLowerMaxBitrateKbps = 312; |
| 2828 | static const int kMaxBitrateKbps = 413; |
| 2829 | static const int kIncreasedStartBitrateKbps = 451; |
| 2830 | static const int kIncreasedMaxBitrateKbps = 597; |
| 2831 | class EncoderBitrateThresholdObserver : public test::SendTest, |
| 2832 | public test::FakeEncoder { |
| 2833 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2834 | explicit EncoderBitrateThresholdObserver( |
| 2835 | test::SingleThreadedTaskQueueForTesting* task_queue) |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2836 | : SendTest(kDefaultTimeoutMs), |
| 2837 | FakeEncoder(Clock::GetRealTimeClock()), |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2838 | task_queue_(task_queue), |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2839 | init_encode_event_(false, false), |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2840 | bitrate_changed_event_(false, false), |
| 2841 | target_bitrate_(0), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 2842 | num_initializations_(0), |
| 2843 | call_(nullptr), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2844 | send_stream_(nullptr), |
| 2845 | encoder_factory_(this) {} |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2846 | |
| 2847 | private: |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2848 | int32_t InitEncode(const VideoCodec* codecSettings, |
| 2849 | int32_t numberOfCores, |
| 2850 | size_t maxPayloadSize) override { |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2851 | EXPECT_GE(codecSettings->startBitrate, codecSettings->minBitrate); |
| 2852 | EXPECT_LE(codecSettings->startBitrate, codecSettings->maxBitrate); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2853 | if (num_initializations_ == 0) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2854 | EXPECT_EQ(static_cast<unsigned int>(kMinBitrateKbps), |
| 2855 | codecSettings->minBitrate); |
| 2856 | EXPECT_EQ(static_cast<unsigned int>(kStartBitrateKbps), |
| 2857 | codecSettings->startBitrate); |
| 2858 | EXPECT_EQ(static_cast<unsigned int>(kMaxBitrateKbps), |
| 2859 | codecSettings->maxBitrate); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 2860 | observation_complete_.Set(); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2861 | } else if (num_initializations_ == 1) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2862 | EXPECT_EQ(static_cast<unsigned int>(kLowerMaxBitrateKbps), |
| 2863 | codecSettings->maxBitrate); |
| 2864 | // The start bitrate should be kept (-1) and capped to the max bitrate. |
| 2865 | // Since this is not an end-to-end call no receiver should have been |
| 2866 | // returning a REMB that could lower this estimate. |
| 2867 | EXPECT_EQ(codecSettings->startBitrate, codecSettings->maxBitrate); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2868 | } else if (num_initializations_ == 2) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2869 | EXPECT_EQ(static_cast<unsigned int>(kIncreasedMaxBitrateKbps), |
| 2870 | codecSettings->maxBitrate); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2871 | // The start bitrate will be whatever the rate BitRateController |
| 2872 | // has currently configured but in the span of the set max and min |
| 2873 | // bitrate. |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2874 | } |
| 2875 | ++num_initializations_; |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2876 | init_encode_event_.Set(); |
| 2877 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2878 | return FakeEncoder::InitEncode(codecSettings, numberOfCores, |
| 2879 | maxPayloadSize); |
| 2880 | } |
| 2881 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 2882 | int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2883 | uint32_t frameRate) override { |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2884 | { |
| 2885 | rtc::CritScope lock(&crit_); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2886 | if (target_bitrate_ == bitrate.get_sum_kbps()) { |
| 2887 | return FakeEncoder::SetRateAllocation(bitrate, frameRate); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2888 | } |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2889 | target_bitrate_ = bitrate.get_sum_kbps(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2890 | } |
| 2891 | bitrate_changed_event_.Set(); |
Erik Språng | 08127a9 | 2016-11-16 16:41:30 +0100 | [diff] [blame] | 2892 | return FakeEncoder::SetRateAllocation(bitrate, frameRate); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | void WaitForSetRates(uint32_t expected_bitrate) { |
| 2896 | EXPECT_TRUE( |
| 2897 | bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) |
| 2898 | << "Timed out while waiting encoder rate to be set."; |
| 2899 | rtc::CritScope lock(&crit_); |
| 2900 | EXPECT_EQ(expected_bitrate, target_bitrate_); |
| 2901 | } |
| 2902 | |
Sebastian Jansson | 7258224 | 2018-07-13 13:19:42 +0200 | [diff] [blame] | 2903 | void ModifySenderCallConfig(Call::Config* config) override { |
| 2904 | config->bitrate_config.min_bitrate_bps = kMinBitrateKbps * 1000; |
| 2905 | config->bitrate_config.start_bitrate_bps = kStartBitrateKbps * 1000; |
| 2906 | config->bitrate_config.max_bitrate_bps = kMaxBitrateKbps * 1000; |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2909 | class VideoStreamFactory |
| 2910 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 2911 | public: |
| 2912 | explicit VideoStreamFactory(int min_bitrate_bps) |
| 2913 | : min_bitrate_bps_(min_bitrate_bps) {} |
| 2914 | |
| 2915 | private: |
| 2916 | std::vector<VideoStream> CreateEncoderStreams( |
| 2917 | int width, |
| 2918 | int height, |
| 2919 | const VideoEncoderConfig& encoder_config) override { |
| 2920 | std::vector<VideoStream> streams = |
| 2921 | test::CreateVideoStreams(width, height, encoder_config); |
| 2922 | streams[0].min_bitrate_bps = min_bitrate_bps_; |
| 2923 | return streams; |
| 2924 | } |
| 2925 | |
| 2926 | const int min_bitrate_bps_; |
| 2927 | }; |
| 2928 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2929 | void ModifyVideoConfigs( |
| 2930 | VideoSendStream::Config* send_config, |
| 2931 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 2932 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2933 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2934 | // Set bitrates lower/higher than min/max to make sure they are properly |
| 2935 | // capped. |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2936 | encoder_config->max_bitrate_bps = kMaxBitrateKbps * 1000; |
| 2937 | // Create a new StreamFactory to be able to set |
| 2938 | // |VideoStream.min_bitrate_bps|. |
| 2939 | encoder_config->video_stream_factory = |
| 2940 | new rtc::RefCountedObject<VideoStreamFactory>(kMinBitrateKbps * 1000); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2941 | encoder_config_ = encoder_config->Copy(); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2944 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2945 | call_ = sender_call; |
| 2946 | } |
| 2947 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 2948 | void OnVideoStreamsCreated( |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 2949 | VideoSendStream* send_stream, |
| 2950 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 2951 | send_stream_ = send_stream; |
| 2952 | } |
| 2953 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2954 | void PerformTest() override { |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2955 | ASSERT_TRUE( |
| 2956 | init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)) |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2957 | << "Timed out while waiting for encoder to be configured."; |
| 2958 | WaitForSetRates(kStartBitrateKbps); |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 2959 | BitrateConstraints bitrate_config; |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2960 | bitrate_config.start_bitrate_bps = kIncreasedStartBitrateKbps * 1000; |
| 2961 | bitrate_config.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2962 | task_queue_->SendTask([this, &bitrate_config]() { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2963 | call_->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 2964 | bitrate_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2965 | }); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2966 | // Encoder rate is capped by EncoderConfig max_bitrate_bps. |
| 2967 | WaitForSetRates(kMaxBitrateKbps); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2968 | encoder_config_.max_bitrate_bps = kLowerMaxBitrateKbps * 1000; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2969 | send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2970 | ASSERT_TRUE( |
| 2971 | init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2972 | EXPECT_EQ(2, num_initializations_) |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2973 | << "Encoder should have been reconfigured with the new value."; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2974 | WaitForSetRates(kLowerMaxBitrateKbps); |
| 2975 | |
| 2976 | encoder_config_.max_bitrate_bps = kIncreasedMaxBitrateKbps * 1000; |
| 2977 | send_stream_->ReconfigureVideoEncoder(encoder_config_.Copy()); |
| 2978 | ASSERT_TRUE( |
| 2979 | init_encode_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 2980 | EXPECT_EQ(3, num_initializations_) |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2981 | << "Encoder should have been reconfigured with the new value."; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2982 | // Expected target bitrate is the start bitrate set in the call to |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2983 | // call_->GetTransportControllerSend()->SetSdpBitrateParameters. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2984 | WaitForSetRates(kIncreasedStartBitrateKbps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2987 | test::SingleThreadedTaskQueueForTesting* const task_queue_; |
pbos | 14fe708 | 2016-04-20 06:35:56 -0700 | [diff] [blame] | 2988 | rtc::Event init_encode_event_; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2989 | rtc::Event bitrate_changed_event_; |
| 2990 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 2991 | uint32_t target_bitrate_ RTC_GUARDED_BY(&crit_); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2992 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2993 | int num_initializations_; |
| 2994 | webrtc::Call* call_; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 2995 | webrtc::VideoSendStream* send_stream_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 2996 | test::EncoderProxyFactory encoder_factory_; |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 2997 | webrtc::VideoEncoderConfig encoder_config_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 2998 | } test(&task_queue_); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2999 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 3000 | RunBaseTest(&test); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3001 | } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3002 | |
| 3003 | TEST_F(VideoSendStreamTest, ReportsSentResolution) { |
| 3004 | static const size_t kNumStreams = 3; |
| 3005 | // Unusual resolutions to make sure that they are the ones being reported. |
| 3006 | static const struct { |
| 3007 | int width; |
| 3008 | int height; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3009 | } kEncodedResolution[kNumStreams] = {{241, 181}, {300, 121}, {121, 221}}; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3010 | class ScreencastTargetBitrateTest : public test::SendTest, |
| 3011 | public test::FakeEncoder { |
| 3012 | public: |
| 3013 | ScreencastTargetBitrateTest() |
| 3014 | : SendTest(kDefaultTimeoutMs), |
Erik Språng | 737336d | 2016-07-29 12:59:36 +0200 | [diff] [blame] | 3015 | test::FakeEncoder(Clock::GetRealTimeClock()), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3016 | send_stream_(nullptr), |
| 3017 | encoder_factory_(this) {} |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3018 | |
| 3019 | private: |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 3020 | int32_t Encode(const VideoFrame& input_image, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 3021 | const CodecSpecificInfo* codecSpecificInfo, |
pbos | 22993e1 | 2015-10-19 02:39:06 -0700 | [diff] [blame] | 3022 | const std::vector<FrameType>* frame_types) override { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3023 | CodecSpecificInfo specifics; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3024 | specifics.codecType = kVideoCodecGeneric; |
| 3025 | |
| 3026 | uint8_t buffer[16] = {0}; |
| 3027 | EncodedImage encoded(buffer, sizeof(buffer), sizeof(buffer)); |
| 3028 | encoded._timeStamp = input_image.timestamp(); |
| 3029 | encoded.capture_time_ms_ = input_image.render_time_ms(); |
| 3030 | |
| 3031 | for (size_t i = 0; i < kNumStreams; ++i) { |
| 3032 | specifics.codecSpecific.generic.simulcast_idx = static_cast<uint8_t>(i); |
| 3033 | encoded._frameType = (*frame_types)[i]; |
| 3034 | encoded._encodedWidth = kEncodedResolution[i].width; |
| 3035 | encoded._encodedHeight = kEncodedResolution[i].height; |
brandtr | e78d266 | 2017-01-16 05:57:16 -0800 | [diff] [blame] | 3036 | EncodedImageCallback* callback; |
| 3037 | { |
| 3038 | rtc::CritScope cs(&crit_sect_); |
| 3039 | callback = callback_; |
| 3040 | } |
| 3041 | RTC_DCHECK(callback); |
| 3042 | if (callback->OnEncodedImage(encoded, &specifics, nullptr).error != |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 3043 | EncodedImageCallback::Result::OK) { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3044 | return -1; |
sergeyu | 2cb155a | 2016-11-04 11:39:29 -0700 | [diff] [blame] | 3045 | } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 3048 | observation_complete_.Set(); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3049 | return 0; |
| 3050 | } |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3051 | void ModifyVideoConfigs( |
| 3052 | VideoSendStream::Config* send_config, |
| 3053 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3054 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3055 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3056 | EXPECT_EQ(kNumStreams, encoder_config->number_of_streams); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3057 | } |
| 3058 | |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 3059 | size_t GetNumVideoStreams() const override { return kNumStreams; } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3060 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 3061 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 3062 | EXPECT_TRUE(Wait()) |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3063 | << "Timed out while waiting for the encoder to send one frame."; |
| 3064 | VideoSendStream::Stats stats = send_stream_->GetStats(); |
| 3065 | |
| 3066 | for (size_t i = 0; i < kNumStreams; ++i) { |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 3067 | ASSERT_TRUE(stats.substreams.find(kVideoSendSsrcs[i]) != |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3068 | stats.substreams.end()) |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 3069 | << "No stats for SSRC: " << kVideoSendSsrcs[i] |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3070 | << ", stats should exist as soon as frames have been encoded."; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 3071 | VideoSendStream::StreamStats ssrc_stats = |
Stefan Holmer | 9fea80f | 2016-01-07 17:43:18 +0100 | [diff] [blame] | 3072 | stats.substreams[kVideoSendSsrcs[i]]; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 3073 | EXPECT_EQ(kEncodedResolution[i].width, ssrc_stats.width); |
| 3074 | EXPECT_EQ(kEncodedResolution[i].height, ssrc_stats.height); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3078 | void OnVideoStreamsCreated( |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3079 | VideoSendStream* send_stream, |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 3080 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3081 | send_stream_ = send_stream; |
| 3082 | } |
| 3083 | |
| 3084 | VideoSendStream* send_stream_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3085 | test::EncoderProxyFactory encoder_factory_; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3086 | } test; |
| 3087 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 3088 | RunBaseTest(&test); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 3089 | } |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3090 | |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 3091 | #if !defined(RTC_DISABLE_VP9) |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3092 | class Vp9HeaderObserver : public test::SendTest { |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3093 | public: |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3094 | Vp9HeaderObserver() |
| 3095 | : SendTest(VideoSendStreamTest::kLongTimeoutMs), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3096 | encoder_factory_([]() { return VP9Encoder::Create(); }), |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3097 | vp9_settings_(VideoEncoder::GetDefaultVp9Settings()), |
| 3098 | packets_sent_(0), |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3099 | frames_sent_(0), |
| 3100 | expected_width_(0), |
| 3101 | expected_height_(0) {} |
philipel | 7fabd46 | 2015-09-03 04:42:32 -0700 | [diff] [blame] | 3102 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3103 | virtual void ModifyVideoConfigsHook( |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3104 | VideoSendStream::Config* send_config, |
| 3105 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3106 | VideoEncoderConfig* encoder_config) {} |
| 3107 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3108 | virtual void InspectHeader(const RTPVideoHeaderVP9& vp9) = 0; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3109 | |
| 3110 | private: |
minyue | 20c84cc | 2017-04-10 16:57:57 -0700 | [diff] [blame] | 3111 | const int kVp9PayloadType = test::CallTest::kVideoSendPayloadType; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3112 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3113 | class VideoStreamFactory |
| 3114 | : public VideoEncoderConfig::VideoStreamFactoryInterface { |
| 3115 | public: |
| 3116 | explicit VideoStreamFactory(size_t number_of_temporal_layers) |
| 3117 | : number_of_temporal_layers_(number_of_temporal_layers) {} |
| 3118 | |
| 3119 | private: |
| 3120 | std::vector<VideoStream> CreateEncoderStreams( |
| 3121 | int width, |
| 3122 | int height, |
| 3123 | const VideoEncoderConfig& encoder_config) override { |
| 3124 | std::vector<VideoStream> streams = |
| 3125 | test::CreateVideoStreams(width, height, encoder_config); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 3126 | streams.back().num_temporal_layers = number_of_temporal_layers_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3127 | return streams; |
| 3128 | } |
| 3129 | |
| 3130 | const size_t number_of_temporal_layers_; |
| 3131 | }; |
| 3132 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3133 | void ModifyVideoConfigs( |
| 3134 | VideoSendStream::Config* send_config, |
| 3135 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3136 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3137 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 3138 | send_config->rtp.payload_name = "VP9"; |
| 3139 | send_config->rtp.payload_type = kVp9PayloadType; |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3140 | ModifyVideoConfigsHook(send_config, receive_configs, encoder_config); |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 3141 | encoder_config->encoder_specific_settings = new rtc::RefCountedObject< |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3142 | VideoEncoderConfig::Vp9EncoderSpecificSettings>(vp9_settings_); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3143 | EXPECT_EQ(1u, encoder_config->number_of_streams); |
| 3144 | encoder_config->video_stream_factory = |
| 3145 | new rtc::RefCountedObject<VideoStreamFactory>( |
| 3146 | vp9_settings_.numberOfTemporalLayers); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3147 | encoder_config_ = encoder_config->Copy(); |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3150 | void ModifyVideoCaptureStartResolution(int* width, |
| 3151 | int* height, |
| 3152 | int* frame_rate) override { |
| 3153 | expected_width_ = *width; |
| 3154 | expected_height_ = *height; |
| 3155 | } |
| 3156 | |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3157 | void PerformTest() override { |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 3158 | EXPECT_TRUE(Wait()) << "Test timed out waiting for VP9 packet, num frames " |
| 3159 | << frames_sent_; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 3163 | RTPHeader header; |
| 3164 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 3165 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3166 | EXPECT_EQ(kVp9PayloadType, header.payloadType); |
| 3167 | const uint8_t* payload = packet + header.headerLength; |
| 3168 | size_t payload_length = length - header.headerLength - header.paddingLength; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3169 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3170 | bool new_packet = packets_sent_ == 0 || |
| 3171 | IsNewerSequenceNumber(header.sequenceNumber, |
| 3172 | last_header_.sequenceNumber); |
| 3173 | if (payload_length > 0 && new_packet) { |
| 3174 | RtpDepacketizer::ParsedPayload parsed; |
| 3175 | RtpDepacketizerVp9 depacketizer; |
| 3176 | EXPECT_TRUE(depacketizer.Parse(&parsed, payload, payload_length)); |
philipel | cb96ad8 | 2018-07-02 14:41:58 +0200 | [diff] [blame] | 3177 | EXPECT_EQ(VideoCodecType::kVideoCodecVP9, parsed.video_header().codec); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3178 | // Verify common fields for all configurations. |
philipel | 5ab67a5 | 2018-07-05 12:27:04 +0200 | [diff] [blame] | 3179 | VerifyCommonHeader(parsed.video_header().vp9()); |
philipel | cb96ad8 | 2018-07-02 14:41:58 +0200 | [diff] [blame] | 3180 | CompareConsecutiveFrames(header, parsed.video_header()); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3181 | // Verify configuration specific settings. |
philipel | 5ab67a5 | 2018-07-05 12:27:04 +0200 | [diff] [blame] | 3182 | InspectHeader(parsed.video_header().vp9()); |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3183 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3184 | ++packets_sent_; |
| 3185 | if (header.markerBit) { |
| 3186 | ++frames_sent_; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3187 | } |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3188 | last_header_ = header; |
philipel | 5ab67a5 | 2018-07-05 12:27:04 +0200 | [diff] [blame] | 3189 | last_vp9_ = parsed.video_header().vp9(); |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3190 | } |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3191 | return SEND_PACKET; |
| 3192 | } |
| 3193 | |
philipel | 7fabd46 | 2015-09-03 04:42:32 -0700 | [diff] [blame] | 3194 | protected: |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3195 | bool ContinuousPictureId(const RTPVideoHeaderVP9& vp9) const { |
| 3196 | if (last_vp9_.picture_id > vp9.picture_id) { |
| 3197 | return vp9.picture_id == 0; // Wrap. |
| 3198 | } else { |
| 3199 | return vp9.picture_id == last_vp9_.picture_id + 1; |
| 3200 | } |
| 3201 | } |
| 3202 | |
| 3203 | void VerifySpatialIdxWithinFrame(const RTPVideoHeaderVP9& vp9) const { |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3204 | bool new_layer = vp9.spatial_idx != last_vp9_.spatial_idx; |
| 3205 | EXPECT_EQ(new_layer, vp9.beginning_of_frame); |
| 3206 | EXPECT_EQ(new_layer, last_vp9_.end_of_frame); |
| 3207 | EXPECT_EQ(new_layer ? last_vp9_.spatial_idx + 1 : last_vp9_.spatial_idx, |
| 3208 | vp9.spatial_idx); |
| 3209 | } |
| 3210 | |
| 3211 | void VerifyFixedTemporalLayerStructure(const RTPVideoHeaderVP9& vp9, |
| 3212 | uint8_t num_layers) const { |
| 3213 | switch (num_layers) { |
| 3214 | case 0: |
| 3215 | VerifyTemporalLayerStructure0(vp9); |
| 3216 | break; |
| 3217 | case 1: |
| 3218 | VerifyTemporalLayerStructure1(vp9); |
| 3219 | break; |
| 3220 | case 2: |
| 3221 | VerifyTemporalLayerStructure2(vp9); |
| 3222 | break; |
| 3223 | case 3: |
| 3224 | VerifyTemporalLayerStructure3(vp9); |
| 3225 | break; |
| 3226 | default: |
| 3227 | RTC_NOTREACHED(); |
| 3228 | } |
| 3229 | } |
| 3230 | |
| 3231 | void VerifyTemporalLayerStructure0(const RTPVideoHeaderVP9& vp9) const { |
| 3232 | EXPECT_EQ(kNoTl0PicIdx, vp9.tl0_pic_idx); |
| 3233 | EXPECT_EQ(kNoTemporalIdx, vp9.temporal_idx); // no tid |
| 3234 | EXPECT_FALSE(vp9.temporal_up_switch); |
| 3235 | } |
| 3236 | |
| 3237 | void VerifyTemporalLayerStructure1(const RTPVideoHeaderVP9& vp9) const { |
| 3238 | EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx); |
| 3239 | EXPECT_EQ(0, vp9.temporal_idx); // 0,0,0,... |
| 3240 | EXPECT_FALSE(vp9.temporal_up_switch); |
| 3241 | } |
| 3242 | |
| 3243 | void VerifyTemporalLayerStructure2(const RTPVideoHeaderVP9& vp9) const { |
| 3244 | EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx); |
| 3245 | EXPECT_GE(vp9.temporal_idx, 0); // 0,1,0,1,... (tid reset on I-frames). |
| 3246 | EXPECT_LE(vp9.temporal_idx, 1); |
| 3247 | EXPECT_EQ(vp9.temporal_idx > 0, vp9.temporal_up_switch); |
| 3248 | if (IsNewPictureId(vp9)) { |
| 3249 | uint8_t expected_tid = |
| 3250 | (!vp9.inter_pic_predicted || last_vp9_.temporal_idx == 1) ? 0 : 1; |
| 3251 | EXPECT_EQ(expected_tid, vp9.temporal_idx); |
| 3252 | } |
| 3253 | } |
| 3254 | |
| 3255 | void VerifyTemporalLayerStructure3(const RTPVideoHeaderVP9& vp9) const { |
| 3256 | EXPECT_NE(kNoTl0PicIdx, vp9.tl0_pic_idx); |
| 3257 | EXPECT_GE(vp9.temporal_idx, 0); // 0,2,1,2,... (tid reset on I-frames). |
| 3258 | EXPECT_LE(vp9.temporal_idx, 2); |
| 3259 | if (IsNewPictureId(vp9) && vp9.inter_pic_predicted) { |
| 3260 | EXPECT_NE(vp9.temporal_idx, last_vp9_.temporal_idx); |
| 3261 | switch (vp9.temporal_idx) { |
| 3262 | case 0: |
| 3263 | EXPECT_EQ(2, last_vp9_.temporal_idx); |
| 3264 | EXPECT_FALSE(vp9.temporal_up_switch); |
| 3265 | break; |
| 3266 | case 1: |
| 3267 | EXPECT_EQ(2, last_vp9_.temporal_idx); |
| 3268 | EXPECT_TRUE(vp9.temporal_up_switch); |
| 3269 | break; |
| 3270 | case 2: |
Sergey Silkin | 377ef24 | 2018-05-07 09:17:12 +0200 | [diff] [blame] | 3271 | EXPECT_LT(last_vp9_.temporal_idx, 2); |
| 3272 | EXPECT_TRUE(vp9.temporal_up_switch); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3273 | break; |
| 3274 | } |
| 3275 | } |
| 3276 | } |
| 3277 | |
| 3278 | void VerifyTl0Idx(const RTPVideoHeaderVP9& vp9) const { |
| 3279 | if (vp9.tl0_pic_idx == kNoTl0PicIdx) |
| 3280 | return; |
| 3281 | |
| 3282 | uint8_t expected_tl0_idx = last_vp9_.tl0_pic_idx; |
| 3283 | if (vp9.temporal_idx == 0) |
| 3284 | ++expected_tl0_idx; |
| 3285 | EXPECT_EQ(expected_tl0_idx, vp9.tl0_pic_idx); |
| 3286 | } |
| 3287 | |
| 3288 | bool IsNewPictureId(const RTPVideoHeaderVP9& vp9) const { |
| 3289 | return frames_sent_ > 0 && (vp9.picture_id != last_vp9_.picture_id); |
| 3290 | } |
| 3291 | |
| 3292 | // Flexible mode (F=1): Non-flexible mode (F=0): |
| 3293 | // |
| 3294 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3295 | // |I|P|L|F|B|E|V|-| |I|P|L|F|B|E|V|-| |
| 3296 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3297 | // I: |M| PICTURE ID | I: |M| PICTURE ID | |
| 3298 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3299 | // M: | EXTENDED PID | M: | EXTENDED PID | |
| 3300 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3301 | // L: | T |U| S |D| L: | T |U| S |D| |
| 3302 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3303 | // P,F: | P_DIFF |X|N| | TL0PICIDX | |
| 3304 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3305 | // X: |EXTENDED P_DIFF| V: | SS .. | |
| 3306 | // +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ |
| 3307 | // V: | SS .. | |
| 3308 | // +-+-+-+-+-+-+-+-+ |
| 3309 | void VerifyCommonHeader(const RTPVideoHeaderVP9& vp9) const { |
| 3310 | EXPECT_EQ(kMaxTwoBytePictureId, vp9.max_picture_id); // M:1 |
| 3311 | EXPECT_NE(kNoPictureId, vp9.picture_id); // I:1 |
| 3312 | EXPECT_EQ(vp9_settings_.flexibleMode, vp9.flexible_mode); // F |
Sergey Silkin | 3f2634e | 2017-11-06 11:49:19 +0100 | [diff] [blame] | 3313 | |
| 3314 | if (vp9_settings_.numberOfSpatialLayers > 1) { |
| 3315 | EXPECT_LT(vp9.spatial_idx, vp9_settings_.numberOfSpatialLayers); |
| 3316 | } else if (vp9_settings_.numberOfTemporalLayers > 1) { |
| 3317 | EXPECT_EQ(vp9.spatial_idx, 0); |
| 3318 | } else { |
| 3319 | EXPECT_EQ(vp9.spatial_idx, kNoSpatialIdx); |
| 3320 | } |
| 3321 | |
| 3322 | if (vp9_settings_.numberOfTemporalLayers > 1) { |
| 3323 | EXPECT_LT(vp9.temporal_idx, vp9_settings_.numberOfTemporalLayers); |
| 3324 | } else if (vp9_settings_.numberOfSpatialLayers > 1) { |
| 3325 | EXPECT_EQ(vp9.temporal_idx, 0); |
| 3326 | } else { |
| 3327 | EXPECT_EQ(vp9.temporal_idx, kNoTemporalIdx); |
| 3328 | } |
| 3329 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3330 | if (vp9.ss_data_available) // V |
| 3331 | VerifySsData(vp9); |
| 3332 | |
| 3333 | if (frames_sent_ == 0) |
| 3334 | EXPECT_FALSE(vp9.inter_pic_predicted); // P |
| 3335 | |
| 3336 | if (!vp9.inter_pic_predicted) { |
| 3337 | EXPECT_TRUE(vp9.temporal_idx == 0 || vp9.temporal_idx == kNoTemporalIdx); |
| 3338 | EXPECT_FALSE(vp9.temporal_up_switch); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | // Scalability structure (SS). |
| 3343 | // |
| 3344 | // +-+-+-+-+-+-+-+-+ |
| 3345 | // V: | N_S |Y|G|-|-|-| |
| 3346 | // +-+-+-+-+-+-+-+-+ |
| 3347 | // Y: | WIDTH | N_S + 1 times |
| 3348 | // +-+-+-+-+-+-+-+-+ |
| 3349 | // | HEIGHT | |
| 3350 | // +-+-+-+-+-+-+-+-+ |
| 3351 | // G: | N_G | |
| 3352 | // +-+-+-+-+-+-+-+-+ |
| 3353 | // N_G: | T |U| R |-|-| N_G times |
| 3354 | // +-+-+-+-+-+-+-+-+ |
| 3355 | // | P_DIFF | R times |
| 3356 | // +-+-+-+-+-+-+-+-+ |
| 3357 | void VerifySsData(const RTPVideoHeaderVP9& vp9) const { |
| 3358 | EXPECT_TRUE(vp9.ss_data_available); // V |
| 3359 | EXPECT_EQ(vp9_settings_.numberOfSpatialLayers, // N_S + 1 |
| 3360 | vp9.num_spatial_layers); |
| 3361 | EXPECT_TRUE(vp9.spatial_layer_resolution_present); // Y:1 |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3362 | int expected_width = expected_width_; |
| 3363 | int expected_height = expected_height_; |
Peter Boström | 0208322 | 2016-06-14 12:52:54 +0200 | [diff] [blame] | 3364 | for (int i = static_cast<int>(vp9.num_spatial_layers) - 1; i >= 0; --i) { |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3365 | EXPECT_EQ(expected_width, vp9.width[i]); // WIDTH |
| 3366 | EXPECT_EQ(expected_height, vp9.height[i]); // HEIGHT |
| 3367 | expected_width /= 2; |
| 3368 | expected_height /= 2; |
| 3369 | } |
| 3370 | } |
| 3371 | |
| 3372 | void CompareConsecutiveFrames(const RTPHeader& header, |
| 3373 | const RTPVideoHeader& video) const { |
philipel | 5ab67a5 | 2018-07-05 12:27:04 +0200 | [diff] [blame] | 3374 | const RTPVideoHeaderVP9& vp9 = video.vp9(); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3375 | |
| 3376 | bool new_frame = packets_sent_ == 0 || |
| 3377 | IsNewerTimestamp(header.timestamp, last_header_.timestamp); |
johan | 0d1b2b6 | 2017-01-10 04:21:35 -0800 | [diff] [blame] | 3378 | EXPECT_EQ(new_frame, video.is_first_packet_in_frame); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3379 | if (!new_frame) { |
| 3380 | EXPECT_FALSE(last_header_.markerBit); |
| 3381 | EXPECT_EQ(last_header_.timestamp, header.timestamp); |
| 3382 | EXPECT_EQ(last_vp9_.picture_id, vp9.picture_id); |
| 3383 | EXPECT_EQ(last_vp9_.temporal_idx, vp9.temporal_idx); |
| 3384 | EXPECT_EQ(last_vp9_.tl0_pic_idx, vp9.tl0_pic_idx); |
| 3385 | VerifySpatialIdxWithinFrame(vp9); |
| 3386 | return; |
| 3387 | } |
| 3388 | // New frame. |
| 3389 | EXPECT_TRUE(vp9.beginning_of_frame); |
| 3390 | |
| 3391 | // Compare with last packet in previous frame. |
| 3392 | if (frames_sent_ == 0) |
| 3393 | return; |
| 3394 | EXPECT_TRUE(last_vp9_.end_of_frame); |
| 3395 | EXPECT_TRUE(last_header_.markerBit); |
| 3396 | EXPECT_TRUE(ContinuousPictureId(vp9)); |
| 3397 | VerifyTl0Idx(vp9); |
| 3398 | } |
| 3399 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3400 | test::FunctionVideoEncoderFactory encoder_factory_; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3401 | VideoCodecVP9 vp9_settings_; |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3402 | webrtc::VideoEncoderConfig encoder_config_; |
| 3403 | RTPHeader last_header_; |
| 3404 | RTPVideoHeaderVP9 last_vp9_; |
| 3405 | size_t packets_sent_; |
| 3406 | size_t frames_sent_; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3407 | int expected_width_; |
| 3408 | int expected_height_; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3409 | }; |
| 3410 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3411 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl1SLayers) { |
| 3412 | const uint8_t kNumTemporalLayers = 1; |
| 3413 | const uint8_t kNumSpatialLayers = 1; |
| 3414 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3415 | } |
| 3416 | |
| 3417 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl1SLayers) { |
| 3418 | const uint8_t kNumTemporalLayers = 2; |
| 3419 | const uint8_t kNumSpatialLayers = 1; |
| 3420 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3421 | } |
| 3422 | |
| 3423 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_3Tl1SLayers) { |
| 3424 | const uint8_t kNumTemporalLayers = 3; |
| 3425 | const uint8_t kNumSpatialLayers = 1; |
| 3426 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3427 | } |
| 3428 | |
| 3429 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_1Tl2SLayers) { |
| 3430 | const uint8_t kNumTemporalLayers = 1; |
| 3431 | const uint8_t kNumSpatialLayers = 2; |
| 3432 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3433 | } |
| 3434 | |
| 3435 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_2Tl2SLayers) { |
| 3436 | const uint8_t kNumTemporalLayers = 2; |
| 3437 | const uint8_t kNumSpatialLayers = 2; |
| 3438 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3439 | } |
| 3440 | |
| 3441 | TEST_F(VideoSendStreamTest, Vp9NonFlexMode_3Tl2SLayers) { |
| 3442 | const uint8_t kNumTemporalLayers = 3; |
| 3443 | const uint8_t kNumSpatialLayers = 2; |
| 3444 | TestVp9NonFlexMode(kNumTemporalLayers, kNumSpatialLayers); |
| 3445 | } |
| 3446 | |
| 3447 | void VideoSendStreamTest::TestVp9NonFlexMode(uint8_t num_temporal_layers, |
| 3448 | uint8_t num_spatial_layers) { |
| 3449 | static const size_t kNumFramesToSend = 100; |
| 3450 | // Set to < kNumFramesToSend and coprime to length of temporal layer |
| 3451 | // structures to verify temporal id reset on key frame. |
| 3452 | static const int kKeyFrameInterval = 31; |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 3453 | |
| 3454 | static const int kWidth = kMinVp9SpatialLayerWidth; |
| 3455 | static const int kHeight = kMinVp9SpatialLayerHeight; |
| 3456 | static const float kGoodBitsPerPixel = 0.1f; |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3457 | class NonFlexibleMode : public Vp9HeaderObserver { |
| 3458 | public: |
| 3459 | NonFlexibleMode(uint8_t num_temporal_layers, uint8_t num_spatial_layers) |
| 3460 | : num_temporal_layers_(num_temporal_layers), |
| 3461 | num_spatial_layers_(num_spatial_layers), |
| 3462 | l_field_(num_temporal_layers > 1 || num_spatial_layers > 1) {} |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 3463 | |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3464 | void ModifyVideoConfigsHook( |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3465 | VideoSendStream::Config* send_config, |
| 3466 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3467 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 04dd176 | 2018-03-23 16:05:22 +0100 | [diff] [blame] | 3468 | encoder_config->codec_type = kVideoCodecVP9; |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 3469 | int bitrate_bps = 0; |
| 3470 | for (int sl_idx = 0; sl_idx < num_spatial_layers_; ++sl_idx) { |
| 3471 | const int width = kWidth << sl_idx; |
| 3472 | const int height = kHeight << sl_idx; |
| 3473 | const float bpp = kGoodBitsPerPixel / (1 << sl_idx); |
| 3474 | bitrate_bps += static_cast<int>(width * height * bpp * 30); |
| 3475 | } |
| 3476 | encoder_config->max_bitrate_bps = bitrate_bps * 2; |
| 3477 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3478 | vp9_settings_.flexibleMode = false; |
| 3479 | vp9_settings_.frameDroppingOn = false; |
| 3480 | vp9_settings_.keyFrameInterval = kKeyFrameInterval; |
| 3481 | vp9_settings_.numberOfTemporalLayers = num_temporal_layers_; |
| 3482 | vp9_settings_.numberOfSpatialLayers = num_spatial_layers_; |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Sergey Silkin | 8668496 | 2018-03-28 19:32:37 +0200 | [diff] [blame] | 3485 | void ModifyVideoCaptureStartResolution(int* width, |
| 3486 | int* height, |
| 3487 | int* frame_rate) override { |
| 3488 | expected_width_ = kWidth << (num_spatial_layers_ - 1); |
| 3489 | expected_height_ = kHeight << (num_spatial_layers_ - 1); |
| 3490 | *width = expected_width_; |
| 3491 | *height = expected_height_; |
| 3492 | } |
| 3493 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3494 | void InspectHeader(const RTPVideoHeaderVP9& vp9) override { |
Sergey Silkin | 3f2634e | 2017-11-06 11:49:19 +0100 | [diff] [blame] | 3495 | bool ss_data_expected = |
| 3496 | !vp9.inter_pic_predicted && vp9.beginning_of_frame && |
| 3497 | (vp9.spatial_idx == 0 || vp9.spatial_idx == kNoSpatialIdx); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3498 | EXPECT_EQ(ss_data_expected, vp9.ss_data_available); |
Sergey Silkin | 3f2634e | 2017-11-06 11:49:19 +0100 | [diff] [blame] | 3499 | if (num_spatial_layers_ > 1) { |
| 3500 | EXPECT_EQ(vp9.spatial_idx > 0, vp9.inter_layer_predicted); |
| 3501 | } else { |
| 3502 | EXPECT_FALSE(vp9.inter_layer_predicted); |
| 3503 | } |
| 3504 | |
asapersson | 38bb8ad | 2015-12-14 01:41:19 -0800 | [diff] [blame] | 3505 | EXPECT_EQ(!vp9.inter_pic_predicted, |
| 3506 | frames_sent_ % kKeyFrameInterval == 0); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3507 | |
| 3508 | if (IsNewPictureId(vp9)) { |
Sergey Silkin | 3f2634e | 2017-11-06 11:49:19 +0100 | [diff] [blame] | 3509 | if (num_temporal_layers_ == 1 && num_spatial_layers_ == 1) { |
| 3510 | EXPECT_EQ(kNoSpatialIdx, vp9.spatial_idx); |
| 3511 | } else { |
| 3512 | EXPECT_EQ(0, vp9.spatial_idx); |
| 3513 | } |
| 3514 | if (num_spatial_layers_ > 1) |
| 3515 | EXPECT_EQ(num_spatial_layers_ - 1, last_vp9_.spatial_idx); |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3516 | } |
| 3517 | |
| 3518 | VerifyFixedTemporalLayerStructure(vp9, |
| 3519 | l_field_ ? num_temporal_layers_ : 0); |
| 3520 | |
| 3521 | if (frames_sent_ > kNumFramesToSend) |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 3522 | observation_complete_.Set(); |
philipel | 0f9af01 | 2015-09-01 07:01:51 -0700 | [diff] [blame] | 3523 | } |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3524 | const uint8_t num_temporal_layers_; |
| 3525 | const uint8_t num_spatial_layers_; |
| 3526 | const bool l_field_; |
| 3527 | } test(num_temporal_layers, num_spatial_layers); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3528 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 3529 | RunBaseTest(&test); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3530 | } |
| 3531 | |
asapersson | d9f641e | 2016-01-21 01:11:35 -0800 | [diff] [blame] | 3532 | TEST_F(VideoSendStreamTest, Vp9NonFlexModeSmallResolution) { |
| 3533 | static const size_t kNumFramesToSend = 50; |
| 3534 | static const int kWidth = 4; |
| 3535 | static const int kHeight = 4; |
| 3536 | class NonFlexibleModeResolution : public Vp9HeaderObserver { |
| 3537 | void ModifyVideoConfigsHook( |
| 3538 | VideoSendStream::Config* send_config, |
| 3539 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3540 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 3541 | encoder_config->codec_type = kVideoCodecVP9; |
asapersson | d9f641e | 2016-01-21 01:11:35 -0800 | [diff] [blame] | 3542 | vp9_settings_.flexibleMode = false; |
| 3543 | vp9_settings_.numberOfTemporalLayers = 1; |
| 3544 | vp9_settings_.numberOfSpatialLayers = 1; |
| 3545 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3546 | EXPECT_EQ(1u, encoder_config->number_of_streams); |
asapersson | d9f641e | 2016-01-21 01:11:35 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override { |
| 3550 | if (frames_sent_ > kNumFramesToSend) |
| 3551 | observation_complete_.Set(); |
| 3552 | } |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3553 | |
| 3554 | void ModifyVideoCaptureStartResolution(int* width, |
| 3555 | int* height, |
| 3556 | int* frame_rate) override { |
| 3557 | expected_width_ = kWidth; |
| 3558 | expected_height_ = kHeight; |
| 3559 | *width = kWidth; |
| 3560 | *height = kHeight; |
| 3561 | } |
asapersson | d9f641e | 2016-01-21 01:11:35 -0800 | [diff] [blame] | 3562 | } test; |
| 3563 | |
| 3564 | RunBaseTest(&test); |
| 3565 | } |
| 3566 | |
kjellander | f9e2a36 | 2017-03-24 12:17:33 -0700 | [diff] [blame] | 3567 | #if defined(WEBRTC_ANDROID) |
| 3568 | // Crashes on Android; bugs.webrtc.org/7401 |
| 3569 | #define MAYBE_Vp9FlexModeRefCount DISABLED_Vp9FlexModeRefCount |
| 3570 | #else |
Sergey Silkin | be71a1e | 2018-05-17 16:46:43 +0200 | [diff] [blame] | 3571 | // TODO(webrtc:9270): Support of flexible mode is temporarily disabled. Enable |
| 3572 | // the test after webrtc:9270 is implemented. |
| 3573 | #define MAYBE_Vp9FlexModeRefCount DISABLED_Vp9FlexModeRefCount |
| 3574 | // #define MAYBE_Vp9FlexModeRefCount Vp9FlexModeRefCount |
kjellander | f9e2a36 | 2017-03-24 12:17:33 -0700 | [diff] [blame] | 3575 | #endif |
| 3576 | TEST_F(VideoSendStreamTest, MAYBE_Vp9FlexModeRefCount) { |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3577 | class FlexibleMode : public Vp9HeaderObserver { |
stefan | ff48361 | 2015-12-21 03:14:00 -0800 | [diff] [blame] | 3578 | void ModifyVideoConfigsHook( |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3579 | VideoSendStream::Config* send_config, |
| 3580 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3581 | VideoEncoderConfig* encoder_config) override { |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 3582 | encoder_config->codec_type = kVideoCodecVP9; |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3583 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3584 | vp9_settings_.flexibleMode = true; |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3585 | vp9_settings_.numberOfTemporalLayers = 1; |
| 3586 | vp9_settings_.numberOfSpatialLayers = 2; |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3587 | } |
| 3588 | |
Åsa Persson | ff24c04 | 2015-12-04 10:58:08 +0100 | [diff] [blame] | 3589 | void InspectHeader(const RTPVideoHeaderVP9& vp9_header) override { |
| 3590 | EXPECT_TRUE(vp9_header.flexible_mode); |
| 3591 | EXPECT_EQ(kNoTl0PicIdx, vp9_header.tl0_pic_idx); |
| 3592 | if (vp9_header.inter_pic_predicted) { |
| 3593 | EXPECT_GT(vp9_header.num_ref_pics, 0u); |
Peter Boström | 5811a39 | 2015-12-10 13:02:50 +0100 | [diff] [blame] | 3594 | observation_complete_.Set(); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3595 | } |
| 3596 | } |
| 3597 | } test; |
| 3598 | |
stefan | e74eef1 | 2016-01-08 06:47:13 -0800 | [diff] [blame] | 3599 | RunBaseTest(&test); |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3600 | } |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 3601 | #endif // !defined(RTC_DISABLE_VP9) |
philipel | cfc319b | 2015-11-10 07:17:23 -0800 | [diff] [blame] | 3602 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3603 | void VideoSendStreamTest::TestRequestSourceRotateVideo( |
| 3604 | bool support_orientation_ext) { |
Sebastian Jansson | 8e6602f | 2018-07-13 10:43:20 +0200 | [diff] [blame] | 3605 | CreateSenderCall(); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3606 | |
| 3607 | test::NullTransport transport; |
brandtr | 841de6a | 2016-11-15 07:10:52 -0800 | [diff] [blame] | 3608 | CreateSendConfig(1, 0, 0, &transport); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 3609 | GetVideoSendConfig()->rtp.extensions.clear(); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3610 | if (support_orientation_ext) { |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 3611 | GetVideoSendConfig()->rtp.extensions.push_back( |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3612 | RtpExtension(RtpExtension::kVideoRotationUri, 1)); |
| 3613 | } |
| 3614 | |
| 3615 | CreateVideoStreams(); |
| 3616 | test::FrameForwarder forwarder; |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 3617 | GetVideoSendStream()->SetSource(&forwarder, |
| 3618 | DegradationPreference::MAINTAIN_FRAMERATE); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3619 | |
| 3620 | EXPECT_TRUE(forwarder.sink_wants().rotation_applied != |
| 3621 | support_orientation_ext); |
| 3622 | |
| 3623 | DestroyStreams(); |
| 3624 | } |
| 3625 | |
| 3626 | TEST_F(VideoSendStreamTest, |
| 3627 | RequestSourceRotateIfVideoOrientationExtensionNotSupported) { |
| 3628 | TestRequestSourceRotateVideo(false); |
| 3629 | } |
| 3630 | |
| 3631 | TEST_F(VideoSendStreamTest, |
| 3632 | DoNotRequestsRotationIfVideoOrientationExtensionSupported) { |
| 3633 | TestRequestSourceRotateVideo(true); |
| 3634 | } |
| 3635 | |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3636 | // This test verifies that overhead is removed from the bandwidth estimate by |
| 3637 | // testing that the maximum possible target payload rate is smaller than the |
| 3638 | // maximum bandwidth estimate by the overhead rate. |
michaelt | 273f31b | 2017-02-08 08:21:52 -0800 | [diff] [blame] | 3639 | TEST_F(VideoSendStreamTest, RemoveOverheadFromBandwidth) { |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3640 | test::ScopedFieldTrials override_field_trials( |
| 3641 | "WebRTC-SendSideBwe-WithOverhead/Enabled/"); |
| 3642 | class RemoveOverheadFromBandwidthTest : public test::EndToEndTest, |
| 3643 | public test::FakeEncoder { |
| 3644 | public: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3645 | explicit RemoveOverheadFromBandwidthTest( |
| 3646 | test::SingleThreadedTaskQueueForTesting* task_queue) |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3647 | : EndToEndTest(test::CallTest::kDefaultTimeoutMs), |
| 3648 | FakeEncoder(Clock::GetRealTimeClock()), |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3649 | task_queue_(task_queue), |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3650 | encoder_factory_(this), |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3651 | call_(nullptr), |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3652 | max_bitrate_bps_(0), |
| 3653 | first_packet_sent_(false), |
| 3654 | bitrate_changed_event_(false, false) {} |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3655 | |
Erik Språng | 566124a | 2018-04-23 12:32:22 +0200 | [diff] [blame] | 3656 | int32_t SetRateAllocation(const VideoBitrateAllocation& bitrate, |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3657 | uint32_t frameRate) override { |
| 3658 | rtc::CritScope lock(&crit_); |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3659 | // Wait for the first sent packet so that videosendstream knows |
| 3660 | // rtp_overhead. |
| 3661 | if (first_packet_sent_) { |
| 3662 | max_bitrate_bps_ = bitrate.get_sum_bps(); |
| 3663 | bitrate_changed_event_.Set(); |
| 3664 | } |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3665 | return FakeEncoder::SetRateAllocation(bitrate, frameRate); |
| 3666 | } |
| 3667 | |
| 3668 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 3669 | call_ = sender_call; |
| 3670 | } |
| 3671 | |
| 3672 | void ModifyVideoConfigs( |
| 3673 | VideoSendStream::Config* send_config, |
| 3674 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3675 | VideoEncoderConfig* encoder_config) override { |
| 3676 | send_config->rtp.max_packet_size = 1200; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3677 | send_config->encoder_settings.encoder_factory = &encoder_factory_; |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3678 | EXPECT_FALSE(send_config->rtp.extensions.empty()); |
| 3679 | } |
| 3680 | |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3681 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 3682 | rtc::CritScope lock(&crit_); |
| 3683 | first_packet_sent_ = true; |
| 3684 | return SEND_PACKET; |
| 3685 | } |
| 3686 | |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3687 | void PerformTest() override { |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 3688 | BitrateConstraints bitrate_config; |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3689 | constexpr int kStartBitrateBps = 60000; |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3690 | constexpr int kMaxBitrateBps = 60000; |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3691 | constexpr int kMinBitrateBps = 10000; |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3692 | bitrate_config.start_bitrate_bps = kStartBitrateBps; |
| 3693 | bitrate_config.max_bitrate_bps = kMaxBitrateBps; |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3694 | bitrate_config.min_bitrate_bps = kMinBitrateBps; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3695 | task_queue_->SendTask([this, &bitrate_config]() { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3696 | call_->GetTransportControllerSend()->SetSdpBitrateParameters( |
| 3697 | bitrate_config); |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3698 | call_->OnTransportOverheadChanged(webrtc::MediaType::VIDEO, 40); |
| 3699 | }); |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3700 | |
| 3701 | // At a bitrate of 60kbps with a packet size of 1200B video and an |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3702 | // overhead of 40B per packet video produces 2240bps overhead. |
| 3703 | // So the encoder BW should be set to 57760bps. |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3704 | EXPECT_TRUE( |
| 3705 | bitrate_changed_event_.Wait(VideoSendStreamTest::kDefaultTimeoutMs)); |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3706 | { |
| 3707 | rtc::CritScope lock(&crit_); |
michaelt | 273f31b | 2017-02-08 08:21:52 -0800 | [diff] [blame] | 3708 | EXPECT_LE(max_bitrate_bps_, 57760u); |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | |
| 3712 | private: |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3713 | test::SingleThreadedTaskQueueForTesting* const task_queue_; |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 3714 | test::EncoderProxyFactory encoder_factory_; |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3715 | Call* call_; |
| 3716 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 3717 | uint32_t max_bitrate_bps_ RTC_GUARDED_BY(&crit_); |
| 3718 | bool first_packet_sent_ RTC_GUARDED_BY(&crit_); |
michaelt | 192132e | 2017-01-26 09:05:27 -0800 | [diff] [blame] | 3719 | rtc::Event bitrate_changed_event_; |
eladalon | 413ee9a | 2017-08-22 04:02:52 -0700 | [diff] [blame] | 3720 | } test(&task_queue_); |
michaelt | a332877 | 2016-11-29 09:25:03 -0800 | [diff] [blame] | 3721 | RunBaseTest(&test); |
| 3722 | } |
| 3723 | |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 3724 | TEST_F(VideoSendStreamTest, SendsKeepAlive) { |
| 3725 | const int kTimeoutMs = 50; // Really short timeout for testing. |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 3726 | |
| 3727 | class KeepaliveObserver : public test::SendTest { |
| 3728 | public: |
| 3729 | KeepaliveObserver() : SendTest(kDefaultTimeoutMs) {} |
| 3730 | |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 3731 | void OnRtpTransportControllerSendCreated( |
| 3732 | RtpTransportControllerSend* controller) override { |
| 3733 | RtpKeepAliveConfig config; |
| 3734 | config.timeout_interval_ms = kTimeoutMs; |
| 3735 | config.payload_type = CallTest::kDefaultKeepalivePayloadType; |
| 3736 | controller->SetKeepAliveConfig(config); |
sprang | e5c4a81 | 2017-07-11 03:44:17 -0700 | [diff] [blame] | 3737 | } |
| 3738 | |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 3739 | private: |
| 3740 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 3741 | RTPHeader header; |
| 3742 | EXPECT_TRUE(parser_->Parse(packet, length, &header)); |
| 3743 | |
sprang | d2702ef | 2017-07-10 08:41:10 -0700 | [diff] [blame] | 3744 | if (header.payloadType != CallTest::kDefaultKeepalivePayloadType) { |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 3745 | // The video stream has started. Stop it now. |
| 3746 | if (capturer_) |
| 3747 | capturer_->Stop(); |
| 3748 | } else { |
| 3749 | observation_complete_.Set(); |
| 3750 | } |
| 3751 | |
| 3752 | return SEND_PACKET; |
| 3753 | } |
| 3754 | |
sprang | 168794c | 2017-07-06 04:38:06 -0700 | [diff] [blame] | 3755 | void PerformTest() override { |
| 3756 | EXPECT_TRUE(Wait()) << "Timed out while waiting for keep-alive packet."; |
| 3757 | } |
| 3758 | |
| 3759 | void OnFrameGeneratorCapturerCreated( |
| 3760 | test::FrameGeneratorCapturer* frame_generator_capturer) override { |
| 3761 | capturer_ = frame_generator_capturer; |
| 3762 | } |
| 3763 | |
| 3764 | test::FrameGeneratorCapturer* capturer_ = nullptr; |
| 3765 | } test; |
| 3766 | |
| 3767 | RunBaseTest(&test); |
| 3768 | } |
| 3769 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3770 | class PacingFactorObserver : public test::SendTest { |
| 3771 | public: |
| 3772 | PacingFactorObserver(bool configure_send_side, |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 3773 | absl::optional<float> expected_pacing_factor) |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3774 | : test::SendTest(VideoSendStreamTest::kDefaultTimeoutMs), |
| 3775 | configure_send_side_(configure_send_side), |
| 3776 | expected_pacing_factor_(expected_pacing_factor) {} |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3777 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3778 | void ModifyVideoConfigs( |
| 3779 | VideoSendStream::Config* send_config, |
| 3780 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3781 | VideoEncoderConfig* encoder_config) override { |
| 3782 | // Check if send-side bwe extension is already present, and remove it if |
| 3783 | // it is not desired. |
| 3784 | bool has_send_side = false; |
| 3785 | for (auto it = send_config->rtp.extensions.begin(); |
| 3786 | it != send_config->rtp.extensions.end(); ++it) { |
| 3787 | if (it->uri == RtpExtension::kTransportSequenceNumberUri) { |
| 3788 | if (configure_send_side_) { |
| 3789 | has_send_side = true; |
| 3790 | } else { |
| 3791 | send_config->rtp.extensions.erase(it); |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3792 | } |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3793 | break; |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3794 | } |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3795 | } |
| 3796 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3797 | if (configure_send_side_ && !has_send_side) { |
| 3798 | // Want send side, not present by default, so add it. |
| 3799 | send_config->rtp.extensions.emplace_back( |
| 3800 | RtpExtension::kTransportSequenceNumberUri, |
| 3801 | RtpExtension::kTransportSequenceNumberDefaultId); |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3802 | } |
| 3803 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3804 | // ALR only enabled for screenshare. |
| 3805 | encoder_config->content_type = VideoEncoderConfig::ContentType::kScreen; |
| 3806 | } |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3807 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3808 | void OnVideoStreamsCreated( |
| 3809 | VideoSendStream* send_stream, |
| 3810 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 3811 | auto internal_send_peer = test::VideoSendStreamPeer(send_stream); |
| 3812 | // Video streams created, check that pacing factor is correctly configured. |
| 3813 | EXPECT_EQ(expected_pacing_factor_, |
| 3814 | internal_send_peer.GetPacingFactorOverride()); |
| 3815 | observation_complete_.Set(); |
| 3816 | } |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3817 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3818 | void PerformTest() override { |
| 3819 | EXPECT_TRUE(Wait()) << "Timed out while waiting for stream creation."; |
| 3820 | } |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3821 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3822 | private: |
| 3823 | const bool configure_send_side_; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 3824 | const absl::optional<float> expected_pacing_factor_; |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3825 | }; |
| 3826 | |
| 3827 | std::string GetAlrProbingExperimentString() { |
| 3828 | return std::string( |
| 3829 | AlrExperimentSettings::kScreenshareProbingBweExperimentName) + |
| 3830 | "/1.0,2875,80,40,-60,3/"; |
| 3831 | } |
| 3832 | const float kAlrProbingExperimentPaceMultiplier = 1.0f; |
| 3833 | |
| 3834 | TEST_F(VideoSendStreamTest, AlrConfiguredWhenSendSideOn) { |
| 3835 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3836 | // Send-side bwe on, use pacing factor from |kAlrProbingExperiment| above. |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3837 | PacingFactorObserver test_with_send_side(true, |
| 3838 | kAlrProbingExperimentPaceMultiplier); |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3839 | RunBaseTest(&test_with_send_side); |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3840 | } |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3841 | |
Sebastian Jansson | a45c8da | 2018-01-16 10:55:29 +0100 | [diff] [blame] | 3842 | TEST_F(VideoSendStreamTest, AlrNotConfiguredWhenSendSideOff) { |
| 3843 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
| 3844 | // Send-side bwe off, use configuration should not be overridden. |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 3845 | PacingFactorObserver test_without_send_side(false, absl::nullopt); |
Erik Språng | 7c8cca3 | 2017-10-24 17:05:18 +0200 | [diff] [blame] | 3846 | RunBaseTest(&test_without_send_side); |
| 3847 | } |
| 3848 | |
Ilya Nikolaevskiy | 4425b05 | 2018-03-15 11:42:00 +0100 | [diff] [blame] | 3849 | // Test class takes as argument a function pointer to reset the send |
| 3850 | // stream and call OnVideoStreamsCreated. This is necessary since you cannot |
| 3851 | // change the content type of a VideoSendStream, you need to recreate it. |
| 3852 | // Stopping and recreating the stream can only be done on the main thread and in |
| 3853 | // the context of VideoSendStreamTest (not BaseTest). The test switches from |
| 3854 | // realtime to screenshare and back. |
| 3855 | template <typename T> |
| 3856 | class ContentSwitchTest : public test::SendTest { |
| 3857 | public: |
| 3858 | enum class StreamState { |
| 3859 | kBeforeSwitch = 0, |
| 3860 | kInScreenshare = 1, |
| 3861 | kAfterSwitchBack = 2, |
| 3862 | }; |
| 3863 | static const uint32_t kMinPacketsToSend = 50; |
| 3864 | |
| 3865 | explicit ContentSwitchTest(T* stream_reset_fun) |
| 3866 | : SendTest(test::CallTest::kDefaultTimeoutMs), |
| 3867 | content_switch_event_(false, false), |
| 3868 | call_(nullptr), |
| 3869 | state_(StreamState::kBeforeSwitch), |
| 3870 | send_stream_(nullptr), |
| 3871 | send_stream_config_(nullptr), |
| 3872 | packets_sent_(0), |
| 3873 | stream_resetter_(stream_reset_fun) { |
| 3874 | RTC_DCHECK(stream_resetter_); |
| 3875 | } |
| 3876 | |
| 3877 | void OnVideoStreamsCreated( |
| 3878 | VideoSendStream* send_stream, |
| 3879 | const std::vector<VideoReceiveStream*>& receive_streams) override { |
| 3880 | rtc::CritScope lock(&crit_); |
| 3881 | send_stream_ = send_stream; |
| 3882 | } |
| 3883 | |
| 3884 | void ModifyVideoConfigs( |
| 3885 | VideoSendStream::Config* send_config, |
| 3886 | std::vector<VideoReceiveStream::Config>* receive_configs, |
| 3887 | VideoEncoderConfig* encoder_config) override { |
| 3888 | RTC_DCHECK_EQ(1, encoder_config->number_of_streams); |
| 3889 | encoder_config->min_transmit_bitrate_bps = 0; |
| 3890 | encoder_config->content_type = |
| 3891 | VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 3892 | send_stream_config_ = send_config->Copy(); |
| 3893 | encoder_config_ = encoder_config->Copy(); |
| 3894 | } |
| 3895 | |
| 3896 | void OnCallsCreated(Call* sender_call, Call* receiver_call) override { |
| 3897 | call_ = sender_call; |
| 3898 | } |
| 3899 | |
| 3900 | Action OnSendRtp(const uint8_t* packet, size_t length) override { |
| 3901 | rtc::CritScope lock(&crit_); |
| 3902 | |
| 3903 | auto internal_send_peer = test::VideoSendStreamPeer(send_stream_); |
| 3904 | float pacing_factor = |
| 3905 | internal_send_peer.GetPacingFactorOverride().value_or(0.0f); |
| 3906 | float expected_pacing_factor = PacedSender::kDefaultPaceMultiplier; |
| 3907 | if (send_stream_->GetStats().content_type == |
| 3908 | webrtc::VideoContentType::SCREENSHARE) { |
| 3909 | expected_pacing_factor = 1.0f; // Currently used pacing factor in ALR. |
| 3910 | } |
| 3911 | |
| 3912 | EXPECT_NEAR(expected_pacing_factor, pacing_factor, 1e-6); |
| 3913 | |
| 3914 | // Wait until at least kMinPacketsToSend packets to be sent, so that |
| 3915 | // some frames would be encoded. |
| 3916 | if (++packets_sent_ < kMinPacketsToSend) |
| 3917 | return SEND_PACKET; |
| 3918 | |
| 3919 | if (state_ != StreamState::kAfterSwitchBack) { |
| 3920 | // We've sent kMinPacketsToSend packets, switch the content type and move |
| 3921 | // move to the next state. |
| 3922 | // Note that we need to recreate the stream if changing content type. |
| 3923 | packets_sent_ = 0; |
| 3924 | if (encoder_config_.content_type == |
| 3925 | VideoEncoderConfig::ContentType::kRealtimeVideo) { |
| 3926 | encoder_config_.content_type = VideoEncoderConfig::ContentType::kScreen; |
| 3927 | } else { |
| 3928 | encoder_config_.content_type = |
| 3929 | VideoEncoderConfig::ContentType::kRealtimeVideo; |
| 3930 | } |
| 3931 | switch (state_) { |
| 3932 | case StreamState::kBeforeSwitch: |
| 3933 | state_ = StreamState::kInScreenshare; |
| 3934 | break; |
| 3935 | case StreamState::kInScreenshare: |
| 3936 | state_ = StreamState::kAfterSwitchBack; |
| 3937 | break; |
| 3938 | case StreamState::kAfterSwitchBack: |
| 3939 | RTC_NOTREACHED(); |
| 3940 | break; |
| 3941 | } |
| 3942 | content_switch_event_.Set(); |
| 3943 | return SEND_PACKET; |
| 3944 | } |
| 3945 | |
| 3946 | observation_complete_.Set(); |
| 3947 | return SEND_PACKET; |
| 3948 | } |
| 3949 | |
| 3950 | void PerformTest() override { |
| 3951 | while (GetStreamState() != StreamState::kAfterSwitchBack) { |
| 3952 | ASSERT_TRUE( |
| 3953 | content_switch_event_.Wait(test::CallTest::kDefaultTimeoutMs)); |
| 3954 | (*stream_resetter_)(send_stream_config_, encoder_config_, this); |
| 3955 | } |
| 3956 | |
| 3957 | ASSERT_TRUE(Wait()) |
| 3958 | << "Timed out waiting for a frame sent after switch back"; |
| 3959 | } |
| 3960 | |
| 3961 | private: |
| 3962 | StreamState GetStreamState() { |
| 3963 | rtc::CritScope lock(&crit_); |
| 3964 | return state_; |
| 3965 | } |
| 3966 | |
| 3967 | rtc::CriticalSection crit_; |
| 3968 | rtc::Event content_switch_event_; |
| 3969 | Call* call_; |
| 3970 | StreamState state_ RTC_GUARDED_BY(crit_); |
| 3971 | VideoSendStream* send_stream_ RTC_GUARDED_BY(crit_); |
| 3972 | VideoSendStream::Config send_stream_config_; |
| 3973 | VideoEncoderConfig encoder_config_; |
| 3974 | uint32_t packets_sent_ RTC_GUARDED_BY(crit_); |
| 3975 | T* stream_resetter_; |
| 3976 | }; |
| 3977 | |
| 3978 | TEST_F(VideoSendStreamTest, SwitchesToScreenshareAndBack) { |
| 3979 | auto reset_fun = [this](const VideoSendStream::Config& send_stream_config, |
| 3980 | const VideoEncoderConfig& encoder_config, |
| 3981 | test::BaseTest* test) { |
| 3982 | task_queue_.SendTask([this, &send_stream_config, &encoder_config, &test]() { |
| 3983 | Stop(); |
Sebastian Jansson | f33905d | 2018-07-13 09:49:00 +0200 | [diff] [blame] | 3984 | DestroyVideoSendStreams(); |
| 3985 | SetVideoSendConfig(send_stream_config); |
| 3986 | SetVideoEncoderConfig(encoder_config); |
| 3987 | CreateVideoSendStreams(); |
| 3988 | SetVideoDegradation(DegradationPreference::MAINTAIN_RESOLUTION); |
| 3989 | test->OnVideoStreamsCreated(GetVideoSendStream(), video_receive_streams_); |
Ilya Nikolaevskiy | 4425b05 | 2018-03-15 11:42:00 +0100 | [diff] [blame] | 3990 | Start(); |
| 3991 | }); |
| 3992 | }; |
| 3993 | ContentSwitchTest<decltype(reset_fun)> test(&reset_fun); |
| 3994 | RunBaseTest(&test); |
| 3995 | } |
| 3996 | |
pbos@webrtc.org | 119a1cc | 2013-08-20 13:14:07 +0000 | [diff] [blame] | 3997 | } // namespace webrtc |