summaryrefslogtreecommitdiff
path: root/src/cam/capture.cpp
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-14 03:40:47 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-09-14 15:05:45 +0300
commitcecfeed61e8bcb4b53c2ed8e1b26d8c8af38b8e3 (patch)
tree783fca9b32651efdca054ad152528b40f2566a74 /src/cam/capture.cpp
parent98dff063f2f497434978a46f9a676307365fd878 (diff)
libcamera: Switch to the std::chrono API
Replace the clock_gettime()-based API with durations expressed as integers with the std::chrono API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src/cam/capture.cpp')
-rw-r--r--src/cam/capture.cpp15
1 files changed, 6 insertions, 9 deletions
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 <chrono>
#include <climits>
#include <iomanip>
#include <iostream>
@@ -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<Stream *, Buffer *> &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<std::chrono::milliseconds>(now - last_).count();
+ fps = last_ != std::chrono::steady_clock::time_point() && fps
+ ? 1000.0 / fps : 0.0;
last_ = now;
std::stringstream info;