diff options
author | Piotr Srebrny <piotr.srebrny@qt.io> | 2022-02-08 17:39:35 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-09 13:23:19 +0000 |
commit | eb47e12fd8927066ca9174b02854f324627e292f (patch) | |
tree | 3ac43a4c4bb4508a21d36efa9fdb95ec3457d9ff | |
parent | d54570a7808e1583c5ebc1fc045867a0822fef49 (diff) |
Fallback on map/upload texture if texture handle is invalid
There is no guarantee that QVideoFrame::textureHandle() will return
a valid texture handle. In some backend implementations texture handle
is generated after QVideoFrame is created in the mapTextures() call,
which may fail. In such case, fallback to QVideoFrame::NoHandle branch.
Fixes: QTBUG-100363
Change-Id: I0ae78b0abfa99af5e4579e454ea70711a8741178
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit 8afe5d160c5a58e79f518d7483561ffbcb67d4e5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/multimedia/video/qvideotexturehelper.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/multimedia/video/qvideotexturehelper.cpp b/src/multimedia/video/qvideotexturehelper.cpp index 07942d93b..2d550e516 100644 --- a/src/multimedia/video/qvideotexturehelper.cpp +++ b/src/multimedia/video/qvideotexturehelper.cpp @@ -44,9 +44,12 @@ #endif #include <qpainter.h> +#include <qloggingcategory.h> QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(qLcVideoTextureHelper, "qt.multimedia.video.texturehelper") + namespace QVideoTextureHelper { @@ -497,15 +500,25 @@ int updateRhiTextures(QVideoFrame frame, QRhi *rhi, QRhiResourceUpdateBatch *res textureFlags |= QRhiTexture::TextureRectangleGL; #endif } + + quint64 textureHandles[TextureDescription::maxPlanes] = {}; + bool textureHandlesOK = true; for (int plane = 0; plane < description->nplanes; ++plane) { - quint64 nativeTexture = frame.textureHandle(plane); - if (!nativeTexture) - qWarning("Texture from QVideoFrame is 0, this cannot be right"); - textures[plane] = rhi->newTexture(description->textureFormat[plane], planeSizes[plane], 1, textureFlags); - if (!textures[plane]->createFrom({nativeTexture, 0})) - qWarning("Failed to initialize QRhiTexture wrapper for native texture object %llu", nativeTexture); + quint64 handle = frame.textureHandle(plane); + textureHandles[plane] = handle; + textureHandlesOK &= handle > 0; + } + + if (textureHandlesOK) { + for (int plane = 0; plane < description->nplanes; ++plane) { + textures[plane] = rhi->newTexture(description->textureFormat[plane], planeSizes[plane], 1, textureFlags); + if (!textures[plane]->createFrom({ textureHandles[plane], 0})) + qWarning("Failed to initialize QRhiTexture wrapper for native texture object %llu", textureHandles[plane]); + } + return description->nplanes; + } else { + qCDebug(qLcVideoTextureHelper) << "Incorrect texture handle from QVideoFrame, trying to map and upload texture"; } - return description->nplanes; } // need to upload textures |