Message ID | 20190702114841.19101-4-kieran.bingham@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
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@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_; > };
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> camera_; bool isCapturing_; std::unique_ptr<CameraConfiguration> config_; + uint64_t firstFrameTime; + uint32_t framesCaptured; ViewFinder *viewfinder_; };
Provide an average FPS in the QCam title bar to show the current rate of frame processing. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> --- src/qcam/main_window.cpp | 23 ++++++++++++++++++++--- src/qcam/main_window.h | 4 +++- 2 files changed, 23 insertions(+), 4 deletions(-)