diff options
author | Chih-hung Hsieh <chh@google.com> | 2015-12-01 17:07:48 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-12-01 17:07:48 +0000 |
commit | a4acd9d6bc9b3b033d7d274316e75ee067df8d20 (patch) | |
tree | 672a185b294789cf991f385c3e395dd63bea9063 /webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc | |
parent | 3681b90ba4fe7a27232dd3e27897d5d7ed9d651c (diff) | |
parent | fe8b4a657979b49e1701bd92f6d5814a99e0b2be (diff) | |
download | webrtc-a4acd9d6bc9b3b033d7d274316e75ee067df8d20.tar.gz |
Merge changes I7bbf776e,I1b827825
am: fe8b4a6579
* commit 'fe8b4a657979b49e1701bd92f6d5814a99e0b2be': (7237 commits)
WIP: Changes after merge commit 'cb3f9bd'
Make the nonlinear beamformer steerable
Utilize bitrate above codec max to protect video.
Enable VP9 internal resize by default.
Filter overlapping RTP header extensions.
Make VCMEncodedFrameCallback const.
MediaCodecVideoEncoder: Add number of quality resolution downscales to Encoded callback.
Remove redudant encoder rate calls.
Create isolate files for nonparallel tests.
Register header extensions in RtpRtcpObserver to avoid log spam.
Make an enum class out of NetEqDecoder, and hide the neteq_decoders_ table
ACM: Move NACK functionality inside NetEq
Fix chromium-style warnings in webrtc/sound/.
Create a 'webrtc_nonparallel_tests' target.
Update scalability structure data according to updates in the RTP payload profile.
audio_coding: rename interface -> include
Rewrote perform_action_on_all_files to be parallell.
Update reference indices according to updates in the RTP payload profile.
Disable P2PTransport...TestFailoverControlledSide on Memcheck
pass clangcl compile options to ignore warnings in gflags.cc
...
Diffstat (limited to 'webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc')
-rw-r--r-- | webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc b/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc new file mode 100644 index 0000000000..bc9cf2ee39 --- /dev/null +++ b/webrtc/modules/rtp_rtcp/source/remote_ntp_time_estimator_unittest.cc @@ -0,0 +1,101 @@ +/* +* Copyright (c) 2014 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. +*/ + +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "webrtc/common_types.h" +#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h" +#include "webrtc/system_wrappers/include/clock.h" + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::SetArgPointee; + +namespace webrtc { + +static const int64_t kTestRtt = 10; +static const int64_t kLocalClockInitialTimeMs = 123; +static const int64_t kRemoteClockInitialTimeMs = 345; +static const uint32_t kTimestampOffset = 567; + +class RemoteNtpTimeEstimatorTest : public ::testing::Test { + protected: + RemoteNtpTimeEstimatorTest() + : local_clock_(kLocalClockInitialTimeMs * 1000), + remote_clock_(kRemoteClockInitialTimeMs * 1000), + estimator_(&local_clock_) {} + ~RemoteNtpTimeEstimatorTest() {} + + void AdvanceTimeMilliseconds(int64_t ms) { + local_clock_.AdvanceTimeMilliseconds(ms); + remote_clock_.AdvanceTimeMilliseconds(ms); + } + + uint32_t GetRemoteTimestamp() { + return static_cast<uint32_t>(remote_clock_.TimeInMilliseconds()) * 90 + + kTimestampOffset; + } + + void SendRtcpSr() { + uint32_t rtcp_timestamp = GetRemoteTimestamp(); + uint32_t ntp_seconds; + uint32_t ntp_fractions; + remote_clock_.CurrentNtp(ntp_seconds, ntp_fractions); + + AdvanceTimeMilliseconds(kTestRtt / 2); + ReceiveRtcpSr(kTestRtt, rtcp_timestamp, ntp_seconds, ntp_fractions); + } + + void UpdateRtcpTimestamp(int64_t rtt, uint32_t ntp_secs, uint32_t ntp_frac, + uint32_t rtp_timestamp, bool expected_result) { + EXPECT_EQ(expected_result, + estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, + rtp_timestamp)); + } + + void ReceiveRtcpSr(int64_t rtt, + uint32_t rtcp_timestamp, + uint32_t ntp_seconds, + uint32_t ntp_fractions) { + UpdateRtcpTimestamp(rtt, ntp_seconds, ntp_fractions, rtcp_timestamp, true); + } + + SimulatedClock local_clock_; + SimulatedClock remote_clock_; + RemoteNtpTimeEstimator estimator_; +}; + +TEST_F(RemoteNtpTimeEstimatorTest, Estimate) { + // Failed without valid NTP. + UpdateRtcpTimestamp(kTestRtt, 0, 0, 0, false); + + AdvanceTimeMilliseconds(1000); + // Remote peer sends first RTCP SR. + SendRtcpSr(); + + // Remote sends a RTP packet. + AdvanceTimeMilliseconds(15); + uint32_t rtp_timestamp = GetRemoteTimestamp(); + int64_t capture_ntp_time_ms = local_clock_.CurrentNtpInMilliseconds(); + + // Local peer needs at least 2 RTCP SR to calculate the capture time. + const int64_t kNotEnoughRtcpSr = -1; + EXPECT_EQ(kNotEnoughRtcpSr, estimator_.Estimate(rtp_timestamp)); + + AdvanceTimeMilliseconds(800); + // Remote sends second RTCP SR. + SendRtcpSr(); + + // Local peer gets enough RTCP SR to calculate the capture time. + EXPECT_EQ(capture_ntp_time_ms, estimator_.Estimate(rtp_timestamp)); +} + +} // namespace webrtc |