[libcamera-devel] [PATCH 4/4] qcam: Update window title with FPS
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Jul 2 16:31:49 CEST 2019
Hi Kieran,
Thank you for the patch.
On Tue, Jul 02, 2019 at 12:48:41PM +0100, Kieran Bingham wrote:
> 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("");
Ah now I see why you have added a MainWindow::setWindowTitle() method.
> 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)
How about passing the fps as a floating point number instead of a
string, and doing the conversion internally ? Otherwise you should pass
a const QString &.
> {
> 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");
I think we should update the title for every frame, but only
periodically (x times per second, which doesn't require a timer but can
simply use a difference between the current timestamp and the last
update timestamp here). Otherwise it would flash a bit too fast to be
really readable.
I think you should also compute the fps using a moving average instead
of an average since the beginning of the stream, as the latter isn't
that meaningful.
> +
> + 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);
You have name the parameter fps above.
>
> 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_;
> };
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list