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>
This commit is contained in:
Yoann Lopes
2014-12-12 12:00:06 +01:00
parent c31d8cddd0
commit fe21ee675e
20 changed files with 1172 additions and 44 deletions

View File

@@ -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>();
}

View File

@@ -989,20 +989,34 @@ QDeclarativeMediaMetaData *QDeclarativeCamera::metaData()
}
/*!
\qmlpropertygroup QtMultimedia::Camera::viewfinder
\qmlproperty size QtMultimedia::Camera::viewfinder.resolution
This property holds the resolution of the camera viewfinder. If no
resolution is given the backend will use a default value.
\since 5.4
*/
/*!
\qmlproperty real QtMultimedia::Camera::viewfinder.minimumFrameRate
\qmlproperty real QtMultimedia::Camera::viewfinder.maximumFrameRate
These properties hold the limits of the preferred frame rate for the
viewfinder in frames per second.
These properties hold the viewfinder settings.
\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.
\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.
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"

View File

@@ -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);

View File

@@ -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"

View File

@@ -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