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

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

Issue 2517243005: Remove overhead from video bitrate. (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 RtcpBandwidthObserver* bandwidth_callback, 42 RtcpBandwidthObserver* bandwidth_callback,
43 TransportFeedbackObserver* transport_feedback_callback, 43 TransportFeedbackObserver* transport_feedback_callback,
44 RtcpRttStats* rtt_stats, 44 RtcpRttStats* rtt_stats,
45 RtpPacketSender* paced_sender, 45 RtpPacketSender* paced_sender,
46 TransportSequenceNumberAllocator* transport_sequence_number_allocator, 46 TransportSequenceNumberAllocator* transport_sequence_number_allocator,
47 FlexfecSender* flexfec_sender, 47 FlexfecSender* flexfec_sender,
48 SendStatisticsProxy* stats_proxy, 48 SendStatisticsProxy* stats_proxy,
49 SendDelayStats* send_delay_stats, 49 SendDelayStats* send_delay_stats,
50 RtcEventLog* event_log, 50 RtcEventLog* event_log,
51 RateLimiter* retransmission_rate_limiter, 51 RateLimiter* retransmission_rate_limiter,
52 OverheadObserver* overhead_observer,
52 size_t num_modules) { 53 size_t num_modules) {
53 RTC_DCHECK_GT(num_modules, 0u); 54 RTC_DCHECK_GT(num_modules, 0u);
54 RtpRtcp::Configuration configuration; 55 RtpRtcp::Configuration configuration;
55 ReceiveStatistics* null_receive_statistics = configuration.receive_statistics; 56 ReceiveStatistics* null_receive_statistics = configuration.receive_statistics;
56 configuration.audio = false; 57 configuration.audio = false;
57 configuration.receiver_only = false; 58 configuration.receiver_only = false;
58 configuration.flexfec_sender = flexfec_sender; 59 configuration.flexfec_sender = flexfec_sender;
59 configuration.receive_statistics = null_receive_statistics; 60 configuration.receive_statistics = null_receive_statistics;
60 configuration.outgoing_transport = outgoing_transport; 61 configuration.outgoing_transport = outgoing_transport;
61 configuration.intra_frame_callback = intra_frame_callback; 62 configuration.intra_frame_callback = intra_frame_callback;
62 configuration.bandwidth_callback = bandwidth_callback; 63 configuration.bandwidth_callback = bandwidth_callback;
63 configuration.transport_feedback_callback = transport_feedback_callback; 64 configuration.transport_feedback_callback = transport_feedback_callback;
64 configuration.rtt_stats = rtt_stats; 65 configuration.rtt_stats = rtt_stats;
65 configuration.rtcp_packet_type_counter_observer = stats_proxy; 66 configuration.rtcp_packet_type_counter_observer = stats_proxy;
66 configuration.paced_sender = paced_sender; 67 configuration.paced_sender = paced_sender;
67 configuration.transport_sequence_number_allocator = 68 configuration.transport_sequence_number_allocator =
68 transport_sequence_number_allocator; 69 transport_sequence_number_allocator;
69 configuration.send_bitrate_observer = stats_proxy; 70 configuration.send_bitrate_observer = stats_proxy;
70 configuration.send_frame_count_observer = stats_proxy; 71 configuration.send_frame_count_observer = stats_proxy;
71 configuration.send_side_delay_observer = stats_proxy; 72 configuration.send_side_delay_observer = stats_proxy;
72 configuration.send_packet_observer = send_delay_stats; 73 configuration.send_packet_observer = send_delay_stats;
73 configuration.event_log = event_log; 74 configuration.event_log = event_log;
74 configuration.retransmission_rate_limiter = retransmission_rate_limiter; 75 configuration.retransmission_rate_limiter = retransmission_rate_limiter;
75 76 configuration.overhead_observer = overhead_observer;
76 std::vector<RtpRtcp*> modules; 77 std::vector<RtpRtcp*> modules;
77 for (size_t i = 0; i < num_modules; ++i) { 78 for (size_t i = 0; i < num_modules; ++i) {
78 RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp(configuration); 79 RtpRtcp* rtp_rtcp = RtpRtcp::CreateRtpRtcp(configuration);
79 rtp_rtcp->SetSendingStatus(false); 80 rtp_rtcp->SetSendingStatus(false);
80 rtp_rtcp->SetSendingMediaStatus(false); 81 rtp_rtcp->SetSendingMediaStatus(false);
81 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound); 82 rtp_rtcp->SetRTCPStatus(RtcpMode::kCompound);
82 modules.push_back(rtp_rtcp); 83 modules.push_back(rtp_rtcp);
83 } 84 }
84 return modules; 85 return modules;
85 } 86 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 namespace internal { 278 namespace internal {
278 279
279 // VideoSendStreamImpl implements internal::VideoSendStream. 280 // VideoSendStreamImpl implements internal::VideoSendStream.
280 // It is created and destroyed on |worker_queue|. The intent is to decrease the 281 // It is created and destroyed on |worker_queue|. The intent is to decrease the
281 // need for locking and to ensure methods are called in sequence. 282 // need for locking and to ensure methods are called in sequence.
282 // Public methods except |DeliverRtcp| must be called on |worker_queue|. 283 // Public methods except |DeliverRtcp| must be called on |worker_queue|.
283 // DeliverRtcp is called on the libjingle worker thread or a network thread. 284 // DeliverRtcp is called on the libjingle worker thread or a network thread.
284 // An encoder may deliver frames through the EncodedImageCallback on an 285 // An encoder may deliver frames through the EncodedImageCallback on an
285 // arbitrary thread. 286 // arbitrary thread.
286 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver, 287 class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
288 public webrtc::OverheadObserver,
287 public webrtc::VCMProtectionCallback, 289 public webrtc::VCMProtectionCallback,
288 public ViEEncoder::EncoderSink { 290 public ViEEncoder::EncoderSink {
289 public: 291 public:
290 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy, 292 VideoSendStreamImpl(SendStatisticsProxy* stats_proxy,
291 rtc::TaskQueue* worker_queue, 293 rtc::TaskQueue* worker_queue,
292 CallStats* call_stats, 294 CallStats* call_stats,
293 CongestionController* congestion_controller, 295 CongestionController* congestion_controller,
294 BitrateAllocator* bitrate_allocator, 296 BitrateAllocator* bitrate_allocator,
295 SendDelayStats* send_delay_stats, 297 SendDelayStats* send_delay_stats,
296 VieRemb* remb, 298 VieRemb* remb,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 uint8_t fraction_loss, 332 uint8_t fraction_loss,
331 int64_t rtt) override; 333 int64_t rtt) override;
332 334
333 // Implements webrtc::VCMProtectionCallback. 335 // Implements webrtc::VCMProtectionCallback.
334 int ProtectionRequest(const FecProtectionParams* delta_params, 336 int ProtectionRequest(const FecProtectionParams* delta_params,
335 const FecProtectionParams* key_params, 337 const FecProtectionParams* key_params,
336 uint32_t* sent_video_rate_bps, 338 uint32_t* sent_video_rate_bps,
337 uint32_t* sent_nack_rate_bps, 339 uint32_t* sent_nack_rate_bps,
338 uint32_t* sent_fec_rate_bps) override; 340 uint32_t* sent_fec_rate_bps) override;
339 341
342 // Implements OverheadObserver.
343 void OnOverheadChanged(size_t overhead_bytes_per_packet) override;
344
340 void OnEncoderConfigurationChanged(std::vector<VideoStream> streams, 345 void OnEncoderConfigurationChanged(std::vector<VideoStream> streams,
341 int min_transmit_bitrate_bps) override; 346 int min_transmit_bitrate_bps) override;
342 347
343 // Implements EncodedImageCallback. The implementation routes encoded frames 348 // Implements EncodedImageCallback. The implementation routes encoded frames
344 // to the |payload_router_| and |config.pre_encode_callback| if set. 349 // to the |payload_router_| and |config.pre_encode_callback| if set.
345 // Called on an arbitrary encoder callback thread. 350 // Called on an arbitrary encoder callback thread.
346 EncodedImageCallback::Result OnEncodedImage( 351 EncodedImageCallback::Result OnEncodedImage(
347 const EncodedImage& encoded_image, 352 const EncodedImage& encoded_image,
348 const CodecSpecificInfo* codec_specific_info, 353 const CodecSpecificInfo* codec_specific_info,
349 const RTPFragmentationHeader* fragmentation) override; 354 const RTPFragmentationHeader* fragmentation) override;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 const std::vector<RtpRtcp*> rtp_rtcp_modules_; 396 const std::vector<RtpRtcp*> rtp_rtcp_modules_;
392 PayloadRouter payload_router_; 397 PayloadRouter payload_router_;
393 398
394 // |weak_ptr_| to our self. This is used since we can not call 399 // |weak_ptr_| to our self. This is used since we can not call
395 // |weak_ptr_factory_.GetWeakPtr| from multiple sequences but it is ok to copy 400 // |weak_ptr_factory_.GetWeakPtr| from multiple sequences but it is ok to copy
396 // an existing WeakPtr. 401 // an existing WeakPtr.
397 rtc::WeakPtr<VideoSendStreamImpl> weak_ptr_; 402 rtc::WeakPtr<VideoSendStreamImpl> weak_ptr_;
398 // |weak_ptr_factory_| must be declared last to make sure all WeakPtr's are 403 // |weak_ptr_factory_| must be declared last to make sure all WeakPtr's are
399 // invalidated before any other members are destroyed. 404 // invalidated before any other members are destroyed.
400 rtc::WeakPtrFactory<VideoSendStreamImpl> weak_ptr_factory_; 405 rtc::WeakPtrFactory<VideoSendStreamImpl> weak_ptr_factory_;
406
407 float payload_fraction_;
408 size_t transport_overhead_per_packet_;
401 }; 409 };
402 410
403 // TODO(tommi): See if there's a more elegant way to create a task that creates 411 // TODO(tommi): See if there's a more elegant way to create a task that creates
404 // an object on the correct task queue. 412 // an object on the correct task queue.
405 class VideoSendStream::ConstructionTask : public rtc::QueuedTask { 413 class VideoSendStream::ConstructionTask : public rtc::QueuedTask {
406 public: 414 public:
407 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream, 415 ConstructionTask(std::unique_ptr<VideoSendStreamImpl>* send_stream,
408 rtc::Event* done_event, 416 rtc::Event* done_event,
409 SendStatisticsProxy* stats_proxy, 417 SendStatisticsProxy* stats_proxy,
410 ViEEncoder* vie_encoder, 418 ViEEncoder* vie_encoder,
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 bandwidth_observer_.get(), 735 bandwidth_observer_.get(),
728 congestion_controller_->GetTransportFeedbackObserver(), 736 congestion_controller_->GetTransportFeedbackObserver(),
729 call_stats_->rtcp_rtt_stats(), 737 call_stats_->rtcp_rtt_stats(),
730 congestion_controller_->pacer(), 738 congestion_controller_->pacer(),
731 congestion_controller_->packet_router(), 739 congestion_controller_->packet_router(),
732 flexfec_sender_.get(), 740 flexfec_sender_.get(),
733 stats_proxy_, 741 stats_proxy_,
734 send_delay_stats, 742 send_delay_stats,
735 event_log, 743 event_log,
736 congestion_controller_->GetRetransmissionRateLimiter(), 744 congestion_controller_->GetRetransmissionRateLimiter(),
745 // TODO(michaelt): Use here "this" when BWE with overhead implemented.
746 nullptr,
737 config_->rtp.ssrcs.size())), 747 config_->rtp.ssrcs.size())),
738 payload_router_(rtp_rtcp_modules_, 748 payload_router_(rtp_rtcp_modules_,
739 config_->encoder_settings.payload_type), 749 config_->encoder_settings.payload_type),
740 weak_ptr_factory_(this) { 750 weak_ptr_factory_(this),
751 payload_fraction_(1) {
741 RTC_DCHECK_RUN_ON(worker_queue_); 752 RTC_DCHECK_RUN_ON(worker_queue_);
742 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString(); 753 LOG(LS_INFO) << "VideoSendStreamInternal: " << config_->ToString();
743 weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); 754 weak_ptr_ = weak_ptr_factory_.GetWeakPtr();
744 module_process_thread_checker_.DetachFromThread(); 755 module_process_thread_checker_.DetachFromThread();
745 756
746 RTC_DCHECK(!config_->rtp.ssrcs.empty()); 757 RTC_DCHECK(!config_->rtp.ssrcs.empty());
747 RTC_DCHECK(call_stats_); 758 RTC_DCHECK(call_stats_);
748 RTC_DCHECK(congestion_controller_); 759 RTC_DCHECK(congestion_controller_);
749 RTC_DCHECK(remb_); 760 RTC_DCHECK(remb_);
750 761
(...skipping 16 matching lines...) Expand all
767 } 778 }
768 779
769 remb_->AddRembSender(rtp_rtcp_modules_[0]); 780 remb_->AddRembSender(rtp_rtcp_modules_[0]);
770 rtp_rtcp_modules_[0]->SetREMBStatus(true); 781 rtp_rtcp_modules_[0]->SetREMBStatus(true);
771 782
772 ConfigureProtection(); 783 ConfigureProtection();
773 ConfigureSsrcs(); 784 ConfigureSsrcs();
774 785
775 // TODO(pbos): Should we set CNAME on all RTP modules? 786 // TODO(pbos): Should we set CNAME on all RTP modules?
776 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str()); 787 rtp_rtcp_modules_.front()->SetCNAME(config_->rtp.c_name.c_str());
777 // 28 to match packet overhead in ModuleRtpRtcpImpl. 788
778 static const size_t kRtpPacketSizeOverhead = 28;
779 RTC_DCHECK_LE(config_->rtp.max_packet_size, 0xFFFFu + kRtpPacketSizeOverhead);
stefan-webrtc 2016/11/22 17:17:01 Is there still a reasonable check we should make o
michaelt 2016/11/23 09:19:13 We could check for lower than IP_MTU(1500)
780 const uint16_t mtu = static_cast<uint16_t>(config_->rtp.max_packet_size +
781 kRtpPacketSizeOverhead);
782 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { 789 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
783 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_); 790 rtp_rtcp->RegisterRtcpStatisticsCallback(stats_proxy_);
784 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_); 791 rtp_rtcp->RegisterSendChannelRtpStatisticsCallback(stats_proxy_);
785 rtp_rtcp->SetMaxTransferUnit(mtu); 792 rtp_rtcp->SetMaxTransferUnit(config_->rtp.max_packet_size);
786 rtp_rtcp->RegisterVideoSendPayload( 793 rtp_rtcp->RegisterVideoSendPayload(
787 config_->encoder_settings.payload_type, 794 config_->encoder_settings.payload_type,
788 config_->encoder_settings.payload_name.c_str()); 795 config_->encoder_settings.payload_name.c_str());
789 } 796 }
790 797
791 RTC_DCHECK(config_->encoder_settings.encoder); 798 RTC_DCHECK(config_->encoder_settings.encoder);
792 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0); 799 RTC_DCHECK_GE(config_->encoder_settings.payload_type, 0);
793 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127); 800 RTC_DCHECK_LE(config_->encoder_settings.payload_type, 127);
794 801
795 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this)); 802 vie_encoder_->SetStartBitrate(bitrate_allocator_->GetStartBitrate(this));
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 : RtcpMode::kOff); 1152 : RtcpMode::kOff);
1146 } 1153 }
1147 } 1154 }
1148 1155
1149 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps, 1156 uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
1150 uint8_t fraction_loss, 1157 uint8_t fraction_loss,
1151 int64_t rtt) { 1158 int64_t rtt) {
1152 RTC_DCHECK_RUN_ON(worker_queue_); 1159 RTC_DCHECK_RUN_ON(worker_queue_);
1153 RTC_DCHECK(payload_router_.active()) 1160 RTC_DCHECK(payload_router_.active())
1154 << "VideoSendStream::Start has not been called."; 1161 << "VideoSendStream::Start has not been called.";
1162
1163 // Substract overhead from bitrate.
1164 bitrate_bps *= payload_fraction_;
minyue-webrtc 2016/11/23 10:48:05 I think we need to create a global flag to make cl
stefan-webrtc 2016/11/23 11:08:11 I don't think that's enough. We have to only subtr
michaelt 2016/11/23 12:00:24 Would prefer a field trial as well. I even think w
1165
1155 // Get the encoder target rate. It is the estimated network rate - 1166 // Get the encoder target rate. It is the estimated network rate -
1156 // protection overhead. 1167 // protection overhead.
1157 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates( 1168 encoder_target_rate_bps_ = protection_bitrate_calculator_.SetTargetRates(
1158 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt); 1169 bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss, rtt);
1159 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_; 1170 uint32_t protection_bitrate = bitrate_bps - encoder_target_rate_bps_;
1160 1171
1161 encoder_target_rate_bps_ = 1172 encoder_target_rate_bps_ =
1162 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_); 1173 std::min(encoder_max_bitrate_bps_, encoder_target_rate_bps_);
1163 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt); 1174 vie_encoder_->OnBitrateUpdated(encoder_target_rate_bps_, fraction_loss, rtt);
1164 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_); 1175 stats_proxy_->OnSetEncoderTargetRate(encoder_target_rate_bps_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 rtp_rtcp->SetFecParameters(*delta_params, *key_params); 1215 rtp_rtcp->SetFecParameters(*delta_params, *key_params);
1205 rtp_rtcp->BitrateSent(&not_used, &module_video_rate, &module_fec_rate, 1216 rtp_rtcp->BitrateSent(&not_used, &module_video_rate, &module_fec_rate,
1206 &module_nack_rate); 1217 &module_nack_rate);
1207 *sent_video_rate_bps += module_video_rate; 1218 *sent_video_rate_bps += module_video_rate;
1208 *sent_nack_rate_bps += module_nack_rate; 1219 *sent_nack_rate_bps += module_nack_rate;
1209 *sent_fec_rate_bps += module_fec_rate; 1220 *sent_fec_rate_bps += module_fec_rate;
1210 } 1221 }
1211 return 0; 1222 return 0;
1212 } 1223 }
1213 1224
1225 void VideoSendStreamImpl::OnOverheadChanged(size_t overhead_bytes_per_packet) {
1226 RTC_DCHECK_RUN_ON(worker_queue_);
1227 payload_fraction_ =
1228 1.0 - (static_cast<float>(overhead_bytes_per_packet) /
1229 (config_->rtp.max_packet_size + transport_overhead_per_packet_));
stefan-webrtc 2016/11/22 17:17:01 This is an approximation assuming only max sized p
michaelt 2016/11/23 09:19:13 Yes I assumed only max packets. I think we can sim
stefan-webrtc 2016/11/23 10:01:07 Yes, you are probably right, the ceil is what's im
1230 }
1231
1214 void VideoSendStreamImpl::SetTransportOverhead( 1232 void VideoSendStreamImpl::SetTransportOverhead(
1215 int transport_overhead_per_packet) { 1233 int transport_overhead_per_packet) {
1216 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) 1234 transport_overhead_per_packet_ = transport_overhead_per_packet;
1235 RTC_DCHECK_LE(config_->rtp.max_packet_size,
1236 0xFFFFu + transport_overhead_per_packet);
1237 const uint16_t mtu = static_cast<uint16_t>(config_->rtp.max_packet_size +
1238 transport_overhead_per_packet);
1239 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) {
1217 rtp_rtcp->SetTransportOverhead(transport_overhead_per_packet); 1240 rtp_rtcp->SetTransportOverhead(transport_overhead_per_packet);
1241 rtp_rtcp->SetMaxTransferUnit(mtu);
1242 }
1218 } 1243 }
1219 1244
1220 } // namespace internal 1245 } // namespace internal
1221 } // namespace webrtc 1246 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698