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
30QT_BEGIN_NAMESPACE
31
32class QQuickVideoBackend;
33class QVideoOutputOrientationHandler;
34class QVideoSink;
35class QSGVideoNode;
36
37class QQuickVideoSink : public QVideoSink
38{
39 Q_OBJECT
40 QML_NAMED_ELEMENT(VideoSink)
41public:
42 QQuickVideoSink(QObject *parent = nullptr) : QVideoSink(parent)
43 {
44 connect(sender: this, signal: &QVideoSink::videoFrameChanged, context: this, slot: &QQuickVideoSink::videoFrameChanged,
45 type: Qt::DirectConnection);
46 }
47
48Q_SIGNALS:
49 void videoFrameChanged();
50};
51
52class Q_MULTIMEDIAQUICK_EXPORT QQuickVideoOutput : public QQuickItem
53{
54 Q_OBJECT
55 Q_DISABLE_COPY(QQuickVideoOutput)
56 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
57 Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
58 Q_PROPERTY(QRectF sourceRect READ sourceRect NOTIFY sourceRectChanged)
59 Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
60 Q_PROPERTY(QVideoSink* videoSink READ videoSink CONSTANT)
61 Q_MOC_INCLUDE(qvideosink.h)
62 Q_MOC_INCLUDE(qvideoframe.h)
63 QML_NAMED_ELEMENT(VideoOutput)
64
65public:
66
67 enum FillMode
68 {
69 Stretch = Qt::IgnoreAspectRatio,
70 PreserveAspectFit = Qt::KeepAspectRatio,
71 PreserveAspectCrop = Qt::KeepAspectRatioByExpanding
72 };
73 Q_ENUM(FillMode)
74
75 QQuickVideoOutput(QQuickItem *parent = 0);
76 ~QQuickVideoOutput();
77
78 Q_INVOKABLE QVideoSink *videoSink() const;
79
80 FillMode fillMode() const;
81 void setFillMode(FillMode mode);
82
83 int orientation() const;
84 void setOrientation(int);
85
86 QRectF sourceRect() const;
87 QRectF contentRect() const;
88
89Q_SIGNALS:
90 void sourceChanged();
91 void fillModeChanged(QQuickVideoOutput::FillMode);
92 void orientationChanged();
93 void sourceRectChanged();
94 void contentRectChanged();
95
96protected:
97 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
98 void itemChange(ItemChange change, const ItemChangeData &changeData) override;
99 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
100 void releaseResources() override;
101
102private:
103 QSize nativeSize() const;
104 void updateGeometry();
105 QRectF adjustedViewport() const;
106
107 void setFrame(const QVideoFrame &frame);
108
109 void invalidateSceneGraph();
110
111 void initRhiForSink();
112 void updateHdr(QSGVideoNode *videoNode);
113
114private Q_SLOTS:
115 void _q_newFrame(QSize);
116 void _q_updateGeometry();
117 void _q_invalidateSceneGraph();
118 void _q_sceneGraphInitialized();
119
120private:
121 QSize m_nativeSize;
122
123 bool m_geometryDirty = true;
124 QRectF m_lastRect; // Cache of last rect to avoid recalculating geometry
125 QRectF m_contentRect; // Destination pixel coordinates, unclipped
126 int m_orientation = 0;
127 QtVideo::Rotation m_frameDisplayingRotation = QtVideo::Rotation::None;
128 Qt::AspectRatioMode m_aspectRatioMode = Qt::KeepAspectRatio;
129
130 QPointer<QQuickWindow> m_window;
131 QVideoSink *m_sink = nullptr;
132 QVideoFrameFormat m_videoFormat;
133
134 QList<QVideoFrame> m_videoFrameQueue;
135 QVideoFrame m_frame;
136 bool m_frameChanged = false;
137 QMutex m_frameMutex;
138 QRectF m_renderedRect; // Destination pixel coordinates, clipped
139 QRectF m_sourceTextureRect; // Source texture coordinates
140};
141
142QT_END_NAMESPACE
143
144#endif // QQUICKVIDEOOUTPUT_P_H
145

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

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