stats: use Timestamp instead of uint64_t
making it clear what unit is being used.
BUG=webrtc:13756
Change-Id: I6354d35a8e02bb93a905ccf32cb0b294b4813e41
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/289460
Commit-Queue: Philipp Hancke <phancke@microsoft.com>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39008}
diff --git a/api/stats/rtc_stats.h b/api/stats/rtc_stats.h
index d4ba51d..abe2a5b 100644
--- a/api/stats/rtc_stats.h
+++ b/api/stats/rtc_stats.h
@@ -21,6 +21,7 @@
#include <vector>
#include "absl/types/optional.h"
+#include "api/units/timestamp.h"
#include "rtc_base/checks.h"
#include "rtc_base/system/rtc_export.h"
#include "rtc_base/system/rtc_export_template.h"
@@ -42,7 +43,7 @@
// Derived classes list their dictionary members, RTCStatsMember<T>, as public
// fields, allowing the following:
//
-// RTCFooStats foo("fooId", GetCurrentTime());
+// RTCFooStats foo("fooId", Timestamp::Micros(GetCurrentTime()));
// foo.bar = 42;
// foo.baz = std::vector<std::string>();
// foo.baz->push_back("hello world");
@@ -55,15 +56,20 @@
// }
class RTC_EXPORT RTCStats {
public:
+ RTCStats(const std::string& id, Timestamp timestamp)
+ : id_(id), timestamp_(timestamp) {}
RTCStats(std::string id, int64_t timestamp_us)
- : id_(std::move(id)), timestamp_us_(timestamp_us) {}
+ : RTCStats(std::move(id), Timestamp::Micros(timestamp_us)) {}
+
virtual ~RTCStats() {}
virtual std::unique_ptr<RTCStats> copy() const = 0;
const std::string& id() const { return id_; }
// Time relative to the UNIX epoch (Jan 1, 1970, UTC), in microseconds.
- int64_t timestamp_us() const { return timestamp_us_; }
+ int64_t timestamp_us() const { return timestamp_.us(); }
+ Timestamp timestamp() const { return timestamp_; }
+
// Returns the static member variable `kType` of the implementing class.
virtual const char* type() const = 0;
// Returns a vector of pointers to all the `RTCStatsMemberInterface` members
@@ -97,7 +103,7 @@
MembersOfThisObjectAndAncestors(size_t additional_capacity) const;
std::string const id_;
- int64_t timestamp_us_;
+ Timestamp timestamp_;
};
// All `RTCStats` classes should use these macros.
diff --git a/api/stats/rtcstats_objects.h b/api/stats/rtcstats_objects.h
index 9d3e697..1647989 100644
--- a/api/stats/rtcstats_objects.h
+++ b/api/stats/rtcstats_objects.h
@@ -120,6 +120,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCCertificateStats(std::string id, Timestamp timestamp);
RTCCertificateStats(std::string id, int64_t timestamp_us);
RTCCertificateStats(const RTCCertificateStats& other);
~RTCCertificateStats() override;
@@ -149,6 +150,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCCodecStats(std::string id, Timestamp timestamp);
RTCCodecStats(std::string id, int64_t timestamp_us);
RTCCodecStats(const RTCCodecStats& other);
~RTCCodecStats() override;
@@ -166,6 +168,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCDataChannelStats(std::string id, Timestamp timestamp);
RTCDataChannelStats(std::string id, int64_t timestamp_us);
RTCDataChannelStats(const RTCDataChannelStats& other);
~RTCDataChannelStats() override;
@@ -186,6 +189,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCIceCandidatePairStats(std::string id, Timestamp timestamp);
RTCIceCandidatePairStats(std::string id, int64_t timestamp_us);
RTCIceCandidatePairStats(const RTCIceCandidatePairStats& other);
~RTCIceCandidatePairStats() override;
@@ -254,6 +258,7 @@
RTCNonStandardStatsMember<std::string> network_adapter_type;
protected:
+ RTCIceCandidateStats(std::string id, Timestamp timestamp, bool is_remote);
RTCIceCandidateStats(std::string id, int64_t timestamp_us, bool is_remote);
};
@@ -265,6 +270,7 @@
class RTC_EXPORT RTCLocalIceCandidateStats final : public RTCIceCandidateStats {
public:
static const char kType[];
+ RTCLocalIceCandidateStats(std::string id, Timestamp timestamp);
RTCLocalIceCandidateStats(std::string id, int64_t timestamp_us);
std::unique_ptr<RTCStats> copy() const override;
const char* type() const override;
@@ -274,6 +280,7 @@
: public RTCIceCandidateStats {
public:
static const char kType[];
+ RTCRemoteIceCandidateStats(std::string id, Timestamp timestamp);
RTCRemoteIceCandidateStats(std::string id, int64_t timestamp_us);
std::unique_ptr<RTCStats> copy() const override;
const char* type() const override;
@@ -284,6 +291,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ DEPRECATED_RTCMediaStreamStats(std::string id, Timestamp timestamp);
DEPRECATED_RTCMediaStreamStats(std::string id, int64_t timestamp_us);
DEPRECATED_RTCMediaStreamStats(const DEPRECATED_RTCMediaStreamStats& other);
~DEPRECATED_RTCMediaStreamStats() override;
@@ -300,6 +308,9 @@
WEBRTC_RTCSTATS_DECL();
DEPRECATED_RTCMediaStreamTrackStats(std::string id,
+ Timestamp timestamp,
+ const char* kind);
+ DEPRECATED_RTCMediaStreamTrackStats(std::string id,
int64_t timestamp_us,
const char* kind);
DEPRECATED_RTCMediaStreamTrackStats(
@@ -345,6 +356,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCPeerConnectionStats(std::string id, Timestamp timestamp);
RTCPeerConnectionStats(std::string id, int64_t timestamp_us);
RTCPeerConnectionStats(const RTCPeerConnectionStats& other);
~RTCPeerConnectionStats() override;
@@ -372,6 +384,7 @@
RTCStatsMember<std::string> media_type; // renamed to kind.
protected:
+ RTCRTPStreamStats(std::string id, Timestamp timestamp);
RTCRTPStreamStats(std::string id, int64_t timestamp_us);
};
@@ -387,6 +400,7 @@
RTCStatsMember<int32_t> packets_lost; // Signed per RFC 3550
protected:
+ RTCReceivedRtpStreamStats(std::string id, Timestamp timestamp);
RTCReceivedRtpStreamStats(std::string id, int64_t timestamp_us);
};
@@ -402,6 +416,7 @@
RTCStatsMember<uint64_t> bytes_sent;
protected:
+ RTCSentRtpStreamStats(std::string id, Timestamp timestamp);
RTCSentRtpStreamStats(std::string id, int64_t timestamp_us);
};
@@ -411,6 +426,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCInboundRTPStreamStats(std::string id, Timestamp timestamp);
RTCInboundRTPStreamStats(std::string id, int64_t timestamp_us);
RTCInboundRTPStreamStats(const RTCInboundRTPStreamStats& other);
~RTCInboundRTPStreamStats() override;
@@ -498,6 +514,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCOutboundRTPStreamStats(std::string id, Timestamp timestamp);
RTCOutboundRTPStreamStats(std::string id, int64_t timestamp_us);
RTCOutboundRTPStreamStats(const RTCOutboundRTPStreamStats& other);
~RTCOutboundRTPStreamStats() override;
@@ -551,6 +568,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCRemoteInboundRtpStreamStats(std::string id, Timestamp timestamp);
RTCRemoteInboundRtpStreamStats(std::string id, int64_t timestamp_us);
RTCRemoteInboundRtpStreamStats(const RTCRemoteInboundRtpStreamStats& other);
~RTCRemoteInboundRtpStreamStats() override;
@@ -568,6 +586,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCRemoteOutboundRtpStreamStats(std::string id, Timestamp timestamp);
RTCRemoteOutboundRtpStreamStats(std::string id, int64_t timestamp_us);
RTCRemoteOutboundRtpStreamStats(const RTCRemoteOutboundRtpStreamStats& other);
~RTCRemoteOutboundRtpStreamStats() override;
@@ -592,6 +611,7 @@
RTCStatsMember<std::string> kind;
protected:
+ RTCMediaSourceStats(std::string id, Timestamp timestamp);
RTCMediaSourceStats(std::string id, int64_t timestamp_us);
};
@@ -600,6 +620,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCAudioSourceStats(std::string id, Timestamp timestamp);
RTCAudioSourceStats(std::string id, int64_t timestamp_us);
RTCAudioSourceStats(const RTCAudioSourceStats& other);
~RTCAudioSourceStats() override;
@@ -616,6 +637,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCVideoSourceStats(std::string id, Timestamp timestamp);
RTCVideoSourceStats(std::string id, int64_t timestamp_us);
RTCVideoSourceStats(const RTCVideoSourceStats& other);
~RTCVideoSourceStats() override;
@@ -631,6 +653,7 @@
public:
WEBRTC_RTCSTATS_DECL();
+ RTCTransportStats(std::string id, Timestamp timestamp);
RTCTransportStats(std::string id, int64_t timestamp_us);
RTCTransportStats(const RTCTransportStats& other);
~RTCTransportStats() override;