[libcamera-devel] [PATCH v2 5/5] qcam: Update window title with FPS

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Jul 4 15:52:56 CEST 2019


Hi Kieran,

Thank you for the patch.

On Thu, Jul 04, 2019 at 02:03:47PM +0100, Kieran Bingham wrote:
> Provide an average FPS in the QCam title bar to show the current rate of
> frame processing.
> 
> The QCam compilation is updated to process the QT MoC headers to support
> signals and slots accordingly.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
>  src/qcam/main_window.cpp | 22 ++++++++++++++++++++++
>  src/qcam/main_window.h   | 11 +++++++++++
>  src/qcam/meson.build     | 11 ++++++++++-
>  3 files changed, 43 insertions(+), 1 deletion(-)
> 
> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> index d61369109d66..9f05ec05549f 100644
> --- a/src/qcam/main_window.cpp
> +++ b/src/qcam/main_window.cpp
> @@ -29,6 +29,10 @@ MainWindow::MainWindow(const OptionsParser::Options &options)
>  	title_ = "QCam " + QString::fromStdString(libcamera::version);
>  	setWindowTitle(title_);
>  
> +	QTimer *timer = new QTimer(this);
> +	connect(timer, SIGNAL(timeout()), this, SLOT(updateTitle()));
> +	timer->start(2000);
> +

Should you start the timer only when starting capture ? And stop it when
stopping capture (and reset the title there to remove the fps) ?

>  	viewfinder_ = new ViewFinder(this);
>  	setCentralWidget(viewfinder_);
>  	viewfinder_->setFixedSize(500, 500);
> @@ -54,6 +58,19 @@ MainWindow::~MainWindow()
>  	CameraManager::instance()->stop();
>  }
>  
> +void MainWindow::updateTitle()
> +{
> +	unsigned int duration = frameRateInterval_.elapsed();
> +	unsigned int frames = framesCaptured_ - previousFrames_;
> +	double fps = frames * 1000.0 / duration;
> +
> +	/* Restart counters */
> +	frameRateInterval_.start();
> +	previousFrames_ = framesCaptured_;
> +
> +	setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps");
> +}
> +
>  int MainWindow::openCamera()
>  {
>  	CameraManager *cm = CameraManager::instance();
> @@ -148,6 +165,9 @@ int MainWindow::startCapture()
>  		requests.push_back(request);
>  	}
>  
> +	frameRateInterval_.start();
> +	previousFrames_ = 0;
> +	framesCaptured_ = 0;
>  	lastBufferTime_ = 0;
>  
>  	ret = camera_->start();
> @@ -196,6 +216,8 @@ void MainWindow::requestComplete(Request *request,
>  	if (request->status() == Request::RequestCancelled)
>  		return;
>  
> +	framesCaptured_++;
> +
>  	Buffer *buffer = buffers.begin()->second;
>  
>  	double fps = buffer->timestamp() - lastBufferTime_;
> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
> index 46a494a9d783..6b3dcab6d490 100644
> --- a/src/qcam/main_window.h
> +++ b/src/qcam/main_window.h
> @@ -10,7 +10,9 @@
>  #include <map>
>  #include <memory>
>  
> +#include <QElapsedTimer>
>  #include <QMainWindow>
> +#include <QObject>
>  
>  #include <libcamera/camera.h>
>  #include <libcamera/stream.h>
> @@ -28,10 +30,15 @@ enum {
>  
>  class MainWindow : public QMainWindow
>  {
> +	Q_OBJECT
> +
>  public:
>  	MainWindow(const OptionsParser::Options &options);
>  	~MainWindow();
>  
> +public Q_SLOTS:
> +	void updateTitle();
> +
>  private:
>  	int openCamera();
>  
> @@ -51,6 +58,10 @@ private:
>  
>  	uint64_t lastBufferTime_;
>  
> +	QElapsedTimer frameRateInterval_;
> +	uint32_t previousFrames_;
> +	uint32_t framesCaptured_;
> +
>  	ViewFinder *viewfinder_;
>  };
>  
> diff --git a/src/qcam/meson.build b/src/qcam/meson.build
> index 9f1fa75f9813..c2c4d7cc9787 100644
> --- a/src/qcam/meson.build
> +++ b/src/qcam/meson.build
> @@ -7,13 +7,22 @@ qcam_sources = files([
>      'viewfinder.cpp',
>  ])
>  
> -import('qt5')
> +qcam_headers = files([
> +    'main_window.h',

Should you list all the headers here ? Otherwise I would name this
variable qcam_moc_headers.

> +])
> +
> +qt5 = import('qt5')
>  qt5_dep = dependency('qt5',
>                       method : 'pkg-config',
>                       modules : ['Core', 'Gui', 'Widgets'],
>                       required : false)
>  
>  if qt5_dep.found()
> +    moc_files = qt5.preprocess(moc_headers: qcam_headers,
> +                               dependencies: qt5_dep)
> +
> +    qcam_sources += moc_files
> +
>      qcam  = executable('qcam', qcam_sources,

You don't need to update qcam_sources, you can list the moc files here:

    qcam  = executable('qcam', qcam_sources, moc_files,

>                         install : true,
>                         dependencies : [libcamera_dep, qt5_dep],

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list