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