| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "webrtc/system_wrappers/include/rtp_to_ntp.h" | 12 #include "webrtc/system_wrappers/include/rtp_to_ntp.h" |
| 13 | 13 |
| 14 namespace webrtc { | 14 namespace webrtc { |
| 15 namespace { |
| 16 const uint32_t kOneMsInNtpFrac = 4294967; |
| 17 const uint32_t kTimestampTicksPerMs = 90; |
| 18 } // namespace |
| 15 | 19 |
| 16 TEST(WrapAroundTests, NoWrap) { | 20 TEST(WrapAroundTests, NoWrap) { |
| 17 EXPECT_EQ(0, CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE)); | 21 EXPECT_EQ(0, CheckForWrapArounds(0xFFFFFFFF, 0xFFFFFFFE)); |
| 18 EXPECT_EQ(0, CheckForWrapArounds(1, 0)); | 22 EXPECT_EQ(0, CheckForWrapArounds(1, 0)); |
| 19 EXPECT_EQ(0, CheckForWrapArounds(0x00010000, 0x0000FFFF)); | 23 EXPECT_EQ(0, CheckForWrapArounds(0x00010000, 0x0000FFFF)); |
| 20 } | 24 } |
| 21 | 25 |
| 22 TEST(WrapAroundTests, ForwardWrap) { | 26 TEST(WrapAroundTests, ForwardWrap) { |
| 23 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFFFFFF)); | 27 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFFFFFF)); |
| 24 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFF0000)); | 28 EXPECT_EQ(1, CheckForWrapArounds(0, 0xFFFF0000)); |
| 25 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF)); | 29 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFFFFFF)); |
| 26 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFF0000)); | 30 EXPECT_EQ(1, CheckForWrapArounds(0x0000FFFF, 0xFFFF0000)); |
| 27 } | 31 } |
| 28 | 32 |
| 29 TEST(WrapAroundTests, BackwardWrap) { | 33 TEST(WrapAroundTests, BackwardWrap) { |
| 30 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0)); | 34 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0)); |
| 31 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0)); | 35 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0)); |
| 32 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF)); | 36 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFFFFFF, 0x0000FFFF)); |
| 33 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0x0000FFFF)); | 37 EXPECT_EQ(-1, CheckForWrapArounds(0xFFFF0000, 0x0000FFFF)); |
| 34 } | 38 } |
| 35 | 39 |
| 36 TEST(WrapAroundTests, OldRtcpWrapped) { | 40 TEST(WrapAroundTests, OldRtcpWrapped) { |
| 37 RtcpList rtcp; | 41 RtcpList rtcp; |
| 38 uint32_t ntp_sec = 0; | 42 uint32_t ntp_sec = 0; |
| 39 uint32_t ntp_frac = 0; | 43 uint32_t ntp_frac = 0; |
| 40 uint32_t timestamp = 0; | 44 uint32_t timestamp = 0; |
| 41 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 42 const uint32_t kTimestampTicksPerMs = 90; | |
| 43 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 45 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 44 ntp_frac += kOneMsInNtpFrac; | 46 ntp_frac += kOneMsInNtpFrac; |
| 45 timestamp -= kTimestampTicksPerMs; | 47 timestamp -= kTimestampTicksPerMs; |
| 46 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 48 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 47 ntp_frac += kOneMsInNtpFrac; | 49 ntp_frac += kOneMsInNtpFrac; |
| 48 timestamp -= kTimestampTicksPerMs; | 50 timestamp -= kTimestampTicksPerMs; |
| 49 int64_t timestamp_in_ms = -1; | 51 int64_t timestamp_in_ms = -1; |
| 50 // This expected to fail since it's highly unlikely that the older RTCP | 52 // This expected to fail since it's highly unlikely that the older RTCP |
| 51 // has a much smaller RTP timestamp than the newer. | 53 // has a much smaller RTP timestamp than the newer. |
| 52 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); | 54 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); |
| 53 } | 55 } |
| 54 | 56 |
| 55 TEST(WrapAroundTests, NewRtcpWrapped) { | 57 TEST(WrapAroundTests, NewRtcpWrapped) { |
| 56 RtcpList rtcp; | 58 RtcpList rtcp; |
| 57 uint32_t ntp_sec = 0; | 59 uint32_t ntp_sec = 0; |
| 58 uint32_t ntp_frac = 0; | 60 uint32_t ntp_frac = 0; |
| 59 uint32_t timestamp = 0xFFFFFFFF; | 61 uint32_t timestamp = 0xFFFFFFFF; |
| 60 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 61 const uint32_t kTimestampTicksPerMs = 90; | |
| 62 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 62 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 63 ntp_frac += kOneMsInNtpFrac; | 63 ntp_frac += kOneMsInNtpFrac; |
| 64 timestamp += kTimestampTicksPerMs; | 64 timestamp += kTimestampTicksPerMs; |
| 65 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 65 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 66 int64_t timestamp_in_ms = -1; | 66 int64_t timestamp_in_ms = -1; |
| 67 EXPECT_TRUE(RtpToNtpMs(rtcp.back().rtp_timestamp, rtcp, ×tamp_in_ms)); | 67 EXPECT_TRUE(RtpToNtpMs(rtcp.back().rtp_timestamp, rtcp, ×tamp_in_ms)); |
| 68 // Since this RTP packet has the same timestamp as the RTCP packet constructed | 68 // Since this RTP packet has the same timestamp as the RTCP packet constructed |
| 69 // at time 0 it should be mapped to 0 as well. | 69 // at time 0 it should be mapped to 0 as well. |
| 70 EXPECT_EQ(0, timestamp_in_ms); | 70 EXPECT_EQ(0, timestamp_in_ms); |
| 71 } | 71 } |
| 72 | 72 |
| 73 TEST(WrapAroundTests, RtpWrapped) { | 73 TEST(WrapAroundTests, RtpWrapped) { |
| 74 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 75 const uint32_t kTimestampTicksPerMs = 90; | |
| 76 RtcpList rtcp; | 74 RtcpList rtcp; |
| 77 uint32_t ntp_sec = 0; | 75 uint32_t ntp_sec = 0; |
| 78 uint32_t ntp_frac = 0; | 76 uint32_t ntp_frac = 0; |
| 79 uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs; | 77 uint32_t timestamp = 0xFFFFFFFF - 2 * kTimestampTicksPerMs; |
| 80 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 78 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 81 ntp_frac += kOneMsInNtpFrac; | 79 ntp_frac += kOneMsInNtpFrac; |
| 82 timestamp += kTimestampTicksPerMs; | 80 timestamp += kTimestampTicksPerMs; |
| 83 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 81 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 84 ntp_frac += kOneMsInNtpFrac; | 82 ntp_frac += kOneMsInNtpFrac; |
| 85 timestamp += kTimestampTicksPerMs; | 83 timestamp += kTimestampTicksPerMs; |
| 86 int64_t timestamp_in_ms = -1; | 84 int64_t timestamp_in_ms = -1; |
| 87 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); | 85 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); |
| 88 // Since this RTP packet has the same timestamp as the RTCP packet constructed | 86 // Since this RTP packet has the same timestamp as the RTCP packet constructed |
| 89 // at time 0 it should be mapped to 0 as well. | 87 // at time 0 it should be mapped to 0 as well. |
| 90 EXPECT_EQ(2, timestamp_in_ms); | 88 EXPECT_EQ(2, timestamp_in_ms); |
| 91 } | 89 } |
| 92 | 90 |
| 93 TEST(WrapAroundTests, OldRtp_RtcpsWrapped) { | 91 TEST(WrapAroundTests, OldRtp_RtcpsWrapped) { |
| 94 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 95 const uint32_t kTimestampTicksPerMs = 90; | |
| 96 RtcpList rtcp; | 92 RtcpList rtcp; |
| 97 uint32_t ntp_sec = 0; | 93 uint32_t ntp_sec = 0; |
| 98 uint32_t ntp_frac = 0; | 94 uint32_t ntp_frac = 0; |
| 99 uint32_t timestamp = 0; | 95 uint32_t timestamp = 0; |
| 100 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 96 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 101 ntp_frac += kOneMsInNtpFrac; | 97 ntp_frac += kOneMsInNtpFrac; |
| 102 timestamp += kTimestampTicksPerMs; | 98 timestamp += kTimestampTicksPerMs; |
| 103 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 99 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 104 ntp_frac += kOneMsInNtpFrac; | 100 ntp_frac += kOneMsInNtpFrac; |
| 105 timestamp -= 2*kTimestampTicksPerMs; | 101 timestamp -= 2*kTimestampTicksPerMs; |
| 106 int64_t timestamp_in_ms = -1; | 102 int64_t timestamp_in_ms = -1; |
| 107 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); | 103 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); |
| 108 } | 104 } |
| 109 | 105 |
| 110 TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) { | 106 TEST(WrapAroundTests, OldRtp_NewRtcpWrapped) { |
| 111 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 112 const uint32_t kTimestampTicksPerMs = 90; | |
| 113 RtcpList rtcp; | 107 RtcpList rtcp; |
| 114 uint32_t ntp_sec = 0; | 108 uint32_t ntp_sec = 0; |
| 115 uint32_t ntp_frac = 0; | 109 uint32_t ntp_frac = 0; |
| 116 uint32_t timestamp = 0xFFFFFFFF; | 110 uint32_t timestamp = 0xFFFFFFFF; |
| 117 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 111 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 118 ntp_frac += kOneMsInNtpFrac; | 112 ntp_frac += kOneMsInNtpFrac; |
| 119 timestamp += kTimestampTicksPerMs; | 113 timestamp += kTimestampTicksPerMs; |
| 120 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 114 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 121 ntp_frac += kOneMsInNtpFrac; | 115 ntp_frac += kOneMsInNtpFrac; |
| 122 timestamp -= kTimestampTicksPerMs; | 116 timestamp -= kTimestampTicksPerMs; |
| 123 int64_t timestamp_in_ms = -1; | 117 int64_t timestamp_in_ms = -1; |
| 124 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); | 118 EXPECT_TRUE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); |
| 125 // Constructed at the same time as the first RTCP and should therefore be | 119 // Constructed at the same time as the first RTCP and should therefore be |
| 126 // mapped to zero. | 120 // mapped to zero. |
| 127 EXPECT_EQ(0, timestamp_in_ms); | 121 EXPECT_EQ(0, timestamp_in_ms); |
| 128 } | 122 } |
| 129 | 123 |
| 130 TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) { | 124 TEST(WrapAroundTests, OldRtp_OldRtcpWrapped) { |
| 131 const uint32_t kOneMsInNtpFrac = 4294967; | |
| 132 const uint32_t kTimestampTicksPerMs = 90; | |
| 133 RtcpList rtcp; | 125 RtcpList rtcp; |
| 134 uint32_t ntp_sec = 0; | 126 uint32_t ntp_sec = 0; |
| 135 uint32_t ntp_frac = 0; | 127 uint32_t ntp_frac = 0; |
| 136 uint32_t timestamp = 0; | 128 uint32_t timestamp = 0; |
| 137 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 129 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 138 ntp_frac += kOneMsInNtpFrac; | 130 ntp_frac += kOneMsInNtpFrac; |
| 139 timestamp -= kTimestampTicksPerMs; | 131 timestamp -= kTimestampTicksPerMs; |
| 140 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); | 132 rtcp.push_front(RtcpMeasurement(ntp_sec, ntp_frac, timestamp)); |
| 141 ntp_frac += kOneMsInNtpFrac; | 133 ntp_frac += kOneMsInNtpFrac; |
| 142 timestamp += 2*kTimestampTicksPerMs; | 134 timestamp += 2*kTimestampTicksPerMs; |
| 143 int64_t timestamp_in_ms = -1; | 135 int64_t timestamp_in_ms = -1; |
| 144 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); | 136 EXPECT_FALSE(RtpToNtpMs(timestamp, rtcp, ×tamp_in_ms)); |
| 145 } | 137 } |
| 146 }; // namespace webrtc | 138 }; // namespace webrtc |
| OLD | NEW |