Add sanity check for decreasing RTP timestamp in RtpToNtpMs. The capture time for a frame (capture_ms) is set later (in ViEEncoder::IncomingCapturedFrame) than the timestamp. Could potentially cause the RTP timestamp in consecutive RTCP SR to decrease. Example: // Frame1 46371: timestamp:2732, capture_ms:46373, rtcp SR ms: 46423 -> estimated current RTP timestamp:2732+(46423-46373)*90 = 7232 // Frame2 46404: timestamp:5702, capture_ms:46412, rtcp SR ms: 46428 -> estimated current RTP timestamp:5702+(46428-46412)*90 = 7142 // Diff: 33 ms: 33 ms, 39 ms, 5 ms BUG=b/31154867 Review-Url: https://codereview.webrtc.org/2354843003 Cr-Commit-Position: refs/heads/master@{#14454}
diff --git a/webrtc/system_wrappers/source/rtp_to_ntp.cc b/webrtc/system_wrappers/source/rtp_to_ntp.cc index 6504737..0509146 100644 --- a/webrtc/system_wrappers/source/rtp_to_ntp.cc +++ b/webrtc/system_wrappers/source/rtp_to_ntp.cc
@@ -110,6 +110,9 @@ &rtcp_timestamp_new)) { return false; } + if (rtcp_timestamp_new < rtcp_timestamp_old) + return false; + double freq_khz; if (!CalculateFrequency(rtcp_ntp_ms_new, rtcp_timestamp_new,
diff --git a/webrtc/system_wrappers/source/rtp_to_ntp_unittest.cc b/webrtc/system_wrappers/source/rtp_to_ntp_unittest.cc index 0e81e4d8..ce1f26d 100644 --- a/webrtc/system_wrappers/source/rtp_to_ntp_unittest.cc +++ b/webrtc/system_wrappers/source/rtp_to_ntp_unittest.cc
@@ -136,6 +136,20 @@ EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); } +TEST(RtpToNtpTests, FailsForDecreasingRtpTimestamp) { + const uint32_t kNtpSec1 = 3683354930; + const uint32_t kNtpFrac1 = 699925050; + const uint32_t kTimestamp1 = 2192705742; + const uint32_t kNtpSec2 = kNtpSec1; + const uint32_t kNtpFrac2 = kNtpFrac1 + kOneMsInNtpFrac; + const uint32_t kTimestamp2 = kTimestamp1 - kTimestampTicksPerMs; + RtcpList rtcp; + rtcp.push_front(RtcpMeasurement(kNtpSec1, kNtpFrac1, kTimestamp1)); + rtcp.push_front(RtcpMeasurement(kNtpSec2, kNtpFrac2, kTimestamp2)); + int64_t timestamp_in_ms = -1; + EXPECT_FALSE(RtpToNtpMs(kTimestamp1, rtcp, ×tamp_in_ms)); +} + TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualNtp) { RtcpList rtcp; uint32_t ntp_sec = 0;