8#include <private/qhwvideobuffer_p.h>
9#include <private/qvideotexturehelper_p.h>
14#include <QtCore/QLoggingCategory>
15#include <QtCore/QSize>
16#include <QtMultimedia/QVideoFrame>
17#include <QtMultimedia/QVideoFrameFormat>
29 QVideoFrameFormat::PixelFormat
pixelFormat = QVideoFrameFormat::Format_Invalid;
32 const QLoggingCategory*
log =
nullptr;
49 QRhiTexture*
texture(uint plane)
const override
51 return plane < static_cast<uint>(
_count) ?
_textures[plane].get() :
nullptr;
63 g_clear_pointer(&
_srcSample, gst_sample_unref);
69 template <
class Handles>
70 bool matchesImport(
const QRhi* rhi, QSize size, QVideoFrameFormat::PixelFormat pixelFormat,
71 const Handles& handles)
const noexcept
73 if ((
_rhi != rhi) || (_size != size) || (_pixelFormat != pixelFormat) ||
77 for (
int i = 0; i <
_count; ++i) {
78 if (_nativeHandles[std::size_t(i)] != nativeHandle(handles[std::size_t(i)])) {
90 return dynamic_cast<FT*
>(old.get());
97 template <
class FT,
class Reuse,
class Make>
101 if constexpr (!std::is_null_pointer_v<std::remove_cvref_t<Reuse>>) {
104 prev->setSourceSample(source.
refSample());
105 return std::move(old);
112 std::unique_ptr<FT> textures = make();
114 if (!textures || !textures->allPlanesValid()) {
118 "QRhiTexture::createFrom failed (format=" <<
int(tail.
pixelFormat) <<
"size=" << tail.
frameSize <<
")");
122 qCInfo(*tail.
log) <<
"First" << tail.
successTag <<
"zero-copy mapTextures success: size=" << tail.
frameSize
123 <<
"format=" << int(tail.
pixelFormat) <<
"planes=" << textures->_count;
125 textures->setSourceSample(source.
refSample());
134 template <
class Handles>
135 void wrapPlanes(QRhi* rhi, QSize size, QVideoFrameFormat::PixelFormat pixelFormat,
const Handles& handles,
136 int layout = 0, QRhiTexture::Flags flags = {})
140 _pixelFormat = pixelFormat;
142 for (
int i = 0; i <
_count; ++i) {
143 _nativeHandles[std::size_t(i)] = nativeHandle(handles[std::size_t(i)]);
145 const auto* desc = QVideoTextureHelper::textureDescription(pixelFormat);
149 for (
int i = 0; i <
_count; ++i) {
150 const quint64 handle = _nativeHandles[std::size_t(i)];
155 desc->rhiTextureFormat(i, rhi, QVideoTextureHelper::TextureDescription::FallbackPolicy::Disable),
156 desc->rhiPlaneSize(size, i, rhi), 1, flags));
170 template <
class Handle>
171 static quint64 nativeHandle(Handle handle)
noexcept
173 if constexpr (std::is_pointer_v<Handle>) {
174 return static_cast<quint64
>(
reinterpret_cast<quintptr
>(handle));
176 return static_cast<quint64
>(handle);
181 QVideoFrameFormat::PixelFormat _pixelFormat = QVideoFrameFormat::Format_Invalid;
182 std::array<quint64, GstHw::kMaxPlanes> _nativeHandles{};
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
#define QGC_HW_WARN_ONCE(LOGCAT, FLAG,...)
Logs once via qCWarning(LOGCAT) the first time FLAG flips true; subsequent trips are silent.
void wrapPlanes(QRhi *rhi, QSize size, QVideoFrameFormat::PixelFormat pixelFormat, const Handles &handles, int layout=0, QRhiTexture::Flags flags={})
bool matchesImport(const QRhi *rhi, QSize size, QVideoFrameFormat::PixelFormat pixelFormat, const Handles &handles) const noexcept
QRhiTexture * texture(uint plane) const override
void setSourceSample(GstSample *s) noexcept
Transfers a ref into the bundle. Caller must have a fresh ref.
~GstHwFrameTexturesBase() override
std::unique_ptr< QRhiTexture > _textures[GstHw::kMaxPlanes]
static QVideoFrameTexturesUPtr finishMap(GstHwVideoBuffer &source, QRhi &rhi, QVideoFrameTexturesUPtr &old, const GstHwMapTail &tail, Reuse &&reuse, Make &&make)
bool allPlanesValid() const noexcept
True when the bundle has planes and every one of them wrapped its native handle.
static FT * reusableBundle(QVideoFrameTexturesUPtr &old)
Common base for GStreamer-backed QHwVideoBuffer subclasses.
GstSample * refSample() noexcept
bool preflightOrRecord(QRhi &rhi, HwVideoBufferPath path, QVideoFrameFormat::PixelFormat pixelFormat, const QSize &size, QRhiTexture::Flags flags)
QVideoFrameTexturesUPtr fail(HwVideoBufferPath path) noexcept
Records a map failure for path and returns the empty bundle mapTextures() reports it with.
@ TextureReuse
Prior frame's QRhiTexture wrappers reused (decoder pool returned same native handle).
void recordFallbackReason(HwVideoBufferPath attemptedPath, HwFallbackReason reason) noexcept
Per-(path,reason) fallback accounting; lets a bug report show why a path demoted to CPU.
void record(HwVideoBufferPath path, Counter counter) noexcept
constexpr int kMaxPlanes
Matches GST_VIDEO_MAX_PLANES (gst-video pins it at 4); single source of truth for every per-platform ...
Per-call inputs of GstHwFrameTexturesBase::finishMap().
bool preflight
False when the caller already preflighted before its costly native import work.
QVideoFrameFormat::PixelFormat pixelFormat
const QLoggingCategory * log
Required: where finishMap() logs, and its once-only flags.
const char * successTag
Logs the one-shot first-success line under this tag when set.
QRhiTexture::Flags textureFlags
GstHw::MapDiagnostics * diag
One-shot warning flags per failure cause; paths with extra causes (DMABuf, D3D, IOSurface) derive and...
std::atomic< bool > loggedTextureCreateFail
std::atomic< bool > loggedFirstSuccess