5#ifdef QGC_UNITTEST_BUILD
8#include <QtCore/QMutex>
18 "SinkCapsPolicy::gpuBin's value-initialized default must be Passthrough");
22#if defined(QGC_HAS_GST_DMABUF_GPU_PATH)
24std::string sinkDmaDrmCaps([[maybe_unused]]
void* display)
27#if GST_CHECK_VERSION(1, 24, 0)
40constexpr const char* kGlMemory2D =
"video/x-raw(memory:GLMemory), texture-target=2D";
42constexpr const char* kD3D12Memory =
"video/x-raw(memory:D3D12Memory)";
44constexpr const char* kD3D12ConvertFormats =
"(string){ RGBA, BGRA }";
45#if defined(QGC_HAS_GST_D3D11_GPU_PATH) && defined(QGC_HAS_GST_D3D12_GPU_PATH)
47constexpr const char* kD3D12DecoderFormats =
"(string){ NV12, P010_10LE }";
51std::string gpuMemoryCaps(
const SinkCapsPolicy& policy,
const std::string& formats)
54 [[maybe_unused]]
const auto offer = [&caps, &formats](
const char* mediaType) {
60 switch (policy.target.backend) {
64#if defined(QGC_HAS_GST_DMABUF_GPU_PATH)
65 if (policy.target.egl && policy.dmaBufDisplay) {
66 caps += sinkDmaDrmCaps(policy.dmaBufDisplay);
70 offer(
"video/x-raw(memory:DMABuf)");
73#if defined(QGC_HAS_GST_GLMEMORY_GPU_PATH)
78#if defined(QGC_HAS_GST_AHARDWAREBUFFER_GPU_PATH)
79 if (policy.target.egl) {
80 offer(
"video/x-raw(memory:AHardwareBuffer)");
85#if defined(QGC_HAS_GST_D3D11_GPU_PATH)
86#if defined(QGC_HAS_GST_D3D12_GPU_PATH)
88 if (policy.d3d11OpensD3D12) {
89 caps += std::string(kD3D12Memory) +
", format=" + kD3D12DecoderFormats +
"; ";
92 offer(
"video/x-raw(memory:D3D11Memory)");
98#if defined(QGC_HAS_GST_DMABUF_VULKAN_IMPORT) && GST_CHECK_VERSION(1, 24, 0)
99 if (policy.dmaBufDisplay) {
122 return std::string(kD3D12Memory) +
", format=" + kD3D12ConvertFormats;
125 return (policy.gpuZeroCopy ? gpuMemoryCaps(policy, formats) : std::string()) +
"video/x-raw, format=" + formats;
129std::string sinkCapsWithSquarePixels(
const std::string& caps)
135 gst_caps_set_simple(parsed.get(),
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1,
nullptr);
137 return text ? std::string(text.get()) : caps;
147 const std::string caps = sinkMemoryCaps(policy);
148 return policy.
squarePixels ? sinkCapsWithSquarePixels(caps) : caps;
151#ifdef QGC_UNITTEST_BUILD
154Q_CONSTINIT QBasicMutex s_testEnvironmentMutex;
155std::optional<SinkEnvironment> s_testEnvironment;
159ScopedSinkEnvironmentForTest::ScopedSinkEnvironmentForTest(
const SinkEnvironment& environment)
161 const QMutexLocker lock(&s_testEnvironmentMutex);
162 _previous = std::exchange(s_testEnvironment, environment);
165ScopedSinkEnvironmentForTest::~ScopedSinkEnvironmentForTest()
167 const QMutexLocker lock(&s_testEnvironmentMutex);
168 s_testEnvironment = _previous;
171std::optional<SinkEnvironment> sinkEnvironmentForTest()
173 const QMutexLocker lock(&s_testEnvironmentMutex);
174 return s_testEnvironment;
std::unique_ptr< GstCaps, GstCapsDeleter > GstCapsPtr
GCharPtr adoptGChar(gchar *str) noexcept
GstCapsPtr adoptCaps(GstCaps *caps) noexcept
std::unique_ptr< gchar, GFreeDeleter > GCharPtr
std::string buildSupportedDmaDrmCaps(std::span< const GstVideoFormat > formats, void *display)
std::string buildVulkanDmaDrmCaps(std::span< const GstVideoFormat > formats)
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
constexpr unsigned kOfferDmaDrm
The EGL-derived DMA_DRM caps: formats the DMABuf importer takes with an explicit modifier.
constexpr unsigned kOfferGlUpload
@ GlUpload
glupload → glcolorconvert → GLMemory 2D; gst-gl imports LINEAR and vendor-tiled DMABuf.
@ Passthrough
Every compiled native memory straight into qgcqvideosink (Windows, Apple, ...).
std::vector< GstVideoFormat > advertisedFormats(unsigned requiredOffers=0)
The advertised formats carrying every flag in requiredOffers, in table order.
std::string advertisedFormatList(unsigned requiredOffers=0)
@ Unknown
No scene graph yet, and the GUI thread hasn't recorded the requested API either.
@ Null
QRhi's Null backend or the software renderer: no GPU import.
std::string buildSinkCaps(const SinkCapsPolicy &policy)
Everything qgcqvideosink's caps depend on.
bool squarePixels
Ask for square pixels, in every kind of memory. The bin's converter scales system memory to them.