blob: 928c7555893c5093f16fd952c2323367a4565e4b [file] [log] [blame]
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +02001/*
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#include "video/video_send_stream_impl.h"
11
Yves Gerey3e707812018-11-28 16:47:49 +010012#include <stdio.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020013
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020014#include <algorithm>
Yves Gerey3e707812018-11-28 16:47:49 +010015#include <cstdint>
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020016#include <string>
17#include <utility>
18
Steve Antonbd631a02019-03-28 10:51:27 -070019#include "absl/algorithm/container.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/crypto/crypto_options.h"
21#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010022#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 14:31:24 +010023#include "api/sequence_checker.h"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "api/video_codecs/video_codec.h"
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020025#include "call/rtp_transport_controller_send_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "call/video_send_stream.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "modules/pacing/paced_sender.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "rtc_base/atomic_ops.h"
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020029#include "rtc_base/checks.h"
30#include "rtc_base/experiments/alr_experiment.h"
Ying Wang8c5520c2019-09-03 15:25:21 +000031#include "rtc_base/experiments/field_trial_parser.h"
Elad Alon80f53b72019-10-11 16:19:43 +020032#include "rtc_base/experiments/min_video_bitrate_experiment.h"
Erik Språngcd76eab2019-01-21 18:06:46 +010033#include "rtc_base/experiments/rate_control_settings.h"
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020034#include "rtc_base/logging.h"
35#include "rtc_base/numerics/safe_conversions.h"
36#include "rtc_base/trace_event.h"
Yves Gerey3e707812018-11-28 16:47:49 +010037#include "system_wrappers/include/clock.h"
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020038#include "system_wrappers/include/field_trial.h"
39
40namespace webrtc {
41namespace internal {
42namespace {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020043
Erik Språng4e193e42018-09-14 19:01:58 +020044// Max positive size difference to treat allocations as "similar".
45static constexpr int kMaxVbaSizeDifferencePercent = 10;
46// Max time we will throttle similar video bitrate allocations.
47static constexpr int64_t kMaxVbaThrottleTimeMs = 500;
48
Danil Chapovalov0c626af2020-02-10 11:16:00 +010049constexpr TimeDelta kEncoderTimeOut = TimeDelta::Seconds(2);
Sebastian Janssonecb68972019-01-18 10:30:54 +010050
Erik Språng9d69cbe2020-10-22 17:44:42 +020051// When send-side BWE is used a stricter 1.1x pacing factor is used, rather than
52// the 2.5x which is used with receive-side BWE. Provides a more careful
53// bandwidth rampup with less risk of overshoots causing adverse effects like
54// packet loss. Not used for receive side BWE, since there we lack the probing
55// feature and so may result in too slow initial rampup.
56static constexpr double kStrictPacingMultiplier = 1.1;
57
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020058bool TransportSeqNumExtensionConfigured(const VideoSendStream::Config& config) {
59 const std::vector<RtpExtension>& extensions = config.rtp.extensions;
Steve Antonbd631a02019-03-28 10:51:27 -070060 return absl::c_any_of(extensions, [](const RtpExtension& ext) {
61 return ext.uri == RtpExtension::kTransportSequenceNumberUri;
62 });
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020063}
64
Erik Språngb57ab382018-09-13 10:52:38 +020065// Calculate max padding bitrate for a multi layer codec.
66int CalculateMaxPadBitrateBps(const std::vector<VideoStream>& streams,
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +020067 bool is_svc,
Rasmus Brandtc402dbe2019-02-04 11:09:46 +010068 VideoEncoderConfig::ContentType content_type,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020069 int min_transmit_bitrate_bps,
Erik Språngb57ab382018-09-13 10:52:38 +020070 bool pad_to_min_bitrate,
71 bool alr_probing) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +020072 int pad_up_to_bitrate_bps = 0;
Erik Språngb57ab382018-09-13 10:52:38 +020073
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +020074 RTC_DCHECK(!is_svc || streams.size() <= 1) << "Only one stream is allowed in "
75 "SVC mode.";
76
Erik Språngb57ab382018-09-13 10:52:38 +020077 // Filter out only the active streams;
78 std::vector<VideoStream> active_streams;
79 for (const VideoStream& stream : streams) {
80 if (stream.active)
81 active_streams.emplace_back(stream);
82 }
83
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +020084 if (active_streams.size() > 1 || (!active_streams.empty() && is_svc)) {
85 // Simulcast or SVC is used.
86 // if SVC is used, stream bitrates should already encode svc bitrates:
87 // min_bitrate = min bitrate of a lowest svc layer.
88 // target_bitrate = sum of target bitrates of lower layers + min bitrate
89 // of the last one (as used in the calculations below).
90 // max_bitrate = sum of all active layers' max_bitrate.
Erik Språngb57ab382018-09-13 10:52:38 +020091 if (alr_probing) {
92 // With alr probing, just pad to the min bitrate of the lowest stream,
93 // probing will handle the rest of the rampup.
94 pad_up_to_bitrate_bps = active_streams[0].min_bitrate_bps;
95 } else {
Rasmus Brandtc402dbe2019-02-04 11:09:46 +010096 // Without alr probing, pad up to start bitrate of the
97 // highest active stream.
98 const double hysteresis_factor =
99 RateControlSettings::ParseFromFieldTrials()
100 .GetSimulcastHysteresisFactor(content_type);
Erik Språng576db1b2020-06-08 13:32:20 +0200101 if (is_svc) {
102 // For SVC, since there is only one "stream", the padding bitrate
103 // needed to enable the top spatial layer is stored in the
104 // |target_bitrate_bps| field.
105 // TODO(sprang): This behavior needs to die.
106 pad_up_to_bitrate_bps = static_cast<int>(
107 hysteresis_factor * active_streams[0].target_bitrate_bps + 0.5);
108 } else {
109 const size_t top_active_stream_idx = active_streams.size() - 1;
110 pad_up_to_bitrate_bps = std::min(
111 static_cast<int>(
112 hysteresis_factor *
113 active_streams[top_active_stream_idx].min_bitrate_bps +
114 0.5),
115 active_streams[top_active_stream_idx].target_bitrate_bps);
Rasmus Brandtc402dbe2019-02-04 11:09:46 +0100116
Erik Språng576db1b2020-06-08 13:32:20 +0200117 // Add target_bitrate_bps of the lower active streams.
118 for (size_t i = 0; i < top_active_stream_idx; ++i) {
119 pad_up_to_bitrate_bps += active_streams[i].target_bitrate_bps;
120 }
Rasmus Brandtc402dbe2019-02-04 11:09:46 +0100121 }
Erik Språngb57ab382018-09-13 10:52:38 +0200122 }
123 } else if (!active_streams.empty() && pad_to_min_bitrate) {
124 pad_up_to_bitrate_bps = active_streams[0].min_bitrate_bps;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200125 }
126
127 pad_up_to_bitrate_bps =
128 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps);
129
130 return pad_up_to_bitrate_bps;
131}
132
Benjamin Wright192eeec2018-10-17 17:27:25 -0700133RtpSenderFrameEncryptionConfig CreateFrameEncryptionConfig(
134 const VideoSendStream::Config* config) {
135 RtpSenderFrameEncryptionConfig frame_encryption_config;
136 frame_encryption_config.frame_encryptor = config->frame_encryptor;
137 frame_encryption_config.crypto_options = config->crypto_options;
138 return frame_encryption_config;
139}
140
Tommi8ae18ad2020-05-03 22:45:02 +0200141RtpSenderObservers CreateObservers(RtcpRttStats* call_stats,
Elad Alon14d1c9d2019-04-08 14:16:17 +0200142 EncoderRtcpFeedback* encoder_feedback,
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200143 SendStatisticsProxy* stats_proxy,
Stefan Holmer64be7fa2018-10-04 15:21:55 +0200144 SendDelayStats* send_delay_stats) {
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200145 RtpSenderObservers observers;
146 observers.rtcp_rtt_stats = call_stats;
147 observers.intra_frame_callback = encoder_feedback;
Elad Alon0a8562e2019-04-09 11:55:13 +0200148 observers.rtcp_loss_notification_observer = encoder_feedback;
Henrik Boström87e3f9d2019-05-27 10:44:24 +0200149 observers.report_block_data_observer = stats_proxy;
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200150 observers.rtp_stats = stats_proxy;
151 observers.bitrate_observer = stats_proxy;
152 observers.frame_count_observer = stats_proxy;
153 observers.rtcp_type_observer = stats_proxy;
154 observers.send_delay_observer = stats_proxy;
155 observers.send_packet_observer = send_delay_stats;
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200156 return observers;
157}
Erik Språngb57ab382018-09-13 10:52:38 +0200158
159absl::optional<AlrExperimentSettings> GetAlrSettings(
160 VideoEncoderConfig::ContentType content_type) {
161 if (content_type == VideoEncoderConfig::ContentType::kScreen) {
162 return AlrExperimentSettings::CreateFromFieldTrial(
163 AlrExperimentSettings::kScreenshareProbingBweExperimentName);
164 }
165 return AlrExperimentSettings::CreateFromFieldTrial(
166 AlrExperimentSettings::kStrictPacingAndProbingExperimentName);
167}
Erik Språng4e193e42018-09-14 19:01:58 +0200168
169bool SameStreamsEnabled(const VideoBitrateAllocation& lhs,
170 const VideoBitrateAllocation& rhs) {
171 for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
172 for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) {
173 if (lhs.HasBitrate(si, ti) != rhs.HasBitrate(si, ti)) {
174 return false;
175 }
176 }
177 }
178 return true;
179}
Tommie902f282021-06-03 12:02:02 +0200180
181// Returns an optional that has value iff TransportSeqNumExtensionConfigured
182// is `true` for the given video send stream config.
183absl::optional<float> GetConfiguredPacingFactor(
184 const VideoSendStream::Config& config,
185 VideoEncoderConfig::ContentType content_type,
186 const PacingConfig& default_pacing_config) {
187 if (!TransportSeqNumExtensionConfigured(config))
188 return absl::nullopt;
189
190 absl::optional<AlrExperimentSettings> alr_settings =
191 GetAlrSettings(content_type);
192 if (alr_settings)
193 return alr_settings->pacing_factor;
194
195 RateControlSettings rate_control_settings =
196 RateControlSettings::ParseFromFieldTrials();
197 return rate_control_settings.GetPacingFactor().value_or(
198 default_pacing_config.pacing_factor);
199}
200
Tommifa3ce632021-06-03 12:06:02 +0200201uint32_t GetInitialEncoderMaxBitrate(int initial_encoder_max_bitrate) {
202 if (initial_encoder_max_bitrate > 0)
203 return rtc::dchecked_cast<uint32_t>(initial_encoder_max_bitrate);
204
205 // TODO(srte): Make sure max bitrate is not set to negative values. We don't
206 // have any way to handle unset values in downstream code, such as the
207 // bitrate allocator. Previously -1 was implicitly casted to UINT32_MAX, a
208 // behaviour that is not safe. Converting to 10 Mbps should be safe for
209 // reasonable use cases as it allows adding the max of multiple streams
210 // without wrappping around.
211 const int kFallbackMaxBitrateBps = 10000000;
212 RTC_DLOG(LS_ERROR) << "ERROR: Initial encoder max bitrate = "
213 << initial_encoder_max_bitrate << " which is <= 0!";
214 RTC_DLOG(LS_INFO) << "Using default encoder max bitrate = 10 Mbps";
215 return kFallbackMaxBitrateBps;
216}
217
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200218} // namespace
219
Christoffer Rodbro196c5ba2018-11-27 11:56:25 +0100220PacingConfig::PacingConfig()
Erik Språng9d69cbe2020-10-22 17:44:42 +0200221 : pacing_factor("factor", kStrictPacingMultiplier),
Christoffer Rodbro196c5ba2018-11-27 11:56:25 +0100222 max_pacing_delay("max_delay",
Danil Chapovalov0c626af2020-02-10 11:16:00 +0100223 TimeDelta::Millis(PacedSender::kMaxQueueLengthMs)) {
Christoffer Rodbro196c5ba2018-11-27 11:56:25 +0100224 ParseFieldTrial({&pacing_factor, &max_pacing_delay},
225 field_trial::FindFullName("WebRTC-Video-Pacing"));
226}
227PacingConfig::PacingConfig(const PacingConfig&) = default;
228PacingConfig::~PacingConfig() = default;
229
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200230VideoSendStreamImpl::VideoSendStreamImpl(
Sebastian Jansson572c60f2019-03-04 18:30:41 +0100231 Clock* clock,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200232 SendStatisticsProxy* stats_proxy,
Tommifa3ce632021-06-03 12:06:02 +0200233 rtc::TaskQueue* rtp_transport_queue,
Tommi8ae18ad2020-05-03 22:45:02 +0200234 RtcpRttStats* call_stats,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200235 RtpTransportControllerSendInterface* transport,
Sebastian Jansson652dc912018-04-19 17:09:15 +0200236 BitrateAllocatorInterface* bitrate_allocator,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200237 SendDelayStats* send_delay_stats,
Sebastian Jansson652dc912018-04-19 17:09:15 +0200238 VideoStreamEncoderInterface* video_stream_encoder,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200239 RtcEventLog* event_log,
240 const VideoSendStream::Config* config,
241 int initial_encoder_max_bitrate,
242 double initial_encoder_bitrate_priority,
243 std::map<uint32_t, RtpState> suspended_ssrcs,
244 std::map<uint32_t, RtpPayloadState> suspended_payload_states,
245 VideoEncoderConfig::ContentType content_type,
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -0800246 std::unique_ptr<FecController> fec_controller)
Sebastian Jansson572c60f2019-03-04 18:30:41 +0100247 : clock_(clock),
248 has_alr_probing_(config->periodic_alr_bandwidth_probing ||
Erik Språngb57ab382018-09-13 10:52:38 +0200249 GetAlrSettings(content_type)),
Christoffer Rodbro196c5ba2018-11-27 11:56:25 +0100250 pacing_config_(PacingConfig()),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200251 stats_proxy_(stats_proxy),
252 config_(config),
Tommifa3ce632021-06-03 12:06:02 +0200253 rtp_transport_queue_(rtp_transport_queue),
Erik Språngcd76eab2019-01-21 18:06:46 +0100254 timed_out_(false),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200255 transport_(transport),
256 bitrate_allocator_(bitrate_allocator),
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200257 disable_padding_(true),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200258 max_padding_bitrate_(0),
259 encoder_min_bitrate_bps_(0),
Tommifa3ce632021-06-03 12:06:02 +0200260 encoder_max_bitrate_bps_(
261 GetInitialEncoderMaxBitrate(initial_encoder_max_bitrate)),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200262 encoder_target_rate_bps_(0),
263 encoder_bitrate_priority_(initial_encoder_bitrate_priority),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200264 video_stream_encoder_(video_stream_encoder),
Tommi28e96532021-06-03 11:52:15 +0200265 encoder_feedback_(
266 clock,
267 config_->rtp.ssrcs,
268 video_stream_encoder,
269 [this](uint32_t ssrc, const std::vector<uint16_t>& seq_nums) {
270 return rtp_video_sender_->GetSentRtpPacketInfos(ssrc, seq_nums);
271 }),
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200272 bandwidth_observer_(transport->GetBandwidthObserver()),
Marina Cioceae77912b2020-02-27 16:16:55 +0100273 rtp_video_sender_(
274 transport_->CreateRtpVideoSender(suspended_ssrcs,
275 suspended_payload_states,
276 config_->rtp,
277 config_->rtcp_report_interval_ms,
278 config_->send_transport,
279 CreateObservers(call_stats,
280 &encoder_feedback_,
281 stats_proxy_,
282 send_delay_stats),
283 event_log,
284 std::move(fec_controller),
285 CreateFrameEncryptionConfig(config_),
286 config->frame_transformer)),
Tommie902f282021-06-03 12:02:02 +0200287 weak_ptr_factory_(this),
288 configured_pacing_factor_(
289 GetConfiguredPacingFactor(*config_, content_type, pacing_config_)) {
Tommifa3ce632021-06-03 12:06:02 +0200290 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
291 RTC_DCHECK_GE(config_->rtp.payload_type, 0);
292 RTC_DCHECK_LE(config_->rtp.payload_type, 127);
Bjorn A Mellem7a9a0922019-11-26 09:19:40 -0800293 RTC_DCHECK(!config_->rtp.ssrcs.empty());
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200294 RTC_DCHECK(transport_);
295 RTC_DCHECK_NE(initial_encoder_max_bitrate, 0);
Tommifa3ce632021-06-03 12:06:02 +0200296 RTC_LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString();
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200297
298 RTC_CHECK(AlrExperimentSettings::MaxOneFieldTrialEnabled());
Tommifa3ce632021-06-03 12:06:02 +0200299
300 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
301 video_stream_encoder->SetFecControllerOverride(rtp_video_sender_);
302
303 absl::optional<bool> enable_alr_bw_probing;
304
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200305 // If send-side BWE is enabled, check if we should apply updated probing and
306 // pacing settings.
Tommie902f282021-06-03 12:02:02 +0200307 if (configured_pacing_factor_.has_value()) {
Erik Språngb57ab382018-09-13 10:52:38 +0200308 absl::optional<AlrExperimentSettings> alr_settings =
309 GetAlrSettings(content_type);
Tommifa3ce632021-06-03 12:06:02 +0200310 int queue_time_limit_ms;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200311 if (alr_settings) {
Tommifa3ce632021-06-03 12:06:02 +0200312 enable_alr_bw_probing = true;
313 queue_time_limit_ms = alr_settings->max_paced_queue_time;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200314 } else {
Erik Språngcd76eab2019-01-21 18:06:46 +0100315 RateControlSettings rate_control_settings =
316 RateControlSettings::ParseFromFieldTrials();
Tommifa3ce632021-06-03 12:06:02 +0200317 enable_alr_bw_probing = rate_control_settings.UseAlrProbing();
318 queue_time_limit_ms = pacing_config_.max_pacing_delay.Get().ms();
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200319 }
Tommie902f282021-06-03 12:02:02 +0200320
Tommifa3ce632021-06-03 12:06:02 +0200321 transport->SetQueueTimeLimit(queue_time_limit_ms);
Tommie902f282021-06-03 12:02:02 +0200322 transport->SetPacingFactor(*configured_pacing_factor_);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200323 }
324
325 if (config_->periodic_alr_bandwidth_probing) {
Tommifa3ce632021-06-03 12:06:02 +0200326 enable_alr_bw_probing = config_->periodic_alr_bandwidth_probing;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200327 }
328
Tommifa3ce632021-06-03 12:06:02 +0200329 if (enable_alr_bw_probing) {
330 transport->EnablePeriodicAlrProbing(*enable_alr_bw_probing);
331 }
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200332
333 video_stream_encoder_->SetStartBitrate(
334 bitrate_allocator_->GetStartBitrate(this));
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200335}
336
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200337VideoSendStreamImpl::~VideoSendStreamImpl() {
Tommifa3ce632021-06-03 12:06:02 +0200338 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Stefan Holmer9416ef82018-07-19 10:34:38 +0200339 RTC_DCHECK(!rtp_video_sender_->IsActive())
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200340 << "VideoSendStreamImpl::Stop not called";
341 RTC_LOG(LS_INFO) << "~VideoSendStreamInternal: " << config_->ToString();
Stefan Holmer9416ef82018-07-19 10:34:38 +0200342 transport_->DestroyRtpVideoSender(rtp_video_sender_);
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200343}
344
345void VideoSendStreamImpl::RegisterProcessThread(
346 ProcessThread* module_process_thread) {
Tommifa3ce632021-06-03 12:06:02 +0200347 // Called on libjingle's worker thread (not rtp_transport_queue_), as part of
348 // the initialization steps. That's also the correct thread/queue for setting
349 // the state for |video_stream_encoder_|.
Tomas Gunnarsson612445e2020-09-21 14:31:23 +0200350
351 // Only request rotation at the source when we positively know that the remote
352 // side doesn't support the rotation extension. This allows us to prepare the
353 // encoder in the expectation that rotation is supported - which is the common
354 // case.
355 bool rotation_applied = absl::c_none_of(
356 config_->rtp.extensions, [](const RtpExtension& extension) {
357 return extension.uri == RtpExtension::kVideoRotationUri;
358 });
359
360 video_stream_encoder_->SetSink(this, rotation_applied);
361
Stefan Holmer9416ef82018-07-19 10:34:38 +0200362 rtp_video_sender_->RegisterProcessThread(module_process_thread);
Stefan Holmerdbdb3a02018-07-17 16:03:46 +0200363}
364
365void VideoSendStreamImpl::DeRegisterProcessThread() {
Stefan Holmer9416ef82018-07-19 10:34:38 +0200366 rtp_video_sender_->DeRegisterProcessThread();
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200367}
368
Niels Möller8fb1a6a2019-03-05 14:29:42 +0100369void VideoSendStreamImpl::DeliverRtcp(const uint8_t* packet, size_t length) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200370 // Runs on a network thread.
Tommifa3ce632021-06-03 12:06:02 +0200371 RTC_DCHECK(!rtp_transport_queue_->IsCurrent());
Stefan Holmer9416ef82018-07-19 10:34:38 +0200372 rtp_video_sender_->DeliverRtcp(packet, length);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200373}
374
375void VideoSendStreamImpl::UpdateActiveSimulcastLayers(
376 const std::vector<bool> active_layers) {
Tommifa3ce632021-06-03 12:06:02 +0200377 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Stefan Holmer9416ef82018-07-19 10:34:38 +0200378 bool previously_active = rtp_video_sender_->IsActive();
379 rtp_video_sender_->SetActiveModules(active_layers);
380 if (!rtp_video_sender_->IsActive() && previously_active) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200381 // Payload router switched from active to inactive.
382 StopVideoSendStream();
Stefan Holmer9416ef82018-07-19 10:34:38 +0200383 } else if (rtp_video_sender_->IsActive() && !previously_active) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200384 // Payload router switched from inactive to active.
385 StartupVideoSendStream();
386 }
387}
388
389void VideoSendStreamImpl::Start() {
Tommifa3ce632021-06-03 12:06:02 +0200390 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200391 RTC_LOG(LS_INFO) << "VideoSendStream::Start";
Stefan Holmer9416ef82018-07-19 10:34:38 +0200392 if (rtp_video_sender_->IsActive())
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200393 return;
394 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Start");
Stefan Holmer9416ef82018-07-19 10:34:38 +0200395 rtp_video_sender_->SetActive(true);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200396 StartupVideoSendStream();
397}
398
399void VideoSendStreamImpl::StartupVideoSendStream() {
Tommifa3ce632021-06-03 12:06:02 +0200400 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Sebastian Jansson464a5572019-02-12 13:32:32 +0100401 bitrate_allocator_->AddObserver(this, GetAllocationConfig());
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200402 // Start monitoring encoder activity.
403 {
Sebastian Janssonecb68972019-01-18 10:30:54 +0100404 RTC_DCHECK(!check_encoder_activity_task_.Running());
405
406 activity_ = false;
407 timed_out_ = false;
Sebastian Janssoncda86dd2019-03-11 17:26:36 +0100408 check_encoder_activity_task_ = RepeatingTaskHandle::DelayedStart(
Tommifa3ce632021-06-03 12:06:02 +0200409 rtp_transport_queue_->Get(), kEncoderTimeOut, [this] {
410 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Sebastian Janssonecb68972019-01-18 10:30:54 +0100411 if (!activity_) {
412 if (!timed_out_) {
413 SignalEncoderTimedOut();
414 }
415 timed_out_ = true;
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200416 disable_padding_ = true;
Sebastian Janssonecb68972019-01-18 10:30:54 +0100417 } else if (timed_out_) {
418 SignalEncoderActive();
419 timed_out_ = false;
420 }
421 activity_ = false;
422 return kEncoderTimeOut;
423 });
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200424 }
425
426 video_stream_encoder_->SendKeyFrame();
427}
428
429void VideoSendStreamImpl::Stop() {
Tommifa3ce632021-06-03 12:06:02 +0200430 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Evan Shrubsole0db33962020-11-25 14:54:58 +0100431 RTC_LOG(LS_INFO) << "VideoSendStreamImpl::Stop";
Stefan Holmer9416ef82018-07-19 10:34:38 +0200432 if (!rtp_video_sender_->IsActive())
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200433 return;
434 TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop");
Stefan Holmer9416ef82018-07-19 10:34:38 +0200435 rtp_video_sender_->SetActive(false);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200436 StopVideoSendStream();
437}
438
439void VideoSendStreamImpl::StopVideoSendStream() {
440 bitrate_allocator_->RemoveObserver(this);
Sebastian Janssonecb68972019-01-18 10:30:54 +0100441 check_encoder_activity_task_.Stop();
Florent Castellia8336d32019-09-09 13:36:55 +0200442 video_stream_encoder_->OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(),
Ying Wang9b881ab2020-02-07 14:29:32 +0100443 DataRate::Zero(), 0, 0, 0);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200444 stats_proxy_->OnSetEncoderTargetRate(0);
445}
446
447void VideoSendStreamImpl::SignalEncoderTimedOut() {
Tommifa3ce632021-06-03 12:06:02 +0200448 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Sebastian Janssonecb68972019-01-18 10:30:54 +0100449 // If the encoder has not produced anything the last kEncoderTimeOut and it
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200450 // is supposed to, deregister as BitrateAllocatorObserver. This can happen
451 // if a camera stops producing frames.
452 if (encoder_target_rate_bps_ > 0) {
453 RTC_LOG(LS_INFO) << "SignalEncoderTimedOut, Encoder timed out.";
454 bitrate_allocator_->RemoveObserver(this);
455 }
456}
457
458void VideoSendStreamImpl::OnBitrateAllocationUpdated(
Erik Språng566124a2018-04-23 12:32:22 +0200459 const VideoBitrateAllocation& allocation) {
Tommifa3ce632021-06-03 12:06:02 +0200460 if (!rtp_transport_queue_->IsCurrent()) {
Erik Språng4e193e42018-09-14 19:01:58 +0200461 auto ptr = weak_ptr_;
Tommifa3ce632021-06-03 12:06:02 +0200462 rtp_transport_queue_->PostTask([=] {
Erik Språng4e193e42018-09-14 19:01:58 +0200463 if (!ptr.get())
464 return;
465 ptr->OnBitrateAllocationUpdated(allocation);
466 });
467 return;
468 }
469
Tommifa3ce632021-06-03 12:06:02 +0200470 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Erik Språng4e193e42018-09-14 19:01:58 +0200471
Sebastian Jansson572c60f2019-03-04 18:30:41 +0100472 int64_t now_ms = clock_->TimeInMilliseconds();
Erik Språngf4ef2dd2018-09-11 12:37:51 +0200473 if (encoder_target_rate_bps_ != 0) {
Erik Språng4e193e42018-09-14 19:01:58 +0200474 if (video_bitrate_allocation_context_) {
475 // If new allocation is within kMaxVbaSizeDifferencePercent larger than
476 // the previously sent allocation and the same streams are still enabled,
477 // it is considered "similar". We do not want send similar allocations
478 // more once per kMaxVbaThrottleTimeMs.
479 const VideoBitrateAllocation& last =
480 video_bitrate_allocation_context_->last_sent_allocation;
481 const bool is_similar =
482 allocation.get_sum_bps() >= last.get_sum_bps() &&
483 allocation.get_sum_bps() <
484 (last.get_sum_bps() * (100 + kMaxVbaSizeDifferencePercent)) /
485 100 &&
486 SameStreamsEnabled(allocation, last);
487 if (is_similar &&
488 (now_ms - video_bitrate_allocation_context_->last_send_time_ms) <
489 kMaxVbaThrottleTimeMs) {
490 // This allocation is too similar, cache it and return.
491 video_bitrate_allocation_context_->throttled_allocation = allocation;
492 return;
493 }
494 } else {
495 video_bitrate_allocation_context_.emplace();
496 }
497
498 video_bitrate_allocation_context_->last_sent_allocation = allocation;
499 video_bitrate_allocation_context_->throttled_allocation.reset();
500 video_bitrate_allocation_context_->last_send_time_ms = now_ms;
501
Erik Språngf4ef2dd2018-09-11 12:37:51 +0200502 // Send bitrate allocation metadata only if encoder is not paused.
503 rtp_video_sender_->OnBitrateAllocationUpdated(allocation);
504 }
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200505}
506
Per Kjellandera9434842020-10-15 17:53:22 +0200507void VideoSendStreamImpl::OnVideoLayersAllocationUpdated(
508 VideoLayersAllocation allocation) {
Per Kjellanderda06e8f2021-01-07 19:37:00 +0100509 // OnVideoLayersAllocationUpdated is handled on the encoder task queue in
510 // order to not race with OnEncodedImage callbacks.
Per Kjellanderaf704182020-10-16 10:30:40 +0200511 rtp_video_sender_->OnVideoLayersAllocationUpdated(allocation);
Per Kjellandera9434842020-10-15 17:53:22 +0200512}
513
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200514void VideoSendStreamImpl::SignalEncoderActive() {
Tommifa3ce632021-06-03 12:06:02 +0200515 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200516 if (rtp_video_sender_->IsActive()) {
517 RTC_LOG(LS_INFO) << "SignalEncoderActive, Encoder is active.";
518 bitrate_allocator_->AddObserver(this, GetAllocationConfig());
519 }
Sebastian Jansson464a5572019-02-12 13:32:32 +0100520}
521
522MediaStreamAllocationConfig VideoSendStreamImpl::GetAllocationConfig() const {
523 return MediaStreamAllocationConfig{
524 static_cast<uint32_t>(encoder_min_bitrate_bps_),
525 encoder_max_bitrate_bps_,
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200526 static_cast<uint32_t>(disable_padding_ ? 0 : max_padding_bitrate_),
Sebastian Jansson464a5572019-02-12 13:32:32 +0100527 /* priority_bitrate */ 0,
528 !config_->suspend_below_min_bitrate,
Sebastian Jansson464a5572019-02-12 13:32:32 +0100529 encoder_bitrate_priority_};
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200530}
531
532void VideoSendStreamImpl::OnEncoderConfigurationChanged(
533 std::vector<VideoStream> streams,
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +0200534 bool is_svc,
Rasmus Brandtc402dbe2019-02-04 11:09:46 +0100535 VideoEncoderConfig::ContentType content_type,
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200536 int min_transmit_bitrate_bps) {
Tommifa3ce632021-06-03 12:06:02 +0200537 if (!rtp_transport_queue_->IsCurrent()) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200538 rtc::WeakPtr<VideoSendStreamImpl> send_stream = weak_ptr_;
Tommifa3ce632021-06-03 12:06:02 +0200539 rtp_transport_queue_->PostTask([send_stream, streams, is_svc, content_type,
540 min_transmit_bitrate_bps]() mutable {
Mirko Bonadei80a86872019-02-04 15:01:43 +0100541 if (send_stream) {
542 send_stream->OnEncoderConfigurationChanged(
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +0200543 std::move(streams), is_svc, content_type, min_transmit_bitrate_bps);
Mirko Bonadei80a86872019-02-04 15:01:43 +0100544 }
545 });
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200546 return;
547 }
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +0200548
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200549 RTC_DCHECK_GE(config_->rtp.ssrcs.size(), streams.size());
550 TRACE_EVENT0("webrtc", "VideoSendStream::OnEncoderConfigurationChanged");
Tommifa3ce632021-06-03 12:06:02 +0200551 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200552
Elad Alon80f53b72019-10-11 16:19:43 +0200553 const VideoCodecType codec_type =
554 PayloadStringToCodecType(config_->rtp.payload_name);
555
556 const absl::optional<DataRate> experimental_min_bitrate =
557 GetExperimentalMinVideoBitrate(codec_type);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200558 encoder_min_bitrate_bps_ =
Elad Alonc67a4d62019-10-11 16:54:18 +0200559 experimental_min_bitrate
560 ? experimental_min_bitrate->bps()
561 : std::max(streams[0].min_bitrate_bps, kDefaultMinVideoBitrateBps);
562
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200563 encoder_max_bitrate_bps_ = 0;
564 double stream_bitrate_priority_sum = 0;
565 for (const auto& stream : streams) {
566 // We don't want to allocate more bitrate than needed to inactive streams.
567 encoder_max_bitrate_bps_ += stream.active ? stream.max_bitrate_bps : 0;
568 if (stream.bitrate_priority) {
569 RTC_DCHECK_GT(*stream.bitrate_priority, 0);
570 stream_bitrate_priority_sum += *stream.bitrate_priority;
571 }
572 }
573 RTC_DCHECK_GT(stream_bitrate_priority_sum, 0);
574 encoder_bitrate_priority_ = stream_bitrate_priority_sum;
575 encoder_max_bitrate_bps_ =
576 std::max(static_cast<uint32_t>(encoder_min_bitrate_bps_),
577 encoder_max_bitrate_bps_);
“Michael277a6562018-06-01 14:09:19 -0500578
Rasmus Brandtc402dbe2019-02-04 11:09:46 +0100579 // TODO(bugs.webrtc.org/10266): Query the VideoBitrateAllocator instead.
Ilya Nikolaevskiy93be66c2020-04-02 14:10:27 +0200580 max_padding_bitrate_ = CalculateMaxPadBitrateBps(
581 streams, is_svc, content_type, min_transmit_bitrate_bps,
582 config_->suspend_below_min_bitrate, has_alr_probing_);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200583
584 // Clear stats for disabled layers.
585 for (size_t i = streams.size(); i < config_->rtp.ssrcs.size(); ++i) {
586 stats_proxy_->OnInactiveSsrc(config_->rtp.ssrcs[i]);
587 }
588
589 const size_t num_temporal_layers =
590 streams.back().num_temporal_layers.value_or(1);
Stefan Holmer64be7fa2018-10-04 15:21:55 +0200591
592 rtp_video_sender_->SetEncodingData(streams[0].width, streams[0].height,
593 num_temporal_layers);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200594
Stefan Holmer9416ef82018-07-19 10:34:38 +0200595 if (rtp_video_sender_->IsActive()) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200596 // The send stream is started already. Update the allocator with new bitrate
597 // limits.
Sebastian Jansson464a5572019-02-12 13:32:32 +0100598 bitrate_allocator_->AddObserver(this, GetAllocationConfig());
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200599 }
600}
601
602EncodedImageCallback::Result VideoSendStreamImpl::OnEncodedImage(
603 const EncodedImage& encoded_image,
Danil Chapovalov2549f172020-08-12 17:30:36 +0200604 const CodecSpecificInfo* codec_specific_info) {
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200605 // Encoded is called on whatever thread the real encoder implementation run
606 // on. In the case of hardware encoders, there might be several encoders
607 // running in parallel on different threads.
Sebastian Janssonecb68972019-01-18 10:30:54 +0100608
609 // Indicate that there still is activity going on.
610 activity_ = true;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200611
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200612 auto enable_padding_task = [this]() {
613 if (disable_padding_) {
Tommifa3ce632021-06-03 12:06:02 +0200614 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200615 disable_padding_ = false;
616 // To ensure that padding bitrate is propagated to the bitrate allocator.
617 SignalEncoderActive();
618 }
619 };
Tommifa3ce632021-06-03 12:06:02 +0200620 if (!rtp_transport_queue_->IsCurrent()) {
621 rtp_transport_queue_->PostTask(enable_padding_task);
Ilya Nikolaevskiyaa9aa572019-04-11 09:20:24 +0200622 } else {
623 enable_padding_task();
624 }
625
Niels Möller46879152019-01-07 15:54:47 +0100626 EncodedImageCallback::Result result(EncodedImageCallback::Result::OK);
Danil Chapovalov2549f172020-08-12 17:30:36 +0200627 result =
628 rtp_video_sender_->OnEncodedImage(encoded_image, codec_specific_info);
Erik Språng4e193e42018-09-14 19:01:58 +0200629 // Check if there's a throttled VideoBitrateAllocation that we should try
630 // sending.
631 rtc::WeakPtr<VideoSendStreamImpl> send_stream = weak_ptr_;
632 auto update_task = [send_stream]() {
633 if (send_stream) {
Tommifa3ce632021-06-03 12:06:02 +0200634 RTC_DCHECK_RUN_ON(send_stream->rtp_transport_queue_);
Erik Språng4e193e42018-09-14 19:01:58 +0200635 auto& context = send_stream->video_bitrate_allocation_context_;
636 if (context && context->throttled_allocation) {
637 send_stream->OnBitrateAllocationUpdated(*context->throttled_allocation);
638 }
639 }
640 };
Tommifa3ce632021-06-03 12:06:02 +0200641 if (!rtp_transport_queue_->IsCurrent()) {
642 rtp_transport_queue_->PostTask(update_task);
Erik Språng4e193e42018-09-14 19:01:58 +0200643 } else {
644 update_task();
645 }
646
647 return result;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200648}
649
Jakob Ivarsson159b4172019-10-30 14:02:14 +0100650void VideoSendStreamImpl::OnDroppedFrame(
651 EncodedImageCallback::DropReason reason) {
652 activity_ = true;
653}
654
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200655std::map<uint32_t, RtpState> VideoSendStreamImpl::GetRtpStates() const {
Stefan Holmer9416ef82018-07-19 10:34:38 +0200656 return rtp_video_sender_->GetRtpStates();
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200657}
658
659std::map<uint32_t, RtpPayloadState> VideoSendStreamImpl::GetRtpPayloadStates()
660 const {
Stefan Holmer9416ef82018-07-19 10:34:38 +0200661 return rtp_video_sender_->GetRtpPayloadStates();
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200662}
663
Sebastian Janssonc0e4d452018-10-25 15:08:32 +0200664uint32_t VideoSendStreamImpl::OnBitrateUpdated(BitrateAllocationUpdate update) {
Tommifa3ce632021-06-03 12:06:02 +0200665 RTC_DCHECK_RUN_ON(rtp_transport_queue_);
Stefan Holmer9416ef82018-07-19 10:34:38 +0200666 RTC_DCHECK(rtp_video_sender_->IsActive())
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200667 << "VideoSendStream::Start has not been called.";
668
Florent Castellia8336d32019-09-09 13:36:55 +0200669 // When the BWE algorithm doesn't pass a stable estimate, we'll use the
670 // unstable one instead.
671 if (update.stable_target_bitrate.IsZero()) {
672 update.stable_target_bitrate = update.target_bitrate;
673 }
674
Sebastian Jansson82ed2e82019-10-15 15:58:37 +0200675 rtp_video_sender_->OnBitrateUpdated(update, stats_proxy_->GetSendFrameRate());
Stefan Holmer64be7fa2018-10-04 15:21:55 +0200676 encoder_target_rate_bps_ = rtp_video_sender_->GetPayloadBitrateBps();
Erik Språng26111642019-03-26 11:09:04 +0100677 const uint32_t protection_bitrate_bps =
678 rtp_video_sender_->GetProtectionBitrateBps();
Erik Språng4c6ca302019-04-08 15:14:01 +0200679 DataRate link_allocation = DataRate::Zero();
680 if (encoder_target_rate_bps_ > protection_bitrate_bps) {
681 link_allocation =
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +0100682 DataRate::BitsPerSec(encoder_target_rate_bps_ - protection_bitrate_bps);
Erik Språng610c7632019-03-06 15:37:33 +0100683 }
Florent Castellia8336d32019-09-09 13:36:55 +0200684 DataRate overhead =
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +0100685 update.target_bitrate - DataRate::BitsPerSec(encoder_target_rate_bps_);
Florent Castellia8336d32019-09-09 13:36:55 +0200686 DataRate encoder_stable_target_rate = update.stable_target_bitrate;
687 if (encoder_stable_target_rate > overhead) {
688 encoder_stable_target_rate = encoder_stable_target_rate - overhead;
689 } else {
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +0100690 encoder_stable_target_rate = DataRate::BitsPerSec(encoder_target_rate_bps_);
Florent Castellia8336d32019-09-09 13:36:55 +0200691 }
692
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200693 encoder_target_rate_bps_ =
694 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
Erik Språng4c6ca302019-04-08 15:14:01 +0200695
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +0100696 encoder_stable_target_rate =
697 std::min(DataRate::BitsPerSec(encoder_max_bitrate_bps_),
698 encoder_stable_target_rate);
Florent Castellia8336d32019-09-09 13:36:55 +0200699
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +0100700 DataRate encoder_target_rate = DataRate::BitsPerSec(encoder_target_rate_bps_);
Erik Språng4c6ca302019-04-08 15:14:01 +0200701 link_allocation = std::max(encoder_target_rate, link_allocation);
Sebastian Jansson13e59032018-11-21 19:13:07 +0100702 video_stream_encoder_->OnBitrateUpdated(
Florent Castellia8336d32019-09-09 13:36:55 +0200703 encoder_target_rate, encoder_stable_target_rate, link_allocation,
Sebastian Jansson13e59032018-11-21 19:13:07 +0100704 rtc::dchecked_cast<uint8_t>(update.packet_loss_ratio * 256),
Ying Wang9b881ab2020-02-07 14:29:32 +0100705 update.round_trip_time.ms(), update.cwnd_reduce_ratio);
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200706 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
Erik Språng26111642019-03-26 11:09:04 +0100707 return protection_bitrate_bps;
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200708}
709
Sebastian Jansson8e0b15b2018-04-18 19:19:22 +0200710} // namespace internal
711} // namespace webrtc