Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | */ |
| 10 | |
| 11 | #include <string> |
| 12 | |
| 13 | #include "call/test/mock_bitrate_allocator.h" |
| 14 | #include "call/test/mock_rtp_transport_controller_send.h" |
| 15 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 16 | #include "modules/video_coding/fec_controller_default.h" |
| 17 | #include "rtc_base/experiments/alr_experiment.h" |
| 18 | #include "rtc_base/task_queue_for_test.h" |
| 19 | #include "test/field_trial.h" |
| 20 | #include "test/gmock.h" |
| 21 | #include "test/gtest.h" |
| 22 | #include "test/mock_transport.h" |
| 23 | #include "video/test/mock_video_stream_encoder.h" |
| 24 | #include "video/video_send_stream_impl.h" |
| 25 | |
| 26 | namespace webrtc { |
| 27 | namespace internal { |
| 28 | namespace { |
| 29 | using testing::NiceMock; |
| 30 | using testing::StrictMock; |
| 31 | using testing::ReturnRef; |
| 32 | using testing::Return; |
| 33 | using testing::Invoke; |
| 34 | using testing::_; |
| 35 | |
| 36 | constexpr int64_t kDefaultInitialBitrateBps = 333000; |
| 37 | const double kDefaultBitratePriority = 0.5; |
| 38 | |
| 39 | const float kAlrProbingExperimentPaceMultiplier = 1.0f; |
| 40 | std::string GetAlrProbingExperimentString() { |
| 41 | return std::string( |
| 42 | AlrExperimentSettings::kScreenshareProbingBweExperimentName) + |
| 43 | "/1.0,2875,80,40,-60,3/"; |
| 44 | } |
| 45 | |
| 46 | } // namespace |
| 47 | |
| 48 | class VideoSendStreamImplTest : public ::testing::Test { |
| 49 | protected: |
| 50 | VideoSendStreamImplTest() |
| 51 | : clock_(1000 * 1000 * 1000), |
| 52 | config_(&transport_), |
| 53 | send_delay_stats_(&clock_), |
| 54 | retransmission_limiter_(&clock_, 1000), |
| 55 | test_queue_("test_queue"), |
| 56 | process_thread_(ProcessThread::Create("test_thread")), |
| 57 | call_stats_(&clock_, process_thread_.get()), |
| 58 | stats_proxy_(&clock_, |
| 59 | config_, |
| 60 | VideoEncoderConfig::ContentType::kRealtimeVideo) { |
| 61 | config_.rtp.ssrcs.push_back(8080); |
| 62 | config_.rtp.payload_type = 1; |
| 63 | |
| 64 | EXPECT_CALL(transport_controller_, keepalive_config()) |
| 65 | .WillRepeatedly(ReturnRef(keepalive_config_)); |
| 66 | EXPECT_CALL(transport_controller_, packet_router()) |
| 67 | .WillRepeatedly(Return(&packet_router_)); |
| 68 | } |
| 69 | ~VideoSendStreamImplTest() {} |
| 70 | |
| 71 | std::unique_ptr<VideoSendStreamImpl> CreateVideoSendStreamImpl( |
| 72 | int initial_encoder_max_bitrate, |
| 73 | double initial_encoder_bitrate_priority, |
| 74 | VideoEncoderConfig::ContentType content_type) { |
| 75 | EXPECT_CALL(bitrate_allocator_, GetStartBitrate(_)) |
| 76 | .WillOnce(Return(123000)); |
| 77 | std::map<uint32_t, RtpState> suspended_ssrcs; |
| 78 | std::map<uint32_t, RtpPayloadState> suspended_payload_states; |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 79 | return absl::make_unique<VideoSendStreamImpl>( |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 80 | &stats_proxy_, &test_queue_, &call_stats_, &transport_controller_, |
| 81 | &bitrate_allocator_, &send_delay_stats_, &video_stream_encoder_, |
| 82 | &event_log_, &config_, initial_encoder_max_bitrate, |
| 83 | initial_encoder_bitrate_priority, suspended_ssrcs, |
| 84 | suspended_payload_states, content_type, |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 85 | absl::make_unique<FecControllerDefault>(&clock_), |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 86 | &retransmission_limiter_); |
| 87 | } |
| 88 | |
| 89 | protected: |
| 90 | NiceMock<MockTransport> transport_; |
| 91 | NiceMock<MockRtpTransportControllerSend> transport_controller_; |
| 92 | NiceMock<MockBitrateAllocator> bitrate_allocator_; |
| 93 | NiceMock<MockVideoStreamEncoder> video_stream_encoder_; |
| 94 | |
| 95 | SimulatedClock clock_; |
| 96 | RtcEventLogNullImpl event_log_; |
| 97 | VideoSendStream::Config config_; |
| 98 | SendDelayStats send_delay_stats_; |
| 99 | RateLimiter retransmission_limiter_; |
| 100 | rtc::test::TaskQueueForTest test_queue_; |
| 101 | std::unique_ptr<ProcessThread> process_thread_; |
| 102 | CallStats call_stats_; |
| 103 | SendStatisticsProxy stats_proxy_; |
| 104 | PacketRouter packet_router_; |
| 105 | RtpKeepAliveConfig keepalive_config_; |
| 106 | }; |
| 107 | |
| 108 | TEST_F(VideoSendStreamImplTest, RegistersAsBitrateObserverOnStart) { |
| 109 | test_queue_.SendTask([this] { |
| 110 | config_.track_id = "test"; |
| 111 | const bool kSuspend = false; |
| 112 | config_.suspend_below_min_bitrate = kSuspend; |
| 113 | auto vss_impl = CreateVideoSendStreamImpl( |
| 114 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 115 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 116 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 117 | .WillOnce(Invoke( |
| 118 | [&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) { |
| 119 | EXPECT_EQ(config.min_bitrate_bps, 0u); |
| 120 | EXPECT_EQ(config.max_bitrate_bps, kDefaultInitialBitrateBps); |
| 121 | EXPECT_EQ(config.pad_up_bitrate_bps, 0u); |
| 122 | EXPECT_EQ(config.enforce_min_bitrate, !kSuspend); |
| 123 | EXPECT_EQ(config.track_id, "test"); |
| 124 | EXPECT_EQ(config.bitrate_priority, kDefaultBitratePriority); |
| 125 | EXPECT_EQ(config.has_packet_feedback, false); |
| 126 | })); |
| 127 | vss_impl->Start(); |
| 128 | EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())).Times(1); |
| 129 | vss_impl->Stop(); |
| 130 | }); |
| 131 | } |
| 132 | |
| 133 | TEST_F(VideoSendStreamImplTest, ReportFeedbackAvailability) { |
| 134 | test_queue_.SendTask([this] { |
| 135 | config_.rtp.extensions.emplace_back( |
| 136 | RtpExtension::kTransportSequenceNumberUri, |
| 137 | RtpExtension::kTransportSequenceNumberDefaultId); |
| 138 | |
| 139 | auto vss_impl = CreateVideoSendStreamImpl( |
| 140 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 141 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 142 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 143 | .WillOnce(Invoke( |
| 144 | [&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) { |
| 145 | EXPECT_EQ(config.has_packet_feedback, true); |
| 146 | })); |
| 147 | vss_impl->Start(); |
| 148 | EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())).Times(1); |
| 149 | vss_impl->Stop(); |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) { |
| 154 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
| 155 | |
| 156 | test_queue_.SendTask([this] { |
| 157 | config_.rtp.extensions.emplace_back( |
| 158 | RtpExtension::kTransportSequenceNumberUri, |
| 159 | RtpExtension::kTransportSequenceNumberDefaultId); |
| 160 | EXPECT_CALL(transport_controller_, |
| 161 | SetPacingFactor(kAlrProbingExperimentPaceMultiplier)) |
| 162 | .Times(1); |
| 163 | auto vss_impl = CreateVideoSendStreamImpl( |
| 164 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 165 | VideoEncoderConfig::ContentType::kScreen); |
| 166 | vss_impl->Start(); |
| 167 | vss_impl->Stop(); |
| 168 | }); |
| 169 | } |
| 170 | |
| 171 | TEST_F(VideoSendStreamImplTest, DoesNotSetPacingFactorWithoutFeedback) { |
| 172 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
| 173 | test_queue_.SendTask([this] { |
| 174 | EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0); |
| 175 | auto vss_impl = CreateVideoSendStreamImpl( |
| 176 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 177 | VideoEncoderConfig::ContentType::kScreen); |
| 178 | vss_impl->Start(); |
| 179 | vss_impl->Stop(); |
| 180 | }); |
| 181 | } |
| 182 | } // namespace internal |
| 183 | } // namespace webrtc |