diff options
Diffstat (limited to 'src/plugins/avfoundation')
4 files changed, 184 insertions, 0 deletions
diff --git a/src/plugins/avfoundation/camera/avfcameraservice.h b/src/plugins/avfoundation/camera/avfcameraservice.h index fffa1442..babee3dc 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.h +++ b/src/plugins/avfoundation/camera/avfcameraservice.h @@ -56,6 +56,7 @@ class AVFCameraFocusControl; class AVFCameraExposureControl; class AVFCameraZoomControl; class AVFCameraViewfinderSettingsControl2; +class AVFCameraViewfinderSettingsControl; class AVFCameraService : public QMediaService { @@ -79,6 +80,7 @@ public: AVFCameraZoomControl *cameraZoomControl() const {return m_cameraZoomControl; } AVFCameraRendererControl *videoOutput() const {return m_videoOutput; } AVFCameraViewfinderSettingsControl2 *viewfinderSettingsControl2() const {return m_viewfinderSettingsControl2; } + AVFCameraViewfinderSettingsControl *viewfinderSettingsControl() const {return m_viewfinderSettingsControl; } private: AVFCameraSession *m_session; @@ -94,6 +96,7 @@ private: AVFCameraExposureControl *m_cameraExposureControl; AVFCameraZoomControl *m_cameraZoomControl; AVFCameraViewfinderSettingsControl2 *m_viewfinderSettingsControl2; + AVFCameraViewfinderSettingsControl *m_viewfinderSettingsControl; }; QT_END_NAMESPACE diff --git a/src/plugins/avfoundation/camera/avfcameraservice.mm b/src/plugins/avfoundation/camera/avfcameraservice.mm index 188dc821..f9c7e5ae 100644 --- a/src/plugins/avfoundation/camera/avfcameraservice.mm +++ b/src/plugins/avfoundation/camera/avfcameraservice.mm @@ -86,6 +86,7 @@ AVFCameraService::AVFCameraService(QObject *parent): m_cameraZoomControl = new AVFCameraZoomControl(this); #endif m_viewfinderSettingsControl2 = new AVFCameraViewfinderSettingsControl2(this); + m_viewfinderSettingsControl = new AVFCameraViewfinderSettingsControl(this); } AVFCameraService::~AVFCameraService() @@ -110,6 +111,7 @@ AVFCameraService::~AVFCameraService() delete m_cameraZoomControl; #endif delete m_viewfinderSettingsControl2; + delete m_viewfinderSettingsControl; delete m_session; } @@ -147,6 +149,9 @@ QMediaControl *AVFCameraService::requestControl(const char *name) if (qstrcmp(name, QCameraViewfinderSettingsControl2_iid) == 0) return m_viewfinderSettingsControl2; + if (qstrcmp(name, QCameraViewfinderSettingsControl_iid) == 0) + return m_viewfinderSettingsControl; + if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) { AVFMediaVideoProbeControl *videoProbe = 0; videoProbe = new AVFMediaVideoProbeControl(this); diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h index d2864c62..fccc938a 100644 --- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h +++ b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.h @@ -38,6 +38,7 @@ #include <QtMultimedia/qcameraviewfindersettings.h> #include <QtMultimedia/qvideoframe.h> +#include <QtCore/qpointer.h> #include <QtCore/qglobal.h> #include <QtCore/qsize.h> @@ -56,6 +57,7 @@ class AVFCameraViewfinderSettingsControl2 : public QCameraViewfinderSettingsCont Q_OBJECT friend class AVFCameraSession; + friend class AVFCameraViewfinderSettingsControl; public: AVFCameraViewfinderSettingsControl2(AVFCameraService *service); @@ -86,6 +88,27 @@ private: 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 #endif diff --git a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm index c9d04f62..c5aa5733 100644 --- a/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm +++ b/src/plugins/avfoundation/camera/avfcameraviewfindersettingscontrol.mm @@ -574,6 +574,159 @@ bool AVFCameraViewfinderSettingsControl2::updateAVFoundationObjects() const 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 #include "moc_avfcameraviewfindersettingscontrol.cpp" |