Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
ntp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_packet/ntp.h
10//! @brief Utitilies for NTP timestamp.
11
12#ifndef ROC_PACKET_NTP_H_
13#define ROC_PACKET_NTP_H_
14
15#include "roc_core/time.h"
16
17namespace roc {
18namespace packet {
19
20//! NTP timestamp.
21//!
22//! Format:
23//! - highest 32 bits - seconds since NTP epoch
24//! - lowest 32 bits - fractions of a second
25//!
26//! Epoch:
27//! - for dates in years 1968-2036, epoch starts from 1 Jan 1900 00:00:00
28//! - for dates in years 2036-2104, epoch starts from 7 Feb 2036 06:28:16
29//!
30//! See RFC 5905 and RFC 2030.
31//!
32//! See also:
33//! - https://tickelton.gitlab.io/articles/ntp-timestamps/
34//! - https://www.eecis.udel.edu/~mills/y2k.html
35typedef uint64_t ntp_timestamp_t;
36
37//! Convert Unix absolute time to NTP absolute time.
38//! @remarks
39//! @p unix_time defines nanoseconds since Unix epoch (should belong to years 1968-2104).
41
42//! Convert NTP absolute time to Unix absolute time.
44
45//! Convert nanoseconds delta to NTP delta.
46//! @remarks
47//! @p ns_delta defines nanoseconds delta (should be positive)
49
50//! Converts NTP delta to nanoseconds delta.
52
53} // namespace packet
54} // namespace roc
55
56#endif // ROC_PACKET_NTP_H_
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
ntp_timestamp_t unix_2_ntp(core::nanoseconds_t unix_time)
Convert Unix absolute time to NTP absolute time.
ntp_timestamp_t nanoseconds_2_ntp(core::nanoseconds_t ns_delta)
Convert nanoseconds delta to NTP delta.
uint64_t ntp_timestamp_t
NTP timestamp.
Definition ntp.h:35
core::nanoseconds_t ntp_2_nanoseconds(ntp_timestamp_t ntp_delta)
Converts NTP delta to nanoseconds delta.
core::nanoseconds_t ntp_2_unix(ntp_timestamp_t ntp_time)
Convert NTP absolute time to Unix absolute time.
Root namespace.
Time definitions.