Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickvideooutput_p.h
Go to the documentation of this file.
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#include <qvideosink.h>
29
31
32class QQuickVideoBackend;
33class QVideoOutputOrientationHandler;
34class QVideoSink;
35class QSGVideoNode;
36class QVideoFrameTexturePool;
37using QVideoFrameTexturePoolWPtr = std::weak_ptr<QVideoFrameTexturePool>;
38
40{
41 Q_OBJECT
42 QML_NAMED_ELEMENT(VideoSink)
43public:
49
52};
53
54class Q_MULTIMEDIAQUICK_EXPORT QQuickVideoOutput : public QQuickItem
55{
56 Q_OBJECT
57 Q_DISABLE_COPY(QQuickVideoOutput)
58 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
59 Q_PROPERTY(EndOfStreamPolicy endOfStreamPolicy READ endOfStreamPolicy WRITE setEndOfStreamPolicy
60 NOTIFY endOfStreamPolicyChanged REVISION(6, 9))
61 Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
62 Q_PROPERTY(bool mirrored READ mirrored WRITE setMirrored NOTIFY mirroredChanged REVISION(6, 9))
63 Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
64 Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
65 Q_PROPERTY(QVideoSink* videoSink READ videoSink CONSTANT)
66 Q_MOC_INCLUDE(qvideosink.h)
67 Q_MOC_INCLUDE(qvideoframe.h)
68 QML_NAMED_ELEMENT(VideoOutput)
69
70public:
71
72 enum FillMode
73 {
74 Stretch = Qt::IgnoreAspectRatio,
75 PreserveAspectFit = Qt::KeepAspectRatio,
76 PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
77 };
78 Q_ENUM(FillMode)
79
80 enum EndOfStreamPolicy
81 {
82 ClearOutput,
83 KeepLastFrame
84 };
85 Q_ENUM(EndOfStreamPolicy)
86
87 QQuickVideoOutput(QQuickItem *parent = 0);
88 ~QQuickVideoOutput() override;
89
90 Q_INVOKABLE QVideoSink *videoSink() const;
91
92 FillMode fillMode() const;
93 void setFillMode(FillMode mode);
94
95 int orientation() const;
96 void setOrientation(int);
97
98 bool mirrored() const;
99 void setMirrored(bool);
100
101 QRectF sourceRect() const;
102 QRectF contentRect() const;
103
104 EndOfStreamPolicy endOfStreamPolicy() const;
105 void setEndOfStreamPolicy(EndOfStreamPolicy policy);
106
107 Q_REVISION(6, 9) Q_INVOKABLE void clearOutput();
108
109Q_SIGNALS:
110 void sourceChanged();
111 void fillModeChanged(QQuickVideoOutput::FillMode);
112 void orientationChanged();
113 void mirroredChanged();
114 void sourceRectChanged();
115 void contentRectChanged();
116 void endOfStreamPolicyChanged(QQuickVideoOutput::EndOfStreamPolicy);
117
118protected:
119 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
120 void itemChange(ItemChange change, const ItemChangeData &changeData) override;
121 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
122 void releaseResources() override;
123
124private:
125 QSize nativeSize() const;
126 void updateGeometry();
127 QRectF adjustedViewport() const;
128
129 void setFrame(const QVideoFrame &frame);
130
131 void initRhiForSink();
132 void updateHdr(QSGVideoNode *videoNode);
133
134private Q_SLOTS:
135 void _q_newFrame(QSize);
136 void _q_updateGeometry();
137 void _q_invalidateSceneGraph();
138 void _q_sceneGraphInitialized();
139 void _q_afterFrameEnd();
140
141private:
142 QSize m_nativeSize;
143
144 bool m_geometryDirty = true;
145 QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
146 QRectF m_contentRect; // Destination pixel coordinates, unclipped
147 int m_orientation = 0;
148 bool m_mirrored = false;
149 QtVideo::Rotation m_frameDisplayingRotation = QtVideo::Rotation::None;
150 Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
151
152 QPointer<QQuickWindow> m_window;
153 QVideoSink *m_sink = nullptr;
154 QVideoFrameFormat m_videoFormat;
155
156 QVideoFrameTexturePoolWPtr m_texturePool;
157 QVideoFrame m_frame;
158 bool m_frameChanged = false;
159 QMutex m_frameMutex;
160 QRectF m_renderedRect; // Destination pixel coordinates, clipped
161 QRectF m_sourceTextureRect; // Source texture coordinates
162
163 EndOfStreamPolicy m_endOfStreamPolicy = ClearOutput;
164};
165
166QT_END_NAMESPACE
167
168#endif // QQUICKVIDEOOUTPUT_P_H
Render video or camera viewfinder.
Combined button and popup list for selecting options.