Commit 98ac2765 authored by Thiago Santini's avatar Thiago Santini

Starts camera parameter access implementation

parent 4c296197
#include "uvccameraimageprocessingcontrol.h"
#include "uvccamerasession.h"
QT_BEGIN_NAMESPACE
UVCCameraImageProcessingControl::UVCCameraImageProcessingControl(UVCCameraSession *session)
: QCameraImageProcessingControl(session)
, m_session(session)
{
}
UVCCameraImageProcessingControl::~UVCCameraImageProcessingControl()
{
}
bool UVCCameraImageProcessingControl::isParameterSupported(
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
return m_session->isImageProcessingParameterSupported(parameter);
}
bool UVCCameraImageProcessingControl::isParameterValueSupported(
QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value) const
{
return m_session->isImageProcessingParameterValueSupported(parameter, value);
}
QVariant UVCCameraImageProcessingControl::parameter(
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
return m_session->imageProcessingParameter(parameter);
}
void UVCCameraImageProcessingControl::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value)
{
m_session->setImageProcessingParameter(parameter, value);
}
QT_END_NAMESPACE
#ifndef UVCCAMERAIMAGEPROCESSINGCONTROL_H
#define UVCCAMERAIMAGEPROCESSINGCONTROL_H
#include <qcamera.h>
#include <qcameraimageprocessingcontrol.h>
QT_BEGIN_NAMESPACE
class UVCCameraSession;
class UVCCameraImageProcessingControl : public QCameraImageProcessingControl
{
Q_OBJECT
public:
UVCCameraImageProcessingControl(UVCCameraSession *session);
virtual ~UVCCameraImageProcessingControl();
bool isParameterSupported(ProcessingParameter) const;
bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const;
QVariant parameter(ProcessingParameter parameter) const;
void setParameter(ProcessingParameter parameter, const QVariant &value);
private:
UVCCameraSession *m_session;
};
QT_END_NAMESPACE
#endif // UVCCAMERAIMAGEPROCESSINGCONTROL_H
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/qvariant.h> #include <QtCore/qvariant.h>
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
...@@ -46,6 +7,7 @@ ...@@ -46,6 +7,7 @@
#include "uvcvideodevicecontrol.h" #include "uvcvideodevicecontrol.h"
#include "uvcvideorenderercontrol.h" #include "uvcvideorenderercontrol.h"
#include "uvccameraviewfindersettingscontrol.h" #include "uvccameraviewfindersettingscontrol.h"
#include "uvccameraimageprocessingcontrol.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
...@@ -56,7 +18,8 @@ UVCCameraService::UVCCameraService(QObject *parent): ...@@ -56,7 +18,8 @@ UVCCameraService::UVCCameraService(QObject *parent):
m_session = new UVCCameraSession(this); m_session = new UVCCameraSession(this);
m_control = new UVCCameraControl(m_session); m_control = new UVCCameraControl(m_session);
m_videoDevice = new UVCVideoDeviceControl(m_session); m_videoDevice = new UVCVideoDeviceControl(m_session);
m_viewfinderSettings = new UVCCameraViewfinderSettingsControl(m_session); m_viewfinderSettings = new UVCCameraViewfinderSettingsControl(m_session);
m_imageProcessingControl = new UVCCameraImageProcessingControl(m_session);
} }
UVCCameraService::~UVCCameraService() UVCCameraService::~UVCCameraService()
...@@ -86,9 +49,9 @@ QMediaControl* UVCCameraService::requestControl(const char *name) ...@@ -86,9 +49,9 @@ QMediaControl* UVCCameraService::requestControl(const char *name)
if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0) if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
return m_viewfinderSettings; return m_viewfinderSettings;
// if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0) if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
// return m_imageProcessingControl; return m_imageProcessingControl;
//
return NULL; return NULL;
} }
......
/**************************************************************************** #ifndef UVCCAMERASERVICE_H
** #define UVCCAMERASERVICE_H
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef DSCAMERASERVICE_H
#define DSCAMERASERVICE_H
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtMultimedia/QMediaService> #include <QtMultimedia/QMediaService>
...@@ -50,6 +11,7 @@ class UVCCameraSession; ...@@ -50,6 +11,7 @@ class UVCCameraSession;
class UVCVideoDeviceControl; class UVCVideoDeviceControl;
class UVCVideoRendererControl; class UVCVideoRendererControl;
class UVCCameraViewfinderSettingsControl; class UVCCameraViewfinderSettingsControl;
class UVCCameraImageProcessingControl;
class UVCCameraService : public QMediaService class UVCCameraService : public QMediaService
{ {
...@@ -66,7 +28,8 @@ private: ...@@ -66,7 +28,8 @@ private:
UVCCameraSession *m_session; UVCCameraSession *m_session;
UVCVideoDeviceControl *m_videoDevice; UVCVideoDeviceControl *m_videoDevice;
UVCVideoRendererControl *m_videoRenderer; UVCVideoRendererControl *m_videoRenderer;
UVCCameraViewfinderSettingsControl *m_viewfinderSettings; UVCCameraViewfinderSettingsControl *m_viewfinderSettings;
UVCCameraImageProcessingControl *m_imageProcessingControl;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -170,6 +170,12 @@ bool UVCCameraSession::load() ...@@ -170,6 +170,12 @@ bool UVCCameraSession::load()
} }
*/ */
QSettings *settings;
QFileInfo uvcSettingsFile( QString("%1/cfg/uvc/%2.ini").arg(QCoreApplication::applicationDirPath()).arg(deviceName) );
bool hasSettings = uvcSettingsFile.exists();
settings = new QSettings(uvcSettingsFile.absoluteFilePath(), QSettings::IniFormat);
uint8_t focus_auto; uint8_t focus_auto;
uint8_t ae_priority; uint8_t ae_priority;
uint8_t ae_mode; uint8_t ae_mode;
...@@ -185,11 +191,6 @@ bool UVCCameraSession::load() ...@@ -185,11 +191,6 @@ bool UVCCameraSession::load()
uint32_t exposure_abs; uint32_t exposure_abs;
QSettings *settings;
QFileInfo uvcSettingsFile( QString("%1/cfg/uvc/%2.ini").arg(QCoreApplication::applicationDirPath()).arg(deviceName) );
bool hasSettings = uvcSettingsFile.exists();
settings = new QSettings(uvcSettingsFile.absoluteFilePath(), QSettings::IniFormat);
// If we didn't have settings, create with default values; otherwise read and set // If we didn't have settings, create with default values; otherwise read and set
if ( !hasSettings ) { if ( !hasSettings ) {
qDebug() << uvcSettingsFile.absoluteFilePath() << "not found. Generating..."; qDebug() << uvcSettingsFile.absoluteFilePath() << "not found. Generating...";
...@@ -417,7 +418,8 @@ void UVCCameraSession::updateSourceCapabilities() ...@@ -417,7 +418,8 @@ void UVCCameraSession::updateSourceCapabilities()
} }
formatDesc = formatDesc->next; formatDesc = formatDesc->next;
} }
} }
bool UVCCameraSession::stopPreview() bool UVCCameraSession::stopPreview()
...@@ -454,30 +456,6 @@ void UVCCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &se ...@@ -454,30 +456,6 @@ void UVCCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &se
interval = 1 / settings.maximumFrameRate(); interval = 1 / settings.maximumFrameRate();
} }
bool UVCCameraSession::isPupilFieldCamera()
{
bool ret = false;
uvc_device_descriptor *desc;
uvc_get_device_descriptor(dev, &desc);
QString name(desc->product);
if ( name.contains("Pupil Cam1 ID2") )
ret = true;
uvc_free_device_descriptor(desc);
return ret;
}
bool UVCCameraSession::isPupilEyeCamera()
{
bool ret = false;
uvc_device_descriptor *desc;
uvc_get_device_descriptor(dev, &desc);
QString name(desc->product);
if ( name.contains("Pupil Cam1 ID0") || name.contains("Pupil Cam1 ID1") )
ret = true;
uvc_free_device_descriptor(desc);
return ret;
}
bool UVCCameraSession::acquire(const QString &device) bool UVCCameraSession::acquire(const QString &device)
{ {
QMutexLocker locker(&devicesMutex); QMutexLocker locker(&devicesMutex);
...@@ -493,3 +471,60 @@ void UVCCameraSession::release(const QString &device) ...@@ -493,3 +471,60 @@ void UVCCameraSession::release(const QString &device)
if (devices.contains(device)) if (devices.contains(device))
devices.remove(device); devices.remove(device);
} }
bool UVCCameraSession::isImageProcessingParameterSupported( QCameraImageProcessingControl::ProcessingParameter parameter) const
{
// TODO
return false;
}
bool UVCCameraSession::isImageProcessingParameterValueSupported( QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value) const
{
// TODO
return false;
}
QVariant UVCCameraSession::imageProcessingParameter( QCameraImageProcessingControl::ProcessingParameter parameter) const
{
//qDebug() << parameter;
switch (parameter) {
case QCameraImageProcessingControl::BrightnessAdjustment:
return uvc_get(devh, uvc_get_brightness);
case QCameraImageProcessingControl::ContrastAdjustment:
return uvc_get(devh, uvc_get_contrast);
case QCameraImageProcessingControl::ColorTemperature:
return uvc_get(devh, uvc_get_white_balance_temperature);
case QCameraImageProcessingControl::SaturationAdjustment:
return uvc_get(devh, uvc_get_saturation);
case QCameraImageProcessingControl::SharpeningAdjustment:
return uvc_get(devh, uvc_get_sharpness);
default:
qWarning() << parameter << "not supported";
return QVariant();
}
}
void UVCCameraSession::setImageProcessingParameter( QCameraImageProcessingControl::ProcessingParameter parameter, const QVariant &value)
{
//qDebug() << parameter;
switch (parameter) {
case QCameraImageProcessingControl::BrightnessAdjustment:
uvc_set(devh, uvc_set_brightness, value, uvc_get_brightness);
break;
case QCameraImageProcessingControl::ContrastAdjustment:
uvc_set(devh, uvc_set_contrast, value, uvc_get_contrast);
break;
case QCameraImageProcessingControl::ColorTemperature:
uvc_set(devh, uvc_set_white_balance_temperature, value, uvc_get_white_balance_temperature);
break;
case QCameraImageProcessingControl::SaturationAdjustment:
uvc_set(devh, uvc_set_saturation, value, uvc_get_saturation);
break;
case QCameraImageProcessingControl::SharpeningAdjustment:
uvc_set(devh, uvc_set_sharpness, value, uvc_get_sharpness);
break;
default:
qWarning() << parameter << "not supported";
}
return;
}
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <QtMultimedia/qvideosurfaceformat.h> #include <QtMultimedia/qvideosurfaceformat.h>
#include <QtMultimedia/qcameraimageprocessingcontrol.h> #include <QtMultimedia/qcameraimageprocessingcontrol.h>
#include <QtMultimedia/qabstractvideobuffer.h> #include <QtMultimedia/qabstractvideobuffer.h>
#include <QtMultimedia/qcameraexposurecontrol.h>
#include <QElapsedTimer> #include <QElapsedTimer>
...@@ -54,6 +55,40 @@ public: ...@@ -54,6 +55,40 @@ public:
QMutex getFrameMutex; QMutex getFrameMutex;
double interval; double interval;
// Image Processing
template<typename T>
QVariant uvc_get( uvc_device_handle_t *devh,
uvc_error_t (*get)( uvc_device_handle_t *, T *, enum uvc_req_code)
) const {
T mn, val, mx;
get(devh, &mn, UVC_GET_MIN);
get(devh, &val, UVC_GET_CUR);
get(devh, &mx, UVC_GET_MAX);
//qDebug() << mn << val << mx;
return (val - mn) / (double) (mx - mn) ;
}
template<typename T>
void uvc_set( uvc_device_handle_t *devh,
uvc_error_t (*set)( uvc_device_handle_t *, T),
QVariant val,
uvc_error_t (*get)( uvc_device_handle_t *, T *, enum uvc_req_code)
) {
T mn, mx;
get(devh, &mn, UVC_GET_MIN);
get(devh, &mx, UVC_GET_MAX);
double value = val.toDouble();
value = value * (mx - mn ) + mn;
//qDebug() << val;
set(devh, static_cast<T>(value));
}
bool isImageProcessingParameterSupported(QCameraImageProcessingControl::ProcessingParameter parameter) const;
bool isImageProcessingParameterValueSupported(QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value) const;
QVariant imageProcessingParameter(QCameraImageProcessingControl::ProcessingParameter parameter) const;
void setImageProcessingParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value);
private Q_SLOTS: private Q_SLOTS:
void presentFrame(QVideoFrame frame, const qreal t); void presentFrame(QVideoFrame frame, const qreal t);
...@@ -79,20 +114,16 @@ private: ...@@ -79,20 +114,16 @@ private:
// capabilities // capabilities
QList<QCameraViewfinderSettings> m_supportedViewfinderSettings; QList<QCameraViewfinderSettings> m_supportedViewfinderSettings;
void updateSourceCapabilities(); void updateSourceCapabilities();
QCameraViewfinderSettings settings; QCameraViewfinderSettings settings;
bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat); bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat);
static QMutex sessionMutex; static QMutex sessionMutex;
bool isPupilFieldCamera();
bool isPupilEyeCamera();
// device availability // device availability
static QMap<QString,bool> UVCCameraSession::devices; static QMap<QString,bool> UVCCameraSession::devices;
static QMutex UVCCameraSession::devicesMutex; static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device); bool acquire(const QString &device);
void release(const QString &device); void release(const QString &device);
}; };
QT_END_NAMESPACE QT_END_NAMESPACE
......
...@@ -20,7 +20,8 @@ SOURCES += uvcserviceplugin.cpp \ ...@@ -20,7 +20,8 @@ SOURCES += uvcserviceplugin.cpp \
uvccameracontrol.cpp \ uvccameracontrol.cpp \
uvccamerasession.cpp \ uvccamerasession.cpp \
uvcvideorenderercontrol.cpp \ uvcvideorenderercontrol.cpp \
uvccameraviewfindersettingscontrol.cpp uvccameraviewfindersettingscontrol.cpp \
uvccameraimageprocessingcontrol.cpp
HEADERS += uvcserviceplugin.h \ HEADERS += uvcserviceplugin.h \
uvccameraservice.h \ uvccameraservice.h \
...@@ -28,7 +29,8 @@ HEADERS += uvcserviceplugin.h \ ...@@ -28,7 +29,8 @@ HEADERS += uvcserviceplugin.h \
uvccameracontrol.h \ uvccameracontrol.h \
uvccamerasession.h \ uvccamerasession.h \
uvcvideorenderercontrol.h \ uvcvideorenderercontrol.h \
uvccameraviewfindersettingscontrol.h uvccameraviewfindersettingscontrol.h \
uvccameraimageprocessingcontrol.h
DISTFILES += uvcengine.json DISTFILES += uvcengine.json
unix { unix {
...@@ -47,11 +49,11 @@ win32:{ ...@@ -47,11 +49,11 @@ win32:{
# LIBUSB-1.0 # LIBUSB-1.0
INCLUDEPATH += "$${LIBUSBPATH}/libusb/" INCLUDEPATH += "$${LIBUSBPATH}/libusb/"
contains(QMAKE_HOST.arch, x86_64) { contains(QMAKE_HOST.arch, x86_64) {
Release:LIBS += "-L$${LIBUSBPATH}/x64/Release/dll" Release:LIBS += "-L$${LIBUSBPATH}/x64/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x64/Debug/dll" Debug:LIBS += "-L$${LIBUSBPATH}/x64/Debug/dll"
} else { } else {
Release:LIBS += "-L$${LIBUSBPATH}/x86/Release/dll" Release:LIBS += "-L$${LIBUSBPATH}/x86/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x86/Debug/dll" Debug:LIBS += "-L$${LIBUSBPATH}/x86/Debug/dll"
} }
LIBS += -llibusb-1.0 LIBS += -llibusb-1.0
......
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