summaryrefslogtreecommitdiffstats
path: root/src/multimedia
diff options
context:
space:
mode:
authorArtem Dyomin <artem.dyomin@qt.io>2024-02-07 21:09:12 +0100
committerArtem Dyomin <artem.dyomin@qt.io>2024-02-08 16:58:26 +0000
commitdb3ac8055f3e7adcd41a07fd251b04b2f6a32aa6 (patch)
tree3db6c04bc4c590e7eede73833068f5334b7b6e71 /src/multimedia
parente808a14d08d37fbf227b3e38e06239490202876b (diff)
Map/unmap QVideoFrame one time upon loading textures from memory
If the planes count is more than 1, no reason to map/unmap frame for handling each plane. Pick-to: 6.7 6.6 6.5 Change-Id: I158e0faa4a9f1e6c617a3a7f245ee084bfdad50b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mikko Hallamaa <mikko.hallamaa@qt.io> Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r--src/multimedia/video/qvideotexturehelper.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp
index a0a87b24a..84b3fad32 100644
--- a/src/multimedia/video/qvideotexturehelper.cpp
+++ b/src/multimedia/video/qvideotexturehelper.cpp
@@ -587,14 +587,9 @@ void updateUniformData(QByteArray *dst, const QVideoFrameFormat &format, const Q
ud->maxLum = fromLinear(float(maxNits)/100.f);
}
-static bool updateTextureWithMap(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, int plane, std::unique_ptr<QRhiTexture> &tex)
+static bool updateTextureWithMap(QVideoFrame& frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, int plane, std::unique_ptr<QRhiTexture> &tex)
{
- if (!frame.map(QVideoFrame::ReadOnly)) {
- qWarning() << "could not map data of QVideoFrame for upload";
- return false;
- }
-
- auto unmapFrameGuard = qScopeGuard([&frame] { frame.unmap(); });
+ Q_ASSERT(frame.isMapped());
QVideoFrameFormat fmt = frame.surfaceFormat();
QVideoFrameFormat::PixelFormat pixelFormat = fmt.pixelFormat();
@@ -718,7 +713,7 @@ static std::unique_ptr<QVideoFrameTextures> createTexturesFromHandles(const QVid
return {};
}
-std::unique_ptr<QVideoFrameTextures> createTexturesFromMemory(const QVideoFrame &frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, QVideoFrameTextures *old)
+static std::unique_ptr<QVideoFrameTextures> createTexturesFromMemory(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *rub, QVideoFrameTextures *old)
{
const TextureDescription &texDesc = descriptions[frame.surfaceFormat().pixelFormat()];
QVideoFrameTexturesArray::TextureArray textures;
@@ -726,6 +721,13 @@ std::unique_ptr<QVideoFrameTextures> createTexturesFromMemory(const QVideoFrame
if (oldArray)
textures = oldArray->takeTextures();
+ if (!frame.map(QVideoFrame::ReadOnly)) {
+ qWarning() << "could not map data of QVideoFrame for upload";
+ return {};
+ }
+
+ auto unmapFrameGuard = qScopeGuard([&frame] { frame.unmap(); });
+
bool ok = true;
for (quint8 plane = 0; plane < texDesc.nplanes; ++plane) {
ok &= updateTextureWithMap(frame, rhi, rub, plane, textures[plane]);