diff --git a/media/base/fakeframesource.cc b/media/base/fakeframesource.cc index ffc3eee773..5e5213be7e 100644 --- a/media/base/fakeframesource.cc +++ b/media/base/fakeframesource.cc @@ -15,13 +15,26 @@ namespace cricket { -FakeFrameSource::FakeFrameSource(int width, int height, int interval_us) - : width_(width), height_(height), interval_us_(interval_us) { +FakeFrameSource::FakeFrameSource(int width, + int height, + int interval_us, + int64_t timestamp_offset_us) + : width_(width), + height_(height), + interval_us_(interval_us), + next_timestamp_us_(timestamp_offset_us) { RTC_CHECK_GT(width_, 0); RTC_CHECK_GT(height_, 0); RTC_CHECK_GT(interval_us_, 0); + RTC_CHECK_GE(next_timestamp_us_, 0); } +FakeFrameSource::FakeFrameSource(int width, int height, int interval_us) + : FakeFrameSource(width, + height, + interval_us, + rtc::kNumMicrosecsPerMillisec) {} + webrtc::VideoRotation FakeFrameSource::GetRotation() const { return rotation_; } diff --git a/media/base/fakeframesource.h b/media/base/fakeframesource.h index db440457c0..fb433ae436 100644 --- a/media/base/fakeframesource.h +++ b/media/base/fakeframesource.h @@ -19,6 +19,10 @@ namespace cricket { class FakeFrameSource { public: + FakeFrameSource(int width, + int height, + int interval_us, + int64_t timestamp_offset_us); FakeFrameSource(int width, int height, int interval_us); webrtc::VideoRotation GetRotation() const; @@ -39,7 +43,7 @@ class FakeFrameSource { const int interval_us_; webrtc::VideoRotation rotation_ = webrtc::kVideoRotation_0; - int64_t next_timestamp_us_ = rtc::kNumMicrosecsPerMillisec; + int64_t next_timestamp_us_; }; } // namespace cricket diff --git a/modules/rtp_rtcp/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index e58aeb06c5..d69a6f07b6 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -11,6 +11,7 @@ #include "modules/rtp_rtcp/source/rtp_sender.h" #include +#include #include #include @@ -1011,7 +1012,15 @@ void RTPSender::UpdateDelayStatistics(int64_t capture_time_ms, int64_t now_ms) { { rtc::CritScope cs(&statistics_crit_); // TODO(holmer): Compute this iteratively instead. - send_delays_[now_ms] = now_ms - capture_time_ms; + RTC_DCHECK_GE(now_ms, static_cast(0)); + RTC_DCHECK_LE(now_ms, std::numeric_limits::max() / 2); + RTC_DCHECK_GE(capture_time_ms, static_cast(0)); + RTC_DCHECK_LE(capture_time_ms, std::numeric_limits::max() / 2); + int64_t diff_ms = now_ms - capture_time_ms; + RTC_DCHECK_GE(diff_ms, static_cast(0)); + RTC_DCHECK_LE(diff_ms, + static_cast(std::numeric_limits::max())); + send_delays_[now_ms] = diff_ms; send_delays_.erase( send_delays_.begin(), send_delays_.lower_bound(now_ms - kSendSideDelayWindowMs)); diff --git a/ortc/ortcfactory_integrationtest.cc b/ortc/ortcfactory_integrationtest.cc index 681dda948e..62f29520ed 100644 --- a/ortc/ortcfactory_integrationtest.cc +++ b/ortc/ortcfactory_integrationtest.cc @@ -24,6 +24,7 @@ #include "rtc_base/fakenetwork.h" #include "rtc_base/gunit.h" #include "rtc_base/system/arch.h" +#include "rtc_base/timeutils.h" #include "rtc_base/virtualsocketserver.h" namespace { @@ -224,9 +225,11 @@ class OrtcFactoryIntegrationTest : public testing::Test { rtc::scoped_refptr CreateLocalVideoTrackAndFakeSource(const std::string& id, OrtcFactoryInterface* ortc_factory) { + FakePeriodicVideoSource::Config config; + config.timestamp_offset_ms = rtc::TimeMillis(); fake_video_track_sources_.emplace_back( new rtc::RefCountedObject( - false /* remote */)); + config, false /* remote */)); return rtc::scoped_refptr( ortc_factory->CreateVideoTrack(id, fake_video_track_sources_.back())); } diff --git a/pc/peerconnection_integrationtest.cc b/pc/peerconnection_integrationtest.cc index d9fa1d5abd..dd977b4d3f 100644 --- a/pc/peerconnection_integrationtest.cc +++ b/pc/peerconnection_integrationtest.cc @@ -61,6 +61,7 @@ #include "rtc_base/gunit.h" #include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/testcertificateverifier.h" +#include "rtc_base/timeutils.h" #include "rtc_base/virtualsocketserver.h" #include "system_wrappers/include/metrics_default.h" #include "test/gmock.h" @@ -348,8 +349,9 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, } rtc::scoped_refptr CreateLocalVideoTrack() { - return CreateLocalVideoTrackInternal( - webrtc::FakePeriodicVideoSource::Config()); + webrtc::FakePeriodicVideoSource::Config config; + config.timestamp_offset_ms = rtc::TimeMillis(); + return CreateLocalVideoTrackInternal(config); } rtc::scoped_refptr @@ -362,6 +364,7 @@ class PeerConnectionWrapper : public webrtc::PeerConnectionObserver, CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) { webrtc::FakePeriodicVideoSource::Config config; config.rotation = rotation; + config.timestamp_offset_ms = rtc::TimeMillis(); return CreateLocalVideoTrackInternal(config); } @@ -1836,6 +1839,7 @@ TEST_P(PeerConnectionIntegrationTest, webrtc::FakePeriodicVideoSource::Config config; config.width = 1280; config.height = 720; + config.timestamp_offset_ms = rtc::TimeMillis(); caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config)); callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config)); diff --git a/pc/test/fakeperiodicvideosource.h b/pc/test/fakeperiodicvideosource.h index 087deeb543..146d49e585 100644 --- a/pc/test/fakeperiodicvideosource.h +++ b/pc/test/fakeperiodicvideosource.h @@ -33,6 +33,7 @@ class FakePeriodicVideoSource final int height = kDefaultHeight; int frame_interval_ms = kDefaultFrameIntervalMs; VideoRotation rotation = kVideoRotation_0; + int64_t timestamp_offset_ms = 0; }; FakePeriodicVideoSource() : FakePeriodicVideoSource(Config()) {} @@ -67,7 +68,8 @@ class FakePeriodicVideoSource final frame_source_( config.width, config.height, - config.frame_interval_ms * rtc::kNumMicrosecsPerMillisec), + config.frame_interval_ms * rtc::kNumMicrosecsPerMillisec, + config.timestamp_offset_ms * rtc::kNumMicrosecsPerMillisec), broadcaster_(broadcaster) { frame_source_.SetRotation(config.rotation); } diff --git a/pc/test/peerconnectiontestwrapper.cc b/pc/test/peerconnectiontestwrapper.cc index 03dabb554e..9be1596373 100644 --- a/pc/test/peerconnectiontestwrapper.cc +++ b/pc/test/peerconnectiontestwrapper.cc @@ -22,6 +22,7 @@ #include "pc/test/mockpeerconnectionobservers.h" #include "pc/test/peerconnectiontestwrapper.h" #include "rtc_base/gunit.h" +#include "rtc_base/timeutils.h" using webrtc::FakeConstraints; using webrtc::FakeVideoTrackRenderer; @@ -287,6 +288,7 @@ PeerConnectionTestWrapper::GetUserMedia( // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. webrtc::FakePeriodicVideoSource::Config config; config.frame_interval_ms = 100; + config.timestamp_offset_ms = rtc::TimeMillis(); rtc::scoped_refptr source = new rtc::RefCountedObject(