Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: webrtc/video/video_send_stream.cc

Issue 2571463002: Fix for video protection_bitrate in BWE with overhead. (Closed)
Patch Set: Response to comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } else if (pad_to_min_bitrate) { 269 } else if (pad_to_min_bitrate) {
270 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps; 270 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps;
271 } 271 }
272 272
273 pad_up_to_bitrate_bps = 273 pad_up_to_bitrate_bps =
274 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps); 274 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps);
275 275
276 return pad_up_to_bitrate_bps; 276 return pad_up_to_bitrate_bps;
277 } 277 }
278 278
279 uint32_t CalculateOverheadRateBps(uint32_t bitrate_bps,
280 size_t packet_size_bytes,
281 size_t overhead_bytes_per_packet,
282 uint32_t max_overhead_bps) {
283 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") !=
284 "Enabled")
285 return 0;
286 int packets_per_second = std::ceil(bitrate_bps / (8 * packet_size_bytes));
287 uint32_t overhead_bps =
288 static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second);
289 return overhead_bps > max_overhead_bps ? max_overhead_bps : overhead_bps;
290 }
291
279 } // namespace 292 } // namespace
280 293
281 namespace internal { 294 namespace internal {
282 295
283 // VideoSendStreamImpl implements internal::VideoSendStream. 296 // VideoSendStreamImpl implements internal::VideoSendStream.
284 // It is created and destroyed on |worker_queue|. The intent is to decrease the 297 // It is created and destroyed on |worker_queue|. The intent is to decrease the
285 // need for locking and to ensure methods are called in sequence. 298 // need for locking and to ensure methods are called in sequence.
286 // Public methods except |DeliverRtcp| must be called on |worker_queue|. 299 // Public methods except |DeliverRtcp| must be called on |worker_queue|.
287 // DeliverRtcp is called on the libjingle worker thread or a network thread. 300 // DeliverRtcp is called on the libjingle worker thread or a network thread.
288 // An encoder may deliver frames through the EncodedImageCallback on an 301 // An encoder may deliver frames through the EncodedImageCallback on an
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 } 1192 }
1180 1193
1181 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, 1194 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
1182 uint8_t fraction_loss, 1195 uint8_t fraction_loss,
1183 int64_t rtt, 1196 int64_t rtt,
1184 int64_t probing_interval_ms) { 1197 int64_t probing_interval_ms) {
1185 RTC_DCHECK_RUN_ON(worker_queue_); 1198 RTC_DCHECK_RUN_ON(worker_queue_);
1186 RTC_DCHECK(payload_router_.IsActive()) 1199 RTC_DCHECK(payload_router_.IsActive())
1187 << "VideoSendStream::Start has not been called."; 1200 << "VideoSendStream::Start has not been called.";
1188 1201
1189 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == 1202 // Substract overhead from bitrate.
1190 "Enabled") { 1203 rtc::CritScope lock(&overhead_bytes_per_packet_crit_);
1191 // Substract overhead from bitrate. 1204 uint32_t payload_bitrate_bps =
1192 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); 1205 bitrate_bps - CalculateOverheadRateBps(
1193 int packets_per_second = 1206 bitrate_bps, config_->rtp.max_packet_size +
1194 std::ceil(bitrate_bps / (8 * (config_->rtp.max_packet_size + 1207 transport_overhead_bytes_per_packet_,
1195 transport_overhead_bytes_per_packet_))); 1208 overhead_bytes_per_packet_, bitrate_bps);
1196 uint32_t overhead_bps = static_cast<uint32_t>(
1197 8 * overhead_bytes_per_packet_ * packets_per_second);
1198 bitrate_bps = overhead_bps > bitrate_bps ? 0u : bitrate_bps - overhead_bps;
1199 }
1200 1209
1201 // Get the encoder target rate. It is the estimated network rate - 1210 // Get the encoder target rate. It is the estimated network rate -
1202 // protection overhead. 1211 // protection overhead.
1203 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( 1212 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates(
1204 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); 1213 payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss,
1205 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; 1214 rtt);
1215
1216 uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps(
1217 encoder_target_rate_bps_,
1218 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet_ -
1219 overhead_bytes_per_packet_,
1220 overhead_bytes_per_packet_, bitrate_bps - encoder_target_rate_bps_);
1221
1222 uint32_t protection_bitrate =
stefan-webrtc 2016/12/22 11:38:41 So this is the protection bitrate including overhe
michaelt 2016/12/22 14:14:14 I'm not sure about this since it would just includ
stefan-webrtc 2017/01/10 15:28:13 Yes, please add a comment in that case.
michaelt 2017/01/10 16:31:53 Done.
1223 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps);
1206 1224
1207 encoder_target_rate_bps_ = 1225 encoder_target_rate_bps_ =
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); 1226 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
1209 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); 1227 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt);
1210 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); 1228 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
1211 return protection_bitrate; 1229 return protection_bitrate;
1212 } 1230 }
1213 1231
1214 void VideoSendStreamImpl::EnableEncodedFrameRecording( 1232 void VideoSendStreamImpl::EnableEncodedFrameRecording(
1215 const std::vector<rtc::PlatformFile>& files, 1233 const std::vector<rtc::PlatformFile>& files,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 const uint16_t mtu = static_cast<uint16_t>( 1288 const uint16_t mtu = static_cast<uint16_t>(
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); 1289 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet);
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 1290 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); 1291 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet);
1274 rtp_rtcp->SetMaxTransferUnit(mtu); 1292 rtp_rtcp->SetMaxTransferUnit(mtu);
1275 } 1293 }
1276 } 1294 }
1277 1295
1278 } // namespace internal 1296 } // namespace internal
1279 } // namespace webrtc 1297 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698