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