Using Ntp times for the absolute send time.

Bug: webrtc:15930
Change-Id: Ie460ac6e3561efafeb11bf36735cb6f33bdfd8a3
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/349162
Commit-Queue: Jesus de Vicente Pena <devicentepena@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Lionel Koenig Gélas <lionelk@google.com>
Cr-Commit-Position: refs/heads/main@{#42183}
This commit is contained in:
Jesús de Vicente Peña 2024-04-26 13:45:40 +02:00 committed by WebRTC LUCI CQ
parent a130e37dad
commit 3703b3500c
5 changed files with 36 additions and 9 deletions

View File

@ -430,6 +430,7 @@ ChannelSend::ChannelSend(
configuration.rtcp_packet_type_counter_observer = this;
configuration.local_media_ssrc = ssrc;
configuration.field_trials = &field_trials;
rtp_rtcp_ = ModuleRtpRtcpImpl2::Create(configuration);
rtp_rtcp_->SetSendingMediaStatus(false);

View File

@ -123,6 +123,9 @@ ACTIVE_FIELD_TRIALS: FrozenSet[FieldTrial] = frozenset([
FieldTrial('WebRTC-TaskQueue-ReplaceLibeventWithStdlib',
'webrtc:14389',
date(2024, 4, 1)),
FieldTrial('WebRTC-UseNtpTimeAbsoluteSendTime',
'webrtc:15930',
date(2024, 9, 1)),
FieldTrial('WebRTC-VP8-MaxFrameInterval',
'webrtc:15530',
date(2024, 4, 1)),

View File

@ -27,6 +27,7 @@
#include "api/video/video_rotation.h"
#include "api/video/video_timing.h"
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "system_wrappers/include/ntp_time.h"
// This file contains class definitions for reading/writing each RTP header
// extension. Each class must be defined such that it is compatible with being
@ -58,6 +59,11 @@ class AbsoluteSendTime {
return static_cast<uint32_t>(time6x18);
}
static uint32_t To24Bits(NtpTime ntp_time) {
uint64_t ntp_time32x32 = static_cast<uint64_t>(ntp_time);
return (ntp_time32x32 >> 14) & 0x00FF'FFFF;
}
static constexpr Timestamp ToTimestamp(uint32_t time_24bits) {
RTC_DCHECK_LT(time_24bits, (1 << 24));
return Timestamp::Micros((time_24bits* int64_t{1'000'000}) >> 18);

View File

@ -26,6 +26,15 @@ constexpr uint32_t kTimestampTicksPerMs = 90;
constexpr TimeDelta kBitrateStatisticsWindow = TimeDelta::Seconds(1);
constexpr size_t kRtpSequenceNumberMapMaxEntries = 1 << 13;
constexpr TimeDelta kUpdateInterval = kBitrateStatisticsWindow;
bool GetUseNtpTimeForAbsoluteSendTime(const FieldTrialsView* field_trials) {
if (field_trials != nullptr &&
field_trials->IsDisabled("WebRTC-UseNtpTimeAbsoluteSendTime")) {
return false;
}
return true;
}
} // namespace
RtpSenderEgress::NonPacedPacketSender::NonPacedPacketSender(
@ -104,7 +113,9 @@ RtpSenderEgress::RtpSenderEgress(const RtpRtcpInterface::Configuration& config,
rtp_sequence_number_map_(need_rtp_packet_infos_
? std::make_unique<RtpSequenceNumberMap>(
kRtpSequenceNumberMapMaxEntries)
: nullptr) {
: nullptr),
use_ntp_time_for_absolute_send_time_(
GetUseNtpTimeForAbsoluteSendTime(config.field_trials)) {
RTC_DCHECK(worker_queue_);
RTC_DCHECK(config.transport_feedback_callback == nullptr)
<< "transport_feedback_callback is no longer used and will soon be "
@ -209,7 +220,12 @@ void RtpSenderEgress::SendPacket(std::unique_ptr<RtpPacketToSend> packet,
packet->SetExtension<TransmissionOffset>(kTimestampTicksPerMs * diff.ms());
}
if (packet->HasExtension<AbsoluteSendTime>()) {
packet->SetExtension<AbsoluteSendTime>(AbsoluteSendTime::To24Bits(now));
if (use_ntp_time_for_absolute_send_time_) {
packet->SetExtension<AbsoluteSendTime>(
AbsoluteSendTime::To24Bits(clock_->ConvertTimestampToNtpTime(now)));
} else {
packet->SetExtension<AbsoluteSendTime>(AbsoluteSendTime::To24Bits(now));
}
}
if (packet->HasExtension<TransportSequenceNumber>() &&
packet->transport_sequence_number()) {
@ -457,16 +473,16 @@ void RtpSenderEgress::UpdateRtpStats(Timestamp now,
} else if (packet_type == RtpPacketMediaType::kRetransmission) {
counters->retransmitted.Add(counter);
}
counters->transmitted.Add(counter);
counters->transmitted.Add(counter);
send_rates_[static_cast<size_t>(packet_type)].Update(packet_size, now);
if (bitrate_callback_) {
send_rates_[static_cast<size_t>(packet_type)].Update(packet_size, now);
if (bitrate_callback_) {
send_rates = GetSendRates(now);
}
}
if (rtp_stats_callback_) {
rtp_stats_callback_->DataCountersUpdated(*counters, packet_ssrc);
}
if (rtp_stats_callback_) {
rtp_stats_callback_->DataCountersUpdated(*counters, packet_ssrc);
}
// The bitrate_callback_ and rtp_stats_callback_ pointers in practice point
// to the same object, so these callbacks could be consolidated into one.

View File

@ -167,6 +167,7 @@ class RtpSenderEgress {
RepeatingTaskHandle update_task_ RTC_GUARDED_BY(worker_queue_);
std::vector<Packet> packets_to_send_ RTC_GUARDED_BY(worker_queue_);
ScopedTaskSafety task_safety_;
const bool use_ntp_time_for_absolute_send_time_;
};
} // namespace webrtc