QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstQgcGpuBin.cc
Go to the documentation of this file.
1#include "GstQgcGpuBin.h"
2
3#ifdef QGC_UNITTEST_BUILD
4#include <optional>
5#endif
6#include <string_view>
7
8#include <QtCore/QByteArray>
9#include <QtCore/QtEnvironmentVariables>
10
11#include "GstQgcRenderTarget.h"
12#include "QGCLoggingCategory.h"
13#ifdef QGC_UNITTEST_BUILD
14#include "GstQgcCaps.h"
15#endif
16
17QGC_LOGGING_CATEGORY(GstQgcGpuBinLog, "Video.GStreamer.GstQgcGpuBin")
18
19namespace GstQgc {
20
22{
23#if defined(QGC_GST_BIN_HAS_GLUPLOAD) && defined(QGC_GST_BIN_HAS_DIRECT_DMABUF)
24 const QByteArray choice = value.trimmed().toByteArray().toLower();
25 if (choice == "dmabuf") {
26 return {.mode = GpuBinMode::DirectDmaBuf, .explicitChoice = true};
27 }
28 if (choice == "glupload") {
29 return {.mode = GpuBinMode::GlUpload, .explicitChoice = true};
30 }
31 if (!choice.isEmpty()) {
32 qCWarning(GstQgcGpuBinLog) << "Unknown QGC_GST_GPU_BIN value" << choice
33 << "(expected glupload or dmabuf); using the default glupload bin";
34 }
35 return {.mode = GpuBinMode::GlUpload};
36#else
37 Q_UNUSED(value);
38#if defined(QGC_GST_BIN_HAS_GLUPLOAD)
39 return {.mode = GpuBinMode::GlUpload};
40#elif defined(QGC_GST_BIN_HAS_DIRECT_DMABUF)
41 return {.mode = GpuBinMode::DirectDmaBuf};
42#else
43 return {};
44#endif
45#endif
46}
47
49{
50#ifdef QGC_UNITTEST_BUILD
51 if (const std::optional<SinkEnvironment> environment = sinkEnvironmentForTest()) {
52 return environment->gpuBin;
53 }
54#endif
55 static const GpuBinPreference preference = [] {
56 const GpuBinPreference parsed = parseGpuBinPreference(qgetenv("QGC_GST_GPU_BIN"));
57 qCDebug(GstQgcGpuBinLog).nospace() << "GPU bin preference: " << gpuBinName(parsed.mode) << " ("
58 << (parsed.explicitChoice ? "QGC_GST_GPU_BIN" : "default") << ")";
59 return parsed;
60 }();
61 return preference;
62}
63
64GpuBinMode selectGpuBin(GpuBinPreference preference, const RenderTarget& target) noexcept
65{
66#if defined(QGC_HAS_GST_D3D12_GPU_PATH)
67 if (target.backend == RenderBackend::Direct3D12) {
69 }
70#endif
71 bool suited = true;
72 switch (preference.mode) {
74 suited = target.sharesGlContext();
75 break;
77 suited = target.isOpenGlOnEgl();
78 break;
80 suited = (target.backend == RenderBackend::Direct3D12);
81 break;
83 break;
84 }
85 return (suited || preference.explicitChoice) ? preference.mode : GpuBinMode::Passthrough;
86}
87
88const char* gpuBinName(GpuBinMode mode) noexcept
89{
90 switch (mode) {
92 return "glupload";
94 return "direct DMABuf";
96 return "d3d12convert";
98 break;
99 }
100 return "passthrough";
101}
102
103bool converterSuitsRenderTarget(const char* pluginName, const char* factoryName, const RenderTarget& target) noexcept
104{
105 const auto is = [](const char* text, std::string_view expected) { return text && (expected == text); };
106 if ((target.backend != RenderBackend::Direct3D11) || !is(pluginName, "d3d11")) {
107 return true;
108 }
109 return is(factoryName, "d3d11upload") || is(factoryName, "d3d11download");
110}
111
112} // namespace GstQgc
#define QGC_LOGGING_CATEGORY(name, categoryStr)
GstVideoSink that pushes decoded frames into a Qt QVideoSink; sole sink in qgcvideosinkbin....
const char * gpuBinName(GpuBinMode mode) noexcept
GpuBinPreference parseGpuBinPreference(QByteArrayView value)
bool converterSuitsRenderTarget(const char *pluginName, const char *factoryName, const RenderTarget &target) noexcept
@ GlUpload
glupload → glcolorconvert → GLMemory 2D; gst-gl imports LINEAR and vendor-tiled DMABuf.
@ Passthrough
Every compiled native memory straight into qgcqvideosink (Windows, Apple, ...).
GpuBinPreference gpuBinPreference()
parseGpuBinPreference() of QGC_GST_GPU_BIN, read and logged on the first call.
GpuBinMode selectGpuBin(GpuBinPreference preference, const RenderTarget &target) noexcept
The GPU bin asked for, before the render target is known.
bool explicitChoice
Chosen through QGC_GST_GPU_BIN: used even under a render target it doesn't suit.