camera: refactor (add qt_camera_base)
This commit is contained in:
parent
5ebd466869
commit
6e410dcef5
|
@ -13,8 +13,8 @@ add_executable(citra-qt
|
||||||
camera/camera_util.h
|
camera/camera_util.h
|
||||||
camera/still_image_camera.cpp
|
camera/still_image_camera.cpp
|
||||||
camera/still_image_camera.h
|
camera/still_image_camera.h
|
||||||
camera/qt_camera_factory.cpp
|
camera/qt_camera_base.cpp
|
||||||
camera/qt_camera_factory.h
|
camera/qt_camera_base.h
|
||||||
camera/qt_multimedia_camera.cpp
|
camera/qt_multimedia_camera.cpp
|
||||||
camera/qt_multimedia_camera.h
|
camera/qt_multimedia_camera.h
|
||||||
citra-qt.rc
|
citra-qt.rc
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
// Copyright 2018 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include "citra_qt/camera/camera_util.h"
|
||||||
|
#include "citra_qt/camera/qt_camera_base.h"
|
||||||
|
|
||||||
|
namespace Camera {
|
||||||
|
|
||||||
|
QtCameraInterface::QtCameraInterface(const Service::CAM::Flip& flip) {
|
||||||
|
using namespace Service::CAM;
|
||||||
|
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
||||||
|
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtCameraInterface::SetFormat(Service::CAM::OutputFormat output_format) {
|
||||||
|
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtCameraInterface::SetResolution(const Service::CAM::Resolution& resolution) {
|
||||||
|
width = resolution.width;
|
||||||
|
height = resolution.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtCameraInterface::SetFlip(Service::CAM::Flip flip) {
|
||||||
|
using namespace Service::CAM;
|
||||||
|
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
||||||
|
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtCameraInterface::SetEffect(Service::CAM::Effect effect) {
|
||||||
|
if (effect != Service::CAM::Effect::None) {
|
||||||
|
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<u16> QtCameraInterface::ReceiveFrame() {
|
||||||
|
return CameraUtil::ProcessImage(QtReceiveFrame(), width, height, output_rgb, flip_horizontal,
|
||||||
|
flip_vertical);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
||||||
|
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
||||||
|
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
||||||
|
|
||||||
|
if (camera->IsPreviewAvailable()) {
|
||||||
|
return camera;
|
||||||
|
}
|
||||||
|
QMessageBox::critical(
|
||||||
|
nullptr, QObject::tr("Error"),
|
||||||
|
(config.empty() ? QObject::tr("Couldn't load the camera")
|
||||||
|
: QObject::tr("Couldn't load %1").arg(QString::fromStdString(config))));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Camera
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright 2018 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "core/frontend/camera/factory.h"
|
||||||
|
|
||||||
|
namespace Camera {
|
||||||
|
|
||||||
|
// Base class for camera interfaces of citra_qt
|
||||||
|
class QtCameraInterface : public CameraInterface {
|
||||||
|
public:
|
||||||
|
QtCameraInterface(const Service::CAM::Flip& flip);
|
||||||
|
void SetResolution(const Service::CAM::Resolution&) override;
|
||||||
|
void SetFlip(Service::CAM::Flip) override;
|
||||||
|
void SetEffect(Service::CAM::Effect) override;
|
||||||
|
void SetFormat(Service::CAM::OutputFormat) override;
|
||||||
|
std::vector<u16> ReceiveFrame() override;
|
||||||
|
virtual QImage QtReceiveFrame() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int width, height;
|
||||||
|
bool output_rgb;
|
||||||
|
bool flip_horizontal, flip_vertical;
|
||||||
|
bool basic_flip_horizontal, basic_flip_vertical;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Base class for camera factories of citra_qt
|
||||||
|
class QtCameraFactory : public CameraFactory {
|
||||||
|
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
||||||
|
const Service::CAM::Flip& flip) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Camera
|
|
@ -1,24 +0,0 @@
|
||||||
// Copyright 2018 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include "citra_qt/camera/qt_camera_factory.h"
|
|
||||||
|
|
||||||
namespace Camera {
|
|
||||||
|
|
||||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
|
||||||
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
|
||||||
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
|
||||||
|
|
||||||
if (camera->IsPreviewAvailable()) {
|
|
||||||
return camera;
|
|
||||||
}
|
|
||||||
QMessageBox::critical(
|
|
||||||
nullptr, QObject::tr("Error"),
|
|
||||||
(config.empty() ? QObject::tr("Couldn't load the camera")
|
|
||||||
: QObject::tr("Couldn't load %1").arg(QString::fromStdString(config))));
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Camera
|
|
|
@ -1,18 +0,0 @@
|
||||||
// Copyright 2018 Citra Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "core/frontend/camera/factory.h"
|
|
||||||
|
|
||||||
namespace Camera {
|
|
||||||
|
|
||||||
// Base class for camera factories of citra_qt
|
|
||||||
class QtCameraFactory : public CameraFactory {
|
|
||||||
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
|
||||||
const Service::CAM::Flip& flip) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Camera
|
|
|
@ -48,16 +48,13 @@ bool QtCameraSurface::present(const QVideoFrame& frame) {
|
||||||
|
|
||||||
QtMultimediaCamera::QtMultimediaCamera(const std::string& camera_name,
|
QtMultimediaCamera::QtMultimediaCamera(const std::string& camera_name,
|
||||||
const Service::CAM::Flip& flip)
|
const Service::CAM::Flip& flip)
|
||||||
: handler(QtMultimediaCameraHandler::GetHandler()) {
|
: QtCameraInterface(flip), handler(QtMultimediaCameraHandler::GetHandler()) {
|
||||||
if (handler->thread() == QThread::currentThread()) {
|
if (handler->thread() == QThread::currentThread()) {
|
||||||
handler->CreateCamera(camera_name);
|
handler->CreateCamera(camera_name);
|
||||||
} else {
|
} else {
|
||||||
QMetaObject::invokeMethod(handler.get(), "CreateCamera", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(handler.get(), "CreateCamera", Qt::BlockingQueuedConnection,
|
||||||
Q_ARG(const std::string&, camera_name));
|
Q_ARG(const std::string&, camera_name));
|
||||||
}
|
}
|
||||||
using namespace Service::CAM;
|
|
||||||
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
|
||||||
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QtMultimediaCamera::~QtMultimediaCamera() {
|
QtMultimediaCamera::~QtMultimediaCamera() {
|
||||||
|
@ -77,10 +74,6 @@ void QtMultimediaCamera::StopCapture() {
|
||||||
handler->StopCamera();
|
handler->StopCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMultimediaCamera::SetFormat(Service::CAM::OutputFormat output_format) {
|
|
||||||
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtMultimediaCamera::SetFrameRate(Service::CAM::FrameRate frame_rate) {
|
void QtMultimediaCamera::SetFrameRate(Service::CAM::FrameRate frame_rate) {
|
||||||
const std::array<QCamera::FrameRateRange, 13> FrameRateList = {
|
const std::array<QCamera::FrameRateRange, 13> FrameRateList = {
|
||||||
/* Rate_15 */ QCamera::FrameRateRange(15, 15),
|
/* Rate_15 */ QCamera::FrameRateRange(15, 15),
|
||||||
|
@ -104,27 +97,9 @@ void QtMultimediaCamera::SetFrameRate(Service::CAM::FrameRate frame_rate) {
|
||||||
handler->settings.setMinimumFrameRate(framerate.maximumFrameRate);
|
handler->settings.setMinimumFrameRate(framerate.maximumFrameRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QtMultimediaCamera::SetResolution(const Service::CAM::Resolution& resolution) {
|
QImage QtMultimediaCamera::QtReceiveFrame() {
|
||||||
width = resolution.width;
|
|
||||||
height = resolution.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtMultimediaCamera::SetFlip(Service::CAM::Flip flip) {
|
|
||||||
using namespace Service::CAM;
|
|
||||||
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
|
||||||
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QtMultimediaCamera::SetEffect(Service::CAM::Effect effect) {
|
|
||||||
if (effect != Service::CAM::Effect::None) {
|
|
||||||
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<u16> QtMultimediaCamera::ReceiveFrame() {
|
|
||||||
QMutexLocker locker(&handler->camera_surface.mutex);
|
QMutexLocker locker(&handler->camera_surface.mutex);
|
||||||
return CameraUtil::ProcessImage(handler->camera_surface.current_frame, width, height,
|
return handler->camera_surface.current_frame;
|
||||||
output_rgb, flip_horizontal, flip_vertical);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtMultimediaCamera::IsPreviewAvailable() {
|
bool QtMultimediaCamera::IsPreviewAvailable() {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include "citra_qt/camera/camera_util.h"
|
#include "citra_qt/camera/camera_util.h"
|
||||||
#include "citra_qt/camera/qt_camera_factory.h"
|
#include "citra_qt/camera/qt_camera_base.h"
|
||||||
#include "core/frontend/camera/interface.h"
|
#include "core/frontend/camera/interface.h"
|
||||||
|
|
||||||
class GMainWindow;
|
class GMainWindow;
|
||||||
|
@ -36,26 +36,18 @@ private:
|
||||||
class QtMultimediaCameraHandler;
|
class QtMultimediaCameraHandler;
|
||||||
|
|
||||||
/// This class is only an interface. It just calls QtMultimediaCameraHandler.
|
/// This class is only an interface. It just calls QtMultimediaCameraHandler.
|
||||||
class QtMultimediaCamera final : public CameraInterface {
|
class QtMultimediaCamera final : public QtCameraInterface {
|
||||||
public:
|
public:
|
||||||
QtMultimediaCamera(const std::string& camera_name, const Service::CAM::Flip& flip);
|
QtMultimediaCamera(const std::string& camera_name, const Service::CAM::Flip& flip);
|
||||||
~QtMultimediaCamera();
|
~QtMultimediaCamera();
|
||||||
void StartCapture() override;
|
void StartCapture() override;
|
||||||
void StopCapture() override;
|
void StopCapture() override;
|
||||||
void SetResolution(const Service::CAM::Resolution&) override;
|
|
||||||
void SetFlip(Service::CAM::Flip) override;
|
|
||||||
void SetEffect(Service::CAM::Effect) override;
|
|
||||||
void SetFormat(Service::CAM::OutputFormat) override;
|
|
||||||
void SetFrameRate(Service::CAM::FrameRate frame_rate) override;
|
void SetFrameRate(Service::CAM::FrameRate frame_rate) override;
|
||||||
std::vector<u16> ReceiveFrame() override;
|
QImage QtReceiveFrame() override;
|
||||||
bool IsPreviewAvailable() override;
|
bool IsPreviewAvailable() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<QtMultimediaCameraHandler> handler;
|
std::shared_ptr<QtMultimediaCameraHandler> handler;
|
||||||
int width, height;
|
|
||||||
bool output_rgb;
|
|
||||||
bool flip_horizontal, flip_vertical;
|
|
||||||
bool basic_flip_horizontal, basic_flip_vertical;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
||||||
|
|
|
@ -10,40 +10,14 @@
|
||||||
namespace Camera {
|
namespace Camera {
|
||||||
|
|
||||||
StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip)
|
StillImageCamera::StillImageCamera(QImage image_, const Service::CAM::Flip& flip)
|
||||||
: image(std::move(image_)) {
|
: QtCameraInterface(flip), image(std::move(image_)) {}
|
||||||
using namespace Service::CAM;
|
|
||||||
flip_horizontal = basic_flip_horizontal = (flip == Flip::Horizontal) || (flip == Flip::Reverse);
|
|
||||||
flip_vertical = basic_flip_vertical = (flip == Flip::Vertical) || (flip == Flip::Reverse);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StillImageCamera::StartCapture() {}
|
void StillImageCamera::StartCapture() {}
|
||||||
|
|
||||||
void StillImageCamera::StopCapture() {}
|
void StillImageCamera::StopCapture() {}
|
||||||
|
|
||||||
void StillImageCamera::SetFormat(Service::CAM::OutputFormat output_format) {
|
QImage StillImageCamera::QtReceiveFrame() {
|
||||||
output_rgb = output_format == Service::CAM::OutputFormat::RGB565;
|
return image;
|
||||||
}
|
|
||||||
|
|
||||||
void StillImageCamera::SetResolution(const Service::CAM::Resolution& resolution) {
|
|
||||||
width = resolution.width;
|
|
||||||
height = resolution.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StillImageCamera::SetFlip(Service::CAM::Flip flip) {
|
|
||||||
using namespace Service::CAM;
|
|
||||||
flip_horizontal = basic_flip_horizontal ^ (flip == Flip::Horizontal || flip == Flip::Reverse);
|
|
||||||
flip_vertical = basic_flip_vertical ^ (flip == Flip::Vertical || flip == Flip::Reverse);
|
|
||||||
}
|
|
||||||
|
|
||||||
void StillImageCamera::SetEffect(Service::CAM::Effect effect) {
|
|
||||||
if (effect != Service::CAM::Effect::None) {
|
|
||||||
NGLOG_ERROR(Service_CAM, "Unimplemented effect {}", static_cast<int>(effect));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<u16> StillImageCamera::ReceiveFrame() {
|
|
||||||
return CameraUtil::ProcessImage(image, width, height, output_rgb, flip_horizontal,
|
|
||||||
flip_vertical);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StillImageCamera::IsPreviewAvailable() {
|
bool StillImageCamera::IsPreviewAvailable() {
|
||||||
|
|
|
@ -7,30 +7,22 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include "citra_qt/camera/camera_util.h"
|
#include "citra_qt/camera/camera_util.h"
|
||||||
#include "citra_qt/camera/qt_camera_factory.h"
|
#include "citra_qt/camera/qt_camera_base.h"
|
||||||
#include "core/frontend/camera/interface.h"
|
#include "core/frontend/camera/interface.h"
|
||||||
|
|
||||||
namespace Camera {
|
namespace Camera {
|
||||||
|
|
||||||
class StillImageCamera final : public CameraInterface {
|
class StillImageCamera final : public QtCameraInterface {
|
||||||
public:
|
public:
|
||||||
StillImageCamera(QImage image, const Service::CAM::Flip& flip);
|
StillImageCamera(QImage image, const Service::CAM::Flip& flip);
|
||||||
void StartCapture() override;
|
void StartCapture() override;
|
||||||
void StopCapture() override;
|
void StopCapture() override;
|
||||||
void SetResolution(const Service::CAM::Resolution&) override;
|
|
||||||
void SetFlip(Service::CAM::Flip) override;
|
|
||||||
void SetEffect(Service::CAM::Effect) override;
|
|
||||||
void SetFormat(Service::CAM::OutputFormat) override;
|
|
||||||
void SetFrameRate(Service::CAM::FrameRate frame_rate) override {}
|
void SetFrameRate(Service::CAM::FrameRate frame_rate) override {}
|
||||||
std::vector<u16> ReceiveFrame() override;
|
QImage QtReceiveFrame() override;
|
||||||
bool IsPreviewAvailable() override;
|
bool IsPreviewAvailable() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QImage image;
|
QImage image;
|
||||||
int width, height;
|
|
||||||
bool output_rgb;
|
|
||||||
bool flip_horizontal, flip_vertical;
|
|
||||||
bool basic_flip_horizontal, basic_flip_vertical;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StillImageCameraFactory final : public QtCameraFactory {
|
class StillImageCameraFactory final : public QtCameraFactory {
|
||||||
|
|
Reference in New Issue