Viewfinder settings control (1) for OS X/iOS
QCameraViewfinderSettingsControl - version for AVFoundation plugin
('obsolete' viewfinder settings control interface, camera session uses v2
instead). v1 is implemented using v2 (the v2 object from camera service).
Change-Id: I81207b52b0ba5a67e64465f0e5e0c80d7267df3e
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
This commit is contained in:
committed by
Yoann Lopes
parent
0d783b7303
commit
985ee3261b
@@ -56,6 +56,7 @@ class AVFCameraFocusControl;
|
|||||||
class AVFCameraExposureControl;
|
class AVFCameraExposureControl;
|
||||||
class AVFCameraZoomControl;
|
class AVFCameraZoomControl;
|
||||||
class AVFCameraViewfinderSettingsControl2;
|
class AVFCameraViewfinderSettingsControl2;
|
||||||
|
class AVFCameraViewfinderSettingsControl;
|
||||||
|
|
||||||
class AVFCameraService : public QMediaService
|
class AVFCameraService : public QMediaService
|
||||||
{
|
{
|
||||||
@@ -79,6 +80,7 @@ public:
|
|||||||
AVFCameraZoomControl *cameraZoomControl() const {return m_cameraZoomControl; }
|
AVFCameraZoomControl *cameraZoomControl() const {return m_cameraZoomControl; }
|
||||||
AVFCameraRendererControl *videoOutput() const {return m_videoOutput; }
|
AVFCameraRendererControl *videoOutput() const {return m_videoOutput; }
|
||||||
AVFCameraViewfinderSettingsControl2 *viewfinderSettingsControl2() const {return m_viewfinderSettingsControl2; }
|
AVFCameraViewfinderSettingsControl2 *viewfinderSettingsControl2() const {return m_viewfinderSettingsControl2; }
|
||||||
|
AVFCameraViewfinderSettingsControl *viewfinderSettingsControl() const {return m_viewfinderSettingsControl; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AVFCameraSession *m_session;
|
AVFCameraSession *m_session;
|
||||||
@@ -94,6 +96,7 @@ private:
|
|||||||
AVFCameraExposureControl *m_cameraExposureControl;
|
AVFCameraExposureControl *m_cameraExposureControl;
|
||||||
AVFCameraZoomControl *m_cameraZoomControl;
|
AVFCameraZoomControl *m_cameraZoomControl;
|
||||||
AVFCameraViewfinderSettingsControl2 *m_viewfinderSettingsControl2;
|
AVFCameraViewfinderSettingsControl2 *m_viewfinderSettingsControl2;
|
||||||
|
AVFCameraViewfinderSettingsControl *m_viewfinderSettingsControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ AVFCameraService::AVFCameraService(QObject *parent):
|
|||||||
m_cameraZoomControl = new AVFCameraZoomControl(this);
|
m_cameraZoomControl = new AVFCameraZoomControl(this);
|
||||||
#endif
|
#endif
|
||||||
m_viewfinderSettingsControl2 = new AVFCameraViewfinderSettingsControl2(this);
|
m_viewfinderSettingsControl2 = new AVFCameraViewfinderSettingsControl2(this);
|
||||||
|
m_viewfinderSettingsControl = new AVFCameraViewfinderSettingsControl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
AVFCameraService::~AVFCameraService()
|
AVFCameraService::~AVFCameraService()
|
||||||
@@ -110,6 +111,7 @@ AVFCameraService::~AVFCameraService()
|
|||||||
delete m_cameraZoomControl;
|
delete m_cameraZoomControl;
|
||||||
#endif
|
#endif
|
||||||
delete m_viewfinderSettingsControl2;
|
delete m_viewfinderSettingsControl2;
|
||||||
|
delete m_viewfinderSettingsControl;
|
||||||
|
|
||||||
delete m_session;
|
delete m_session;
|
||||||
}
|
}
|
||||||
@@ -147,6 +149,9 @@ QMediaControl *AVFCameraService::requestControl(const char *name)
|
|||||||
if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
|
if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0)
|
||||||
return m_viewfinderSettingsControl2;
|
return m_viewfinderSettingsControl2;
|
||||||
|
|
||||||
|
if (qstrcmp(name, QCameraViewfinderSettingsControl_iid) == 0)
|
||||||
|
return m_viewfinderSettingsControl;
|
||||||
|
|
||||||
if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
|
if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
|
||||||
AVFMediaVideoProbeControl *videoProbe = 0;
|
AVFMediaVideoProbeControl *videoProbe = 0;
|
||||||
videoProbe = new AVFMediaVideoProbeControl(this);
|
videoProbe = new AVFMediaVideoProbeControl(this);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#include <QtMultimedia/qcameraviewfindersettings.h>
|
#include <QtMultimedia/qcameraviewfindersettings.h>
|
||||||
#include <QtMultimedia/qvideoframe.h>
|
#include <QtMultimedia/qvideoframe.h>
|
||||||
|
|
||||||
|
#include <QtCore/qpointer.h>
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QtCore/qsize.h>
|
#include <QtCore/qsize.h>
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ class AVFCameraViewfinderSettingsControl2 : public QCameraViewfinderSettingsCont
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
friend class AVFCameraSession;
|
friend class AVFCameraSession;
|
||||||
|
friend class AVFCameraViewfinderSettingsControl;
|
||||||
public:
|
public:
|
||||||
AVFCameraViewfinderSettingsControl2(AVFCameraService *service);
|
AVFCameraViewfinderSettingsControl2(AVFCameraService *service);
|
||||||
|
|
||||||
@@ -86,6 +88,27 @@ private:
|
|||||||
mutable AVCaptureConnection *m_videoConnection;
|
mutable AVCaptureConnection *m_videoConnection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AVFCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AVFCameraViewfinderSettingsControl(AVFCameraService *service);
|
||||||
|
|
||||||
|
bool isViewfinderParameterSupported(ViewfinderParameter parameter) const Q_DECL_OVERRIDE;
|
||||||
|
QVariant viewfinderParameter(ViewfinderParameter parameter) const Q_DECL_OVERRIDE;
|
||||||
|
void setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setResolution(const QVariant &resolution);
|
||||||
|
void setAspectRatio(const QVariant &aspectRatio);
|
||||||
|
void setFrameRate(const QVariant &fps, bool max);
|
||||||
|
void setPixelFormat(const QVariant &pf);
|
||||||
|
bool initSettingsControl() const;
|
||||||
|
|
||||||
|
AVFCameraService *m_service;
|
||||||
|
mutable QPointer<AVFCameraViewfinderSettingsControl2> m_settingsControl;
|
||||||
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -574,6 +574,159 @@ bool AVFCameraViewfinderSettingsControl2::updateAVFoundationObjects() const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AVFCameraViewfinderSettingsControl::AVFCameraViewfinderSettingsControl(AVFCameraService *service)
|
||||||
|
: m_service(service)
|
||||||
|
{
|
||||||
|
// Legacy viewfinder settings control.
|
||||||
|
Q_ASSERT(service);
|
||||||
|
initSettingsControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AVFCameraViewfinderSettingsControl::isViewfinderParameterSupported(ViewfinderParameter parameter) const
|
||||||
|
{
|
||||||
|
return parameter == Resolution
|
||||||
|
|| parameter == PixelAspectRatio
|
||||||
|
|| parameter == MinimumFrameRate
|
||||||
|
|| parameter == MaximumFrameRate
|
||||||
|
|| parameter == PixelFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant AVFCameraViewfinderSettingsControl::viewfinderParameter(ViewfinderParameter parameter) const
|
||||||
|
{
|
||||||
|
if (!isViewfinderParameterSupported(parameter)) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "parameter is not supported";
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSettingsControl()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "initialization failed";
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
const QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
|
||||||
|
if (parameter == Resolution)
|
||||||
|
return settings.resolution();
|
||||||
|
if (parameter == PixelAspectRatio)
|
||||||
|
return settings.pixelAspectRatio();
|
||||||
|
if (parameter == MinimumFrameRate)
|
||||||
|
return settings.minimumFrameRate();
|
||||||
|
if (parameter == MaximumFrameRate)
|
||||||
|
return settings.maximumFrameRate();
|
||||||
|
if (parameter == PixelFormat)
|
||||||
|
return QVariant::fromValue(settings.pixelFormat());
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraViewfinderSettingsControl::setViewfinderParameter(ViewfinderParameter parameter, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (!isViewfinderParameterSupported(parameter)) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "parameter is not supported";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameter == Resolution)
|
||||||
|
setResolution(value);
|
||||||
|
if (parameter == PixelAspectRatio)
|
||||||
|
setAspectRatio(value);
|
||||||
|
if (parameter == MinimumFrameRate)
|
||||||
|
setFrameRate(value, false);
|
||||||
|
if (parameter == MaximumFrameRate)
|
||||||
|
setFrameRate(value, true);
|
||||||
|
if (parameter == PixelFormat)
|
||||||
|
setPixelFormat(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraViewfinderSettingsControl::setResolution(const QVariant &newValue)
|
||||||
|
{
|
||||||
|
if (!newValue.canConvert<QSize>()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "QSize type expected";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSettingsControl()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "initialization failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QSize res(newValue.toSize());
|
||||||
|
if (res.isNull() || !res.isValid()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "invalid resolution:" << res;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
|
||||||
|
settings.setResolution(res);
|
||||||
|
m_settingsControl->setViewfinderSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraViewfinderSettingsControl::setAspectRatio(const QVariant &newValue)
|
||||||
|
{
|
||||||
|
if (!newValue.canConvert<QSize>()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "QSize type expected";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSettingsControl()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "initialization failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QSize par(newValue.value<QSize>());
|
||||||
|
if (par.isNull() || !par.isValid()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "invalid pixel aspect ratio:" << par;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
|
||||||
|
settings.setPixelAspectRatio(par);
|
||||||
|
m_settingsControl->setViewfinderSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraViewfinderSettingsControl::setFrameRate(const QVariant &newValue, bool max)
|
||||||
|
{
|
||||||
|
if (!newValue.canConvert<qreal>()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "qreal type expected";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSettingsControl()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "initialization failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal fps(newValue.toReal());
|
||||||
|
QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
|
||||||
|
max ? settings.setMaximumFrameRate(fps) : settings.setMinimumFrameRate(fps);
|
||||||
|
m_settingsControl->setViewfinderSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AVFCameraViewfinderSettingsControl::setPixelFormat(const QVariant &newValue)
|
||||||
|
{
|
||||||
|
if (!newValue.canConvert<QVideoFrame::PixelFormat>()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO
|
||||||
|
<< "QVideoFrame::PixelFormat type expected";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSettingsControl()) {
|
||||||
|
qDebugCamera() << Q_FUNC_INFO << "initialization failed";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QCameraViewfinderSettings settings(m_settingsControl->viewfinderSettings());
|
||||||
|
settings.setPixelFormat(newValue.value<QVideoFrame::PixelFormat>());
|
||||||
|
m_settingsControl->setViewfinderSettings(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AVFCameraViewfinderSettingsControl::initSettingsControl()const
|
||||||
|
{
|
||||||
|
if (!m_settingsControl)
|
||||||
|
m_settingsControl = m_service->viewfinderSettingsControl2();
|
||||||
|
|
||||||
|
return !m_settingsControl.isNull();
|
||||||
|
}
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
#include "moc_avfcameraviewfindersettingscontrol.cpp"
|
#include "moc_avfcameraviewfindersettingscontrol.cpp"
|
||||||
|
|||||||
Reference in New Issue
Block a user