Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: webrtc/test/drifting_clock.cc

Issue 1674413004: Added A/V sync tests with drifting clocks. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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) {
19 RTC_CHECK(clock);
20 RTC_CHECK_GT(drift, -1.);
stefan-webrtc 2016/02/09 14:02:20 I think all of these float constants should be -1.
danilchap 2016/02/09 14:56:49 Done.
21 start_time_ = clock_->TimeInMicroseconds();
22 }
23
24 float DriftingClock::Drift() const {
25 return (clock_->TimeInMicroseconds() - start_time_) * drift_;
stefan-webrtc 2016/02/09 14:02:20 DCHECK that start_time_ >= 0 here.
danilchap 2016/02/09 14:56:49 But start_time_ is set in the constructor 3 lines
stefan-webrtc 2016/02/10 13:20:52 Ah, my mistake. Good that you moved it to the init
26 }
27
28 int64_t DriftingClock::TimeInMilliseconds() const {
29 return clock_->TimeInMilliseconds() + Drift() / 1000.;
30 }
31
32 int64_t DriftingClock::TimeInMicroseconds() const {
33 return clock_->TimeInMicroseconds() + Drift();
34 }
35
36 void DriftingClock::CurrentNtp(uint32_t& seconds, uint32_t& fractions) const {
37 const double kNtpFracPerMicroSecond = 4294.967296; // = 2^32 / 10^6
38
39 clock_->CurrentNtp(seconds, fractions);
40 uint64_t totalfractions = (static_cast<uint64_t>(seconds) << 32) | fractions;
stefan-webrtc 2016/02/09 14:02:20 total_fractions
danilchap 2016/02/09 14:56:49 Done.
41 totalfractions += Drift() * kNtpFracPerMicroSecond;
42 seconds = totalfractions >> 32;
43 fractions = static_cast<uint32_t>(totalfractions);
44 }
45
46 int64_t DriftingClock::CurrentNtpInMilliseconds() const {
47 return clock_->CurrentNtpInMilliseconds() + Drift() / 1000.;
48 }
49 } // namespace test
50 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698