[libcamera-devel] [PATCH 12/21] qcam: Use Qt qInfo() and qWarning() logging facilities
Kieran Bingham
kieran.bingham at ideasonboard.com
Mon Mar 23 16:55:42 CET 2020
Hi Laurent,
On 23/03/2020 14:21, Laurent Pinchart wrote:
> Replace manual usage of std::cout and std::cerr with the Qt logging
> facilities. This allows redirection log output if needed, and integrates
> better with Qt.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
With the compile issues fixed...
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
> src/qcam/main.cpp | 8 +++----
> src/qcam/main_window.cpp | 45 ++++++++++++++++++++--------------------
> 2 files changed, 26 insertions(+), 27 deletions(-)
>
> diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
> index 297453914ae9..862d714f467c 100644
> --- a/src/qcam/main.cpp
> +++ b/src/qcam/main.cpp
> @@ -5,11 +5,11 @@
> * main.cpp - cam - The libcamera swiss army knife
> */
>
> -#include <iostream>
> #include <signal.h>
> #include <string.h>
>
> #include <QApplication>
> +#include <QtDebug>
>
> #include <libcamera/camera_manager.h>
>
> @@ -18,7 +18,7 @@
>
> void signalHandler(int signal)
> {
> - std::cout << "Exiting" << std::endl;
> + qInfo() << "Exiting";
> qApp->quit();
> }
>
> @@ -65,8 +65,8 @@ int main(int argc, char **argv)
>
> ret = cm->start();
> if (ret) {
> - std::cout << "Failed to start camera manager: "
> - << strerror(-ret) << std::endl;
> + qInfo() << "Failed to start camera manager:"
> + << strerror(-ret);
> return EXIT_FAILURE;
> }
>
> diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
> index ed8301502fb2..184345b0e2a6 100644
> --- a/src/qcam/main_window.cpp
> +++ b/src/qcam/main_window.cpp
> @@ -8,7 +8,6 @@
> #include "main_window.h"
>
> #include <iomanip>
> -#include <iostream>
> #include <string>
> #include <sys/mman.h>
>
> @@ -24,6 +23,7 @@
> #include <QTimer>
> #include <QToolBar>
> #include <QToolButton>
> +#include <QtDebug>
>
> #include <libcamera/camera_manager.h>
> #include <libcamera/version.h>
> @@ -177,11 +177,11 @@ void MainWindow::switchCamera(int index)
> const std::shared_ptr<Camera> &cam = cameras[index];
>
> if (cam->acquire()) {
> - std::cout << "Failed to acquire camera " << cam->name() << std::endl;
> + qInfo() << "Failed to acquire camera" << cam->name().c_str();
> return;
> }
>
> - std::cout << "Switching to camera " << cam->name() << std::endl;
> + qInfo() << "Switching to camera" << cam->name().c_str();
>
> /*
> * Stop the capture session, release the current camera, replace it with
> @@ -236,13 +236,12 @@ int MainWindow::openCamera()
> /* Get and acquire the camera. */
> camera_ = cm_->get(cameraName);
> if (!camera_) {
> - std::cout << "Camera " << cameraName << " not found"
> - << std::endl;
> + qInfo() << "Camera" << cameraName.c_str() << "not found";
> return -ENODEV;
> }
>
> if (camera_->acquire()) {
> - std::cout << "Failed to acquire camera" << std::endl;
> + qInfo() << "Failed to acquire camera";
> camera_.reset();
> return -EBUSY;
> }
> @@ -296,18 +295,18 @@ int MainWindow::startCapture()
>
> CameraConfiguration::Status validation = config_->validate();
> if (validation == CameraConfiguration::Invalid) {
> - std::cerr << "Failed to create valid camera configuration";
> + qWarning() << "Failed to create valid camera configuration";
> return -EINVAL;
> }
>
> if (validation == CameraConfiguration::Adjusted) {
> - std::cout << "Stream size adjusted to "
> - << cfg.size.toString() << std::endl;
> + qInfo() << "Stream size adjusted to"
> + << cfg.size.toString().c_str();
> }
>
> ret = camera_->configure(config_.get());
> if (ret < 0) {
> - std::cout << "Failed to configure camera" << std::endl;
> + qInfo() << "Failed to configure camera";
> return ret;
> }
>
> @@ -316,7 +315,7 @@ int MainWindow::startCapture()
> ret = viewfinder_->setFormat(cfg.pixelFormat,
> QSize(cfg.size.width, cfg.size.height));
> if (ret < 0) {
> - std::cout << "Failed to set viewfinder format" << std::endl;
> + qInfo() << "Failed to set viewfinder format";
> return ret;
> }
>
> @@ -326,7 +325,7 @@ int MainWindow::startCapture()
> allocator_ = new FrameBufferAllocator(camera_);
> ret = allocator_->allocate(stream);
> if (ret < 0) {
> - std::cerr << "Failed to allocate capture buffers" << std::endl;
> + qWarning() << "Failed to allocate capture buffers";
> return ret;
> }
>
> @@ -334,14 +333,14 @@ int MainWindow::startCapture()
> for (const std::unique_ptr<FrameBuffer> &buffer : allocator_->buffers(stream)) {
> Request *request = camera_->createRequest();
> if (!request) {
> - std::cerr << "Can't create request" << std::endl;
> + qWarning() << "Can't create request";
> ret = -ENOMEM;
> goto error;
> }
>
> ret = request->addBuffer(stream, buffer.get());
> if (ret < 0) {
> - std::cerr << "Can't set buffer for request" << std::endl;
> + qWarning() << "Can't set buffer for request";
> goto error;
> }
>
> @@ -364,7 +363,7 @@ int MainWindow::startCapture()
>
> ret = camera_->start();
> if (ret) {
> - std::cout << "Failed to start capture" << std::endl;
> + qInfo() << "Failed to start capture";
> goto error;
> }
>
> @@ -374,7 +373,7 @@ int MainWindow::startCapture()
> for (Request *request : requests) {
> ret = camera_->queueRequest(request);
> if (ret < 0) {
> - std::cerr << "Can't queue request" << std::endl;
> + qWarning() << "Can't queue request";
> goto error_disconnect;
> }
> }
> @@ -417,7 +416,7 @@ void MainWindow::stopCapture()
>
> int ret = camera_->stop();
> if (ret)
> - std::cout << "Failed to stop capture" << std::endl;
> + qInfo() << "Failed to stop capture";
>
> camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);
>
> @@ -513,11 +512,11 @@ void MainWindow::processCapture()
> fps = lastBufferTime_ && fps ? 1000000000.0 / fps : 0.0;
> lastBufferTime_ = metadata.timestamp;
>
> - std::cout << "seq: " << std::setw(6) << std::setfill('0') << metadata.sequence
> - << " bytesused: " << metadata.planes[0].bytesused
> - << " timestamp: " << metadata.timestamp
> - << " fps: " << std::fixed << std::setprecision(2) << fps
> - << std::endl;
> + qInfo() << "seq:" << qSetFieldWidth(6) << qSetPadChar('0')
> + << metadata.sequence << Qt::reset
> + << "bytesused:" << metadata.planes[0].bytesused
> + << "timestamp:" << metadata.timestamp
> + << "fps:" << Qt::fixed << qSetRealNumberPrecision(2) << fps;
>
> /* Display the buffer and requeue it to the camera. */
> display(buffer);
> @@ -542,7 +541,7 @@ void MainWindow::queueRequest(FrameBuffer *buffer)
> {
> Request *request = camera_->createRequest();
> if (!request) {
> - std::cerr << "Can't create request" << std::endl;
> + qWarning() << "Can't create request";
> return;
> }
>
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list