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 /src/imports | |
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>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/multimedia/multimedia.cpp | 1 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativecamera.cpp | 105 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativecamera_p.h | 5 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativecameraviewfinder.cpp | 60 | ||||
-rw-r--r-- | src/imports/multimedia/qdeclarativecameraviewfinder_p.h | 5 |
5 files changed, 140 insertions, 36 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 |