Skip to content

Commit 9dd7db7

Browse files
committed
d3d11 3440 fix
1 parent fd3f9b4 commit 9dd7db7

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/main/java/org/dpsoftware/config/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ public class Constants {
448448
public static final String INTERNAL_SCALING_Y = "INTERNAL_SCALING_Y";
449449
public static final int RESAMPLING_FACTOR = 4;
450450
public static final String EMIT_SIGNALS = "emit-signals";
451+
public static final int GSTREAMER_MEMORY_DIVIDER = 32;
452+
public static final String GSTREAMER_PIPELINE_DDUPL_SM ="video/x-raw(memory:SystemMemory),width=INTERNAL_SCALING_X,height=INTERNAL_SCALING_Y,sync=false,";
451453
public static final String GSTREAMER_PIPELINE_DDUPL = "video/x-raw(memory:D3D11Memory),width=INTERNAL_SCALING_X,height=INTERNAL_SCALING_Y,sync=false,";
452454
public static final String GSTREAMER_PIPELINE = "video/x-raw,width=INTERNAL_SCALING_X,height=INTERNAL_SCALING_Y,sync=false,";
453455
public static final String BYTE_ORDER_BGR = "format=BGRx";
@@ -463,6 +465,7 @@ public class Constants {
463465
// ./gst-device-monitor-1.0.exe "Source/Monitor"
464466
// ./gst-launch-1.0 d3d11screencapturesrc monitor-handle=221948 ! d3d11convert ! d3d11download ! autovideosink
465467
// ./gst-launch-1.0 ximagesrc startx=0 endx=3839 starty=0 endy=2159 ! videoscale ! videoconvert ! autovideosink
468+
public static final String GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE_SM = "d3d11screencapturesrc monitor-handle={0} ! d3d11convert ! d3d11download";
466469
public static final String GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE = "d3d11screencapturesrc monitor-handle={0} ! d3d11convert";
467470
public static final String GSTREAMER_PIPELINE_LINUX = "ximagesrc startx={0} endx={1} starty={2} endy={3} ! videoscale ! videoconvert";
468471
public static final String GSTREAMER_PIPELINE_MAC = "avfvideosrc capture-screen=true ! videoscale ! videoconvert";

src/main/java/org/dpsoftware/grabber/GStreamerGrabber.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ public GStreamerGrabber(AppSink appsink) {
7070
videosink.connect(listener);
7171
String gstreamerPipeline;
7272
if (FireflyLuciferin.config.getCaptureMethod().equals(Configuration.CaptureMethod.DDUPL.name())) {
73-
// Scale image inside the GPU by RESAMPLING_FACTOR
74-
gstreamerPipeline = Constants.GSTREAMER_PIPELINE_DDUPL
75-
.replace(Constants.INTERNAL_SCALING_X, String.valueOf(FireflyLuciferin.config.getScreenResX() / Constants.RESAMPLING_FACTOR))
76-
.replace(Constants.INTERNAL_SCALING_Y, String.valueOf(FireflyLuciferin.config.getScreenResY() / Constants.RESAMPLING_FACTOR));
73+
// Scale image inside the GPU by RESAMPLING_FACTOR, Constants.GSTREAMER_MEMORY_DIVIDER tells if resolution is compatible with D3D11Memory with no padding.
74+
if ((FireflyLuciferin.config.getScreenResX() / Constants.GSTREAMER_MEMORY_DIVIDER) % 2 == 0) {
75+
gstreamerPipeline = Constants.GSTREAMER_PIPELINE_DDUPL
76+
.replace(Constants.INTERNAL_SCALING_X, String.valueOf(FireflyLuciferin.config.getScreenResX() / Constants.RESAMPLING_FACTOR))
77+
.replace(Constants.INTERNAL_SCALING_Y, String.valueOf(FireflyLuciferin.config.getScreenResY() / Constants.RESAMPLING_FACTOR));
78+
} else {
79+
gstreamerPipeline = Constants.GSTREAMER_PIPELINE_DDUPL_SM
80+
.replace(Constants.INTERNAL_SCALING_X, String.valueOf(FireflyLuciferin.config.getScreenResX() / Constants.RESAMPLING_FACTOR))
81+
.replace(Constants.INTERNAL_SCALING_Y, String.valueOf(FireflyLuciferin.config.getScreenResY() / Constants.RESAMPLING_FACTOR));
82+
}
7783
} else {
7884
gstreamerPipeline = Constants.GSTREAMER_PIPELINE
7985
.replace(Constants.INTERNAL_SCALING_X, String.valueOf(FireflyLuciferin.config.getScreenResX() / Constants.RESAMPLING_FACTOR))

src/main/java/org/dpsoftware/grabber/GrabberManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ public void launchAdvancedGrabber(ImageProcessor imageProcessor) {
9292
if (NativeExecutor.isWindows()) {
9393
DisplayManager displayManager = new DisplayManager();
9494
String monitorNativePeer = String.valueOf(displayManager.getDisplayInfo(FireflyLuciferin.config.getMonitorNumber()).getNativePeer());
95-
bin = Gst.parseBinFromDescription(Constants.GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE.replace("{0}", monitorNativePeer), true);
95+
// Constants.GSTREAMER_MEMORY_DIVIDER tells if resolution is compatible with D3D11Memory with no padding.
96+
if ((FireflyLuciferin.config.getScreenResX() / Constants.GSTREAMER_MEMORY_DIVIDER) % 2 == 0) {
97+
bin = Gst.parseBinFromDescription(Constants.GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE.replace("{0}", monitorNativePeer), true);
98+
} else {
99+
bin = Gst.parseBinFromDescription(Constants.GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE_SM.replace("{0}", monitorNativePeer), true);
100+
}
96101
} else if (NativeExecutor.isLinux()) {
97102
bin = Gst.parseBinFromDescription(finalLinuxParams, true);
98103
} else {

0 commit comments

Comments
 (0)