danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 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 WEBRTC_MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_ |
| 12 | #define WEBRTC_MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_ |
| 13 | |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 16 | #include "webrtc/system_wrappers/include/ntp_time.h" |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // Converts NTP timestamp to RTP timestamp. |
| 21 | inline uint32_t NtpToRtp(NtpTime ntp, uint32_t freq) { |
| 22 | uint32_t tmp = (static_cast<uint64_t>(ntp.fractions()) * freq) >> 32; |
| 23 | return ntp.seconds() * freq + tmp; |
| 24 | } |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 25 | |
| 26 | // Helper function for compact ntp representation: |
| 27 | // RFC 3550, Section 4. Time Format. |
| 28 | // Wallclock time is represented using the timestamp format of |
| 29 | // the Network Time Protocol (NTP). |
| 30 | // ... |
| 31 | // In some fields where a more compact representation is |
| 32 | // appropriate, only the middle 32 bits are used; that is, the low 16 |
| 33 | // bits of the integer part and the high 16 bits of the fractional part. |
| 34 | inline uint32_t CompactNtp(NtpTime ntp) { |
| 35 | return (ntp.seconds() << 16) | (ntp.fractions() >> 16); |
| 36 | } |
| 37 | // Converts interval between compact ntp timestamps to milliseconds. |
Danil Chapovalov | c1e55c7 | 2016-03-09 15:14:35 +0100 | [diff] [blame] | 38 | // This interval can be up to ~9.1 hours (2^15 seconds). |
| 39 | // Values close to 2^16 seconds consider negative and result in minimum rtt = 1. |
| 40 | int64_t CompactNtpRttToMs(uint32_t compact_ntp_interval); |
danilchap | 1227e8b | 2015-12-21 11:06:50 -0800 | [diff] [blame] | 41 | |
| 42 | } // namespace webrtc |
| 43 | #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_ |