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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, | |
minyue-webrtc
2017/01/10 22:17:31
not totally obvious to me that the bitrate_bps and
michaelt
2017/01/11 08:55:15
Done.
| |
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)); | |
minyue-webrtc
2017/01/10 22:17:31
I don't ceil can do anything. it only makes sense
michaelt
2017/01/11 08:55:15
Good catch. Thanks.
| |
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; | |
minyue-webrtc
2017/01/10 22:17:31
I'd prefer std::min(xxx, xxx)
michaelt
2017/01/11 08:55:15
Done.
| |
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 Loading... | |
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 // When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled | |
1223 // protection_bitrate includes overhead. | |
1224 uint32_t protection_bitrate = | |
1225 bitrate_bps - (encoder_target_rate_bps_ + encoder_overhead_rate_bps); | |
1206 | 1226 |
1207 encoder_target_rate_bps_ = | 1227 encoder_target_rate_bps_ = |
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1228 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
1209 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1229 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); |
1210 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1230 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
1211 return protection_bitrate; | 1231 return protection_bitrate; |
1212 } | 1232 } |
1213 | 1233 |
1214 void VideoSendStreamImpl::EnableEncodedFrameRecording( | 1234 void VideoSendStreamImpl::EnableEncodedFrameRecording( |
1215 const std::vector<rtc::PlatformFile>& files, | 1235 const std::vector<rtc::PlatformFile>& files, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 const uint16_t mtu = static_cast<uint16_t>( | 1290 const uint16_t mtu = static_cast<uint16_t>( |
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); | 1291 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); |
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1292 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); | 1293 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); |
1274 rtp_rtcp->SetMaxTransferUnit(mtu); | 1294 rtp_rtcp->SetMaxTransferUnit(mtu); |
1275 } | 1295 } |
1276 } | 1296 } |
1277 | 1297 |
1278 } // namespace internal | 1298 } // namespace internal |
1279 } // namespace webrtc | 1299 } // namespace webrtc |
OLD | NEW |