Use time units in Syncable interface
That interface works with different kind of representation of time that
also arrive from different clocks. Using strong types partially document
what those times are.
Bug: webrtc:42223979
Change-Id: I1dad85cdf150a389828bca1887da34de6a0e098f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/403682
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45315}
diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc
index bbe8480..0496aa8 100644
--- a/audio/audio_receive_stream.cc
+++ b/audio/audio_receive_stream.cc
@@ -33,6 +33,8 @@
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/transport/rtp/rtp_source.h"
+#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
#include "audio/audio_send_stream.h"
#include "audio/audio_state.h"
#include "audio/channel_receive.h"
@@ -45,6 +47,7 @@
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/time_utils.h"
+#include "system_wrappers/include/ntp_time.h"
namespace webrtc {
@@ -410,25 +413,23 @@
return channel_receive_->GetSyncInfo();
}
-bool AudioReceiveStreamImpl::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const {
+std::optional<Syncable::PlayoutInfo>
+AudioReceiveStreamImpl::GetPlayoutRtpTimestamp() const {
// Called on video capture thread.
- return channel_receive_->GetPlayoutRtpTimestamp(rtp_timestamp, time_ms);
+ return channel_receive_->GetPlayoutRtpTimestamp();
}
-void AudioReceiveStreamImpl::SetEstimatedPlayoutNtpTimestampMs(
- int64_t ntp_timestamp_ms,
- int64_t time_ms) {
+void AudioReceiveStreamImpl::SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) {
// Called on video capture thread.
- channel_receive_->SetEstimatedPlayoutNtpTimestampMs(ntp_timestamp_ms,
- time_ms);
+ channel_receive_->SetEstimatedPlayoutNtpTimestamp(ntp_time, time);
}
-bool AudioReceiveStreamImpl::SetMinimumPlayoutDelay(int delay_ms) {
+bool AudioReceiveStreamImpl::SetMinimumPlayoutDelay(TimeDelta delay) {
// TODO(bugs.webrtc.org/11993): This is called via RtpStreamsSynchronizer,
// expect to be called on the network thread.
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
- return channel_receive_->SetMinimumPlayoutDelay(delay_ms);
+ return channel_receive_->SetMinimumPlayoutDelay(delay);
}
void AudioReceiveStreamImpl::DeliverRtcp(ArrayView<const uint8_t> packet) {
diff --git a/audio/audio_receive_stream.h b/audio/audio_receive_stream.h
index 0d78482..4b6c57b 100644
--- a/audio/audio_receive_stream.h
+++ b/audio/audio_receive_stream.h
@@ -32,12 +32,15 @@
#include "api/scoped_refptr.h"
#include "api/sequence_checker.h"
#include "api/transport/rtp/rtp_source.h"
+#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
#include "audio/audio_state.h"
#include "call/audio_receive_stream.h"
#include "call/audio_state.h"
#include "call/syncable.h"
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/thread_annotations.h"
+#include "system_wrappers/include/ntp_time.h"
namespace webrtc {
class PacketRouter;
@@ -118,11 +121,10 @@
// Syncable
uint32_t id() const override;
std::optional<Syncable::Info> GetInfo() const override;
- bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const override;
- void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) override;
- bool SetMinimumPlayoutDelay(int delay_ms) override;
+ std::optional<Syncable::PlayoutInfo> GetPlayoutRtpTimestamp() const override;
+ void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) override;
+ bool SetMinimumPlayoutDelay(TimeDelta delay) override;
void DeliverRtcp(ArrayView<const uint8_t> packet);
diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc
index 658266e..b98ac8e 100644
--- a/audio/channel_receive.cc
+++ b/audio/channel_receive.cc
@@ -72,7 +72,6 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
-#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/numerics/sequence_number_unwrapper.h"
#include "rtc_base/race_checker.h"
#include "rtc_base/strings/string_builder.h"
@@ -92,8 +91,8 @@
constexpr double kAudioSampleDurationSeconds = 0.01;
// Video Sync.
-constexpr int kVoiceEngineMinMinPlayoutDelayMs = 0;
-constexpr int kVoiceEngineMaxMinPlayoutDelayMs = 10000;
+constexpr TimeDelta kVoiceEngineMinMinPlayoutDelay = TimeDelta::Zero();
+constexpr TimeDelta kVoiceEngineMaxMinPlayoutDelay = TimeDelta::Seconds(10);
std::unique_ptr<NetEq> CreateNetEq(
NetEqFactory* neteq_factory,
@@ -169,11 +168,10 @@
// Audio+Video Sync.
uint32_t GetDelayEstimate() const override;
- bool SetMinimumPlayoutDelay(int delay_ms) override;
- bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const override;
- void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) override;
+ bool SetMinimumPlayoutDelay(TimeDelta delay) override;
+ std::optional<Syncable::PlayoutInfo> GetPlayoutRtpTimestamp() const override;
+ void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) override;
std::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
int64_t now_ms) const override;
@@ -221,7 +219,7 @@
const RTPHeader& header,
Timestamp receive_time) RTC_RUN_ON(worker_thread_checker_);
int ResendPackets(const uint16_t* sequence_numbers, int length);
- void UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms)
+ void UpdatePlayoutTimestamp(bool rtcp, Timestamp now)
RTC_RUN_ON(worker_thread_checker_);
int GetRtpTimestampRateHz() const;
@@ -266,7 +264,7 @@
std::optional<uint32_t> last_received_rtp_timestamp_
RTC_GUARDED_BY(&worker_thread_checker_);
- std::optional<int64_t> last_received_rtp_system_time_ms_
+ std::optional<Timestamp> last_received_rtp_system_time_
RTC_GUARDED_BY(&worker_thread_checker_);
const std::unique_ptr<NetEq> neteq_; // NetEq is thread-safe; no lock needed.
@@ -281,13 +279,12 @@
// Timestamp of the audio pulled from NetEq.
std::optional<uint32_t> jitter_buffer_playout_timestamp_;
- uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(worker_thread_checker_);
- std::optional<int64_t> playout_timestamp_rtp_time_ms_
+ std::optional<Syncable::PlayoutInfo> playout_timestamp_
RTC_GUARDED_BY(worker_thread_checker_);
uint32_t playout_delay_ms_ RTC_GUARDED_BY(worker_thread_checker_);
- std::optional<int64_t> playout_timestamp_ntp_
+ std::optional<NtpTime> playout_timestamp_ntp_
RTC_GUARDED_BY(worker_thread_checker_);
- std::optional<int64_t> playout_timestamp_ntp_time_ms_
+ std::optional<Timestamp> playout_timestamp_ntp_time_
RTC_GUARDED_BY(worker_thread_checker_);
mutable Mutex ts_stats_lock_;
@@ -579,7 +576,6 @@
decoder_factory)),
_outputAudioLevel(),
ntp_estimator_(&env_.clock()),
- playout_timestamp_rtp_(0),
playout_delay_ms_(0),
capture_start_rtp_time_stamp_(-1),
capture_start_ntp_time_ms_(-1),
@@ -662,13 +658,13 @@
void ChannelReceive::OnRtpPacket(const RtpPacketReceived& packet) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
- int64_t now_ms = TimeMillis();
+ Timestamp now = Timestamp::Millis(TimeMillis());
last_received_rtp_timestamp_ = packet.Timestamp();
- last_received_rtp_system_time_ms_ = now_ms;
+ last_received_rtp_system_time_ = now;
// Store playout timestamp for the received RTP packet
- UpdatePlayoutTimestamp(false, now_ms);
+ UpdatePlayoutTimestamp(false, now);
const auto& it = payload_type_frequencies_.find(packet.PayloadType());
if (it == payload_type_frequencies_.end())
@@ -759,7 +755,7 @@
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
// Store playout timestamp for the received RTCP packet
- UpdatePlayoutTimestamp(true, TimeMillis());
+ UpdatePlayoutTimestamp(true, Timestamp::Millis(TimeMillis()));
// Deliver RTCP packet to RTP/RTCP module for parsing
rtp_rtcp_->IncomingRtcpPacket(MakeArrayView(data, length));
@@ -1046,46 +1042,41 @@
return neteq_->FilteredCurrentDelayMs() + playout_delay_ms_;
}
-bool ChannelReceive::SetMinimumPlayoutDelay(int delay_ms) {
+bool ChannelReceive::SetMinimumPlayoutDelay(TimeDelta delay) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
// Limit to range accepted by both VoE and ACM, so we're at least getting as
// close as possible, instead of failing.
- delay_ms = SafeClamp(delay_ms, kVoiceEngineMinMinPlayoutDelayMs,
- kVoiceEngineMaxMinPlayoutDelayMs);
- if (!neteq_->SetMinimumDelay(delay_ms)) {
+ delay = std::clamp(delay, kVoiceEngineMinMinPlayoutDelay,
+ kVoiceEngineMaxMinPlayoutDelay);
+ if (!neteq_->SetMinimumDelay(delay.ms())) {
RTC_DLOG(LS_ERROR)
- << "SetMinimumPlayoutDelay() failed to set min playout delay "
- << delay_ms;
+ << "SetMinimumPlayoutDelay() failed to set min playout delay " << delay;
return false;
}
return true;
}
-bool ChannelReceive::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const {
+std::optional<Syncable::PlayoutInfo> ChannelReceive::GetPlayoutRtpTimestamp()
+ const {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
- if (!playout_timestamp_rtp_time_ms_)
- return false;
- *rtp_timestamp = playout_timestamp_rtp_;
- *time_ms = playout_timestamp_rtp_time_ms_.value();
- return true;
+ return playout_timestamp_;
}
-void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) {
+void ChannelReceive::SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
- playout_timestamp_ntp_ = ntp_timestamp_ms;
- playout_timestamp_ntp_time_ms_ = time_ms;
+ playout_timestamp_ntp_ = ntp_time;
+ playout_timestamp_ntp_time_ = time;
}
std::optional<int64_t> ChannelReceive::GetCurrentEstimatedPlayoutNtpTimestampMs(
int64_t now_ms) const {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
- if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_ms_)
+ if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_)
return std::nullopt;
- int64_t elapsed_ms = now_ms - *playout_timestamp_ntp_time_ms_;
- return *playout_timestamp_ntp_ + elapsed_ms;
+ int64_t elapsed_ms = now_ms - playout_timestamp_ntp_time_->ms();
+ return playout_timestamp_ntp_->ToMs() + elapsed_ms;
}
bool ChannelReceive::SetBaseMinimumPlayoutDelayMs(int delay_ms) {
@@ -1106,23 +1097,23 @@
if (!last_sr.has_value()) {
return std::nullopt;
}
- info.capture_time_ntp_secs = last_sr->last_remote_ntp_timestamp.seconds();
- info.capture_time_ntp_frac = last_sr->last_remote_ntp_timestamp.fractions();
- info.capture_time_source_clock = last_sr->last_remote_rtp_timestamp;
+ info.capture_time_ntp = last_sr->last_remote_ntp_timestamp;
+ info.capture_time_rtp = last_sr->last_remote_rtp_timestamp;
- if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
+ if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_) {
return std::nullopt;
}
- info.latest_received_capture_timestamp = *last_received_rtp_timestamp_;
- info.latest_receive_time_ms = *last_received_rtp_system_time_ms_;
+ info.latest_received_capture_rtp_timestamp = *last_received_rtp_timestamp_;
+ info.latest_receive_time = *last_received_rtp_system_time_;
int jitter_buffer_delay = neteq_->FilteredCurrentDelayMs();
- info.current_delay_ms = jitter_buffer_delay + playout_delay_ms_;
+ info.current_delay =
+ TimeDelta::Millis(jitter_buffer_delay + playout_delay_ms_);
return info;
}
-void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms) {
+void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, Timestamp now) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_);
jitter_buffer_playout_timestamp_ = neteq_->GetPlayoutTimestamp();
@@ -1147,9 +1138,9 @@
// Remove the playout delay.
playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
- if (!rtcp && playout_timestamp != playout_timestamp_rtp_) {
- playout_timestamp_rtp_ = playout_timestamp;
- playout_timestamp_rtp_time_ms_ = now_ms;
+ if (!rtcp && (!playout_timestamp_.has_value() ||
+ playout_timestamp_->rtp_timestamp != playout_timestamp)) {
+ playout_timestamp_ = {{.time = now, .rtp_timestamp = playout_timestamp}};
}
playout_delay_ms_ = delay_ms;
}
diff --git a/audio/channel_receive.h b/audio/channel_receive.h
index 0783363..7eb8639 100644
--- a/audio/channel_receive.h
+++ b/audio/channel_receive.h
@@ -39,6 +39,7 @@
#include "call/rtp_packet_sink_interface.h"
#include "call/syncable.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h"
+#include "system_wrappers/include/ntp_time.h"
namespace webrtc {
@@ -123,11 +124,11 @@
// Audio+Video Sync.
virtual uint32_t GetDelayEstimate() const = 0;
- virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
- virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const = 0;
- virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) = 0;
+ virtual bool SetMinimumPlayoutDelay(TimeDelta delay) = 0;
+ virtual std::optional<Syncable::PlayoutInfo> GetPlayoutRtpTimestamp()
+ const = 0;
+ virtual void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) = 0;
virtual std::optional<int64_t> GetCurrentEstimatedPlayoutNtpTimestampMs(
int64_t now_ms) const = 0;
diff --git a/audio/mock_voe_channel_proxy.h b/audio/mock_voe_channel_proxy.h
index cd2927d..7818a36 100644
--- a/audio/mock_voe_channel_proxy.h
+++ b/audio/mock_voe_channel_proxy.h
@@ -35,6 +35,8 @@
#include "api/scoped_refptr.h"
#include "api/transport/rtp/rtp_source.h"
#include "api/units/data_rate.h"
+#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
#include "audio/channel_receive.h"
#include "audio/channel_send.h"
#include "call/syncable.h"
@@ -42,6 +44,7 @@
#include "modules/rtp_rtcp/include/report_block_data.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
+#include "system_wrappers/include/ntp_time.h"
#include "test/gmock.h"
namespace webrtc {
@@ -83,13 +86,13 @@
(override));
MOCK_METHOD(int, PreferredSampleRate, (), (const, override));
MOCK_METHOD(std::vector<RtpSource>, GetSources, (), (const, override));
- MOCK_METHOD(bool,
+ MOCK_METHOD(std::optional<Syncable::PlayoutInfo>,
GetPlayoutRtpTimestamp,
- (uint32_t*, int64_t*),
+ (),
(const, override));
MOCK_METHOD(void,
- SetEstimatedPlayoutNtpTimestampMs,
- (int64_t ntp_timestamp_ms, int64_t time_ms),
+ SetEstimatedPlayoutNtpTimestamp,
+ (NtpTime ntp_time, Timestamp time),
(override));
MOCK_METHOD(std::optional<int64_t>,
GetCurrentEstimatedPlayoutNtpTimestampMs,
@@ -99,7 +102,7 @@
GetSyncInfo,
(),
(const, override));
- MOCK_METHOD(bool, SetMinimumPlayoutDelay, (int delay_ms), (override));
+ MOCK_METHOD(bool, SetMinimumPlayoutDelay, (TimeDelta delay), (override));
MOCK_METHOD(bool, SetBaseMinimumPlayoutDelayMs, (int delay_ms), (override));
MOCK_METHOD(int, GetBaseMinimumPlayoutDelayMs, (), (const, override));
MOCK_METHOD((std::optional<std::pair<int, SdpAudioFormat>>),
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 3f5c615..d3504a3 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -77,6 +77,7 @@
"../rtc_base:copy_on_write_buffer",
"../rtc_base:stringutils",
"../rtc_base/network:sent_packet",
+ "../system_wrappers",
"../video/config:encoder_config",
"//third_party/abseil-cpp/absl/functional:any_invocable",
"//third_party/abseil-cpp/absl/strings",
diff --git a/call/syncable.h b/call/syncable.h
index 09c0f22..b6cff19 100644
--- a/call/syncable.h
+++ b/call/syncable.h
@@ -14,32 +14,45 @@
#ifndef CALL_SYNCABLE_H_
#define CALL_SYNCABLE_H_
-#include <stdint.h>
-
+#include <cstdint>
#include <optional>
+#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
+#include "system_wrappers/include/ntp_time.h"
+
namespace webrtc {
class Syncable {
public:
struct Info {
- int64_t latest_receive_time_ms = 0;
- uint32_t latest_received_capture_timestamp = 0;
- uint32_t capture_time_ntp_secs = 0;
- uint32_t capture_time_ntp_frac = 0;
- uint32_t capture_time_source_clock = 0;
- int current_delay_ms = 0;
+ // Local time when the the last RTP packet was received.
+ Timestamp latest_receive_time = Timestamp::Zero();
+ // RTP timestamp of the last RTP packet received.
+ uint32_t latest_received_capture_rtp_timestamp = 0;
+
+ // NTP and RTP timestamp from the last RTCP sender report received.
+ uint32_t capture_time_rtp = 0;
+ NtpTime capture_time_ntp;
+
+ // Current playout delay for the given `Syncable`.
+ TimeDelta current_delay;
+ };
+
+ // Mapping between capture/render time in RTP timestamps and local clock.
+ struct PlayoutInfo {
+ Timestamp time;
+ uint32_t rtp_timestamp;
};
virtual ~Syncable();
virtual uint32_t id() const = 0;
virtual std::optional<Info> GetInfo() const = 0;
- virtual bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const = 0;
- virtual bool SetMinimumPlayoutDelay(int delay_ms) = 0;
- virtual void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) = 0;
+ virtual std::optional<PlayoutInfo> GetPlayoutRtpTimestamp() const = 0;
+ virtual bool SetMinimumPlayoutDelay(TimeDelta delay) = 0;
+ virtual void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) = 0;
};
} // namespace webrtc
diff --git a/video/rtp_streams_synchronizer2.cc b/video/rtp_streams_synchronizer2.cc
index f3c3875..2019ec3 100644
--- a/video/rtp_streams_synchronizer2.cc
+++ b/video/rtp_streams_synchronizer2.cc
@@ -16,6 +16,7 @@
#include "api/sequence_checker.h"
#include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h"
+#include "api/units/timestamp.h"
#include "call/syncable.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@@ -35,11 +36,10 @@
bool UpdateMeasurements(StreamSynchronization::Measurements* stream,
const Syncable::Info& info) {
- stream->latest_timestamp = info.latest_received_capture_timestamp;
- stream->latest_receive_time_ms = info.latest_receive_time_ms;
- return stream->rtp_to_ntp.UpdateMeasurements(
- NtpTime(info.capture_time_ntp_secs, info.capture_time_ntp_frac),
- info.capture_time_source_clock) !=
+ stream->latest_timestamp = info.latest_received_capture_rtp_timestamp;
+ stream->latest_receive_time_ms = info.latest_receive_time.ms();
+ return stream->rtp_to_ntp.UpdateMeasurements(info.capture_time_ntp,
+ info.capture_time_rtp) !=
RtpToNtpEstimator::kInvalidMeasurement;
}
@@ -133,23 +133,23 @@
if (log_stats) {
RTC_LOG(LS_INFO) << "Sync info stats: " << now_ms
<< ", {ssrc: " << sync_->audio_stream_id() << ", "
- << "cur_delay_ms: " << audio_info->current_delay_ms
+ << "cur_delay: " << audio_info->current_delay
<< "} {ssrc: " << sync_->video_stream_id() << ", "
- << "cur_delay_ms: " << video_info->current_delay_ms
+ << "cur_delay: " << video_info->current_delay
<< "} {relative_delay_ms: " << relative_delay_ms << "} ";
}
TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay",
- video_info->current_delay_ms);
+ video_info->current_delay.ms());
TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay",
- audio_info->current_delay_ms);
+ audio_info->current_delay.ms());
TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms);
int target_audio_delay_ms = 0;
- int target_video_delay_ms = video_info->current_delay_ms;
+ int target_video_delay_ms = video_info->current_delay.ms();
// Calculate the necessary extra audio delay and desired total video
// delay to get the streams in sync.
- if (!sync_->ComputeDelays(relative_delay_ms, audio_info->current_delay_ms,
+ if (!sync_->ComputeDelays(relative_delay_ms, audio_info->current_delay.ms(),
&target_audio_delay_ms, &target_video_delay_ms)) {
return;
}
@@ -162,10 +162,12 @@
<< "target_delay_ms: " << target_video_delay_ms << "} ";
}
- if (!syncable_audio_->SetMinimumPlayoutDelay(target_audio_delay_ms)) {
+ if (!syncable_audio_->SetMinimumPlayoutDelay(
+ TimeDelta::Millis(target_audio_delay_ms))) {
sync_->ReduceAudioDelay();
}
- if (!syncable_video_->SetMinimumPlayoutDelay(target_video_delay_ms)) {
+ if (!syncable_video_->SetMinimumPlayoutDelay(
+ TimeDelta::Millis(target_video_delay_ms))) {
sync_->ReduceVideoDelay();
}
}
@@ -184,22 +186,21 @@
if (!syncable_audio_)
return false;
- uint32_t audio_rtp_timestamp;
- int64_t time_ms;
- if (!syncable_audio_->GetPlayoutRtpTimestamp(&audio_rtp_timestamp,
- &time_ms)) {
+ std::optional<Syncable::PlayoutInfo> audio =
+ syncable_audio_->GetPlayoutRtpTimestamp();
+ if (!audio.has_value()) {
return false;
}
NtpTime latest_audio_ntp =
- audio_measurement_.rtp_to_ntp.Estimate(audio_rtp_timestamp);
+ audio_measurement_.rtp_to_ntp.Estimate(audio->rtp_timestamp);
if (!latest_audio_ntp.Valid()) {
return false;
}
int64_t latest_audio_ntp_ms = latest_audio_ntp.ToMs();
- syncable_audio_->SetEstimatedPlayoutNtpTimestampMs(latest_audio_ntp_ms,
- time_ms);
+ syncable_audio_->SetEstimatedPlayoutNtpTimestamp(latest_audio_ntp,
+ audio->time);
NtpTime latest_video_ntp =
video_measurement_.rtp_to_ntp.Estimate(rtp_timestamp);
@@ -209,13 +210,14 @@
int64_t latest_video_ntp_ms = latest_video_ntp.ToMs();
// Current audio ntp.
- int64_t now_ms = TimeMillis();
- latest_audio_ntp_ms += (now_ms - time_ms);
+ Timestamp now = Timestamp::Millis(TimeMillis());
+ latest_audio_ntp_ms += (now - audio->time).ms();
// Remove video playout delay.
- int64_t time_to_render_ms = render_time_ms - now_ms;
- if (time_to_render_ms > 0)
+ int64_t time_to_render_ms = render_time_ms - now.ms();
+ if (time_to_render_ms > 0) {
latest_video_ntp_ms -= time_to_render_ms;
+ }
*video_playout_ntp_ms = latest_video_ntp_ms;
*stream_offset_ms = latest_audio_ntp_ms - latest_video_ntp_ms;
diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc
index 804fff8..ef79a69 100644
--- a/video/rtp_video_stream_receiver2.cc
+++ b/video/rtp_video_stream_receiver2.cc
@@ -426,15 +426,14 @@
if (!last_sr.has_value()) {
return std::nullopt;
}
- info.capture_time_ntp_secs = last_sr->last_remote_ntp_timestamp.seconds();
- info.capture_time_ntp_frac = last_sr->last_remote_ntp_timestamp.fractions();
- info.capture_time_source_clock = last_sr->last_remote_rtp_timestamp;
+ info.capture_time_ntp = last_sr->last_remote_ntp_timestamp;
+ info.capture_time_rtp = last_sr->last_remote_rtp_timestamp;
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_) {
return std::nullopt;
}
- info.latest_received_capture_timestamp = *last_received_rtp_timestamp_;
- info.latest_receive_time_ms = last_received_rtp_system_time_->ms();
+ info.latest_received_capture_rtp_timestamp = *last_received_rtp_timestamp_;
+ info.latest_receive_time = *last_received_rtp_system_time_;
// Leaves info.current_delay_ms uninitialized.
return info;
diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc
index 6c3ebfa..5df80d0 100644
--- a/video/video_receive_stream2.cc
+++ b/video/video_receive_stream2.cc
@@ -84,6 +84,7 @@
#include "rtc_base/time_utils.h"
#include "rtc_base/trace_event.h"
#include "system_wrappers/include/clock.h"
+#include "system_wrappers/include/ntp_time.h"
#include "video/call_stats2.h"
#include "video/corruption_detection/frame_instrumentation_evaluation.h"
#include "video/decode_synchronizer.h"
@@ -790,25 +791,24 @@
if (!info)
return std::nullopt;
- info->current_delay_ms = timing_->TargetVideoDelay().ms();
+ info->current_delay = timing_->TargetVideoDelay();
return info;
}
-bool VideoReceiveStream2::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const {
+std::optional<Syncable::PlayoutInfo>
+VideoReceiveStream2::GetPlayoutRtpTimestamp() const {
RTC_DCHECK_NOTREACHED();
- return false;
+ return std::nullopt;
}
-void VideoReceiveStream2::SetEstimatedPlayoutNtpTimestampMs(
- int64_t ntp_timestamp_ms,
- int64_t time_ms) {
+void VideoReceiveStream2::SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) {
RTC_DCHECK_NOTREACHED();
}
-bool VideoReceiveStream2::SetMinimumPlayoutDelay(int delay_ms) {
+bool VideoReceiveStream2::SetMinimumPlayoutDelay(TimeDelta delay) {
RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
- syncable_minimum_playout_delay_ = TimeDelta::Millis(delay_ms);
+ syncable_minimum_playout_delay_ = delay;
UpdatePlayoutDelays();
return true;
}
diff --git a/video/video_receive_stream2.h b/video/video_receive_stream2.h
index 9ac106f..a00d8cb 100644
--- a/video/video_receive_stream2.h
+++ b/video/video_receive_stream2.h
@@ -50,6 +50,7 @@
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/thread_annotations.h"
+#include "system_wrappers/include/ntp_time.h"
#include "video/corruption_detection/frame_instrumentation_evaluation.h"
#include "video/decode_synchronizer.h"
#include "video/receive_statistics_proxy.h"
@@ -195,13 +196,12 @@
// Implements Syncable.
uint32_t id() const override;
std::optional<Syncable::Info> GetInfo() const override;
- bool GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
- int64_t* time_ms) const override;
- void SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
- int64_t time_ms) override;
+ std::optional<Syncable::PlayoutInfo> GetPlayoutRtpTimestamp() const override;
+ void SetEstimatedPlayoutNtpTimestamp(NtpTime ntp_time,
+ Timestamp time) override;
// SetMinimumPlayoutDelay is only called by A/V sync.
- bool SetMinimumPlayoutDelay(int delay_ms) override;
+ bool SetMinimumPlayoutDelay(TimeDelta delay) override;
std::vector<webrtc::RtpSource> GetSources() const override;
diff --git a/video/video_receive_stream2_unittest.cc b/video/video_receive_stream2_unittest.cc
index ec7f76e..ca8772b 100644
--- a/video/video_receive_stream2_unittest.cc
+++ b/video/video_receive_stream2_unittest.cc
@@ -327,7 +327,7 @@
EXPECT_EQ(kPlayoutDelay.max(), timings.max_playout_delay);
// Check that the biggest minimum delay is chosen.
- video_receive_stream_->SetMinimumPlayoutDelay(400);
+ video_receive_stream_->SetMinimumPlayoutDelay(TimeDelta::Millis(400));
timings = timing_->GetTimings();
EXPECT_EQ(400, timings.min_playout_delay.ms());
@@ -344,7 +344,7 @@
timings = timing_->GetTimings();
EXPECT_EQ(400, timings.min_playout_delay.ms());
- video_receive_stream_->SetMinimumPlayoutDelay(0);
+ video_receive_stream_->SetMinimumPlayoutDelay(TimeDelta::Zero());
timings = timing_->GetTimings();
EXPECT_EQ(123, timings.min_playout_delay.ms());
}
@@ -360,7 +360,7 @@
EXPECT_EQ(timing_->GetTimings().min_playout_delay, kPlayoutDelay.min());
// Check that the biggest minimum delay is limited by the max playout delay.
- video_receive_stream_->SetMinimumPlayoutDelay(400);
+ video_receive_stream_->SetMinimumPlayoutDelay(TimeDelta::Millis(400));
EXPECT_EQ(timing_->GetTimings().min_playout_delay, kPlayoutDelay.max());
}