From patchwork Mon Mar 23 17:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3278 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A92962C75 for ; Mon, 23 Mar 2020 18:36:20 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A94D308 for ; Mon, 23 Mar 2020 18:36:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584984980; bh=XyKVwKMcUtSXSHJwN6mAV5phrTcamQLSPcFS0Hb5rvo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VaRKsJdQTIKVigtz+bHEpFkGF6MnBLB6DZDX8NcZfsqVdTCpwMTad7Mky5trRQ58O psaORePr4Pp9HaoHsLDW+jPSeryXrlf1EZQ2qOhlkJqTRc70RlYAqRtMhHLNbzbRru OUs/fF7BIi3WwV+nr4UpxB4rACxDWAO7xUKSU5Ec= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 19:35:50 +0200 Message-Id: <20200323173559.21109-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> References: <20200323173559.21109-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/21] qcam: Use Qt qInfo() and qWarning() logging facilities X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2020 17:36:26 -0000 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 Reviewed-by: Kieran Bingham --- Changes since v1: - Fix compilation on Qt 5.12 --- 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 #include #include #include +#include #include @@ -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 c0d42c64749c..cb8f769e9bb8 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -8,7 +8,6 @@ #include "main_window.h" #include -#include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include @@ -179,11 +179,11 @@ void MainWindow::switchCamera(int index) const std::shared_ptr &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 @@ -238,13 +238,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; } @@ -300,18 +299,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; } @@ -320,7 +319,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; } @@ -330,7 +329,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; } @@ -338,14 +337,14 @@ int MainWindow::startCapture() for (const std::unique_ptr &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; } @@ -368,7 +367,7 @@ int MainWindow::startCapture() ret = camera_->start(); if (ret) { - std::cout << "Failed to start capture" << std::endl; + qInfo() << "Failed to start capture"; goto error; } @@ -378,7 +377,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; } } @@ -421,7 +420,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); @@ -518,11 +517,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 << reset + << "bytesused:" << metadata.planes[0].bytesused + << "timestamp:" << metadata.timestamp + << "fps:" << fixed << qSetRealNumberPrecision(2) << fps; /* Display the buffer and requeue it to the camera. */ display(buffer); @@ -547,7 +546,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; }