3#include <QtCore/QByteArray>
4#include <QtCore/QMutex>
6#include <QtMultimedia/QVideoFrame>
7#include <QtMultimedia/QVideoFrameFormat>
11#include <gst/video/video-info.h>
14class QAbstractVideoBuffer;
23 QVideoFrame
acquireFrame(
const QVideoFrameFormat& format,
const GstVideoInfo& info);
27 static std::unique_ptr<QAbstractVideoBuffer>
wrapZeroCopy(GstBuffer* buffer,
const GstVideoInfo& info,
28 const QVideoFrameFormat& format);
31 quint64
hitCount() const noexcept {
return _hits.load(std::memory_order_relaxed); }
33 quint64
missCount() const noexcept {
return _misses.load(std::memory_order_relaxed); }
48 static QVideoFrame
copyFromBuffer(GstBuffer* buffer,
const GstVideoInfo& videoInfo,
49 const QVideoFrameFormat& format);
52 void releaseBacking(QSize size, QVideoFrameFormat::PixelFormat format, QByteArray&& backing);
57 QByteArray acquireBacking(
const PlaneLayout& layout, QSize size, QVideoFrameFormat::PixelFormat format);
59 static constexpr int kMaxPerSlot = 4;
61 static constexpr int kMaxSlots = 8;
66 QVideoFrameFormat::PixelFormat format = QVideoFrameFormat::Format_Invalid;
67 std::array<QByteArray, kMaxPerSlot> available;
68 int availableCount = 0;
72 std::array<Slot, kMaxSlots> _slots;
74 std::atomic<quint64> _hits{0};
75 std::atomic<quint64> _misses{0};
Recycles CPU-backed QVideoFrame storage keyed by (size, pixelFormat) to avoid per-frame malloc churn.
static CpuVideoFramePool & instance()
static QVideoFrame copyFromBuffer(GstBuffer *buffer, const GstVideoInfo &videoInfo, const QVideoFrameFormat &format)
Copy buffer's planes into a pool-allocated QVideoFrame; invalid on stride overflow or unsupported for...
quint64 missCount() const noexcept
void releaseBacking(QSize size, QVideoFrameFormat::PixelFormat format, QByteArray &&backing)
Return a backing array to the pool; called by PooledCpuVideoBuffer's destructor only.
static PlaneLayout computeLayout(const GstVideoInfo &info)
Destination plane layout mirroring info (strides/offsets from the decoder). planeCount==0 means unsup...
QVideoFrame acquireFrame(const QVideoFrameFormat &format, const GstVideoInfo &info)
Returns a pool-backed frame sized to info, or freshly allocates on a pool miss; invalid if unsupporte...
static std::unique_ptr< QAbstractVideoBuffer > wrapZeroCopy(GstBuffer *buffer, const GstVideoInfo &info, const QVideoFrameFormat &format)
quint64 hitCount() const noexcept
Telemetry: total acquireFrame() calls satisfied from the pool vs. fresh alloc.