From 081b9028e4dfda2968b1d4744b9bf3db322b4f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Fri, 12 Apr 2019 16:14:11 +0300 Subject: [PATCH 01/24] [Settings] (bug_fix) Fixed crashing when no camera is attached. --- src/video/camerafilter.cpp | 4 +-- src/video/camerainfo.cpp | 56 ++++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/video/camerafilter.cpp b/src/video/camerafilter.cpp index 55afd5be..4497de71 100644 --- a/src/video/camerafilter.cpp +++ b/src/video/camerafilter.cpp @@ -13,7 +13,7 @@ CameraFilter::CameraFilter(QString id, StatisticsInterface *stats): Filter(id, "Camera", stats, NONE, RGB32VIDEO), - camera_(), + camera_(nullptr), cameraFrameGrabber_(), framerate_(0) {} @@ -176,7 +176,7 @@ bool CameraFilter::cameraSetup() void CameraFilter::stop() { - if(camera_->state() == QCamera::ActiveState) + if(camera_ && camera_->state() == QCamera::ActiveState) { camera_->stop(); } diff --git a/src/video/camerainfo.cpp b/src/video/camerainfo.cpp index 7c00eadd..3d3895e7 100644 --- a/src/video/camerainfo.cpp +++ b/src/video/camerainfo.cpp @@ -66,13 +66,15 @@ void CameraInfo::getVideoFormats(int deviceID, QStringList& formats) formats.clear(); std::unique_ptr camera = loadCamera(deviceID); - - QList p_formats = camera->supportedViewfinderPixelFormats(); - qDebug() << "Settings, CameraInfo : Found" << p_formats.size() << "formats for deviceID:" << deviceID; - - for(int i = 0; i < p_formats.size() ; ++i) + if (camera != nullptr) { - formats.push_back(pixelFormatStrings.at(p_formats.at(i))); + QList p_formats = camera->supportedViewfinderPixelFormats(); + qDebug() << "Settings, CameraInfo : Found" << p_formats.size() << "formats for deviceID:" << deviceID; + + for(int i = 0; i < p_formats.size() ; ++i) + { + formats.push_back(pixelFormatStrings.at(p_formats.at(i))); + } } } @@ -86,13 +88,16 @@ void CameraInfo::getFormatResolutions(int deviceID, QString format, QStringList std::unique_ptr camera = loadCamera(deviceID); - QList supporteResolutions = camera->supportedViewfinderResolutions(viewSettings); - qDebug() << "Settings, CameraInfo : Found" << supporteResolutions.size() << "resolutions for deviceID:" << deviceID; - - for (int i = 0; i < supporteResolutions.size(); ++i) + if (camera != nullptr) { - resolutions.push_back(QString::number(supporteResolutions[i].width()) + "x" + - QString::number(supporteResolutions[i].height())); + QList supporteResolutions = camera->supportedViewfinderResolutions(viewSettings); + qDebug() << "Settings, CameraInfo : Found" << supporteResolutions.size() << "resolutions for deviceID:" << deviceID; + + for (int i = 0; i < supporteResolutions.size(); ++i) + { + resolutions.push_back(QString::number(supporteResolutions[i].width()) + "x" + + QString::number(supporteResolutions[i].height())); + } } } @@ -131,6 +136,7 @@ std::unique_ptr CameraInfo::loadCamera(int deviceID) if(deviceID == -1 || deviceID >= cameras.size()) { qDebug() << "ERROR: Invalid deviceID for getVideoCapabilities"; + return std::unique_ptr (nullptr); } std::unique_ptr camera @@ -163,19 +169,21 @@ QVideoFrame::PixelFormat CameraInfo::stringToPixelFormat(QString format) QSize CameraInfo::getResolution(int deviceID, int formatID, int resolutionID) { std::unique_ptr camera = loadCamera(deviceID); - - QString format = getFormat(deviceID, formatID); - QCameraViewfinderSettings viewSettings; - viewSettings.setPixelFormat(stringToPixelFormat(format)); - QList supporteResolutions = camera->supportedViewfinderResolutions(viewSettings); - - if(supporteResolutions.size() > resolutionID) - { - return supporteResolutions.at(resolutionID); - } - else if(!supporteResolutions.empty()) + if (camera != nullptr) { - supporteResolutions.at(0); + QString format = getFormat(deviceID, formatID); + QCameraViewfinderSettings viewSettings; + viewSettings.setPixelFormat(stringToPixelFormat(format)); + QList supporteResolutions = camera->supportedViewfinderResolutions(viewSettings); + + if(supporteResolutions.size() > resolutionID) + { + return supporteResolutions.at(resolutionID); + } + else if(!supporteResolutions.empty()) + { + supporteResolutions.at(0); + } } return QSize(0,0); From 7484608fb7ed840fa5fefb8909bb78cd52002fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joni=20R=C3=A4s=C3=A4nen?= Date: Tue, 16 Apr 2019 15:11:13 +0300 Subject: [PATCH 02/24] [Settings] (bug_fix) Linux compatible ui filepath. --- src/gui/customsettings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/customsettings.cpp b/src/gui/customsettings.cpp index 7dfbbe11..1dcbce83 100644 --- a/src/gui/customsettings.cpp +++ b/src/gui/customsettings.cpp @@ -1,6 +1,6 @@ #include "customsettings.h" -#include "ui_customsettings.h" +#include "ui_customSettings.h" #include