[{"id":2127,"web_url":"https://patchwork.libcamera.org/comment/2127/","msgid":"<20190702143149.GC5033@pendragon.ideasonboard.com>","date":"2019-07-02T14:31:49","subject":"Re: [libcamera-devel] [PATCH 4/4] qcam: Update window title with FPS","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Tue, Jul 02, 2019 at 12:48:41PM +0100, Kieran Bingham wrote:\n> Provide an average FPS in the QCam title bar to show the current rate of\n> frame processing.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  src/qcam/main_window.cpp | 23 ++++++++++++++++++++---\n>  src/qcam/main_window.h   |  4 +++-\n>  2 files changed, 23 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp\n> index 61d7aa9469f0..c093bd0c809e 100644\n> --- a/src/qcam/main_window.cpp\n> +++ b/src/qcam/main_window.cpp\n> @@ -26,7 +26,7 @@ MainWindow::MainWindow(const OptionsParser::Options &options)\n>  {\n>  \tint ret;\n>  \n> -\tsetWindowTitle();\n> +\tsetWindowTitle(\"\");\n\nAh now I see why you have added a MainWindow::setWindowTitle() method.\n\n>  \tviewfinder_ = new ViewFinder(this);\n>  \tsetCentralWidget(viewfinder_);\n>  \tviewfinder_->setFixedSize(500, 500);\n> @@ -52,10 +52,11 @@ MainWindow::~MainWindow()\n>  \tCameraManager::instance()->stop();\n>  }\n>  \n> -void MainWindow::setWindowTitle()\n> +void MainWindow::setWindowTitle(QString fps)\n\nHow about passing the fps as a floating point number instead of a\nstring, and doing the conversion internally ? Otherwise you should pass\na const QString &.\n\n>  {\n>  \tQMainWindow::setWindowTitle(\"QCam : \"\n> -\t\t+ QString::fromStdString(libcamera::version.toString()));\n> +\t\t+ QString::fromStdString(libcamera::version.toString())\n> +\t\t+ \" (\" + fps + \")\");\n>  }\n>  \n>  int MainWindow::openCamera()\n> @@ -152,6 +153,9 @@ int MainWindow::startCapture()\n>  \t\trequests.push_back(request);\n>  \t}\n>  \n> +\tfirstFrameTime = 0;\n> +\tframesCaptured = 0;\n> +\n>  \tret = camera_->start();\n>  \tif (ret) {\n>  \t\tstd::cout << \"Failed to start capture\" << std::endl;\n> @@ -215,6 +219,19 @@ void MainWindow::requestComplete(Request *request,\n>  \n>  \tdisplay(buffer);\n>  \n> +\tif (firstFrameTime == 0)\n> +\t\tfirstFrameTime = buffer->timestamp();\n> +\n> +\tuint64_t duration = buffer->timestamp() - firstFrameTime;\n> +\tif (duration)\n> +\t\tfps = framesCaptured * 1000000000.0 / duration;\n> +\telse\n> +\t\tfps = 0.0;\n> +\n> +\tsetWindowTitle(QString::number(fps, 'f', 2) + \" fps\");\n\nI think we should update the title for every frame, but only\nperiodically (x times per second, which doesn't require a timer but can\nsimply use a difference between the current timestamp and the last\nupdate timestamp here). Otherwise it would flash a bit too fast to be\nreally readable.\n\nI think you should also compute the fps using a moving average instead\nof an average since the beginning of the stream, as the latter isn't\nthat meaningful.\n\n> +\n> +\tframesCaptured++;\n> +\n>  \trequest = camera_->createRequest();\n>  \tif (!request) {\n>  \t\tstd::cerr << \"Can't create request\" << std::endl;\n> diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h\n> index b30a86768efc..792f89c2d831 100644\n> --- a/src/qcam/main_window.h\n> +++ b/src/qcam/main_window.h\n> @@ -33,7 +33,7 @@ public:\n>  \t~MainWindow();\n>  \n>  private:\n> -\tvoid setWindowTitle();\n> +\tvoid setWindowTitle(QString info);\n\nYou have name the parameter fps above.\n\n>  \n>  \tint openCamera();\n>  \n> @@ -49,6 +49,8 @@ private:\n>  \tstd::shared_ptr<Camera> camera_;\n>  \tbool isCapturing_;\n>  \tstd::unique_ptr<CameraConfiguration> config_;\n> +\tuint64_t firstFrameTime;\n> +\tuint32_t framesCaptured;\n>  \n>  \tViewFinder *viewfinder_;\n>  };","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 09D0960B10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Jul 2019 16:32:09 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 841C6524;\n\tTue,  2 Jul 2019 16:32:08 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1562077928;\n\tbh=KsYXbVEgPkcpyAqM2wn3fOO0E7jwcH21q9K6e4hyiy8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=TkI3gi+HXo2/M4nc8o2nMzi6btwG1Zi+oFtGN8BrGZnsCeJmo/KpnVZtbvWdkca8K\n\tHdmRBmlfp46LdRqgpBVbFm70e3dtQJQSdbcqIJDjTXBJSMvJxBmPtmzTxH9lRX7gRo\n\tNXS7JiWzuWxrUAgdHX6ZUSMaRPuxKZ46aBbRy04Y=","Date":"Tue, 2 Jul 2019 17:31:49 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"LibCamera Devel <libcamera-devel@lists.libcamera.org>","Message-ID":"<20190702143149.GC5033@pendragon.ideasonboard.com>","References":"<20190702114841.19101-1-kieran.bingham@ideasonboard.com>\n\t<20190702114841.19101-4-kieran.bingham@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20190702114841.19101-4-kieran.bingham@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 02 Jul 2019 14:32:09 -0000"}}]