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/qdebug.h>
......@@ -46,6 +7,7 @@
#include "uvcvideodevicecontrol.h"
#include "uvcvideorenderercontrol.h"
#include "uvccameraviewfindersettingscontrol.h"
#include "uvccameraimageprocessingcontrol.h"
QT_BEGIN_NAMESPACE
......@@ -57,6 +19,7 @@ UVCCameraService::UVCCameraService(QObject *parent):
m_control = new UVCCameraControl(m_session);
m_videoDevice = new UVCVideoDeviceControl(m_session);
m_viewfinderSettings = new UVCCameraViewfinderSettingsControl(m_session);
m_imageProcessingControl = new UVCCameraImageProcessingControl(m_session);
}
UVCCameraService::~UVCCameraService()
......@@ -86,9 +49,9 @@ QMediaControl* UVCCameraService::requestControl(const char *name)
if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
return m_viewfinderSettings;
// if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
// return m_imageProcessingControl;
//
if (qstrcmp(name, QCameraImageProcessingControl_iid) == 0)
return m_imageProcessingControl;
return NULL;
}
......
/****************************************************************************
**
** 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
#ifndef UVCCAMERASERVICE_H
#define UVCCAMERASERVICE_H
#include <QtCore/qobject.h>
#include <QtMultimedia/QMediaService>
......@@ -50,6 +11,7 @@ class UVCCameraSession;
class UVCVideoDeviceControl;
class UVCVideoRendererControl;
class UVCCameraViewfinderSettingsControl;
class UVCCameraImageProcessingControl;
class UVCCameraService : public QMediaService
{
......@@ -67,6 +29,7 @@ private:
UVCVideoDeviceControl *m_videoDevice;
UVCVideoRendererControl *m_videoRenderer;
UVCCameraViewfinderSettingsControl *m_viewfinderSettings;
UVCCameraImageProcessingControl *m_imageProcessingControl;
};
QT_END_NAMESPACE
......
......@@ -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 ae_priority;
uint8_t ae_mode;
......@@ -185,11 +191,6 @@ bool UVCCameraSession::load()
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 ( !hasSettings ) {
qDebug() << uvcSettingsFile.absoluteFilePath() << "not found. Generating...";
......@@ -418,6 +419,7 @@ void UVCCameraSession::updateSourceCapabilities()
formatDesc = formatDesc->next;
}
}
bool UVCCameraSession::stopPreview()
......@@ -454,30 +456,6 @@ void UVCCameraSession::setViewfinderSettings(const QCameraViewfinderSettings &se
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)
{
QMutexLocker locker(&devicesMutex);
......@@ -493,3 +471,60 @@ void UVCCameraSession::release(const QString &device)
if (devices.contains(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 @@
#include <QtMultimedia/qvideosurfaceformat.h>
#include <QtMultimedia/qcameraimageprocessingcontrol.h>
#include <QtMultimedia/qabstractvideobuffer.h>
#include <QtMultimedia/qcameraexposurecontrol.h>
#include <QElapsedTimer>
......@@ -54,6 +55,40 @@ public:
QMutex getFrameMutex;
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:
void presentFrame(QVideoFrame frame, const qreal t);
......@@ -84,15 +119,11 @@ private:
static QMutex sessionMutex;
bool isPupilFieldCamera();
bool isPupilEyeCamera();
// device availability
static QMap<QString,bool> UVCCameraSession::devices;
static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device);
void release(const QString &device);
};
QT_END_NAMESPACE
......
......@@ -20,7 +20,8 @@ SOURCES += uvcserviceplugin.cpp \
uvccameracontrol.cpp \
uvccamerasession.cpp \
uvcvideorenderercontrol.cpp \
uvccameraviewfindersettingscontrol.cpp
uvccameraviewfindersettingscontrol.cpp \
uvccameraimageprocessingcontrol.cpp
HEADERS += uvcserviceplugin.h \
uvccameraservice.h \
......@@ -28,7 +29,8 @@ HEADERS += uvcserviceplugin.h \
uvccameracontrol.h \
uvccamerasession.h \
uvcvideorenderercontrol.h \
uvccameraviewfindersettingscontrol.h
uvccameraviewfindersettingscontrol.h \
uvccameraimageprocessingcontrol.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