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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "video/video_send_stream_impl.h" |
| 12 | |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 13 | #include <memory> |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 14 | #include <string> |
| 15 | |
Elad Alon | 8b60e8b | 2019-04-08 14:14:05 +0200 | [diff] [blame] | 16 | #include "absl/types/optional.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 17 | #include "api/rtc_event_log/rtc_event_log.h" |
Stefan Holmer | 9416ef8 | 2018-07-19 10:34:38 +0200 | [diff] [blame] | 18 | #include "call/rtp_video_sender.h" |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 19 | #include "call/test/mock_bitrate_allocator.h" |
| 20 | #include "call/test/mock_rtp_transport_controller_send.h" |
Elad Alon | 8b60e8b | 2019-04-08 14:14:05 +0200 | [diff] [blame] | 21 | #include "modules/rtp_rtcp/source/rtp_sequence_number_map.h" |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 22 | #include "modules/utility/include/process_thread.h" |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 23 | #include "modules/video_coding/fec_controller_default.h" |
| 24 | #include "rtc_base/experiments/alr_experiment.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "rtc_base/fake_clock.h" |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 26 | #include "rtc_base/task_queue_for_test.h" |
| 27 | #include "test/field_trial.h" |
| 28 | #include "test/gmock.h" |
| 29 | #include "test/gtest.h" |
| 30 | #include "test/mock_transport.h" |
| 31 | #include "video/test/mock_video_stream_encoder.h" |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 32 | |
| 33 | namespace webrtc { |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 34 | |
| 35 | bool operator==(const BitrateAllocationUpdate& a, |
| 36 | const BitrateAllocationUpdate& b) { |
| 37 | return a.target_bitrate == b.target_bitrate && |
| 38 | a.round_trip_time == b.round_trip_time && |
| 39 | a.packet_loss_ratio == b.packet_loss_ratio; |
| 40 | } |
| 41 | |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 42 | namespace internal { |
| 43 | namespace { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 44 | using ::testing::_; |
| 45 | using ::testing::Invoke; |
| 46 | using ::testing::NiceMock; |
| 47 | using ::testing::Return; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 48 | |
| 49 | constexpr int64_t kDefaultInitialBitrateBps = 333000; |
| 50 | const double kDefaultBitratePriority = 0.5; |
| 51 | |
| 52 | const float kAlrProbingExperimentPaceMultiplier = 1.0f; |
| 53 | std::string GetAlrProbingExperimentString() { |
| 54 | return std::string( |
| 55 | AlrExperimentSettings::kScreenshareProbingBweExperimentName) + |
| 56 | "/1.0,2875,80,40,-60,3/"; |
| 57 | } |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 58 | class MockRtpVideoSender : public RtpVideoSenderInterface { |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 59 | public: |
| 60 | MOCK_METHOD1(RegisterProcessThread, void(ProcessThread*)); |
| 61 | MOCK_METHOD0(DeRegisterProcessThread, void()); |
| 62 | MOCK_METHOD1(SetActive, void(bool)); |
| 63 | MOCK_METHOD1(SetActiveModules, void(const std::vector<bool>)); |
| 64 | MOCK_METHOD0(IsActive, bool()); |
| 65 | MOCK_METHOD1(OnNetworkAvailability, void(bool)); |
| 66 | MOCK_CONST_METHOD0(GetRtpStates, std::map<uint32_t, RtpState>()); |
| 67 | MOCK_CONST_METHOD0(GetRtpPayloadStates, |
| 68 | std::map<uint32_t, RtpPayloadState>()); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 69 | MOCK_METHOD2(DeliverRtcp, void(const uint8_t*, size_t)); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 70 | MOCK_METHOD1(OnBitrateAllocationUpdated, void(const VideoBitrateAllocation&)); |
| 71 | MOCK_METHOD3(OnEncodedImage, |
| 72 | EncodedImageCallback::Result(const EncodedImage&, |
| 73 | const CodecSpecificInfo*, |
| 74 | const RTPFragmentationHeader*)); |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 75 | MOCK_METHOD1(OnTransportOverheadChanged, void(size_t)); |
| 76 | MOCK_METHOD1(OnOverheadChanged, void(size_t)); |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 77 | MOCK_METHOD2(OnBitrateUpdated, void(BitrateAllocationUpdate, int)); |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 78 | MOCK_CONST_METHOD0(GetPayloadBitrateBps, uint32_t()); |
| 79 | MOCK_CONST_METHOD0(GetProtectionBitrateBps, uint32_t()); |
| 80 | MOCK_METHOD3(SetEncodingData, void(size_t, size_t, size_t)); |
Elad Alon | 898395d | 2019-04-10 15:55:00 +0200 | [diff] [blame] | 81 | MOCK_CONST_METHOD2(GetSentRtpPacketInfos, |
| 82 | std::vector<RtpSequenceNumberMap::Info>( |
| 83 | uint32_t ssrc, |
| 84 | rtc::ArrayView<const uint16_t> sequence_numbers)); |
Elad Alon | 8f01c4e | 2019-06-28 15:19:43 +0200 | [diff] [blame] | 85 | |
| 86 | MOCK_METHOD1(SetFecAllowed, void(bool fec_allowed)); |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 87 | }; |
Sebastian Jansson | c0e4d45 | 2018-10-25 15:08:32 +0200 | [diff] [blame] | 88 | |
| 89 | BitrateAllocationUpdate CreateAllocation(int bitrate_bps) { |
| 90 | BitrateAllocationUpdate update; |
Sebastian Jansson | 13e5903 | 2018-11-21 19:13:07 +0100 | [diff] [blame] | 91 | update.target_bitrate = DataRate::bps(bitrate_bps); |
| 92 | update.packet_loss_ratio = 0; |
| 93 | update.round_trip_time = TimeDelta::Zero(); |
Sebastian Jansson | c0e4d45 | 2018-10-25 15:08:32 +0200 | [diff] [blame] | 94 | return update; |
| 95 | } |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 96 | } // namespace |
| 97 | |
| 98 | class VideoSendStreamImplTest : public ::testing::Test { |
| 99 | protected: |
| 100 | VideoSendStreamImplTest() |
| 101 | : clock_(1000 * 1000 * 1000), |
| 102 | config_(&transport_), |
| 103 | send_delay_stats_(&clock_), |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 104 | test_queue_("test_queue"), |
| 105 | process_thread_(ProcessThread::Create("test_thread")), |
| 106 | call_stats_(&clock_, process_thread_.get()), |
| 107 | stats_proxy_(&clock_, |
| 108 | config_, |
| 109 | VideoEncoderConfig::ContentType::kRealtimeVideo) { |
| 110 | config_.rtp.ssrcs.push_back(8080); |
| 111 | config_.rtp.payload_type = 1; |
| 112 | |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 113 | EXPECT_CALL(transport_controller_, packet_router()) |
| 114 | .WillRepeatedly(Return(&packet_router_)); |
Elad Alon | 8f01c4e | 2019-06-28 15:19:43 +0200 | [diff] [blame] | 115 | EXPECT_CALL(transport_controller_, CreateRtpVideoSender) |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 116 | .WillRepeatedly(Return(&rtp_video_sender_)); |
| 117 | EXPECT_CALL(rtp_video_sender_, SetActive(_)) |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 118 | .WillRepeatedly(::testing::Invoke( |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 119 | [&](bool active) { rtp_video_sender_active_ = active; })); |
| 120 | EXPECT_CALL(rtp_video_sender_, IsActive()) |
Stefan Holmer | dbdb3a0 | 2018-07-17 16:03:46 +0200 | [diff] [blame] | 121 | .WillRepeatedly( |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 122 | ::testing::Invoke([&]() { return rtp_video_sender_active_; })); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 123 | } |
| 124 | ~VideoSendStreamImplTest() {} |
| 125 | |
| 126 | std::unique_ptr<VideoSendStreamImpl> CreateVideoSendStreamImpl( |
| 127 | int initial_encoder_max_bitrate, |
| 128 | double initial_encoder_bitrate_priority, |
| 129 | VideoEncoderConfig::ContentType content_type) { |
| 130 | EXPECT_CALL(bitrate_allocator_, GetStartBitrate(_)) |
| 131 | .WillOnce(Return(123000)); |
| 132 | std::map<uint32_t, RtpState> suspended_ssrcs; |
| 133 | std::map<uint32_t, RtpPayloadState> suspended_payload_states; |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 134 | return std::make_unique<VideoSendStreamImpl>( |
Sebastian Jansson | 572c60f | 2019-03-04 18:30:41 +0100 | [diff] [blame] | 135 | &clock_, &stats_proxy_, &test_queue_, &call_stats_, |
| 136 | &transport_controller_, &bitrate_allocator_, &send_delay_stats_, |
| 137 | &video_stream_encoder_, &event_log_, &config_, |
| 138 | initial_encoder_max_bitrate, initial_encoder_bitrate_priority, |
| 139 | suspended_ssrcs, suspended_payload_states, content_type, |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 140 | std::make_unique<FecControllerDefault>(&clock_)); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | protected: |
| 144 | NiceMock<MockTransport> transport_; |
| 145 | NiceMock<MockRtpTransportControllerSend> transport_controller_; |
| 146 | NiceMock<MockBitrateAllocator> bitrate_allocator_; |
| 147 | NiceMock<MockVideoStreamEncoder> video_stream_encoder_; |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 148 | NiceMock<MockRtpVideoSender> rtp_video_sender_; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 149 | |
Stefan Holmer | 64be7fa | 2018-10-04 15:21:55 +0200 | [diff] [blame] | 150 | bool rtp_video_sender_active_ = false; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 151 | SimulatedClock clock_; |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 152 | RtcEventLogNull event_log_; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 153 | VideoSendStream::Config config_; |
| 154 | SendDelayStats send_delay_stats_; |
Danil Chapovalov | d26a916 | 2019-03-19 18:08:37 +0100 | [diff] [blame] | 155 | TaskQueueForTest test_queue_; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 156 | std::unique_ptr<ProcessThread> process_thread_; |
| 157 | CallStats call_stats_; |
| 158 | SendStatisticsProxy stats_proxy_; |
| 159 | PacketRouter packet_router_; |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | TEST_F(VideoSendStreamImplTest, RegistersAsBitrateObserverOnStart) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 163 | test_queue_.SendTask( |
| 164 | [this] { |
| 165 | const bool kSuspend = false; |
| 166 | config_.suspend_below_min_bitrate = kSuspend; |
| 167 | auto vss_impl = CreateVideoSendStreamImpl( |
| 168 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 169 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 170 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 171 | .WillOnce(Invoke([&](BitrateAllocatorObserver*, |
| 172 | MediaStreamAllocationConfig config) { |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 173 | EXPECT_EQ(config.min_bitrate_bps, 0u); |
| 174 | EXPECT_EQ(config.max_bitrate_bps, kDefaultInitialBitrateBps); |
| 175 | EXPECT_EQ(config.pad_up_bitrate_bps, 0u); |
| 176 | EXPECT_EQ(config.enforce_min_bitrate, !kSuspend); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 177 | EXPECT_EQ(config.bitrate_priority, kDefaultBitratePriority); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 178 | })); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 179 | vss_impl->Start(); |
| 180 | EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())) |
| 181 | .Times(1); |
| 182 | vss_impl->Stop(); |
| 183 | }, |
| 184 | RTC_FROM_HERE); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 187 | TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChange) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 188 | test_queue_.SendTask( |
| 189 | [this] { |
| 190 | const bool kSuspend = false; |
| 191 | config_.suspend_below_min_bitrate = kSuspend; |
| 192 | config_.rtp.extensions.emplace_back( |
| 193 | RtpExtension::kTransportSequenceNumberUri, 1); |
| 194 | auto vss_impl = CreateVideoSendStreamImpl( |
| 195 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 196 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 197 | vss_impl->Start(); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 198 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 199 | // QVGA + VGA configuration matching defaults in |
| 200 | // media/engine/simulcast.cc. |
| 201 | VideoStream qvga_stream; |
| 202 | qvga_stream.width = 320; |
| 203 | qvga_stream.height = 180; |
| 204 | qvga_stream.max_framerate = 30; |
| 205 | qvga_stream.min_bitrate_bps = 30000; |
| 206 | qvga_stream.target_bitrate_bps = 150000; |
| 207 | qvga_stream.max_bitrate_bps = 200000; |
| 208 | qvga_stream.max_qp = 56; |
| 209 | qvga_stream.bitrate_priority = 1; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 210 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 211 | VideoStream vga_stream; |
| 212 | vga_stream.width = 640; |
| 213 | vga_stream.height = 360; |
| 214 | vga_stream.max_framerate = 30; |
| 215 | vga_stream.min_bitrate_bps = 150000; |
| 216 | vga_stream.target_bitrate_bps = 500000; |
| 217 | vga_stream.max_bitrate_bps = 700000; |
| 218 | vga_stream.max_qp = 56; |
| 219 | vga_stream.bitrate_priority = 1; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 220 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 221 | int min_transmit_bitrate_bps = 30000; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 222 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 223 | config_.rtp.ssrcs.emplace_back(1); |
| 224 | config_.rtp.ssrcs.emplace_back(2); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 225 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 226 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 227 | .WillRepeatedly(Invoke([&](BitrateAllocatorObserver*, |
| 228 | MediaStreamAllocationConfig config) { |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 229 | EXPECT_EQ(config.min_bitrate_bps, |
| 230 | static_cast<uint32_t>(min_transmit_bitrate_bps)); |
| 231 | EXPECT_EQ(config.max_bitrate_bps, |
| 232 | static_cast<uint32_t>(qvga_stream.max_bitrate_bps + |
| 233 | vga_stream.max_bitrate_bps)); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 234 | if (config.pad_up_bitrate_bps != 0) { |
| 235 | EXPECT_EQ(config.pad_up_bitrate_bps, |
| 236 | static_cast<uint32_t>(qvga_stream.target_bitrate_bps + |
| 237 | vga_stream.min_bitrate_bps)); |
| 238 | } |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 239 | EXPECT_EQ(config.enforce_min_bitrate, !kSuspend); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 240 | })); |
| 241 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 242 | static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get()) |
| 243 | ->OnEncoderConfigurationChanged( |
| 244 | std::vector<VideoStream>{qvga_stream, vga_stream}, |
| 245 | VideoEncoderConfig::ContentType::kRealtimeVideo, |
| 246 | min_transmit_bitrate_bps); |
| 247 | vss_impl->Stop(); |
| 248 | }, |
| 249 | RTC_FROM_HERE); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 253 | test_queue_.SendTask( |
| 254 | [this] { |
| 255 | const bool kSuspend = false; |
| 256 | config_.suspend_below_min_bitrate = kSuspend; |
| 257 | config_.rtp.extensions.emplace_back( |
| 258 | RtpExtension::kTransportSequenceNumberUri, 1); |
| 259 | config_.periodic_alr_bandwidth_probing = true; |
| 260 | auto vss_impl = CreateVideoSendStreamImpl( |
| 261 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 262 | VideoEncoderConfig::ContentType::kScreen); |
| 263 | vss_impl->Start(); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 264 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 265 | // Simulcast screenshare. |
| 266 | VideoStream low_stream; |
| 267 | low_stream.width = 1920; |
| 268 | low_stream.height = 1080; |
| 269 | low_stream.max_framerate = 5; |
| 270 | low_stream.min_bitrate_bps = 30000; |
| 271 | low_stream.target_bitrate_bps = 200000; |
| 272 | low_stream.max_bitrate_bps = 1000000; |
| 273 | low_stream.num_temporal_layers = 2; |
| 274 | low_stream.max_qp = 56; |
| 275 | low_stream.bitrate_priority = 1; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 276 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 277 | VideoStream high_stream; |
| 278 | high_stream.width = 1920; |
| 279 | high_stream.height = 1080; |
| 280 | high_stream.max_framerate = 30; |
| 281 | high_stream.min_bitrate_bps = 60000; |
| 282 | high_stream.target_bitrate_bps = 1250000; |
| 283 | high_stream.max_bitrate_bps = 1250000; |
| 284 | high_stream.num_temporal_layers = 2; |
| 285 | high_stream.max_qp = 56; |
| 286 | high_stream.bitrate_priority = 1; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 287 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 288 | // With ALR probing, this will be the padding target instead of |
| 289 | // low_stream.target_bitrate_bps + high_stream.min_bitrate_bps. |
| 290 | int min_transmit_bitrate_bps = 400000; |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 291 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 292 | config_.rtp.ssrcs.emplace_back(1); |
| 293 | config_.rtp.ssrcs.emplace_back(2); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 294 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 295 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 296 | .WillRepeatedly(Invoke([&](BitrateAllocatorObserver*, |
| 297 | MediaStreamAllocationConfig config) { |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 298 | EXPECT_EQ(config.min_bitrate_bps, |
| 299 | static_cast<uint32_t>(low_stream.min_bitrate_bps)); |
| 300 | EXPECT_EQ(config.max_bitrate_bps, |
| 301 | static_cast<uint32_t>(low_stream.max_bitrate_bps + |
| 302 | high_stream.max_bitrate_bps)); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 303 | if (config.pad_up_bitrate_bps != 0) { |
| 304 | EXPECT_EQ(config.pad_up_bitrate_bps, |
| 305 | static_cast<uint32_t>(min_transmit_bitrate_bps)); |
| 306 | } |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 307 | EXPECT_EQ(config.enforce_min_bitrate, !kSuspend); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 308 | })); |
| 309 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 310 | static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get()) |
| 311 | ->OnEncoderConfigurationChanged( |
| 312 | std::vector<VideoStream>{low_stream, high_stream}, |
| 313 | VideoEncoderConfig::ContentType::kScreen, |
| 314 | min_transmit_bitrate_bps); |
| 315 | vss_impl->Stop(); |
| 316 | }, |
| 317 | RTC_FROM_HERE); |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | TEST_F(VideoSendStreamImplTest, |
| 321 | UpdatesObserverOnConfigurationChangeWithSimulcastVideoHysteresis) { |
| 322 | test::ScopedFieldTrials hysteresis_experiment( |
| 323 | "WebRTC-VideoRateControl/video_hysteresis:1.25/"); |
| 324 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 325 | test_queue_.SendTask( |
| 326 | [this] { |
| 327 | auto vss_impl = CreateVideoSendStreamImpl( |
| 328 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 329 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 330 | vss_impl->Start(); |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 331 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 332 | // 2-layer video simulcast. |
| 333 | VideoStream low_stream; |
| 334 | low_stream.width = 320; |
| 335 | low_stream.height = 240; |
| 336 | low_stream.max_framerate = 30; |
| 337 | low_stream.min_bitrate_bps = 30000; |
| 338 | low_stream.target_bitrate_bps = 100000; |
| 339 | low_stream.max_bitrate_bps = 200000; |
| 340 | low_stream.max_qp = 56; |
| 341 | low_stream.bitrate_priority = 1; |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 342 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 343 | VideoStream high_stream; |
| 344 | high_stream.width = 640; |
| 345 | high_stream.height = 480; |
| 346 | high_stream.max_framerate = 30; |
| 347 | high_stream.min_bitrate_bps = 150000; |
| 348 | high_stream.target_bitrate_bps = 500000; |
| 349 | high_stream.max_bitrate_bps = 750000; |
| 350 | high_stream.max_qp = 56; |
| 351 | high_stream.bitrate_priority = 1; |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 352 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 353 | config_.rtp.ssrcs.emplace_back(1); |
| 354 | config_.rtp.ssrcs.emplace_back(2); |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 355 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 356 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 357 | .WillRepeatedly(Invoke([&](BitrateAllocatorObserver*, |
| 358 | MediaStreamAllocationConfig config) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 359 | EXPECT_EQ(config.min_bitrate_bps, |
| 360 | static_cast<uint32_t>(low_stream.min_bitrate_bps)); |
| 361 | EXPECT_EQ(config.max_bitrate_bps, |
| 362 | static_cast<uint32_t>(low_stream.max_bitrate_bps + |
| 363 | high_stream.max_bitrate_bps)); |
| 364 | if (config.pad_up_bitrate_bps != 0) { |
| 365 | EXPECT_EQ( |
| 366 | config.pad_up_bitrate_bps, |
| 367 | static_cast<uint32_t>(low_stream.target_bitrate_bps + |
| 368 | 1.25 * high_stream.min_bitrate_bps)); |
| 369 | } |
| 370 | })); |
Rasmus Brandt | c402dbe | 2019-02-04 11:09:46 +0100 | [diff] [blame] | 371 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 372 | static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get()) |
| 373 | ->OnEncoderConfigurationChanged( |
| 374 | std::vector<VideoStream>{low_stream, high_stream}, |
| 375 | VideoEncoderConfig::ContentType::kRealtimeVideo, |
| 376 | /*min_transmit_bitrate_bps=*/0); |
| 377 | vss_impl->Stop(); |
| 378 | }, |
| 379 | RTC_FROM_HERE); |
Erik Språng | b57ab38 | 2018-09-13 10:52:38 +0200 | [diff] [blame] | 380 | } |
| 381 | |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 382 | TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) { |
| 383 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
| 384 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 385 | test_queue_.SendTask( |
| 386 | [this] { |
| 387 | constexpr int kId = 1; |
| 388 | config_.rtp.extensions.emplace_back( |
| 389 | RtpExtension::kTransportSequenceNumberUri, kId); |
| 390 | EXPECT_CALL(transport_controller_, |
| 391 | SetPacingFactor(kAlrProbingExperimentPaceMultiplier)) |
| 392 | .Times(1); |
| 393 | auto vss_impl = CreateVideoSendStreamImpl( |
| 394 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 395 | VideoEncoderConfig::ContentType::kScreen); |
| 396 | vss_impl->Start(); |
| 397 | vss_impl->Stop(); |
| 398 | }, |
| 399 | RTC_FROM_HERE); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | TEST_F(VideoSendStreamImplTest, DoesNotSetPacingFactorWithoutFeedback) { |
| 403 | test::ScopedFieldTrials alr_experiment(GetAlrProbingExperimentString()); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 404 | test_queue_.SendTask( |
| 405 | [this] { |
| 406 | EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0); |
| 407 | auto vss_impl = CreateVideoSendStreamImpl( |
| 408 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 409 | VideoEncoderConfig::ContentType::kScreen); |
| 410 | vss_impl->Start(); |
| 411 | vss_impl->Stop(); |
| 412 | }, |
| 413 | RTC_FROM_HERE); |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 414 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 415 | |
| 416 | TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationWhenEnabled) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 417 | test_queue_.SendTask( |
| 418 | [this] { |
| 419 | EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0); |
| 420 | auto vss_impl = CreateVideoSendStreamImpl( |
| 421 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 422 | VideoEncoderConfig::ContentType::kScreen); |
| 423 | vss_impl->Start(); |
| 424 | VideoBitrateAllocationObserver* const observer = |
| 425 | static_cast<VideoBitrateAllocationObserver*>(vss_impl.get()); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 426 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 427 | // Populate a test instance of video bitrate allocation. |
| 428 | VideoBitrateAllocation alloc; |
| 429 | alloc.SetBitrate(0, 0, 10000); |
| 430 | alloc.SetBitrate(0, 1, 20000); |
| 431 | alloc.SetBitrate(1, 0, 30000); |
| 432 | alloc.SetBitrate(1, 1, 40000); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 433 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 434 | // Encoder starts out paused, don't forward allocation. |
| 435 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 436 | .Times(0); |
| 437 | observer->OnBitrateAllocationUpdated(alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 438 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 439 | // Unpause encoder, allocation should be passed through. |
| 440 | const uint32_t kBitrateBps = 100000; |
| 441 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 442 | .Times(1) |
| 443 | .WillOnce(Return(kBitrateBps)); |
| 444 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 445 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
| 446 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 447 | .Times(1); |
| 448 | observer->OnBitrateAllocationUpdated(alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 449 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 450 | // Pause encoder again, and block allocations. |
| 451 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 452 | .Times(1) |
| 453 | .WillOnce(Return(0)); |
| 454 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 455 | ->OnBitrateUpdated(CreateAllocation(0)); |
| 456 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 457 | .Times(0); |
| 458 | observer->OnBitrateAllocationUpdated(alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 459 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 460 | vss_impl->Stop(); |
| 461 | }, |
| 462 | RTC_FROM_HERE); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | TEST_F(VideoSendStreamImplTest, ThrottlesVideoBitrateAllocationWhenTooSimilar) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 466 | test_queue_.SendTask( |
| 467 | [this] { |
| 468 | auto vss_impl = CreateVideoSendStreamImpl( |
| 469 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 470 | VideoEncoderConfig::ContentType::kScreen); |
| 471 | vss_impl->Start(); |
| 472 | // Unpause encoder, to allows allocations to be passed through. |
| 473 | const uint32_t kBitrateBps = 100000; |
| 474 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 475 | .Times(1) |
| 476 | .WillOnce(Return(kBitrateBps)); |
| 477 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 478 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
| 479 | VideoBitrateAllocationObserver* const observer = |
| 480 | static_cast<VideoBitrateAllocationObserver*>(vss_impl.get()); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 481 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 482 | // Populate a test instance of video bitrate allocation. |
| 483 | VideoBitrateAllocation alloc; |
| 484 | alloc.SetBitrate(0, 0, 10000); |
| 485 | alloc.SetBitrate(0, 1, 20000); |
| 486 | alloc.SetBitrate(1, 0, 30000); |
| 487 | alloc.SetBitrate(1, 1, 40000); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 488 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 489 | // Initial value. |
| 490 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 491 | .Times(1); |
| 492 | observer->OnBitrateAllocationUpdated(alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 493 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 494 | VideoBitrateAllocation updated_alloc = alloc; |
| 495 | // Needs 10% increase in bitrate to trigger immediate forward. |
| 496 | const uint32_t base_layer_min_update_bitrate_bps = |
| 497 | alloc.GetBitrate(0, 0) + alloc.get_sum_bps() / 10; |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 498 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 499 | // Too small increase, don't forward. |
| 500 | updated_alloc.SetBitrate(0, 0, base_layer_min_update_bitrate_bps - 1); |
| 501 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(_)).Times(0); |
| 502 | observer->OnBitrateAllocationUpdated(updated_alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 503 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 504 | // Large enough increase, do forward. |
| 505 | updated_alloc.SetBitrate(0, 0, base_layer_min_update_bitrate_bps); |
| 506 | EXPECT_CALL(rtp_video_sender_, |
| 507 | OnBitrateAllocationUpdated(updated_alloc)) |
| 508 | .Times(1); |
| 509 | observer->OnBitrateAllocationUpdated(updated_alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 510 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 511 | // This is now a decrease compared to last forward allocation, forward |
| 512 | // immediately. |
| 513 | updated_alloc.SetBitrate(0, 0, base_layer_min_update_bitrate_bps - 1); |
| 514 | EXPECT_CALL(rtp_video_sender_, |
| 515 | OnBitrateAllocationUpdated(updated_alloc)) |
| 516 | .Times(1); |
| 517 | observer->OnBitrateAllocationUpdated(updated_alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 518 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 519 | vss_impl->Stop(); |
| 520 | }, |
| 521 | RTC_FROM_HERE); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationOnLayerChange) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 525 | test_queue_.SendTask( |
| 526 | [this] { |
| 527 | auto vss_impl = CreateVideoSendStreamImpl( |
| 528 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 529 | VideoEncoderConfig::ContentType::kScreen); |
| 530 | vss_impl->Start(); |
| 531 | // Unpause encoder, to allows allocations to be passed through. |
| 532 | const uint32_t kBitrateBps = 100000; |
| 533 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 534 | .Times(1) |
| 535 | .WillOnce(Return(kBitrateBps)); |
| 536 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 537 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
| 538 | VideoBitrateAllocationObserver* const observer = |
| 539 | static_cast<VideoBitrateAllocationObserver*>(vss_impl.get()); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 540 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 541 | // Populate a test instance of video bitrate allocation. |
| 542 | VideoBitrateAllocation alloc; |
| 543 | alloc.SetBitrate(0, 0, 10000); |
| 544 | alloc.SetBitrate(0, 1, 20000); |
| 545 | alloc.SetBitrate(1, 0, 30000); |
| 546 | alloc.SetBitrate(1, 1, 40000); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 547 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 548 | // Initial value. |
| 549 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 550 | .Times(1); |
| 551 | observer->OnBitrateAllocationUpdated(alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 552 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 553 | // Move some bitrate from one layer to a new one, but keep sum the same. |
| 554 | // Since layout has changed, immediately trigger forward. |
| 555 | VideoBitrateAllocation updated_alloc = alloc; |
| 556 | updated_alloc.SetBitrate(2, 0, 10000); |
| 557 | updated_alloc.SetBitrate(1, 1, alloc.GetBitrate(1, 1) - 10000); |
| 558 | EXPECT_EQ(alloc.get_sum_bps(), updated_alloc.get_sum_bps()); |
| 559 | EXPECT_CALL(rtp_video_sender_, |
| 560 | OnBitrateAllocationUpdated(updated_alloc)) |
| 561 | .Times(1); |
| 562 | observer->OnBitrateAllocationUpdated(updated_alloc); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 563 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 564 | vss_impl->Stop(); |
| 565 | }, |
| 566 | RTC_FROM_HERE); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationAfterTimeout) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 570 | test_queue_.SendTask( |
| 571 | [this] { |
| 572 | auto vss_impl = CreateVideoSendStreamImpl( |
| 573 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 574 | VideoEncoderConfig::ContentType::kScreen); |
| 575 | vss_impl->Start(); |
| 576 | const uint32_t kBitrateBps = 100000; |
| 577 | // Unpause encoder, to allows allocations to be passed through. |
| 578 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 579 | .Times(1) |
| 580 | .WillRepeatedly(Return(kBitrateBps)); |
| 581 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 582 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
| 583 | VideoBitrateAllocationObserver* const observer = |
| 584 | static_cast<VideoBitrateAllocationObserver*>(vss_impl.get()); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 585 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 586 | // Populate a test instance of video bitrate allocation. |
| 587 | VideoBitrateAllocation alloc; |
| 588 | alloc.SetBitrate(0, 0, 10000); |
| 589 | alloc.SetBitrate(0, 1, 20000); |
| 590 | alloc.SetBitrate(1, 0, 30000); |
| 591 | alloc.SetBitrate(1, 1, 40000); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 592 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 593 | EncodedImage encoded_image; |
| 594 | CodecSpecificInfo codec_specific; |
| 595 | EXPECT_CALL(rtp_video_sender_, OnEncodedImage(_, _, _)) |
| 596 | .WillRepeatedly(Return(EncodedImageCallback::Result( |
| 597 | EncodedImageCallback::Result::OK))); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 598 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 599 | // Max time we will throttle similar video bitrate allocations. |
| 600 | static constexpr int64_t kMaxVbaThrottleTimeMs = 500; |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 601 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 602 | { |
| 603 | // Initial value. |
| 604 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 605 | .Times(1); |
| 606 | observer->OnBitrateAllocationUpdated(alloc); |
| 607 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 608 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 609 | { |
| 610 | // Sending same allocation again, this one should be throttled. |
| 611 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 612 | .Times(0); |
| 613 | observer->OnBitrateAllocationUpdated(alloc); |
| 614 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 615 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 616 | clock_.AdvanceTimeMicroseconds(kMaxVbaThrottleTimeMs * 1000); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 617 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 618 | { |
| 619 | // Sending similar allocation again after timeout, should forward. |
| 620 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 621 | .Times(1); |
| 622 | observer->OnBitrateAllocationUpdated(alloc); |
| 623 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 624 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 625 | { |
| 626 | // Sending similar allocation again without timeout, throttle. |
| 627 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 628 | .Times(0); |
| 629 | observer->OnBitrateAllocationUpdated(alloc); |
| 630 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 631 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 632 | { |
| 633 | // Send encoded image, should be a noop. |
| 634 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 635 | .Times(0); |
| 636 | static_cast<EncodedImageCallback*>(vss_impl.get()) |
| 637 | ->OnEncodedImage(encoded_image, &codec_specific, nullptr); |
| 638 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 639 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 640 | { |
| 641 | // Advance time and send encoded image, this should wake up and send |
| 642 | // cached bitrate allocation. |
| 643 | clock_.AdvanceTimeMicroseconds(kMaxVbaThrottleTimeMs * 1000); |
| 644 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 645 | .Times(1); |
| 646 | static_cast<EncodedImageCallback*>(vss_impl.get()) |
| 647 | ->OnEncodedImage(encoded_image, &codec_specific, nullptr); |
| 648 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 649 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 650 | { |
| 651 | // Advance time and send encoded image, there should be no cached |
| 652 | // allocation to send. |
| 653 | clock_.AdvanceTimeMicroseconds(kMaxVbaThrottleTimeMs * 1000); |
| 654 | EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)) |
| 655 | .Times(0); |
| 656 | static_cast<EncodedImageCallback*>(vss_impl.get()) |
| 657 | ->OnEncodedImage(encoded_image, &codec_specific, nullptr); |
| 658 | } |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 659 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 660 | vss_impl->Stop(); |
| 661 | }, |
| 662 | RTC_FROM_HERE); |
Erik Språng | 4e193e4 | 2018-09-14 19:01:58 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 665 | TEST_F(VideoSendStreamImplTest, CallsVideoStreamEncoderOnBitrateUpdate) { |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 666 | test_queue_.SendTask( |
| 667 | [this] { |
| 668 | const bool kSuspend = false; |
| 669 | config_.suspend_below_min_bitrate = kSuspend; |
| 670 | config_.rtp.extensions.emplace_back( |
| 671 | RtpExtension::kTransportSequenceNumberUri, 1); |
| 672 | auto vss_impl = CreateVideoSendStreamImpl( |
| 673 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 674 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 675 | vss_impl->Start(); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 676 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 677 | VideoStream qvga_stream; |
| 678 | qvga_stream.width = 320; |
| 679 | qvga_stream.height = 180; |
| 680 | qvga_stream.max_framerate = 30; |
| 681 | qvga_stream.min_bitrate_bps = 30000; |
| 682 | qvga_stream.target_bitrate_bps = 150000; |
| 683 | qvga_stream.max_bitrate_bps = 200000; |
| 684 | qvga_stream.max_qp = 56; |
| 685 | qvga_stream.bitrate_priority = 1; |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 686 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 687 | int min_transmit_bitrate_bps = 30000; |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 688 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 689 | config_.rtp.ssrcs.emplace_back(1); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 690 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 691 | static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get()) |
| 692 | ->OnEncoderConfigurationChanged( |
| 693 | std::vector<VideoStream>{qvga_stream}, |
| 694 | VideoEncoderConfig::ContentType::kRealtimeVideo, |
| 695 | min_transmit_bitrate_bps); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 696 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 697 | const DataRate network_constrained_rate = |
| 698 | DataRate::bps(qvga_stream.target_bitrate_bps); |
| 699 | BitrateAllocationUpdate update; |
| 700 | update.target_bitrate = network_constrained_rate; |
| 701 | update.stable_target_bitrate = network_constrained_rate; |
| 702 | update.round_trip_time = TimeDelta::ms(1); |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 703 | EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _)); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 704 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 705 | .WillOnce(Return(network_constrained_rate.bps())); |
| 706 | EXPECT_CALL( |
| 707 | video_stream_encoder_, |
| 708 | OnBitrateUpdated(network_constrained_rate, network_constrained_rate, |
| 709 | network_constrained_rate, 0, _)); |
| 710 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 711 | ->OnBitrateUpdated(update); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 712 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 713 | // Test allocation where the link allocation is larger than the target, |
| 714 | // meaning we have some headroom on the link. |
| 715 | const DataRate qvga_max_bitrate = |
| 716 | DataRate::bps(qvga_stream.max_bitrate_bps); |
| 717 | const DataRate headroom = DataRate::bps(50000); |
| 718 | const DataRate rate_with_headroom = qvga_max_bitrate + headroom; |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 719 | update.target_bitrate = rate_with_headroom; |
| 720 | update.stable_target_bitrate = rate_with_headroom; |
| 721 | EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _)); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 722 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 723 | .WillOnce(Return(rate_with_headroom.bps())); |
| 724 | EXPECT_CALL(video_stream_encoder_, |
| 725 | OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate, |
| 726 | rate_with_headroom, 0, _)); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 727 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 728 | ->OnBitrateUpdated(update); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 729 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 730 | // Add protection bitrate to the mix, this should be subtracted from the |
| 731 | // headroom. |
| 732 | const uint32_t protection_bitrate_bps = 10000; |
| 733 | EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps()) |
| 734 | .WillOnce(Return(protection_bitrate_bps)); |
Erik Språng | 2611164 | 2019-03-26 11:09:04 +0100 | [diff] [blame] | 735 | |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 736 | EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _)); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 737 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 738 | .WillOnce(Return(rate_with_headroom.bps())); |
| 739 | const DataRate headroom_minus_protection = |
| 740 | rate_with_headroom - DataRate::bps(protection_bitrate_bps); |
| 741 | EXPECT_CALL(video_stream_encoder_, |
| 742 | OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate, |
| 743 | headroom_minus_protection, 0, _)); |
| 744 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 745 | ->OnBitrateUpdated(update); |
Erik Språng | 2611164 | 2019-03-26 11:09:04 +0100 | [diff] [blame] | 746 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 747 | // Protection bitrate exceeds head room, link allocation should be |
| 748 | // capped to target bitrate. |
| 749 | EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps()) |
| 750 | .WillOnce(Return(headroom.bps() + 1000)); |
Sebastian Jansson | 82ed2e8 | 2019-10-15 15:58:37 +0200 | [diff] [blame] | 751 | EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _)); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 752 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 753 | .WillOnce(Return(rate_with_headroom.bps())); |
| 754 | EXPECT_CALL(video_stream_encoder_, |
| 755 | OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate, |
| 756 | qvga_max_bitrate, 0, _)); |
| 757 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 758 | ->OnBitrateUpdated(update); |
Erik Språng | 2611164 | 2019-03-26 11:09:04 +0100 | [diff] [blame] | 759 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 760 | // Set rates to zero on stop. |
| 761 | EXPECT_CALL(video_stream_encoder_, |
| 762 | OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(), |
| 763 | DataRate::Zero(), 0, 0)); |
| 764 | vss_impl->Stop(); |
| 765 | }, |
| 766 | RTC_FROM_HERE); |
Erik Språng | 610c763 | 2019-03-06 15:37:33 +0100 | [diff] [blame] | 767 | } |
| 768 | |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 769 | TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) { |
| 770 | int padding_bitrate = 0; |
| 771 | std::unique_ptr<VideoSendStreamImpl> vss_impl; |
| 772 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 773 | test_queue_.SendTask( |
| 774 | [&] { |
| 775 | vss_impl = CreateVideoSendStreamImpl( |
| 776 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 777 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 778 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 779 | // Capture padding bitrate for testing. |
| 780 | EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _)) |
| 781 | .WillRepeatedly(Invoke([&](BitrateAllocatorObserver*, |
| 782 | MediaStreamAllocationConfig config) { |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 783 | padding_bitrate = config.pad_up_bitrate_bps; |
| 784 | })); |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 785 | // If observer is removed, no padding will be sent. |
| 786 | EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())) |
| 787 | .WillRepeatedly(Invoke( |
| 788 | [&](BitrateAllocatorObserver*) { padding_bitrate = 0; })); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 789 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 790 | EXPECT_CALL(rtp_video_sender_, OnEncodedImage(_, _, _)) |
| 791 | .WillRepeatedly(Return(EncodedImageCallback::Result( |
| 792 | EncodedImageCallback::Result::OK))); |
| 793 | const bool kSuspend = false; |
| 794 | config_.suspend_below_min_bitrate = kSuspend; |
| 795 | config_.rtp.extensions.emplace_back( |
| 796 | RtpExtension::kTransportSequenceNumberUri, 1); |
| 797 | VideoStream qvga_stream; |
| 798 | qvga_stream.width = 320; |
| 799 | qvga_stream.height = 180; |
| 800 | qvga_stream.max_framerate = 30; |
| 801 | qvga_stream.min_bitrate_bps = 30000; |
| 802 | qvga_stream.target_bitrate_bps = 150000; |
| 803 | qvga_stream.max_bitrate_bps = 200000; |
| 804 | qvga_stream.max_qp = 56; |
| 805 | qvga_stream.bitrate_priority = 1; |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 806 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 807 | int min_transmit_bitrate_bps = 30000; |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 808 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 809 | config_.rtp.ssrcs.emplace_back(1); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 810 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 811 | vss_impl->Start(); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 812 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 813 | // Starts without padding. |
| 814 | EXPECT_EQ(0, padding_bitrate); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 815 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 816 | // Reconfigure e.g. due to a fake frame. |
| 817 | static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get()) |
| 818 | ->OnEncoderConfigurationChanged( |
| 819 | std::vector<VideoStream>{qvga_stream}, |
| 820 | VideoEncoderConfig::ContentType::kRealtimeVideo, |
| 821 | min_transmit_bitrate_bps); |
| 822 | // Still no padding because no actual frames were passed, only |
| 823 | // reconfiguration happened. |
| 824 | EXPECT_EQ(0, padding_bitrate); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 825 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 826 | // Unpause encoder. |
| 827 | const uint32_t kBitrateBps = 100000; |
| 828 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 829 | .Times(1) |
| 830 | .WillOnce(Return(kBitrateBps)); |
| 831 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 832 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 833 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 834 | // A frame is encoded. |
| 835 | EncodedImage encoded_image; |
| 836 | CodecSpecificInfo codec_specific; |
| 837 | static_cast<EncodedImageCallback*>(vss_impl.get()) |
| 838 | ->OnEncodedImage(encoded_image, &codec_specific, nullptr); |
| 839 | // Only after actual frame is encoded are we enabling the padding. |
| 840 | EXPECT_GT(padding_bitrate, 0); |
| 841 | }, |
| 842 | RTC_FROM_HERE); |
Ilya Nikolaevskiy | aa9aa57 | 2019-04-11 09:20:24 +0200 | [diff] [blame] | 843 | |
| 844 | rtc::Event done; |
| 845 | test_queue_.PostDelayedTask( |
| 846 | [&] { |
| 847 | // No padding supposed to be sent for paused observer |
| 848 | EXPECT_EQ(0, padding_bitrate); |
| 849 | testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_); |
| 850 | vss_impl->Stop(); |
| 851 | vss_impl.reset(); |
| 852 | done.Set(); |
| 853 | }, |
| 854 | 5000); |
| 855 | |
| 856 | // Pause the test suite so that the last delayed task executes. |
| 857 | ASSERT_TRUE(done.Wait(10000)); |
| 858 | } |
| 859 | |
Jakob Ivarsson | 159b417 | 2019-10-30 14:02:14 +0100 | [diff] [blame] | 860 | TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) { |
| 861 | std::unique_ptr<VideoSendStreamImpl> vss_impl; |
| 862 | test_queue_.SendTask( |
| 863 | [&] { |
| 864 | vss_impl = CreateVideoSendStreamImpl( |
| 865 | kDefaultInitialBitrateBps, kDefaultBitratePriority, |
| 866 | VideoEncoderConfig::ContentType::kRealtimeVideo); |
| 867 | vss_impl->Start(); |
| 868 | const uint32_t kBitrateBps = 100000; |
| 869 | EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps()) |
| 870 | .Times(1) |
| 871 | .WillOnce(Return(kBitrateBps)); |
| 872 | static_cast<BitrateAllocatorObserver*>(vss_impl.get()) |
| 873 | ->OnBitrateUpdated(CreateAllocation(kBitrateBps)); |
| 874 | |
| 875 | // Keep the stream from deallocating by dropping a frame. |
| 876 | static_cast<EncodedImageCallback*>(vss_impl.get()) |
| 877 | ->OnDroppedFrame( |
| 878 | EncodedImageCallback::DropReason::kDroppedByEncoder); |
| 879 | EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())) |
| 880 | .Times(0); |
| 881 | }, |
| 882 | RTC_FROM_HERE); |
| 883 | |
| 884 | rtc::Event done; |
| 885 | test_queue_.PostDelayedTask( |
| 886 | [&] { |
| 887 | testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_); |
| 888 | vss_impl->Stop(); |
| 889 | vss_impl.reset(); |
| 890 | done.Set(); |
| 891 | }, |
| 892 | 2000); |
| 893 | ASSERT_TRUE(done.Wait(5000)); |
| 894 | } |
| 895 | |
Sebastian Jansson | 652dc91 | 2018-04-19 17:09:15 +0200 | [diff] [blame] | 896 | } // namespace internal |
| 897 | } // namespace webrtc |