diff --git a/api/BUILD.gn b/api/BUILD.gn index 388c289d01..6c9414e54d 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -706,6 +706,7 @@ rtc_source_set("rtc_stats_api") { "../rtc_base:checks", "../rtc_base:refcount", "../rtc_base/system:rtc_export", + "units:timestamp", ] } diff --git a/api/stats/rtc_stats_report.h b/api/stats/rtc_stats_report.h index f84272cb81..1cc6293fec 100644 --- a/api/stats/rtc_stats_report.h +++ b/api/stats/rtc_stats_report.h @@ -23,6 +23,7 @@ #include "api/ref_counted_base.h" #include "api/scoped_refptr.h" #include "api/stats/rtc_stats.h" +#include "api/units/timestamp.h" // TODO(tommi): Remove this include after fixing iwyu issue in chromium. // See: third_party/blink/renderer/platform/peerconnection/rtc_stats.cc #include "rtc_base/ref_counted_object.h" @@ -59,15 +60,21 @@ class RTC_EXPORT RTCStatsReport final StatsMap::const_iterator it_; }; - // TODO(hbos): Remove "= 0" once Chromium unittest has been updated to call - // with a parameter. crbug.com/627816 + // TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp. + // TODO(hbos): Remove "= 0" once downstream has been updated to call with a + // parameter. static rtc::scoped_refptr Create(int64_t timestamp_us = 0); + static rtc::scoped_refptr Create(Timestamp timestamp); + // TODO(bugs.webrtc.org/13756): deprecate this in favor of Timestamp. explicit RTCStatsReport(int64_t timestamp_us); + explicit RTCStatsReport(Timestamp timestamp); + RTCStatsReport(const RTCStatsReport& other) = delete; rtc::scoped_refptr Copy() const; - int64_t timestamp_us() const { return timestamp_us_; } + int64_t timestamp_us() const { return timestamp_.us_or(-1); } + Timestamp timestamp() const { return timestamp_; } void AddStats(std::unique_ptr stats); // On success, returns a non-owning pointer to `stats`. If the stats ID is not // unique, `stats` is not inserted and nullptr is returned. @@ -128,7 +135,7 @@ class RTC_EXPORT RTCStatsReport final ~RTCStatsReport() = default; private: - int64_t timestamp_us_; + Timestamp timestamp_; StatsMap stats_; }; diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 7ef00a90a4..cc5c7208e3 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -1307,7 +1307,7 @@ rtc::scoped_refptr CreateReportFilteredBySelector( } } if (rtpstream_ids.empty()) - return RTCStatsReport::Create(report->timestamp_us()); + return RTCStatsReport::Create(report->timestamp()); return TakeReferencedStats(report->Copy(), rtpstream_ids); } @@ -1469,7 +1469,7 @@ void RTCStatsCollector::ProducePartialResultsOnSignalingThread( RTC_DCHECK_RUN_ON(signaling_thread_); rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; - partial_report_ = RTCStatsReport::Create(timestamp_us); + partial_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us)); ProducePartialResultsOnSignalingThreadImpl(timestamp_us, partial_report_.get()); @@ -1505,7 +1505,7 @@ void RTCStatsCollector::ProducePartialResultsOnNetworkThread( // Touching `network_report_` on this thread is safe by this method because // `network_report_event_` is reset before this method is invoked. - network_report_ = RTCStatsReport::Create(timestamp_us); + network_report_ = RTCStatsReport::Create(Timestamp::Micros(timestamp_us)); std::set transport_names; if (sctp_transport_name) { diff --git a/pc/rtc_stats_traversal.cc b/pc/rtc_stats_traversal.cc index 6d886f5099..279488f135 100644 --- a/pc/rtc_stats_traversal.cc +++ b/pc/rtc_stats_traversal.cc @@ -62,7 +62,7 @@ rtc::scoped_refptr TakeReferencedStats( rtc::scoped_refptr report, const std::vector& ids) { rtc::scoped_refptr result = - RTCStatsReport::Create(report->timestamp_us()); + RTCStatsReport::Create(report->timestamp()); for (const auto& id : ids) { TraverseAndTakeVisitedStats(report.get(), result.get(), id); } diff --git a/pc/rtc_stats_traversal_unittest.cc b/pc/rtc_stats_traversal_unittest.cc index 6e9b784313..efc7bbcec8 100644 --- a/pc/rtc_stats_traversal_unittest.cc +++ b/pc/rtc_stats_traversal_unittest.cc @@ -28,14 +28,14 @@ class RTCStatsTraversalTest : public ::testing::Test { candidate_pair_ = new RTCIceCandidatePairStats("candidate-pair", 0); local_candidate_ = new RTCLocalIceCandidateStats("local-candidate", 0); remote_candidate_ = new RTCRemoteIceCandidateStats("remote-candidate", 0); - initial_report_ = RTCStatsReport::Create(0); + initial_report_ = RTCStatsReport::Create(Timestamp::Zero()); initial_report_->AddStats(std::unique_ptr(transport_)); initial_report_->AddStats(std::unique_ptr(candidate_pair_)); initial_report_->AddStats( std::unique_ptr(local_candidate_)); initial_report_->AddStats( std::unique_ptr(remote_candidate_)); - result_ = RTCStatsReport::Create(0); + result_ = RTCStatsReport::Create(Timestamp::Zero()); } void TakeReferencedStats(std::vector start_nodes) { diff --git a/stats/rtc_stats_report.cc b/stats/rtc_stats_report.cc index 187adadd7e..f6fbd8c44d 100644 --- a/stats/rtc_stats_report.cc +++ b/stats/rtc_stats_report.cc @@ -59,11 +59,17 @@ rtc::scoped_refptr RTCStatsReport::Create( return rtc::scoped_refptr(new RTCStatsReport(timestamp_us)); } +rtc::scoped_refptr RTCStatsReport::Create(Timestamp timestamp) { + return rtc::scoped_refptr(new RTCStatsReport(timestamp)); +} + RTCStatsReport::RTCStatsReport(int64_t timestamp_us) - : timestamp_us_(timestamp_us) {} + : RTCStatsReport(Timestamp::Micros(timestamp_us)) {} + +RTCStatsReport::RTCStatsReport(Timestamp timestamp) : timestamp_(timestamp) {} rtc::scoped_refptr RTCStatsReport::Copy() const { - rtc::scoped_refptr copy = Create(timestamp_us_); + rtc::scoped_refptr copy = Create(timestamp_); for (auto it = stats_.begin(); it != stats_.end(); ++it) { copy->AddStats(it->second->copy()); } diff --git a/stats/rtc_stats_report_unittest.cc b/stats/rtc_stats_report_unittest.cc index 2081364f66..8af6dbe620 100644 --- a/stats/rtc_stats_report_unittest.cc +++ b/stats/rtc_stats_report_unittest.cc @@ -53,8 +53,10 @@ class RTCTestStats3 : public RTCStats { WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", &string) TEST(RTCStatsReport, AddAndGetStats) { - rtc::scoped_refptr report = RTCStatsReport::Create(1337); + rtc::scoped_refptr report = + RTCStatsReport::Create(Timestamp::Micros(1337)); EXPECT_EQ(report->timestamp_us(), 1337u); + EXPECT_EQ(report->timestamp().us_or(-1), 1337u); EXPECT_EQ(report->size(), static_cast(0)); report->AddStats(std::unique_ptr(new RTCTestStats1("a0", 1))); report->AddStats(std::unique_ptr(new RTCTestStats1("a1", 2))); @@ -87,8 +89,10 @@ TEST(RTCStatsReport, AddAndGetStats) { } TEST(RTCStatsReport, StatsOrder) { - rtc::scoped_refptr report = RTCStatsReport::Create(1337); + rtc::scoped_refptr report = + RTCStatsReport::Create(Timestamp::Micros(1337)); EXPECT_EQ(report->timestamp_us(), 1337u); + EXPECT_EQ(report->timestamp().us_or(-1), 1337u); report->AddStats(std::unique_ptr(new RTCTestStats1("C", 2))); report->AddStats(std::unique_ptr(new RTCTestStats1("D", 3))); report->AddStats(std::unique_ptr(new RTCTestStats2("B", 1))); @@ -105,7 +109,8 @@ TEST(RTCStatsReport, StatsOrder) { } TEST(RTCStatsReport, Take) { - rtc::scoped_refptr report = RTCStatsReport::Create(0); + rtc::scoped_refptr report = + RTCStatsReport::Create(Timestamp::Zero()); report->AddStats(std::unique_ptr(new RTCTestStats1("A", 1))); report->AddStats(std::unique_ptr(new RTCTestStats1("B", 2))); EXPECT_TRUE(report->Get("A")); @@ -118,13 +123,17 @@ TEST(RTCStatsReport, Take) { } TEST(RTCStatsReport, TakeMembersFrom) { - rtc::scoped_refptr a = RTCStatsReport::Create(1337); + rtc::scoped_refptr a = + RTCStatsReport::Create(Timestamp::Micros(1337)); EXPECT_EQ(a->timestamp_us(), 1337u); + EXPECT_EQ(a->timestamp().us_or(-1), 1337u); a->AddStats(std::unique_ptr(new RTCTestStats1("B", 1))); a->AddStats(std::unique_ptr(new RTCTestStats1("C", 2))); a->AddStats(std::unique_ptr(new RTCTestStats1("E", 4))); - rtc::scoped_refptr b = RTCStatsReport::Create(1338); + rtc::scoped_refptr b = + RTCStatsReport::Create(Timestamp::Micros(1338)); EXPECT_EQ(b->timestamp_us(), 1338u); + EXPECT_EQ(b->timestamp().us_or(-1), 1338u); b->AddStats(std::unique_ptr(new RTCTestStats1("A", 0))); b->AddStats(std::unique_ptr(new RTCTestStats1("D", 3))); b->AddStats(std::unique_ptr(new RTCTestStats1("F", 5)));