mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-16 07:10:38 +01:00

In https://webrtc-review.googlesource.com/c/src/+/1560 we moved WebRTC from src/webrtc to src/ (in order to preserve an healthy git history). This CL takes care of fixing header guards, #include paths, etc... NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true TBR=tommi@webrtc.org Bug: chromium:611808 Change-Id: Iea91618212bee0af16aa3f05071eab8f93706578 Reviewed-on: https://webrtc-review.googlesource.com/1561 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Henrik Kjellander <kjellander@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#19846}
42 lines
1.8 KiB
C++
42 lines
1.8 KiB
C++
/*
|
|
* 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 "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) {
|
|
// Caller ensure x is positive by converting unsigned value into it.
|
|
// So this Divide doesn't need to handle negative argument case.
|
|
return (x + y / 2) / y;
|
|
}
|
|
} // namespace
|
|
|
|
int64_t CompactNtpRttToMs(uint32_t compact_ntp_interval) {
|
|
// Interval to convert expected to be positive, e.g. rtt or delay.
|
|
// Because interval can be derived from non-monotonic ntp clock,
|
|
// it might become negative that is indistinguishable from very large values.
|
|
// Since very large rtt/delay are less likely than non-monotonic ntp clock,
|
|
// those values consider to be negative and convert to minimum value of 1ms.
|
|
if (compact_ntp_interval > 0x80000000)
|
|
return 1;
|
|
// Convert to 64bit value to avoid multiplication overflow.
|
|
int64_t value = static_cast<int64_t>(compact_ntp_interval);
|
|
// To convert to milliseconds need to divide by 2^16 to get seconds,
|
|
// then multiply by 1000 to get milliseconds. To avoid float operations,
|
|
// multiplication and division swapped.
|
|
int64_t ms = DivideRoundToNearest(value * 1000, 1 << 16);
|
|
// Rtt value 0 considered too good to be true and increases to 1.
|
|
return std::max<int64_t>(ms, 1);
|
|
}
|
|
} // namespace webrtc
|