From cecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 14 Sep 2019 03:40:47 +0300 Subject: libcamera: Switch to the std::chrono API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/cam/capture.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/cam/capture.cpp') diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index df9602de..8a939c62 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -5,6 +5,7 @@ * capture.cpp - Cam capture */ +#include #include #include #include @@ -16,7 +17,7 @@ using namespace libcamera; Capture::Capture(Camera *camera, CameraConfiguration *config) - : camera_(camera), config_(config), writer_(nullptr), last_(0) + : camera_(camera), config_(config), writer_(nullptr) { } @@ -135,17 +136,13 @@ int Capture::capture(EventLoop *loop) void Capture::requestComplete(Request *request, const std::map &buffers) { - double fps = 0.0; - uint64_t now; - if (request->status() == Request::RequestCancelled) return; - struct timespec time; - clock_gettime(CLOCK_MONOTONIC, &time); - now = time.tv_sec * 1000 + time.tv_nsec / 1000000; - fps = now - last_; - fps = last_ && fps ? 1000.0 / fps : 0.0; + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + double fps = std::chrono::duration_cast(now - last_).count(); + fps = last_ != std::chrono::steady_clock::time_point() && fps + ? 1000.0 / fps : 0.0; last_ = now; std::stringstream info; -- cgit v1.2.1