From 636c5f17f5e5ee37962d5a4bb8ba4efae5b93fe4 Mon Sep 17 00:00:00 2001 From: s0ckz Date: Fri, 30 May 2014 20:05:46 -0300 Subject: [PATCH] Different apps support and bug resolved There was a bug that prevented the app from running again if it was minimized. My solution is try to quit it before starting it again. --- .../com/limelight/nvstream/NvConnection.java | 52 ++++++++++++++----- .../nvstream/StreamConfiguration.java | 8 ++- .../com/limelight/nvstream/http/NvHTTP.java | 8 +-- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/NvConnection.java b/moonlight-common/src/com/limelight/nvstream/NvConnection.java index db00627b..99796372 100644 --- a/moonlight-common/src/com/limelight/nvstream/NvConnection.java +++ b/moonlight-common/src/com/limelight/nvstream/NvConnection.java @@ -134,7 +134,7 @@ public class NvConnection { } } - private boolean startSteamBigPicture() throws XmlPullParserException, IOException + private boolean startApp() throws XmlPullParserException, IOException { NvHTTP h = new NvHTTP(hostAddr, getMacAddressString(), localDeviceName); @@ -154,18 +154,21 @@ public class NvConnection { return false; } - NvApp app = h.getSteamApp(); + NvApp app = h.getApp(config.getApp()); if (app == null) { - listener.displayMessage("Steam not found in GFE app list"); + listener.displayMessage("The app " + config.getApp() + " is not in GFE app list"); return false; } // If there's a game running, resume it if (h.getCurrentGame() != 0) { try { - if (!h.resumeApp()) { + if (h.getCurrentGame() == app.getAppId() && !h.resumeApp()) { listener.displayMessage("Failed to resume existing session"); return false; + } else if (h.getCurrentGame() != app.getAppId()) { + listener.displayMessage("Another app was running. Quitting it"); + return quitAndLaunch(h, app); } } catch (GfeHttpResponseException e) { if (e.getErrorCode() == 470) { @@ -176,22 +179,43 @@ public class NvConnection { "device or the PC itself and try again. (Error code: "+e.getErrorCode()+")"); return false; } - else { + else if (e.getErrorCode() == 525) { + listener.displayMessage("The application is minimized. Trying to quit it"); + return quitAndLaunch(h, app); + } else { throw e; } } + LimeLog.info("Resumed existing game session"); + return true; } else { - // Launch the app since it's not running - int gameSessionId = h.launchApp(app.getAppId(), config.getWidth(), - config.getHeight(), config.getRefreshRate()); - if (gameSessionId == 0) { - listener.displayMessage("Failed to launch application"); - return false; - } - LimeLog.info("Launched new game session"); + return launchNotRunningApp(h, app); } + } + + protected boolean quitAndLaunch(NvHTTP h, NvApp app) throws IOException, + XmlPullParserException { + if (!h.quitApp()) { + listener.displayMessage("Failed to quit previous session! You must quit it manually"); + return false; + } else { + return launchNotRunningApp(h, app); + } + } + + 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()); + if (gameSessionId == 0) { + listener.displayMessage("Failed to launch application"); + return false; + } + + LimeLog.info("Launched new game session"); return true; } @@ -247,7 +271,7 @@ public class NvConnection { switch (currentStage) { case LAUNCH_APP: - success = startSteamBigPicture(); + success = startApp(); break; case RTSP_HANDSHAKE: diff --git a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java index 33789db0..3cf7d6e6 100644 --- a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java +++ b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java @@ -1,11 +1,13 @@ package com.limelight.nvstream; public class StreamConfiguration { + private String app; private int width, height; private int refreshRate; private int bitrate; - public StreamConfiguration(int width, int height, int refreshRate, int bitrate) { + public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate) { + this.app = app; this.width = width; this.height = height; this.refreshRate = refreshRate; @@ -27,4 +29,8 @@ public class StreamConfiguration { public int getBitrate() { return bitrate; } + + public String getApp() { + return app; + } } diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index 701ad31d..5438e5c6 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -109,12 +109,12 @@ public class NvHTTP { return Integer.parseInt(game); } - public NvApp getSteamApp() throws IOException, + public NvApp getApp(String app) throws IOException, XmlPullParserException { LinkedList appList = getAppList(); - for (NvApp app : appList) { - if (app.getAppName().equals("Steam")) { - return app; + for (NvApp appFromList : appList) { + if (appFromList.getAppName().equals(app)) { + return appFromList; } } return null;