| 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(QByteArray data, int bytesPerLine) |
| 21 | : m_bytesPerLine(bytesPerLine), m_data(std::move(data)) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | /*! |
| 26 | Destroys a system memory allocated video buffer. |
| 27 | */ |
| 28 | QMemoryVideoBuffer::~QMemoryVideoBuffer() = default; |
| 29 | |
| 30 | /*! |
| 31 | \reimp |
| 32 | */ |
| 33 | QAbstractVideoBuffer::MapData QMemoryVideoBuffer::map(QVideoFrame::MapMode mode) |
| 34 | { |
| 35 | MapData mapData; |
| 36 | |
| 37 | if (!m_data.isEmpty()) { |
| 38 | mapData.planeCount = 1; |
| 39 | mapData.bytesPerLine[0] = m_bytesPerLine; |
| 40 | // avoid detaching and extra copying in case the underlyingByteArray is |
| 41 | // being held by textures or anything else. |
| 42 | if (mode == QVideoFrame::ReadOnly) |
| 43 | mapData.data[0] = reinterpret_cast<uchar *>(const_cast<char *>(m_data.constData())); |
| 44 | else |
| 45 | mapData.data[0] = reinterpret_cast<uchar *>(m_data.data()); |
| 46 | mapData.dataSize[0] = m_data.size(); |
| 47 | } |
| 48 | |
| 49 | return mapData; |
| 50 | } |
| 51 | |
| 52 | QT_END_NAMESPACE |
| 53 |
