3#if defined(QGC_HAS_GST_D3D11_GPU_PATH) || defined(QGC_HAS_GST_D3D12_GPU_PATH)
5#include <glib-object.h>
7#include <QtCore/QLoggingCategory>
8#include <QtCore/QMutexLocker>
9#include <QtCore/QString>
16void GstD3DContextBridge::onDeviceRemoved(GObject* , GParamSpec* , gpointer bridge)
18 static_cast<GstD3DContextBridge*
>(bridge)->noteDeviceRemoved();
21gint64 GstD3DContextBridge::readAdapterLuid(gpointer device)
23 if (!device || !G_IS_OBJECT(device)) {
27 g_object_get(G_OBJECT(device),
"adapter-luid", &luid,
nullptr);
33bool GstD3DContextBridge::snapshotBackendMatches()
37 qCDebug(category()) <<
"QRhi snapshot not yet populated; will retry on next NEED_CONTEXT";
40 if ((backend != _qrhiBackend) && (backend != _secondQrhiBackend)) {
41 if (!_warnedWrongBackend) {
42 qCInfo(category()) <<
"QRhi backend tag is" << backend <<
"(not" << apiName() <<
"); bridge inactive";
43 _warnedWrongBackend =
true;
50bool GstD3DContextBridge::primeLocked()
52 if (!snapshotBackendMatches()) {
55 GstObject*
device = createDevice();
61 if (g_object_class_find_property(G_OBJECT_GET_CLASS(device),
"device-removed-reason")) {
62 _removalHandler = g_signal_connect(device,
"notify::device-removed-reason", G_CALLBACK(&onDeviceRemoved),
this);
64 qCInfo(category()) << apiName() <<
"bridge primed: shared device =" <<
device;
68GstObject* GstD3DContextBridge::refObject(
const char* )
70 return _device ? GST_OBJECT(gst_object_ref(_device)) : nullptr;
73GstContext* GstD3DContextBridge::buildContext(
const char* , GstObject*
object)
75 GstContext* ctx = makeDeviceContext(
object);
77 qCWarning(category()) << apiName() <<
"context_new failed";
82void GstD3DContextBridge::clearLocked()
84 if (_removalHandler != 0) {
85 g_signal_handler_disconnect(_device, _removalHandler);
88 gst_clear_object(&_device);
89 _warnedWrongBackend =
false;
92GstObject* GstD3DContextBridge::refDevice()
94 QMutexLocker lock(&_mutex);
95 return _device ? GST_OBJECT(gst_object_ref(_device)) : nullptr;
98void GstD3DContextBridge::logAdapterMatch(gint64 expectedLuid, gpointer gstDevice)
const
100 const gint64 actualLuid = readAdapterLuid(gstDevice);
101 if (actualLuid != expectedLuid) {
102 qCWarning(category()).noquote() << apiName() <<
"bridge: gst device LUID mismatch — QRhi LUID=" << expectedLuid
103 <<
"but wrapped device LUID=" << actualLuid
104 <<
"(zero-copy will appear corrupt; check NEED_CONTEXT race)";
107 qCInfo(category()).noquote() << apiName() <<
"bridge adapter LUID="
108 << QString::asprintf(
"0x%llx",
static_cast<long long>(expectedLuid));
DeviceSnapshot & deviceSnapshot() noexcept
Returns the global snapshot. Atomic fields make individual reads thread-safe.
QCameraDevice device(const QString &description)
The attached camera of description description; a null device when none is.
std::atomic< int > backend
QRhi::Implementation cast to int (-1 = unset).