From 43d3e5026027af9570f33bcd3087945950158b0c Mon Sep 17 00:00:00 2001 From: Qiu Jianlin Date: Tue, 23 Apr 2019 09:11:19 +0800 Subject: [PATCH 1/3] Disable frame drop for low latency mode --- modules/video_coding/video_sender.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/video_coding/video_sender.cc b/modules/video_coding/video_sender.cc index c55befc02a3..6dd394f5114 100644 --- a/modules/video_coding/video_sender.cc +++ b/modules/video_coding/video_sender.cc @@ -256,16 +256,13 @@ int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame, if (_encoder == nullptr) return VCM_UNINITIALIZED; SetEncoderParameters(encoder_params, encoder_has_internal_source); - if (_mediaOpt.DropFrame()) { + if (_mediaOpt.DropFrame() && !field_trial::IsEnabled("OWT-LowLatencyMode")) { RTC_LOG(LS_VERBOSE) << "Drop Frame " << "target bitrate " << encoder_params.target_bitrate.get_sum_bps() << " loss rate " << encoder_params.loss_rate << " rtt " << encoder_params.rtt << " input frame rate " << encoder_params.input_frame_rate; - // For low latency mode we don't drop. - if (field_trial::IsEnabled("OWT-LowLatencyMode")) - return VCM_OK; post_encode_callback_->OnDroppedFrame( EncodedImageCallback::DropReason::kDroppedByMediaOptimizations); return VCM_OK; From c4f852812c8eb5a0abba7ac23182bb39d46d9c3b Mon Sep 17 00:00:00 2001 From: Qiu Jianlin Date: Sun, 5 May 2019 11:34:33 +0800 Subject: [PATCH 2/3] Remove critical section in pacer for cg --- modules/pacing/paced_sender.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc index b58d020894a..97ae3616010 100644 --- a/modules/pacing/paced_sender.cc +++ b/modules/pacing/paced_sender.cc @@ -407,12 +407,12 @@ bool PacedSender::SendPacket(const PacketQueueInterface::Packet& packet, return false; } } - critsect_.Leave(); + //critsect_.Leave(); RTC_LOG(LS_ERROR) << "b:" << clock_->TimeInMilliseconds(); const bool success = packet_sender_->TimeToSendPacket( packet.ssrc, packet.sequence_number, packet.capture_time_ms, packet.retransmission, pacing_info); - critsect_.Enter(); + //critsect_.Enter(); RTC_LOG(LS_ERROR) << "a:" << clock_->TimeInMilliseconds(); if (success) { if (first_sent_packet_ms_ == -1) From f84ce7465406c09acd53429affacd4fe9606a2f5 Mon Sep 17 00:00:00 2001 From: Qiu Jianlin Date: Thu, 9 May 2019 07:18:44 +0800 Subject: [PATCH 3/3] Reduce pacer sending latency to sub-2ms range --- call/rtp_transport_controller_send.cc | 4 ++-- modules/pacing/paced_sender.cc | 27 ++++++++++++++++++++++++--- modules/pacing/paced_sender.h | 1 + modules/video_coding/video_sender.cc | 2 +- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc index 79b7a144b97..a42193e0440 100644 --- a/call/rtp_transport_controller_send.cc +++ b/call/rtp_transport_controller_send.cc @@ -80,7 +80,7 @@ RtpTransportControllerSend::RtpTransportControllerSend( TaskQueueExperimentEnabled(), controller_factory); process_thread_->RegisterModule(&pacer_, RTC_FROM_HERE); - process_thread_->RegisterModule(send_side_cc_.get(), RTC_FROM_HERE); + //process_thread_->RegisterModule(send_side_cc_.get(), RTC_FROM_HERE); if (!LowLatencyStreamingEnabled()) { process_thread_->Start(); } else { @@ -90,7 +90,7 @@ RtpTransportControllerSend::RtpTransportControllerSend( RtpTransportControllerSend::~RtpTransportControllerSend() { process_thread_->Stop(); - process_thread_->DeRegisterModule(send_side_cc_.get()); + //process_thread_->DeRegisterModule(send_side_cc_.get()); process_thread_->DeRegisterModule(&pacer_); } diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc index 97ae3616010..a086a00ecc9 100644 --- a/modules/pacing/paced_sender.cc +++ b/modules/pacing/paced_sender.cc @@ -49,6 +49,10 @@ namespace webrtc { const int64_t PacedSender::kMaxQueueLengthMs = 2000; const float PacedSender::kDefaultPaceMultiplier = 2.5f; +int64_t capture_timestamp = 0; +int64_t end_timestamp = 0; +size_t total_size = 0; +int64_t frame_count = 0; PacedSender::PacedSender(const Clock* clock, PacketSender* packet_sender, RtcEventLog* event_log) @@ -92,6 +96,7 @@ PacedSender::PacedSender(const Clock* clock, UpdateBudgetWithElapsedTime(kMinPacketLimitMs); if (low_latency_mode_) prober_->SetEnabled(false); + recorder = fopen("pacer.txt", "a+"); } PacedSender::~PacedSender() {} @@ -356,6 +361,22 @@ void PacedSender::Process() { << ",cu: " << clock_->TimeInMilliseconds() << ",sz: " << packet.bytes << ", q: " << packets_->SizeInPackets(); + + if (capture_timestamp != packet.capture_time_ms) { // New frame + int64_t last_frame_cost = end_timestamp - capture_timestamp; + int64_t time_since_last_frame = + clock_->TimeInMilliseconds() - end_timestamp; + fprintf(recorder, "%lld\t%lld\t%zd\t%lld\n", frame_count, last_frame_cost, + total_size, time_since_last_frame); + frame_count++; + total_size = 0; + end_timestamp = clock_->TimeInMilliseconds(); + capture_timestamp = packet.capture_time_ms; + } else { + capture_timestamp = packet.capture_time_ms; + total_size += packet.bytes; + end_timestamp = clock_->TimeInMilliseconds(); + } if (is_probing && bytes_sent > recommended_probe_size) break; } else { @@ -407,14 +428,14 @@ bool PacedSender::SendPacket(const PacketQueueInterface::Packet& packet, return false; } } - //critsect_.Leave(); + critsect_.Leave(); RTC_LOG(LS_ERROR) << "b:" << clock_->TimeInMilliseconds(); const bool success = packet_sender_->TimeToSendPacket( packet.ssrc, packet.sequence_number, packet.capture_time_ms, packet.retransmission, pacing_info); - //critsect_.Enter(); + critsect_.Enter(); RTC_LOG(LS_ERROR) << "a:" << clock_->TimeInMilliseconds(); - if (success) { + if (success && !IsLowLatencyMode()) { if (first_sent_packet_ms_ == -1) first_sent_packet_ms_ = clock_->TimeInMilliseconds(); if (!audio_packet || account_for_audio_) { diff --git a/modules/pacing/paced_sender.h b/modules/pacing/paced_sender.h index 212ecbd590b..f1e9c0e5675 100644 --- a/modules/pacing/paced_sender.h +++ b/modules/pacing/paced_sender.h @@ -213,6 +213,7 @@ class PacedSender : public Pacer { int64_t queue_time_limit RTC_GUARDED_BY(critsect_); bool account_for_audio_ RTC_GUARDED_BY(critsect_); + FILE* recorder; }; } // namespace webrtc #endif // MODULES_PACING_PACED_SENDER_H_ diff --git a/modules/video_coding/video_sender.cc b/modules/video_coding/video_sender.cc index 6dd394f5114..30c638c7d10 100644 --- a/modules/video_coding/video_sender.cc +++ b/modules/video_coding/video_sender.cc @@ -301,7 +301,7 @@ int32_t VideoSender::AddVideoFrame(const VideoFrame& videoFrame, _encoder->Encode(converted_frame, codecSpecificInfo, next_frame_types); if (ret < 0) { RTC_LOG(LS_ERROR) << "Failed to encode frame. Error code: " << ret; - return ret; + //return ret; } {