mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-03 22:46:14 +00:00
now use preferences to select resolution and fullscreen option
This commit is contained in:
@@ -17,6 +17,9 @@ import com.limelight.nvstream.NvConnection;
|
||||
import com.limelight.nvstream.NvConnectionListener;
|
||||
import com.limelight.nvstream.StreamConfiguration;
|
||||
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||
import com.limelight.settings.PreferencesManager;
|
||||
import com.limelight.settings.PreferencesManager.Preferences;
|
||||
import com.limelight.settings.PreferencesManager.Preferences.Resolution;
|
||||
|
||||
public class Limelight implements NvConnectionListener {
|
||||
public static final double VERSION = 1.0;
|
||||
@@ -26,7 +29,6 @@ public class Limelight implements NvConnectionListener {
|
||||
private NvConnection conn;
|
||||
private boolean connectionFailed;
|
||||
private static JFrame limeFrame;
|
||||
private StreamConfiguration streamConfig = new StreamConfiguration(1280, 720, 30);
|
||||
|
||||
public Limelight(String host) {
|
||||
this.host = host;
|
||||
@@ -79,10 +81,14 @@ public class Limelight implements NvConnectionListener {
|
||||
extractNativeLibrary("avcodec-55.dll", nativeLibDir);
|
||||
}
|
||||
|
||||
private void startUp(boolean fullscreen) {
|
||||
private void startUp() {
|
||||
streamFrame = new StreamFrame();
|
||||
|
||||
Preferences prefs = PreferencesManager.getPreferences();
|
||||
StreamConfiguration streamConfig = createConfiguration(prefs.getResolution());
|
||||
|
||||
conn = new NvConnection(host, this, streamConfig);
|
||||
streamFrame.build(conn, streamConfig, fullscreen);
|
||||
streamFrame.build(conn, streamConfig, prefs.getFullscreen());
|
||||
conn.start(PlatformBinding.getDeviceName(), streamFrame,
|
||||
VideoDecoderRenderer.FLAG_PREFER_QUALITY,
|
||||
PlatformBinding.getAudioRenderer(),
|
||||
@@ -92,6 +98,18 @@ public class Limelight implements NvConnectionListener {
|
||||
|
||||
}
|
||||
|
||||
private StreamConfiguration createConfiguration(Resolution res) {
|
||||
switch(res) {
|
||||
case RES_720:
|
||||
return new StreamConfiguration(1280, 720, 30);
|
||||
case RES_1080:
|
||||
return new StreamConfiguration(1920, 1080, 60);
|
||||
default:
|
||||
// this should never happen, if it does we want the NPE to occur so we know something is wrong
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void startControllerListener() {
|
||||
ControllerListener.startUp();
|
||||
}
|
||||
@@ -103,9 +121,9 @@ public class Limelight implements NvConnectionListener {
|
||||
startControllerListener();
|
||||
}
|
||||
|
||||
public static void createInstance(String host, boolean fullscreen) {
|
||||
public static void createInstance(String host) {
|
||||
Limelight limelight = new Limelight(host);
|
||||
limelight.startUp(fullscreen);
|
||||
limelight.startUp();
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.net.UnknownHostException;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
@@ -37,7 +36,6 @@ public class MainFrame {
|
||||
private JTextField hostField;
|
||||
private JButton pair;
|
||||
private JButton stream;
|
||||
private JCheckBox fullscreen;
|
||||
private JFrame limeFrame;
|
||||
|
||||
public JFrame getLimeFrame() {
|
||||
@@ -76,8 +74,6 @@ public class MainFrame {
|
||||
pair.addActionListener(createPairButtonListener());
|
||||
pair.setToolTipText("Send pair request to GeForce PC");
|
||||
|
||||
fullscreen = new JCheckBox("Fullscreen", true);
|
||||
|
||||
Box streamBox = Box.createHorizontalBox();
|
||||
streamBox.add(Box.createHorizontalGlue());
|
||||
streamBox.add(stream);
|
||||
@@ -98,8 +94,6 @@ public class MainFrame {
|
||||
contentBox.add(Box.createVerticalStrut(20));
|
||||
contentBox.add(hostBox);
|
||||
contentBox.add(Box.createVerticalStrut(5));
|
||||
contentBox.add(fullscreen);
|
||||
contentBox.add(Box.createVerticalStrut(5));
|
||||
contentBox.add(streamBox);
|
||||
contentBox.add(Box.createVerticalStrut(10));
|
||||
contentBox.add(pairBox);
|
||||
@@ -150,7 +144,7 @@ public class MainFrame {
|
||||
return new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Limelight.createInstance(hostField.getText(), fullscreen.isSelected());
|
||||
Limelight.createInstance(hostField.getText());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,19 +14,20 @@ import javax.swing.JPanel;
|
||||
|
||||
import com.limelight.settings.PreferencesManager;
|
||||
import com.limelight.settings.PreferencesManager.Preferences;
|
||||
import com.limelight.settings.PreferencesManager.Preferences.Resolution;
|
||||
|
||||
public class PreferencesFrame extends JFrame {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private JComboBox resolution;
|
||||
private JCheckBox fullscreen;
|
||||
private Preferences prefs;
|
||||
private boolean prefsChanged = false;
|
||||
|
||||
public PreferencesFrame() {
|
||||
super("Preferences");
|
||||
this.setSize(200, 100);
|
||||
this.setResizable(false);
|
||||
this.setAlwaysOnTop(true);
|
||||
prefs = PreferencesManager.getPreferences();
|
||||
}
|
||||
|
||||
public void build() {
|
||||
@@ -35,12 +36,15 @@ public class PreferencesFrame extends JFrame {
|
||||
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
resolution = new JComboBox();
|
||||
resolution.addItem("1080p");
|
||||
resolution.addItem("720p");
|
||||
for (Resolution res : Resolution.values()) {
|
||||
resolution.addItem(res);
|
||||
}
|
||||
|
||||
resolution.setSelectedItem(prefs.getResolution());
|
||||
|
||||
fullscreen = new JCheckBox("Fullscreen");
|
||||
|
||||
|
||||
fullscreen.setSelected(prefs.getFullscreen());
|
||||
|
||||
Box resolutionBox = Box.createHorizontalBox();
|
||||
resolutionBox.add(Box.createHorizontalGlue());
|
||||
resolutionBox.add(resolution);
|
||||
@@ -61,7 +65,7 @@ public class PreferencesFrame extends JFrame {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
super.windowClosing(e);
|
||||
if (prefsChanged) {
|
||||
if (prefsChanged()) {
|
||||
writePreferences();
|
||||
}
|
||||
}
|
||||
@@ -76,7 +80,14 @@ public class PreferencesFrame extends JFrame {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
private boolean prefsChanged() {
|
||||
return (prefs.getResolution() != resolution.getSelectedItem()) ||
|
||||
(prefs.getFullscreen() != fullscreen.isSelected());
|
||||
}
|
||||
|
||||
private void writePreferences() {
|
||||
prefs.setFullscreen(fullscreen.isSelected());
|
||||
prefs.setResolution((Resolution)resolution.getSelectedItem());
|
||||
PreferencesManager.writePreferences(prefs);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,16 @@ public abstract class PreferencesManager {
|
||||
private static Preferences cachedPreferences = null;
|
||||
|
||||
public static void writePreferences(Preferences prefs) {
|
||||
System.out.println("Writing Preferences");
|
||||
File prefFile = SettingsManager.getInstance().getSettingsFile();
|
||||
|
||||
SettingsManager.writeSettings(prefFile, prefs);
|
||||
cachedPreferences = prefs;
|
||||
}
|
||||
|
||||
public static Preferences getPreferences() {
|
||||
if (cachedPreferences == null) {
|
||||
System.out.println("Reading Preferences");
|
||||
File prefFile = SettingsManager.getInstance().getSettingsFile();
|
||||
Preferences savedPref = (Preferences)SettingsManager.readSettings(prefFile);
|
||||
cachedPreferences = savedPref;
|
||||
@@ -29,7 +32,18 @@ public abstract class PreferencesManager {
|
||||
public static class Preferences implements Serializable {
|
||||
private static final long serialVersionUID = -5575445156215348048L;
|
||||
|
||||
public enum Resolution { RES_720, RES_1080 };
|
||||
public enum Resolution { RES_720("1280x720 (720p)"), RES_1080("1920x1080 (1080p)");
|
||||
public String name;
|
||||
|
||||
private Resolution(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
};
|
||||
|
||||
private Resolution res;
|
||||
private boolean fullscreen;
|
||||
|
||||
Reference in New Issue
Block a user