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/multimedia/camera | |
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/multimedia/camera')
-rw-r--r-- | src/multimedia/camera/camera.pri | 7 | ||||
-rw-r--r-- | src/multimedia/camera/qcamera.cpp | 246 | ||||
-rw-r--r-- | src/multimedia/camera/qcamera.h | 18 | ||||
-rw-r--r-- | src/multimedia/camera/qcamera_p.h | 6 | ||||
-rw-r--r-- | src/multimedia/camera/qcameraviewfindersettings.cpp | 311 | ||||
-rw-r--r-- | src/multimedia/camera/qcameraviewfindersettings.h | 86 |
6 files changed, 671 insertions, 3 deletions
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 |