...
 
Commits (7)
#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
#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,8 @@
#include "uvcvideodevicecontrol.h"
#include "uvcvideorenderercontrol.h"
#include "uvccameraviewfindersettingscontrol.h"
#include "uvccameraimageprocessingcontrol.h"
#include "uvccameraexposurecontrol.h"
QT_BEGIN_NAMESPACE
......@@ -56,7 +19,9 @@ UVCCameraService::UVCCameraService(QObject *parent):
m_session = new UVCCameraSession(this);
m_control = new UVCCameraControl(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);
m_cameraExposureControl = new UVCCameraExposureControl(m_session);
}
UVCCameraService::~UVCCameraService()
......@@ -65,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)
......@@ -86,9 +55,12 @@ 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;
if (qstrcmp(name, QCameraExposureControl_iid) == 0)
return m_cameraExposureControl;
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,8 @@ class UVCCameraSession;
class UVCVideoDeviceControl;
class UVCVideoRendererControl;
class UVCCameraViewfinderSettingsControl;
class UVCCameraImageProcessingControl;
class UVCCameraExposureControl;
class UVCCameraService : public QMediaService
{
......@@ -66,7 +29,9 @@ private:
UVCCameraSession *m_session;
UVCVideoDeviceControl *m_videoDevice;
UVCVideoRendererControl *m_videoRenderer;
UVCCameraViewfinderSettingsControl *m_viewfinderSettings;
UVCCameraViewfinderSettingsControl *m_viewfinderSettings;
UVCCameraImageProcessingControl *m_imageProcessingControl;
UVCCameraExposureControl *m_cameraExposureControl;
};
QT_END_NAMESPACE
......
This diff is collapsed.
......@@ -13,11 +13,13 @@
#include <QtMultimedia/qvideosurfaceformat.h>
#include <QtMultimedia/qcameraimageprocessingcontrol.h>
#include <QtMultimedia/qabstractvideobuffer.h>
#include <QtMultimedia/qcameraexposurecontrol.h>
#include <QElapsedTimer>
#include <vector>
#include <atomic>
#include <map>
#include "libuvc/libuvc.h"
......@@ -26,6 +28,43 @@ QT_BEGIN_NAMESPACE
// Maximum acceptable latency for calling the surface present method
#define MAX_LATENCY_MS 1.0e3/25
struct DefaultParameters {
double bandwidthFactor;
double brightness;
double contrast;
double saturation;
double white_balance;
double sharpness;
double backlight_compensation;
double gamma;
double gain;
double exposure_abs;
double hue;
int ae_mode;
int ae_priority;
int contrast_auto;
int focus_auto;
int white_balance_component_auto;
int white_balance_temperature_auto;
int hue_auto;
};
class ProductFactory {
public:
QString make(const uvc_device_descriptor_t * const desc) {
QString product(desc->product);
if (entries.contains(product)) {
entries[product] += 1;
product = QString("%1 #%2").arg(product).arg(entries[product]);
} else
entries[product] = 0;
return product;
}
private:
QMap<QString,int> entries;
};
class UVCCameraSession : public QObject
{
Q_OBJECT
......@@ -54,11 +93,68 @@ public:
QMutex getFrameMutex;
double interval;
// Image Processing
// TODO: we don't check if the camera supports the parameters since some
// cameras underreport their capabilities; is this safe?
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);
return (val - mn) / (double) (mx - mn) ;
}
template<typename T>
QVariant uvc_get_mode( uvc_device_handle_t *devh,
uvc_error_t (*get)( uvc_device_handle_t *, T *, enum uvc_req_code)
) const {
T val;
get(devh, &val, UVC_GET_CUR);
return val;
}
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;
set(devh, static_cast<T>(value));
}
template<typename T>
void uvc_set_mode( uvc_device_handle_t *devh,
uvc_error_t (*set)( uvc_device_handle_t *, T),
QVariant val
) {
set(devh, static_cast<T>(val.toInt()));
}
// Image Processing
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);
// 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);
private:
float bandwidthFactor;
double bandwidthFactor;
QCamera::Status m_status;
QAbstractVideoSurface *m_surface;
QMutex surfaceMutex;
......@@ -79,20 +175,33 @@ private:
// capabilities
QList<QCameraViewfinderSettings> m_supportedViewfinderSettings;
void updateSourceCapabilities();
QCameraViewfinderSettings settings;
QCameraViewfinderSettings settings;
bool qPixelFormat2UVCFrameFormat(const QVideoFrame::PixelFormat &qFormat, uvc_frame_format &uvcFormat);
double getBandwidthFactor();
static QMutex sessionMutex;
bool isPupilFieldCamera();
bool isPupilEyeCamera();
// device availability
static QMap<QString,bool> UVCCameraSession::devices;
static QMap<QString,bool> devices;
static QMutex UVCCameraSession::devicesMutex;
bool acquire(const QString &device);
void release(const QString &device);
std::map<QString,DefaultParameters> defaults;
void setDefaultParameters();
QVideoFrame::PixelFormat fourcc2PixelFormat(const uint8_t *fourcc, QString &str) {
str = QString("%1%2%3%4").arg(
(char) fourcc[0]).arg(
(char) fourcc[1]).arg(
(char) fourcc[2]).arg(
(char) fourcc[3]);
if ( str.compare("yuyv", Qt::CaseInsensitive) == 0 )
return QVideoFrame::Format_YUYV;
if ( str.compare("yuy2", Qt::CaseInsensitive) == 0 ) // duplicate of yuyv http://www.fourcc.org/pixel-format/yuv-yuy2/
return QVideoFrame::Format_YUYV;
return QVideoFrame::Format_Invalid;
}
};
QT_END_NAMESPACE
......
......@@ -11,6 +11,7 @@ QT += core gui multimedia
TARGET = uvcengine
TEMPLATE = lib
CONFIG += plugin
CONFIG += force_debug_info
DESTDIR = $$[QT_INSTALL_PLUGINS]/mediaservice
......@@ -20,7 +21,9 @@ SOURCES += uvcserviceplugin.cpp \
uvccameracontrol.cpp \
uvccamerasession.cpp \
uvcvideorenderercontrol.cpp \
uvccameraviewfindersettingscontrol.cpp
uvccameraviewfindersettingscontrol.cpp \
uvccameraimageprocessingcontrol.cpp \
uvccameraexposurecontrol.cpp
HEADERS += uvcserviceplugin.h \
uvccameraservice.h \
......@@ -28,7 +31,9 @@ HEADERS += uvcserviceplugin.h \
uvccameracontrol.h \
uvccamerasession.h \
uvcvideorenderercontrol.h \
uvccameraviewfindersettingscontrol.h
uvccameraviewfindersettingscontrol.h \
uvccameraimageprocessingcontrol.h \
uvccameraexposurecontrol.h
DISTFILES += uvcengine.json
unix {
......@@ -47,17 +52,16 @@ win32:{
# LIBUSB-1.0
INCLUDEPATH += "$${LIBUSBPATH}/libusb/"
contains(QMAKE_HOST.arch, x86_64) {
Release:LIBS += "-L$${LIBUSBPATH}/x64/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x64/Debug/dll"
Release:LIBS += "-L$${LIBUSBPATH}/x64/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x64/Debug/dll"
} else {
Release:LIBS += "-L$${LIBUSBPATH}/x86/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x86/Debug/dll"
Release:LIBS += "-L$${LIBUSBPATH}/x86/Release/dll"
Debug:LIBS += "-L$${LIBUSBPATH}/x86/Debug/dll"
}
LIBS += -llibusb-1.0
# LIBUVC
INCLUDEPATH += "$${LIBUVCPATH}/include/"
INCLUDEPATH += "$${LIBUVCPATH}/build/include/"
INCLUDEPATH += "$${LIBUVCPATH}/install/include/"
contains(QMAKE_HOST.arch, x86_64) {
Release:LIBS += "-L$${LIBUVCPATH}/build/Release/"
Debug:LIBS += "-L$${LIBUVCPATH}/build/Debug"
......
......@@ -101,6 +101,7 @@ void UVCVideoDeviceControl::updateDevices()
return;
}
ProductFactory pf;
int idx = 0;
while (1) {
uvc_device_t *dev = devList[idx];
......@@ -119,8 +120,9 @@ void UVCVideoDeviceControl::updateDevices()
UVCVideoDeviceInfo devInfo;
devInfo.first = QString(desc->product).toUtf8();
devInfo.second = QString(desc->product).toUtf8();
QString product = pf.make(desc);
devInfo.first = QString(product).toUtf8();
devInfo.second = QString(product).toUtf8();
deviceList->append(devInfo);
......