1// Copyright (C) 2021 The Qt Company Ltd.
2// Copyright (C) 2016 Research In Motion
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QQUICKVIDEOOUTPUT_P_H
6#define QQUICKVIDEOOUTPUT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtCore/qrect.h>
20#include <QtCore/qsharedpointer.h>
21#include <QtQuick/qquickitem.h>
22#include <QtCore/qpointer.h>
23#include <QtCore/qmutex.h>
24
25#include <private/qtmultimediaquickglobal_p.h>
26#include <qvideoframe.h>
27#include <qvideoframeformat.h>
28
29QT_BEGIN_NAMESPACE
30
31class QQuickVideoBackend;
32class QVideoOutputOrientationHandler;
33class QVideoSink;
34
35class Q_MULTIMEDIAQUICK_EXPORT QQuickVideoOutput : public QQuickItem
36{
37 Q_OBJECT
38 Q_DISABLE_COPY(QQuickVideoOutput)
39 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
40 Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
41 Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
42 Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
43 Q_PROPERTY(QVideoSink* videoSink READ videoSink CONSTANT)
44 Q_MOC_INCLUDE(qvideosink.h)
45 Q_MOC_INCLUDE(qvideoframe.h)
46 QML_NAMED_ELEMENT(VideoOutput)
47
48public:
49
50 enum FillMode
51 {
52 Stretch = Qt::IgnoreAspectRatio,
53 PreserveAspectFit = Qt::KeepAspectRatio,
54 PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
55 };
56 Q_ENUM(FillMode)
57
58 QQuickVideoOutput(QQuickItem *parent = 0);
59 ~QQuickVideoOutput();
60
61 Q_INVOKABLE QVideoSink *videoSink() const;
62
63 FillMode fillMode() const;
64 void setFillMode(FillMode mode);
65
66 int orientation() const;
67 void setOrientation(int);
68
69 QRectF sourceRect() const;
70 QRectF contentRect() const;
71
72Q_SIGNALS:
73 void sourceChanged();
74 void fillModeChanged(QQuickVideoOutput::FillMode);
75 void orientationChanged();
76 void sourceRectChanged();
77 void contentRectChanged();
78 void frameUpdated(QSize);
79
80protected:
81 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
82 void itemChange(ItemChange change, const ItemChangeData &changeData) override;
83 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
84 void releaseResources() override;
85
86private:
87 QSize nativeSize() const;
88 void updateGeometry();
89 QRectF adjustedViewport() const;
90
91 friend class QSGVideoItemSurface;
92 void setFrame(const QVideoFrame &frame);
93 void stop();
94
95 void invalidateSceneGraph();
96
97 void initRhiForSink();
98
99private Q_SLOTS:
100 void _q_newFrame(QSize);
101 void _q_updateGeometry();
102 void _q_invalidateSceneGraph();
103 void _q_sceneGraphInitialized();
104
105private:
106 QSize m_nativeSize;
107
108 bool m_geometryDirty = true;
109 QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
110 QRectF m_contentRect; // Destination pixel coordinates, unclipped
111 int m_orientation = 0;
112 int m_frameOrientation = 0;
113 Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
114
115 QPointer<QQuickWindow> m_window;
116 QVideoSink *m_sink = nullptr;
117 QVideoFrameFormat m_surfaceFormat;
118
119 QList<QVideoFrame> m_videoFrameQueue;
120 QVideoFrame m_frame;
121 bool m_frameChanged = false;
122 QMutex m_frameMutex;
123 QRectF m_renderedRect; // Destination pixel coordinates, clipped
124 QRectF m_sourceTextureRect; // Source texture coordinates
125};
126
127QT_END_NAMESPACE
128
129#endif // QQUICKVIDEOOUTPUT_P_H
130

source code of qtmultimedia/src/multimediaquick/qquickvideooutput_p.h