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