OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include "webrtc/test/drifting_clock.h" | |
12 #include "webrtc/base/checks.h" | |
13 | |
14 namespace webrtc { | |
15 namespace test { | |
16 | |
17 DriftingClock::DriftingClock(Clock* clock, float drift) | |
18 : clock_(clock), drift_(drift), start_time_(-1) { | |
pbos-webrtc
2016/02/09 20:42:25
make start_time_ const and set in init list
danilchap
2016/02/10 12:40:35
Done.
| |
19 RTC_CHECK(clock); | |
20 RTC_CHECK_GT(drift, -1.0f); | |
21 start_time_ = clock_->TimeInMicroseconds(); | |
22 } | |
23 | |
24 float DriftingClock::Drift() const { | |
25 int64_t now = clock_->TimeInMicroseconds(); | |
26 RTC_DCHECK_GE(now, start_time_); | |
27 return (now - start_time_) * drift_; | |
28 } | |
29 | |
30 int64_t DriftingClock::TimeInMilliseconds() const { | |
31 return clock_->TimeInMilliseconds() + Drift() / 1000.; | |
32 } | |
33 | |
34 int64_t DriftingClock::TimeInMicroseconds() const { | |
35 return clock_->TimeInMicroseconds() + Drift(); | |
36 } | |
37 | |
38 void DriftingClock::CurrentNtp(uint32_t& seconds, uint32_t& fractions) const { | |
39 const double kNtpFracPerMicroSecond = 4294.967296; // = 2^32 / 10^6 | |
pbos-webrtc
2016/02/09 20:42:25
Can you link to something or explain that NTP are
danilchap
2016/02/10 12:40:35
Added small comment stating NTP is based on 1/2^32
| |
40 | |
41 clock_->CurrentNtp(seconds, fractions); | |
42 uint64_t total_fractions = (static_cast<uint64_t>(seconds) << 32) | fractions; | |
43 total_fractions += Drift() * kNtpFracPerMicroSecond; | |
44 seconds = total_fractions >> 32; | |
45 fractions = static_cast<uint32_t>(total_fractions); | |
46 } | |
47 | |
48 int64_t DriftingClock::CurrentNtpInMilliseconds() const { | |
49 return clock_->CurrentNtpInMilliseconds() + Drift() / 1000.; | |
50 } | |
51 } // namespace test | |
52 } // namespace webrtc | |
OLD | NEW |