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, | |
280 size_t packet_size_byte, | |
stefan-webrtc
2016/12/12 16:19:55
packet_size_bytes
michaelt
2016/12/13 13:07:16
Done.
| |
281 size_t overhead_byte_per_packet) { | |
stefan-webrtc
2016/12/12 16:19:55
overhead_bytes_per_packet or packet_overhead_bytes
michaelt
2016/12/13 13:07:16
Done.
| |
282 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") != | |
283 "Enabled") | |
284 return 0; | |
285 int packets_per_second = std::ceil(bitrate_bps / (8 * packet_size_byte)); | |
286 return static_cast<uint32_t>(8 * overhead_byte_per_packet * | |
287 packets_per_second); | |
288 } | |
289 | |
279 } // namespace | 290 } // namespace |
280 | 291 |
281 namespace internal { | 292 namespace internal { |
282 | 293 |
283 // VideoSendStreamImpl implements internal::VideoSendStream. | 294 // VideoSendStreamImpl implements internal::VideoSendStream. |
284 // It is created and destroyed on |worker_queue|. The intent is to decrease the | 295 // 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. | 296 // need for locking and to ensure methods are called in sequence. |
286 // Public methods except |DeliverRtcp| must be called on |worker_queue|. | 297 // Public methods except |DeliverRtcp| must be called on |worker_queue|. |
287 // DeliverRtcp is called on the libjingle worker thread or a network thread. | 298 // DeliverRtcp is called on the libjingle worker thread or a network thread. |
288 // An encoder may deliver frames through the EncodedImageCallback on an | 299 // An encoder may deliver frames through the EncodedImageCallback on an |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 } | 1190 } |
1180 | 1191 |
1181 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, | 1192 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, |
1182 uint8_t fraction_loss, | 1193 uint8_t fraction_loss, |
1183 int64_t rtt, | 1194 int64_t rtt, |
1184 int64_t probing_interval_ms) { | 1195 int64_t probing_interval_ms) { |
1185 RTC_DCHECK_RUN_ON(worker_queue_); | 1196 RTC_DCHECK_RUN_ON(worker_queue_); |
1186 RTC_DCHECK(payload_router_.IsActive()) | 1197 RTC_DCHECK(payload_router_.IsActive()) |
1187 << "VideoSendStream::Start has not been called."; | 1198 << "VideoSendStream::Start has not been called."; |
1188 | 1199 |
1189 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == | 1200 // Substract overhead from bitrate. |
1190 "Enabled") { | 1201 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1191 // Substract overhead from bitrate. | 1202 uint32_t overhead_bps = CalculateOverheadRateBps( |
1192 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1203 bitrate_bps, |
1193 int packets_per_second = | 1204 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet_, |
1194 std::ceil(bitrate_bps / (8 * (config_->rtp.max_packet_size + | 1205 overhead_bytes_per_packet_); |
1195 transport_overhead_bytes_per_packet_))); | 1206 bitrate_bps = overhead_bps > bitrate_bps ? 0u : bitrate_bps - overhead_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 | 1207 |
1201 // Get the encoder target rate. It is the estimated network rate - | 1208 // Get the encoder target rate. It is the estimated network rate - |
1202 // protection overhead. | 1209 // protection overhead. |
1203 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( | 1210 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( |
1204 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); | 1211 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); |
1205 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; | 1212 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; |
1206 | 1213 |
1207 encoder_target_rate_bps_ = | 1214 encoder_target_rate_bps_ = |
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1215 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
1209 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); | 1216 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); |
1210 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); | 1217 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); |
1211 return protection_bitrate; | 1218 // Add overhead to the protection_bitrate |
1219 return protection_bitrate + | |
1220 CalculateOverheadRateBps(protection_bitrate, | |
1221 config_->rtp.max_packet_size + | |
1222 transport_overhead_bytes_per_packet_ - | |
1223 overhead_bytes_per_packet_, | |
1224 overhead_bytes_per_packet_); | |
stefan-webrtc
2016/12/12 16:19:55
The overhead for FEC isn't the same as the overhea
michaelt
2016/12/13 08:07:09
Do you think it's not worth to take the overhead i
stefan-webrtc
2016/12/13 08:16:30
The difference in overhead. Do you agree?
michaelt
2016/12/13 13:07:16
I don't know how the video FEC packets are build.
stefan-webrtc
2016/12/13 13:26:04
Instead of doing this, maybe we should do:
protec
michaelt
2016/12/20 10:15:56
Did something similar to your idea pleas take a lo
| |
1212 } | 1225 } |
1213 | 1226 |
1214 void VideoSendStreamImpl::EnableEncodedFrameRecording( | 1227 void VideoSendStreamImpl::EnableEncodedFrameRecording( |
1215 const std::vector<rtc::PlatformFile>& files, | 1228 const std::vector<rtc::PlatformFile>& files, |
1216 size_t byte_limit) { | 1229 size_t byte_limit) { |
1217 { | 1230 { |
1218 rtc::CritScope lock(&ivf_writers_crit_); | 1231 rtc::CritScope lock(&ivf_writers_crit_); |
1219 for (unsigned int i = 0; i < kMaxSimulcastStreams; ++i) { | 1232 for (unsigned int i = 0; i < kMaxSimulcastStreams; ++i) { |
1220 if (i < files.size()) { | 1233 if (i < files.size()) { |
1221 file_writers_[i] = IvfFileWriter::Wrap(rtc::File(files[i]), byte_limit); | 1234 file_writers_[i] = IvfFileWriter::Wrap(rtc::File(files[i]), byte_limit); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1270 const uint16_t mtu = static_cast<uint16_t>( | 1283 const uint16_t mtu = static_cast<uint16_t>( |
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); | 1284 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); |
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1285 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); | 1286 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); |
1274 rtp_rtcp->SetMaxTransferUnit(mtu); | 1287 rtp_rtcp->SetMaxTransferUnit(mtu); |
1275 } | 1288 } |
1276 } | 1289 } |
1277 | 1290 |
1278 } // namespace internal | 1291 } // namespace internal |
1279 } // namespace webrtc | 1292 } // namespace webrtc |
OLD | NEW |