blob: c883e5ca38f3dd0798ee9dd8bcfef29803f9ddfa [file] [log] [blame]
danilchap1227e8b2015-12-21 11:06:50 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
12#define MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
danilchap1227e8b2015-12-21 11:06:50 -080013
pbosc7c26a02017-01-02 08:42:32 -080014#include <stdint.h>
15
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "system_wrappers/include/ntp_time.h"
danilchap1227e8b2015-12-21 11:06:50 -080017
18namespace webrtc {
19
danilchap1227e8b2015-12-21 11:06:50 -080020// Helper function for compact ntp representation:
21// RFC 3550, Section 4. Time Format.
22// Wallclock time is represented using the timestamp format of
23// the Network Time Protocol (NTP).
24// ...
25// In some fields where a more compact representation is
26// appropriate, only the middle 32 bits are used; that is, the low 16
27// bits of the integer part and the high 16 bits of the fractional part.
28inline uint32_t CompactNtp(NtpTime ntp) {
29 return (ntp.seconds() << 16) | (ntp.fractions() >> 16);
30}
Danil Chapovalovd4fdc272017-11-09 11:34:32 +010031
32// Converts interval in microseconds to compact ntp (1/2^16 seconds) resolution.
33// Negative values converted to 0, Overlarge values converted to max uint32_t.
34uint32_t SaturatedUsToCompactNtp(int64_t us);
35
danilchap1227e8b2015-12-21 11:06:50 -080036// Converts interval between compact ntp timestamps to milliseconds.
Danil Chapovalovc1e55c72016-03-09 15:14:35 +010037// This interval can be up to ~9.1 hours (2^15 seconds).
38// Values close to 2^16 seconds consider negative and result in minimum rtt = 1.
39int64_t CompactNtpRttToMs(uint32_t compact_ntp_interval);
danilchap1227e8b2015-12-21 11:06:50 -080040
41} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#endif // MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_