summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2022-08-05 14:20:55 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2022-08-09 18:27:44 +0200
commitc37c805b75c9c24a0d032c29e372a2310f9344fa (patch)
tree8ae161bcbf74ca68b9127145a4c8ff69f73d51bc
parent762dbfe09d2d0c0b5c9c1e210d67d403fa9fd5f7 (diff)
downloadqtmultimedia-c37c805b75c9c24a0d032c29e372a2310f9344fa.tar.gz
Remove access to texture handles from public QVideoFrame API
textureHandle and rhiTexture should only be use internally and we can get access to those from QAbstractVideoBuffer Change-Id: Ifad8a3c533b3d76a6b97fde5b2e52986bffd1bb8 Reviewed-by: Lars Knoll <lars.knoll@gmail.com>
-rw-r--r--src/multimedia/video/qvideoframe.cpp24
-rw-r--r--src/multimedia/video/qvideoframe.h3
-rw-r--r--src/multimedia/video/qvideoframeconverter.cpp4
-rw-r--r--src/multimedia/video/qvideotexturehelper.cpp12
-rw-r--r--src/multimedia/video/qvideowindow.cpp5
-rw-r--r--src/multimediaquick/qsgvideonode_p.cpp5
-rw-r--r--tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp5
7 files changed, 25 insertions, 33 deletions
diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp
index de219b239..34ec1527d 100644
--- a/src/multimedia/video/qvideoframe.cpp
+++ b/src/multimedia/video/qvideoframe.cpp
@@ -565,30 +565,6 @@ int QVideoFrame::planeCount() const
}
/*!
- \internal
- Returns a texture id to the video frame's buffers.
-*/
-quint64 QVideoFrame::textureHandle(int plane) const
-{
- if (!d || !d->buffer)
- return 0;
- d->buffer->mapTextures();
- return d->buffer->textureHandle(plane);
-}
-
-/*!
- \internal
- Returns a QRhiTexture of the video frame
-*/
-std::unique_ptr<QRhiTexture> QVideoFrame::rhiTexture(int plane) const
-{
- if (!d || !d->buffer)
- return {};
- d->buffer->mapTextures();
- return d->buffer->texture(plane);
-}
-
-/*!
Returns the presentation time (in microseconds) when the frame should be displayed.
An invalid time is represented as -1.
diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h
index c82382180..be3e8810d 100644
--- a/src/multimedia/video/qvideoframe.h
+++ b/src/multimedia/video/qvideoframe.h
@@ -90,9 +90,6 @@ public:
int mappedBytes(int plane) const;
int planeCount() const;
- quint64 textureHandle(int plane) const;
- std::unique_ptr<QRhiTexture> rhiTexture(int plane) const;
-
qint64 startTime() const;
void setStartTime(qint64 time);
diff --git a/src/multimedia/video/qvideoframeconverter.cpp b/src/multimedia/video/qvideoframeconverter.cpp
index 8cd3151a3..ddf2e491d 100644
--- a/src/multimedia/video/qvideoframeconverter.cpp
+++ b/src/multimedia/video/qvideoframeconverter.cpp
@@ -194,6 +194,10 @@ static bool updateTextures(QRhi *rhi,
auto textureDesc = QVideoTextureHelper::textureDescription(pixelFormat);
+ QAbstractVideoBuffer *vb = frame.videoBuffer();
+ if (!vb)
+ return false;
+ vb->mapTextures();
for (int i = 0; i < QVideoTextureHelper::TextureDescription::maxPlanes; ++i)
QVideoTextureHelper::updateRhiTexture(frame, rhi, rub, i, textures[i]);
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp
index a717d25f0..fa57491d6 100644
--- a/src/multimedia/video/qvideotexturehelper.cpp
+++ b/src/multimedia/video/qvideotexturehelper.cpp
@@ -638,7 +638,7 @@ static bool updateTextureWithMap(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdat
return true;
}
-static bool updateTextureWithHandle(QVideoFrame frame, QRhi *rhi, int plane, std::unique_ptr<QRhiTexture> &tex)
+static bool updateTextureWithHandle(QVideoFrame frame, quint64 handle, QRhi *rhi, int plane, std::unique_ptr<QRhiTexture> &tex)
{
QVideoFrameFormat fmt = frame.surfaceFormat();
QVideoFrameFormat::PixelFormat pixelFormat = fmt.pixelFormat();
@@ -661,7 +661,7 @@ static bool updateTextureWithHandle(QVideoFrame frame, QRhi *rhi, int plane, std
#endif
}
- if (quint64 handle = frame.textureHandle(plane); handle) {
+ if (handle) {
tex.reset(rhi->newTexture(texDesc.textureFormat[plane], planeSize, 1, textureFlags));
if (!tex->createFrom({handle, 0})) {
qWarning("Failed to initialize QRhiTexture wrapper for native texture object %llu",handle);
@@ -682,13 +682,17 @@ void updateRhiTexture(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub
return;
}
+ QAbstractVideoBuffer *vb = frame.videoBuffer();
+ if (!vb)
+ return;
+
if (frame.handleType() == QVideoFrame::RhiTextureHandle) {
- if (std::unique_ptr<QRhiTexture> ftex = frame.rhiTexture(plane); ftex) {
+ if (std::unique_ptr<QRhiTexture> ftex = vb->texture(plane); ftex) {
tex = std::move(ftex);
return;
}
- if (QVideoTextureHelper::updateTextureWithHandle(frame, rhi, plane, tex))
+ if (QVideoTextureHelper::updateTextureWithHandle(frame, vb->textureHandle(plane), rhi, plane, tex))
return;
}
diff --git a/src/multimedia/video/qvideowindow.cpp b/src/multimedia/video/qvideowindow.cpp
index 9e42017d0..cf9bc3292 100644
--- a/src/multimedia/video/qvideowindow.cpp
+++ b/src/multimedia/video/qvideowindow.cpp
@@ -6,6 +6,7 @@
#include <qfile.h>
#include <qpainter.h>
#include <private/qguiapplication_p.h>
+#include <private/qabstractvideobuffer_p.h>
#include <private/qmemoryvideobuffer_p.h>
#include <qpa/qplatformintegration.h>
@@ -213,6 +214,10 @@ void QVideoWindowPrivate::updateTextures(QRhiResourceUpdateBatch *rub)
m_currentFrame = QVideoFrame(new QMemoryVideoBuffer(QByteArray{4, 0}, 4),
QVideoFrameFormat(QSize(1,1), QVideoFrameFormat::Format_RGBA8888));
+ QAbstractVideoBuffer *vb = m_currentFrame.videoBuffer();
+ if (!vb)
+ return;
+ vb->mapTextures();
for (int i = 0; i < QVideoTextureHelper::TextureDescription::maxPlanes; ++i)
QVideoTextureHelper::updateRhiTexture(m_currentFrame, m_rhi.get(), rub, i, m_frameTextures[i]);
diff --git a/src/multimediaquick/qsgvideonode_p.cpp b/src/multimediaquick/qsgvideonode_p.cpp
index 2d843e5aa..166f5625d 100644
--- a/src/multimediaquick/qsgvideonode_p.cpp
+++ b/src/multimediaquick/qsgvideonode_p.cpp
@@ -5,6 +5,7 @@
#include <QtQuick/qsgmaterial.h>
#include "qsgvideotexture_p.h"
#include <QtMultimedia/private/qvideotexturehelper_p.h>
+#include <private/qabstractvideobuffer_p.h>
#include <private/qquicktextnode_p.h>
#include <private/qquickvideooutput_p.h>
#include <qmutex.h>
@@ -123,6 +124,10 @@ void QSGVideoMaterial::updateTextures(QRhi *rhi, QRhiResourceUpdateBatch *resour
m_videoFrameSlots[rhi->currentFrameSlot()] = m_currentFrame;
// update and upload all textures
+ QAbstractVideoBuffer *vb = m_currentFrame.videoBuffer();
+ if (!vb)
+ return;
+ vb->mapTextures();
for (int plane = 0; plane < 3; ++plane) {
QSGVideoTexture *sgTex = m_textures[plane].get();
if (sgTex) {
diff --git a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
index b6e31f6f8..5d3f35844 100644
--- a/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
+++ b/tests/auto/unit/multimedia/qvideoframe/tst_qvideoframe.cpp
@@ -164,7 +164,8 @@ void tst_QVideoFrame::create()
QVERIFY(frame.isValid());
QCOMPARE(frame.handleType(), QVideoFrame::NoHandle);
- QCOMPARE(frame.textureHandle(0), 0u);
+ QVERIFY(frame.videoBuffer() != nullptr);
+ QCOMPARE(frame.videoBuffer()->textureHandle(0), 0u);
QCOMPARE(frame.pixelFormat(), pixelFormat);
QCOMPARE(frame.size(), size);
QCOMPARE(frame.width(), size.width());
@@ -195,7 +196,7 @@ void tst_QVideoFrame::createInvalid()
QVERIFY(!frame.isValid());
QCOMPARE(frame.handleType(), QVideoFrame::NoHandle);
- QCOMPARE(frame.textureHandle(0), 0u);
+ QCOMPARE(frame.videoBuffer(), nullptr);
QCOMPARE(frame.pixelFormat(), pixelFormat);
QCOMPARE(frame.size(), size);
QCOMPARE(frame.width(), size.width());