Index: webrtc/modules/rtp_rtcp/source/time_util.cc |
diff --git a/webrtc/modules/rtp_rtcp/source/time_util.cc b/webrtc/modules/rtp_rtcp/source/time_util.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..73b320c5db14183c141bee5f7a0454dce0c145a0 |
--- /dev/null |
+++ b/webrtc/modules/rtp_rtcp/source/time_util.cc |
@@ -0,0 +1,30 @@ |
+/* |
+ * Copyright (c) 2016 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. |
+ */ |
+ |
+#include "webrtc/modules/rtp_rtcp/source/time_util.h" |
+ |
+#include <algorithm> |
+ |
+namespace webrtc { |
+namespace { |
+// TODO(danilchap): Make generic, optimize and move to base. |
+inline int64_t DivideRoundToNearest(int64_t x, uint32_t y) { |
+ return (x + y/2) / y; |
+} |
+} // namespace |
+ |
+int64_t CompactNtpRttToMs(uint32_t compact_ntp_interval) { |
+ if (compact_ntp_interval > 0x80000000) |
+ return 1; |
+ int64_t value = static_cast<int64_t>(compact_ntp_interval); |
+ value = DivideRoundToNearest(value * 1000, 1 << 16); |
stefan-webrtc
2016/03/04 14:07:33
I think you should comment on how and why this div
danilchap
2016/03/04 15:05:50
negative case handled before division (otherwise d
|
+ return std::max<int64_t>(value, 1); |
+} |
+} // namespace webrtc |