1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Research In Motion
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QDECLARATIVEVIDEOOUTPUT_P_H
42#define QDECLARATIVEVIDEOOUTPUT_P_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists purely as an
49// implementation detail. This header file may change from version to
50// version without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <QtCore/qrect.h>
56#include <QtCore/qsharedpointer.h>
57#include <QtQuick/qquickitem.h>
58#include <QtCore/qpointer.h>
59#include <QtMultimedia/qcamerainfo.h>
60#include <QtMultimedia/qabstractvideofilter.h>
61
62#include <private/qtmultimediaquickdefs_p.h>
63
64QT_BEGIN_NAMESPACE
65
66class QMediaObject;
67class QMediaService;
68class QDeclarativeVideoBackend;
69class QVideoOutputOrientationHandler;
70class QAbstractVideoSurface;
71
72class Q_MULTIMEDIAQUICK_EXPORT QDeclarativeVideoOutput : public QQuickItem
73{
74 Q_OBJECT
75 Q_DISABLE_COPY(QDeclarativeVideoOutput)
76 Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
77 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
78 Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
79 Q_PROPERTY(bool autoOrientation READ autoOrientation WRITE setAutoOrientation NOTIFY autoOrientationChanged REVISION 2)
80 Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
81 Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
82 Q_PROPERTY(QQmlListProperty<QAbstractVideoFilter> filters READ filters);
83 Q_PROPERTY(FlushMode flushMode READ flushMode WRITE setFlushMode NOTIFY flushModeChanged REVISION 13)
84 Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT REVISION 15)
85 Q_ENUMS(FlushMode)
86 Q_ENUMS(FillMode)
87
88public:
89
90 enum FlushMode
91 {
92 EmptyFrame,
93 FirstFrame,
94 LastFrame
95 };
96
97 enum FillMode
98 {
99 Stretch = Qt::IgnoreAspectRatio,
100 PreserveAspectFit = Qt::KeepAspectRatio,
101 PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
102 };
103
104 QDeclarativeVideoOutput(QQuickItem *parent = 0);
105 ~QDeclarativeVideoOutput();
106
107 QAbstractVideoSurface *videoSurface() const;
108
109 QObject *source() const { return m_source.data(); }
110 void setSource(QObject *source);
111
112 FillMode fillMode() const;
113 void setFillMode(FillMode mode);
114
115 int orientation() const;
116 void setOrientation(int);
117
118 bool autoOrientation() const;
119 void setAutoOrientation(bool);
120
121 QRectF sourceRect() const;
122 QRectF contentRect() const;
123
124 Q_INVOKABLE QPointF mapPointToItem(const QPointF &point) const;
125 Q_INVOKABLE QRectF mapRectToItem(const QRectF &rectangle) const;
126 Q_INVOKABLE QPointF mapNormalizedPointToItem(const QPointF &point) const;
127 Q_INVOKABLE QRectF mapNormalizedRectToItem(const QRectF &rectangle) const;
128 Q_INVOKABLE QPointF mapPointToSource(const QPointF &point) const;
129 Q_INVOKABLE QRectF mapRectToSource(const QRectF &rectangle) const;
130 Q_INVOKABLE QPointF mapPointToSourceNormalized(const QPointF &point) const;
131 Q_INVOKABLE QRectF mapRectToSourceNormalized(const QRectF &rectangle) const;
132
133 enum SourceType {
134 NoSource,
135 MediaObjectSource,
136 VideoSurfaceSource
137 };
138 SourceType sourceType() const;
139
140 QQmlListProperty<QAbstractVideoFilter> filters();
141
142 FlushMode flushMode() const { return m_flushMode; }
143 void setFlushMode(FlushMode mode);
144
145Q_SIGNALS:
146 void sourceChanged();
147 void fillModeChanged(QDeclarativeVideoOutput::FillMode);
148 void orientationChanged();
149 void autoOrientationChanged();
150 void sourceRectChanged();
151 void contentRectChanged();
152 void flushModeChanged();
153
154protected:
155 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
156 void itemChange(ItemChange change, const ItemChangeData &changeData) override;
157 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
158 void releaseResources() override;
159
160private Q_SLOTS:
161 void _q_updateMediaObject();
162 void _q_updateCameraInfo();
163 void _q_updateNativeSize();
164 void _q_updateGeometry();
165 void _q_screenOrientationChanged(int);
166 void _q_invalidateSceneGraph();
167
168private:
169 bool createBackend(QMediaService *service);
170
171 static void filter_append(QQmlListProperty<QAbstractVideoFilter> *property, QAbstractVideoFilter *value);
172 static int filter_count(QQmlListProperty<QAbstractVideoFilter> *property);
173 static QAbstractVideoFilter *filter_at(QQmlListProperty<QAbstractVideoFilter> *property, int index);
174 static void filter_clear(QQmlListProperty<QAbstractVideoFilter> *property);
175
176 SourceType m_sourceType;
177
178 QPointer<QObject> m_source;
179 QPointer<QMediaObject> m_mediaObject;
180 QPointer<QMediaService> m_service;
181 QCameraInfo m_cameraInfo;
182
183 FillMode m_fillMode;
184 QSize m_nativeSize;
185
186 bool m_geometryDirty;
187 QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
188 QRectF m_contentRect; // Destination pixel coordinates, unclipped
189 int m_orientation;
190 bool m_autoOrientation;
191 QVideoOutputOrientationHandler *m_screenOrientationHandler;
192
193 QScopedPointer<QDeclarativeVideoBackend> m_backend;
194
195 QList<QAbstractVideoFilter *> m_filters;
196 FlushMode m_flushMode = EmptyFrame;
197};
198
199QT_END_NAMESPACE
200
201#endif // QDECLARATIVEVIDEOOUTPUT_H
202

source code of qtmultimedia/src/qtmultimediaquicktools/qdeclarativevideooutput_p.h