OLD | NEW |
(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_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_ |
| 11 #define WEBRTC_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_ |
| 12 |
| 13 #include "webrtc/base/basictypes.h" |
| 14 #include "webrtc/system_wrappers/include/clock.h" |
| 15 |
| 16 namespace webrtc { |
| 17 namespace rtcp { |
| 18 |
| 19 class NtpTime { |
| 20 public: |
| 21 NtpTime() : seconds_(0), fractions_(0) {} |
| 22 explicit NtpTime(const Clock& clock) { |
| 23 clock.CurrentNtp(seconds_, fractions_); |
| 24 } |
| 25 NtpTime(uint32_t seconds, uint32_t fractions) |
| 26 : seconds_(seconds), fractions_(fractions) {} |
| 27 |
| 28 NtpTime(const NtpTime&) = default; |
| 29 NtpTime& operator=(const NtpTime&) = default; |
| 30 |
| 31 void SetCurrent(const Clock& clock) { |
| 32 clock.CurrentNtp(seconds_, fractions_); |
| 33 } |
| 34 void Set(uint32_t seconds, uint32_t fractions) { |
| 35 seconds_ = seconds; |
| 36 fractions_ = fractions; |
| 37 } |
| 38 void Reset() { |
| 39 seconds_ = 0; |
| 40 fractions_ = 0; |
| 41 } |
| 42 |
| 43 int64_t ToMs() const { return Clock::NtpToMs(seconds_, fractions_); } |
| 44 // RFC3611, section 4.5. DLRR Report Block. |
| 45 // Used to calculate delays in 1/65536 seconds. |
| 46 uint32_t MidNtp() const { return (seconds_ << 16) | (fractions_ >> 16); } |
| 47 |
| 48 // NTP standard (RFC1305, section 3.1) explicitly state value 0/0 is invalid. |
| 49 bool Valid() const { return !(seconds_ == 0 && fractions_ == 0); } |
| 50 |
| 51 uint32_t seconds() const { return seconds_; } |
| 52 uint32_t fractions() const { return fractions_; } |
| 53 |
| 54 private: |
| 55 uint32_t seconds_; |
| 56 uint32_t fractions_; |
| 57 }; |
| 58 |
| 59 inline bool operator==(const NtpTime& n1, const NtpTime& n2) { |
| 60 return n1.seconds() == n2.seconds() && n1.fractions() == n2.fractions(); |
| 61 } |
| 62 inline bool operator!=(const NtpTime& n1, const NtpTime& n2) { |
| 63 return !(n1 == n2); |
| 64 } |
| 65 |
| 66 } // namespace rtcp |
| 67 } // namespace webrtc |
| 68 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_ |
OLD | NEW |