diff --git a/uvcengine/uvccameraexposurecontrol.cpp b/uvcengine/uvccameraexposurecontrol.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0fb1117a1b2034cc316e591cf5c57dee47d68943 --- /dev/null +++ b/uvcengine/uvccameraexposurecontrol.cpp @@ -0,0 +1,41 @@ +#include "uvccameraexposurecontrol.h" +#include "uvccamerasession.h" + +QT_BEGIN_NAMESPACE + +UVCCameraExposureControl::UVCCameraExposureControl(UVCCameraSession *session) + : QCameraExposureControl(session) + , m_session(session) +{ +} + +UVCCameraExposureControl::~UVCCameraExposureControl() +{ +} + +QVariant UVCCameraExposureControl::actualValue(ExposureParameter parameter) const +{ + return m_session->actualExposureValue(parameter); +} + +bool UVCCameraExposureControl::isParameterSupported(ExposureParameter parameter) const +{ + return m_session->isExposureParameterSupported(parameter); +} + +QVariant UVCCameraExposureControl::requestedValue(ExposureParameter parameter) const +{ + return m_session->requestedExposureValue(parameter); +} + +bool UVCCameraExposureControl::setValue(ExposureParameter parameter, const QVariant &value) +{ + return m_session->setExposureValue(parameter, value); +} + +QVariantList UVCCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous) const +{ + return m_session->supportedExposureParameterRange(parameter, continuous); +} + +QT_END_NAMESPACE diff --git a/uvcengine/uvccameraexposurecontrol.h b/uvcengine/uvccameraexposurecontrol.h new file mode 100644 index 0000000000000000000000000000000000000000..c7b81ff2c489c0be076d49aea5c6f245314aae31 --- /dev/null +++ b/uvcengine/uvccameraexposurecontrol.h @@ -0,0 +1,31 @@ +#ifndef UVCCAMERAEXPOSURECONTROL_H +#define UVCCAMERAEXPOSURECONTROL_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class UVCCameraSession; + +class UVCCameraExposureControl : public QCameraExposureControl +{ + Q_OBJECT + +public: + UVCCameraExposureControl(UVCCameraSession *session); + virtual ~UVCCameraExposureControl(); + + QVariant actualValue(ExposureParameter parameter) const; + bool isParameterSupported(ExposureParameter parameter) const; + QVariant requestedValue(ExposureParameter parameter) const; + bool setValue(ExposureParameter parameter, const QVariant &value); + QVariantList supportedParameterRange(ExposureParameter parameter, bool *continuous) const; + +private: + UVCCameraSession *m_session; +}; + +QT_END_NAMESPACE + +#endif // UVCCAMERAEXPOSURECONTROL_H diff --git a/uvcengine/uvccameraservice.cpp b/uvcengine/uvccameraservice.cpp index 6986b440ffc6e3899b267d4410be8d276443f181..74effe2ba76145164a37bf685fbd1a8d50930a90 100644 --- a/uvcengine/uvccameraservice.cpp +++ b/uvcengine/uvccameraservice.cpp @@ -8,6 +8,7 @@ #include "uvcvideorenderercontrol.h" #include "uvccameraviewfindersettingscontrol.h" #include "uvccameraimageprocessingcontrol.h" +#include "uvccameraexposurecontrol.h" QT_BEGIN_NAMESPACE @@ -20,6 +21,7 @@ UVCCameraService::UVCCameraService(QObject *parent): m_videoDevice = new UVCVideoDeviceControl(m_session); m_viewfinderSettings = new UVCCameraViewfinderSettingsControl(m_session); m_imageProcessingControl = new UVCCameraImageProcessingControl(m_session); + m_cameraExposureControl = new UVCCameraExposureControl(m_session); } UVCCameraService::~UVCCameraService() @@ -28,7 +30,11 @@ UVCCameraService::~UVCCameraService() delete m_viewfinderSettings; delete m_videoDevice; delete m_videoRenderer; - delete m_session; + delete m_imageProcessingControl; + delete m_cameraExposureControl; + + // session must be last since it's used by the rest + delete m_session; } QMediaControl* UVCCameraService::requestControl(const char *name) @@ -52,6 +58,9 @@ QMediaControl* UVCCameraService::requestControl(const char *name) if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0) return m_imageProcessingControl; + if (qstrcmp(name, QCameraExposureControl_iid) == 0) + return m_cameraExposureControl; + return NULL; } diff --git a/uvcengine/uvccameraservice.h b/uvcengine/uvccameraservice.h index e67aca32a81739a7da1c522a30c41c5329477368..1aff1c0ddab2dd73804f4fd90d67e7b270321c6f 100644 --- a/uvcengine/uvccameraservice.h +++ b/uvcengine/uvccameraservice.h @@ -12,6 +12,7 @@ class UVCVideoDeviceControl; class UVCVideoRendererControl; class UVCCameraViewfinderSettingsControl; class UVCCameraImageProcessingControl; +class UVCCameraExposureControl; class UVCCameraService : public QMediaService { @@ -30,6 +31,7 @@ private: UVCVideoRendererControl *m_videoRenderer; UVCCameraViewfinderSettingsControl *m_viewfinderSettings; UVCCameraImageProcessingControl *m_imageProcessingControl; + UVCCameraExposureControl *m_cameraExposureControl; }; QT_END_NAMESPACE diff --git a/uvcengine/uvccamerasession.cpp b/uvcengine/uvccamerasession.cpp index 830bb91e73cc6ce17ec155413b223970b45bf348..dd38ce2cc46e635fcb72b4c4b3567e8d20246f47 100644 --- a/uvcengine/uvccamerasession.cpp +++ b/uvcengine/uvccamerasession.cpp @@ -191,6 +191,7 @@ bool UVCCameraSession::load() uint32_t exposure_abs; + /* // If we didn't have settings, create with default values; otherwise read and set if ( !hasSettings ) { qDebug() << uvcSettingsFile.absoluteFilePath() << "not found. Generating..."; @@ -272,6 +273,7 @@ bool UVCCameraSession::load() uvc_set_contrast(devh, contrast); } + */ settings->deleteLater(); @@ -475,12 +477,15 @@ void UVCCameraSession::release(const QString &device) bool UVCCameraSession::isImageProcessingParameterSupported( QCameraImageProcessingControl::ProcessingParameter parameter) const { // TODO + Q_UNUSED(parameter); return false; } bool UVCCameraSession::isImageProcessingParameterValueSupported( QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value) const { // TODO + Q_UNUSED(parameter); + Q_UNUSED(value); return false; } @@ -528,3 +533,76 @@ void UVCCameraSession::setImageProcessingParameter( QCameraImageProcessingContro } return; } + +QVariant UVCCameraSession::actualExposureValue(QCameraExposureControl::ExposureParameter parameter) const +{ + switch (parameter) { + case QCameraExposureControl::ExposureMode: + uint8_t mode; + uvc_get_ae_mode(devh, &mode, UVC_GET_CUR); + switch (mode) { + case 1: + return QCameraExposure::ExposureManual; + case 2: + return QCameraExposure::ExposureAuto; + default: + return QVariant(); + } + break; + + case QCameraExposureControl::Aperture: + return uvc_get(devh, uvc_get_exposure_abs); + + default: + qWarning() << parameter << "not supported"; + } +} + +bool UVCCameraSession::isExposureParameterSupported(QCameraExposureControl::ExposureParameter parameter) const +{ + return false; +} + +QVariant UVCCameraSession::requestedExposureValue(QCameraExposureControl::ExposureParameter parameter) const +{ + return QVariant(); +} + +bool UVCCameraSession::setExposureValue(QCameraExposureControl::ExposureParameter parameter, const QVariant &value) +{ + switch (parameter) { + case QCameraExposureControl::ExposureMode: { + QCameraExposure::ExposureMode mode = value.value(); + switch (mode) { + case QCameraExposure::ExposureManual: + uvc_set_ae_mode(devh, 1); + uvc_set_ae_priority(devh, 0); + break; + case QCameraExposure::ExposureAuto: + uvc_set_ae_mode(devh, 2); + uvc_set_ae_priority(devh, 0); + break; + default: + qWarning() << mode << "not supported"; + } + if (actualExposureValue(parameter) != mode) + qWarning() << "Failed to set mode" << mode; + break; + } + + case QCameraExposureControl::Aperture: { + uvc_set(devh, uvc_set_exposure_abs, value, uvc_get_exposure_abs); + break; + } + + default: + qWarning() << parameter << "not supported"; + } + + return false; +} + +QVariantList UVCCameraSession::supportedExposureParameterRange(QCameraExposureControl::ExposureParameter parameter, bool *continuous) const +{ + return QVariantList(); +} diff --git a/uvcengine/uvccamerasession.h b/uvcengine/uvccamerasession.h index 667d15c6cfa583ccd498d0175bd21db5258935f1..45c3c74882826c22e820071098ed3545a955a2b9 100644 --- a/uvcengine/uvccamerasession.h +++ b/uvcengine/uvccamerasession.h @@ -82,6 +82,7 @@ public: set(devh, static_cast(value)); } + // Image Processing bool isImageProcessingParameterSupported(QCameraImageProcessingControl::ProcessingParameter parameter) const; bool isImageProcessingParameterValueSupported(QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value) const; @@ -89,6 +90,13 @@ public: void setImageProcessingParameter(QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value); + // Exposure + QVariant actualExposureValue(QCameraExposureControl::ExposureParameter parameter) const; + bool isExposureParameterSupported(QCameraExposureControl::ExposureParameter parameter) const; + QVariant requestedExposureValue(QCameraExposureControl::ExposureParameter parameter) const; + bool setExposureValue(QCameraExposureControl::ExposureParameter parameter, const QVariant &value); + QVariantList supportedExposureParameterRange(QCameraExposureControl::ExposureParameter parameter, bool *continuous) const; + private Q_SLOTS: void presentFrame(QVideoFrame frame, const qreal t); diff --git a/uvcengine/uvcengine.pro b/uvcengine/uvcengine.pro index dc5f0fb87a924b20cc7bed253aef819057b61bd1..9c2cea383219c30fa7626304a89a61efd46dccba 100644 --- a/uvcengine/uvcengine.pro +++ b/uvcengine/uvcengine.pro @@ -11,6 +11,7 @@ QT += core gui multimedia TARGET = uvcengine TEMPLATE = lib CONFIG += plugin +CONFIG += force_debug_info DESTDIR = $$[QT_INSTALL_PLUGINS]/mediaservice @@ -21,7 +22,8 @@ SOURCES += uvcserviceplugin.cpp \ uvccamerasession.cpp \ uvcvideorenderercontrol.cpp \ uvccameraviewfindersettingscontrol.cpp \ - uvccameraimageprocessingcontrol.cpp + uvccameraimageprocessingcontrol.cpp \ + uvccameraexposurecontrol.cpp HEADERS += uvcserviceplugin.h \ uvccameraservice.h \ @@ -30,7 +32,8 @@ HEADERS += uvcserviceplugin.h \ uvccamerasession.h \ uvcvideorenderercontrol.h \ uvccameraviewfindersettingscontrol.h \ - uvccameraimageprocessingcontrol.h + uvccameraimageprocessingcontrol.h \ + uvccameraexposurecontrol.h DISTFILES += uvcengine.json unix {