[libcamera-devel] [PATCH 4/4] qcam: Update window title with FPS
Kieran Bingham
kieran.bingham at ideasonboard.com
Tue Jul 2 13:48:41 CEST 2019
Provide an average FPS in the QCam title bar to show the current rate of
frame processing.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
src/qcam/main_window.cpp | 23 ++++++++++++++++++++---
src/qcam/main_window.h | 4 +++-
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 61d7aa9469f0..c093bd0c809e 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -26,7 +26,7 @@ MainWindow::MainWindow(const OptionsParser::Options &options)
{
int ret;
- setWindowTitle();
+ setWindowTitle("");
viewfinder_ = new ViewFinder(this);
setCentralWidget(viewfinder_);
viewfinder_->setFixedSize(500, 500);
@@ -52,10 +52,11 @@ MainWindow::~MainWindow()
CameraManager::instance()->stop();
}
-void MainWindow::setWindowTitle()
+void MainWindow::setWindowTitle(QString fps)
{
QMainWindow::setWindowTitle("QCam : "
- + QString::fromStdString(libcamera::version.toString()));
+ + QString::fromStdString(libcamera::version.toString())
+ + " (" + fps + ")");
}
int MainWindow::openCamera()
@@ -152,6 +153,9 @@ int MainWindow::startCapture()
requests.push_back(request);
}
+ firstFrameTime = 0;
+ framesCaptured = 0;
+
ret = camera_->start();
if (ret) {
std::cout << "Failed to start capture" << std::endl;
@@ -215,6 +219,19 @@ void MainWindow::requestComplete(Request *request,
display(buffer);
+ if (firstFrameTime == 0)
+ firstFrameTime = buffer->timestamp();
+
+ uint64_t duration = buffer->timestamp() - firstFrameTime;
+ if (duration)
+ fps = framesCaptured * 1000000000.0 / duration;
+ else
+ fps = 0.0;
+
+ setWindowTitle(QString::number(fps, 'f', 2) + " fps");
+
+ framesCaptured++;
+
request = camera_->createRequest();
if (!request) {
std::cerr << "Can't create request" << std::endl;
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index b30a86768efc..792f89c2d831 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -33,7 +33,7 @@ public:
~MainWindow();
private:
- void setWindowTitle();
+ void setWindowTitle(QString info);
int openCamera();
@@ -49,6 +49,8 @@ private:
std::shared_ptr<Camera> camera_;
bool isCapturing_;
std::unique_ptr<CameraConfiguration> config_;
+ uint64_t firstFrameTime;
+ uint32_t framesCaptured;
ViewFinder *viewfinder_;
};
--
2.20.1
More information about the libcamera-devel
mailing list