Add set_timestamp() method to RTCStats.

Useful for when creating aggregate stats objects, seems like an
oversight that we don't have it already.

Bug: None
Change-Id: Ied36afd2122464a81c7d725825353f9af59fe632
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376220
Auto-Submit: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43844}
This commit is contained in:
Henrik Boström 2025-02-03 14:24:10 +01:00 committed by WebRTC LUCI CQ
parent 9cc5bc8499
commit 0533b5eafe
2 changed files with 7 additions and 0 deletions

View File

@ -63,6 +63,7 @@ class RTC_EXPORT RTCStats {
const std::string& id() const { return id_; } const std::string& id() const { return id_; }
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds. // Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds.
Timestamp timestamp() const { return timestamp_; } Timestamp timestamp() const { return timestamp_; }
void set_timestamp(Timestamp timestamp) { timestamp_ = timestamp; }
// Returns the static member variable `kType` of the implementing class. // Returns the static member variable `kType` of the implementing class.
virtual const char* type() const = 0; virtual const char* type() const = 0;

View File

@ -484,6 +484,12 @@ TEST(RTCStatsTest, AttributeToString) {
stats.GetAttribute(stats.m_map_string_double).ToString()); stats.GetAttribute(stats.m_map_string_double).ToString());
} }
TEST(RTCStatsTest, SetTimestamp) {
RTCTestStats test_stats("testId", Timestamp::Micros(123));
test_stats.set_timestamp(Timestamp::Micros(321));
EXPECT_EQ(test_stats.timestamp(), Timestamp::Micros(321));
}
// Death tests. // Death tests.
// Disabled on Android because death tests misbehave on Android, see // Disabled on Android because death tests misbehave on Android, see
// base/test/gtest_util.h. // base/test/gtest_util.h.