1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QVIDEOFRAME_H
5#define QVIDEOFRAME_H
6
7#include <QtMultimedia/qtmultimediaglobal.h>
8#include <QtMultimedia/qvideoframeformat.h>
9
10#include <QtCore/qmetatype.h>
11#include <QtCore/qshareddata.h>
12#include <QtGui/qimage.h>
13
14QT_BEGIN_NAMESPACE
15
16class QSize;
17class QVideoFramePrivate;
18class QAbstractVideoBuffer;
19class QRhi;
20class QRhiResourceUpdateBatch;
21class QRhiTexture;
22
23QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QVideoFramePrivate, Q_MULTIMEDIA_EXPORT)
24
25class Q_MULTIMEDIA_EXPORT QVideoFrame
26{
27public:
28
29 enum HandleType
30 {
31 NoHandle,
32 RhiTextureHandle
33 };
34
35 enum MapMode
36 {
37 NotMapped = 0x00,
38 ReadOnly = 0x01,
39 WriteOnly = 0x02,
40 ReadWrite = ReadOnly | WriteOnly
41 };
42
43 enum RotationAngle
44 {
45 Rotation0 = 0,
46 Rotation90 = 90,
47 Rotation180 = 180,
48 Rotation270 = 270
49 };
50
51 QVideoFrame();
52 QVideoFrame(const QVideoFrameFormat &format);
53 QVideoFrame(const QVideoFrame &other);
54 ~QVideoFrame();
55
56 QVideoFrame(QVideoFrame &&other) noexcept = default;
57 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QVideoFrame)
58 void swap(QVideoFrame &other) noexcept
59 { d.swap(other&: other.d); }
60
61
62 QVideoFrame &operator =(const QVideoFrame &other);
63 bool operator==(const QVideoFrame &other) const;
64 bool operator!=(const QVideoFrame &other) const;
65
66 bool isValid() const;
67
68 QVideoFrameFormat::PixelFormat pixelFormat() const;
69
70 QVideoFrameFormat surfaceFormat() const;
71 QVideoFrame::HandleType handleType() const;
72
73 QSize size() const;
74 int width() const;
75 int height() const;
76
77 bool isMapped() const;
78 bool isReadable() const;
79 bool isWritable() const;
80
81 QVideoFrame::MapMode mapMode() const;
82
83 bool map(QVideoFrame::MapMode mode);
84 void unmap();
85
86 int bytesPerLine(int plane) const;
87
88 uchar *bits(int plane);
89 const uchar *bits(int plane) const;
90 int mappedBytes(int plane) const;
91 int planeCount() const;
92
93 qint64 startTime() const;
94 void setStartTime(qint64 time);
95
96 qint64 endTime() const;
97 void setEndTime(qint64 time);
98
99 void setRotationAngle(RotationAngle);
100 RotationAngle rotationAngle() const;
101
102 void setMirrored(bool);
103 bool mirrored() const;
104
105 QImage toImage() const;
106
107 struct PaintOptions {
108 QColor backgroundColor = Qt::transparent;
109 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
110 enum PaintFlag {
111 DontDrawSubtitles = 0x1
112 };
113 Q_DECLARE_FLAGS(PaintFlags, PaintFlag)
114 PaintFlags paintFlags = {};
115 };
116
117 QString subtitleText() const;
118 void setSubtitleText(const QString &text);
119
120 void paint(QPainter *painter, const QRectF &rect, const PaintOptions &options);
121
122 QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format);
123
124 QAbstractVideoBuffer *videoBuffer() const;
125private:
126 QExplicitlySharedDataPointer<QVideoFramePrivate> d;
127};
128
129Q_DECLARE_SHARED(QVideoFrame)
130
131#ifndef QT_NO_DEBUG_STREAM
132Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoFrame&);
133Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, QVideoFrame::HandleType);
134#endif
135
136QT_END_NAMESPACE
137
138Q_DECLARE_METATYPE(QVideoFrame)
139
140#endif
141
142

source code of qtmultimedia/src/multimedia/video/qvideoframe.h