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 do MTU discovery, so assume that we have the standard ethernet MTU. |
| 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 // Subtract total overhead (transport + rtp) from bitrate. |
1192 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1194 size_t rtp_overhead; |
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 (rtp_overhead >= config_->rtp.max_packet_size) { |
| 1202 LOG(LS_WARNING) << "RTP overhead (" << rtp_overhead |
| 1203 << " bytes)" << "exceeds maximum packet size (" |
| 1204 << config_->rtp.max_packet_size << " bytes)"; |
| 1205 |
| 1206 bitrate_bps = 0; |
| 1207 } else { |
| 1208 bitrate_bps = |
| 1209 static_cast<uint64_t>(bitrate_bps) * |
| 1210 (config_->rtp.max_packet_size - rtp_overhead) / |
| 1211 (config_->rtp.max_packet_size + transport_overhead_bytes_per_packet_); |
| 1212 } |
1199 } | 1213 } |
1200 | 1214 |
1201 // Get the encoder target rate. It is the estimated network rate - | 1215 // Get the encoder target rate. It is the estimated network rate - |
1202 // protection overhead. | 1216 // protection overhead. |
1203 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( | 1217 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( |
1204 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); | 1218 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); |
1205 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; | 1219 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; |
1206 | 1220 |
1207 encoder_target_rate_bps_ = | 1221 encoder_target_rate_bps_ = |
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); | 1222 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; | 1271 return 0; |
1258 } | 1272 } |
1259 | 1273 |
1260 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) { | 1274 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) { |
1261 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); | 1275 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); |
1262 overhead_bytes_per_packet_ = overhead_bytes_per_packet; | 1276 overhead_bytes_per_packet_ = overhead_bytes_per_packet; |
1263 } | 1277 } |
1264 | 1278 |
1265 void VideoSendStreamImpl::SetTransportOverhead( | 1279 void VideoSendStreamImpl::SetTransportOverhead( |
1266 int transport_overhead_bytes_per_packet) { | 1280 int transport_overhead_bytes_per_packet) { |
| 1281 if (transport_overhead_bytes_per_packet >= static_cast<int>(kPathMTU)) { |
| 1282 LOG(LS_ERROR) << "Transport overhead exceeds size of ethernet frame"; |
| 1283 return; |
| 1284 } |
| 1285 |
1267 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; | 1286 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; |
1268 RTC_DCHECK_LE(config_->rtp.max_packet_size, | 1287 |
1269 0xFFFFu + transport_overhead_bytes_per_packet); | 1288 congestion_controller_->SetTransportOverhead( |
1270 const uint16_t mtu = static_cast<uint16_t>( | 1289 transport_overhead_bytes_per_packet_); |
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); | 1290 |
| 1291 size_t rtp_packet_size = |
| 1292 std::min(config_->rtp.max_packet_size, |
| 1293 kPathMTU - transport_overhead_bytes_per_packet_); |
| 1294 |
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 1295 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); | 1296 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size); |
1274 rtp_rtcp->SetMaxTransferUnit(mtu); | |
1275 } | 1297 } |
1276 } | 1298 } |
1277 | 1299 |
1278 } // namespace internal | 1300 } // namespace internal |
1279 } // namespace webrtc | 1301 } // namespace webrtc |
OLD | NEW |