From fc6f6434748dc87f1e27e10bb5150cfd3b60328b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 17 May 2022 15:42:49 -0400
Subject: [PATCH] SinkClient: use steady_clock for FPS calculation

Change-Id: Ic14fe56d0223433782d06a97904024b56c9ab732
---
 src/media/video/sinkclient.cpp | 10 +++++-----
 src/media/video/sinkclient.h   |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/media/video/sinkclient.cpp b/src/media/video/sinkclient.cpp
index 6d8ba4b65b..4e9f15bd48 100644
--- a/src/media/video/sinkclient.cpp
+++ b/src/media/video/sinkclient.cpp
@@ -330,7 +330,7 @@ SinkClient::SinkClient(const std::string& id, bool mixer)
     , scaler_(new VideoScaler())
 #ifdef DEBUG_FPS
     , frameCount_(0u)
-    , lastFrameDebug_(std::chrono::system_clock::now())
+    , lastFrameDebug_(std::chrono::steady_clock::now())
 #endif
 {
     JAMI_DBG("[Sink:%p] Sink [%s] created", this, getId().c_str());
@@ -416,11 +416,11 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/,
                    const std::shared_ptr<MediaFrame>& frame_p)
 {
 #ifdef DEBUG_FPS
-    auto currentTime = std::chrono::system_clock::now();
-    std::chrono::duration<double> seconds = currentTime - lastFrameDebug_;
+    auto currentTime = std::chrono::steady_clock::now();
+    auto seconds = currentTime - lastFrameDebug_;
     ++frameCount_;
-    if (seconds.count() > 1) {
-        auto fps = frameCount_ / seconds.count();
+    if (seconds > std::chrono::seconds(1)) {
+        auto fps = frameCount_ / std::chrono::duration<double>(seconds).count();
         // Send the framerate in smartInfo
         Smartools::getInstance().setFrameRate(id_, std::to_string(fps));
         frameCount_ = 0;
diff --git a/src/media/video/sinkclient.h b/src/media/video/sinkclient.h
index 90313f4878..ed3d9fdfe5 100644
--- a/src/media/video/sinkclient.h
+++ b/src/media/video/sinkclient.h
@@ -119,7 +119,7 @@ private:
 
 #ifdef DEBUG_FPS
     unsigned frameCount_;
-    std::chrono::time_point<std::chrono::system_clock> lastFrameDebug_;
+    std::chrono::steady_clock::time_point lastFrameDebug_;
 #endif
 
 #if HAVE_SHM
-- 
GitLab