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

Unified Diff: webrtc/modules/rtp_rtcp/source/ntp_time.h

Issue 1435833003: Introduce helper class NtpTime (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/modules.gyp ('k') | webrtc/modules/rtp_rtcp/source/ntp_time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/rtp_rtcp/source/ntp_time.h
diff --git a/webrtc/modules/rtp_rtcp/source/ntp_time.h b/webrtc/modules/rtp_rtcp/source/ntp_time.h
new file mode 100644
index 0000000000000000000000000000000000000000..455d1a2968831b47efd710cb48da934255b059d0
--- /dev/null
+++ b/webrtc/modules/rtp_rtcp/source/ntp_time.h
@@ -0,0 +1,56 @@
+/*
+* Copyright (c) 2015 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.
+*/
+#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_
+#define WEBRTC_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_
+
+#include "webrtc/base/basictypes.h"
+#include "webrtc/system_wrappers/include/clock.h"
+
+namespace webrtc {
+namespace rtcp {
+
+class NtpTime {
+ public:
+ NtpTime() : seconds_(0), fractions_(0) {}
+ explicit NtpTime(const Clock& clock) {
+ clock.CurrentNtp(seconds_, fractions_);
+ }
+ NtpTime(uint32_t seconds, uint32_t fractions)
+ : seconds_(seconds), fractions_(fractions) {}
+
+ NtpTime(const NtpTime&) = default;
+ NtpTime& operator=(const NtpTime&) = default;
+
+ void SetCurrent(const Clock& clock) {
+ clock.CurrentNtp(seconds_, fractions_);
+ }
+ void Set(uint32_t seconds, uint32_t fractions) {
+ seconds_ = seconds;
+ fractions_ = fractions;
+ }
+ void clear() { seconds_ = fractions_ = 0; }
sprang_webrtc 2015/11/12 15:34:48 Assign separately
danilchap 2015/11/12 19:05:31 Done.
+
+ int64_t ToMs() const { return Clock::NtpToMs(seconds_, fractions_); }
+ uint32_t MidNtp() const { return (seconds_ << 16) | (fractions_ >> 16); }
sprang_webrtc 2015/11/12 15:34:48 I think this one deserves a comment :)
danilchap 2015/11/12 19:05:31 (bad excuse)RTCPUtility::MidNtp I took this from d
sprang_webrtc 2015/11/16 09:55:25 Ah, so great that we get one now!
+
+ // Conversion to bool to test if we have a valid value.
+ explicit operator bool() const { return seconds_ != 0 || fractions_ != 0; }
sprang_webrtc 2015/11/12 15:34:48 When would this be used? Are we implicitly saying
danilchap 2015/11/12 19:05:31 To make it more explicit conversion to bool replac
sprang_webrtc 2015/11/16 09:55:25 Gotcha. A comment to that affect would be great. :
danilchap 2015/11/16 11:01:33 Done.
+
+ uint32_t seconds() const { return seconds_; }
+ uint32_t fractions() const { return fractions_; }
+
+ private:
+ uint32_t seconds_;
+ uint32_t fractions_;
+};
+
+} // namespace rtcp
+} // namespace webrtc
+#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_NTP_TIME_H_
« no previous file with comments | « webrtc/modules/modules.gyp ('k') | webrtc/modules/rtp_rtcp/source/ntp_time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698