QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstHwPathRegistry.cc
Go to the documentation of this file.
1#include "GstHwPathRegistry.h"
2
3#include <algorithm>
4#include <atomic>
5
7namespace {
8
9// CUDA precedes DMABuf because it exports CUDA memory to the DMABuf importer.
10constexpr const HwPathDescriptor* kCompiledPaths[] = {
11#if defined(QGC_HAS_GST_CUDA_GPU_PATH)
12 &GstHwPaths::kCuda,
13#endif
14#if defined(QGC_HAS_GST_DMABUF_GPU_PATH)
15 &GstHwPaths::kDmaBuf,
16#endif
17#if defined(QGC_HAS_GST_GLMEMORY_GPU_PATH)
18 &GstHwPaths::kGlMemory,
19#endif
20#if defined(QGC_HAS_GST_D3D11_GPU_PATH)
21 &GstHwPaths::kD3D11,
22#endif
23#if defined(QGC_HAS_GST_D3D12_GPU_PATH)
24 &GstHwPaths::kD3D12,
25#endif
26#if defined(QGC_HAS_GST_VULKAN_GPU_PATH)
27 &GstHwPaths::kVulkan,
28#endif
29#if defined(QGC_HAS_GST_IOSURFACE_GPU_PATH)
30 &GstHwPaths::kIOSurface,
31#endif
32#if defined(QGC_HAS_GST_AHARDWAREBUFFER_GPU_PATH)
33 &GstHwPaths::kAHardwareBuffer,
34#endif
35};
36
37#ifdef QGC_UNITTEST_BUILD
38constinit std::atomic<const std::vector<const HwPathDescriptor*>*> s_testPaths{nullptr};
39#endif
40
41} // namespace
42
43std::span<const HwPathDescriptor* const> paths() noexcept
44{
45#ifdef QGC_UNITTEST_BUILD
46 if (const auto* testPaths = s_testPaths.load(std::memory_order_acquire)) {
47 return *testPaths;
48 }
49#endif
50 return kCompiledPaths;
51}
52
53bool has(HwVideoBufferPath path) noexcept
54{
55 const auto compiled = paths();
56 return std::any_of(compiled.begin(), compiled.end(),
57 [path](const HwPathDescriptor* descriptor) { return descriptor->path == path; });
58}
59
60#ifdef QGC_UNITTEST_BUILD
61ScopedPathsForTest::ScopedPathsForTest(std::initializer_list<const HwPathDescriptor*> paths)
62 : _paths(paths)
63 , _previous(s_testPaths.exchange(&_paths, std::memory_order_acq_rel))
64{}
65
66ScopedPathsForTest::~ScopedPathsForTest()
67{
68 s_testPaths.store(_previous, std::memory_order_release);
69}
70#endif
71
72} // namespace GstHwPathRegistry
HwVideoBufferPath
GPU zero-copy path a frame is imported through; None means the frame takes the CPU path.
Definition GstHwTypes.h:7
bool has(HwVideoBufferPath path) noexcept
std::span< const HwPathDescriptor *const > paths() noexcept