From patchwork Thu Jul 4 13:03:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1612 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D6F7C61570 for ; Thu, 4 Jul 2019 15:03:54 +0200 (CEST) Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 82F35E21; Thu, 4 Jul 2019 15:03:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562245434; bh=PHlxt8y8jHEgOvB4XDf8D8pN9uWwZ2srk+YLHPgO7C4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZXU+rJI+byl19a4hwDJpLOo+U1BtONIzXsMjdO4M6qFDmWhtcUG1ZgKlJgJhNsHI+ 8wOz7NQ06fvBJTYI2yWQkSEct7F60aiVrJdQEtx8TxXrq0wZnA4hp8yryMkvV6Wvfn 5qvVk/R8xWosxQhX+YujmOuX9HP1Gf+HD6rfUv24= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 14:03:47 +0100 Message-Id: <20190704130347.9372-10-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190704130347.9372-1-kieran.bingham@ideasonboard.com> References: <20190704130347.9372-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 5/5] qcam: Update window title with FPS X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jul 2019 13:03:55 -0000 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 --- 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); + 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 #include +#include #include +#include #include #include @@ -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', +]) + +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, install : true, dependencies : [libcamera_dep, qt5_dep],