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

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

Issue 2571463002: Fix for video protection_bitrate in BWE with overhead. (Closed)
Patch Set: Made unittest better and fixed a bug in the impl. Created 3 years, 11 months 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
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } else if (pad_to_min_bitrate) { 272 } else if (pad_to_min_bitrate) {
273 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps; 273 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps;
274 } 274 }
275 275
276 pad_up_to_bitrate_bps = 276 pad_up_to_bitrate_bps =
277 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps); 277 std::max(pad_up_to_bitrate_bps, min_transmit_bitrate_bps);
278 278
279 return pad_up_to_bitrate_bps; 279 return pad_up_to_bitrate_bps;
280 } 280 }
281 281
282 uint32_t CalculateOverheadRateBps(int packets_per_second,
283 size_t overhead_bytes_per_packet,
284 uint32_t max_overhead_bps) {
285 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") !=
286 "Enabled")
287 return 0;
288 uint32_t overhead_bps =
289 static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second);
290 return std::min(overhead_bps, max_overhead_bps);
291 }
292
293 int CalculatePacketRate(uint32_t bitrate_bps, size_t packet_size_bytes) {
294 int packet_size_bits = 8 * packet_size_bytes;
295 // Ceil for int value of bitrate_bps / packet_size_bits.
296 return (bitrate_bps + packet_size_bits - 1) / packet_size_bits;
297 }
298
282 } // namespace 299 } // namespace
283 300
284 namespace internal { 301 namespace internal {
285 302
286 // VideoSendStreamImpl implements internal::VideoSendStream. 303 // VideoSendStreamImpl implements internal::VideoSendStream.
287 // It is created and destroyed on |worker_queue|. The intent is to decrease the 304 // It is created and destroyed on |worker_queue|. The intent is to decrease the
288 // need for locking and to ensure methods are called in sequence. 305 // need for locking and to ensure methods are called in sequence.
289 // Public methods except |DeliverRtcp| must be called on |worker_queue|. 306 // Public methods except |DeliverRtcp| must be called on |worker_queue|.
290 // DeliverRtcp is called on the libjingle worker thread or a network thread. 307 // DeliverRtcp is called on the libjingle worker thread or a network thread.
291 // An encoder may deliver frames through the EncodedImageCallback on an 308 // An encoder may deliver frames through the EncodedImageCallback on an
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 } 1199 }
1183 1200
1184 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, 1201 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
1185 uint8_t fraction_loss, 1202 uint8_t fraction_loss,
1186 int64_t rtt, 1203 int64_t rtt,
1187 int64_t probing_interval_ms) { 1204 int64_t probing_interval_ms) {
1188 RTC_DCHECK_RUN_ON(worker_queue_); 1205 RTC_DCHECK_RUN_ON(worker_queue_);
1189 RTC_DCHECK(payload_router_.IsActive()) 1206 RTC_DCHECK(payload_router_.IsActive())
1190 << "VideoSendStream::Start has not been called."; 1207 << "VideoSendStream::Start has not been called.";
1191 1208
1192 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == 1209 // Substract overhead from bitrate.
1193 "Enabled") { 1210 rtc::CritScope lock(&overhead_bytes_per_packet_crit_);
1194 // Subtract total overhead (transport + rtp) from bitrate. 1211 uint32_t payload_bitrate_bps =
1195 size_t rtp_overhead; 1212 bitrate_bps -
1196 { 1213 CalculateOverheadRateBps(
1197 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); 1214 CalculatePacketRate(bitrate_bps,
1198 rtp_overhead = overhead_bytes_per_packet_; 1215 config_->rtp.max_packet_size +
1199 } 1216 transport_overhead_bytes_per_packet_),
1200 RTC_CHECK_GE(rtp_overhead, 0); 1217 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_,
1201 RTC_DCHECK_LT(rtp_overhead, config_->rtp.max_packet_size); 1218 bitrate_bps);
1202 if (rtp_overhead >= config_->rtp.max_packet_size) {
1203 LOG(LS_WARNING) << "RTP overhead (" << rtp_overhead << " bytes)"
1204 << "exceeds maximum packet size ("
1205 << config_->rtp.max_packet_size << " bytes)";
1206
1207 bitrate_bps = 0;
1208 } else {
1209 bitrate_bps =
1210 static_cast<uint32_t>(static_cast<uint64_t>(bitrate_bps) *
1211 (config_->rtp.max_packet_size - rtp_overhead) /
1212 (config_->rtp.max_packet_size +
1213 transport_overhead_bytes_per_packet_));
1214 }
1215 }
1216 1219
1217 // Get the encoder target rate. It is the estimated network rate - 1220 // Get the encoder target rate. It is the estimated network rate -
1218 // protection overhead. 1221 // protection overhead.
1219 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( 1222 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates(
1220 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); 1223 payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss,
1221 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; 1224 rtt);
1225
1226 uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps(
1227 CalculatePacketRate(encoder_target_rate_bps_,
1228 config_->rtp.max_packet_size +
1229 transport_overhead_bytes_per_packet_ -
1230 overhead_bytes_per_packet_),
1231 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_,
1232 bitrate_bps - encoder_target_rate_bps_);
1233
1234 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled
1235 // protection_bitrate includes overhead.
1236 uint32_t protection_bitrate =
1237 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps);
1222 1238
1223 encoder_target_rate_bps_ = 1239 encoder_target_rate_bps_ =
1224 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); 1240 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
1225 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); 1241 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt);
1226 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); 1242 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
1227 return protection_bitrate; 1243 return protection_bitrate;
1228 } 1244 }
1229 1245
1230 void VideoSendStreamImpl::EnableEncodedFrameRecording( 1246 void VideoSendStreamImpl::EnableEncodedFrameRecording(
1231 const std::vector<rtc::PlatformFile>& files, 1247 const std::vector<rtc::PlatformFile>& files,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 std::min(config_->rtp.max_packet_size, 1310 std::min(config_->rtp.max_packet_size,
1295 kPathMTU - transport_overhead_bytes_per_packet_); 1311 kPathMTU - transport_overhead_bytes_per_packet_);
1296 1312
1297 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 1313 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
1298 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); 1314 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size);
1299 } 1315 }
1300 } 1316 }
1301 1317
1302 } // namespace internal 1318 } // namespace internal
1303 } // namespace webrtc 1319 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/video/video_send_stream_tests.cc » ('j') | webrtc/video/video_send_stream_tests.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698