4#if defined(QGC_HAS_GST_GLMEMORY_GPU_PATH) || defined(QGC_HAS_GST_D3D11_GPU_PATH) || defined(QGC_HAS_GST_D3D12_GPU_PATH)
10QGC_LOGGING_CATEGORY(GstContextBridgeRegistryLog,
"Video.GStreamer.HwBuffers.GstContextBridgeRegistry")
12namespace GstContextBridgeRegistry {
16constexpr int kMaxHandlers = 8;
19std::array<std::atomic<BridgeHandler>, kMaxHandlers> s_handlers{};
20std::atomic<int> s_count{0};
21std::array<std::atomic<ResetCallback>, kMaxHandlers> s_resets{};
22std::atomic<int> s_resetCount{0};
23std::mutex s_registerMutex;
27void registerBridgeHandler(BridgeHandler handler)
30 std::lock_guard<std::mutex> lock(s_registerMutex);
31 const int slot = s_count.load(std::memory_order_relaxed);
32 if (slot >= kMaxHandlers) {
33 qCWarning(GstContextBridgeRegistryLog)
34 <<
"Bridge handler limit (" << kMaxHandlers <<
") exceeded — dropping registration";
39 s_handlers[slot].store(handler, std::memory_order_release);
40 s_count.store(slot + 1, std::memory_order_release);
45GstBusSyncReply dispatchBridges(GstMessage *message)
47 const int count = s_count.load(std::memory_order_acquire);
48 for (
int i = 0; i < count && i < kMaxHandlers; ++i) {
49 BridgeHandler h = s_handlers[i].load(std::memory_order_acquire);
50 if (h && h(message) == GST_BUS_DROP) {
57void registerResetCallback(ResetCallback callback)
59 if (!callback)
return;
60 std::lock_guard<std::mutex> lock(s_registerMutex);
61 const int slot = s_resetCount.load(std::memory_order_relaxed);
62 if (slot >= kMaxHandlers) {
63 qCWarning(GstContextBridgeRegistryLog)
64 <<
"Reset callback limit (" << kMaxHandlers <<
") exceeded — dropping registration";
67 s_resets[slot].store(callback, std::memory_order_release);
68 s_resetCount.store(slot + 1, std::memory_order_release);
73 const int count = s_resetCount.load(std::memory_order_acquire);
74 for (
int i = 0; i < count && i < kMaxHandlers; ++i) {
75 ResetCallback cb = s_resets[i].load(std::memory_order_acquire);
87 std::lock_guard<std::mutex> lock(s_registerMutex);
91 s_count.store(0, std::memory_order_release);
92 s_resetCount.store(0, std::memory_order_release);
93 for (
auto &slot : s_handlers) slot.store(nullptr, std::memory_order_release);
94 for (
auto &slot : s_resets) slot.store(nullptr, std::memory_order_release);
#define QGC_LOGGING_CATEGORY(name, categoryStr)