diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-02-11 18:05:58 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-02-17 08:27:17 +0000 |
commit | 0d5527ba1ed568abc1f3ffe943d0def9929d2123 (patch) | |
tree | af5e53c97a3f98ed39af1aa6f5dfb4add76bd590 | |
parent | 79159a4ff3678218e7fe6a55417355430f7e4a59 (diff) |
Fix QML VideoOutput element
Requires a bit of plumming to get this to work. This
is currently not ideal, and will require some further
work.
Change-Id: I5126e8ac0ba1db383d4694c3ab80b67a395a5464
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
10 files changed, 83 insertions, 612 deletions
diff --git a/src/imports/multimedia/qdeclarativecamera_p.h b/src/imports/multimedia/qdeclarativecamera_p.h index f5fca68e9..7a13d6fc6 100644 --- a/src/imports/multimedia/qdeclarativecamera_p.h +++ b/src/imports/multimedia/qdeclarativecamera_p.h @@ -89,6 +89,7 @@ class QDeclarativeCamera : public QObject, public QQmlParserStatus Q_PROPERTY(qreal minimumZoomFactor READ minimumZoomFactor) Q_PROPERTY(qreal maximumZoomFactor READ maximumZoomFactor) Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor NOTIFY zoomFactorChanged) + Q_PROPERTY(QObject *mediaSource READ mediaSource CONSTANT); Q_PROPERTY(QDeclarativeCameraCapture* imageCapture READ imageCapture CONSTANT) Q_PROPERTY(QDeclarativeCameraRecorder* videoRecorder READ videoRecorder CONSTANT) diff --git a/src/qtmultimediaquicktools/CMakeLists.txt b/src/qtmultimediaquicktools/CMakeLists.txt index c40bee147..9dd826316 100644 --- a/src/qtmultimediaquicktools/CMakeLists.txt +++ b/src/qtmultimediaquicktools/CMakeLists.txt @@ -9,9 +9,7 @@ qt_add_module(MultimediaQuick INTERNAL_MODULE SOURCES qdeclarativevideooutput.cpp qdeclarativevideooutput_p.h - qdeclarativevideooutput_backend_p.h qdeclarativevideooutput_render.cpp qdeclarativevideooutput_render_p.h - qdeclarativevideooutput_window.cpp qdeclarativevideooutput_window_p.h qsgvideonode_p.cpp qsgvideonode_p.h qsgvideonode_rgb.cpp qsgvideonode_rgb_p.h qsgvideonode_texture.cpp qsgvideonode_texture_p.h diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp index 2aae59509..93fbd75ab 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput.cpp @@ -40,10 +40,9 @@ #include "qdeclarativevideooutput_p.h" #include "qdeclarativevideooutput_render_p.h" -#include "qdeclarativevideooutput_window_p.h" +#include "qdeclarativevideooutput_p.h" #include <private/qvideooutputorientationhandler_p.h> -#include <QtMultimedia/qmediasource.h> -#include <QtMultimedia/qmediaservice.h> +#include <QtMultimedia/qmediaplayer.h> #include <QtMultimedia/qcamera.h> #include <private/qfactoryloader_p.h> #include <QtCore/qloggingcategory.h> @@ -130,7 +129,6 @@ Q_LOGGING_CATEGORY(qLcVideo, "qt.multimedia.video") QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) : QQuickItem(parent), - m_sourceType(NoSource), m_fillMode(PreserveAspectFit), m_geometryDirty(true), m_orientation(0), @@ -139,14 +137,12 @@ QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) : { initResource(); setFlag(ItemHasContents, true); - createBackend(nullptr); + createBackend(); } QDeclarativeVideoOutput::~QDeclarativeVideoOutput() { m_backend.reset(); - m_source.clear(); - _q_updateMediaSource(); } /*! @@ -185,157 +181,38 @@ void QDeclarativeVideoOutput::setSource(QObject *source) if (source == m_source.data()) return; - - if (m_source && m_sourceType == MediaSourceSource) { - disconnect(m_source.data(), nullptr, this, SLOT(_q_updateMediaSource())); - disconnect(m_source.data(), nullptr, this, SLOT(_q_updateCameraInfo())); - } - - if (m_backend) - m_backend->releaseSource(); - m_source = source; - if (m_source) { + QObject *s = source; + if (s) { const QMetaObject *metaObject = m_source.data()->metaObject(); - int mediaSourcePropertyIndex = metaObject->indexOfProperty("mediaSource"); if (mediaSourcePropertyIndex != -1) { const QMetaProperty mediaSourceProperty = metaObject->property(mediaSourcePropertyIndex); - - if (mediaSourceProperty.hasNotifySignal()) { - QMetaMethod method = mediaSourceProperty.notifySignal(); - QMetaObject::connect(m_source.data(), method.methodIndex(), - this, this->metaObject()->indexOfSlot("_q_updateMediaSource()"), - Qt::DirectConnection, nullptr); - - } - - int deviceIdPropertyIndex = metaObject->indexOfProperty("deviceId"); - if (deviceIdPropertyIndex != -1) { // Camera source - const QMetaProperty deviceIdProperty = metaObject->property(deviceIdPropertyIndex); - - if (deviceIdProperty.hasNotifySignal()) { - QMetaMethod method = deviceIdProperty.notifySignal(); - QMetaObject::connect(m_source.data(), method.methodIndex(), - this, this->metaObject()->indexOfSlot("_q_updateCameraInfo()"), - Qt::DirectConnection, nullptr); - - } - } - - m_sourceType = MediaSourceSource; - } else if (metaObject->indexOfProperty("videoSurface") != -1) { - m_source.data()->setProperty("videoSurface", - QVariant::fromValue<QAbstractVideoSurface *>(videoSurface())); - m_sourceType = VideoSurfaceSource; - } else { - m_sourceType = NoSource; + s = mediaSourceProperty.read(s).value<QObject *>(); } - } else { - m_sourceType = NoSource; } - _q_updateMediaSource(); - emit sourceChanged(); -} - -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, videoBackendFactoryLoader, - (QDeclarativeVideoBackendFactoryInterface_iid, QLatin1String("video/declarativevideobackend"), Qt::CaseInsensitive)) - -bool QDeclarativeVideoOutput::createBackend(QMediaService *service) -{ - bool backendAvailable = false; - - int i = 0; - while (const auto instance = videoBackendFactoryLoader()->instance(i)) { - if (QDeclarativeVideoBackendFactoryInterface *plugin = qobject_cast<QDeclarativeVideoBackendFactoryInterface*>(instance)) { - if (!m_backend) - m_backend.reset(plugin->create(this)); - if (m_backend && m_backend->init(service)) { - backendAvailable = true; - break; - } - } - } - - if (!backendAvailable) { - if (!m_backend) - m_backend.reset(new QDeclarativeVideoRendererBackend(this)); - if (m_backend->init(service)) - backendAvailable = true; + if (QCamera *c = qobject_cast<QCamera *>(s)) { + c->setViewfinder(videoSurface()); + } else if (QMediaPlayer *p = qobject_cast<QMediaPlayer *>(s)) { + p->setVideoOutput(videoSurface()); } - - // QDeclarativeVideoWindowBackend only works when there is a service with a QVideoWindowControl. - // Without service, the QDeclarativeVideoRendererBackend should always work. - if (!backendAvailable) { - Q_ASSERT(service); - m_backend.reset(new QDeclarativeVideoWindowBackend(this)); - if (m_backend->init(service)) - backendAvailable = true; - } - - if (backendAvailable) { - // Since new backend has been created needs to update its geometry. - m_geometryDirty = true; - - m_backend->clearFilters(); - for (int i = 0; i < m_filters.count(); ++i) - m_backend->appendFilter(m_filters[i]); - } else { - qWarning() << Q_FUNC_INFO << "Media service has neither renderer nor window control available."; - m_backend.reset(); - } - - return backendAvailable; + emit sourceChanged(); } -void QDeclarativeVideoOutput::_q_updateMediaSource() +bool QDeclarativeVideoOutput::createBackend() { - QMediaSource *mediaSource = nullptr; - - if (m_source) - mediaSource = qobject_cast<QMediaSource*>(m_source.data()->property("mediaSource").value<QObject*>()); - - qCDebug(qLcVideo) << "media object is" << mediaSource; - - if (m_mediaSource.data() == mediaSource) - return; - - m_mediaSource.clear(); - m_service.clear(); - - if (mediaSource) { - if (QMediaService *service = mediaSource->service()) { - if (createBackend(service)) { - m_service = service; - m_mediaSource = mediaSource; - } - } - } - - _q_updateCameraInfo(); -} + m_backend.reset(new QDeclarativeVideoBackend(this)); -void QDeclarativeVideoOutput::_q_updateCameraInfo() -{ - if (m_mediaSource) { - const QCamera *camera = qobject_cast<const QCamera *>(m_mediaSource); - if (camera) { - QCameraInfo info = camera->cameraInfo(); + // Since new backend has been created needs to update its geometry. + m_geometryDirty = true; - if (m_cameraInfo != info) { - m_cameraInfo = info; + m_backend->clearFilters(); + for (int i = 0; i < m_filters.count(); ++i) + m_backend->appendFilter(m_filters[i]); - // The camera position and orientation need to be taken into account for - // the viewport auto orientation - if (m_autoOrientation) - _q_screenOrientationChanged(m_screenOrientationHandler->currentOrientation()); - } - } - } else { - m_cameraInfo = QCameraInfo(); - } + return true; } /*! @@ -746,11 +623,6 @@ QRectF QDeclarativeVideoOutput::mapRectToSourceNormalized(const QRectF &rectangl mapPointToSourceNormalized(rectangle.bottomRight())).normalized(); } -QDeclarativeVideoOutput::SourceType QDeclarativeVideoOutput::sourceType() const -{ - return m_sourceType; -} - /*! \qmlmethod QPointF QtMultimedia::VideoOutput::mapPointToItem(const QPointF &point) const diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h deleted file mode 100644 index da99b387a..000000000 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_backend_p.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Research In Motion -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEVIDEOOUTPUT_BACKEND_P_H -#define QDECLARATIVEVIDEOOUTPUT_BACKEND_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtCore/qpointer.h> -#include <QtCore/qsize.h> -#include <QtQuick/qquickitem.h> -#include <QtQuick/qsgnode.h> -#include <private/qtmultimediaquickdefs_p.h> - -QT_BEGIN_NAMESPACE - -class QAbstractVideoSurface; -class QDeclarativeVideoOutput; -class QMediaService; -class QAbstractVideoFilter; - -class Q_MULTIMEDIAQUICK_EXPORT QDeclarativeVideoBackend -{ -public: - explicit QDeclarativeVideoBackend(QDeclarativeVideoOutput *parent) - : q(parent) - {} - - virtual ~QDeclarativeVideoBackend() - {} - - virtual bool init(QMediaService *service) = 0; - virtual void releaseSource() = 0; - virtual void releaseControl() = 0; - virtual void itemChange(QQuickItem::ItemChange change, - const QQuickItem::ItemChangeData &changeData) = 0; - virtual QSize nativeSize() const = 0; - virtual void updateGeometry() = 0; - virtual QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) = 0; - virtual QAbstractVideoSurface *videoSurface() const = 0; - - // The viewport, adjusted for the pixel aspect ratio - virtual QRectF adjustedViewport() const = 0; - - virtual void appendFilter(QAbstractVideoFilter *filter) { Q_UNUSED(filter); } - virtual void clearFilters() { } - - virtual void releaseResources() { } - virtual void invalidateSceneGraph() { } - -protected: - QDeclarativeVideoOutput *q; - QPointer<QMediaService> m_service; -}; - -class QDeclarativeVideoBackendFactoryInterface -{ -public: - virtual QDeclarativeVideoBackend *create(QDeclarativeVideoOutput *parent) = 0; -}; - -#define QDeclarativeVideoBackendFactoryInterface_iid "org.qt-project.qt.declarativevideobackendfactory/5.2" -Q_DECLARE_INTERFACE(QDeclarativeVideoBackendFactoryInterface, QDeclarativeVideoBackendFactoryInterface_iid) - -/* - * Helper - returns true if the given orientation has the same aspect as the default (e.g. 180*n) - */ -namespace { - -inline bool qIsDefaultAspect(int o) -{ - return (o % 180) == 0; -} - -/* - * Return the orientation normalized to 0-359 - */ -inline int qNormalizedOrientation(int o) -{ - // Negative orientations give negative results - int o2 = o % 360; - if (o2 < 0) - o2 += 360; - return o2; -} - -} - -QT_END_NAMESPACE - -#endif diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h index 194f7fc48..6927bccd8 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h @@ -56,7 +56,6 @@ #include <QtCore/qsharedpointer.h> #include <QtQuick/qquickitem.h> #include <QtCore/qpointer.h> -#include <QtMultimedia/qcamerainfo.h> #include <QtMultimedia/qabstractvideofilter.h> #include <private/qtmultimediaquickdefs_p.h> @@ -106,11 +105,11 @@ public: QDeclarativeVideoOutput(QQuickItem *parent = 0); ~QDeclarativeVideoOutput(); - QAbstractVideoSurface *videoSurface() const; - QObject *source() const { return m_source.data(); } void setSource(QObject *source); + Q_INVOKABLE QAbstractVideoSurface *videoSurface() const; + FillMode fillMode() const; void setFillMode(FillMode mode); @@ -160,27 +159,20 @@ protected: void releaseResources() override; private Q_SLOTS: - void _q_updateMediaSource(); - void _q_updateCameraInfo(); void _q_updateNativeSize(); void _q_updateGeometry(); void _q_screenOrientationChanged(int); void _q_invalidateSceneGraph(); private: - bool createBackend(QMediaService *service); + bool createBackend(); static void filter_append(QQmlListProperty<QAbstractVideoFilter> *property, QAbstractVideoFilter *value); static qsizetype filter_count(QQmlListProperty<QAbstractVideoFilter> *property); static QAbstractVideoFilter *filter_at(QQmlListProperty<QAbstractVideoFilter> *property, qsizetype index); static void filter_clear(QQmlListProperty<QAbstractVideoFilter> *property); - SourceType m_sourceType; - QPointer<QObject> m_source; - QPointer<QMediaSource> m_mediaSource; - QPointer<QMediaService> m_service; - QCameraInfo m_cameraInfo; FillMode m_fillMode; QSize m_nativeSize; diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp index cdfc17479..cd36c3537 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp @@ -61,8 +61,8 @@ Q_DECLARE_LOGGING_CATEGORY(qLcVideo) Q_GLOBAL_STATIC_WITH_ARGS(QMediaPluginLoader, videoNodeFactoryLoader, (QSGVideoNodeFactoryInterface_iid, QLatin1String("video/videonode"), Qt::CaseInsensitive)) -QDeclarativeVideoRendererBackend::QDeclarativeVideoRendererBackend(QDeclarativeVideoOutput *parent) - : QDeclarativeVideoBackend(parent), +QDeclarativeVideoBackend::QDeclarativeVideoBackend(QDeclarativeVideoOutput *parent) + : q(parent), m_frameChanged(false) { m_surface = new QSGVideoItemSurface(this); @@ -91,37 +91,18 @@ QDeclarativeVideoRendererBackend::QDeclarativeVideoRendererBackend(QDeclarativeV m_videoNodeFactories.append(&m_textureFactory); } -QDeclarativeVideoRendererBackend::~QDeclarativeVideoRendererBackend() +QDeclarativeVideoBackend::~QDeclarativeVideoBackend() { - releaseSource(); - releaseControl(); delete m_surface; } -bool QDeclarativeVideoRendererBackend::init(QMediaService *service) -{ - // When there is no service, the source is an object with a "videoSurface" property, which - // doesn't require a QVideoRendererControl and therefore always works - if (!service) - return true; - - if (QObject *control = service->requestControl(QVideoRendererControl_iid)) { - if ((m_rendererControl = qobject_cast<QVideoRendererControl *>(control))) { - m_rendererControl->setSurface(m_surface); - m_service = service; - return true; - } - } - return false; -} - -void QDeclarativeVideoRendererBackend::appendFilter(QAbstractVideoFilter *filter) +void QDeclarativeVideoBackend::appendFilter(QAbstractVideoFilter *filter) { QMutexLocker lock(&m_frameMutex); m_filters.append(Filter(filter)); } -void QDeclarativeVideoRendererBackend::clearFilters() +void QDeclarativeVideoBackend::clearFilters() { QMutexLocker lock(&m_frameMutex); scheduleDeleteFilterResources(); @@ -140,7 +121,7 @@ private: QList<QVideoFilterRunnable *> m_runnables; }; -void QDeclarativeVideoRendererBackend::scheduleDeleteFilterResources() +void QDeclarativeVideoBackend::scheduleDeleteFilterResources() { if (!q->window()) return; @@ -161,13 +142,13 @@ void QDeclarativeVideoRendererBackend::scheduleDeleteFilterResources() } } -void QDeclarativeVideoRendererBackend::releaseResources() +void QDeclarativeVideoBackend::releaseResources() { // Called on the gui thread when the window is closed or changed. invalidateSceneGraph(); } -void QDeclarativeVideoRendererBackend::invalidateSceneGraph() +void QDeclarativeVideoBackend::invalidateSceneGraph() { // Called on the render thread, e.g. when the context is lost. QMutexLocker lock(&m_frameMutex); @@ -179,7 +160,7 @@ void QDeclarativeVideoRendererBackend::invalidateSceneGraph() } } -void QDeclarativeVideoRendererBackend::itemChange(QQuickItem::ItemChange change, +void QDeclarativeVideoBackend::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) { if (change == QQuickItem::ItemSceneChange) { @@ -189,32 +170,12 @@ void QDeclarativeVideoRendererBackend::itemChange(QQuickItem::ItemChange change, } } -void QDeclarativeVideoRendererBackend::releaseSource() -{ - if (q->source() && q->sourceType() == QDeclarativeVideoOutput::VideoSurfaceSource) { - if (q->source()->property("videoSurface").value<QAbstractVideoSurface*>() == m_surface) - q->source()->setProperty("videoSurface", QVariant::fromValue<QAbstractVideoSurface*>(0)); - } - - m_surface->stop(); -} - -void QDeclarativeVideoRendererBackend::releaseControl() -{ - if (m_rendererControl) { - m_rendererControl->setSurface(nullptr); - if (m_service) - m_service->releaseControl(m_rendererControl); - m_rendererControl = nullptr; - } -} - -QSize QDeclarativeVideoRendererBackend::nativeSize() const +QSize QDeclarativeVideoBackend::nativeSize() const { return m_surfaceFormat.sizeHint(); } -void QDeclarativeVideoRendererBackend::updateGeometry() +void QDeclarativeVideoBackend::updateGeometry() { const QRectF viewport = m_surfaceFormat.viewport(); const QSizeF frameSize = m_surfaceFormat.frameSize(); @@ -271,7 +232,7 @@ void QDeclarativeVideoRendererBackend::updateGeometry() } } -QSGNode *QDeclarativeVideoRendererBackend::updatePaintNode(QSGNode *oldNode, +QSGNode *QDeclarativeVideoBackend::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) { Q_UNUSED(data); @@ -385,12 +346,12 @@ QSGNode *QDeclarativeVideoRendererBackend::updatePaintNode(QSGNode *oldNode, return videoNode; } -QAbstractVideoSurface *QDeclarativeVideoRendererBackend::videoSurface() const +QAbstractVideoSurface *QDeclarativeVideoBackend::videoSurface() const { return m_surface; } -QRectF QDeclarativeVideoRendererBackend::adjustedViewport() const +QRectF QDeclarativeVideoBackend::adjustedViewport() const { const QRectF viewport = m_surfaceFormat.viewport(); const QSizeF pixelAspectRatio = m_surfaceFormat.pixelAspectRatio(); @@ -407,13 +368,13 @@ QRectF QDeclarativeVideoRendererBackend::adjustedViewport() const } #if QT_CONFIG(opengl) -QOpenGLContext *QDeclarativeVideoRendererBackend::glContext() const +QOpenGLContext *QDeclarativeVideoBackend::glContext() const { return m_glContext; } #endif -void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame) +void QDeclarativeVideoBackend::present(const QVideoFrame &frame) { m_frameMutex.lock(); m_frame = frame.isValid() ? frame : m_frameOnFlush; @@ -423,12 +384,12 @@ void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame) q->update(); } -void QDeclarativeVideoRendererBackend::stop() +void QDeclarativeVideoBackend::stop() { present(QVideoFrame()); } -QSGVideoItemSurface::QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent) +QSGVideoItemSurface::QSGVideoItemSurface(QDeclarativeVideoBackend *backend, QObject *parent) : QAbstractVideoSurface(parent), m_backend(backend) { diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h index 445c5a01a..739177800 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput_render_p.h @@ -52,7 +52,8 @@ // We mean it. // -#include <private/qdeclarativevideooutput_backend_p.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/qsgnode.h> #include <private/qsgvideonode_yuv_p.h> #include <private/qsgvideonode_rgb_p.h> #include <private/qsgvideonode_texture_p.h> @@ -67,22 +68,20 @@ class QVideoRendererControl; class QOpenGLContext; class QAbstractVideoFilter; class QVideoFilterRunnable; +class QDeclarativeVideoOutput; -class QDeclarativeVideoRendererBackend : public QDeclarativeVideoBackend +class QDeclarativeVideoBackend { public: - QDeclarativeVideoRendererBackend(QDeclarativeVideoOutput *parent); - ~QDeclarativeVideoRendererBackend(); - - bool init(QMediaService *service) override; - void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override; - void releaseSource() override; - void releaseControl() override; - QSize nativeSize() const override; - void updateGeometry() override; - QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override; - QAbstractVideoSurface *videoSurface() const override; - QRectF adjustedViewport() const override; + QDeclarativeVideoBackend(QDeclarativeVideoOutput *parent); + ~QDeclarativeVideoBackend(); + + void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData); + QSize nativeSize() const; + void updateGeometry(); + QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data); + QAbstractVideoSurface *videoSurface() const; + QRectF adjustedViewport() const; #if QT_CONFIG(opengl) QOpenGLContext *glContext() const; @@ -92,15 +91,15 @@ public: void present(const QVideoFrame &frame); void stop(); - void appendFilter(QAbstractVideoFilter *filter) override; - void clearFilters() override; - void releaseResources() override; - void invalidateSceneGraph() override; + void appendFilter(QAbstractVideoFilter *filter); + void clearFilters(); + void releaseResources(); + void invalidateSceneGraph(); private: void scheduleDeleteFilterResources(); + QDeclarativeVideoOutput *q; - QPointer<QVideoRendererControl> m_rendererControl; QList<QSGVideoNodeFactoryInterface*> m_videoNodeFactories; QSGVideoItemSurface *m_surface; QVideoSurfaceFormat m_surfaceFormat; @@ -132,7 +131,7 @@ class QSGVideoItemSurface : public QAbstractVideoSurface { Q_OBJECT public: - explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0); + explicit QSGVideoItemSurface(QDeclarativeVideoBackend *backend, QObject *parent = 0); ~QSGVideoItemSurface(); QList<QVideoFrame::PixelFormat> supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const override; bool start(const QVideoSurfaceFormat &format) override; @@ -146,9 +145,31 @@ private slots: #endif private: - QDeclarativeVideoRendererBackend *m_backend; + QDeclarativeVideoBackend *m_backend; }; + +namespace { + +inline bool qIsDefaultAspect(int o) +{ + return (o % 180) == 0; +} + +/* + * Return the orientation normalized to 0-359 + */ +inline int qNormalizedOrientation(int o) +{ + // Negative orientations give negative results + int o2 = o % 360; + if (o2 < 0) + o2 += 360; + return o2; +} + +} + QT_END_NAMESPACE #endif diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp deleted file mode 100644 index 4188a4a6e..000000000 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_window.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Research In Motion -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qdeclarativevideooutput_window_p.h" -#include "qdeclarativevideooutput_p.h" -#include <QtQuick/qquickwindow.h> -#include <QtMultimedia/qmediaservice.h> -#include <QtMultimedia/qvideowindowcontrol.h> - -QT_BEGIN_NAMESPACE - -QDeclarativeVideoWindowBackend::QDeclarativeVideoWindowBackend(QDeclarativeVideoOutput *parent) - : QDeclarativeVideoBackend(parent), - m_visible(true) -{ -} - -QDeclarativeVideoWindowBackend::~QDeclarativeVideoWindowBackend() -{ - releaseSource(); - releaseControl(); -} - -bool QDeclarativeVideoWindowBackend::init(QMediaService *service) -{ - if (QObject *control = service->requestControl(QVideoWindowControl_iid)) { - if ((m_videoWindowControl = qobject_cast<QVideoWindowControl *>(control))) { - if (q->window()) - m_videoWindowControl->setWinId(q->window()->winId()); - m_service = service; - QObject::connect(m_videoWindowControl.data(), SIGNAL(nativeSizeChanged()), - q, SLOT(_q_updateNativeSize())); - return true; - } - } - return false; -} - -void QDeclarativeVideoWindowBackend::itemChange(QQuickItem::ItemChange change, - const QQuickItem::ItemChangeData &changeData) -{ - if (!m_videoWindowControl) - return; - - switch (change) { - case QQuickItem::ItemVisibleHasChanged: - m_visible = changeData.boolValue; - updateGeometry(); - break; - case QQuickItem::ItemSceneChange: - if (changeData.window) - m_videoWindowControl->setWinId(changeData.window->winId()); - else - m_videoWindowControl->setWinId(0); - break; - default: break; - } -} - -void QDeclarativeVideoWindowBackend::releaseSource() -{ -} - -void QDeclarativeVideoWindowBackend::releaseControl() -{ - if (m_videoWindowControl) { - m_videoWindowControl->setWinId(0); - if (m_service) - m_service->releaseControl(m_videoWindowControl); - m_videoWindowControl = nullptr; - } -} - -QSize QDeclarativeVideoWindowBackend::nativeSize() const -{ - return m_videoWindowControl->nativeSize(); -} - -void QDeclarativeVideoWindowBackend::updateGeometry() -{ - switch (q->fillMode()) { - case QDeclarativeVideoOutput::PreserveAspectFit: - m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatio); break; - case QDeclarativeVideoOutput::PreserveAspectCrop: - m_videoWindowControl->setAspectRatioMode(Qt::KeepAspectRatioByExpanding); break; - case QDeclarativeVideoOutput::Stretch: - m_videoWindowControl->setAspectRatioMode(Qt::IgnoreAspectRatio); break; - }; - - const QRectF canvasRect = q->mapRectToScene(QRectF(0, 0, q->width(), q->height())); - m_videoWindowControl->setDisplayRect(m_visible ? canvasRect.toAlignedRect() : QRect()); -} - -QSGNode *QDeclarativeVideoWindowBackend::updatePaintNode(QSGNode *oldNode, - QQuickItem::UpdatePaintNodeData *data) -{ - Q_UNUSED(oldNode); - Q_UNUSED(data); - m_videoWindowControl->repaint(); - return nullptr; -} - -QAbstractVideoSurface *QDeclarativeVideoWindowBackend::videoSurface() const -{ - return nullptr; -} - -QRectF QDeclarativeVideoWindowBackend::adjustedViewport() const -{ - // No viewport supported by QVideoWindowControl, so make the viewport the same size - // as the source - return QRectF(QPointF(0, 0), nativeSize()); -} - -QT_END_NAMESPACE diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h b/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h deleted file mode 100644 index eb1814b07..000000000 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_window_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Research In Motion -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEVIDEOOUTPUT_WINDOW_P_H -#define QDECLARATIVEVIDEOOUTPUT_WINDOW_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qdeclarativevideooutput_backend_p.h> - -QT_BEGIN_NAMESPACE - -class QVideoWindowControl; - -class QDeclarativeVideoWindowBackend : public QDeclarativeVideoBackend -{ -public: - QDeclarativeVideoWindowBackend(QDeclarativeVideoOutput *parent); - ~QDeclarativeVideoWindowBackend(); - - bool init(QMediaService *service) override; - void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &changeData) override; - void releaseSource() override; - void releaseControl() override; - QSize nativeSize() const override; - void updateGeometry() override; - QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override; - QAbstractVideoSurface *videoSurface() const override; - QRectF adjustedViewport() const override; - -private: - QPointer<QVideoWindowControl> m_videoWindowControl; - bool m_visible; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/qtmultimediaquicktools/qtmultimediaquicktools.pro b/src/qtmultimediaquicktools/qtmultimediaquicktools.pro index 82e3e463f..96f0af788 100644 --- a/src/qtmultimediaquicktools/qtmultimediaquicktools.pro +++ b/src/qtmultimediaquicktools/qtmultimediaquicktools.pro @@ -5,20 +5,17 @@ CONFIG += internal_module PRIVATE_HEADERS += \ qdeclarativevideooutput_p.h \ - qdeclarativevideooutput_backend_p.h \ qsgvideonode_p.h \ qsgvideotexture_p.h \ qtmultimediaquickdefs_p.h HEADERS += \ $$PRIVATE_HEADERS \ - qdeclarativevideooutput_window_p.h SOURCES += \ qsgvideonode_p.cpp \ qsgvideotexture.cpp \ qdeclarativevideooutput.cpp \ - qdeclarativevideooutput_window.cpp SOURCES += qdeclarativevideooutput_render.cpp \ qsgvideonode_rgb.cpp \ |