Commit 96f94e6b authored by Thiago Santini's avatar Thiago Santini

Adds exposure option

parent 98ac2765
#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
#ifndef UVCCAMERAEXPOSURECONTROL_H
#define UVCCAMERAEXPOSURECONTROL_H
#include <qcamera.h>
#include <qcameraexposurecontrol.h>
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
......@@ -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,6 +30,10 @@ UVCCameraService::~UVCCameraService()
delete m_viewfinderSettings;
delete m_videoDevice;
delete m_videoRenderer;
delete m_imageProcessingControl;
delete m_cameraExposureControl;
// session must be last since it's used by the rest
delete m_session;
}
......@@ -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;
}
......
......@@ -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
......
......@@ -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<QCameraExposure::ExposureMode>();
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();
}
......@@ -82,6 +82,7 @@ public:
set(devh, static_cast<T>(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);
......
......@@ -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 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment