...
 
Commits (2)
......@@ -6,18 +6,15 @@
QT_BEGIN_NAMESPACE
UVCCameraControl::UVCCameraControl(QObject *parent)
UVCCameraControl::UVCCameraControl(QObject* parent)
: QCameraControl(parent)
, m_session(qobject_cast<UVCCameraSession*>(parent))
, m_service(nullptr)
, m_state(QCamera::UnloadedState)
, m_captureMode(QCamera::CaptureStillImage)
{
m_session = qobject_cast<UVCCameraSession*>(parent);
//connect(m_session, SIGNAL(statusChanged(QCamera::Status)),
// this, SIGNAL(statusChanged(QCamera::Status)));
}
UVCCameraControl::~UVCCameraControl()
{
// this, SIGNAL(statusChanged(QCamera::Status)));
}
void UVCCameraControl::setState(QCamera::State state)
......@@ -27,30 +24,30 @@ void UVCCameraControl::setState(QCamera::State state)
bool succeeded = false;
switch (state) {
case QCamera::UnloadedState:
succeeded = m_session->unload();
break;
case QCamera::UnloadedState:
succeeded = m_session->unload();
break;
case QCamera::LoadedState:
if (m_state == QCamera::UnloadedState && !(succeeded=m_session->load()))
return;
if (m_state == QCamera::ActiveState)
succeeded = m_session->stopPreview();
break;
case QCamera::LoadedState:
if (m_state == QCamera::UnloadedState && !(succeeded = m_session->load()))
return;
if (m_state == QCamera::ActiveState)
succeeded = m_session->stopPreview();
break;
case QCamera::ActiveState:
if (m_state == QCamera::UnloadedState) {
if (!m_session->load())
break;
m_state = QCamera::LoadedState;
}
case QCamera::ActiveState:
if (m_state == QCamera::UnloadedState) {
if (!m_session->load())
break;
m_state = QCamera::LoadedState;
}
if (state == QCamera::ActiveState)
succeeded = m_session->startPreview();
else
succeeded = m_session->stopPreview();
if (state == QCamera::ActiveState)
succeeded = m_session->startPreview();
else
succeeded = m_session->stopPreview();
break;
break;
}
if (succeeded) {
......
#ifndef UVCCAMERACONTROL_H
#define UVCCAMERACONTROL_H
#include <QtCore/qobject.h>
#include <QtMultimedia/QCameraControl>
......@@ -10,27 +9,26 @@ QT_BEGIN_NAMESPACE
class UVCCameraService;
class UVCCameraSession;
class UVCCameraControl : public QCameraControl
{
class UVCCameraControl : public QCameraControl {
Q_OBJECT
public:
UVCCameraControl(QObject *parent = 0);
~UVCCameraControl();
UVCCameraControl(QObject* parent = 0);
~UVCCameraControl() = default;
QCamera::State state() const { return m_state; }
QCamera::CaptureModes captureMode() const { return m_captureMode; }
void setCaptureMode(QCamera::CaptureModes mode);
void setCaptureMode(QCamera::CaptureModes mode);
void setState(QCamera::State state);
QCamera::Status status() const;
bool isCaptureModeSupported(QCamera::CaptureModes mode) const;
bool canChangeProperty(PropertyChangeType /* changeType */, QCamera::Status /* status */) const {return false; }
bool canChangeProperty(PropertyChangeType /* changeType */, QCamera::Status /* status */) const { return false; }
private:
UVCCameraSession *m_session;
UVCCameraService *m_service;
UVCCameraSession* m_session;
UVCCameraService* m_service;
QCamera::State m_state;
QCamera::CaptureModes m_captureMode;
};
......
......@@ -3,39 +3,35 @@
QT_BEGIN_NAMESPACE
UVCCameraExposureControl::UVCCameraExposureControl(UVCCameraSession *session)
: QCameraExposureControl(session)
UVCCameraExposureControl::UVCCameraExposureControl(UVCCameraSession* session)
: QCameraExposureControl(session)
, m_session(session)
{
}
UVCCameraExposureControl::~UVCCameraExposureControl()
{
}
QVariant UVCCameraExposureControl::actualValue(ExposureParameter parameter) const
{
return m_session->actualExposureValue(parameter);
return m_session->actualExposureValue(parameter);
}
bool UVCCameraExposureControl::isParameterSupported(ExposureParameter parameter) const
{
return m_session->isExposureParameterSupported(parameter);
return m_session->isExposureParameterSupported(parameter);
}
QVariant UVCCameraExposureControl::requestedValue(ExposureParameter parameter) const
{
return m_session->requestedExposureValue(parameter);
return m_session->requestedExposureValue(parameter);
}
bool UVCCameraExposureControl::setValue(ExposureParameter parameter, const QVariant &value)
bool UVCCameraExposureControl::setValue(ExposureParameter parameter, const QVariant& value)
{
return m_session->setExposureValue(parameter, value);
return m_session->setExposureValue(parameter, value);
}
QVariantList UVCCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool *continuous) const
QVariantList UVCCameraExposureControl::supportedParameterRange(ExposureParameter parameter, bool* continuous) const
{
return m_session->supportedExposureParameterRange(parameter, continuous);
return m_session->supportedExposureParameterRange(parameter, continuous);
}
QT_END_NAMESPACE
......@@ -8,22 +8,21 @@ QT_BEGIN_NAMESPACE
class UVCCameraSession;
class UVCCameraExposureControl : public QCameraExposureControl
{
class UVCCameraExposureControl : public QCameraExposureControl {
Q_OBJECT
public:
UVCCameraExposureControl(UVCCameraSession *session);
virtual ~UVCCameraExposureControl();
UVCCameraExposureControl(UVCCameraSession* session);
virtual ~UVCCameraExposureControl() = default;
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;
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;
UVCCameraSession* m_session;
};
QT_END_NAMESPACE
......
......@@ -3,37 +3,33 @@
QT_BEGIN_NAMESPACE
UVCCameraImageProcessingControl::UVCCameraImageProcessingControl(UVCCameraSession *session)
UVCCameraImageProcessingControl::UVCCameraImageProcessingControl(UVCCameraSession* session)
: QCameraImageProcessingControl(session)
, m_session(session)
{
}
UVCCameraImageProcessingControl::~UVCCameraImageProcessingControl()
{
}
bool UVCCameraImageProcessingControl::isParameterSupported(
QCameraImageProcessingControl::ProcessingParameter parameter) const
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
return m_session->isImageProcessingParameterSupported(parameter);
}
bool UVCCameraImageProcessingControl::isParameterValueSupported(
QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value) const
QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant& value) const
{
return m_session->isImageProcessingParameterValueSupported(parameter, value);
}
QVariant UVCCameraImageProcessingControl::parameter(
QCameraImageProcessingControl::ProcessingParameter parameter) const
QCameraImageProcessingControl::ProcessingParameter parameter) const
{
return m_session->imageProcessingParameter(parameter);
}
void UVCCameraImageProcessingControl::setParameter(QCameraImageProcessingControl::ProcessingParameter parameter,
const QVariant &value)
const QVariant& value)
{
m_session->setImageProcessingParameter(parameter, value);
}
......
......@@ -8,21 +8,20 @@ QT_BEGIN_NAMESPACE
class UVCCameraSession;
class UVCCameraImageProcessingControl : public QCameraImageProcessingControl
{
class UVCCameraImageProcessingControl : public QCameraImageProcessingControl {
Q_OBJECT
public:
UVCCameraImageProcessingControl(UVCCameraSession *session);
virtual ~UVCCameraImageProcessingControl();
UVCCameraImageProcessingControl(UVCCameraSession* session);
virtual ~UVCCameraImageProcessingControl() = default;
bool isParameterSupported(ProcessingParameter) const;
bool isParameterValueSupported(ProcessingParameter parameter, const QVariant &value) const;
bool isParameterValueSupported(ProcessingParameter parameter, const QVariant& value) const;
QVariant parameter(ProcessingParameter parameter) const;
void setParameter(ProcessingParameter parameter, const QVariant &value);
void setParameter(ProcessingParameter parameter, const QVariant& value);
private:
UVCCameraSession *m_session;
UVCCameraSession* m_session;
};
QT_END_NAMESPACE
......
This diff is collapsed.
This diff is collapsed.
#include "uvcserviceplugin.h"
QMediaService* UVCServicePlugin::create(const QString &key)
QMediaService* UVCServicePlugin::create(const QString& key)
{
if (key == Q_MEDIASERVICE_CAMERA)
return new UVCCameraService();
if (key == Q_MEDIASERVICE_CAMERA)
return new UVCCameraService();
return nullptr;
}
void UVCServicePlugin::release(QMediaService *service)
void UVCServicePlugin::release(QMediaService* service)
{
delete service;
}
QByteArray UVCServicePlugin::defaultDevice(const QByteArray &service) const
QByteArray UVCServicePlugin::defaultDevice(const QByteArray& service) const
{
if (service == Q_MEDIASERVICE_CAMERA) {
const QList<UVCVideoDeviceInfo> &devs = UVCVideoDeviceControl::availableDevices();
const QList<UVCVideoDeviceInfo>& devs = UVCVideoDeviceControl::availableDevices();
if (!devs.isEmpty())
return devs.first().first;
}
......@@ -23,24 +23,24 @@ QByteArray UVCServicePlugin::defaultDevice(const QByteArray &service) const
return QByteArray();
}
QList<QByteArray> UVCServicePlugin::devices(const QByteArray &service) const
QList<QByteArray> UVCServicePlugin::devices(const QByteArray& service) const
{
QList<QByteArray> result;
if (service == Q_MEDIASERVICE_CAMERA) {
const QList<UVCVideoDeviceInfo> &devs = UVCVideoDeviceControl::availableDevices();
for (const UVCVideoDeviceInfo &info : devs)
const QList<UVCVideoDeviceInfo>& devs = UVCVideoDeviceControl::availableDevices();
for (const UVCVideoDeviceInfo& info : devs)
result.append(info.first);
}
return result;
}
QString UVCServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
QString UVCServicePlugin::deviceDescription(const QByteArray& service, const QByteArray& device)
{
if (service == Q_MEDIASERVICE_CAMERA) {
const QList<UVCVideoDeviceInfo> &devs = UVCVideoDeviceControl::availableDevices();
for (const UVCVideoDeviceInfo &info : devs)
const QList<UVCVideoDeviceInfo>& devs = UVCVideoDeviceControl::availableDevices();
for (const UVCVideoDeviceInfo& info : devs)
if (info.first == device)
return info.second;
}
......@@ -49,12 +49,12 @@ QString UVCServicePlugin::deviceDescription(const QByteArray &service, const QBy
}
QMediaServiceProviderHint::Features UVCServicePlugin::supportedFeatures(
const QByteArray &service) const
const QByteArray& service) const
{
if (service == Q_MEDIASERVICE_MEDIAPLAYER)
return QMediaServiceProviderHint::StreamPlayback | QMediaServiceProviderHint::VideoSurface;
else
return QMediaServiceProviderHint::Features();
return {};
}
#if QT_VERSION < 0x050000
......
......@@ -5,22 +5,18 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QList<UVCVideoDeviceInfo>, deviceList)
bool UVCVideoDeviceControl::printVersion = true;
UVCVideoDeviceControl::UVCVideoDeviceControl(QObject *parent)
: QVideoDeviceSelectorControl(parent),
selected(0),
ctx(nullptr)
UVCVideoDeviceControl::UVCVideoDeviceControl(QObject* parent)
: QVideoDeviceSelectorControl(parent)
, selected(0)
, ctx(nullptr)
{
if (printVersion) {
qInfo() << QString("uvcengine version: %1 %2").arg(GIT_BRANCH).arg(GIT_COMMIT_HASH);
printVersion = false;
}
m_session = qobject_cast<UVCCameraSession*>(parent);
updateDevices();
}
if (printVersion) {
qInfo() << QString("uvcengine version: %1 %2").arg(GIT_BRANCH).arg(GIT_COMMIT_HASH);
printVersion = false;
}
UVCVideoDeviceControl::~UVCVideoDeviceControl()
{
m_session = qobject_cast<UVCCameraSession*>(parent);
updateDevices();
}
int UVCVideoDeviceControl::deviceCount() const
......@@ -66,13 +62,13 @@ void UVCVideoDeviceControl::setSelectedDevice(int index)
if (index >= 0 && index < deviceList->count()) {
if (m_session) {
QString device = deviceList->at(index).first;
if ( m_session->setDevice(device) )
selected = index;
if (m_session->setDevice(device))
selected = index;
}
}
}
const QList<UVCVideoDeviceInfo> &UVCVideoDeviceControl::availableDevices()
const QList<UVCVideoDeviceInfo>& UVCVideoDeviceControl::availableDevices()
{
updateDevices();
return *deviceList;
......@@ -82,32 +78,32 @@ void UVCVideoDeviceControl::updateDevices()
{
static QElapsedTimer timer;
if (timer.isValid() && timer.elapsed() < 500) // ms
return;
return;
deviceList->clear();
uvc_error_t res;
uvc_context_t *ctx;
res = uvc_init(&ctx, nullptr);
if (res < 0) {
qWarning() << "uvc_init" << uvc_strerror(res);
return ;
}
uvc_device_t **devList;
uvc_error_t res;
uvc_context_t* ctx;
res = uvc_init(&ctx, nullptr);
if (res < 0) {
qWarning() << "uvc_init" << uvc_strerror(res);
return;
}
uvc_device_t** devList;
res = uvc_get_device_list(ctx, &devList);
if (res < 0) {
qWarning() << "uvc_get_device_list" << uvc_strerror(res);
return;
}
ProductFactory pf;
ProductFactory pf;
int idx = 0;
while (1) {
uvc_device_t *dev = devList[idx];
uvc_device_t* dev = devList[idx];
idx++;
if (dev == nullptr)
break;
uvc_device_descriptor_t *desc;
uvc_device_descriptor_t* desc;
res = uvc_get_device_descriptor(dev, &desc);
if (res < 0) {
qWarning() << "uvc_get_device_descriptor" << uvc_strerror(res);
......@@ -119,17 +115,17 @@ void UVCVideoDeviceControl::updateDevices()
UVCVideoDeviceInfo devInfo;
QString product = pf.make(desc);
devInfo.first = QString(product).toUtf8();
devInfo.second = QString(product).toUtf8();
QString product = pf.make(desc);
devInfo.first = QString(product).toUtf8();
devInfo.second = QString(product).toUtf8();
deviceList->append(devInfo);
uvc_free_device_descriptor(desc);
}
uvc_free_device_list(devList, 0);
uvc_exit(ctx);
uvc_free_device_list(devList, 0);
uvc_exit(ctx);
timer.restart();
}
#ifndef UVCVIDEODEVICECONTROL_H
#define UVCVIDEODEVICECONTROL_H
#include <QVideoDeviceSelectorControl>
#include <QStringList>
#include <QElapsedTimer>
#include <QDebug>
#include <QElapsedTimer>
#include <QStringList>
#include <QVideoDeviceSelectorControl>
#include "uvccamerasession.h"
......@@ -14,12 +14,11 @@ QT_BEGIN_NAMESPACE
typedef QPair<QByteArray, QString> UVCVideoDeviceInfo;
class UVCVideoDeviceControl : public QVideoDeviceSelectorControl
{
class UVCVideoDeviceControl : public QVideoDeviceSelectorControl {
Q_OBJECT
public:
UVCVideoDeviceControl(QObject *parent = 0);
~UVCVideoDeviceControl();
UVCVideoDeviceControl(QObject* parent = 0);
~UVCVideoDeviceControl() = default;
int deviceCount() const;
QString deviceName(int index) const;
......@@ -27,19 +26,19 @@ public:
int defaultDevice() const;
int selectedDevice() const;
static const QList<UVCVideoDeviceInfo> &availableDevices();
static const QList<UVCVideoDeviceInfo>& availableDevices();
public Q_SLOTS:
void setSelectedDevice(int index);
private:
static bool printVersion;
static bool printVersion;
static void updateDevices();
static void updateDevices();
UVCCameraSession* m_session;
int selected;
uvc_context_t* ctx;
uvc_context_t* ctx;
};
QT_END_NAMESPACE
......
......@@ -2,14 +2,10 @@
QT_BEGIN_NAMESPACE
UVCVideoRendererControl::UVCVideoRendererControl(UVCCameraSession* session, QObject *parent)
:QVideoRendererControl(parent),
m_surface(nullptr),
m_session(session)
{
}
UVCVideoRendererControl::~UVCVideoRendererControl()
UVCVideoRendererControl::UVCVideoRendererControl(UVCCameraSession* session, QObject* parent)
: QVideoRendererControl(parent)
, m_surface(nullptr)
, m_session(session)
{
}
......@@ -18,10 +14,10 @@ QAbstractVideoSurface* UVCVideoRendererControl::surface() const
return m_surface;
}
void UVCVideoRendererControl::setSurface(QAbstractVideoSurface *surface)
void UVCVideoRendererControl::setSurface(QAbstractVideoSurface* surface)
{
m_surface = surface;
if(m_session)
if (m_session)
m_session->setSurface(m_surface);
}
......
#ifndef UVCVIDEORENDERERCONTROL_H
#define UVCVIDEORENDERERCONTROL_H
#include <qvideorenderercontrol.h>
#include "uvccamerasession.h"
#include <qvideorenderercontrol.h>
class CameraFormatConverter;
QT_BEGIN_NAMESPACE
class UVCVideoRendererControl : public QVideoRendererControl
{
class UVCVideoRendererControl : public QVideoRendererControl {
Q_OBJECT
public:
UVCVideoRendererControl(UVCCameraSession* session, QObject *parent = 0);
~UVCVideoRendererControl();
UVCVideoRendererControl(UVCCameraSession* session, QObject* parent = 0);
~UVCVideoRendererControl() = default;
QAbstractVideoSurface *surface() const;
void setSurface(QAbstractVideoSurface *surface);
QAbstractVideoSurface* surface() const;
void setSurface(QAbstractVideoSurface* surface);
private:
QAbstractVideoSurface* m_surface;
UVCCameraSession* m_session;
CameraFormatConverter* converter;
};
QT_END_NAMESPACE
......