From b0169b0edfbacc5235bbc3782e36fc90397c3d8c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 2 Nov 2014 20:52:09 -0800 Subject: [PATCH] Use a builder for StreamConfiguration to avoid further breaking changes to the constructor. Add support for local audio playback mode. --- .../com/limelight/nvstream/NvConnection.java | 4 +- .../nvstream/StreamConfiguration.java | 72 ++++++++++++++----- .../com/limelight/nvstream/http/NvHTTP.java | 10 +-- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index eacb52af..8885be67 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -170,9 +170,7 @@ public class NvConnection { private boolean launchNotRunningApp(NvHTTP h, NvApp app) throws IOException, XmlPullParserException { // Launch the app since it's not running - int gameSessionId = h.launchApp(app.getAppId(), config.getWidth(), - config.getHeight(), config.getRefreshRate(), riKey, config.getSops(), - riKeyId); + int gameSessionId = h.launchApp(app.getAppId(), riKey, riKeyId, config); if (gameSessionId == 0) { listener.displayMessage("Failed to launch application"); return false; diff --git a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java index 51c75416..ab5e7d00 100644 --- a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java +++ b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java @@ -7,25 +7,61 @@ public class StreamConfiguration { private int bitrate; private boolean sops; private boolean enableAdaptiveResolution; + private boolean playLocalAudio; - public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate) { - this.app = app; - this.width = width; - this.height = height; - this.refreshRate = refreshRate; - this.bitrate = bitrate; - this.sops = true; + public static class Builder { + private StreamConfiguration config = new StreamConfiguration(); + + public StreamConfiguration.Builder setApp(String app) { + config.app = app; + return this; + } + + public StreamConfiguration.Builder setResolution(int width, int height) { + config.width = width; + config.height = height; + return this; + } + + public StreamConfiguration.Builder setRefreshRate(int refreshRate) { + config.refreshRate = refreshRate; + return this; + } + + public StreamConfiguration.Builder setBitrate(int bitrate) { + config.bitrate = bitrate; + return this; + } + + public StreamConfiguration.Builder setEnableSops(boolean enable) { + config.sops = enable; + return this; + } + + public StreamConfiguration.Builder enableAdaptiveResolution(boolean enable) { + config.enableAdaptiveResolution = enable; + return this; + } + + public StreamConfiguration.Builder enableLocalAudioPlayback(boolean enable) { + config.playLocalAudio = enable; + return this; + } + + public StreamConfiguration build() { + return config; + } } - public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate, boolean sops, - boolean enableAdaptiveResolution) { - this.app = app; - this.width = width; - this.height = height; - this.refreshRate = refreshRate; - this.bitrate = bitrate; - this.sops = sops; - this.enableAdaptiveResolution = enableAdaptiveResolution; + private StreamConfiguration() { + // Set default attributes + this.app = "Steam"; + this.width = 1280; + this.height = 720; + this.refreshRate = 60; + this.bitrate = 10000; + this.sops = true; + this.enableAdaptiveResolution = false; } public int getWidth() { @@ -59,4 +95,8 @@ public class StreamConfiguration { public boolean getAdaptiveResolutionEnabled() { return enableAdaptiveResolution; } + + public boolean getPlayLocalAudio() { + return playLocalAudio; + } } diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index 43194343..4eda6af0 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -21,6 +21,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; +import com.limelight.nvstream.StreamConfiguration; import com.limelight.nvstream.http.PairingManager.PairState; @@ -278,14 +279,15 @@ public class NvHTTP { return new String(hexChars); } - public int launchApp(int appId, int width, int height, int refreshRate, SecretKey inputKey, boolean sops, int riKeyId) throws IOException, XmlPullParserException { + public int launchApp(int appId, SecretKey inputKey, int riKeyId, StreamConfiguration config) throws IOException, XmlPullParserException { InputStream in = openHttpConnection(baseUrl + "/launch?uniqueid=" + uniqueId + "&appid=" + appId + - "&mode=" + width + "x" + height + "x" + refreshRate + - "&additionalStates=1&sops=" + (sops ? 1 : 0) + + "&mode=" + config.getWidth() + "x" + config.getHeight() + "x" + config.getRefreshRate() + + "&additionalStates=1&sops=" + (config.getSops() ? 1 : 0) + "&rikey="+bytesToHex(inputKey.getEncoded()) + - "&rikeyid="+riKeyId, false); + "&rikeyid="+riKeyId + + "&localAudioPlayMode=" + (config.getPlayLocalAudio() ? 1 : 0), false); String gameSession = getXmlString(in, "gamesession"); return Integer.parseInt(gameSession); }