• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
12 #define MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
13 
14 #include <stdint.h>
15 
16 #include "system_wrappers/include/ntp_time.h"
17 
18 namespace webrtc {
19 
20 // Converts time obtained using rtc::TimeMicros to ntp format.
21 // TimeMicrosToNtp guarantees difference of the returned values matches
22 // difference of the passed values.
23 // As a result TimeMicrosToNtp(rtc::TimeMicros()) doesn't guarantee to match
24 // system time.
25 // However, TimeMicrosToNtp Guarantees that returned NtpTime will be offsetted
26 // from rtc::TimeMicros() by integral number of milliseconds.
27 // Use NtpOffsetMs() to get that offset value.
28 NtpTime TimeMicrosToNtp(int64_t time_us);
29 
30 // Difference between Ntp time and local relative time returned by
31 // rtc::TimeMicros()
32 int64_t NtpOffsetMs();
33 
34 // Helper function for compact ntp representation:
35 // RFC 3550, Section 4. Time Format.
36 // Wallclock time is represented using the timestamp format of
37 // the Network Time Protocol (NTP).
38 // ...
39 // In some fields where a more compact representation is
40 // appropriate, only the middle 32 bits are used; that is, the low 16
41 // bits of the integer part and the high 16 bits of the fractional part.
CompactNtp(NtpTime ntp)42 inline uint32_t CompactNtp(NtpTime ntp) {
43   return (ntp.seconds() << 16) | (ntp.fractions() >> 16);
44 }
45 
46 // Converts interval in microseconds to compact ntp (1/2^16 seconds) resolution.
47 // Negative values converted to 0, Overlarge values converted to max uint32_t.
48 uint32_t SaturatedUsToCompactNtp(int64_t us);
49 
50 // Converts interval between compact ntp timestamps to milliseconds.
51 // This interval can be up to ~9.1 hours (2^15 seconds).
52 // Values close to 2^16 seconds consider negative and result in minimum rtt = 1.
53 int64_t CompactNtpRttToMs(uint32_t compact_ntp_interval);
54 
55 }  // namespace webrtc
56 #endif  // MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
57