chromium/third_party/openscreen/src/cast/streaming/impl/ntp_time.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_STREAMING_IMPL_NTP_TIME_H_
#define CAST_STREAMING_IMPL_NTP_TIME_H_

#include <stdint.h>

#include "platform/api/time.h"

namespace openscreen::cast {

// NTP timestamps are 64-bit timestamps that consist of two 32-bit parts: 1) The
// number of seconds since 1 January 1900; and 2) The fraction of the second,
// where 0 maps to 0x00000000 and each unit increment represents another 2^-32
// seconds.
//
// Note that it is part of the design of NTP for the seconds part to roll around
// on 7 February 2036.
NtpTimestamp;

// NTP fixed-point time math: Declare two std::chrono::duration types with the
// bit-width necessary to reliably perform all conversions to/from NTP format.
NtpSeconds;
NtpFraction;

constexpr NtpSeconds NtpSecondsPart(NtpTimestamp timestamp) {}

constexpr NtpFraction NtpFractionPart(NtpTimestamp timestamp) {}

constexpr NtpTimestamp AssembleNtpTimestamp(NtpSeconds seconds,
                                            NtpFraction fraction) {}

// Converts between Clock::time_points and NtpTimestamps. The class is
// instantiated with the current Clock time and the current wall clock time, and
// these are used to determine a fixed origin reference point for all
// conversions. Thus, to avoid introducing unintended timing-related behaviors,
// only one NtpTimeConverter instance should be used for converting all the NTP
// timestamps in the same streaming session.
class NtpTimeConverter {};

}  // namespace openscreen::cast

#endif  // CAST_STREAMING_IMPL_NTP_TIME_H_