From d30092a435d287f751b71ff4f2edd956e85dd956 Mon Sep 17 00:00:00 2001 From: baydam Date: Fri, 18 Oct 2019 18:01:59 +0000 Subject: [PATCH] Camera implement improvements --- src/core/CameraImpl.cpp | 4 ++++ src/gui/MainWindow.cpp | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/core/CameraImpl.cpp b/src/core/CameraImpl.cpp index 73076c0..b242920 100644 --- a/src/core/CameraImpl.cpp +++ b/src/core/CameraImpl.cpp @@ -51,6 +51,10 @@ bool CameraImpl::loadMovie(const QString &path) if (_camera->state() == QCamera::ActiveState) return true; + if (_camera->error() != QCamera::NoError) + QMessageBox(QMessageBox::Critical, "Camera Error", + "Failed to start: " + _camera->errorString()).exec(); + return false; } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 13f68f3..d7d43b4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -630,6 +630,9 @@ void MainWindow::importMedia() void MainWindow::openCameraDevice() { #if QT_VERSION >= 0x050300 + // Stop video playback, if it is playing, to avoid lags. XXX Hack + pause(!pauseAction->isVisible()); + QString device; QList cameras = QCameraInfo::availableCameras(); @@ -653,18 +656,25 @@ void MainWindow::openCameraDevice() if (devices.contains(deviceName)) device = devices.value(deviceName); } - } - else if (QCameraInfo::defaultCamera().isNull()) - { - QMessageBox::warning(this, tr("No camera available"), tr("You can not use this feature!\nNo camera available in your system")); } else { - device = QCameraInfo::defaultCamera().deviceName(); + if (QCameraInfo::defaultCamera().isNull()) + { + QMessageBox::warning(this, tr("No camera available"), tr("You can not use this feature!\nNo camera available in your system")); + + } + else + { + device = QCameraInfo::defaultCamera().deviceName(); + } } + // Restart video playback if it was previously playing. XXX Hack + play(!pauseAction->isVisible()); + if (!device.isEmpty()) importMediaFile(device, false, true); #else @@ -2714,12 +2724,11 @@ bool MainWindow::importMediaFile(const QString &fileName, bool isImage, bool isC if (!fileSupported(fileName, isImage)) return false; -// if (fileName.contains(QString("/dev/video"))) { if (isCamera) { type = VIDEO_WEBCAM; } - if (!file.open(QIODevice::ReadOnly)) { + if (!isCamera && !file.open(QIODevice::ReadOnly)) { if (file.isSequential()) { type = VIDEO_SHMSRC; }