Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Reduce pacer sending latency to sub-2ms range
Browse files Browse the repository at this point in the history
  • Loading branch information
taste1981 committed May 8, 2019
1 parent c4f8528 commit f84ce74
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 2 additions & 2 deletions call/rtp_transport_controller_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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_);
}

Expand Down
27 changes: 24 additions & 3 deletions modules/pacing/paced_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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_) {
Expand Down
1 change: 1 addition & 0 deletions modules/pacing/paced_sender.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 1 addition & 1 deletion modules/video_coding/video_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

{
Expand Down

0 comments on commit f84ce74

Please sign in to comment.