2012-09-26 16:47:40 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-27 12:41:33 +00:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
2015-10-28 18:17:40 +01:00
|
|
|
#include "webrtc/system_wrappers/include/rtp_to_ntp.h"
|
2012-09-26 16:47:40 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-03-15 01:00:47 -07:00
|
|
|
namespace {
|
|
|
|
|
const uint32_t kOneMsInNtpFrac = 4294967;
|
|
|
|
|
const uint32_t kTimestampTicksPerMs = 90;
|
|
|
|
|
} // namespace
|
2012-09-26 16:47:40 +00:00
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, NoWrap) {
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_EQ(0, CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE));
|
|
|
|
|
EXPECT_EQ(0, CheckForWrapArounds(1, 0));
|
|
|
|
|
EXPECT_EQ(0, CheckForWrapArounds(0x00010000, 0x0000FFFF));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, ForwardWrap) {
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFFFFFF));
|
|
|
|
|
EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFF0000));
|
|
|
|
|
EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF));
|
|
|
|
|
EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFF0000));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, BackwardWrap) {
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0));
|
|
|
|
|
EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0));
|
|
|
|
|
EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF));
|
|
|
|
|
EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0x0000FFFF));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, OldRtcpWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp -= kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp -= kTimestampTicksPerMs;
|
|
|
|
|
int64_t timestamp_in_ms = -1;
|
|
|
|
|
// This expected to fail since it's highly unlikely that the older RTCP
|
|
|
|
|
// has a much smaller RTP timestamp than the newer.
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, NewRtcpWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0xFFFFFFFF;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
int64_t timestamp_in_ms = -1;
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_TRUE(RtpToNtpMs(rtcp.back().rtp_timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
// Since this RTP packet has the same timestamp as the RTCP packet constructed
|
|
|
|
|
// at time 0 it should be mapped to 0 as well.
|
|
|
|
|
EXPECT_EQ(0, timestamp_in_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, RtpWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += kTimestampTicksPerMs;
|
|
|
|
|
int64_t timestamp_in_ms = -1;
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
// Since this RTP packet has the same timestamp as the RTCP packet constructed
|
|
|
|
|
// at time 0 it should be mapped to 0 as well.
|
|
|
|
|
EXPECT_EQ(2, timestamp_in_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, OldRtp_RtcpsWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp -= 2*kTimestampTicksPerMs;
|
|
|
|
|
int64_t timestamp_in_ms = -1;
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0xFFFFFFFF;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp -= kTimestampTicksPerMs;
|
|
|
|
|
int64_t timestamp_in_ms = -1;
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
// Constructed at the same time as the first RTCP and should therefore be
|
|
|
|
|
// mapped to zero.
|
|
|
|
|
EXPECT_EQ(0, timestamp_in_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) {
|
2014-05-07 17:09:44 +00:00
|
|
|
RtcpList rtcp;
|
2012-09-26 16:47:40 +00:00
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp -= kTimestampTicksPerMs;
|
2014-05-07 17:09:44 +00:00
|
|
|
rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp));
|
2012-09-26 16:47:40 +00:00
|
|
|
ntp_frac += kOneMsInNtpFrac;
|
|
|
|
|
timestamp += 2*kTimestampTicksPerMs;
|
|
|
|
|
int64_t timestamp_in_ms = -1;
|
2014-05-07 17:09:44 +00:00
|
|
|
EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms));
|
2012-09-26 16:47:40 +00:00
|
|
|
}
|
2016-04-19 07:04:47 -07:00
|
|
|
|
|
|
|
|
TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualNtp) {
|
|
|
|
|
RtcpList rtcp;
|
|
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 2;
|
|
|
|
|
uint32_t timestamp = 0x12345678;
|
|
|
|
|
|
|
|
|
|
bool new_sr;
|
|
|
|
|
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
|
|
|
|
|
EXPECT_TRUE(new_sr);
|
|
|
|
|
|
|
|
|
|
++timestamp;
|
|
|
|
|
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
|
|
|
|
|
EXPECT_FALSE(new_sr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(UpdateRtcpListTests, InjectRtcpSrWithEqualTimestamp) {
|
|
|
|
|
RtcpList rtcp;
|
|
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 2;
|
|
|
|
|
uint32_t timestamp = 0x12345678;
|
|
|
|
|
|
|
|
|
|
bool new_sr;
|
|
|
|
|
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
|
|
|
|
|
EXPECT_TRUE(new_sr);
|
|
|
|
|
|
|
|
|
|
++ntp_frac;
|
|
|
|
|
EXPECT_TRUE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
|
|
|
|
|
EXPECT_FALSE(new_sr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(UpdateRtcpListTests, InjectRtcpSrWithZeroNtpFails) {
|
|
|
|
|
RtcpList rtcp;
|
|
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
uint32_t timestamp = 0x12345678;
|
|
|
|
|
|
|
|
|
|
bool new_sr;
|
|
|
|
|
EXPECT_FALSE(UpdateRtcpList(ntp_sec, ntp_frac, timestamp, &rtcp, &new_sr));
|
|
|
|
|
}
|
2012-09-26 16:47:40 +00:00
|
|
|
}; // namespace webrtc
|