From patchwork Thu Jul 4 13:03:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1603 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EBDB861569 for ; Thu, 4 Jul 2019 15:03:51 +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 6764024B; Thu, 4 Jul 2019 15:03:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562245431; bh=LAy9/9/LuEB3/aD5JnBEpqvsmsPDQwE7xpqSX+8RY5M=; h=From:To:Cc:Subject:Date:From; b=sqfTmVD9uJEbtwusuO/MddEzdzZHvs0JfOOl8PY0W5rP64XrN4krY7smZplnwjZGk F3MmWuw9oLQx3XEEqaKbNBXjXioKmQtuNkQirjP06Q89ybukeQPJBSRUvqxN3sm6aF vrI/1Izn9QJU9MzD5dtUXdLPayVQvFpYuYlrnPCo= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 14:03:38 +0100 Message-Id: <20190704130347.9372-1-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] Documentation: Make the project brief more expressive 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:52 -0000 The current project brief lacks any quotation marks, and causes the Doxygen API documents to show the header "libcameraframework". Replace the simplistic definition with a better brief, and ensure quotation marks are provided to maintain spacing. Fixes: 53c4d4c34fc4 ("Documentation: Generate source code documentation using Doxygen") Signed-off-by: Kieran Bingham --- Documentation/Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/Doxyfile.in b/Documentation/Doxyfile.in index c58631200dd5..0dc1ab3944d1 100644 --- a/Documentation/Doxyfile.in +++ b/Documentation/Doxyfile.in @@ -44,7 +44,7 @@ PROJECT_NUMBER = @VERSION@ # for a project that appears at the top of each page and should give viewer a # quick idea about the purpose of the project. Keep the description short. -PROJECT_BRIEF = libcamera framework +PROJECT_BRIEF = "Supporting complex camera pipelines and devices" # With the PROJECT_LOGO tag one can specify a logo or an icon that is included # in the documentation. The maximum height of the logo should not exceed 55 From patchwork Thu Jul 4 13:03:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1604 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 327FC61569 for ; Thu, 4 Jul 2019 15:03:52 +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 B9C1B2AF; Thu, 4 Jul 2019 15:03:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562245431; bh=lVmwcE5IIfm80uWWnVDzsDkB7qENFPtscBmaqv/7ufU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=stHj9FesAI97k1+o+gq0zSrQkKG129slalxyF+1ji47eLhpsrMyXbuOHW9IlM6FAT 1PbRbySImNa3nvUPZA1+OoyECT3FA5yEgvj220m68dwpXykEgU5otJdlzZKeQjrUGm doysyrVzM3b5Oq0DfZ6J1ZDQ2Z+MBCuD/Z7O4Xsc= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 14:03:39 +0100 Message-Id: <20190704130347.9372-2-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 2/4] libcamera: Auto generate version information 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:52 -0000 Generate a version string, and provide a global singleton object which allows applications to interogate the current libcamera version information. The version header is automatically updated by meson on each build. The string roughly follows the semver [0] conventions of major.minor.patch-label as a value. [0] https://semver.org/ The utils/version-gen script will look for tags in the form vX.Y as starting points for the version string. While the repository does not have any matching tags, v0.0 will be assumed, resulting in versions with both major and minor being set to '0', and the patch count resulting from the number of patches in the history to that point. Finally, a uniquely identifying shortened checksum is provided from git: v0.0.509.c544 Signed-off-by: Kieran Bingham --- v2: - Store VCS_Tag return reference for dependancy linking - Fix indentation on meson.build - fix shell usage and shellcheck warnings in version-gen - Make LibcameraVersion version global - Sphinx version now explicit as to it's source from Documentation/meson.build - Pass project_version() through api_version - Use Camera object to report version rather than global constructor. --- Documentation/conf.py | 7 ++---- Documentation/meson.build | 2 +- include/libcamera/meson.build | 1 + include/libcamera/version.h | 24 +++++++++++++++++++++ meson.build | 12 ++++++----- src/libcamera/camera_manager.cpp | 3 +++ src/libcamera/meson.build | 1 + src/libcamera/version.cpp | 35 ++++++++++++++++++++++++++++++ utils/version-gen | 37 ++++++++++++++++++++++++++++++++ version.h.in | 14 ++++++++++++ 10 files changed, 125 insertions(+), 11 deletions(-) create mode 100644 include/libcamera/version.h create mode 100644 src/libcamera/version.cpp create mode 100755 utils/version-gen create mode 100644 version.h.in diff --git a/Documentation/conf.py b/Documentation/conf.py index 970edf3d7298..3ac61a208145 100644 --- a/Documentation/conf.py +++ b/Documentation/conf.py @@ -23,11 +23,8 @@ project = 'libcamera' copyright = '2018-2019, The libcamera documentation authors' author = u'Kieran Bingham, Jacopo Mondi, Laurent Pinchart, Niklas Söderlund' -# The short X.Y version -version = '' -# The full version, including alpha/beta/rc tags -release = '0.1' - +# Version information is provided by the build environment, through the +# configuration_data (cdata) in Documentation/meson.build # -- General configuration --------------------------------------------------- diff --git a/Documentation/meson.build b/Documentation/meson.build index 629e853120cb..91539b2afd66 100644 --- a/Documentation/meson.build +++ b/Documentation/meson.build @@ -1,4 +1,4 @@ -doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(api_version)) +doc_install_dir = join_paths(get_option('datadir'), 'doc', 'libcamera-@0@'.format(meson.project_version())) # # Doxygen diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 15484724df01..c925af7b3f96 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -12,6 +12,7 @@ libcamera_api = files([ 'signal.h', 'stream.h', 'timer.h', + 'version.h', ]) gen_header = files('gen-header.sh') diff --git a/include/libcamera/version.h b/include/libcamera/version.h new file mode 100644 index 000000000000..3075cfb7a6e3 --- /dev/null +++ b/include/libcamera/version.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * version.h - Library version information + */ +#ifndef __LIBCAMERA_VERSION_H__ +#define __LIBCAMERA_VERSION_H__ + +#include + +namespace libcamera { + +class LibcameraVersion +{ +public: + std::string toString() const; +}; + +extern const LibcameraVersion version; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_VERSION_H__ */ diff --git a/meson.build b/meson.build index a3b0bc820072..c34763162d7d 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,8 @@ project('libcamera', 'c', 'cpp', meson_version : '>= 0.40', - version : '0.1', + version : run_command('utils/version-gen', + '@0@'.format(meson.source_root()), + check : true).stdout().strip(), default_options : [ 'werror=true', 'warning_level=2', @@ -8,10 +10,10 @@ project('libcamera', 'c', 'cpp', ], license : 'LGPL 2.1+') -# TODO: Extract this from project.version. -# Ideally the version at Documentation/conf.py should be -# generated from this too. -api_version = '0.1' +vcs = vcs_tag(command: ['utils/version-gen', '.'], + input: 'version.h.in', + output: 'version.h', + fallback: 'v0.0') cc = meson.get_compiler('c') config_h = configuration_data() diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index cf881ce2e641..09be4b03af45 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -9,6 +9,7 @@ #include #include +#include #include "device_enumerator.h" #include "event_dispatcher_poll.h" @@ -79,6 +80,8 @@ int CameraManager::start() if (enumerator_) return -EBUSY; + LOG(Camera, Info) << "libcamera version : " << version.toString(); + enumerator_ = DeviceEnumerator::create(); if (!enumerator_ || enumerator_->enumerate()) return -ENODEV; diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 45bd9d1793aa..0110f1906bc3 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -28,6 +28,7 @@ libcamera_sources = files([ 'v4l2_device.cpp', 'v4l2_subdevice.cpp', 'v4l2_videodevice.cpp', + 'version.cpp', ]) libcamera_headers = files([ diff --git a/src/libcamera/version.cpp b/src/libcamera/version.cpp new file mode 100644 index 000000000000..d46985c88da5 --- /dev/null +++ b/src/libcamera/version.cpp @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * version.cpp - Version information + */ + +#include + +#include "log.h" + +/* The version header is automatically generated at the base of the project. */ +#include "../../version.h" + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Version) + +/** + * \class LibcameraVersion + * + * Reports library version information + */ + +/** + * \brief Return the library version as a string + */ +std::string LibcameraVersion::toString() const +{ + return LIBCAMERA_VERSION; +} + +const LibcameraVersion version; + +} /* namespace libcamera */ diff --git a/utils/version-gen b/utils/version-gen new file mode 100755 index 000000000000..481616b45c70 --- /dev/null +++ b/utils/version-gen @@ -0,0 +1,37 @@ +#!/bin/sh + +# SPDX-License-Identifier: GPL-2.0-or-later +# Generate a version string using git describe + +if [ -n "$1" ] +then + cd "$1" 2>/dev/null || exit 1 +fi + +# Get a short description from the tree. +version=$(git describe --abbrev=4 --match "v[0-9]*" 2>/dev/null) + +if [ -z "$version" ] +then + # Handle an un-tagged repository + sha=$(git describe --abbrev=4 --always 2>/dev/null) + commits=$(git log --oneline | wc -l 2>/dev/null) + version=v0.0.$commits.$sha +fi + +# Prevent changed timestamps causing -dirty labels +git update-index --refresh > /dev/null 2>&1 +dirty=$(git diff-index --name-only HEAD 2>/dev/null) || dirty= + +# Strip the 'g' +version=$(echo "$version" | sed -e 's/-g/-/g') + +# Fix the '-' (the patch count) to a '.' as a version increment. +version=$(echo "$version" | sed -e 's/-/./g') + +if [ -n "$dirty" ] +then + version=$version-dirty +fi + +echo "$version" diff --git a/version.h.in b/version.h.in new file mode 100644 index 000000000000..ad9134682df6 --- /dev/null +++ b/version.h.in @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * version.h - VCS TAG generated file. + * + * This file is auto-generated. Do not modify. + */ +#ifndef __LIBCAMERA_VERSION_TAG_H__ +#define __LIBCAMERA_VERSION_TAG_H__ + +#define LIBCAMERA_VERSION "@VCS_TAG@" + +#endif // __LIBCAMERA_VERSION_TAG_H__ From patchwork Thu Jul 4 13:03:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1605 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7E9B861569 for ; Thu, 4 Jul 2019 15:03:52 +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 18C18E21; Thu, 4 Jul 2019 15:03:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562245432; bh=kPRmPVpIuL84OkffCwEfKcOsAHxi5Nm7ZfvAeUM88XQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hp9wf1WyXxNGBaFsb53lU5X/gxfP3jQpQS6OQZGjmsxRAMd828jfm5LNkWWIP0jgq SrsSkBDsKO2e9C34P9f1o0WUlse2VN+T5LcuQw/4FBtOLefzoH4t838nIeTTiycYm6 SAm7VNypfIiTVbcLdpQkGCsskaCO7G45FFoThReA= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 14:03:40 +0100 Message-Id: <20190704130347.9372-3-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 3/4] qcam: Add the version string to the title 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:52 -0000 Provide the version string reported by the libcamera library on the qcam test utility. This helps confirm the exact version of the library that is being used while testing. Signed-off-by: Kieran Bingham --- src/qcam/main_window.cpp | 8 ++++++++ src/qcam/main_window.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 16b123132dd9..61d7aa9469f0 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -14,6 +14,7 @@ #include #include +#include #include "main_window.h" #include "viewfinder.h" @@ -25,6 +26,7 @@ MainWindow::MainWindow(const OptionsParser::Options &options) { int ret; + setWindowTitle(); viewfinder_ = new ViewFinder(this); setCentralWidget(viewfinder_); viewfinder_->setFixedSize(500, 500); @@ -50,6 +52,12 @@ MainWindow::~MainWindow() CameraManager::instance()->stop(); } +void MainWindow::setWindowTitle() +{ + QMainWindow::setWindowTitle("QCam : " + + QString::fromStdString(libcamera::version.toString())); +} + int MainWindow::openCamera() { CameraManager *cm = CameraManager::instance(); diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index fe565cbcb460..b30a86768efc 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -33,6 +33,8 @@ public: ~MainWindow(); private: + void setWindowTitle(); + int openCamera(); int startCapture(); From patchwork Thu Jul 4 13:03:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 1606 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 C628861569 for ; Thu, 4 Jul 2019 15:03:52 +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 68DCA24B; Thu, 4 Jul 2019 15:03:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1562245432; bh=lK8GD458CQXK9G4Kv7p20o6wxLv1mGNibXiiEc3regY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FNbSQM2t/8Ft1+A/qCAdDUo16xfq4Lv6eL7R6asCdFQyYl1+eYUCNOH04Sl1Pp8e3 YHtro6hW1dK7V8upzvvHHba9kXSh4l/PYWy6IVXd+NCHr876GbXJsUvLLRo4MQK7Km xHE2J7/I5H1DndVTm4zzeRCtTeNYs1ayYQvNoLfg= From: Kieran Bingham To: LibCamera Devel Date: Thu, 4 Jul 2019 14:03:41 +0100 Message-Id: <20190704130347.9372-4-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 4/4] 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:52 -0000 Provide an average FPS in the QCam title bar to show the current rate of frame processing. Signed-off-by: Kieran Bingham --- 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_; bool isCapturing_; std::unique_ptr config_; + uint64_t firstFrameTime; + uint32_t framesCaptured; ViewFinder *viewfinder_; }; 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],