OLD | NEW |
---|---|
(Empty) | |
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 | |
14 #include "webrtc/base/basictypes.h" | |
15 #include "webrtc/system_wrappers/include/ntp_time.h" | |
16 | |
17 namespace webrtc { | |
18 | |
19 // Converts NTP timestamp to RTP timestamp. | |
20 inline uint32_t NtpToRtp(NtpTime ntp, uint32_t freq) { | |
21 uint32_t tmp = (static_cast<uint64_t>(ntp.fractions()) * freq) >> 32; | |
22 return ntp.seconds() * freq + tmp; | |
23 } | |
24 // Return the current RTP timestamp from the NTP timestamp | |
25 // returned by the specified clock. | |
26 inline uint32_t CurrentRtp(const Clock& clock, uint32_t freq) { | |
27 return NtpToRtp(NtpTime(clock), freq); | |
28 } | |
29 | |
30 // Helper function for compact ntp representation: | |
31 // RFC 3550, Section 4. Time Format. | |
32 // Wallclock time is represented using the timestamp format of | |
33 // the Network Time Protocol (NTP). | |
34 // ... | |
35 // In some fields where a more compact representation is | |
36 // appropriate, only the middle 32 bits are used; that is, the low 16 | |
37 // bits of the integer part and the high 16 bits of the fractional part. | |
38 inline uint32_t CompactNtp(NtpTime ntp) { | |
39 return (ntp.seconds() << 16) | (ntp.fractions() >> 16); | |
40 } | |
åsapersson
2015/12/21 15:16:20
Maybe add a comment that a Ntp difference up to ~1
danilchap
2015/12/21 16:14:34
Done.
| |
41 inline uint32_t CompactNtpIntervalToMs(uint32_t ntp) { | |
åsapersson
2015/12/21 15:16:20
call this ntp_diff?
danilchap
2015/12/21 16:14:34
good idea. Called it compact_ntp_interval:
compact
| |
42 return static_cast<uint64_t>(ntp) * 1000 / (1 << 16); | |
43 } | |
44 | |
45 } // namespace webrtc | |
46 #endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_ | |
OLD | NEW |