6#include <gst/video/video-frame.h>
7#include <gst/video/video-info.h>
10#include <QtCore/QByteArray>
11#include <QtCore/QMutex>
12#include <QtCore/QSize>
13#include <QtMultimedia/QAbstractVideoBuffer>
14#include <QtMultimedia/QVideoFrame>
15#include <QtMultimedia/QVideoFrameFormat>
18class CpuVideoFramePool
21 static CpuVideoFramePool&
instance();
24 QVideoFrame
acquireFrame(
const QVideoFrameFormat& format,
const GstVideoInfo& info);
38 static std::unique_ptr<QAbstractVideoBuffer>
wrapZeroCopy(GstBuffer* buffer,
const GstVideoInfo& info,
39 const QVideoFrameFormat& format,
55 static QAbstractVideoBuffer::MapData
mapDataFor(
const GstVideoFrame& frame);
70 bool mapFrame(GstBuffer* buffer,
const GstVideoInfo& info, GstMapFlags flags = GST_MAP_READ);
73 const GstVideoFrame&
frame()
const {
return _frame; }
76 QAbstractVideoBuffer::MapData
map(GstBuffer* buffer,
const GstVideoInfo& info);
77 void unmap() noexcept;
80 GstVideoFrame _frame = {};
87 static QVideoFrame
copyFromBuffer(GstBuffer* buffer,
const GstVideoInfo& videoInfo,
88 const QVideoFrameFormat& format);
91 void releaseBacking(QSize size, QVideoFrameFormat::PixelFormat format, QByteArray&& backing);
94 CpuVideoFramePool() =
default;
96 QByteArray acquireBacking(
const PlaneLayout& layout, QSize size, QVideoFrameFormat::PixelFormat format);
98 static constexpr int kMaxPerSlot = 4;
100 static constexpr int kMaxSlots = 8;
105 QVideoFrameFormat::PixelFormat format = QVideoFrameFormat::Format_Invalid;
106 std::array<QByteArray, kMaxPerSlot> available;
107 int availableCount = 0;
111 std::array<Slot, kMaxSlots> _slots;
112 int _evictCursor = 0;
bool mapFrame(GstBuffer *buffer, const GstVideoInfo &info, GstMapFlags flags=GST_MAP_READ)
Maps buffer with flags on the first call; false when that fails.
const GstVideoFrame & frame() const
The mapped frame; valid while mapFrame() succeeded and unmap() hasn't run.
FrameMapping(const FrameMapping &)=delete
QAbstractVideoBuffer::MapData map(GstBuffer *buffer, const GstVideoInfo &info)
mapFrame() for reading, as Qt map data; empty when the map fails.
FrameMapping & operator=(const FrameMapping &)=delete
static std::unique_ptr< QAbstractVideoBuffer > wrapZeroCopy(GstBuffer *buffer, const GstVideoInfo &info, const QVideoFrameFormat &format, const PinnedFrameCounter &pinned)
std::shared_ptr< std::atomic< int > > PinnedFrameCounter
Live zero-copy frames of one sink; shared so frames Qt still holds after the sink is gone can release...
static CpuVideoFramePool & instance()
static QVideoFrame copyFromBuffer(GstBuffer *buffer, const GstVideoInfo &videoInfo, const QVideoFrameFormat &format)
static constexpr int kMaxPinnedFrames
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 QAbstractVideoBuffer::MapData mapDataFor(const GstVideoFrame &frame)
Qt map data for a frame mapped with gst_video_frame_map, each plane sized by its own row count.