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 21 matching lines...) Expand all Loading... | |
32 #include "webrtc/system_wrappers/include/field_trial.h" | 32 #include "webrtc/system_wrappers/include/field_trial.h" |
33 #include "webrtc/video/call_stats.h" | 33 #include "webrtc/video/call_stats.h" |
34 #include "webrtc/video/vie_remb.h" | 34 #include "webrtc/video/vie_remb.h" |
35 #include "webrtc/video_send_stream.h" | 35 #include "webrtc/video_send_stream.h" |
36 | 36 |
37 namespace webrtc { | 37 namespace webrtc { |
38 | 38 |
39 static const int kMinSendSidePacketHistorySize = 600; | 39 static const int kMinSendSidePacketHistorySize = 600; |
40 namespace { | 40 namespace { |
41 | 41 |
42 // We don't to MTU discovery, so assume that we have the standard ethernet MTU. | |
stefan-webrtc
2016/12/20 13:05:01
we don't do
nisse-webrtc
2016/12/20 13:38:13
Done.
| |
43 const size_t kPathMTU = 1500; | |
44 | |
42 std::vector<RtpRtcp*> CreateRtpRtcpModules( | 45 std::vector<RtpRtcp*> CreateRtpRtcpModules( |
43 Transport* outgoing_transport, | 46 Transport* outgoing_transport, |
44 RtcpIntraFrameObserver* intra_frame_callback, | 47 RtcpIntraFrameObserver* intra_frame_callback, |
45 RtcpBandwidthObserver* bandwidth_callback, | 48 RtcpBandwidthObserver* bandwidth_callback, |
46 TransportFeedbackObserver* transport_feedback_callback, | 49 TransportFeedbackObserver* transport_feedback_callback, |
47 RtcpRttStats* rtt_stats, | 50 RtcpRttStats* rtt_stats, |
48 RtpPacketSender* paced_sender, | 51 RtpPacketSender* paced_sender, |
49 TransportSequenceNumberAllocator* transport_sequence_number_allocator, | 52 TransportSequenceNumberAllocator* transport_sequence_number_allocator, |
50 FlexfecSender* flexfec_sender, | 53 FlexfecSender* flexfec_sender, |
51 SendStatisticsProxy* stats_proxy, | 54 SendStatisticsProxy* stats_proxy, |
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 | 804 |
802 ConfigureProtection(); | 805 ConfigureProtection(); |
803 ConfigureSsrcs(); | 806 ConfigureSsrcs(); |
804 | 807 |
805 // TODO(pbos): Should we set CNAME on all RTP modules? | 808 // TODO(pbos): Should we set CNAME on all RTP modules? |
806 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); | 809 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); |
807 | 810 |
808 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 811 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
809 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); | 812 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); |
810 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_); | 813 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_); |
811 rtp_rtcp->SetMaxTransferUnit( | 814 rtp_rtcp->SetMaxRtpPacketSize(config_->rtp.max_packet_size); |
812 static_cast<uint16_t>(config_->rtp.max_packet_size)); | |
813 rtp_rtcp->RegisterVideoSendPayload( | 815 rtp_rtcp->RegisterVideoSendPayload( |
814 config_->encoder_settings.payload_type, | 816 config_->encoder_settings.payload_type, |
815 config_->encoder_settings.payload_name.c_str()); | 817 config_->encoder_settings.payload_name.c_str()); |
816 } | 818 } |
817 | 819 |
818 RTC_DCHECK(config_->encoder_settings.encoder); | 820 RTC_DCHECK(config_->encoder_settings.encoder); |
819 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); | 821 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); |
820 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); | 822 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); |
821 | 823 |
822 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this)); | 824 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this)); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1181 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, | 1183 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, |
1182 uint8_t fraction_loss, | 1184 uint8_t fraction_loss, |
1183 int64_t rtt, | 1185 int64_t rtt, |
1184 int64_t probing_interval_ms) { | 1186 int64_t probing_interval_ms) { |
1185 RTC_DCHECK_RUN_ON(worker_queue_); | 1187 RTC_DCHECK_RUN_ON(worker_queue_); |
1186 RTC_DCHECK(payload_router_.IsActive()) | 1188 RTC_DCHECK(payload_router_.IsActive()) |
1187 << "VideoSendStream::Start has not been called."; | 1189 << "VideoSendStream::Start has not been called."; |
1188 | 1190 |
1189 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == | 1191 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == |
1190 "Enabled") { | 1192 "Enabled") { |
1191 // Substract overhead from bitrate. | 1193 // Substract total overhead (transport + rtp) from bitrate. |
stefan-webrtc
2016/12/20 13:05:01
Subtract
nisse-webrtc
2016/12/20 13:38:13
Done.
| |
1192 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1194 int rtp_overhead; |
stefan-webrtc
2016/12/20 13:05:01
Should probably change this to a size_t to avoid c
nisse-webrtc
2016/12/20 13:38:13
Done. (For some reason I thought the overhead_byte
| |
1193 int packets_per_second = | 1195 { |
1194 std::ceil(bitrate_bps / (8 * (config_->rtp.max_packet_size + | 1196 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1195 transport_overhead_bytes_per_packet_))); | 1197 rtp_overhead = overhead_bytes_per_packet_; |
1196 uint32_t overhead_bps = static_cast<uint32_t>( | 1198 } |
1197 8 * overhead_bytes_per_packet_ * packets_per_second); | 1199 RTC_CHECK_GE(rtp_overhead, 0); |
1198 bitrate_bps = overhead_bps > bitrate_bps ? 0u : bitrate_bps - overhead_bps; | 1200 RTC_DCHECK_LT(rtp_overhead, config_->rtp.max_packet_size); |
1201 if (static_cast<size_t>(rtp_overhead) >= config_->rtp.max_packet_size) { | |
1202 bitrate_bps = 0; | |
stefan-webrtc
2016/12/20 13:05:01
I would log a warning if this ever happens... :)
nisse-webrtc
2016/12/20 13:38:13
Done.
| |
1203 } else { | |
1204 bitrate_bps = | |
1205 static_cast<uint64_t>(bitrate_bps) * | |
1206 (config_->rtp.max_packet_size - rtp_overhead) / | |
1207 (config_->rtp.max_packet_size + transport_overhead_bytes_per_packet_); | |
1208 } | |
1199 } | 1209 } |
1200 | 1210 |
1201 // Get the encoder target rate. It is the estimated network rate - | 1211 // Get the encoder target rate. It is the estimated network rate - |
1202 // protection overhead. | 1212 // protection overhead. |
1203 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( | 1213 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( |
1204 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); | 1214 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); |
1205 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; | 1215 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; |
1206 | 1216 |
1207 encoder_target_rate_bps_ = | 1217 encoder_target_rate_bps_ = |
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1218 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1257 return 0; | 1267 return 0; |
1258 } | 1268 } |
1259 | 1269 |
1260 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) { | 1270 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) { |
1261 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1271 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1262 overhead_bytes_per_packet_ = overhead_bytes_per_packet; | 1272 overhead_bytes_per_packet_ = overhead_bytes_per_packet; |
1263 } | 1273 } |
1264 | 1274 |
1265 void VideoSendStreamImpl::SetTransportOverhead( | 1275 void VideoSendStreamImpl::SetTransportOverhead( |
1266 int transport_overhead_bytes_per_packet) { | 1276 int transport_overhead_bytes_per_packet) { |
1277 if (transport_overhead_bytes_per_packet >= static_cast<int>(kPathMTU)) { | |
1278 LOG(LS_ERROR) << "transport_overhead exceeds size of ethrnet frame"; | |
stefan-webrtc
2016/12/20 13:05:01
"Transport overhead exceeds size of ethernet frame
nisse-webrtc
2016/12/20 13:38:13
Done.
| |
1279 return; | |
1280 } | |
1281 | |
1267 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; | 1282 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; |
1268 RTC_DCHECK_LE(config_->rtp.max_packet_size, | 1283 |
1269 0xFFFFu + transport_overhead_bytes_per_packet); | 1284 congestion_controller_->SetTransportOverhead( |
1270 const uint16_t mtu = static_cast<uint16_t>( | 1285 transport_overhead_bytes_per_packet_); |
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); | 1286 |
1287 size_t rtp_packet_size = | |
1288 std::min(config_->rtp.max_packet_size, | |
1289 kPathMTU - transport_overhead_bytes_per_packet_); | |
1290 | |
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1291 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); | 1292 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
1274 rtp_rtcp->SetMaxTransferUnit(mtu); | |
1275 } | 1293 } |
1276 } | 1294 } |
1277 | 1295 |
1278 } // namespace internal | 1296 } // namespace internal |
1279 } // namespace webrtc | 1297 } // namespace webrtc |
OLD | NEW |