tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b57de3573ed0ed29dae8c6f1243b56a9f7f98996
parent 91568cbae16d756939b8fe9b26c20630d3c7a351
Author: Dan Baker <dbaker@mozilla.com>
Date:   Wed, 22 Oct 2025 15:43:23 -0600

Bug 1995393 - Vendor libwebrtc from d121734ee7

Upstream commit: https://webrtc.googlesource.com/src/+/d121734ee7b5086b7a20c9ad1edb7db9c81443d6
    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}

Diffstat:
Mthird_party/libwebrtc/README.mozilla.last-vendor | 4++--
Mthird_party/libwebrtc/audio/audio_receive_stream.cc | 21+++++++++++----------
Mthird_party/libwebrtc/audio/audio_receive_stream.h | 12+++++++-----
Mthird_party/libwebrtc/audio/channel_receive.cc | 91++++++++++++++++++++++++++++++++++++-------------------------------------------
Mthird_party/libwebrtc/audio/channel_receive.h | 11++++++-----
Mthird_party/libwebrtc/audio/mock_voe_channel_proxy.h | 13++++++++-----
Mthird_party/libwebrtc/call/BUILD.gn | 1+
Mthird_party/libwebrtc/call/syncable.h | 39++++++++++++++++++++++++++-------------
Mthird_party/libwebrtc/moz-patch-stack/s0001.patch | 2+-
Mthird_party/libwebrtc/moz-patch-stack/s0027.patch | 2+-
Mthird_party/libwebrtc/moz-patch-stack/s0030.patch | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0035.patch | 24++++++++++++------------
Mthird_party/libwebrtc/moz-patch-stack/s0037.patch | 8++++----
Mthird_party/libwebrtc/moz-patch-stack/s0039.patch | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0042.patch | 8++++----
Mthird_party/libwebrtc/moz-patch-stack/s0057.patch | 8++++----
Mthird_party/libwebrtc/moz-patch-stack/s0058.patch | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0059.patch | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0060.patch | 4++--
Mthird_party/libwebrtc/moz-patch-stack/s0071.patch | 2+-
Mthird_party/libwebrtc/moz-patch-stack/s0128.patch | 10+++++-----
Mthird_party/libwebrtc/video/rtp_streams_synchronizer2.cc | 50++++++++++++++++++++++++++------------------------
Mthird_party/libwebrtc/video/rtp_video_stream_receiver2.cc | 9++++-----
Mthird_party/libwebrtc/video/video_receive_stream2.cc | 18+++++++++---------
Mthird_party/libwebrtc/video/video_receive_stream2.h | 10+++++-----
Mthird_party/libwebrtc/video/video_receive_stream2_unittest.cc | 6+++---
26 files changed, 191 insertions(+), 178 deletions(-)

diff --git a/third_party/libwebrtc/README.mozilla.last-vendor b/third_party/libwebrtc/README.mozilla.last-vendor @@ -1,4 +1,4 @@ # ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc -libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-22T21:14:31.120179+00:00. +libwebrtc updated from /Users/danielbaker/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-10-22T21:43:05.832067+00:00. # base of lastest vendoring -684e8494e0 +d121734ee7 diff --git a/third_party/libwebrtc/audio/audio_receive_stream.cc b/third_party/libwebrtc/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 { @@ -411,25 +414,23 @@ std::optional<Syncable::Info> AudioReceiveStreamImpl::GetInfo() const { 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/third_party/libwebrtc/audio/audio_receive_stream.h b/third_party/libwebrtc/audio/audio_receive_stream.h @@ -32,6 +32,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" // This can be removed after Bug 1768116 enables // c++20 builds across the entire Mozilla tree. #if !defined(WEBRTC_MOZILLA_BUILD) @@ -42,6 +44,7 @@ #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; @@ -130,11 +133,10 @@ class AudioReceiveStreamImpl final : public webrtc::AudioReceiveStreamInterface, // 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/third_party/libwebrtc/audio/channel_receive.cc b/third_party/libwebrtc/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 @@ namespace { 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, @@ -170,11 +169,10 @@ class ChannelReceive : public ChannelReceiveInterface, // 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; @@ -222,7 +220,7 @@ class ChannelReceive : public ChannelReceiveInterface, 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; @@ -267,7 +265,7 @@ class ChannelReceive : public ChannelReceiveInterface, 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. @@ -282,13 +280,12 @@ class ChannelReceive : public ChannelReceiveInterface, // 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_; @@ -581,7 +578,6 @@ ChannelReceive::ChannelReceive( 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), @@ -665,13 +661,13 @@ void ChannelReceive::SetReceiveCodecs( 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()) @@ -762,7 +758,7 @@ void ChannelReceive::ReceivedRTCPPacket(const uint8_t* data, size_t length) { 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)); @@ -1049,46 +1045,41 @@ uint32_t ChannelReceive::GetDelayEstimate() const { 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) { @@ -1109,23 +1100,23 @@ std::optional<Syncable::Info> ChannelReceive::GetSyncInfo() const { 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(); @@ -1150,9 +1141,9 @@ void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms) { // 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/third_party/libwebrtc/audio/channel_receive.h b/third_party/libwebrtc/audio/channel_receive.h @@ -40,6 +40,7 @@ #include "call/syncable.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" +#include "system_wrappers/include/ntp_time.h" namespace webrtc { @@ -124,11 +125,11 @@ class ChannelReceiveInterface : public RtpPacketSinkInterface { // 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/third_party/libwebrtc/audio/mock_voe_channel_proxy.h b/third_party/libwebrtc/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 @@ class MockChannelReceive : public voe::ChannelReceiveInterface { (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 @@ class MockChannelReceive : public voe::ChannelReceiveInterface { 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/third_party/libwebrtc/call/BUILD.gn b/third_party/libwebrtc/call/BUILD.gn @@ -75,6 +75,7 @@ rtc_library("call_interfaces") { "../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/third_party/libwebrtc/call/syncable.h b/third_party/libwebrtc/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/third_party/libwebrtc/moz-patch-stack/s0001.patch b/third_party/libwebrtc/moz-patch-stack/s0001.patch @@ -413,7 +413,7 @@ index 7bd443f711..a433aa21e7 100644 bool RtpExtension::IsSupportedForVideo(absl::string_view uri) { diff --git a/call/BUILD.gn b/call/BUILD.gn -index 3f5c615fac..d9ef5920dc 100644 +index d3504a3aba..a9c0de8016 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -20,6 +20,7 @@ rtc_library("call_interfaces") { diff --git a/third_party/libwebrtc/moz-patch-stack/s0027.patch b/third_party/libwebrtc/moz-patch-stack/s0027.patch @@ -478,7 +478,7 @@ index 67a2dbf7ec..9c5e881a70 100644 if (rtc_include_tests) { rtc_source_set("test_feedback_generator_interface") { diff --git a/call/BUILD.gn b/call/BUILD.gn -index d9ef5920dc..808f55d243 100644 +index a9c0de8016..f8b2a9b7b5 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -48,7 +48,7 @@ rtc_library("call_interfaces") { diff --git a/third_party/libwebrtc/moz-patch-stack/s0030.patch b/third_party/libwebrtc/moz-patch-stack/s0030.patch @@ -25,10 +25,10 @@ index ae9951e6f9..c69ec1a674 100644 // See LntfConfig for description. diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index 804fff8951..932a2cd7a7 100644 +index ef79a69ad2..47274dcf33 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc -@@ -1411,7 +1411,7 @@ void RtpVideoStreamReceiver2::StartReceive() { +@@ -1410,7 +1410,7 @@ void RtpVideoStreamReceiver2::StartReceive() { // Change REMB candidate egibility. packet_router_->RemoveReceiveRtpModule(rtp_rtcp_.get()); packet_router_->AddReceiveRtpModule(rtp_rtcp_.get(), diff --git a/third_party/libwebrtc/moz-patch-stack/s0035.patch b/third_party/libwebrtc/moz-patch-stack/s0035.patch @@ -20,10 +20,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/d0b311007c033e838 11 files changed, 55 insertions(+), 10 deletions(-) diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc -index bbe84801e5..c61d4ba025 100644 +index 0496aa8126..fad0e247a1 100644 --- a/audio/audio_receive_stream.cc +++ b/audio/audio_receive_stream.cc -@@ -58,6 +58,8 @@ std::string AudioReceiveStreamInterface::Config::Rtp::ToString() const { +@@ -61,6 +61,8 @@ std::string AudioReceiveStreamInterface::Config::Rtp::ToString() const { << (rtcp_mode == RtcpMode::kCompound ? "compound" : (rtcp_mode == RtcpMode::kReducedSize ? "reducedSize" : "off")); @@ -32,7 +32,7 @@ index bbe84801e5..c61d4ba025 100644 ss << '}'; return ss.str(); } -@@ -91,7 +93,7 @@ std::unique_ptr<voe::ChannelReceiveInterface> CreateChannelReceive( +@@ -94,7 +96,7 @@ std::unique_ptr<voe::ChannelReceiveInterface> CreateChannelReceive( config.jitter_buffer_min_delay_ms, config.enable_non_sender_rtt, config.decoder_factory, config.codec_pair_id, std::move(config.frame_decryptor), config.crypto_options, @@ -42,10 +42,10 @@ index bbe84801e5..c61d4ba025 100644 } // namespace diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc -index 658266e41b..296551f60a 100644 +index b98ac8efc8..149d4a287d 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc -@@ -133,7 +133,8 @@ class ChannelReceive : public ChannelReceiveInterface, +@@ -132,7 +132,8 @@ class ChannelReceive : public ChannelReceiveInterface, std::optional<AudioCodecPairId> codec_pair_id, scoped_refptr<FrameDecryptorInterface> frame_decryptor, const CryptoOptions& crypto_options, @@ -55,7 +55,7 @@ index 658266e41b..296551f60a 100644 ~ChannelReceive() override; void SetSink(AudioSinkInterface* sink) override; -@@ -564,7 +565,8 @@ ChannelReceive::ChannelReceive( +@@ -561,7 +562,8 @@ ChannelReceive::ChannelReceive( std::optional<AudioCodecPairId> codec_pair_id, scoped_refptr<FrameDecryptorInterface> frame_decryptor, const CryptoOptions& crypto_options, @@ -65,7 +65,7 @@ index 658266e41b..296551f60a 100644 : env_(env), worker_thread_(TaskQueueBase::Current()), rtp_receive_statistics_(ReceiveStatistics::Create(&env_.clock())), -@@ -599,6 +601,7 @@ ChannelReceive::ChannelReceive( +@@ -595,6 +597,7 @@ ChannelReceive::ChannelReceive( configuration.local_media_ssrc = local_ssrc; configuration.rtcp_packet_type_counter_observer = this; configuration.non_sender_rtt_measurement = enable_non_sender_rtt; @@ -73,7 +73,7 @@ index 658266e41b..296551f60a 100644 if (frame_transformer) InitFrameTransformerDelegate(std::move(frame_transformer)); -@@ -1191,13 +1194,14 @@ std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( +@@ -1182,13 +1185,14 @@ std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( std::optional<AudioCodecPairId> codec_pair_id, scoped_refptr<FrameDecryptorInterface> frame_decryptor, const CryptoOptions& crypto_options, @@ -91,7 +91,7 @@ index 658266e41b..296551f60a 100644 } // namespace voe diff --git a/audio/channel_receive.h b/audio/channel_receive.h -index 0783363a7a..f99568ae78 100644 +index 7eb8639dd7..27ae061fd5 100644 --- a/audio/channel_receive.h +++ b/audio/channel_receive.h @@ -39,6 +39,7 @@ @@ -99,10 +99,10 @@ index 0783363a7a..f99568ae78 100644 #include "call/syncable.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h" +#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" + #include "system_wrappers/include/ntp_time.h" namespace webrtc { - -@@ -183,7 +184,8 @@ std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( +@@ -184,7 +185,8 @@ std::unique_ptr<ChannelReceiveInterface> CreateChannelReceive( std::optional<AudioCodecPairId> codec_pair_id, scoped_refptr<FrameDecryptorInterface> frame_decryptor, const webrtc::CryptoOptions& crypto_options, @@ -267,7 +267,7 @@ index 40836198de..d2304e87db 100644 // DEPRECATED, transport_feedback_callback is no longer invoked by the RTP diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index 932a2cd7a7..a16b936cf6 100644 +index 47274dcf33..f51b30ad41 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -129,7 +129,8 @@ std::unique_ptr<ModuleRtpRtcpImpl2> CreateRtpRtcpModule( diff --git a/third_party/libwebrtc/moz-patch-stack/s0037.patch b/third_party/libwebrtc/moz-patch-stack/s0037.patch @@ -15,10 +15,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/edac9d01a9ac7594f 3 files changed, 24 insertions(+) diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index a16b936cf6..deb1c0d4f7 100644 +index f51b30ad41..252425d32d 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc -@@ -1177,6 +1177,16 @@ std::optional<int64_t> RtpVideoStreamReceiver2::LastReceivedKeyframePacketMs() +@@ -1176,6 +1176,16 @@ std::optional<int64_t> RtpVideoStreamReceiver2::LastReceivedKeyframePacketMs() return std::nullopt; } @@ -53,10 +53,10 @@ index 18ee7ffa46..7e358c3c13 100644 // Implements RtpVideoFrameReceiver. void ManageFrame(std::unique_ptr<RtpFrameObject> frame) override; diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc -index 6c3ebfa4d4..8e3a3a3a93 100644 +index 5df80d049a..9f2ca6ad5a 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc -@@ -626,6 +626,14 @@ VideoReceiveStreamInterface::Stats VideoReceiveStream2::GetStats() const { +@@ -627,6 +627,14 @@ VideoReceiveStreamInterface::Stats VideoReceiveStream2::GetStats() const { stats.sender_reports_bytes_sent = rtcp_sr_stats->bytes_sent; stats.sender_reports_reports_count = rtcp_sr_stats->reports_count; } diff --git a/third_party/libwebrtc/moz-patch-stack/s0039.patch b/third_party/libwebrtc/moz-patch-stack/s0039.patch @@ -16,10 +16,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/c186df8a088e46285 1 file changed, 1 deletion(-) diff --git a/audio/audio_receive_stream.cc b/audio/audio_receive_stream.cc -index c61d4ba025..9edf55fb0a 100644 +index fad0e247a1..a276df5b24 100644 --- a/audio/audio_receive_stream.cc +++ b/audio/audio_receive_stream.cc -@@ -382,7 +382,6 @@ int AudioReceiveStreamImpl::GetBaseMinimumPlayoutDelayMs() const { +@@ -385,7 +385,6 @@ int AudioReceiveStreamImpl::GetBaseMinimumPlayoutDelayMs() const { } std::vector<RtpSource> AudioReceiveStreamImpl::GetSources() const { diff --git a/third_party/libwebrtc/moz-patch-stack/s0042.patch b/third_party/libwebrtc/moz-patch-stack/s0042.patch @@ -159,10 +159,10 @@ index d2304e87db..bbdb38864e 100644 // Within this list, the sender-source SSRC pair is unique and per-pair the // ReportBlockData represents the latest Report Block that was received for diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index deb1c0d4f7..7f98bd0249 100644 +index 252425d32d..5ef6f85a9f 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc -@@ -1182,9 +1182,10 @@ std::optional<int64_t> RtpVideoStreamReceiver2::LastReceivedKeyframePacketMs() +@@ -1181,9 +1181,10 @@ std::optional<int64_t> RtpVideoStreamReceiver2::LastReceivedKeyframePacketMs() // seem to be any support for these stats right now. So, we hack this in. void RtpVideoStreamReceiver2::RemoteRTCPSenderInfo( uint32_t* packet_count, uint32_t* octet_count, @@ -190,10 +190,10 @@ index 7e358c3c13..05498bd640 100644 private: // Implements RtpVideoFrameReceiver. diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc -index 8e3a3a3a93..293c0f58e0 100644 +index 9f2ca6ad5a..0f7db25b33 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc -@@ -632,7 +632,8 @@ VideoReceiveStreamInterface::Stats VideoReceiveStream2::GetStats() const { +@@ -633,7 +633,8 @@ VideoReceiveStreamInterface::Stats VideoReceiveStream2::GetStats() const { // seem to be any support for these stats right now. So, we hack this in. rtp_video_stream_receiver_.RemoteRTCPSenderInfo( &stats.rtcp_sender_packets_sent, &stats.rtcp_sender_octets_sent, diff --git a/third_party/libwebrtc/moz-patch-stack/s0057.patch b/third_party/libwebrtc/moz-patch-stack/s0057.patch @@ -214,7 +214,7 @@ index 111b7f3c45..fb411d4bbf 100644 int current_delay_ms, int target_delay_ms, diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index 7f98bd0249..172ffa94c9 100644 +index 5ef6f85a9f..94ec20c1d4 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -286,6 +286,7 @@ RtpVideoStreamReceiver2::RtpVideoStreamReceiver2( @@ -233,7 +233,7 @@ index 7f98bd0249..172ffa94c9 100644 packet_buffer_(kPacketBufferStartSize, PacketBufferMaxSize(env_.field_trials())), reference_finder_(std::make_unique<RtpFrameReferenceFinder>()), -@@ -1402,7 +1404,8 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { +@@ -1401,7 +1403,8 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { int64_t unwrapped_rtp_seq_num = rtp_seq_num_unwrapper_.Unwrap(seq_num); packet_infos_.erase(packet_infos_.begin(), packet_infos_.upper_bound(unwrapped_rtp_seq_num)); @@ -272,10 +272,10 @@ index 05498bd640..e35711dc8b 100644 RTC_GUARDED_BY(packet_sequence_checker_); // h26x_packet_buffer_ is applicable to H.264 and H.265. For H.265 it is diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc -index 293c0f58e0..0c5d0b8e83 100644 +index 0f7db25b33..91bc98b49b 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc -@@ -256,6 +256,7 @@ VideoReceiveStream2::VideoReceiveStream2( +@@ -257,6 +257,7 @@ VideoReceiveStream2::VideoReceiveStream2( &stats_proxy_, &stats_proxy_, nack_periodic_processor, diff --git a/third_party/libwebrtc/moz-patch-stack/s0058.patch b/third_party/libwebrtc/moz-patch-stack/s0058.patch @@ -30,10 +30,10 @@ index c8058ea132..568fd441d2 100644 void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) { diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index 172ffa94c9..be0e8914a3 100644 +index 94ec20c1d4..4468be7128 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc -@@ -1405,7 +1405,9 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { +@@ -1404,7 +1404,9 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { packet_infos_.erase(packet_infos_.begin(), packet_infos_.upper_bound(unwrapped_rtp_seq_num)); uint32_t num_packets_cleared = packet_buffer_.ClearTo(seq_num); diff --git a/third_party/libwebrtc/moz-patch-stack/s0059.patch b/third_party/libwebrtc/moz-patch-stack/s0059.patch @@ -166,7 +166,7 @@ index 568fd441d2..30eec9f090 100644 } diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index be0e8914a3..52bb158a36 100644 +index 4468be7128..c6298b0025 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -91,6 +91,7 @@ @@ -177,7 +177,7 @@ index be0e8914a3..52bb158a36 100644 #include "system_wrappers/include/ntp_time.h" #include "video/buffered_frame_decryptor.h" -@@ -1406,6 +1407,9 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { +@@ -1405,6 +1406,9 @@ void RtpVideoStreamReceiver2::FrameDecoded(int64_t picture_id) { packet_infos_.upper_bound(unwrapped_rtp_seq_num)); uint32_t num_packets_cleared = packet_buffer_.ClearTo(seq_num); if (num_packets_cleared > 0) { diff --git a/third_party/libwebrtc/moz-patch-stack/s0060.patch b/third_party/libwebrtc/moz-patch-stack/s0060.patch @@ -9,10 +9,10 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/5b2a7894ef1cf096d 1 file changed, 6 insertions(+) diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index 52bb158a36..ca9dc3fcf7 100644 +index c6298b0025..93e4c70b04 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc -@@ -830,6 +830,12 @@ void RtpVideoStreamReceiver2::OnRtpPacket(const RtpPacketReceived& packet) { +@@ -829,6 +829,12 @@ void RtpVideoStreamReceiver2::OnRtpPacket(const RtpPacketReceived& packet) { void RtpVideoStreamReceiver2::RequestKeyFrame() { RTC_DCHECK_RUN_ON(&worker_task_checker_); diff --git a/third_party/libwebrtc/moz-patch-stack/s0071.patch b/third_party/libwebrtc/moz-patch-stack/s0071.patch @@ -50,7 +50,7 @@ index 1e6678b4ee..1ed48c08d7 100644 Clock* const clock_; bool short_circuit_ RTC_GUARDED_BY(network_sequence_checker_) = false; diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc -index ca9dc3fcf7..273e0b01f5 100644 +index 93e4c70b04..e756ce0b75 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -383,7 +383,7 @@ RtpVideoStreamReceiver2::RtpVideoStreamReceiver2( diff --git a/third_party/libwebrtc/moz-patch-stack/s0128.patch b/third_party/libwebrtc/moz-patch-stack/s0128.patch @@ -15,13 +15,13 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/9c487a574d218cc1c 1 file changed, 12 insertions(+) diff --git a/audio/audio_receive_stream.h b/audio/audio_receive_stream.h -index 0d78482e0e..d7ebd8c9d1 100644 +index 4b6c57b871..3f054776d2 100644 --- a/audio/audio_receive_stream.h +++ b/audio/audio_receive_stream.h -@@ -32,7 +32,11 @@ - #include "api/scoped_refptr.h" - #include "api/sequence_checker.h" +@@ -34,7 +34,11 @@ #include "api/transport/rtp/rtp_source.h" + #include "api/units/time_delta.h" + #include "api/units/timestamp.h" +// This can be removed after Bug 1768116 enables +// c++20 builds across the entire Mozilla tree. +#if !defined(WEBRTC_MOZILLA_BUILD) @@ -30,7 +30,7 @@ index 0d78482e0e..d7ebd8c9d1 100644 #include "call/audio_receive_stream.h" #include "call/audio_state.h" #include "call/syncable.h" -@@ -44,6 +48,14 @@ class PacketRouter; +@@ -47,6 +51,14 @@ class PacketRouter; class RtpStreamReceiverControllerInterface; class RtpStreamReceiverInterface; diff --git a/third_party/libwebrtc/video/rtp_streams_synchronizer2.cc b/third_party/libwebrtc/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 @@ constexpr TimeDelta kSyncInterval = TimeDelta::Millis(1000); 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 @@ void RtpStreamsSynchronizer::UpdateDelay() { 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 @@ void RtpStreamsSynchronizer::UpdateDelay() { << "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 @@ bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs( 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 @@ bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs( 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/third_party/libwebrtc/video/rtp_video_stream_receiver2.cc b/third_party/libwebrtc/video/rtp_video_stream_receiver2.cc @@ -432,15 +432,14 @@ std::optional<Syncable::Info> RtpVideoStreamReceiver2::GetSyncInfo() const { 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/third_party/libwebrtc/video/video_receive_stream2.cc b/third_party/libwebrtc/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" @@ -800,25 +801,24 @@ std::optional<Syncable::Info> VideoReceiveStream2::GetInfo() const { 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/third_party/libwebrtc/video/video_receive_stream2.h b/third_party/libwebrtc/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 @@ class VideoReceiveStream2 // 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/third_party/libwebrtc/video/video_receive_stream2_unittest.cc b/third_party/libwebrtc/video/video_receive_stream2_unittest.cc @@ -327,7 +327,7 @@ TEST_P(VideoReceiveStream2Test, PlayoutDelay) { 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 @@ TEST_P(VideoReceiveStream2Test, PlayoutDelay) { 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 @@ TEST_P(VideoReceiveStream2Test, MinPlayoutDelayIsLimitedByMaxPlayoutDelay) { 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()); }