diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2014-12-12 12:00:06 +0100 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-01-13 13:34:41 +0100 |
commit | fe21ee675e72f7cb3936db6aa01862cfd322ce50 (patch) | |
tree | 8d2caa1d13b79cff554a7fbb8b98051c0695d683 | |
parent | c31d8cddd0a2e1f1ee622bc9ea07d038191ceea2 (diff) |
New camera viewfinder settings API.
There already was a control interface for the viewfinder settings
but no real public C++ API and a partial QML API.
This patch adds a new C++ API and improves the QML API.
Supported viewfinder settings are resolution, minimumFrameRate,
maximumFrameRate and pixelFormat. The camera can be queried for
the supported values for each of these settings.
A new control interface was created to match the new API.
Change-Id: I289fea038fe46277a5516c956a64280da09ed985
Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
20 files changed, 1171 insertions, 43 deletions
diff --git a/src/imports/multimedia/multimedia.cpp b/src/imports/multimedia/multimedia.cpp index 01b037a79..8b2287ce4 100644 --- a/src/imports/multimedia/multimedia.cpp +++ b/src/imports/multimedia/multimedia.cpp @@ -105,6 +105,7 @@ public: // 5.5 types qmlRegisterUncreatableType<QDeclarativeCameraImageProcessing, 1>(uri, 5, 5, "CameraImageProcessing", trUtf8("CameraImageProcessing is provided by Camera")); + qmlRegisterRevision<QDeclarativeCamera, 2>(uri, 5, 5); qmlRegisterType<QDeclarativeMediaMetaData>(); } diff --git a/src/imports/multimedia/qdeclarativecamera.cpp b/src/imports/multimedia/qdeclarativecamera.cpp index 61ac518c7..bec91f199 100644 --- a/src/imports/multimedia/qdeclarativecamera.cpp +++ b/src/imports/multimedia/qdeclarativecamera.cpp @@ -989,20 +989,34 @@ QDeclarativeMediaMetaData *QDeclarativeCamera::metaData() } /*! + \qmlpropertygroup QtMultimedia::Camera::viewfinder \qmlproperty size QtMultimedia::Camera::viewfinder.resolution + \qmlproperty real QtMultimedia::Camera::viewfinder.minimumFrameRate + \qmlproperty real QtMultimedia::Camera::viewfinder.maximumFrameRate - This property holds the resolution of the camera viewfinder. If no - resolution is given the backend will use a default value. + These properties hold the viewfinder settings. - \since 5.4 -*/ + \c viewfinder.resolution holds the resolution of the camera viewfinder. If no + resolution is given or if it is empty, the backend uses a default value. -/*! - \qmlproperty real QtMultimedia::Camera::viewfinder.minimumFrameRate - \qmlproperty real QtMultimedia::Camera::viewfinder.maximumFrameRate + \c viewfinder.minimumFrameRate holds the minimum frame rate for the viewfinder in + frames per second. If no value is given or if set to \c 0, the backend uses a default value. + + \c viewfinder.maximumFrameRate holds the maximum frame rate for the viewfinder in + frames per second. If no value is given or if set to \c 0, the backend uses a default value. + + If \c viewfinder.minimumFrameRate is equal to \c viewfinder.maximumFrameRate, the frame rate is + fixed. If not, the actual frame rate fluctuates between the two values. - These properties hold the limits of the preferred frame rate for the - viewfinder in frames per second. + Changing the viewfinder settings while the camera is in the \c Camera.ActiveState state may + cause the camera to be restarted. + + If the camera is used to capture videos or images, the viewfinder settings might be + ignored if they conflict with the capture settings. You can check the actual viewfinder settings + once the camera is in the \c Camera.ActiveStatus status. + + Supported values can be retrieved with supportedViewfinderResolutions() and + supportedViewfinderFrameRateRanges(). \since 5.4 */ @@ -1015,6 +1029,79 @@ QDeclarativeCameraViewfinder *QDeclarativeCamera::viewfinder() return m_viewfinder; } +/*! + \qmlmethod list<size> QtMultimedia::Camera::supportedViewfinderResolutions(real minimumFrameRate = undefined, real maximumFrameRate = undefined) + + Returns a list of supported viewfinder resolutions. + + If both optional parameters \a minimumFrameRate and \a maximumFrameRate are specified, the + returned list is reduced to resolutions supported for the given frame rate range. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa {QtMultimedia::Camera::viewfinder}{viewfinder} + + \since 5.5 +*/ +QJSValue QDeclarativeCamera::supportedViewfinderResolutions(qreal minimumFrameRate, qreal maximumFrameRate) +{ + QQmlEngine *engine = qmlEngine(this); + + QCameraViewfinderSettings settings; + settings.setMinimumFrameRate(minimumFrameRate); + settings.setMaximumFrameRate(maximumFrameRate); + QList<QSize> resolutions = m_camera->supportedViewfinderResolutions(settings); + + QJSValue supportedResolutions = engine->newArray(resolutions.count()); + int i = 0; + Q_FOREACH (const QSize &resolution, resolutions) { + QJSValue size = engine->newObject(); + size.setProperty(QStringLiteral("width"), resolution.width()); + size.setProperty(QStringLiteral("height"), resolution.height()); + supportedResolutions.setProperty(i++, size); + } + + return supportedResolutions; +} + +/*! + \qmlmethod list<object> QtMultimedia::Camera::supportedViewfinderFrameRateRanges(size resolution = undefined) + + Returns a list of supported viewfinder frame rate ranges. + + Each range object in the list has the \c minimumFrameRate and \c maximumFrameRate properties. + + If the optional parameter \a resolution is specified, the returned list is reduced to frame rate + ranges supported for the given \a resolution. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa {QtMultimedia::Camera::viewfinder}{viewfinder} + + \since 5.5 +*/ +QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QSize &resolution) +{ + QQmlEngine *engine = qmlEngine(this); + + QCameraViewfinderSettings settings; + settings.setResolution(resolution); + QList<QCamera::FrameRateRange> frameRateRanges = m_camera->supportedViewfinderFrameRateRanges(settings); + + QJSValue supportedFrameRateRanges = engine->newArray(frameRateRanges.count()); + int i = 0; + Q_FOREACH (const QCamera::FrameRateRange &frameRateRange, frameRateRanges) { + QJSValue range = engine->newObject(); + range.setProperty(QStringLiteral("minimumFrameRate"), frameRateRange.first); + range.setProperty(QStringLiteral("maximumFrameRate"), frameRateRange.second); + supportedFrameRateRanges.setProperty(i++, range); + } + + return supportedFrameRateRanges; +} + QT_END_NAMESPACE #include "moc_qdeclarativecamera_p.cpp" diff --git a/src/imports/multimedia/qdeclarativecamera_p.h b/src/imports/multimedia/qdeclarativecamera_p.h index 4bc60652e..df1820dae 100644 --- a/src/imports/multimedia/qdeclarativecamera_p.h +++ b/src/imports/multimedia/qdeclarativecamera_p.h @@ -294,6 +294,11 @@ public Q_SLOTS: void setOpticalZoom(qreal); void setDigitalZoom(qreal); + Q_REVISION(2) QJSValue supportedViewfinderResolutions(qreal minimumFrameRate = 0.0, + qreal maximumFrameRate = 0.0); + + Q_REVISION(2) QJSValue supportedViewfinderFrameRateRanges(const QSize &resolution = QSize()); + Q_SIGNALS: void errorChanged(); void error(QDeclarativeCamera::Error errorCode, const QString &errorString); diff --git a/src/imports/multimedia/qdeclarativecameraviewfinder.cpp b/src/imports/multimedia/qdeclarativecameraviewfinder.cpp index 66d4e1bbc..abb0b6290 100644 --- a/src/imports/multimedia/qdeclarativecameraviewfinder.cpp +++ b/src/imports/multimedia/qdeclarativecameraviewfinder.cpp @@ -42,68 +42,76 @@ QT_BEGIN_NAMESPACE QDeclarativeCameraViewfinder::QDeclarativeCameraViewfinder(QCamera *camera, QObject *parent) : QObject(parent) , m_camera(camera) - , m_control(0) { - if (QMediaService *service = m_camera->service()) - m_control = service->requestControl<QCameraViewfinderSettingsControl *>(); + connect(m_camera, &QCamera::statusChanged, + this, &QDeclarativeCameraViewfinder::_q_cameraStatusChanged); } QDeclarativeCameraViewfinder::~QDeclarativeCameraViewfinder() { - if (m_control) { - if (QMediaService *service = m_camera->service()) - service->releaseControl(m_control); - } } QSize QDeclarativeCameraViewfinder::resolution() const { - return m_control - ? m_control->viewfinderParameter(QCameraViewfinderSettingsControl::Resolution).value<QSize>() - : QSize(); + return m_settings.resolution(); } -void QDeclarativeCameraViewfinder::setResolution(const QSize &resolution) +void QDeclarativeCameraViewfinder::setResolution(const QSize &res) { - if (m_control) { - m_control->setViewfinderParameter( - QCameraViewfinderSettingsControl::Resolution, resolution); + if (res != m_settings.resolution()) { + m_settings = m_camera->viewfinderSettings(); + m_settings.setResolution(res); + m_camera->setViewfinderSettings(m_settings); emit resolutionChanged(); } } qreal QDeclarativeCameraViewfinder::minimumFrameRate() const { - return m_control - ? m_control->viewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate).value<qreal>() - : 0.0; + return m_settings.minimumFrameRate(); } void QDeclarativeCameraViewfinder::setMinimumFrameRate(qreal frameRate) { - if (m_control) { - m_control->setViewfinderParameter( - QCameraViewfinderSettingsControl::MinimumFrameRate, frameRate); + if (frameRate != minimumFrameRate()) { + m_settings = m_camera->viewfinderSettings(); + m_settings.setMinimumFrameRate(frameRate); + m_camera->setViewfinderSettings(m_settings); emit minimumFrameRateChanged(); } } qreal QDeclarativeCameraViewfinder::maximumFrameRate() const { - return m_control - ? m_control->viewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate).value<qreal>() - : 0.0; + return m_settings.maximumFrameRate(); } void QDeclarativeCameraViewfinder::setMaximumFrameRate(qreal frameRate) { - if (m_control) { - m_control->setViewfinderParameter( - QCameraViewfinderSettingsControl::MaximumFrameRate, frameRate); + if (frameRate != maximumFrameRate()) { + m_settings = m_camera->viewfinderSettings(); + m_settings.setMaximumFrameRate(frameRate); + m_camera->setViewfinderSettings(m_settings); emit maximumFrameRateChanged(); } } +void QDeclarativeCameraViewfinder::_q_cameraStatusChanged(QCamera::Status status) +{ + // Settings values might change when the camera starts, for example if the settings are + // undefined, if unsupported values were set or if the settings conflict with capture settings. + if (status == QCamera::ActiveStatus) { + QCameraViewfinderSettings oldSettings = m_settings; + m_settings = m_camera->viewfinderSettings(); + if (oldSettings.resolution() != m_settings.resolution()) + emit resolutionChanged(); + if (oldSettings.minimumFrameRate() != m_settings.minimumFrameRate()) + emit minimumFrameRateChanged(); + if (oldSettings.maximumFrameRate() != m_settings.maximumFrameRate()) + emit maximumFrameRateChanged(); + } +} + QT_END_NAMESPACE #include "moc_qdeclarativecameraviewfinder_p.cpp" diff --git a/src/imports/multimedia/qdeclarativecameraviewfinder_p.h b/src/imports/multimedia/qdeclarativecameraviewfinder_p.h index 3597ca0cc..2df03584a 100644 --- a/src/imports/multimedia/qdeclarativecameraviewfinder_p.h +++ b/src/imports/multimedia/qdeclarativecameraviewfinder_p.h @@ -78,9 +78,12 @@ Q_SIGNALS: void minimumFrameRateChanged(); void maximumFrameRateChanged(); +private Q_SLOTS: + void _q_cameraStatusChanged(QCamera::Status status); + private: QCamera *m_camera; - QCameraViewfinderSettingsControl *m_control; + QCameraViewfinderSettings m_settings; }; QT_END_NAMESPACE diff --git a/src/multimedia/camera/camera.pri b/src/multimedia/camera/camera.pri index 0e0031fd9..29ed96668 100644 --- a/src/multimedia/camera/camera.pri +++ b/src/multimedia/camera/camera.pri @@ -9,7 +9,8 @@ PUBLIC_HEADERS += \ camera/qcameraexposure.h \ camera/qcamerafocus.h \ camera/qcameraimageprocessing.h \ - camera/qcamerainfo.h + camera/qcamerainfo.h \ + camera/qcameraviewfindersettings.h SOURCES += \ camera/qcamera.cpp \ @@ -17,5 +18,5 @@ SOURCES += \ camera/qcamerafocus.cpp \ camera/qcameraimageprocessing.cpp \ camera/qcameraimagecapture.cpp \ - camera/qcamerainfo.cpp - + camera/qcamerainfo.cpp \ + camera/qcameraviewfindersettings.cpp diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp index 6ba106f41..cdd65a18c 100644 --- a/src/multimedia/camera/qcamera.cpp +++ b/src/multimedia/camera/qcamera.cpp @@ -45,6 +45,7 @@ #include <qcameraimagecapturecontrol.h> #include <qvideodeviceselectorcontrol.h> #include <qcamerainfocontrol.h> +#include <qcameraviewfindersettingscontrol.h> #include <QDebug> @@ -64,6 +65,16 @@ static void qRegisterCameraMetaTypes() Q_CONSTRUCTOR_FUNCTION(qRegisterCameraMetaTypes) +static bool qt_sizeLessThan(const QSize &s1, const QSize &s2) +{ + return (s1.width() * s1.height()) < (s2.width() * s2.height()); +} + +static bool qt_frameRateRangeLessThan(const QCamera::FrameRateRange &s1, const QCamera::FrameRateRange &s2) +{ + return s1.second < s2.second; +} + /*! \class QCamera @@ -168,6 +179,9 @@ void QCameraPrivate::initControls() locksControl = qobject_cast<QCameraLocksControl *>(service->requestControl(QCameraLocksControl_iid)); deviceControl = qobject_cast<QVideoDeviceSelectorControl*>(service->requestControl(QVideoDeviceSelectorControl_iid)); infoControl = qobject_cast<QCameraInfoControl*>(service->requestControl(QCameraInfoControl_iid)); + viewfinderSettingsControl2 = qobject_cast<QCameraViewfinderSettingsControl2*>(service->requestControl(QCameraViewfinderSettingsControl2_iid)); + if (!viewfinderSettingsControl2) + viewfinderSettingsControl = qobject_cast<QCameraViewfinderSettingsControl*>(service->requestControl(QCameraViewfinderSettingsControl_iid)); if (control) { q->connect(control, SIGNAL(stateChanged(QCamera::State)), q, SLOT(_q_updateState(QCamera::State))); @@ -189,6 +203,8 @@ void QCameraPrivate::initControls() locksControl = 0; deviceControl = 0; infoControl = 0; + viewfinderSettingsControl = 0; + viewfinderSettingsControl2 = 0; error = QCamera::ServiceMissingError; errorString = QCamera::tr("The camera service is missing"); @@ -210,6 +226,10 @@ void QCameraPrivate::clear() service->releaseControl(deviceControl); if (infoControl) service->releaseControl(infoControl); + if (viewfinderSettingsControl) + service->releaseControl(viewfinderSettingsControl); + if (viewfinderSettingsControl2) + service->releaseControl(viewfinderSettingsControl2); provider->releaseService(service); } @@ -221,6 +241,8 @@ void QCameraPrivate::clear() locksControl = 0; deviceControl = 0; infoControl = 0; + viewfinderSettingsControl = 0; + viewfinderSettingsControl2 = 0; service = 0; } @@ -517,6 +539,219 @@ void QCamera::setViewfinder(QAbstractVideoSurface *surface) } /*! + Returns the viewfinder settings being used by the camera. + + Settings may change when the camera is started, for example if the viewfinder settings + are undefined or if unsupported values are set. + + If viewfinder settings are not supported by the camera, it always returns a null + QCameraViewfinderSettings object. + + \sa setViewfinderSettings() + + \since 5.5 +*/ +QCameraViewfinderSettings QCamera::viewfinderSettings() const +{ + Q_D(const QCamera); + + if (d->viewfinderSettingsControl2) + return d->viewfinderSettingsControl2->viewfinderSettings(); + + QCameraViewfinderSettings settings; + if (d->viewfinderSettingsControl) { + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution)) + settings.setResolution(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::Resolution).toSize()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate)) + settings.setMinimumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate).toReal()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate)) + settings.setMaximumFrameRate(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate).toReal()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio)) + settings.setPixelAspectRatio(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio).toSize()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat)) + settings.setPixelFormat(qvariant_cast<QVideoFrame::PixelFormat>(d->viewfinderSettingsControl->viewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat))); + } + return settings; +} + +/*! + Sets the viewfinder \a settings. + + If some parameters are not specified, or null settings are passed, the camera will choose + default values. + + If the camera is used to capture videos or images, the viewfinder settings might be + ignored if they conflict with the capture settings. You can check the actual viewfinder settings + once the camera is in the \c QCamera::ActiveStatus status. + + Changing the viewfinder settings while the camera is in the QCamera::ActiveState state may + cause the camera to be restarted. + + \sa viewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(), + supportedViewfinderPixelFormats() + + \since 5.5 +*/ +void QCamera::setViewfinderSettings(const QCameraViewfinderSettings &settings) +{ + Q_D(QCamera); + + if (d->viewfinderSettingsControl || d->viewfinderSettingsControl2) + d->_q_preparePropertyChange(QCameraControl::ViewfinderSettings); + + if (d->viewfinderSettingsControl2) { + d->viewfinderSettingsControl2->setViewfinderSettings(settings); + + } else if (d->viewfinderSettingsControl) { + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::Resolution)) + d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::Resolution, settings.resolution()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MinimumFrameRate)) + d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MinimumFrameRate, settings.minimumFrameRate()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::MaximumFrameRate)) + d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::MaximumFrameRate, settings.maximumFrameRate()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelAspectRatio)) + d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelAspectRatio, settings.pixelAspectRatio()); + + if (d->viewfinderSettingsControl->isViewfinderParameterSupported(QCameraViewfinderSettingsControl::PixelFormat)) + d->viewfinderSettingsControl->setViewfinderParameter(QCameraViewfinderSettingsControl::PixelFormat, settings.pixelFormat()); + } +} + +/*! + Returns a list of supported viewfinder settings. + + The list is ordered by preference; preferred settings come first. + + The optional \a settings argument can be used to conveniently filter the results. + If \a settings is non null, the returned list is reduced to settings matching the given partial + \a settings. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa setViewfinderSettings(), supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges(), + supportedViewfinderPixelFormats() + + \since 5.5 +*/ +QList<QCameraViewfinderSettings> QCamera::supportedViewfinderSettings(const QCameraViewfinderSettings &settings) const +{ + Q_D(const QCamera); + + if (!d->viewfinderSettingsControl2) + return QList<QCameraViewfinderSettings>(); + + if (settings.isNull()) + return d->viewfinderSettingsControl2->supportedViewfinderSettings(); + + QList<QCameraViewfinderSettings> results; + QList<QCameraViewfinderSettings> supported = d->viewfinderSettingsControl2->supportedViewfinderSettings(); + Q_FOREACH (const QCameraViewfinderSettings &s, supported) { + if ((settings.resolution().isEmpty() || settings.resolution() == s.resolution()) + && (qFuzzyIsNull(settings.minimumFrameRate()) || qFuzzyCompare((float)settings.minimumFrameRate(), (float)s.minimumFrameRate())) + && (qFuzzyIsNull(settings.maximumFrameRate()) || qFuzzyCompare((float)settings.maximumFrameRate(), (float)s.maximumFrameRate())) + && (settings.pixelFormat() == QVideoFrame::Format_Invalid || settings.pixelFormat() == s.pixelFormat()) + && (settings.pixelAspectRatio() == QSize(1, 1) || settings.pixelAspectRatio() == s.pixelAspectRatio())) { + results.append(s); + } + } + + return results; +} + +/*! + Returns a list of supported viewfinder resolutions. + + This is a convenience function which retrieves unique resolutions from the supported settings. + + If non null viewfinder \a settings are passed, the returned list is reduced to resolutions + supported with partial \a settings applied. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa QCameraViewfinderSettings::resolution(), setViewfinderSettings() + + \since 5.5 +*/ +QList<QSize> QCamera::supportedViewfinderResolutions(const QCameraViewfinderSettings &settings) const +{ + QList<QSize> resolutions; + QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings); + Q_FOREACH (const QCameraViewfinderSettings &s, capabilities) { + if (!resolutions.contains(s.resolution())) + resolutions.append(s.resolution()); + } + std::sort(resolutions.begin(), resolutions.end(), qt_sizeLessThan); + + return resolutions; +} + +/*! + Returns a list of supported viewfinder frame rate ranges. + + This is a convenience function which retrieves unique frame rate ranges from the supported settings. + + If non null viewfinder \a settings are passed, the returned list is reduced to frame rate ranges + supported with partial \a settings applied. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa QCameraViewfinderSettings::minimumFrameRate(), QCameraViewfinderSettings::maximumFrameRate(), + setViewfinderSettings() + + \since 5.5 +*/ +QList<QCamera::FrameRateRange> QCamera::supportedViewfinderFrameRateRanges(const QCameraViewfinderSettings &settings) const +{ + QList<QCamera::FrameRateRange> frameRateRanges; + QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings); + Q_FOREACH (const QCameraViewfinderSettings &s, capabilities) { + QCamera::FrameRateRange range(s.minimumFrameRate(), s.maximumFrameRate()); + if (!frameRateRanges.contains(range)) + frameRateRanges.append(range); + } + std::sort(frameRateRanges.begin(), frameRateRanges.end(), qt_frameRateRangeLessThan); + + return frameRateRanges; +} + +/*! + Returns a list of supported viewfinder pixel formats. + + This is a convenience function which retrieves unique pixel formats from the supported settings. + + If non null viewfinder \a settings are passed, the returned list is reduced to pixel formats + supported with partial \a settings applied. + + The camera must be loaded before calling this function, otherwise the returned list + is empty. + + \sa QCameraViewfinderSettings::pixelFormat(), setViewfinderSettings() + + \since 5.5 +*/ +QList<QVideoFrame::PixelFormat> QCamera::supportedViewfinderPixelFormats(const QCameraViewfinderSettings &settings) const +{ + QList<QVideoFrame::PixelFormat> pixelFormats; + QList<QCameraViewfinderSettings> capabilities = supportedViewfinderSettings(settings); + Q_FOREACH (const QCameraViewfinderSettings &s, capabilities) { + if (!pixelFormats.contains(s.pixelFormat())) + pixelFormats.append(s.pixelFormat()); + } + + return pixelFormats; +} + +/*! Returns the error state of the object. */ @@ -793,6 +1028,17 @@ void QCamera::unlock() /*! + \typedef QCamera::FrameRateRange + + This is a typedef for QPair<qreal, qreal>. + + A frame rate range contains a minimum and a maximum frame rate, respectively the first and + second element of the pair. If the minimum frame rate is equal to the maximum frame rate, the + frame rate is fixed. If not, the actual frame rate fluctuates between the minimum and the maximum. +*/ + + +/*! \enum QCamera::State \value UnloadedState The initial camera state, with camera not loaded, diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h index 9c6fc8f8a..0c5881a3e 100644 --- a/src/multimedia/camera/qcamera.h +++ b/src/multimedia/camera/qcamera.h @@ -47,6 +47,7 @@ #include <QtMultimedia/qcameraexposure.h> #include <QtMultimedia/qcamerafocus.h> #include <QtMultimedia/qcameraimageprocessing.h> +#include <QtMultimedia/qcameraviewfindersettings.h> #include <QtMultimedia/qmediaenumdebug.h> @@ -76,6 +77,8 @@ class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject Q_ENUMS(LockType) Q_ENUMS(Position) public: + typedef QPair<qreal, qreal> FrameRateRange; + enum Status { UnavailableStatus, UnloadedStatus, @@ -169,6 +172,21 @@ public: void setViewfinder(QGraphicsVideoItem *viewfinder); void setViewfinder(QAbstractVideoSurface *surface); + QCameraViewfinderSettings viewfinderSettings() const; + void setViewfinderSettings(const QCameraViewfinderSettings &settings); + + QList<QCameraViewfinderSettings> supportedViewfinderSettings( + const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const; + + QList<QSize> supportedViewfinderResolutions( + const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const; + + QList<FrameRateRange> supportedViewfinderFrameRateRanges( + const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const; + + QList<QVideoFrame::PixelFormat> supportedViewfinderPixelFormats( + const QCameraViewfinderSettings &settings = QCameraViewfinderSettings()) const; + Error error() const; QString errorString() const; diff --git a/src/multimedia/camera/qcamera_p.h b/src/multimedia/camera/qcamera_p.h index d43c510bc..7e81e55ba 100644 --- a/src/multimedia/camera/qcamera_p.h +++ b/src/multimedia/camera/qcamera_p.h @@ -56,6 +56,8 @@ class QCameraControl; class QVideoDeviceSelectorControl; class QCameraLocksControl; class QCameraInfoControl; +class QCameraViewfinderSettingsControl; +class QCameraViewfinderSettingsControl2; class QCameraPrivate : public QMediaObjectPrivate { @@ -68,6 +70,8 @@ public: deviceControl(0), locksControl(0), infoControl(0), + viewfinderSettingsControl(0), + viewfinderSettingsControl2(0), viewfinder(0), capture(0), state(QCamera::UnloadedState), @@ -91,6 +95,8 @@ public: QVideoDeviceSelectorControl *deviceControl; QCameraLocksControl *locksControl; QCameraInfoControl *infoControl; + QCameraViewfinderSettingsControl *viewfinderSettingsControl; + QCameraViewfinderSettingsControl2 *viewfinderSettingsControl2; QCameraExposure *cameraExposure; QCameraFocus *cameraFocus; diff --git a/src/multimedia/camera/qcameraviewfindersettings.cpp b/src/multimedia/camera/qcameraviewfindersettings.cpp new file mode 100644 index 000000000..6bcc253a2 --- /dev/null +++ b/src/multimedia/camera/qcameraviewfindersettings.cpp @@ -0,0 +1,311 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qcameraviewfindersettings.h" + +QT_BEGIN_NAMESPACE + +static void qRegisterViewfinderSettingsMetaType() +{ + qRegisterMetaType<QCameraViewfinderSettings>(); +} + +Q_CONSTRUCTOR_FUNCTION(qRegisterViewfinderSettingsMetaType) + + +class QCameraViewfinderSettingsPrivate : public QSharedData +{ +public: + QCameraViewfinderSettingsPrivate() : + isNull(true), + minimumFrameRate(0.0), + maximumFrameRate(0.0), + pixelFormat(QVideoFrame::Format_Invalid), + pixelAspectRatio(1, 1) + { + } + + QCameraViewfinderSettingsPrivate(const QCameraViewfinderSettingsPrivate &other): + QSharedData(other), + isNull(other.isNull), + resolution(other.resolution), + minimumFrameRate(other.minimumFrameRate), + maximumFrameRate(other.maximumFrameRate), + pixelFormat(other.pixelFormat), + pixelAspectRatio(other.pixelAspectRatio) + { + } + + bool isNull; + QSize resolution; + qreal minimumFrameRate; + qreal maximumFrameRate; + QVideoFrame::PixelFormat pixelFormat; + QSize pixelAspectRatio; + +private: + QCameraViewfinderSettingsPrivate& operator=(const QCameraViewfinderSettingsPrivate &other); +}; + + +/*! + \class QCameraViewfinderSettings + \since 5.5 + \brief The QCameraViewfinderSettings class provides a set of viewfinder settings. + + \inmodule QtMultimedia + \ingroup multimedia + \ingroup multimedia_camera + + A viewfinder settings object is used to specify the viewfinder settings used by QCamera. + Viewfinder settings are selected by constructing a QCameraViewfinderSettings object, + setting the desired properties and then passing it to a QCamera instance using the + QCamera::setViewfinderSettings() function. + + \snippet multimedia-snippets/camera.cpp Camera viewfinder settings + + Different cameras may have different capabilities. The application should query the camera + capabilities before setting parameters. For example, the application should call + QCamera::supportedViewfinderResolutions() before calling setResolution(). + + \sa QCamera +*/ + +/*! + Constructs a null viewfinder settings object. +*/ +QCameraViewfinderSettings::QCameraViewfinderSettings() + : d(new QCameraViewfinderSettingsPrivate) +{ +} + +/*! + Constructs a copy of the viewfinder settings object \a other. +*/ +QCameraViewfinderSettings::QCameraViewfinderSettings(const QCameraViewfinderSettings &other) + : d(other.d) +{ + +} + +/*! + Destroys a viewfinder settings object. +*/ +QCameraViewfinderSettings::~QCameraViewfinderSettings() +{ + +} + +/*! + Assigns the value of \a other to a viewfinder settings object. +*/ +QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(const QCameraViewfinderSettings &other) +{ + d = other.d; + return *this; +} + +/*! + Determines if \a other is of equal value to a viewfinder settings object. + + Returns true if the settings objects are of equal value, and false if they + are not of equal value. +*/ +bool QCameraViewfinderSettings::operator==(const QCameraViewfinderSettings &other) const +{ + return (d == other.d) || + (d->isNull == other.d->isNull && + d->resolution == other.d->resolution && + qFuzzyCompare(d->minimumFrameRate, other.d->minimumFrameRate) && + qFuzzyCompare(d->maximumFrameRate, other.d->maximumFrameRate) && + d->pixelFormat == other.d->pixelFormat && + d->pixelAspectRatio == other.d->pixelAspectRatio); +} + +/*! + Determines if \a other is of equal value to a viewfinder settings object. + + Returns true if the settings objects are not of equal value, and false if + they are of equal value. +*/ +bool QCameraViewfinderSettings::operator!=(const QCameraViewfinderSettings &other) const +{ + return !(*this == other); +} + +/*! + Identifies if a viewfinder settings object is uninitalized. + + Returns true if the settings are null, and false if they are not. +*/ +bool QCameraViewfinderSettings::isNull() const +{ + return d->isNull; +} + +/*! + Returns the viewfinder resolution. +*/ +QSize QCameraViewfinderSettings::resolution() const +{ + return d->resolution; +} + +/*! + Sets the viewfinder \a resolution. + + If the given \a resolution is empty, the backend makes an optimal choice based on the + supported resolutions and the other viewfinder settings. + + If the camera is used to capture videos or images, the viewfinder resolution might be + ignored if it conflicts with the capture resolution. + + \sa QVideoEncoderSettings::setResolution(), QImageEncoderSettings::setResolution(), + QCamera::supportedViewfinderResolutions() +*/ +void QCameraViewfinderSettings::setResolution(const QSize &resolution) +{ + d->isNull = false; + d->resolution = resolution; +} + +/*! + \fn QCameraViewfinderSettings::setResolution(int width, int height) + + This is an overloaded function. + + Sets the \a width and \a height of the viewfinder resolution. +*/ + +/*! + Returns the viewfinder minimum frame rate in frames per second. + + \sa maximumFrameRate() +*/ +qreal QCameraViewfinderSettings::minimumFrameRate() const +{ + return d->minimumFrameRate; +} + +/*! + Sets the viewfinder minimum frame \a rate in frames per second. + + If the minimum frame \a rate is equal to the maximum frame rate, the frame rate is fixed. + If not, the actual frame rate fluctuates between the minimum and the maximum. + + If the given \a rate equals to \c 0, the backend makes an optimal choice based on the + supported frame rates and the other viewfinder settings. + + \sa setMaximumFrameRate(), QCamera::supportedViewfinderFrameRateRanges() +*/ +void QCameraViewfinderSettings::setMinimumFrameRate(qreal rate) +{ + d->isNull = false; + d->minimumFrameRate = rate; +} + +/*! + Returns the viewfinder maximum frame rate in frames per second. + + \sa minimumFrameRate() +*/ +qreal QCameraViewfinderSettings::maximumFrameRate() const +{ + return d->maximumFrameRate; +} + +/*! + Sets the viewfinder maximum frame \a rate in frames per second. + + If the maximum frame \a rate is equal to the minimum frame rate, the frame rate is fixed. + If not, the actual frame rate fluctuates between the minimum and the maximum. + + If the given \a rate equals to \c 0, the backend makes an optimal choice based on the + supported frame rates and the other viewfinder settings. + + \sa setMinimumFrameRate(), QCamera::supportedViewfinderFrameRateRanges() +*/ +void QCameraViewfinderSettings::setMaximumFrameRate(qreal rate) +{ + d->isNull = false; + d->maximumFrameRate = rate; +} + +/*! + Returns the viewfinder pixel format. +*/ +QVideoFrame::PixelFormat QCameraViewfinderSettings::pixelFormat() const +{ + return d->pixelFormat; +} + +/*! + Sets the viewfinder pixel \a format. + + If the given \a format is equal to QVideoFrame::Format_Invalid, the backend uses the + default format. + + \sa QCamera::supportedViewfinderPixelFormats() +*/ +void QCameraViewfinderSettings::setPixelFormat(QVideoFrame::PixelFormat format) +{ + d->isNull = false; + d->pixelFormat = format; +} + +/*! + Returns the viewfinder pixel aspect ratio. +*/ +QSize QCameraViewfinderSettings::pixelAspectRatio() const +{ + return d->pixelAspectRatio; +} + +/*! + Sets the viewfinder pixel aspect \a ratio. +*/ +void QCameraViewfinderSettings::setPixelAspectRatio(const QSize &ratio) +{ + d->isNull = false; + d->pixelAspectRatio = ratio; +} + +/*! + \fn QCameraViewfinderSettings::setPixelAspectRatio(int horizontal, int vertical) + + This is an overloaded function. + + Sets the \a horizontal and \a vertical elements of the viewfinder's pixel aspect ratio. +*/ + +QT_END_NAMESPACE diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h new file mode 100644 index 000000000..9f53c627e --- /dev/null +++ b/src/multimedia/camera/qcameraviewfindersettings.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QCAMERAVIEWFINDERSETTINGS_H +#define QCAMERAVIEWFINDERSETTINGS_H + +#include <QtCore/qsharedpointer.h> +#include <QtMultimedia/qtmultimediadefs.h> +#include <QtMultimedia/qvideoframe.h> + +QT_BEGIN_NAMESPACE + +class QCameraViewfinderSettingsPrivate; + +class Q_MULTIMEDIA_EXPORT QCameraViewfinderSettings +{ +public: + QCameraViewfinderSettings(); + QCameraViewfinderSettings(const QCameraViewfinderSettings& other); + + ~QCameraViewfinderSettings(); + + QCameraViewfinderSettings& operator=(const QCameraViewfinderSettings &other); + bool operator==(const QCameraViewfinderSettings &other) const; + bool operator!=(const QCameraViewfinderSettings &other) const; + + bool isNull() const; + + QSize resolution() const; + void setResolution(const QSize &); + inline void setResolution(int width, int height) + { setResolution(QSize(width, height)); } + + qreal minimumFrameRate() const; + void setMinimumFrameRate(qreal rate); + + qreal maximumFrameRate() const; + void setMaximumFrameRate(qreal rate); + + QVideoFrame::PixelFormat pixelFormat() const; + void setPixelFormat(QVideoFrame::PixelFormat format); + + QSize pixelAspectRatio() const; + void setPixelAspectRatio(const QSize &ratio); + inline void setPixelAspectRatio(int horizontal, int vertical) + { setPixelAspectRatio(QSize(horizontal, vertical)); } + +private: + QSharedDataPointer<QCameraViewfinderSettingsPrivate> d; +}; + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QCameraViewfinderSettings) + +#endif // QCAMERAVIEWFINDERSETTINGS_H diff --git a/src/multimedia/controls/qcameracontrol.cpp b/src/multimedia/controls/qcameracontrol.cpp index dfbc07ba4..34433792e 100644 --- a/src/multimedia/controls/qcameracontrol.cpp +++ b/src/multimedia/controls/qcameracontrol.cpp @@ -190,6 +190,7 @@ QCameraControl::~QCameraControl() \value VideoEncodingSettings Video encoder settings are changed, including audio, video and container settings. \value Viewfinder Viewfinder is changed. + \value ViewfinderSettings Viewfinder settings are changed. */ #include "moc_qcameracontrol.cpp" diff --git a/src/multimedia/controls/qcameracontrol.h b/src/multimedia/controls/qcameracontrol.h index 7a9066591..1a59152cc 100644 --- a/src/multimedia/controls/qcameracontrol.h +++ b/src/multimedia/controls/qcameracontrol.h @@ -53,7 +53,8 @@ public: CaptureMode = 1, ImageEncodingSettings = 2, VideoEncodingSettings = 3, - Viewfinder = 4 + Viewfinder = 4, + ViewfinderSettings = 5 }; ~QCameraControl(); diff --git a/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp b/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp index 7a1b74182..22c925e69 100644 --- a/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp +++ b/src/multimedia/controls/qcameraviewfindersettingscontrol.cpp @@ -50,13 +50,17 @@ QT_BEGIN_NAMESPACE The interface name of QCameraViewfinderSettingsControl is \c org.qt-project.qt.cameraviewfindersettingscontrol/5.0 as defined in QCameraViewfinderSettingsControl_iid. - \sa QMediaService::requestControl(), QCamera + \warning New backends should implement QCameraViewfinderSettingsControl2 instead. + Application developers should request this control only if QCameraViewfinderSettingsControl2 + is not available. + + \sa QMediaService::requestControl(), QCameraViewfinderSettingsControl2, QCamera */ /*! \macro QCameraViewfinderSettingsControl_iid - \c org.qt-project.qt.cameraviewfinderresettingscontrol/5.0 + \c org.qt-project.qt.cameraviewfindersettingscontrol/5.0 Defines the interface name of the QCameraViewfinderSettingsControl class. @@ -123,6 +127,73 @@ QCameraViewfinderSettingsControl::~QCameraViewfinderSettingsControl() with viewfinder settings, the camara configuration is usually preferred. */ + +/*! + \class QCameraViewfinderSettingsControl2 + \inmodule QtMultimedia + \ingroup multimedia_control + \since 5.5 + + \brief The QCameraViewfinderSettingsControl2 class provides access to the viewfinder settings + of a camera media service. + + The functionality provided by this control is exposed to application code through the QCamera class. + + The interface name of QCameraViewfinderSettingsControl2 is \c org.qt-project.qt.cameraviewfindersettingscontrol2/5.5 as + defined in QCameraViewfinderSettingsControl2_iid. + + \sa QMediaService::requestControl(), QCameraViewfinderSettings, QCamera +*/ + +/*! + \macro QCameraViewfinderSettingsControl2_iid + + \c org.qt-project.qt.cameraviewfindersettingscontrol2/5.5 + + Defines the interface name of the QCameraViewfinderSettingsControl2 class. + + \relates QCameraViewfinderSettingsControl2 +*/ + +/*! + Constructs a camera viewfinder settings control object with \a parent. +*/ +QCameraViewfinderSettingsControl2::QCameraViewfinderSettingsControl2(QObject *parent) + : QMediaControl(*new QMediaControlPrivate, parent) +{ +} + +/*! + Destroys the camera viewfinder settings control object. +*/ +QCameraViewfinderSettingsControl2::~QCameraViewfinderSettingsControl2() +{ +} + +/*! + \fn QCameraViewfinderSettingsControl2::supportedViewfinderSettings() const + + Returns a list of supported camera viewfinder settings. + + The list is ordered by preference; preferred settings come first. +*/ + +/*! + \fn QCameraViewfinderSettingsControl2::viewfinderSettings() const + + Returns the viewfinder settings. + + If undefined or unsupported values are passed to QCameraViewfinderSettingsControl2::setViewfinderSettings(), + this function returns the actual settings used by the camera viewfinder. These may be available + only once the camera is active. +*/ + +/*! + \fn QCameraViewfinderSettingsControl2::setViewfinderSettings(const QCameraViewfinderSettings &settings) + + Sets the camera viewfinder \a settings. +*/ + #include "moc_qcameraviewfindersettingscontrol.cpp" QT_END_NAMESPACE diff --git a/src/multimedia/controls/qcameraviewfindersettingscontrol.h b/src/multimedia/controls/qcameraviewfindersettingscontrol.h index ea6f19550..534667b8e 100644 --- a/src/multimedia/controls/qcameraviewfindersettingscontrol.h +++ b/src/multimedia/controls/qcameraviewfindersettingscontrol.h @@ -37,6 +37,7 @@ #define QCAMERAVIEWFINDERSETTINGSCONTROL_H #include <QtMultimedia/qmediacontrol.h> +#include <QtMultimedia/qcamera.h> QT_BEGIN_NAMESPACE @@ -69,6 +70,28 @@ protected: #define QCameraViewfinderSettingsControl_iid "org.qt-project.qt.cameraviewfindersettingscontrol/5.0" Q_MEDIA_DECLARE_CONTROL(QCameraViewfinderSettingsControl, QCameraViewfinderSettingsControl_iid) + +// Required for QDoc workaround +class QString; + +class Q_MULTIMEDIA_EXPORT QCameraViewfinderSettingsControl2 : public QMediaControl +{ + Q_OBJECT +public: + virtual ~QCameraViewfinderSettingsControl2(); + + virtual QList<QCameraViewfinderSettings> supportedViewfinderSettings() const = 0; + + virtual QCameraViewfinderSettings viewfinderSettings() const = 0; + virtual void setViewfinderSettings(const QCameraViewfinderSettings &settings) = 0; + +protected: + QCameraViewfinderSettingsControl2(QObject *parent = 0); +}; + +#define QCameraViewfinderSettingsControl2_iid "org.qt-project.qt.cameraviewfindersettingscontrol2/5.5" +Q_MEDIA_DECLARE_CONTROL(QCameraViewfinderSettingsControl2, QCameraViewfinderSettingsControl2_iid) + QT_END_NAMESPACE #endif // QCAMERAVIEWFINDERSETTINGSCONTROL_H diff --git a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp index 64fd254f4..705a74a73 100644 --- a/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp +++ b/src/multimedia/doc/snippets/multimedia-snippets/camera.cpp @@ -36,6 +36,7 @@ #include "qcamera.h" #include "qcamerainfo.h" #include "qcameraviewfinder.h" +#include "qcameraviewfindersettings.h" #include "qmediarecorder.h" #include "qcameraimagecapture.h" #include "qcameraimageprocessing.h" @@ -273,3 +274,15 @@ void camerafocus() } //! [Camera focus zones] } + +void camera_viewfindersettings() +{ + //! [Camera viewfinder settings] + QCameraViewfinderSettings viewfinderSettings; + viewfinderSettings.setResolution(640, 480); + viewfinderSettings.setMinimumFrameRate(15.0); + viewfinderSettings.setMaximumFrameRate(30.0); + + camera->setViewfinderSettings(viewfinderSettings); + //! [Camera viewfinder settings] +} diff --git a/tests/auto/unit/qcamera/tst_qcamera.cpp b/tests/auto/unit/qcamera/tst_qcamera.cpp index 6d3979dfc..004dd4366 100644 --- a/tests/auto/unit/qcamera/tst_qcamera.cpp +++ b/tests/auto/unit/qcamera/tst_qcamera.cpp @@ -88,6 +88,8 @@ private slots: void testCameraCapture(); void testCameraCaptureMetadata(); void testImageSettings(); + void testViewfinderSettings(); + void testViewfinderSettingsChange(); void testCameraLock(); void testCameraLockCancel(); void testCameraEncodingProperyChange(); @@ -874,6 +876,174 @@ void tst_QCamera::testImageSettings() QVERIFY(settings1 != settings2); } +void tst_QCamera::testViewfinderSettings() +{ + QCameraViewfinderSettings settings; + QVERIFY(settings.isNull()); + QVERIFY(settings == QCameraViewfinderSettings()); + + QCOMPARE(settings.resolution(), QSize()); + settings.setResolution(QSize(640, 480)); + QCOMPARE(settings.resolution(), QSize(640, 480)); + settings.setResolution(1280, 720); + QCOMPARE(settings.resolution(), QSize(1280, 720)); + QVERIFY(!settings.isNull()); + QVERIFY(settings != QCameraViewfinderSettings()); + + settings = QCameraViewfinderSettings(); + QVERIFY(qFuzzyIsNull(settings.minimumFrameRate())); + settings.setMinimumFrameRate(10.0); + QVERIFY(qFuzzyCompare(settings.minimumFrameRate(), 10.0)); + QVERIFY(qFuzzyIsNull(settings.maximumFrameRate())); + settings.setMaximumFrameRate(20.0); + QVERIFY(qFuzzyCompare(settings.maximumFrameRate(), 20.0)); + QVERIFY(!settings.isNull()); + + settings = QCameraViewfinderSettings(); + QCOMPARE(settings.pixelFormat(), QVideoFrame::Format_Invalid); + settings.setPixelFormat(QVideoFrame::Format_RGB32); + QCOMPARE(settings.pixelFormat(), QVideoFrame::Format_RGB32); + QVERIFY(!settings.isNull()); + + settings = QCameraViewfinderSettings(); + QCOMPARE(settings.pixelAspectRatio(), QSize(1, 1)); + settings.setPixelAspectRatio(QSize(2, 1)); + QCOMPARE(settings.pixelAspectRatio(), QSize(2, 1)); + settings.setPixelAspectRatio(3, 2); + QCOMPARE(settings.pixelAspectRatio(), QSize(3, 2)); + QVERIFY(!settings.isNull()); + + settings = QCameraViewfinderSettings(); + + { + QCameraViewfinderSettings settings1; + QCameraViewfinderSettings settings2; + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setResolution(800, 600); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + { + QCameraViewfinderSettings settings1; + QCameraViewfinderSettings settings2(settings1); + QCOMPARE(settings2, settings1); + + settings2 = settings1; + QCOMPARE(settings2, settings1); + QVERIFY(settings2.isNull()); + + settings1.setResolution(800, 600); + + QVERIFY(settings2.isNull()); + QVERIFY(!settings1.isNull()); + QVERIFY(settings1 != settings2); + } + + QCameraViewfinderSettings settings1; + QCameraViewfinderSettings settings2; + + settings1 = QCameraViewfinderSettings(); + settings1.setResolution(800,600); + settings2 = QCameraViewfinderSettings(); + settings2.setResolution(QSize(800,600)); + QVERIFY(settings1 == settings2); + settings2.setResolution(QSize(400,300)); + QVERIFY(settings1 != settings2); + + settings1 = QCameraViewfinderSettings(); + settings1.setMinimumFrameRate(10.0); + settings2 = QCameraViewfinderSettings(); + settings2.setMinimumFrameRate(10.0); + QVERIFY(settings1 == settings2); + settings2.setMinimumFrameRate(15.0); + QVERIFY(settings1 != settings2); + + settings1 = QCameraViewfinderSettings(); + settings1.setMaximumFrameRate(30.0); + settings2 = QCameraViewfinderSettings(); + settings2.setMaximumFrameRate(30.0); + QVERIFY(settings1 == settings2); + settings2.setMaximumFrameRate(15.0); + QVERIFY(settings1 != settings2); + + settings1 = QCameraViewfinderSettings(); + settings1.setPixelFormat(QVideoFrame::Format_YV12); + settings2 = QCameraViewfinderSettings(); + settings2.setPixelFormat(QVideoFrame::Format_YV12); + QVERIFY(settings1 == settings2); + settings2.setPixelFormat(QVideoFrame::Format_NV21); + QVERIFY(settings1 != settings2); + + settings1 = QCameraViewfinderSettings(); + settings1.setPixelAspectRatio(2,1); + settings2 = QCameraViewfinderSettings(); + settings2.setPixelAspectRatio(QSize(2,1)); + QVERIFY(settings1 == settings2); + settings2.setPixelAspectRatio(QSize(1,2)); + QVERIFY(settings1 != settings2); +} + +void tst_QCamera::testViewfinderSettingsChange() +{ + QCamera camera; + + QSignalSpy stateChangedSignal(&camera, SIGNAL(stateChanged(QCamera::State))); + QSignalSpy statusChangedSignal(&camera, SIGNAL(statusChanged(QCamera::Status))); + + camera.start(); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::ActiveStatus); + + QCOMPARE(stateChangedSignal.count(), 1); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start + camera.setViewfinderSettings(QCameraViewfinderSettings()); + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + //the settings change should trigger camera stop/start only once + camera.setViewfinderSettings(QCameraViewfinderSettings()); + camera.setViewfinderSettings(QCameraViewfinderSettings()); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QCOMPARE(camera.status(), QCamera::LoadedStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); + stateChangedSignal.clear(); + statusChangedSignal.clear(); + + QCOMPARE(camera.state(), QCamera::ActiveState); + QTRY_COMPARE(camera.status(), QCamera::ActiveStatus); + + QCOMPARE(stateChangedSignal.count(), 0); + QCOMPARE(statusChangedSignal.count(), 1); +} + void tst_QCamera::testCameraLock() { QCamera camera; diff --git a/tests/auto/unit/qmultimedia_common/mockcamera.pri b/tests/auto/unit/qmultimedia_common/mockcamera.pri index dbd7312b2..f6f97de1e 100644 --- a/tests/auto/unit/qmultimedia_common/mockcamera.pri +++ b/tests/auto/unit/qmultimedia_common/mockcamera.pri @@ -18,7 +18,8 @@ HEADERS *= \ ../qmultimedia_common/mockimageencodercontrol.h \ ../qmultimedia_common/mockcameracontrol.h \ ../qmultimedia_common/mockvideodeviceselectorcontrol.h \ - ../qmultimedia_common/mockcamerainfocontrol.h + ../qmultimedia_common/mockcamerainfocontrol.h \ + ../qmultimedia_common/mockcameraviewfindersettingscontrol.h include(mockvideo.pri) diff --git a/tests/auto/unit/qmultimedia_common/mockcameraservice.h b/tests/auto/unit/qmultimedia_common/mockcameraservice.h index f9ffcfdce..28fa0fd4d 100644 --- a/tests/auto/unit/qmultimedia_common/mockcameraservice.h +++ b/tests/auto/unit/qmultimedia_common/mockcameraservice.h @@ -51,6 +51,7 @@ #include "../qmultimedia_common/mockvideowindowcontrol.h" #include "../qmultimedia_common/mockvideodeviceselectorcontrol.h" #include "../qmultimedia_common/mockcamerainfocontrol.h" +#include "../qmultimedia_common/mockcameraviewfindersettingscontrol.h" class MockSimpleCameraService : public QMediaService { @@ -101,6 +102,7 @@ public: windowControl = new MockVideoWindowControl(this); mockVideoDeviceSelectorControl = new MockVideoDeviceSelectorControl(this); mockCameraInfoControl = new MockCameraInfoControl(this); + mockViewfinderSettingsControl = new MockCameraViewfinderSettingsControl(this); rendererRef = 0; windowRef = 0; } @@ -162,6 +164,11 @@ public: return windowControl; } } + + if (qstrcmp(iid, QCameraViewfinderSettingsControl2_iid) == 0) { + return mockViewfinderSettingsControl; + } + return 0; } @@ -188,6 +195,7 @@ public: MockVideoWindowControl *windowControl; MockVideoDeviceSelectorControl *mockVideoDeviceSelectorControl; MockCameraInfoControl *mockCameraInfoControl; + MockCameraViewfinderSettingsControl *mockViewfinderSettingsControl; int rendererRef; int windowRef; }; diff --git a/tests/auto/unit/qmultimedia_common/mockcameraviewfindersettingscontrol.h b/tests/auto/unit/qmultimedia_common/mockcameraviewfindersettingscontrol.h new file mode 100644 index 000000000..49b323202 --- /dev/null +++ b/tests/auto/unit/qmultimedia_common/mockcameraviewfindersettingscontrol.h @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef MOCKCAMERAVIEWFINDERSETTINGSCONTROL_H +#define MOCKCAMERAVIEWFINDERSETTINGSCONTROL_H + +#include "qcameraviewfindersettingscontrol.h" + +class MockCameraViewfinderSettingsControl : public QCameraViewfinderSettingsControl2 +{ + Q_OBJECT +public: + MockCameraViewfinderSettingsControl(QObject *parent = 0): + QCameraViewfinderSettingsControl2(parent) + { + } + + ~MockCameraViewfinderSettingsControl() {} + + QCameraViewfinderSettings viewfinderSettings() const + { + return settings; + } + + void setViewfinderSettings(const QCameraViewfinderSettings &s) + { + settings = s; + } + + QList<QCameraViewfinderSettings> supportedViewfinderSettings() const + { + return QList<QCameraViewfinderSettings>(); + } + + QCameraViewfinderSettings settings; +}; + +#endif // MOCKCAMERAVIEWFINDERSETTINGSCONTROL_H |