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