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 | QT_BEGIN_NAMESPACE |
7 | |
8 | /*! |
9 | \class QMemoryVideoBuffer |
10 | \brief The QMemoryVideoBuffer class provides a system memory allocated video data buffer. |
11 | \internal |
12 | |
13 | QMemoryVideoBuffer is the default video buffer for allocating system memory. It may be used to |
14 | allocate memory for a QVideoFrame without implementing your own QAbstractVideoBuffer. |
15 | */ |
16 | |
17 | /*! |
18 | Constructs a video buffer with an image stride of \a bytesPerLine from a byte \a array. |
19 | */ |
20 | QMemoryVideoBuffer::QMemoryVideoBuffer(const QByteArray &array, int bytesPerLine) |
21 | : QAbstractVideoBuffer(QVideoFrame::NoHandle) |
22 | { |
23 | data = array; |
24 | this->bytesPerLine = bytesPerLine; |
25 | } |
26 | |
27 | /*! |
28 | Destroys a system memory allocated video buffer. |
29 | */ |
30 | QMemoryVideoBuffer::~QMemoryVideoBuffer() = default; |
31 | |
32 | /*! |
33 | \reimp |
34 | */ |
35 | QVideoFrame::MapMode QMemoryVideoBuffer::mapMode() const |
36 | { |
37 | return m_mapMode; |
38 | } |
39 | |
40 | /*! |
41 | \reimp |
42 | */ |
43 | QAbstractVideoBuffer::MapData QMemoryVideoBuffer::map(QVideoFrame::MapMode mode) |
44 | { |
45 | MapData mapData; |
46 | if (m_mapMode == QVideoFrame::NotMapped && data.size() && mode != QVideoFrame::NotMapped) { |
47 | m_mapMode = mode; |
48 | |
49 | mapData.nPlanes = 1; |
50 | mapData.bytesPerLine[0] = bytesPerLine; |
51 | mapData.data[0] = reinterpret_cast<uchar *>(data.data()); |
52 | mapData.size[0] = data.size(); |
53 | } |
54 | |
55 | return mapData; |
56 | } |
57 | |
58 | /*! |
59 | \reimp |
60 | */ |
61 | void QMemoryVideoBuffer::unmap() |
62 | { |
63 | m_mapMode = QVideoFrame::NotMapped; |
64 | } |
65 | |
66 | QT_END_NAMESPACE |
67 |