Split out time_util to separate target ntp_time_util
Split out time_util.h and cc from target rtp_rtcp to its own target. This is to avoid possible circular dependencies and not having all targets using them to depend on the full RtpRcp module. Bug: webrtc:343076000 Change-Id: I7b3c84456b17f1920f71afdd5a644d27e28caed2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/352480 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Auto-Submit: Per Kjellander <perkj@webrtc.org> Commit-Queue: Per Kjellander <perkj@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Reviewed-by: Jakob Ivarsson <jakobi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42392}
This commit is contained in:
parent
045589e64c
commit
61fff586b1
@ -236,6 +236,7 @@ if (rtc_include_tests) {
|
||||
"../logging:mocks",
|
||||
"../modules/audio_device:mock_audio_device",
|
||||
"../modules/rtp_rtcp",
|
||||
"../modules/rtp_rtcp:ntp_time_util",
|
||||
"../modules/rtp_rtcp:rtp_rtcp_format",
|
||||
"../rtc_base:logging",
|
||||
"../rtc_base:threading",
|
||||
|
||||
@ -19,12 +19,12 @@
|
||||
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
|
||||
#include "modules/audio_device/include/mock_audio_device.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/sdes.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
@ -233,7 +233,6 @@ rtc_library("rtp_rtcp") {
|
||||
"source/rtp_video_stream_receiver_frame_transformer_delegate.h",
|
||||
"source/source_tracker.cc",
|
||||
"source/source_tracker.h",
|
||||
"source/time_util.cc",
|
||||
"source/time_util.h",
|
||||
"source/tmmbr_help.cc",
|
||||
"source/tmmbr_help.h",
|
||||
@ -272,6 +271,7 @@ rtc_library("rtp_rtcp") {
|
||||
|
||||
deps = [
|
||||
":leb128",
|
||||
":ntp_time_util",
|
||||
":rtp_rtcp_format",
|
||||
":rtp_video_header",
|
||||
"..:module_api_public",
|
||||
@ -364,6 +364,7 @@ rtc_source_set("rtp_rtcp_legacy") {
|
||||
"source/rtp_rtcp_impl.h",
|
||||
]
|
||||
deps = [
|
||||
":ntp_time_util",
|
||||
":rtp_rtcp",
|
||||
":rtp_rtcp_format",
|
||||
"..:module_fec_api",
|
||||
@ -388,6 +389,22 @@ rtc_source_set("rtp_rtcp_legacy") {
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("ntp_time_util") {
|
||||
visibility = [ "*" ]
|
||||
sources = [
|
||||
"source/ntp_time_util.cc",
|
||||
"source/ntp_time_util.h",
|
||||
]
|
||||
deps = [
|
||||
"../../api/units:time_delta",
|
||||
"../../rtc_base:checks",
|
||||
"../../rtc_base:divide_round",
|
||||
"../../rtc_base:safe_conversions",
|
||||
"../../rtc_base:timeutils",
|
||||
"../../system_wrappers",
|
||||
]
|
||||
}
|
||||
|
||||
rtc_library("rtcp_transceiver") {
|
||||
visibility = [ "*" ]
|
||||
public = [
|
||||
@ -401,6 +418,7 @@ rtc_library("rtcp_transceiver") {
|
||||
"source/rtcp_transceiver_impl.cc",
|
||||
]
|
||||
deps = [
|
||||
":ntp_time_util",
|
||||
":rtp_rtcp",
|
||||
":rtp_rtcp_format",
|
||||
"../../api:array_view",
|
||||
@ -552,6 +570,7 @@ if (rtc_include_tests) {
|
||||
"source/flexfec_sender_unittest.cc",
|
||||
"source/leb128_unittest.cc",
|
||||
"source/nack_rtx_unittest.cc",
|
||||
"source/ntp_time_util_unittest.cc",
|
||||
"source/packet_loss_stats_unittest.cc",
|
||||
"source/packet_sequencer_unittest.cc",
|
||||
"source/receive_statistics_unittest.cc",
|
||||
@ -613,7 +632,6 @@ if (rtc_include_tests) {
|
||||
"source/rtp_video_layers_allocation_extension_unittest.cc",
|
||||
"source/rtp_video_stream_receiver_frame_transformer_delegate_unittest.cc",
|
||||
"source/source_tracker_unittest.cc",
|
||||
"source/time_util_unittest.cc",
|
||||
"source/ulpfec_generator_unittest.cc",
|
||||
"source/ulpfec_header_reader_writer_unittest.cc",
|
||||
"source/ulpfec_receiver_unittest.cc",
|
||||
@ -636,6 +654,7 @@ if (rtc_include_tests) {
|
||||
":frame_transformer_factory_unittest",
|
||||
":leb128",
|
||||
":mock_rtp_rtcp",
|
||||
":ntp_time_util",
|
||||
":rtcp_transceiver",
|
||||
":rtp_packetizer_av1_test_helper",
|
||||
":rtp_rtcp",
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
56
modules/rtp_rtcp/source/ntp_time_util.h
Normal file
56
modules/rtp_rtcp/source/ntp_time_util.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_RTP_RTCP_SOURCE_NTP_TIME_UTIL_H_
|
||||
#define MODULES_RTP_RTCP_SOURCE_NTP_TIME_UTIL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
#include "system_wrappers/include/ntp_time.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Helper function for compact ntp representation:
|
||||
// RFC 3550, Section 4. Time Format.
|
||||
// Wallclock time is represented using the timestamp format of
|
||||
// the Network Time Protocol (NTP).
|
||||
// ...
|
||||
// In some fields where a more compact representation is
|
||||
// appropriate, only the middle 32 bits are used; that is, the low 16
|
||||
// bits of the integer part and the high 16 bits of the fractional part.
|
||||
inline uint32_t CompactNtp(NtpTime ntp) {
|
||||
return (ntp.seconds() << 16) | (ntp.fractions() >> 16);
|
||||
}
|
||||
|
||||
// Converts interval to compact ntp (1/2^16 seconds) resolution.
|
||||
// Negative values converted to 0, Overlarge values converted to max uint32_t.
|
||||
uint32_t SaturatedToCompactNtp(TimeDelta delta);
|
||||
|
||||
// Convert interval to the NTP time resolution (1/2^32 seconds ~= 0.2 ns).
|
||||
// For deltas with absolute value larger than 35 minutes result is unspecified.
|
||||
inline constexpr int64_t ToNtpUnits(TimeDelta delta) {
|
||||
// For better precision `delta` is taken with best TimeDelta precision (us),
|
||||
// then multiplaction and conversion to seconds are swapped to avoid float
|
||||
// arithmetic.
|
||||
// 2^31 us ~= 35.8 minutes.
|
||||
return (rtc::saturated_cast<int32_t>(delta.us()) * (int64_t{1} << 32)) /
|
||||
1'000'000;
|
||||
}
|
||||
|
||||
// Converts interval from compact ntp (1/2^16 seconds) resolution to TimeDelta.
|
||||
// This interval can be up to ~9.1 hours (2^15 seconds).
|
||||
// Values close to 2^16 seconds are considered negative and are converted to
|
||||
// minimum value of 1ms.
|
||||
TimeDelta CompactNtpRttToTimeDelta(uint32_t compact_ntp_interval);
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_RTP_RTCP_SOURCE_NTP_TIME_UTIL_H_
|
||||
@ -7,17 +7,16 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#include "api/units/time_delta.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
TEST(TimeUtilTest, CompactNtp) {
|
||||
TEST(NtpTimeUtilTest, CompactNtp) {
|
||||
const uint32_t kNtpSec = 0x12345678;
|
||||
const uint32_t kNtpFrac = 0x23456789;
|
||||
const NtpTime kNtp(kNtpSec, kNtpFrac);
|
||||
@ -25,7 +24,7 @@ TEST(TimeUtilTest, CompactNtp) {
|
||||
EXPECT_EQ(kNtpMid, CompactNtp(kNtp));
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, CompactNtpRttToTimeDelta) {
|
||||
TEST(NtpTimeUtilTest, CompactNtpRttToTimeDelta) {
|
||||
const NtpTime ntp1(0x12345, 0x23456);
|
||||
const NtpTime ntp2(0x12654, 0x64335);
|
||||
int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
|
||||
@ -34,7 +33,7 @@ TEST(TimeUtilTest, CompactNtpRttToTimeDelta) {
|
||||
EXPECT_NEAR(CompactNtpRttToTimeDelta(ntp_diff).ms(), ms_diff, 1);
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, CompactNtpRttToTimeDeltaWithWrap) {
|
||||
TEST(NtpTimeUtilTest, CompactNtpRttToTimeDeltaWithWrap) {
|
||||
const NtpTime ntp1(0x1ffff, 0x23456);
|
||||
const NtpTime ntp2(0x20000, 0x64335);
|
||||
int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
|
||||
@ -48,7 +47,7 @@ TEST(TimeUtilTest, CompactNtpRttToTimeDeltaWithWrap) {
|
||||
EXPECT_NEAR(CompactNtpRttToTimeDelta(ntp_diff).ms(), ms_diff, 1);
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, CompactNtpRttToTimeDeltaLarge) {
|
||||
TEST(NtpTimeUtilTest, CompactNtpRttToTimeDeltaLarge) {
|
||||
const NtpTime ntp1(0x10000, 0x00006);
|
||||
const NtpTime ntp2(0x17fff, 0xffff5);
|
||||
int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
|
||||
@ -58,7 +57,7 @@ TEST(TimeUtilTest, CompactNtpRttToTimeDeltaLarge) {
|
||||
EXPECT_NEAR(CompactNtpRttToTimeDelta(ntp_diff).ms(), ms_diff, 1);
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, CompactNtpRttToTimeDeltaNegative) {
|
||||
TEST(NtpTimeUtilTest, CompactNtpRttToTimeDeltaNegative) {
|
||||
const NtpTime ntp1(0x20000, 0x23456);
|
||||
const NtpTime ntp2(0x1ffff, 0x64335);
|
||||
int64_t ms_diff = ntp2.ToMs() - ntp1.ToMs();
|
||||
@ -68,7 +67,7 @@ TEST(TimeUtilTest, CompactNtpRttToTimeDeltaNegative) {
|
||||
EXPECT_EQ(CompactNtpRttToTimeDelta(ntp_diff), TimeDelta::Millis(1));
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, SaturatedToCompactNtp) {
|
||||
TEST(NtpTimeUtilTest, SaturatedToCompactNtp) {
|
||||
// Converts negative to zero.
|
||||
EXPECT_EQ(SaturatedToCompactNtp(TimeDelta::Micros(-1)), 0u);
|
||||
EXPECT_EQ(SaturatedToCompactNtp(TimeDelta::Zero()), 0u);
|
||||
@ -99,7 +98,7 @@ TEST(TimeUtilTest, SaturatedToCompactNtp) {
|
||||
5'515, 16);
|
||||
}
|
||||
|
||||
TEST(TimeUtilTest, ToNtpUnits) {
|
||||
TEST(NtpTimeUtilTest, ToNtpUnits) {
|
||||
EXPECT_EQ(ToNtpUnits(TimeDelta::Zero()), 0);
|
||||
EXPECT_EQ(ToNtpUnits(TimeDelta::Seconds(1)), int64_t{1} << 32);
|
||||
EXPECT_EQ(ToNtpUnits(TimeDelta::Seconds(-1)), -(int64_t{1} << 32));
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "system_wrappers/include/ntp_time.h"
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "system_wrappers/include/ntp_time.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "api/video/video_bitrate_allocator.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
|
||||
@ -45,7 +46,6 @@
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/tmmbr_help.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "modules/rtp_rtcp/include/report_block_data.h"
|
||||
#include "modules/rtp_rtcp/mocks/mock_network_link_rtcp_observer.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/app.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
@ -38,7 +39,6 @@
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/fake_clock.h"
|
||||
#include "rtc_base/random.h"
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
#include "api/units/time_delta.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/app.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
|
||||
@ -41,7 +42,6 @@
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/tmmbr_help.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include "api/video/video_bitrate_allocation.h"
|
||||
#include "modules/rtp_rtcp/include/receive_statistics.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
|
||||
@ -31,7 +32,6 @@
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/sdes.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/containers/flat_map.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
@ -26,10 +26,10 @@
|
||||
#include "modules/rtp_rtcp/include/report_block_data.h"
|
||||
#include "modules/rtp_rtcp/mocks/mock_network_link_rtcp_observer.h"
|
||||
#include "modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/app.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/gmock.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
@ -21,11 +21,11 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_sender.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "system_wrappers/include/ntp_time.h"
|
||||
|
||||
@ -24,10 +24,10 @@
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/units/time_delta.h"
|
||||
#include "api/units/timestamp.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_history.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
|
||||
@ -23,10 +23,10 @@
|
||||
#include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_cvo.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor_extension.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
|
||||
@ -24,10 +24,10 @@
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/absolute_capture_time_sender.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/absolute_capture_time_sender.h"
|
||||
#include "modules/rtp_rtcp/source/byte_io.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_dependency_descriptor_extension.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_descriptor_authentication.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_format.h"
|
||||
@ -37,7 +38,6 @@
|
||||
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_video_layers_allocation_extension.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
@ -7,50 +7,11 @@
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
|
||||
#define MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
// TODO: bugs.webrtc.org/343076000 - Remove this forwarding header when
|
||||
// downstream projects are updated to use ntp_time_util directly.
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
|
||||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/numerics/safe_conversions.h"
|
||||
#include "system_wrappers/include/ntp_time.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// Helper function for compact ntp representation:
|
||||
// RFC 3550, Section 4. Time Format.
|
||||
// Wallclock time is represented using the timestamp format of
|
||||
// the Network Time Protocol (NTP).
|
||||
// ...
|
||||
// In some fields where a more compact representation is
|
||||
// appropriate, only the middle 32 bits are used; that is, the low 16
|
||||
// bits of the integer part and the high 16 bits of the fractional part.
|
||||
inline uint32_t CompactNtp(NtpTime ntp) {
|
||||
return (ntp.seconds() << 16) | (ntp.fractions() >> 16);
|
||||
}
|
||||
|
||||
// Converts interval to compact ntp (1/2^16 seconds) resolution.
|
||||
// Negative values converted to 0, Overlarge values converted to max uint32_t.
|
||||
uint32_t SaturatedToCompactNtp(TimeDelta delta);
|
||||
|
||||
// Convert interval to the NTP time resolution (1/2^32 seconds ~= 0.2 ns).
|
||||
// For deltas with absolute value larger than 35 minutes result is unspecified.
|
||||
inline constexpr int64_t ToNtpUnits(TimeDelta delta) {
|
||||
// For better precision `delta` is taken with best TimeDelta precision (us),
|
||||
// then multiplaction and conversion to seconds are swapped to avoid float
|
||||
// arithmetic.
|
||||
// 2^31 us ~= 35.8 minutes.
|
||||
return (rtc::saturated_cast<int32_t>(delta.us()) * (int64_t{1} << 32)) /
|
||||
1'000'000;
|
||||
}
|
||||
|
||||
// Converts interval from compact ntp (1/2^16 seconds) resolution to TimeDelta.
|
||||
// This interval can be up to ~9.1 hours (2^15 seconds).
|
||||
// Values close to 2^16 seconds are considered negative and are converted to
|
||||
// minimum value of 1ms.
|
||||
TimeDelta CompactNtpRttToTimeDelta(uint32_t compact_ntp_interval);
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_RTP_RTCP_SOURCE_TIME_UTIL_H_
|
||||
|
||||
@ -393,6 +393,7 @@ if (!build_with_chromium) {
|
||||
"../modules/pacing",
|
||||
"../modules/remote_bitrate_estimator",
|
||||
"../modules/rtp_rtcp",
|
||||
"../modules/rtp_rtcp:ntp_time_util",
|
||||
"../modules/rtp_rtcp:rtp_rtcp_format",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:logging",
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#include "logging/rtc_event_log/rtc_event_log_parser.h"
|
||||
#include "logging/rtc_event_log/rtc_event_processor.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/rtp_rtcp/source/time_util.h"
|
||||
#include "modules/rtp_rtcp/source/ntp_time_util.h"
|
||||
#include "rtc_base/network/sent_packet.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user