Skip to content

Commit 0b4696a

Browse files
committed
NVIDIA CUDA Linux pipeline
1 parent 9604170 commit 0b4696a

File tree

7 files changed

+78
-23
lines changed

7 files changed

+78
-23
lines changed

src/main/java/org/dpsoftware/FireflyLuciferin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ private void launchGrabberAndConsumers() throws AWTException {
284284
// Desktop Duplication API producers
285285
if ((MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.DDUPL.name()))
286286
|| (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.XIMAGESRC.name()))
287+
|| (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.XIMAGESRC_NVIDIA.name()))
287288
|| (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name()))
289+
|| (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA.name()))
288290
|| (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.AVFVIDEOSRC.name()))) {
289291
grabberManager.launchAdvancedGrabber(imageProcessor);
290292
} else { // Standard Producers

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,26 @@ public LinkedHashMap<Integer, LEDCoordinate> getLedMatrixInUse(String ledMatrixI
182182
return ledMatrix.get(ledMatrixInUse);
183183
}
184184

185-
// WinAPI and DDUPL enables GPU Hardware Acceleration, CPU uses CPU brute force only,
186-
// DDUPL (Desktop Duplication API) is recommended in Win8/Win10/Win11
185+
/**
186+
* WinAPI and DDUPL enables GPU Hardware Acceleration on Windows, CPU uses CPU brute force only.
187+
* DDUPL (Desktop Duplication API) is recommended in Win8/Win10/Win11 and it uses DX11
188+
* CUDA is used in Linux only, it needs additional libs and it works on Nvidia GPUs only.
189+
*/
190+
@Getter
187191
public enum CaptureMethod {
188-
CPU,
189-
WinAPI,
190-
DDUPL,
191-
XIMAGESRC,
192-
PIPEWIREXDG,
193-
AVFVIDEOSRC
192+
CPU("CPU"),
193+
WinAPI("WinAPI"),
194+
DDUPL("DDUPL"),
195+
XIMAGESRC("XIMAGESRC"),
196+
XIMAGESRC_NVIDIA("XIMAGESRC (NVIDIA)"),
197+
PIPEWIREXDG("PIPEWIREXDG"),
198+
PIPEWIREXDG_NVIDIA("PIPEWIREXDG (NVIDIA)"),
199+
AVFVIDEOSRC("AVFVIDEOSRC");
200+
private final String captureMethod;
201+
202+
CaptureMethod(String captureMethod) {
203+
this.captureMethod = captureMethod;
204+
}
194205
}
195206

196207
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,10 @@ public class Constants {
492492
// ./gst-launch-1.0 ximagesrc startx=0 endx=3839 starty=0 endy=2159 use-damage=0 ! videoscale ! videoconvert ! autovideosink
493493
public static final String GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE_SM = "d3d11screencapturesrc monitor-handle={0} ! d3d11convert ! d3d11download";
494494
public static final String GSTREAMER_PIPELINE_WINDOWS_HARDWARE_HANDLE = "d3d11screencapturesrc monitor-handle={0} ! d3d11convert";
495-
public static final String GSTREAMER_PIPELINE_LINUX = "ximagesrc startx={0} endx={1} starty={2} endy={3} use-damage=0 ! videoscale ! videoconvert";
495+
public static final String GSTREAMER_PIPELINE_XIMAGESRC = "ximagesrc startx={0} endx={1} starty={2} endy={3} use-damage=0 ! videoscale ! videoconvert";
496+
public static final String GSTREAMER_PIPELINE_XIMAGESRC_CUDA = "ximagesrc startx={0} endx={1} starty={2} endy={3} use-damage=0 ! cudaupload ! cudascale ! cudaconvert ! cudadownload";
496497
public static final String GSTREAMER_PIPELINE_PIPEWIREXDG = "pipewiresrc fd={1} path={2} ! videorate ! videoscale ! videoconvert";
498+
public static final String GSTREAMER_PIPELINE_PIPEWIREXDG_CUDA = "pipewiresrc fd={1} path={2} ! videorate ! cudaupload ! cudascale ! cudaconvert ! cudadownload";
497499
public static final String GSTREAMER_PIPELINE_MAC = "avfvideosrc capture-screen=true ! videoscale ! videoconvert";
498500
public static final String FRAMERATE_PLACEHOLDER = "framerate=FRAMERATE_PLACEHOLDER/1,";
499501
public static final String FPS_PLACEHOLDER = "FRAMERATE_PLACEHOLDER";

src/main/java/org/dpsoftware/gui/controllers/MiscTabController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,10 @@ public void initValuesFromSettingsFile(Configuration currentConfig, boolean upda
301301
}
302302
frameInsertion.setDisable((!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.DDUPL.name()))
303303
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.XIMAGESRC.name()))
304-
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name())
305-
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.AVFVIDEOSRC.name()))));
304+
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.XIMAGESRC_NVIDIA.name()))
305+
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name()))
306+
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA.name()))
307+
&& (!currentConfig.getCaptureMethod().equals(Configuration.CaptureMethod.AVFVIDEOSRC.name())));
306308
gamma.setValue(String.valueOf(MainSingleton.getInstance().config.getGamma()));
307309
colorMode.setValue(Enums.ColorMode.values()[MainSingleton.getInstance().config.getColorMode() - 1].getI18n());
308310
if (!MainSingleton.getInstance().config.getDesiredFramerate().equals(Enums.Framerate.UNLOCKED.getBaseI18n())) {

src/main/java/org/dpsoftware/gui/controllers/ModeTabController.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javafx.scene.control.Label;
2828
import javafx.scene.control.TextField;
2929
import javafx.scene.input.InputEvent;
30+
import javafx.util.StringConverter;
3031
import org.dpsoftware.MainSingleton;
3132
import org.dpsoftware.NativeExecutor;
3233
import org.dpsoftware.config.Configuration;
@@ -93,9 +94,6 @@ public void injectSettingsController(SettingsController settingsController) {
9394
*/
9495
@FXML
9596
protected void initialize() {
96-
if (NativeExecutor.isLinux()) {
97-
captureMethod.getItems().addAll(Configuration.CaptureMethod.XIMAGESRC, Configuration.CaptureMethod.PIPEWIREXDG);
98-
}
9997
for (Enums.Algo al : Enums.Algo.values()) {
10098
algo.getItems().add(al.getI18n());
10199
}
@@ -111,6 +109,31 @@ protected void initialize() {
111109
}
112110
}
113111

112+
/**
113+
* Handle key valye combo box
114+
*/
115+
public void setCaptureMethodConverter() {
116+
captureMethod.setConverter(new StringConverter<>() {
117+
@Override
118+
public String toString(Configuration.CaptureMethod object) {
119+
return switch (object) {
120+
case CPU -> Configuration.CaptureMethod.CPU.name();
121+
case WinAPI -> Configuration.CaptureMethod.WinAPI.name();
122+
case DDUPL -> Configuration.CaptureMethod.DDUPL.name();
123+
case XIMAGESRC -> Configuration.CaptureMethod.XIMAGESRC.name();
124+
case XIMAGESRC_NVIDIA -> Configuration.CaptureMethod.XIMAGESRC_NVIDIA.getCaptureMethod();
125+
case PIPEWIREXDG -> Configuration.CaptureMethod.PIPEWIREXDG.name();
126+
case PIPEWIREXDG_NVIDIA -> Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA.getCaptureMethod();
127+
default -> null;
128+
};
129+
}
130+
@Override
131+
public Configuration.CaptureMethod fromString(String string) {
132+
return null;
133+
}
134+
});
135+
}
136+
114137
/**
115138
* Init combo boxes
116139
*/
@@ -156,7 +179,7 @@ void initDefaultValues() {
156179
if (NativeExecutor.isWindows()) {
157180
captureMethod.setValue(Configuration.CaptureMethod.DDUPL);
158181
} else if (NativeExecutor.isMac()) {
159-
captureMethod.setValue(Configuration.CaptureMethod.DDUPL);
182+
captureMethod.setValue(Configuration.CaptureMethod.AVFVIDEOSRC);
160183
} else {
161184
if (System.getenv(Constants.DISPLAY_MANAGER_CHK).equalsIgnoreCase(Constants.WAYLAND)) {
162185
captureMethod.setValue(Configuration.CaptureMethod.PIPEWIREXDG);

src/main/java/org/dpsoftware/gui/controllers/SettingsController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,12 @@ void setCaptureMethod(Configuration config) {
526526
} else {
527527
if (modeTabController.captureMethod.getValue() == Configuration.CaptureMethod.XIMAGESRC) {
528528
config.setCaptureMethod(Configuration.CaptureMethod.XIMAGESRC.name());
529+
} else if (modeTabController.captureMethod.getValue() == Configuration.CaptureMethod.XIMAGESRC_NVIDIA) {
530+
config.setCaptureMethod(Configuration.CaptureMethod.XIMAGESRC_NVIDIA.name());
529531
} else if (modeTabController.captureMethod.getValue() == Configuration.CaptureMethod.PIPEWIREXDG) {
530532
config.setCaptureMethod(Configuration.CaptureMethod.PIPEWIREXDG.name());
533+
} else if (modeTabController.captureMethod.getValue() == Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA) {
534+
config.setCaptureMethod(Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA.name());
531535
}
532536
}
533537
}
@@ -756,9 +760,11 @@ public void initOutputDeviceChooser(boolean initCaptureMethod) {
756760
} else if (NativeExecutor.isMac()) {
757761
modeTabController.captureMethod.getItems().addAll(Configuration.CaptureMethod.AVFVIDEOSRC);
758762
} else {
759-
modeTabController.captureMethod.getItems().addAll(Configuration.CaptureMethod.XIMAGESRC, Configuration.CaptureMethod.PIPEWIREXDG);
763+
modeTabController.captureMethod.getItems().addAll(Configuration.CaptureMethod.XIMAGESRC, Configuration.CaptureMethod.XIMAGESRC_NVIDIA,
764+
Configuration.CaptureMethod.PIPEWIREXDG, Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA);
760765
}
761766
}
767+
modeTabController.setCaptureMethodConverter();
762768
if (NativeExecutor.isWindows()) {
763769
SerialManager serialManager = new SerialManager();
764770
Map<String, Boolean> availableDevices = serialManager.getAvailableDevices();

src/main/java/org/dpsoftware/managers/PipelineManager.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ record XdgStreamDetails(Integer streamId, FileDescriptor fileDescriptor) {}
8282
* FileDescriptor from org.freedesktop.portal.ScreenCast:OpenPipeWireRemote
8383
*/
8484
@SneakyThrows
85+
@SuppressWarnings("all")
8586
public static XdgStreamDetails getXdgStreamDetails() {
8687
CompletableFuture<String> sessionHandleMaybe = new CompletableFuture<>();
8788
CompletableFuture<Integer> streamIdMaybe = new CompletableFuture<>();
@@ -136,26 +137,34 @@ public static XdgStreamDetails getXdgStreamDetails() {
136137
*/
137138
public static String getLinuxPipelineParams() {
138139
String gstreamerPipeline;
139-
140-
if (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name())) {
140+
String pipeline;
141+
if (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name())
142+
|| MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG_NVIDIA.name())) {
143+
if (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.PIPEWIREXDG.name())) {
144+
pipeline = Constants.GSTREAMER_PIPELINE_PIPEWIREXDG;
145+
} else {
146+
pipeline = Constants.GSTREAMER_PIPELINE_PIPEWIREXDG_CUDA;
147+
}
141148
XdgStreamDetails xdgStreamDetails = getXdgStreamDetails();
142-
143-
gstreamerPipeline = Constants.GSTREAMER_PIPELINE_PIPEWIREXDG
149+
gstreamerPipeline = pipeline
144150
.replace("{1}", String.valueOf(xdgStreamDetails.fileDescriptor.getIntFileDescriptor()))
145151
.replace("{2}", xdgStreamDetails.streamId.toString());
146152
} else {
147153
// startx{0}, endx{1}, starty{2}, endy{3}
154+
if (MainSingleton.getInstance().config.getCaptureMethod().equals(Configuration.CaptureMethod.XIMAGESRC.name())) {
155+
pipeline = Constants.GSTREAMER_PIPELINE_XIMAGESRC;
156+
} else {
157+
pipeline = Constants.GSTREAMER_PIPELINE_XIMAGESRC_CUDA;
158+
}
148159
DisplayManager displayManager = new DisplayManager();
149160
List<DisplayInfo> displayList = displayManager.getDisplayList();
150161
DisplayInfo monitorInfo = displayList.get(MainSingleton.getInstance().config.getMonitorNumber());
151-
152-
gstreamerPipeline = Constants.GSTREAMER_PIPELINE_LINUX
162+
gstreamerPipeline = pipeline
153163
.replace("{0}", String.valueOf((int) (monitorInfo.getMinX() + 1)))
154164
.replace("{1}", String.valueOf((int) (monitorInfo.getMinX() + monitorInfo.getWidth() - 1)))
155165
.replace("{2}", String.valueOf((int) (monitorInfo.getMinY())))
156166
.replace("{3}", String.valueOf((int) (monitorInfo.getMinY() + monitorInfo.getHeight() - 1)));
157167
}
158-
159168
log.info(gstreamerPipeline);
160169
return gstreamerPipeline;
161170
}

0 commit comments

Comments
 (0)