summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-23 01:53:41 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-03-24 10:33:59 +0200
commit494da4467ddf091d457863cd363067979552d67e (patch)
treed41b9a767423a94adbbb53e6cb64eb7151127eac /src/qcam
parent9cec54a4ee90617ce3f01875961a2afb1588f300 (diff)
qcam: Use Qt qInfo() and qWarning() logging facilities
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@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/main.cpp8
-rw-r--r--src/qcam/main_window.cpp45
2 files changed, 26 insertions, 27 deletions
diff --git a/src/qcam/main.cpp b/src/qcam/main.cpp
index 29745391..862d714f 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 c0d42c64..cb8f769e 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>
@@ -23,6 +22,7 @@
#include <QTimer>
#include <QToolBar>
#include <QToolButton>
+#include <QtDebug>
#include <libcamera/camera_manager.h>
#include <libcamera/version.h>
@@ -179,11 +179,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
@@ -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<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;
}
@@ -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;
}