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}
This commit is contained in:
asapersson 2016-09-30 03:16:19 -07:00 committed by Commit bot
parent f5297a019e
commit 3cc47ebd2d
2 changed files with 17 additions and 0 deletions

View File

@ -110,6 +110,9 @@ bool RtpToNtpMs(int64_t rtp_timestamp,
&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,

View File

@ -136,6 +136,20 @@ TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) {
EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, &timestamp_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, &timestamp_in_ms));
}
TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualNtp) {
RtcpList rtcp;
uint32_t ntp_sec = 0;