QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstHwVideoBuffer.cc
Go to the documentation of this file.
1#include "GstHwVideoBuffer.h"
2
3#include <rhi/qrhi.h>
4
5GstHwVideoBuffer::GstHwVideoBuffer(QVideoFrame::HandleType handleType, GstSample* sample, const GstVideoInfo& videoInfo,
6 QVideoFrameFormat format)
7 : QHwVideoBuffer(handleType),
8 _sample(sample ? gst_sample_ref(sample) : nullptr),
9 _videoInfo(videoInfo),
10 _format(std::move(format))
11{
12 // Crop is applied by the renderer via QVideoFrameFormat::viewport(); see GStreamerFrameMap::applyCropMeta.
13}
14
16{
17 if (_sample) {
18 gst_sample_unref(_sample);
19 }
20}
21
22bool GstHwVideoBuffer::checkMapPreconditions(const QRhi& rhi, int expectedBackend, const QLoggingCategory& cat,
23 GstHw::MapDiagnostics& diag, GstBuffer*& outBuffer) const
24{
25 if (!_sample) {
26 if (!diag.loggedNullSample.exchange(true, std::memory_order_relaxed))
27 qCWarning(cat) << "mapTextures: GstSample is null";
28 return false;
29 }
30 if (!rhi.thread()->isCurrentThread()) {
31 if (!diag.loggedWrongThread.exchange(true, std::memory_order_relaxed))
32 qCWarning(cat) << "mapTextures: called outside QRhi render thread";
33 return false;
34 }
35 if (static_cast<int>(rhi.backend()) != expectedBackend) {
36 if (!diag.loggedBadBackend.exchange(true, std::memory_order_relaxed))
37 qCWarning(cat) << "mapTextures: QRhi backend is" << rhi.backendName() << "(backend id" << expectedBackend
38 << "required)";
39 return false;
40 }
41 outBuffer = gst_sample_get_buffer(_sample);
42 if (!outBuffer) {
43 if (!diag.loggedNullBuffer.exchange(true, std::memory_order_relaxed))
44 qCWarning(cat) << "mapTextures: GstSample has no buffer";
45 return false;
46 }
47 return true;
48}
49
50void GstHwVideoBuffer::logFirstSuccess(std::atomic<bool>& flag, const QLoggingCategory& cat, const char* tag,
51 QSize frameSize, QVideoFrameFormat::PixelFormat pixelFormat, int planes)
52{
53 if (!flag.exchange(true, std::memory_order_relaxed)) {
54 qCInfo(cat) << "First" << tag << "zero-copy mapTextures success: size=" << frameSize
55 << "format=" << int(pixelFormat) << "planes=" << planes;
56 }
57}
GstHwVideoBuffer(QVideoFrame::HandleType handleType, GstSample *sample, const GstVideoInfo &videoInfo, QVideoFrameFormat format)
~GstHwVideoBuffer() override
static void logFirstSuccess(std::atomic< bool > &flag, const QLoggingCategory &cat, const char *tag, QSize frameSize, QVideoFrameFormat::PixelFormat pixelFormat, int planes)
One-shot "first zero-copy success" info line; silent after flag first flips.
bool checkMapPreconditions(const QRhi &rhi, int expectedBackend, const QLoggingCategory &cat, GstHw::MapDiagnostics &diag, GstBuffer *&outBuffer) const
Shared mapTextures preamble; warns once per cause via diag flags, returns false on first failure.
One-shot warning flags per failure cause; paths with extra causes (D3D, IOSurface) derive and add mem...
std::atomic< bool > loggedNullSample
std::atomic< bool > loggedNullBuffer
std::atomic< bool > loggedBadBackend
std::atomic< bool > loggedWrongThread