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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } else if (pad_to_min_bitrate) { | 282 } else if (pad_to_min_bitrate) { |
283 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps; | 283 pad_up_to_bitrate_bps = streams[0].min_bitrate_bps; |
284 } | 284 } |
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, |
| 293 size_t overhead_bytes_per_packet, |
| 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 = |
| 299 static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second); |
| 300 return std::min(overhead_bps, max_overhead_bps); |
| 301 } |
| 302 |
| 303 int CalculatePacketRate(uint32_t bitrate_bps, size_t packet_size_bytes) { |
| 304 size_t packet_size_bits = 8 * packet_size_bytes; |
| 305 // Ceil for int value of bitrate_bps / packet_size_bits. |
| 306 return static_cast<int>((bitrate_bps + packet_size_bits - 1) / |
| 307 packet_size_bits); |
| 308 } |
| 309 |
292 } // namespace | 310 } // namespace |
293 | 311 |
294 namespace internal { | 312 namespace internal { |
295 | 313 |
296 // VideoSendStreamImpl implements internal::VideoSendStream. | 314 // VideoSendStreamImpl implements internal::VideoSendStream. |
297 // It is created and destroyed on |worker_queue|. The intent is to decrease the | 315 // It is created and destroyed on |worker_queue|. The intent is to decrease the |
298 // need for locking and to ensure methods are called in sequence. | 316 // need for locking and to ensure methods are called in sequence. |
299 // Public methods except |DeliverRtcp| must be called on |worker_queue|. | 317 // Public methods except |DeliverRtcp| must be called on |worker_queue|. |
300 // DeliverRtcp is called on the libjingle worker thread or a network thread. | 318 // DeliverRtcp is called on the libjingle worker thread or a network thread. |
301 // An encoder may deliver frames through the EncodedImageCallback on an | 319 // An encoder may deliver frames through the EncodedImageCallback on an |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 } | 1214 } |
1197 | 1215 |
1198 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, | 1216 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, |
1199 uint8_t fraction_loss, | 1217 uint8_t fraction_loss, |
1200 int64_t rtt, | 1218 int64_t rtt, |
1201 int64_t probing_interval_ms) { | 1219 int64_t probing_interval_ms) { |
1202 RTC_DCHECK_RUN_ON(worker_queue_); | 1220 RTC_DCHECK_RUN_ON(worker_queue_); |
1203 RTC_DCHECK(payload_router_.IsActive()) | 1221 RTC_DCHECK(payload_router_.IsActive()) |
1204 << "VideoSendStream::Start has not been called."; | 1222 << "VideoSendStream::Start has not been called."; |
1205 | 1223 |
1206 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == | 1224 // Substract overhead from bitrate. |
1207 "Enabled") { | 1225 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1208 // Subtract total overhead (transport + rtp) from bitrate. | 1226 uint32_t payload_bitrate_bps = |
1209 size_t rtp_overhead; | 1227 bitrate_bps - |
1210 { | 1228 CalculateOverheadRateBps( |
1211 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1229 CalculatePacketRate(bitrate_bps, |
1212 rtp_overhead = overhead_bytes_per_packet_; | 1230 config_->rtp.max_packet_size + |
1213 } | 1231 transport_overhead_bytes_per_packet_), |
1214 RTC_CHECK_GE(rtp_overhead, 0); | 1232 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, |
1215 RTC_DCHECK_LT(rtp_overhead, config_->rtp.max_packet_size); | 1233 bitrate_bps); |
1216 if (rtp_overhead >= config_->rtp.max_packet_size) { | |
1217 LOG(LS_WARNING) << "RTP overhead (" << rtp_overhead << " bytes)" | |
1218 << "exceeds maximum packet size (" | |
1219 << config_->rtp.max_packet_size << " bytes)"; | |
1220 | |
1221 bitrate_bps = 0; | |
1222 } else { | |
1223 bitrate_bps = | |
1224 static_cast<uint32_t>(static_cast<uint64_t>(bitrate_bps) * | |
1225 (config_->rtp.max_packet_size - rtp_overhead) / | |
1226 (config_->rtp.max_packet_size + | |
1227 transport_overhead_bytes_per_packet_)); | |
1228 } | |
1229 } | |
1230 | 1234 |
1231 // Get the encoder target rate. It is the estimated network rate - | 1235 // Get the encoder target rate. It is the estimated network rate - |
1232 // protection overhead. | 1236 // protection overhead. |
1233 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( | 1237 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( |
1234 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); | 1238 payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, |
1235 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; | 1239 rtt); |
| 1240 |
| 1241 uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps( |
| 1242 CalculatePacketRate(encoder_target_rate_bps_, |
| 1243 config_->rtp.max_packet_size + |
| 1244 transport_overhead_bytes_per_packet_ - |
| 1245 overhead_bytes_per_packet_), |
| 1246 overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_, |
| 1247 bitrate_bps - encoder_target_rate_bps_); |
| 1248 |
| 1249 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled |
| 1250 // protection_bitrate includes overhead. |
| 1251 uint32_t protection_bitrate = |
| 1252 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); |
1236 | 1253 |
1237 encoder_target_rate_bps_ = | 1254 encoder_target_rate_bps_ = |
1238 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1255 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
1239 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1256 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); |
1240 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1257 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
1241 return protection_bitrate; | 1258 return protection_bitrate; |
1242 } | 1259 } |
1243 | 1260 |
1244 void VideoSendStreamImpl::EnableEncodedFrameRecording( | 1261 void VideoSendStreamImpl::EnableEncodedFrameRecording( |
1245 const std::vector<rtc::PlatformFile>& files, | 1262 const std::vector<rtc::PlatformFile>& files, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 std::min(config_->rtp.max_packet_size, | 1325 std::min(config_->rtp.max_packet_size, |
1309 kPathMTU - transport_overhead_bytes_per_packet_); | 1326 kPathMTU - transport_overhead_bytes_per_packet_); |
1310 | 1327 |
1311 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1328 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1312 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); | 1329 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
1313 } | 1330 } |
1314 } | 1331 } |
1315 | 1332 |
1316 } // namespace internal | 1333 } // namespace internal |
1317 } // namespace webrtc | 1334 } // namespace webrtc |
OLD | NEW |