3333namespace {
3434// Time limit in milliseconds between packet bursts.
3535const int64_t kMinPacketLimitMs = 5 ;
36- const int64_t kMinPacketLimitLowLatency = 1 ; // For low latency mode we set process interval to 1ms instead.
36+ const int64_t kMinPacketLimitLowLatency =
37+ 1 ; // For low latency mode we set process interval to 1ms instead.
3738const int64_t kCongestedPacketIntervalMs = 500 ;
3839const int64_t kPausedProcessIntervalMs = kCongestedPacketIntervalMs ;
3940const int64_t kMaxElapsedTimeMs = 2000 ;
@@ -48,6 +49,7 @@ namespace webrtc {
4849
4950const int64_t PacedSender::kMaxQueueLengthMs = 2000 ;
5051const float PacedSender::kDefaultPaceMultiplier = 2 .5f ;
52+ const char kLogLatencyToFileFieldTrial [] = " OWT-Log-Latency-To-File" ;
5153
5254int64_t capture_timestamp = 0 ;
5355int64_t end_timestamp = 0 ;
@@ -96,14 +98,21 @@ PacedSender::PacedSender(const Clock* clock,
9698 UpdateBudgetWithElapsedTime (kMinPacketLimitMs );
9799 if (low_latency_mode_)
98100 prober_->SetEnabled (false );
99- recorder = fopen (" pacer.txt" , " a+" );
101+ recorder = nullptr ;
102+ if (webrtc::field_trial::IsEnabled (kLogLatencyToFileFieldTrial ))
103+ recorder = fopen (" pacer.txt" , " a+" );
100104}
101105
102- PacedSender::~PacedSender () {}
106+ PacedSender::~PacedSender () {
107+ if (recorder != nullptr ) {
108+ fclose (recorder);
109+ recorder = nullptr ;
110+ }
111+ }
103112
104113void PacedSender::CreateProbeCluster (int bitrate_bps) {
105114 rtc::CritScope cs (&critsect_);
106- if (!low_latency_mode_) // Do not create probe cluster on low latency mode.
115+ if (!low_latency_mode_) // Do not create probe cluster on low latency mode.
107116 prober_->CreateProbeCluster (bitrate_bps, clock_->TimeInMilliseconds ());
108117}
109118
@@ -300,7 +309,7 @@ void PacedSender::Process() {
300309 // congested state due to no feedback being received.
301310 int64_t elapsed_since_last_send_us = now_us - last_send_time_us_;
302311 if (elapsed_since_last_send_us >= kCongestedPacketIntervalMs * 1000 ) {
303- // We can not send padding unless a normal packet has first been sent. If
312+ // We do not send padding unless a normal packet has first been sent. If
304313 // we do, timestamps get messed up.
305314 if (packet_counter_ > 0 ) {
306315 PacedPacketInfo pacing_info;
@@ -311,7 +320,7 @@ void PacedSender::Process() {
311320 }
312321 if (paused_) {
313322 RTC_LOG (LS_ERROR) << " Paused." ;
314- // return;
323+ // return;
315324 }
316325
317326 if (elapsed_time_ms > 0 ) {
@@ -362,21 +371,24 @@ void PacedSender::Process() {
362371 << " ,sz: " << packet.bytes
363372 << " , q: " << packets_->SizeInPackets ();
364373
365- if (capture_timestamp != packet.capture_time_ms ) { // New frame
366- int64_t last_frame_cost = end_timestamp - capture_timestamp;
367- int64_t time_since_last_frame =
368- clock_->TimeInMilliseconds () - end_timestamp;
369- fprintf (recorder, " %lld\t %lld\t %zd\t %lld\n " , frame_count, last_frame_cost,
370- total_size, time_since_last_frame);
371- frame_count++;
372- total_size = 0 ;
373- end_timestamp = clock_->TimeInMilliseconds ();
374- capture_timestamp = packet.capture_time_ms ;
375- } else {
376- capture_timestamp = packet.capture_time_ms ;
377- total_size += packet.bytes ;
378- end_timestamp = clock_->TimeInMilliseconds ();
379- }
374+ if (webrtc::field_trial::IsEnabled (kLogLatencyToFileFieldTrial )) {
375+ if (capture_timestamp != packet.capture_time_ms ) { // New frame
376+ int64_t last_frame_cost = end_timestamp - capture_timestamp;
377+ int64_t time_since_last_frame =
378+ clock_->TimeInMilliseconds () - end_timestamp;
379+ fprintf (recorder, " %lld\t %lld\t %zd\t %lld\n " , frame_count,
380+ last_frame_cost, total_size, time_since_last_frame);
381+ frame_count++;
382+ total_size = 0 ;
383+ end_timestamp = clock_->TimeInMilliseconds ();
384+ capture_timestamp = packet.capture_time_ms ;
385+ } else {
386+ capture_timestamp = packet.capture_time_ms ;
387+ total_size += packet.bytes ;
388+ end_timestamp = clock_->TimeInMilliseconds ();
389+ }
390+ }
391+
380392 if (is_probing && bytes_sent > recommended_probe_size)
381393 break ;
382394 } else {
@@ -389,12 +401,12 @@ void PacedSender::Process() {
389401
390402 if (!IsLowLatencyMode ()) {
391403 if (packets_->Empty () && !Congested ()) {
392- // We can not send padding unless a normal packet has first been sent. If we
393- // do, timestamps get messed up.
404+ // We can not send padding unless a normal packet has first been sent. If
405+ // we do, timestamps get messed up.
394406 if (packet_counter_ > 0 ) {
395407 int padding_needed =
396408 static_cast <int >(is_probing ? (recommended_probe_size - bytes_sent)
397- : padding_budget_->bytes_remaining ());
409+ : padding_budget_->bytes_remaining ());
398410 if (padding_needed > 0 ) {
399411 bytes_sent += SendPadding (padding_needed, pacing_info);
400412 }
@@ -422,9 +434,10 @@ bool PacedSender::SendPacket(const PacketQueueInterface::Packet& packet,
422434 bool apply_pacing =
423435 !audio_packet || account_for_audio_ || video_blocks_audio_;
424436 if (!IsLowLatencyMode ()) {
425- if (apply_pacing && (Congested () || (media_budget_->bytes_remaining () == 0 &&
426- pacing_info.probe_cluster_id ==
427- PacedPacketInfo::kNotAProbe ))) {
437+ if (apply_pacing &&
438+ (Congested () ||
439+ (media_budget_->bytes_remaining () == 0 &&
440+ pacing_info.probe_cluster_id == PacedPacketInfo::kNotAProbe ))) {
428441 return false ;
429442 }
430443 }
0 commit comments