diff options
author | Lars Knoll <lars.knoll@qt.io> | 2021-04-13 10:09:11 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-04-16 11:00:32 +0000 |
commit | 919d33f108f3cd54b4d36d873bda63eb22cfcfd5 (patch) | |
tree | 3d4e547486fdf2cf78b499b1f0315f84a4fbe1c9 /src/multimedia/video | |
parent | 1306531589d45a96a39db6e37706c30bf38934db (diff) |
Remove QVideoFrame(QImage) constructor
It doesn't make a lot of sense and only ever worked for some
image formats. In addition, it's never used except for some auto tests.
Change-Id: I6a32eabca8c36646ffc11d728e9cdf9b2f74d758
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia/video')
-rw-r--r-- | src/multimedia/video/qimagevideobuffer.cpp | 86 | ||||
-rw-r--r-- | src/multimedia/video/qimagevideobuffer_p.h | 80 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.cpp | 24 | ||||
-rw-r--r-- | src/multimedia/video/qvideoframe.h | 5 | ||||
-rw-r--r-- | src/multimedia/video/qvideotexturehelper.cpp | 84 | ||||
-rw-r--r-- | src/multimedia/video/qvideotexturehelper_p.h | 3 |
6 files changed, 69 insertions, 213 deletions
diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp deleted file mode 100644 index 58ec66fa1..000000000 --- a/src/multimedia/video/qimagevideobuffer.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qimagevideobuffer_p.h" - -#include <qimage.h> - -QT_BEGIN_NAMESPACE - -/*! - * \class QImageVideoBuffer - * \internal - * - * A video buffer class for a QImage. - */ - -QImageVideoBuffer::QImageVideoBuffer(const QImage &image) - : QAbstractVideoBuffer(QVideoFrame::NoHandle) -{ - this->image = image; -} - -QImageVideoBuffer::~QImageVideoBuffer() = default; - -QVideoFrame::MapMode QImageVideoBuffer::mapMode() const -{ - return m_mapMode; -} - -QImageVideoBuffer::MapData QImageVideoBuffer::map(QVideoFrame::MapMode mode) -{ - MapData mapData; - if (m_mapMode == QVideoFrame::NotMapped && image.bits() && mode != QVideoFrame::NotMapped) { - m_mapMode = mode; - - mapData.nBytes = int(image.sizeInBytes()); - mapData.nPlanes = 1; - mapData.bytesPerLine[0] = image.bytesPerLine(); - mapData.data[0] = image.bits(); - } - - return mapData; -} - -void QImageVideoBuffer::unmap() -{ - m_mapMode = QVideoFrame::NotMapped; -} - -QT_END_NAMESPACE diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h deleted file mode 100644 index 15176f52c..000000000 --- a/src/multimedia/video/qimagevideobuffer_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QIMAGEVIDEOBUFFER_P_H -#define QIMAGEVIDEOBUFFER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qabstractvideobuffer_p.h> -#include <qvideoframe.h> - -QT_BEGIN_NAMESPACE - -class QImage; - -class Q_MULTIMEDIA_EXPORT QImageVideoBuffer : public QAbstractVideoBuffer -{ -public: - QImageVideoBuffer(const QImage &image); - ~QImageVideoBuffer(); - - QVideoFrame::MapMode mapMode() const override; - - MapData map(QVideoFrame::MapMode mode) override; - void unmap() override; - -private: - QVideoFrame::MapMode m_mapMode = QVideoFrame::NotMapped; - QImage image; -}; - -QT_END_NAMESPACE - - -#endif diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp index 9995b9708..8f95706bb 100644 --- a/src/multimedia/video/qvideoframe.cpp +++ b/src/multimedia/video/qvideoframe.cpp @@ -39,7 +39,7 @@ #include "qvideoframe.h" -#include "qimagevideobuffer_p.h" +#include "qvideotexturehelper_p.h" #include "qmemoryvideobuffer_p.h" #include "qvideoframeconversionhelper_p.h" #include "qvideoframeformat.h" @@ -263,6 +263,7 @@ QVideoFrame::QVideoFrame() } /*! + \internal Constructs a video frame from a \a buffer with the given pixel \a format and \a size in pixels. \note This doesn't increment the reference count of the video buffer. @@ -279,35 +280,22 @@ QVideoFrame::QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat & The \a bytesPerLine (stride) is the length of each scan line in bytes, and \a bytes is the total number of bytes that must be allocated for the frame. */ -QVideoFrame::QVideoFrame(int bytes, int bytesPerLine, const QVideoFrameFormat &format) +QVideoFrame::QVideoFrame(const QVideoFrameFormat &format) : d(new QVideoFramePrivate(format)) { + auto *textureDescription = QVideoTextureHelper::textureDescription(format.pixelFormat()); + qsizetype bytes = textureDescription->bytesForSize(format.frameSize()); if (bytes > 0) { QByteArray data; data.resize(bytes); // Check the memory was successfully allocated. if (!data.isEmpty()) - d->buffer = new QMemoryVideoBuffer(data, bytesPerLine); + d->buffer = new QMemoryVideoBuffer(data, textureDescription->stride*format.frameWidth()); } } /*! - Constructs a video frame from an \a image. - - \note This will construct an invalid video frame if there is no frame type equivalent to the - image format. - - \sa pixelFormatFromImageFormat() -*/ -QVideoFrame::QVideoFrame(const QImage &image) - : d(new QVideoFramePrivate(QVideoFrameFormat(image.size(), - QVideoFrameFormat::pixelFormatFromImageFormat(image.format())))) -{ - d->buffer = new QImageVideoBuffer(image); -} - -/*! Constructs a shallow copy of \a other. Since QVideoFrame is explicitly shared, these two instances will reflect the same frame. diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h index 2d5e2d57e..1ee2de622 100644 --- a/src/multimedia/video/qvideoframe.h +++ b/src/multimedia/video/qvideoframe.h @@ -76,9 +76,7 @@ public: }; QVideoFrame(); - QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format); - QVideoFrame(int bytes, int bytesPerLine, const QVideoFrameFormat &format); - QVideoFrame(const QImage &image); + QVideoFrame(const QVideoFrameFormat &format); QVideoFrame(const QVideoFrame &other); ~QVideoFrame(); @@ -126,6 +124,7 @@ public: QImage toImage() const; + QVideoFrame(QAbstractVideoBuffer *buffer, const QVideoFrameFormat &format); private: QExplicitlySharedDataPointer<QVideoFramePrivate> d; }; diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp index 706844022..77ad98f3e 100644 --- a/src/multimedia/video/qvideotexturehelper.cpp +++ b/src/multimedia/video/qvideotexturehelper.cpp @@ -45,135 +45,167 @@ namespace QVideoTextureHelper static const TextureDescription descriptions[QVideoFrameFormat::NPixelFormats] = { // Format_Invalid - { 0, + { 0, 0, + [](QSize) { return 0; }, { QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat}, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ARGB32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ARGB32_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_RGB32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGRA32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGRA32_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_ABGR32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_BGR32 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_AYUV444 - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_AYUV444_Premultiplied - { 1, + { 1, 4, + [](QSize s) { return 4*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_YUV420P - { 3, + { 3, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_YUV422P - { 3, + { 3, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 1 }, { 2, 1 } } }, // Format_YV12 - { 3, + { 3, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_UYVY - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 2, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_YUYV - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::BGRA8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 2, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_NV12 - { 2, + { 2, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_NV21 - { 2, + { 2, 1, + [](QSize s) { return 3*s.width()*s.height() / 2; }, { QRhiTexture::R8, QRhiTexture::RG8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_IMC1 - { 3, + { 3, 1, + [](QSize s) { + // IMC1 requires that U and V components are aligned on a multiple of 16 lines + return s.width()*((s.height()*3/2 + 15) & ~15 + s.height()/2); + }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_IMC2 - { 2, + { 2, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 2 }, { 1, 1 } } }, // Format_IMC3 - { 3, + { 3, 1, + [](QSize s) { + // IMC3 requires that U and V components are aligned on a multiple of 16 lines + return s.width()*((s.height()*3/2 + 15) & ~15 + s.height()/2); + }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::R8 }, { { 1, 1 }, { 2, 2 }, { 2, 2 } } }, // Format_IMC4 - { 2, + { 2, 1, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::R8, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 2 }, { 1, 1 } } }, // Format_Y8 - { 1, + { 1, 1, + [](QSize s) { return s.width()*s.height(); }, { QRhiTexture::R8, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_Y16 - { 1, + { 1, 2, + [](QSize s) { return 2*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } }, // Format_P010 - { 2, + { 2, 2, + [](QSize s) { return 3*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_P016 - { 2, + { 2, 2, + [](QSize s) { return 3*s.width()*s.height(); }, { QRhiTexture::R16, QRhiTexture::RG16, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 2, 2 }, { 1, 1 } } }, // Format_Jpeg - { 1, + { 1, 0, + [](QSize) { return 0; }, { QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat, QRhiTexture::UnknownFormat }, { { 1, 1 }, { 1, 1 }, { 1, 1 } } } diff --git a/src/multimedia/video/qvideotexturehelper_p.h b/src/multimedia/video/qvideotexturehelper_p.h index 153752010..e0b72243a 100644 --- a/src/multimedia/video/qvideotexturehelper_p.h +++ b/src/multimedia/video/qvideotexturehelper_p.h @@ -57,8 +57,11 @@ struct TextureDescription int x; int y; }; + using BytesForSize = int(*)(QSize s); int nplanes; + int stride; + BytesForSize bytesForSize; QRhiTexture::Format textureFormat[maxPlanes]; SizeScale sizeScale[maxPlanes]; }; |