summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/capture.cpp15
-rw-r--r--src/cam/capture.h3
2 files changed, 8 insertions, 10 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;
diff --git a/src/cam/capture.h b/src/cam/capture.h
index 1d4a25a8..ee0dc421 100644
--- a/src/cam/capture.h
+++ b/src/cam/capture.h
@@ -7,6 +7,7 @@
#ifndef __CAM_CAPTURE_H__
#define __CAM_CAPTURE_H__
+#include <chrono>
#include <memory>
#include <libcamera/camera.h>
@@ -35,7 +36,7 @@ private:
std::map<libcamera::Stream *, std::string> streamName_;
BufferWriter *writer_;
- uint64_t last_;
+ std::chrono::steady_clock::time_point last_;
};
#endif /* __CAM_CAPTURE_H__ */