Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Side by Side Diff: webrtc/video/video_send_stream.cc

Issue 2589743002: Make OverheadObserver::OnOverheadChanged count RTP headers only (Closed)
Patch Set: Add explicit cast. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/voice_engine/channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 void SignalNetworkState(NetworkState state); 322 void SignalNetworkState(NetworkState state);
320 bool DeliverRtcp(const uint8_t* packet, size_t length); 323 bool DeliverRtcp(const uint8_t* packet, size_t length);
321 void Start(); 324 void Start();
322 void Stop(); 325 void Stop();
323 326
324 VideoSendStream::RtpStateMap GetRtpStates() const; 327 VideoSendStream::RtpStateMap GetRtpStates() const;
325 328
326 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files, 329 void EnableEncodedFrameRecording(const std::vector<rtc::PlatformFile>& files,
327 size_t byte_limit); 330 size_t byte_limit);
328 331
329 void SetTransportOverhead(int transport_overhead_per_packet); 332 void SetTransportOverhead(size_t transport_overhead_per_packet);
330 333
331 private: 334 private:
332 class CheckEncoderActivityTask; 335 class CheckEncoderActivityTask;
333 class EncoderReconfiguredTask; 336 class EncoderReconfiguredTask;
334 337
335 // Implements BitrateAllocatorObserver. 338 // Implements BitrateAllocatorObserver.
336 uint32_t OnBitrateUpdated(uint32_t bitrate_bps, 339 uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
337 uint8_t fraction_loss, 340 uint8_t fraction_loss,
338 int64_t rtt, 341 int64_t rtt,
339 int64_t probing_interval_ms) override; 342 int64_t probing_interval_ms) override;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 vie_encoder_->DeRegisterProcessThread(); 685 vie_encoder_->DeRegisterProcessThread();
683 VideoSendStream::RtpStateMap state_map; 686 VideoSendStream::RtpStateMap state_map;
684 send_stream_->DeRegisterProcessThread(); 687 send_stream_->DeRegisterProcessThread();
685 worker_queue_->PostTask( 688 worker_queue_->PostTask(
686 std::unique_ptr<rtc::QueuedTask>(new DestructAndGetRtpStateTask( 689 std::unique_ptr<rtc::QueuedTask>(new DestructAndGetRtpStateTask(
687 &state_map, std::move(send_stream_), &thread_sync_event_))); 690 &state_map, std::move(send_stream_), &thread_sync_event_)));
688 thread_sync_event_.Wait(rtc::Event::kForever); 691 thread_sync_event_.Wait(rtc::Event::kForever);
689 return state_map; 692 return state_map;
690 } 693 }
691 694
692 void VideoSendStream::SetTransportOverhead(int transport_overhead_per_packet) { 695 void VideoSendStream::SetTransportOverhead(
696 size_t transport_overhead_per_packet) {
693 RTC_DCHECK_RUN_ON(&thread_checker_); 697 RTC_DCHECK_RUN_ON(&thread_checker_);
694 VideoSendStreamImpl* send_stream = send_stream_.get(); 698 VideoSendStreamImpl* send_stream = send_stream_.get();
695 worker_queue_->PostTask([send_stream, transport_overhead_per_packet] { 699 worker_queue_->PostTask([send_stream, transport_overhead_per_packet] {
696 send_stream->SetTransportOverhead(transport_overhead_per_packet); 700 send_stream->SetTransportOverhead(transport_overhead_per_packet);
697 }); 701 });
698 } 702 }
699 703
700 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { 704 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
701 // Called on a network thread. 705 // Called on a network thread.
702 return send_stream_->DeliverRtcp(packet, length); 706 return send_stream_->DeliverRtcp(packet, length);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 805
802 ConfigureProtection(); 806 ConfigureProtection();
803 ConfigureSsrcs(); 807 ConfigureSsrcs();
804 808
805 // TODO(pbos): Should we set CNAME on all RTP modules? 809 // TODO(pbos): Should we set CNAME on all RTP modules?
806 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); 810 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str());
807 811
808 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 812 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
809 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); 813 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_);
810 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_); 814 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_);
811 rtp_rtcp->SetMaxTransferUnit( 815 rtp_rtcp->SetMaxRtpPacketSize(config_->rtp.max_packet_size);
812 static_cast<uint16_t>(config_->rtp.max_packet_size));
813 rtp_rtcp->RegisterVideoSendPayload( 816 rtp_rtcp->RegisterVideoSendPayload(
814 config_->encoder_settings.payload_type, 817 config_->encoder_settings.payload_type,
815 config_->encoder_settings.payload_name.c_str()); 818 config_->encoder_settings.payload_name.c_str());
816 } 819 }
817 820
818 RTC_DCHECK(config_->encoder_settings.encoder); 821 RTC_DCHECK(config_->encoder_settings.encoder);
819 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); 822 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0);
820 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); 823 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127);
821 824
822 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this)); 825 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this));
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, 1184 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
1182 uint8_t fraction_loss, 1185 uint8_t fraction_loss,
1183 int64_t rtt, 1186 int64_t rtt,
1184 int64_t probing_interval_ms) { 1187 int64_t probing_interval_ms) {
1185 RTC_DCHECK_RUN_ON(worker_queue_); 1188 RTC_DCHECK_RUN_ON(worker_queue_);
1186 RTC_DCHECK(payload_router_.IsActive()) 1189 RTC_DCHECK(payload_router_.IsActive())
1187 << "VideoSendStream::Start has not been called."; 1190 << "VideoSendStream::Start has not been called.";
1188 1191
1189 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") == 1192 if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") ==
1190 "Enabled") { 1193 "Enabled") {
1191 // Substract overhead from bitrate. 1194 // Subtract total overhead (transport + rtp) from bitrate.
1192 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); 1195 size_t rtp_overhead;
1193 int packets_per_second = 1196 {
1194 std::ceil(bitrate_bps / (8 * (config_->rtp.max_packet_size + 1197 rtc::CritScope lock(&overhead_bytes_per_packet_crit_);
1195 transport_overhead_bytes_per_packet_))); 1198 rtp_overhead = overhead_bytes_per_packet_;
1196 uint32_t overhead_bps = static_cast<uint32_t>( 1199 }
1197 8 * overhead_bytes_per_packet_ * packets_per_second); 1200 RTC_CHECK_GE(rtp_overhead, 0);
1198 bitrate_bps = overhead_bps > bitrate_bps ? 0u : bitrate_bps - overhead_bps; 1201 RTC_DCHECK_LT(rtp_overhead, config_->rtp.max_packet_size);
1202 if (rtp_overhead >= config_->rtp.max_packet_size) {
1203 LOG(LS_WARNING) << "RTP overhead (" << rtp_overhead << " bytes)"
1204 << "exceeds maximum packet size ("
1205 << config_->rtp.max_packet_size << " bytes)";
1206
1207 bitrate_bps = 0;
1208 } else {
1209 bitrate_bps =
1210 static_cast<uint32_t>(static_cast<uint64_t>(bitrate_bps) *
1211 (config_->rtp.max_packet_size - rtp_overhead) /
1212 (config_->rtp.max_packet_size +
1213 transport_overhead_bytes_per_packet_));
1214 }
1199 } 1215 }
1200 1216
1201 // Get the encoder target rate. It is the estimated network rate - 1217 // Get the encoder target rate. It is the estimated network rate -
1202 // protection overhead. 1218 // protection overhead.
1203 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( 1219 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates(
1204 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); 1220 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt);
1205 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; 1221 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_;
1206 1222
1207 encoder_target_rate_bps_ = 1223 encoder_target_rate_bps_ =
1208 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); 1224 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1272 }
1257 return 0; 1273 return 0;
1258 } 1274 }
1259 1275
1260 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) { 1276 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) {
1261 rtc::CritScope lock(&overhead_bytes_per_packet_crit_); 1277 rtc::CritScope lock(&overhead_bytes_per_packet_crit_);
1262 overhead_bytes_per_packet_ = overhead_bytes_per_packet; 1278 overhead_bytes_per_packet_ = overhead_bytes_per_packet;
1263 } 1279 }
1264 1280
1265 void VideoSendStreamImpl::SetTransportOverhead( 1281 void VideoSendStreamImpl::SetTransportOverhead(
1266 int transport_overhead_bytes_per_packet) { 1282 size_t transport_overhead_bytes_per_packet) {
1283 if (transport_overhead_bytes_per_packet >= static_cast<int>(kPathMTU)) {
1284 LOG(LS_ERROR) << "Transport overhead exceeds size of ethernet frame";
1285 return;
1286 }
1287
1267 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet; 1288 transport_overhead_bytes_per_packet_ = transport_overhead_bytes_per_packet;
1268 RTC_DCHECK_LE(config_->rtp.max_packet_size, 1289
1269 0xFFFFu + transport_overhead_bytes_per_packet); 1290 congestion_controller_->SetTransportOverhead(
1270 const uint16_t mtu = static_cast<uint16_t>( 1291 transport_overhead_bytes_per_packet_);
1271 config_->rtp.max_packet_size + transport_overhead_bytes_per_packet); 1292
1293 size_t rtp_packet_size =
1294 std::min(config_->rtp.max_packet_size,
1295 kPathMTU - transport_overhead_bytes_per_packet_);
1296
1272 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 1297 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
1273 rtp_rtcp->SetTransportOverhead(transport_overhead_bytes_per_packet); 1298 rtp_rtcp->SetMaxRtpPacketSize(rtp_packet_size);
1274 rtp_rtcp->SetMaxTransferUnit(mtu);
1275 } 1299 }
1276 } 1300 }
1277 1301
1278 } // namespace internal 1302 } // namespace internal
1279 } // namespace webrtc 1303 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/voice_engine/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698