OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/video/video_send_stream.h" | 10 #include "webrtc/video/video_send_stream.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 pad_up_to_bitrate_bps = | 286 pad_up_to_bitrate_bps = |
287 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps); | 287 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps); |
288 | 288 |
289 return pad_up_to_bitrate_bps; | 289 return pad_up_to_bitrate_bps; |
290 } | 290 } |
291 | 291 |
292 uint32_t CalculateOverheadRateBps(int packets_per_second, | 292 uint32_t CalculateOverheadRateBps(int packets_per_second, |
293 size_t overhead_bytes_per_packet, | 293 size_t overhead_bytes_per_packet, |
294 uint32_t max_overhead_bps) { | 294 uint32_t max_overhead_bps) { |
295 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") != | |
296 "Enabled") | |
297 return 0; | |
298 uint32_t overhead_bps = | 295 uint32_t overhead_bps = |
299 static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second); | 296 static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second); |
300 return std::min(overhead_bps, max_overhead_bps); | 297 return std::min(overhead_bps, max_overhead_bps); |
301 } | 298 } |
302 | 299 |
303 int CalculatePacketRate(uint32_t bitrate_bps, size_t packet_size_bytes) { | 300 int CalculatePacketRate(uint32_t bitrate_bps, size_t packet_size_bytes) { |
304 size_t packet_size_bits = 8 * packet_size_bytes; | 301 size_t packet_size_bits = 8 * packet_size_bytes; |
305 // Ceil for int value of bitrate_bps / packet_size_bits. | 302 // Ceil for int value of bitrate_bps / packet_size_bits. |
306 return static_cast<int>((bitrate_bps + packet_size_bits - 1) / | 303 return static_cast<int>((bitrate_bps + packet_size_bits - 1) / |
307 packet_size_bits); | 304 packet_size_bits); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 const RTPFragmentationHeader* fragmentation) override; | 388 const RTPFragmentationHeader* fragmentation) override; |
392 | 389 |
393 // Implements VideoBitrateAllocationObserver. | 390 // Implements VideoBitrateAllocationObserver. |
394 void OnBitrateAllocationUpdated(const BitrateAllocation& allocation) override; | 391 void OnBitrateAllocationUpdated(const BitrateAllocation& allocation) override; |
395 | 392 |
396 void ConfigureProtection(); | 393 void ConfigureProtection(); |
397 void ConfigureSsrcs(); | 394 void ConfigureSsrcs(); |
398 void SignalEncoderTimedOut(); | 395 void SignalEncoderTimedOut(); |
399 void SignalEncoderActive(); | 396 void SignalEncoderActive(); |
400 | 397 |
| 398 const bool send_side_bwe_with_overhead_; |
| 399 |
401 SendStatisticsProxy* const stats_proxy_; | 400 SendStatisticsProxy* const stats_proxy_; |
402 const VideoSendStream::Config* const config_; | 401 const VideoSendStream::Config* const config_; |
403 std::map<uint32_t, RtpState> suspended_ssrcs_; | 402 std::map<uint32_t, RtpState> suspended_ssrcs_; |
404 | 403 |
405 ProcessThread* module_process_thread_; | 404 ProcessThread* module_process_thread_; |
406 rtc::ThreadChecker module_process_thread_checker_; | 405 rtc::ThreadChecker module_process_thread_checker_; |
407 rtc::TaskQueue* const worker_queue_; | 406 rtc::TaskQueue* const worker_queue_; |
408 | 407 |
409 rtc::CriticalSection encoder_activity_crit_sect_; | 408 rtc::CriticalSection encoder_activity_crit_sect_; |
410 CheckEncoderActivityTask* check_encoder_activity_task_ | 409 CheckEncoderActivityTask* check_encoder_activity_task_ |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 CongestionController* congestion_controller, | 750 CongestionController* congestion_controller, |
752 PacketRouter* packet_router, | 751 PacketRouter* packet_router, |
753 BitrateAllocator* bitrate_allocator, | 752 BitrateAllocator* bitrate_allocator, |
754 SendDelayStats* send_delay_stats, | 753 SendDelayStats* send_delay_stats, |
755 VieRemb* remb, | 754 VieRemb* remb, |
756 ViEEncoder* vie_encoder, | 755 ViEEncoder* vie_encoder, |
757 RtcEventLog* event_log, | 756 RtcEventLog* event_log, |
758 const VideoSendStream::Config* config, | 757 const VideoSendStream::Config* config, |
759 int initial_encoder_max_bitrate, | 758 int initial_encoder_max_bitrate, |
760 std::map<uint32_t, RtpState> suspended_ssrcs) | 759 std::map<uint32_t, RtpState> suspended_ssrcs) |
761 : stats_proxy_(stats_proxy), | 760 : send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName( |
| 761 "WebRTC-SendSideBwe-WithOverhead") == "Enabled"), |
| 762 stats_proxy_(stats_proxy), |
762 config_(config), | 763 config_(config), |
763 suspended_ssrcs_(std::move(suspended_ssrcs)), | 764 suspended_ssrcs_(std::move(suspended_ssrcs)), |
764 module_process_thread_(nullptr), | 765 module_process_thread_(nullptr), |
765 worker_queue_(worker_queue), | 766 worker_queue_(worker_queue), |
766 check_encoder_activity_task_(nullptr), | 767 check_encoder_activity_task_(nullptr), |
767 call_stats_(call_stats), | 768 call_stats_(call_stats), |
768 congestion_controller_(congestion_controller), | 769 congestion_controller_(congestion_controller), |
769 packet_router_(packet_router), | 770 packet_router_(packet_router), |
770 bitrate_allocator_(bitrate_allocator), | 771 bitrate_allocator_(bitrate_allocator), |
771 remb_(remb), | 772 remb_(remb), |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, | 1220 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, |
1220 uint8_t fraction_loss, | 1221 uint8_t fraction_loss, |
1221 int64_t rtt, | 1222 int64_t rtt, |
1222 int64_t probing_interval_ms) { | 1223 int64_t probing_interval_ms) { |
1223 RTC_DCHECK_RUN_ON(worker_queue_); | 1224 RTC_DCHECK_RUN_ON(worker_queue_); |
1224 RTC_DCHECK(payload_router_.IsActive()) | 1225 RTC_DCHECK(payload_router_.IsActive()) |
1225 << "VideoSendStream::Start has not been called."; | 1226 << "VideoSendStream::Start has not been called."; |
1226 | 1227 |
1227 // Substract overhead from bitrate. | 1228 // Substract overhead from bitrate. |
1228 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1229 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1229 uint32_t payload_bitrate_bps = | 1230 uint32_t payload_bitrate_bps = bitrate_bps; |
1230 bitrate_bps - | 1231 if (send_side_bwe_with_overhead_) { |
1231 CalculateOverheadRateBps( | 1232 payload_bitrate_bps -= CalculateOverheadRateBps( |
1232 CalculatePacketRate(bitrate_bps, | 1233 CalculatePacketRate(bitrate_bps, |
1233 config_->rtp.max_packet_size + | 1234 config_->rtp.max_packet_size + |
1234 transport_overhead_bytes_per_packet_), | 1235 transport_overhead_bytes_per_packet_), |
1235 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, | 1236 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, |
1236 bitrate_bps); | 1237 bitrate_bps); |
| 1238 } |
1237 | 1239 |
1238 // Get the encoder target rate. It is the estimated network rate - | 1240 // Get the encoder target rate. It is the estimated network rate - |
1239 // protection overhead. | 1241 // protection overhead. |
1240 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( | 1242 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( |
1241 payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, | 1243 payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, |
1242 rtt); | 1244 rtt); |
1243 | 1245 |
1244 uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps( | 1246 uint32_t encoder_overhead_rate_bps = |
1245 CalculatePacketRate(encoder_target_rate_bps_, | 1247 send_side_bwe_with_overhead_ |
1246 config_->rtp.max_packet_size + | 1248 ? CalculateOverheadRateBps( |
1247 transport_overhead_bytes_per_packet_ - | 1249 CalculatePacketRate(encoder_target_rate_bps_, |
1248 overhead_bytes_per_packet_), | 1250 config_->rtp.max_packet_size + |
1249 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, | 1251 transport_overhead_bytes_per_packet_ - |
1250 bitrate_bps - encoder_target_rate_bps_); | 1252 overhead_bytes_per_packet_), |
| 1253 overhead_bytes_per_packet_ + |
| 1254 transport_overhead_bytes_per_packet_, |
| 1255 bitrate_bps - encoder_target_rate_bps_) |
| 1256 : 0; |
1251 | 1257 |
1252 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled | 1258 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled |
1253 // protection_bitrate includes overhead. | 1259 // protection_bitrate includes overhead. |
1254 uint32_t protection_bitrate = | 1260 uint32_t protection_bitrate = |
1255 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); | 1261 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); |
1256 | 1262 |
1257 encoder_target_rate_bps_ = | 1263 encoder_target_rate_bps_ = |
1258 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1264 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
1259 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1265 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); |
1260 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1266 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1328 std::min(config_->rtp.max_packet_size, | 1334 std::min(config_->rtp.max_packet_size, |
1329 kPathMTU - transport_overhead_bytes_per_packet_); | 1335 kPathMTU - transport_overhead_bytes_per_packet_); |
1330 | 1336 |
1331 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1337 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1332 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); | 1338 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
1333 } | 1339 } |
1334 } | 1340 } |
1335 | 1341 |
1336 } // namespace internal | 1342 } // namespace internal |
1337 } // namespace webrtc | 1343 } // namespace webrtc |
OLD | NEW |