aboutsummaryrefslogtreecommitdiff
path: root/cast/streaming
diff options
context:
space:
mode:
authorJordan Bayles <jophba@chromium.org>2020-06-02 15:51:31 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-03 14:49:40 +0000
commitc9201dd611b0aa8d66fe7ef2749c7ce0c157f0a1 (patch)
tree35865dd50de7765c9c82abb42c74a7d70a4b8178 /cast/streaming
parent724a60fb10c7042a3e00eb4f1cf25b41b88b0c8b (diff)
downloadopenscreen-c9201dd611b0aa8d66fe7ef2749c7ce0c157f0a1.tar.gz
Move std::chrono using statements to util/
This patch moves openscreen::<time type> using statements to be part of a new util/ header, chrono_helpers.h. Some helpful convenience functions are provided for doing conversions, and a new conversion method, to_duration, is added to the Clock implementation. Change-Id: I5a153c4da5266bceea97de0cad00a71a739f71ca Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2222684 Reviewed-by: mark a. foltz <mfoltz@chromium.org> Reviewed-by: Ryan Keane <rwkeane@google.com> Commit-Queue: Jordan Bayles <jophba@chromium.org>
Diffstat (limited to 'cast/streaming')
-rw-r--r--cast/streaming/answer_messages.h2
-rw-r--r--cast/streaming/answer_messages_unittest.cc24
-rw-r--r--cast/streaming/bandwidth_estimator.cc3
-rw-r--r--cast/streaming/bandwidth_estimator_unittest.cc2
-rw-r--r--cast/streaming/compound_rtcp_builder_unittest.cc13
-rw-r--r--cast/streaming/compound_rtcp_parser_unittest.cc7
-rw-r--r--cast/streaming/ntp_time.cc15
-rw-r--r--cast/streaming/ntp_time_unittest.cc28
-rw-r--r--cast/streaming/offer_messages.h2
-rw-r--r--cast/streaming/packet_receive_stats_tracker_unittest.cc26
-rw-r--r--cast/streaming/receiver.cc20
-rw-r--r--cast/streaming/receiver.h3
-rw-r--r--cast/streaming/receiver_session.cc2
-rw-r--r--cast/streaming/receiver_session.h1
-rw-r--r--cast/streaming/receiver_session_unittest.cc2
-rw-r--r--cast/streaming/receiver_unittest.cc10
-rw-r--r--cast/streaming/rtcp_common.cc3
-rw-r--r--cast/streaming/rtcp_common_unittest.cc24
-rw-r--r--cast/streaming/rtp_packetizer_unittest.cc26
-rw-r--r--cast/streaming/rtp_time_unittest.cc3
-rw-r--r--cast/streaming/sender.cc13
-rw-r--r--cast/streaming/sender.h2
-rw-r--r--cast/streaming/sender_packet_router.cc4
-rw-r--r--cast/streaming/sender_packet_router.h2
-rw-r--r--cast/streaming/sender_packet_router_unittest.cc3
-rw-r--r--cast/streaming/sender_unittest.cc11
-rw-r--r--cast/streaming/session_config.h2
27 files changed, 134 insertions, 119 deletions
diff --git a/cast/streaming/answer_messages.h b/cast/streaming/answer_messages.h
index 60b9a494..efd72d6a 100644
--- a/cast/streaming/answer_messages.h
+++ b/cast/streaming/answer_messages.h
@@ -6,7 +6,7 @@
#define CAST_STREAMING_ANSWER_MESSAGES_H_
#include <array>
-#include <chrono> // NOLINT
+#include <chrono>
#include <cstdint>
#include <initializer_list>
#include <memory>
diff --git a/cast/streaming/answer_messages_unittest.cc b/cast/streaming/answer_messages_unittest.cc
index d1c70828..35ad846a 100644
--- a/cast/streaming/answer_messages_unittest.cc
+++ b/cast/streaming/answer_messages_unittest.cc
@@ -4,10 +4,12 @@
#include "cast/streaming/answer_messages.h"
+#include <chrono>
#include <utility>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
+#include "util/chrono_helpers.h"
#include "util/json/json_serialization.h"
namespace openscreen {
@@ -22,12 +24,12 @@ const Answer kValidAnswer{
std::vector<Ssrc>{123, 456}, // ssrcs
Constraints{
AudioConstraints{
- 96000, // max_sample_rate
- 7, // max_channels
- 32000, // min_bit_rate
- 96000, // max_bit_rate
- std::chrono::milliseconds(2000) // max_delay
- }, // audio
+ 96000, // max_sample_rate
+ 7, // max_channels
+ 32000, // min_bit_rate
+ 96000, // max_bit_rate
+ milliseconds(2000) // max_delay
+ }, // audio
VideoConstraints{
40000.0, // max_pixels_per_second
Dimensions{
@@ -40,11 +42,11 @@ const Answer kValidAnswer{
1080, // height
SimpleFraction{288, 2} // frame_rate
},
- 300000, // min_bit_rate
- 144000000, // max_bit_rate
- std::chrono::milliseconds(3000) // max_delay
- } // video
- }, // constraints
+ 300000, // min_bit_rate
+ 144000000, // max_bit_rate
+ milliseconds(3000) // max_delay
+ } // video
+ }, // constraints
DisplayDescription{
Dimensions{
640, // width
diff --git a/cast/streaming/bandwidth_estimator.cc b/cast/streaming/bandwidth_estimator.cc
index 5c42aa4a..e6bc594f 100644
--- a/cast/streaming/bandwidth_estimator.cc
+++ b/cast/streaming/bandwidth_estimator.cc
@@ -24,8 +24,7 @@ int ToClampedBitsPerSecond(int32_t bytes, Clock::duration time_window) {
// Divide |bytes| by |time_window| and scale the units to bits per second.
constexpr int64_t kBitsPerByte = 8;
constexpr int64_t kClockTicksPerSecond =
- std::chrono::duration_cast<Clock::duration>(std::chrono::seconds(1))
- .count();
+ Clock::to_duration(std::chrono::seconds(1)).count();
const int64_t bits = bytes * kBitsPerByte;
const int64_t bits_per_second =
(bits * kClockTicksPerSecond) / time_window.count();
diff --git a/cast/streaming/bandwidth_estimator_unittest.cc b/cast/streaming/bandwidth_estimator_unittest.cc
index d5891da3..6a2e1fc9 100644
--- a/cast/streaming/bandwidth_estimator_unittest.cc
+++ b/cast/streaming/bandwidth_estimator_unittest.cc
@@ -4,12 +4,14 @@
#include "cast/streaming/bandwidth_estimator.h"
+#include <chrono>
#include <limits>
#include <random>
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/api/time.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
diff --git a/cast/streaming/compound_rtcp_builder_unittest.cc b/cast/streaming/compound_rtcp_builder_unittest.cc
index 969056cf..4cc7de00 100644
--- a/cast/streaming/compound_rtcp_builder_unittest.cc
+++ b/cast/streaming/compound_rtcp_builder_unittest.cc
@@ -14,6 +14,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/api/time.h"
+#include "util/chrono_helpers.h"
using testing::_;
using testing::Invoke;
@@ -57,7 +58,7 @@ class CompoundRtcpBuilderTest : public testing::Test {
TEST_F(CompoundRtcpBuilderTest, TheBasics) {
const FrameId checkpoint = FrameId::first() + 42;
builder()->SetCheckpointFrame(checkpoint);
- const std::chrono::milliseconds playout_delay{321};
+ const milliseconds playout_delay{321};
builder()->SetPlayoutDelay(playout_delay);
const auto send_time = Clock::now();
@@ -115,7 +116,7 @@ TEST_F(CompoundRtcpBuilderTest, WithReceiverReportBlock) {
// Build again, but this time the builder should not include the receiver
// report block.
- const auto second_send_time = send_time + std::chrono::milliseconds(500);
+ const auto second_send_time = send_time + milliseconds(500);
const auto second_packet = builder()->BuildPacket(second_send_time, buffer);
ASSERT_TRUE(second_packet.data());
EXPECT_CALL(*(client()), OnReceiverReferenceTimeAdvanced(
@@ -160,7 +161,7 @@ TEST_F(CompoundRtcpBuilderTest, WithPictureLossIndicator) {
Mock::VerifyAndClearExpectations(client());
++checkpoint;
- send_time += std::chrono::milliseconds(500);
+ send_time += milliseconds(500);
}
}
}
@@ -200,7 +201,7 @@ TEST_F(CompoundRtcpBuilderTest, WithNacks) {
Mock::VerifyAndClearExpectations(client());
// Build again, but this time the builder should not include the feedback.
- const auto second_send_time = send_time + std::chrono::milliseconds(500);
+ const auto second_send_time = send_time + milliseconds(500);
const auto second_packet = builder()->BuildPacket(second_send_time, buffer);
ASSERT_TRUE(second_packet.data());
EXPECT_CALL(*(client()), OnReceiverReferenceTimeAdvanced(
@@ -248,7 +249,7 @@ TEST_F(CompoundRtcpBuilderTest, WithAcks) {
// Build again, but this time the builder should not include the feedback
// because it was already provided in the prior packet.
- send_time += std::chrono::milliseconds(500);
+ send_time += milliseconds(500);
const auto second_packet = builder()->BuildPacket(send_time, buffer);
ASSERT_TRUE(second_packet.data());
EXPECT_CALL(*(client()), OnReceiverReferenceTimeAdvanced(
@@ -258,7 +259,7 @@ TEST_F(CompoundRtcpBuilderTest, WithAcks) {
ASSERT_TRUE(parser()->Parse(second_packet, kMaxFeedbackFrameId));
Mock::VerifyAndClearExpectations(client());
- send_time += std::chrono::milliseconds(500);
+ send_time += milliseconds(500);
}
}
diff --git a/cast/streaming/compound_rtcp_parser_unittest.cc b/cast/streaming/compound_rtcp_parser_unittest.cc
index 9f8e3c50..7b2499a2 100644
--- a/cast/streaming/compound_rtcp_parser_unittest.cc
+++ b/cast/streaming/compound_rtcp_parser_unittest.cc
@@ -12,6 +12,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "platform/api/time.h"
+#include "util/chrono_helpers.h"
using testing::_;
using testing::Mock;
@@ -264,7 +265,7 @@ TEST_F(CompoundRtcpParserTest, ParsesSimpleFeedback) {
// First scenario: Valid range of FrameIds is [0,42].
const auto kMaxFeedbackFrameId0 = FrameId::first() + 42;
const auto expected_frame_id0 = FrameId::first() + 10;
- const auto expected_playout_delay = std::chrono::milliseconds(550);
+ const auto expected_playout_delay = milliseconds(550);
EXPECT_CALL(*(client()),
OnReceiverCheckpoint(expected_frame_id0, expected_playout_delay));
EXPECT_TRUE(parser()->Parse(kFeedbackPacket, kMaxFeedbackFrameId0));
@@ -321,7 +322,7 @@ TEST_F(CompoundRtcpParserTest, ParsesFeedbackWithNacks) {
const auto kMaxFeedbackFrameId = FrameId::first() + 42;
const auto expected_frame_id = FrameId::first() + 10;
- const auto expected_playout_delay = std::chrono::milliseconds(552);
+ const auto expected_playout_delay = milliseconds(552);
EXPECT_CALL(*(client()),
OnReceiverCheckpoint(expected_frame_id, expected_playout_delay));
EXPECT_CALL(*(client()), OnReceiverIsMissingPackets(kMissingPackets));
@@ -386,7 +387,7 @@ TEST_F(CompoundRtcpParserTest, ParsesFeedbackWithAcks) {
// Test the smaller packet.
const auto kMaxFeedbackFrameId = FrameId::first() + 100;
const auto expected_frame_id = FrameId::first() + 10;
- const auto expected_playout_delay = std::chrono::milliseconds(294);
+ const auto expected_playout_delay = milliseconds(294);
EXPECT_CALL(*(client()),
OnReceiverCheckpoint(expected_frame_id, expected_playout_delay));
EXPECT_CALL(*(client()), OnReceiverHasFrames(kFrame13Only));
diff --git a/cast/streaming/ntp_time.cc b/cast/streaming/ntp_time.cc
index d983de50..9fd04e03 100644
--- a/cast/streaming/ntp_time.cc
+++ b/cast/streaming/ntp_time.cc
@@ -19,17 +19,19 @@ constexpr NtpSeconds kTimeBetweenNtpEpochAndUnixEpoch{INT64_C(2208988800)};
NtpTimeConverter::NtpTimeConverter(Clock::time_point now,
std::chrono::seconds since_unix_epoch)
: start_time_(now),
- since_ntp_epoch_(duration_cast<NtpSeconds>(since_unix_epoch) +
- kTimeBetweenNtpEpochAndUnixEpoch) {}
+ since_ntp_epoch_(
+ std::chrono::duration_cast<NtpSeconds>(since_unix_epoch) +
+ kTimeBetweenNtpEpochAndUnixEpoch) {}
NtpTimeConverter::~NtpTimeConverter() = default;
NtpTimestamp NtpTimeConverter::ToNtpTimestamp(
Clock::time_point time_point) const {
const Clock::duration time_since_start = time_point - start_time_;
- const auto whole_seconds = duration_cast<NtpSeconds>(time_since_start);
+ const auto whole_seconds =
+ std::chrono::duration_cast<NtpSeconds>(time_since_start);
const auto remainder =
- duration_cast<NtpFraction>(time_since_start - whole_seconds);
+ std::chrono::duration_cast<NtpFraction>(time_since_start - whole_seconds);
return AssembleNtpTimestamp(since_ntp_epoch_ + whole_seconds, remainder);
}
@@ -45,9 +47,8 @@ Clock::time_point NtpTimeConverter::ToLocalTime(NtpTimestamp timestamp) const {
const auto whole_seconds = ntp_seconds - since_ntp_epoch_;
const auto seconds_since_start =
- duration_cast<Clock::duration>(whole_seconds) + start_time_;
- const auto remainder =
- duration_cast<Clock::duration>(NtpFractionPart(timestamp));
+ Clock::to_duration(whole_seconds) + start_time_;
+ const auto remainder = Clock::to_duration(NtpFractionPart(timestamp));
return seconds_since_start + remainder;
}
diff --git a/cast/streaming/ntp_time_unittest.cc b/cast/streaming/ntp_time_unittest.cc
index 5a865908..325e7587 100644
--- a/cast/streaming/ntp_time_unittest.cc
+++ b/cast/streaming/ntp_time_unittest.cc
@@ -4,7 +4,10 @@
#include "cast/streaming/ntp_time.h"
+#include <chrono>
+
#include "gtest/gtest.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
@@ -18,8 +21,7 @@ TEST(NtpTimestampTest, SplitsIntoParts) {
// 1 Jan 1900 plus 10 ms.
timestamp = UINT64_C(0x00000000028f5c29);
EXPECT_EQ(NtpSeconds::zero(), NtpSecondsPart(timestamp));
- EXPECT_EQ(milliseconds(10),
- duration_cast<milliseconds>(NtpFractionPart(timestamp)));
+ EXPECT_EQ(milliseconds(10), to_microseconds(NtpFractionPart(timestamp)));
// 1 Jan 1970 minus 2^-32 seconds.
timestamp = UINT64_C(0x83aa7e80ffffffff);
@@ -29,8 +31,7 @@ TEST(NtpTimestampTest, SplitsIntoParts) {
// 2019-03-23 17:25:50.500.
timestamp = UINT64_C(0xe0414d0e80000000);
EXPECT_EQ(NtpSeconds(INT64_C(3762375950)), NtpSecondsPart(timestamp));
- EXPECT_EQ(milliseconds(500),
- duration_cast<milliseconds>(NtpFractionPart(timestamp)));
+ EXPECT_EQ(milliseconds(500), to_microseconds(NtpFractionPart(timestamp)));
}
TEST(NtpTimestampTest, AssemblesFromParts) {
@@ -39,13 +40,14 @@ TEST(NtpTimestampTest, AssemblesFromParts) {
AssembleNtpTimestamp(NtpSeconds::zero(), NtpFraction::zero());
EXPECT_EQ(UINT64_C(0x0000000000000000), timestamp);
- // 1 Jan 1900 plus 10 ms. Note that the duration_cast<NtpFraction>(10ms)
- // truncates rather than rounds the 10ms value, so the resulting timestamp is
- // one fractional tick less than the one found in the SplitsIntoParts test.
- // The ~0.4 nanosecond error in the conversion is totally insignificant to a
- // live system.
+ // 1 Jan 1900 plus 10 ms. Note that the
+ // std::chrono::duration_cast<NtpFraction>(10ms) truncates rather than rounds
+ // the 10ms value, so the resulting timestamp is one fractional tick less than
+ // the one found in the SplitsIntoParts test. The ~0.4 nanosecond error in the
+ // conversion is totally insignificant to a live system.
timestamp = AssembleNtpTimestamp(
- NtpSeconds::zero(), duration_cast<NtpFraction>(milliseconds(10)));
+ NtpSeconds::zero(),
+ std::chrono::duration_cast<NtpFraction>(milliseconds(10)));
EXPECT_EQ(UINT64_C(0x00000000028f5c28), timestamp);
// 1 Jan 1970 minus 2^-32 seconds.
@@ -54,9 +56,9 @@ TEST(NtpTimestampTest, AssemblesFromParts) {
EXPECT_EQ(UINT64_C(0x83aa7e7fffffffff), timestamp);
// 2019-03-23 17:25:50.500.
- timestamp =
- AssembleNtpTimestamp(NtpSeconds(INT64_C(3762375950)),
- duration_cast<NtpFraction>(milliseconds(500)));
+ timestamp = AssembleNtpTimestamp(
+ NtpSeconds(INT64_C(3762375950)),
+ std::chrono::duration_cast<NtpFraction>(milliseconds(500)));
EXPECT_EQ(UINT64_C(0xe0414d0e80000000), timestamp);
}
diff --git a/cast/streaming/offer_messages.h b/cast/streaming/offer_messages.h
index 319145bc..f5642495 100644
--- a/cast/streaming/offer_messages.h
+++ b/cast/streaming/offer_messages.h
@@ -5,7 +5,7 @@
#ifndef CAST_STREAMING_OFFER_MESSAGES_H_
#define CAST_STREAMING_OFFER_MESSAGES_H_
-#include <chrono> // NOLINT
+#include <chrono>
#include <string>
#include <vector>
diff --git a/cast/streaming/packet_receive_stats_tracker_unittest.cc b/cast/streaming/packet_receive_stats_tracker_unittest.cc
index 5146cc8d..eb1b45c7 100644
--- a/cast/streaming/packet_receive_stats_tracker_unittest.cc
+++ b/cast/streaming/packet_receive_stats_tracker_unittest.cc
@@ -4,10 +4,12 @@
#include "cast/streaming/packet_receive_stats_tracker.h"
+#include <chrono>
#include <limits>
#include "cast/streaming/constants.h"
#include "gtest/gtest.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
@@ -74,8 +76,7 @@ TEST(PacketReceiveStatsTrackerTest, PopulatesReportWithOnePacketTracked) {
constexpr uint16_t kSequenceNumber = 1234;
constexpr RtpTimeTicks kRtpTimestamp =
RtpTimeTicks() + RtpTimeDelta::FromTicks(42);
- constexpr auto kArrivalTime =
- Clock::time_point() + std::chrono::seconds(3600);
+ constexpr auto kArrivalTime = Clock::time_point() + seconds(3600);
PacketReceiveStatsTracker tracker(kSomeRtpTimebase);
tracker.OnReceivedValidRtpPacket(kSequenceNumber, kRtpTimestamp,
@@ -96,8 +97,7 @@ TEST(PacketReceiveStatsTrackerTest, WhenReceivingAllPackets) {
std::numeric_limits<uint16_t>::max() - 2;
constexpr RtpTimeTicks kFirstRtpTimestamp =
RtpTimeTicks() + RtpTimeDelta::FromTicks(42);
- constexpr auto kFirstArrivalTime =
- Clock::time_point() + std::chrono::seconds(3600);
+ constexpr auto kFirstArrivalTime = Clock::time_point() + seconds(3600);
PacketReceiveStatsTracker tracker(kSomeRtpTimebase);
@@ -107,7 +107,7 @@ TEST(PacketReceiveStatsTrackerTest, WhenReceivingAllPackets) {
tracker.OnReceivedValidRtpPacket(
kFirstSequenceNumber + i,
kFirstRtpTimestamp + RtpTimeDelta::FromTicks(kSomeRtpTimebase) * i,
- kFirstArrivalTime + std::chrono::seconds(i));
+ kFirstArrivalTime + seconds(i));
}
RtcpReportBlock report = GetSentinel();
@@ -131,8 +131,7 @@ TEST(PacketReceiveStatsTrackerTest, WhenReceivingAboutHalfThePackets) {
constexpr uint16_t kFirstSequenceNumber = 3;
constexpr RtpTimeTicks kFirstRtpTimestamp =
RtpTimeTicks() + RtpTimeDelta::FromTicks(99);
- constexpr auto kFirstArrivalTime =
- Clock::time_point() + std::chrono::seconds(8888);
+ constexpr auto kFirstArrivalTime = Clock::time_point() + seconds(8888);
PacketReceiveStatsTracker tracker(kSomeRtpTimebase);
@@ -145,7 +144,7 @@ TEST(PacketReceiveStatsTrackerTest, WhenReceivingAboutHalfThePackets) {
tracker.OnReceivedValidRtpPacket(
kFirstSequenceNumber + (i * 2 + 1),
kFirstRtpTimestamp + RtpTimeDelta::FromTicks(kSomeRtpTimebase) * i,
- kFirstArrivalTime + std::chrono::seconds(i));
+ kFirstArrivalTime + seconds(i));
}
RtcpReportBlock report = GetSentinel();
@@ -163,14 +162,12 @@ TEST(PacketReceiveStatsTrackerTest, ComputesJitterCorrectly) {
constexpr uint16_t kFirstSequenceNumber = 3;
constexpr RtpTimeTicks kFirstRtpTimestamp =
RtpTimeTicks() + RtpTimeDelta::FromTicks(99);
- constexpr auto kFirstArrivalTime =
- Clock::time_point() + std::chrono::seconds(8888);
+ constexpr auto kFirstArrivalTime = Clock::time_point() + seconds(8888);
// Record 100 packet arrivals, one second apart, where each packet's RTP
// timestamps are progressing 2 seconds forward. Thus, the jitter calculation
// should gradually converge towards a difference of one second.
- constexpr auto kTrueJitter =
- std::chrono::duration_cast<Clock::duration>(std::chrono::seconds(1));
+ constexpr auto kTrueJitter = Clock::to_duration(seconds(1));
PacketReceiveStatsTracker tracker(kSomeRtpTimebase);
Clock::duration last_diff = Clock::duration::max();
for (int i = 0; i < 100; ++i) {
@@ -178,7 +175,7 @@ TEST(PacketReceiveStatsTrackerTest, ComputesJitterCorrectly) {
kFirstSequenceNumber + i,
kFirstRtpTimestamp +
RtpTimeDelta::FromTicks(kSomeRtpTimebase) * (i * 2),
- kFirstArrivalTime + std::chrono::seconds(i));
+ kFirstArrivalTime + seconds(i));
// Expect that the jitter is becoming closer to the actual value in each
// iteration.
@@ -198,8 +195,7 @@ TEST(PacketReceiveStatsTrackerTest, ComputesJitterCorrectly) {
tracker.PopulateNextReport(&report);
const auto diff =
kTrueJitter - report.jitter.ToDuration<Clock::duration>(kSomeRtpTimebase);
- constexpr auto kMaxDiffAtEnd =
- std::chrono::duration_cast<Clock::duration>(std::chrono::milliseconds(2));
+ constexpr auto kMaxDiffAtEnd = Clock::to_duration(milliseconds(2));
EXPECT_NEAR(0, diff.count(), kMaxDiffAtEnd.count());
}
diff --git a/cast/streaming/receiver.cc b/cast/streaming/receiver.cc
index 5c8babd1..d4c86da4 100644
--- a/cast/streaming/receiver.cc
+++ b/cast/streaming/receiver.cc
@@ -5,11 +5,13 @@
#include "cast/streaming/receiver.h"
#include <algorithm>
+#include <utility>
#include "absl/types/span.h"
#include "cast/streaming/constants.h"
#include "cast/streaming/receiver_packet_router.h"
#include "cast/streaming/session_config.h"
+#include "util/chrono_helpers.h"
#include "util/osp_logging.h"
#include "util/std_util.h"
@@ -144,14 +146,14 @@ EncodedFrame Receiver::ConsumeNextFrame(absl::Span<uint8_t> buffer) {
frame.reference_time =
*entry.estimated_capture_time + ResolveTargetPlayoutDelay(frame_id);
- RECEIVER_VLOG
- << "ConsumeNextFrame → " << frame.frame_id << ": " << frame.data.size()
- << " payload bytes, RTP Timestamp "
- << frame.rtp_timestamp.ToTimeSinceOrigin<microseconds>(rtp_timebase_)
- .count()
- << " µs, to play-out "
- << duration_cast<microseconds>(frame.reference_time - now_()).count()
- << " µs from now.";
+ RECEIVER_VLOG << "ConsumeNextFrame → " << frame.frame_id << ": "
+ << frame.data.size() << " payload bytes, RTP Timestamp "
+ << frame.rtp_timestamp
+ .ToTimeSinceOrigin<microseconds>(rtp_timebase_)
+ .count()
+ << " µs, to play-out "
+ << to_microseconds(frame.reference_time - now_()).count()
+ << " µs from now.";
entry.Reset();
last_frame_consumed_ = frame_id;
@@ -306,7 +308,7 @@ void Receiver::OnReceivedRtcpPacket(Clock::time_point arrival_time,
smoothed_clock_offset_.Update(arrival_time, measured_offset);
RECEIVER_VLOG
<< "Received Sender Report: Local clock is ahead of Sender's by "
- << duration_cast<microseconds>(smoothed_clock_offset_.Current()).count()
+ << to_microseconds(smoothed_clock_offset_.Current()).count()
<< " µs (minus one-way network transit time).";
RtcpReportBlock report;
diff --git a/cast/streaming/receiver.h b/cast/streaming/receiver.h
index e63a9e4e..b4c53868 100644
--- a/cast/streaming/receiver.h
+++ b/cast/streaming/receiver.h
@@ -8,8 +8,9 @@
#include <stdint.h>
#include <array>
-#include <chrono> // NOLINT
+#include <chrono>
#include <memory>
+#include <utility>
#include <vector>
#include "absl/types/optional.h"
diff --git a/cast/streaming/receiver_session.cc b/cast/streaming/receiver_session.cc
index 83ac0cf6..5d2e74bd 100644
--- a/cast/streaming/receiver_session.cc
+++ b/cast/streaming/receiver_session.cc
@@ -4,7 +4,7 @@
#include "cast/streaming/receiver_session.h"
-#include <chrono> // NOLINT
+#include <chrono>
#include <string>
#include <utility>
diff --git a/cast/streaming/receiver_session.h b/cast/streaming/receiver_session.h
index d41af31c..44cf864b 100644
--- a/cast/streaming/receiver_session.h
+++ b/cast/streaming/receiver_session.h
@@ -7,6 +7,7 @@
#include <memory>
#include <string>
+#include <utility>
#include <vector>
#include "cast/streaming/answer_messages.h"
diff --git a/cast/streaming/receiver_session_unittest.cc b/cast/streaming/receiver_session_unittest.cc
index ce9a0079..afedde2f 100644
--- a/cast/streaming/receiver_session_unittest.cc
+++ b/cast/streaming/receiver_session_unittest.cc
@@ -365,7 +365,7 @@ TEST_F(ReceiverSessionTest, CanNegotiateWithCustomConstraints) {
AudioConstraints{1, 2, 3, 4},
VideoConstraints{3.14159, Dimensions{320, 240, SimpleFraction{24, 1}},
Dimensions{1920, 1080, SimpleFraction{144, 1}}, 3000,
- 90000000, std::chrono::milliseconds{1000}}}};
+ 90000000, std::chrono::milliseconds(1000)}}};
auto display = std::unique_ptr<DisplayDescription>{new DisplayDescription{
Dimensions{640, 480, SimpleFraction{60, 1}}, AspectRatio{16, 9},
diff --git a/cast/streaming/receiver_unittest.cc b/cast/streaming/receiver_unittest.cc
index 19791bdb..d3c77178 100644
--- a/cast/streaming/receiver_unittest.cc
+++ b/cast/streaming/receiver_unittest.cc
@@ -35,6 +35,7 @@
#include "platform/base/udp_packet.h"
#include "platform/test/fake_clock.h"
#include "platform/test/fake_task_runner.h"
+#include "util/chrono_helpers.h"
#include "util/osp_logging.h"
using testing::_;
@@ -399,11 +400,10 @@ TEST_F(ReceiverTest, ReceivesAndSendsRtcpPackets) {
// from the wire-format NtpTimestamps. See the unit tests in
// ntp_time_unittest.cc for further discussion.
constexpr auto kAllowedNtpRoundingError = microseconds(2);
- EXPECT_NEAR(duration_cast<microseconds>(kOneWayNetworkDelay).count(),
- duration_cast<microseconds>(receiver_reference_time -
- sender_reference_time)
- .count(),
- kAllowedNtpRoundingError.count());
+ EXPECT_NEAR(
+ to_microseconds(kOneWayNetworkDelay).count(),
+ to_microseconds(receiver_reference_time - sender_reference_time).count(),
+ kAllowedNtpRoundingError.count());
// Without the Sender doing anything, the Receiver should continue providing
// RTCP reports at regular intervals. Simulate three intervals of time,
diff --git a/cast/streaming/rtcp_common.cc b/cast/streaming/rtcp_common.cc
index 696849bb..ce1e42d9 100644
--- a/cast/streaming/rtcp_common.cc
+++ b/cast/streaming/rtcp_common.cc
@@ -4,6 +4,7 @@
#include "cast/streaming/rtcp_common.h"
+#include <algorithm>
#include <limits>
#include "cast/streaming/packet_util.h"
@@ -187,7 +188,7 @@ void RtcpReportBlock::SetDelaySinceLastReport(
// math (well, only for unusually large inputs).
constexpr Delay kMaxValidReportedDelay{std::numeric_limits<uint32_t>::max()};
constexpr auto kMaxValidLocalClockDelay =
- std::chrono::duration_cast<Clock::duration>(kMaxValidReportedDelay);
+ Clock::to_duration(kMaxValidReportedDelay);
if (local_clock_delay > kMaxValidLocalClockDelay) {
delay_since_last_report = kMaxValidReportedDelay;
return;
diff --git a/cast/streaming/rtcp_common_unittest.cc b/cast/streaming/rtcp_common_unittest.cc
index d593e4f0..14aaa7ee 100644
--- a/cast/streaming/rtcp_common_unittest.cc
+++ b/cast/streaming/rtcp_common_unittest.cc
@@ -10,6 +10,7 @@
#include "absl/types/span.h"
#include "gtest/gtest.h"
#include "platform/api/time.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
@@ -280,28 +281,23 @@ TEST(RtcpCommonTest, ComputesDelayForReportBlocks) {
// A duration less than or equal to zero should clamp to zero.
EXPECT_EQ(Delay::zero(), ComputeDelay(Clock::duration::min()));
- EXPECT_EQ(Delay::zero(), ComputeDelay(std::chrono::milliseconds(-1234)));
+ EXPECT_EQ(Delay::zero(), ComputeDelay(milliseconds{-1234}));
EXPECT_EQ(Delay::zero(), ComputeDelay(Clock::duration::zero()));
// Test conversion of various durations that should not clamp.
EXPECT_EQ(Delay(32768 /* 1/2 second worth of ticks */),
- ComputeDelay(std::chrono::milliseconds(500)));
+ ComputeDelay(milliseconds(500)));
EXPECT_EQ(Delay(65536 /* 1 second worth of ticks */),
- ComputeDelay(std::chrono::seconds(1)));
+ ComputeDelay(seconds(1)));
EXPECT_EQ(Delay(655360 /* 10 seconds worth of ticks */),
- ComputeDelay(std::chrono::seconds(10)));
- EXPECT_EQ(Delay(4294967294),
- ComputeDelay(std::chrono::microseconds(65535999983)));
- EXPECT_EQ(Delay(4294967294),
- ComputeDelay(std::chrono::microseconds(65535999984)));
+ ComputeDelay(seconds(10)));
+ EXPECT_EQ(Delay(4294967294), ComputeDelay(microseconds(65535999983)));
+ EXPECT_EQ(Delay(4294967294), ComputeDelay(microseconds(65535999984)));
// A too-large duration should clamp to the maximum-possible Delay value.
- EXPECT_EQ(Delay(4294967295),
- ComputeDelay(std::chrono::microseconds(65535999985)));
- EXPECT_EQ(Delay(4294967295),
- ComputeDelay(std::chrono::microseconds(65535999986)));
- EXPECT_EQ(Delay(4294967295),
- ComputeDelay(std::chrono::microseconds(999999000000)));
+ EXPECT_EQ(Delay(4294967295), ComputeDelay(microseconds(65535999985)));
+ EXPECT_EQ(Delay(4294967295), ComputeDelay(microseconds(65535999986)));
+ EXPECT_EQ(Delay(4294967295), ComputeDelay(microseconds(999999000000)));
EXPECT_EQ(Delay(4294967295), ComputeDelay(Clock::duration::max()));
}
diff --git a/cast/streaming/rtp_packetizer_unittest.cc b/cast/streaming/rtp_packetizer_unittest.cc
index d99eefa0..8b471065 100644
--- a/cast/streaming/rtp_packetizer_unittest.cc
+++ b/cast/streaming/rtp_packetizer_unittest.cc
@@ -4,12 +4,16 @@
#include "cast/streaming/rtp_packetizer.h"
+#include <chrono>
+#include <memory>
+
#include "absl/types/optional.h"
#include "cast/streaming/frame_crypto.h"
#include "cast/streaming/rtp_defines.h"
#include "cast/streaming/rtp_packet_parser.h"
#include "cast/streaming/ssrc.h"
#include "gtest/gtest.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
@@ -34,7 +38,7 @@ class RtpPacketizerTest : public testing::Test {
EncryptedFrame CreateFrame(FrameId frame_id,
bool is_key_frame,
- std::chrono::milliseconds new_playout_delay,
+ milliseconds new_playout_delay,
int payload_size) const {
EncodedFrame frame;
frame.dependency = is_key_frame ? EncodedFrame::KEY_FRAME
@@ -102,7 +106,7 @@ class RtpPacketizerTest : public testing::Test {
if (packet_id == FramePacketId{0}) {
EXPECT_EQ(frame.new_playout_delay, result->new_playout_delay);
} else {
- EXPECT_EQ(std::chrono::milliseconds(0), result->new_playout_delay);
+ EXPECT_EQ(milliseconds(0), result->new_playout_delay);
}
// Check that the RTP payload is correct for this packet.
@@ -141,8 +145,8 @@ TEST_F(RtpPacketizerTest, GeneratesPacketsForSequenceOfFrames) {
const bool is_key_frame = (i == 0);
const int frame_payload_size = is_key_frame ? 48269 : 10000;
const EncryptedFrame frame =
- CreateFrame(FrameId::first() + i, is_key_frame,
- std::chrono::milliseconds(0), frame_payload_size);
+ CreateFrame(FrameId::first() + i, is_key_frame, milliseconds(0),
+ frame_payload_size);
SCOPED_TRACE(testing::Message() << "frame_id=" << frame.frame_id);
const int num_packets = packetizer()->ComputeNumberOfPackets(frame);
ASSERT_EQ(is_key_frame ? 34 : 7, num_packets);
@@ -160,9 +164,8 @@ TEST_F(RtpPacketizerTest, GeneratesPacketsForSequenceOfFrames) {
// delay change. Only the first packet should mention the playout delay change.
TEST_F(RtpPacketizerTest, GeneratesPacketsForFrameWithLatencyChange) {
const int frame_payload_size = 38383;
- const EncryptedFrame frame =
- CreateFrame(FrameId::first() + 42, true, std::chrono::milliseconds(543),
- frame_payload_size);
+ const EncryptedFrame frame = CreateFrame(
+ FrameId::first() + 42, true, milliseconds(543), frame_payload_size);
const int num_packets = packetizer()->ComputeNumberOfPackets(frame);
ASSERT_EQ(27, num_packets);
@@ -179,9 +182,8 @@ TEST_F(RtpPacketizerTest, GeneratesPacketsForFrameWithLatencyChange) {
// silence can be represented by an empty payload).
TEST_F(RtpPacketizerTest, GeneratesOnePacketForFrameWithNoPayload) {
const int frame_payload_size = 0;
- const EncryptedFrame frame =
- CreateFrame(FrameId::first() + 99, false, std::chrono::milliseconds(0),
- frame_payload_size);
+ const EncryptedFrame frame = CreateFrame(FrameId::first() + 99, false,
+ milliseconds(0), frame_payload_size);
ASSERT_EQ(1, packetizer()->ComputeNumberOfPackets(frame));
TestGeneratePacket(frame, FramePacketId{0});
}
@@ -190,8 +192,8 @@ TEST_F(RtpPacketizerTest, GeneratesOnePacketForFrameWithNoPayload) {
// a different sequence counter value in the packet each time.
TEST_F(RtpPacketizerTest, GeneratesPacketForRetransmission) {
const int frame_payload_size = 16384;
- const EncryptedFrame frame = CreateFrame(
- FrameId::first(), true, std::chrono::milliseconds(0), frame_payload_size);
+ const EncryptedFrame frame =
+ CreateFrame(FrameId::first(), true, milliseconds(0), frame_payload_size);
const int num_packets = packetizer()->ComputeNumberOfPackets(frame);
ASSERT_EQ(12, num_packets);
diff --git a/cast/streaming/rtp_time_unittest.cc b/cast/streaming/rtp_time_unittest.cc
index 89254372..54173a8b 100644
--- a/cast/streaming/rtp_time_unittest.cc
+++ b/cast/streaming/rtp_time_unittest.cc
@@ -4,7 +4,10 @@
#include "cast/streaming/rtp_time.h"
+#include <chrono>
+
#include "gtest/gtest.h"
+#include "util/chrono_helpers.h"
namespace openscreen {
namespace cast {
diff --git a/cast/streaming/sender.cc b/cast/streaming/sender.cc
index 56fc7b67..3713a199 100644
--- a/cast/streaming/sender.cc
+++ b/cast/streaming/sender.cc
@@ -5,9 +5,11 @@
#include "cast/streaming/sender.h"
#include <algorithm>
-#include <ratio> // NOLINT
+#include <chrono>
+#include <ratio>
#include "cast/streaming/session_config.h"
+#include "util/chrono_helpers.h"
#include "util/osp_logging.h"
#include "util/std_util.h"
@@ -260,7 +262,7 @@ void Sender::OnReceiverReport(const RtcpReportBlock& receiver_report) {
sender_report_builder_.GetRecentReportTime(
receiver_report.last_status_report_id, rtcp_packet_arrival_time_);
const auto non_network_delay =
- duration_cast<Clock::duration>(receiver_report.delay_since_last_report);
+ Clock::to_duration(receiver_report.delay_since_last_report);
// Round trip time measurement: This is the time elapsed since the Sender
// Report was sent, minus the time the Receiver did other stuff before sending
@@ -271,8 +273,7 @@ void Sender::OnReceiverReport(const RtcpReportBlock& receiver_report) {
// true value is likely very close to zero (i.e., this is ideal network
// behavior); and so just represent this as 75 µs, an optimistic
// wired-Ethernet LAN ping time.
- constexpr auto kNearZeroRoundTripTime =
- duration_cast<Clock::duration>(microseconds(75));
+ constexpr auto kNearZeroRoundTripTime = Clock::to_duration(microseconds(75));
static_assert(kNearZeroRoundTripTime > Clock::duration::zero(),
"More precision in Clock::duration needed!");
const Clock::duration measurement =
@@ -497,8 +498,8 @@ Sender::ChosenPacketAndWhen Sender::ChooseKickstartPacket() {
// arrivals.
using kWaitFraction = std::ratio<1, 20>;
const Clock::duration desired_kickstart_interval =
- duration_cast<Clock::duration>(target_playout_delay_) *
- kWaitFraction::num / kWaitFraction::den;
+ Clock::to_duration(target_playout_delay_) * kWaitFraction::num /
+ kWaitFraction::den;
// The actual interval used is increased, if current network performance
// warrants waiting longer. Don't send a Kickstart packet until no NACKs
// have been received for two network round-trip periods.
diff --git a/cast/streaming/sender.h b/cast/streaming/sender.h
index 48f651c0..33ea5227 100644
--- a/cast/streaming/sender.h
+++ b/cast/streaming/sender.h
@@ -8,7 +8,7 @@
#include <stdint.h>
#include <array>
-#include <chrono> // NOLINT
+#include <chrono>
#include <vector>
#include "absl/types/span.h"
diff --git a/cast/streaming/sender_packet_router.cc b/cast/streaming/sender_packet_router.cc
index 71fb2991..c3fccd18 100644
--- a/cast/streaming/sender_packet_router.cc
+++ b/cast/streaming/sender_packet_router.cc
@@ -9,6 +9,7 @@
#include "cast/streaming/constants.h"
#include "cast/streaming/packet_util.h"
+#include "util/chrono_helpers.h"
#include "util/osp_logging.h"
#include "util/saturate_cast.h"
#include "util/stringprintf.h"
@@ -223,8 +224,7 @@ int SenderPacketRouter::SendJustTheRtpPackets(Clock::time_point send_time,
namespace {
constexpr int kBitsPerByte = 8;
-constexpr auto kOneSecondInMilliseconds =
- duration_cast<milliseconds>(seconds(1));
+constexpr auto kOneSecondInMilliseconds = to_microseconds(seconds(1));
} // namespace
// static
diff --git a/cast/streaming/sender_packet_router.h b/cast/streaming/sender_packet_router.h
index e73e73ec..a6c161a9 100644
--- a/cast/streaming/sender_packet_router.h
+++ b/cast/streaming/sender_packet_router.h
@@ -7,7 +7,7 @@
#include <stdint.h>
-#include <chrono> // NOLINT
+#include <chrono>
#include <memory>
#include <vector>
diff --git a/cast/streaming/sender_packet_router_unittest.cc b/cast/streaming/sender_packet_router_unittest.cc
index 2ccbf241..d0b717c9 100644
--- a/cast/streaming/sender_packet_router_unittest.cc
+++ b/cast/streaming/sender_packet_router_unittest.cc
@@ -4,6 +4,8 @@
#include "cast/streaming/sender_packet_router.h"
+#include <chrono>
+
#include "cast/streaming/constants.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
@@ -11,6 +13,7 @@
#include "platform/test/fake_clock.h"
#include "platform/test/fake_task_runner.h"
#include "util/big_endian.h"
+#include "util/chrono_helpers.h"
#include "util/osp_logging.h"
using testing::_;
diff --git a/cast/streaming/sender_unittest.cc b/cast/streaming/sender_unittest.cc
index 2ab64c59..7b162161 100644
--- a/cast/streaming/sender_unittest.cc
+++ b/cast/streaming/sender_unittest.cc
@@ -8,10 +8,11 @@
#include <algorithm>
#include <array>
-#include <chrono> // NOLINT
+#include <chrono>
#include <limits>
#include <map>
#include <set>
+#include <utility>
#include <vector>
#include "absl/types/optional.h"
@@ -36,6 +37,7 @@
#include "platform/test/fake_clock.h"
#include "platform/test/fake_task_runner.h"
#include "util/alarm.h"
+#include "util/chrono_helpers.h"
#include "util/yet_another_bit_vector.h"
using testing::_;
@@ -522,8 +524,7 @@ TEST_F(SenderTest, ComputesInFlightMediaDuration) {
TEST_F(SenderTest, RespondsToNetworkLatencyChanges) {
// The expected maximum error in time calculations is one tick of the RTCP
// report block's delay type.
- constexpr auto kEpsilon =
- duration_cast<nanoseconds>(RtcpReportBlock::Delay(1));
+ constexpr auto kEpsilon = to_nanoseconds(RtcpReportBlock::Delay(1));
// Before the Sender has the necessary information to compute the network
// round-trip time, GetMaxInFlightMediaDuration() will return half the target
@@ -566,8 +567,8 @@ TEST_F(SenderTest, RespondsToNetworkLatencyChanges) {
// Create the Receiver Report "reply," and simulate it being sent across the
// network, back to the Sender.
receiver()->SetReceiverReport(
- sender_report_id,
- duration_cast<RtcpReportBlock::Delay>(kReceiverProcessingDelay));
+ sender_report_id, std::chrono::duration_cast<RtcpReportBlock::Delay>(
+ kReceiverProcessingDelay));
receiver()->TransmitRtcpFeedbackPacket();
SimulateExecution(kInboundDelay);
diff --git a/cast/streaming/session_config.h b/cast/streaming/session_config.h
index 4d611b65..f1fc0299 100644
--- a/cast/streaming/session_config.h
+++ b/cast/streaming/session_config.h
@@ -6,7 +6,7 @@
#define CAST_STREAMING_SESSION_CONFIG_H_
#include <array>
-#include <chrono> // NOLINT
+#include <chrono>
#include <cstdint>
#include "cast/streaming/ssrc.h"