Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qmemoryvideobuffer.cpp
Go to the documentation of this file.
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
#
include
"qmemoryvideobuffer_p.h"
5
6
#
include
<
QtMultimedia
/
private
/
qcaptureslotregistry_p
.
h
>
7
8
#
include
<
QtCore
/
qloggingcategory
.
h
>
9
#
include
<
QtCore
/
qscopeguard
.
h
>
10
11
QT_BEGIN_NAMESPACE
12
13
Q_LOGGING_CATEGORY(qLcCaptureSlots,
"qt.multimedia.captureslots"
)
14
Q_LOGGING_CATEGORY(qLcCaptureSlotsTrace,
"qt.multimedia.captureslots.trace"
)
15
16
/*!
17
\class QMemoryVideoBuffer
18
\brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer.
19
\internal
20
21
QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to
22
allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer.
23
*/
24
25
/*!
26
Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array.
27
*/
28
QMemoryVideoBuffer::QMemoryVideoBuffer(QByteArray data,
int
bytesPerLine)
29
: m_bytesPerLine(bytesPerLine), m_data(std::move(data))
30
{
31
}
32
33
/*!
34
Destroys a system memory allocated video buffer.
35
*/
36
QMemoryVideoBuffer::~QMemoryVideoBuffer() =
default
;
37
38
/*!
39
\reimp
40
*/
41
QAbstractVideoBuffer::MapData QMemoryVideoBuffer::map(QVideoFrame::MapMode mode)
42
{
43
MapData mapData;
44
45
if
(!m_data.isEmpty()) {
46
mapData.planeCount = 1;
47
mapData.bytesPerLine[0] = m_bytesPerLine;
48
// avoid detaching and extra copying in case the underlyingByteArray is
49
// being held by textures or anything else.
50
if
(mode == QVideoFrame::ReadOnly)
51
mapData.data[0] =
reinterpret_cast
<uchar *>(
const_cast
<
char
*>(m_data.constData()));
52
else
53
mapData.data[0] =
reinterpret_cast
<uchar *>(m_data.data());
54
mapData.dataSize[0] = m_data.size();
55
}
56
57
return
mapData;
58
}
59
60
/*!
61
\internal
62
\class QMultiPlaneMemoryVideoBuffer
63
\brief Holds the planes of a video frame in CPU memory, one QByteArray per plane.
64
*/
65
66
QMultiPlaneMemoryVideoBuffer::QMultiPlaneMemoryVideoBuffer(QVarLengthArray<Plane, 4> planes)
67
: m_planes(std::move(planes))
68
{
69
}
70
71
QMultiPlaneMemoryVideoBuffer::~QMultiPlaneMemoryVideoBuffer() =
default
;
72
73
std::unique_ptr<QMultiPlaneMemoryVideoBuffer>
74
QMultiPlaneMemoryVideoBuffer::copyFrom(QAbstractVideoBuffer &source)
75
{
76
const
MapData sourceData = source.map(QVideoFrame::ReadOnly);
77
if
(sourceData.planeCount == 0)
78
return
nullptr
;
79
80
const
QScopeGuard unmapOnExit([&] {
81
source.unmap();
82
});
83
84
QVarLengthArray<Plane, 4> planes;
85
for
(
int
plane = 0; plane < sourceData.planeCount; ++plane) {
86
Plane copy;
87
copy.data = QByteArray(
reinterpret_cast
<
const
char
*>(sourceData.data[plane]),
88
sourceData.dataSize[plane]);
89
copy.bytesPerLine = sourceData.bytesPerLine[plane];
90
planes.append(std::move(copy));
91
}
92
93
return
std::make_unique<QMultiPlaneMemoryVideoBuffer>(std::move(planes));
94
}
95
96
QAbstractVideoBuffer::MapData QMultiPlaneMemoryVideoBuffer::map(QVideoFrame::MapMode mode)
97
{
98
MapData mapData;
99
mapData.planeCount =
int
(m_planes.size());
100
for
(
int
plane = 0; plane < mapData.planeCount; ++plane) {
101
QByteArray &data = m_planes[plane].data;
102
// avoid detaching the array in read-only mode, as the data may be shared
103
mapData.data[plane] =
reinterpret_cast
<uchar *>(
104
mode == QVideoFrame::ReadOnly ?
const_cast
<
char
*>(data.constData()) : data.data());
105
mapData.bytesPerLine[plane] = m_planes[plane].bytesPerLine;
106
mapData.dataSize[plane] =
int
(data.size());
107
}
108
return
mapData;
109
}
110
111
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtmultimedia
src
multimedia
video
qmemoryvideobuffer.cpp
Generated on
for Qt by
1.18.0