1// Copyright (C) 2024 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_P_H
5#define QVIDEOFRAME_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qvideoframe.h"
19#include "qhwvideobuffer_p.h"
20#include "private/qvideotransformation_p.h"
21
22#include <qmutex.h>
23
24QT_BEGIN_NAMESPACE
25
26class QVideoFramePrivate : public QSharedData
27{
28public:
29 QVideoFramePrivate() = default;
30
31 ~QVideoFramePrivate()
32 {
33 if (videoBuffer && mapMode != QVideoFrame::NotMapped)
34 videoBuffer->unmap();
35 }
36
37 template <typename Buffer>
38 static QVideoFrame createFrame(std::unique_ptr<Buffer> buffer, QVideoFrameFormat format)
39 {
40 QVideoFrame result;
41 result.d.reset(ptr: new QVideoFramePrivate(std::move(format), std::move(buffer)));
42 return result;
43 }
44
45 template <typename Buffer = QAbstractVideoBuffer>
46 QVideoFramePrivate(QVideoFrameFormat format, std::unique_ptr<Buffer> buffer = nullptr)
47 : format{ std::move(format) }, videoBuffer{ std::move(buffer) }
48 {
49 if constexpr (std::is_base_of_v<QHwVideoBuffer, Buffer>)
50 hwVideoBuffer = static_cast<QHwVideoBuffer *>(videoBuffer.get());
51 else if constexpr (std::is_same_v<QAbstractVideoBuffer, Buffer>)
52 hwVideoBuffer = dynamic_cast<QHwVideoBuffer *>(videoBuffer.get());
53 // else hwVideoBuffer == nullptr
54 }
55
56 static QVideoFramePrivate *handle(QVideoFrame &frame) { return frame.d.get(); };
57
58 static QHwVideoBuffer *hwBuffer(const QVideoFrame &frame)
59 {
60 return frame.d ? frame.d->hwVideoBuffer : nullptr;
61 };
62
63 static QAbstractVideoBuffer *buffer(const QVideoFrame &frame)
64 {
65 return frame.d ? frame.d->videoBuffer.get() : nullptr;
66 };
67
68 QVideoFrame adoptThisByVideoFrame()
69 {
70 QVideoFrame frame;
71 frame.d = QExplicitlySharedDataPointer(this, QAdoptSharedDataTag{});
72 return frame;
73 }
74
75 qint64 startTime = -1;
76 qint64 endTime = -1;
77 QAbstractVideoBuffer::MapData mapData;
78 QVideoFrame::MapMode mapMode = QVideoFrame::NotMapped;
79 QVideoFrameFormat format;
80 std::unique_ptr<QAbstractVideoBuffer> videoBuffer;
81 QHwVideoBuffer *hwVideoBuffer = nullptr;
82 int mappedCount = 0;
83 QMutex mapMutex;
84 QString subtitleText;
85 QImage image;
86 QMutex imageMutex;
87 VideoTransformation presentationTransformation;
88
89private:
90 Q_DISABLE_COPY(QVideoFramePrivate)
91};
92
93QT_END_NAMESPACE
94
95#endif // QVIDEOFRAMEPRIVATE_P_H
96

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