d3d11desktopdup: Support desktop switches
authorJakub Adam <jakub.adam@collabora.com>
Thu, 29 Apr 2021 20:10:15 +0000 (22:10 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 30 Apr 2021 04:47:36 +0000 (04:47 +0000)
Before creating output duplication interface, call SetThreadDesktop()
with HDESK of the current input desktop in case a desktop switch has
occurred.

This allows d3d11desktopdupsrc to capture Windows User Account Control
(UAC) prompts, which appear on a separate secure desktop. Otherwise
IDXGIOutput1::DuplicateOutput() will return E_ACCESSDENIED and the
element won't produce any frames as long as the UAC screen is active.

Note that in order to access secure desktop the application still has to
run at LOCAL_SYSTEM privileges. For GStreamer applications running with
regular user privileges this change has no effect.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2209>

sys/d3d11/gstd3d11desktopdup.cpp

index 065378d..43bcb08 100644 (file)
@@ -661,6 +661,17 @@ private:
       return GST_FLOW_ERROR;
     }
 
+    HDESK hdesk = OpenInputDesktop (0, FALSE, GENERIC_ALL);
+    if (hdesk) {
+      if (!SetThreadDesktop (hdesk)) {
+        GST_WARNING ("SetThreadDesktop() failed, error %lu", GetLastError());
+      }
+
+      CloseDesktop (hdesk);
+    } else {
+      GST_WARNING ("OpenInputDesktop() failed, error %lu", GetLastError());
+    }
+
     /* FIXME: Use DuplicateOutput1 to avoid potentail color conversion */
     hr = output1->DuplicateOutput(d3d11_device.Get(), &dupl_);
     if (!gst_d3d11_result (hr, device)) {