Add nanoseconds accessor to Timestamp
Bug: webrtc:42223992
Change-Id: I21f0c5b319ddf08b27462679f19cc32dc3e7923a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/404965
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Auto-Submit: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45364}
diff --git a/api/units/timestamp.h b/api/units/timestamp.h
index 7831bba..0317e9f 100644
--- a/api/units/timestamp.h
+++ b/api/units/timestamp.h
@@ -60,6 +60,10 @@
constexpr T us() const {
return ToValue<T>();
}
+ template <typename T = int64_t>
+ constexpr T ns() const {
+ return ToMultiple<1000, T>();
+ }
constexpr int64_t seconds_or(int64_t fallback_value) const {
return ToFractionOr<1000000>(fallback_value);
diff --git a/api/units/timestamp_unittest.cc b/api/units/timestamp_unittest.cc
index 1b88cb7..c9254c2 100644
--- a/api/units/timestamp_unittest.cc
+++ b/api/units/timestamp_unittest.cc
@@ -37,6 +37,7 @@
EXPECT_EQ(kTimestampSeconds.seconds(), kValue);
EXPECT_EQ(kTimestampMs.ms(), kValue);
EXPECT_EQ(kTimestampUs.us(), kValue);
+ EXPECT_EQ(kTimestampUs.ns(), kValue * 1000);
}
TEST(TimestampTest, GetBackSameValues) {