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

Side by Side Diff: webrtc/system_wrappers/include/ntp_time.h

Issue 1482593002: Introduce helper class NtpTime (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | webrtc/system_wrappers/source/ntp_time_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2015 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 #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_
11 #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_
12
13 #include "webrtc/base/basictypes.h"
14 #include "webrtc/system_wrappers/include/clock.h"
15
16 namespace webrtc {
17
18 class NtpTime {
19 public:
20 NtpTime() : seconds_(0), fractions_(0) {}
21 explicit NtpTime(const Clock& clock) {
22 clock.CurrentNtp(seconds_, fractions_);
23 }
24 NtpTime(uint32_t seconds, uint32_t fractions)
25 : seconds_(seconds), fractions_(fractions) {}
26
27 NtpTime(const NtpTime&) = default;
28 NtpTime& operator=(const NtpTime&) = default;
29
30 void SetCurrent(const Clock& clock) {
31 clock.CurrentNtp(seconds_, fractions_);
32 }
33 void Set(uint32_t seconds, uint32_t fractions) {
34 seconds_ = seconds;
35 fractions_ = fractions;
36 }
37 void Reset() {
38 seconds_ = 0;
39 fractions_ = 0;
40 }
41
42 int64_t ToMs() const { return Clock::NtpToMs(seconds_, fractions_); }
43
44 // NTP standard (RFC1305, section 3.1) explicitly state value 0/0 is invalid.
45 bool Valid() const { return !(seconds_ == 0 && fractions_ == 0); }
46
47 uint32_t seconds() const { return seconds_; }
48 uint32_t fractions() const { return fractions_; }
49
50 private:
51 uint32_t seconds_;
52 uint32_t fractions_;
53 };
54
55 inline bool operator==(const NtpTime& n1, const NtpTime& n2) {
56 return n1.seconds() == n2.seconds() && n1.fractions() == n2.fractions();
57 }
58 inline bool operator!=(const NtpTime& n1, const NtpTime& n2) {
59 return !(n1 == n2);
60 }
61
62 } // namespace webrtc
63 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_NTP_TIME_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/system_wrappers/source/ntp_time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698