Use a builder for StreamConfiguration to avoid further breaking changes to the constructor. Add support for local audio playback mode.

This commit is contained in:
Cameron Gutman 2014-11-02 20:52:09 -08:00
parent ae79f03e61
commit b0169b0edf
3 changed files with 63 additions and 23 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}