summaryrefslogtreecommitdiffstats
path: root/dom/media/gtest/TestRTCStatsTimestampMaker.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/media/gtest/TestRTCStatsTimestampMaker.cpp
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/gtest/TestRTCStatsTimestampMaker.cpp')
-rw-r--r--dom/media/gtest/TestRTCStatsTimestampMaker.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/dom/media/gtest/TestRTCStatsTimestampMaker.cpp b/dom/media/gtest/TestRTCStatsTimestampMaker.cpp
new file mode 100644
index 0000000000..931d5e107d
--- /dev/null
+++ b/dom/media/gtest/TestRTCStatsTimestampMaker.cpp
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <cmath>
+
+#include "gtest/gtest.h"
+#include "libwebrtcglue/SystemTime.h"
+
+using namespace mozilla;
+using namespace dom;
+
+TEST(RTCStatsTimestampMakerRealtimeClock, ConvertTimestampToNtpTime)
+{
+ RTCStatsTimestampMaker maker;
+ RTCStatsTimestampMakerRealtimeClock clock(maker);
+ constexpr auto ntpTo1Jan1970Ms = webrtc::kNtpJan1970 * 1000LL;
+ for (int i = 1000; i < 20000; i += 93) {
+ const auto t = webrtc::Timestamp::Micros(i);
+ const auto ntp = clock.ConvertTimestampToNtpTime(t);
+ // Because of precision differences, these round to a specific millisecond
+ // slightly differently.
+ EXPECT_NEAR(ntp.ToMs() - ntpTo1Jan1970Ms,
+ maker.ConvertRealtimeTo1Jan1970(t).ms(), 1.0)
+ << " for i=" << i;
+ }
+}
+
+TEST(RTCStatsTimestampMaker, ConvertNtpToDomTime)
+{
+ RTCStatsTimestampMaker maker;
+ RTCStatsTimestampMakerRealtimeClock clock(maker);
+ for (int i = 1000; i < 20000; i += 93) {
+ const auto t = webrtc::Timestamp::Micros(i);
+ const auto ntp = clock.ConvertTimestampToNtpTime(t);
+ const auto dom =
+ maker.ConvertNtpToDomTime(webrtc::Timestamp::Millis(ntp.ToMs()));
+ // Because of precision differences, these round to a specific millisecond
+ // slightly differently.
+ EXPECT_NEAR(std::lround(dom), std::lround(maker.ReduceRealtimePrecision(t)),
+ 1.0)
+ << " for i=" << i;
+ }
+}