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