mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-19 11:03:01 +00:00
Plumb common->JNI functions
This commit is contained in:
parent
a3d5e955aa
commit
c62986e7b1
@ -7,32 +7,15 @@ import javax.crypto.SecretKey;
|
|||||||
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||||
|
|
||||||
public class ConnectionContext {
|
public class ConnectionContext {
|
||||||
// Gen 3 servers are 2.1.1 - 2.2.1
|
|
||||||
public static final int SERVER_GENERATION_3 = 3;
|
|
||||||
|
|
||||||
// Gen 4 servers are 2.2.2+
|
|
||||||
public static final int SERVER_GENERATION_4 = 4;
|
|
||||||
|
|
||||||
// Gen 5 servers are 2.10.2+
|
|
||||||
public static final int SERVER_GENERATION_5 = 5;
|
|
||||||
|
|
||||||
// Gen 6 servers haven't been seen in the wild
|
|
||||||
public static final int SERVER_GENERATION_6 = 6;
|
|
||||||
|
|
||||||
// Gen 7 servers are GFE 2.11.2.46+
|
|
||||||
public static final int SERVER_GENERATION_7 = 7;
|
|
||||||
|
|
||||||
public InetAddress serverAddress;
|
public InetAddress serverAddress;
|
||||||
public StreamConfiguration streamConfig;
|
public StreamConfiguration streamConfig;
|
||||||
public VideoDecoderRenderer videoDecoderRenderer;
|
|
||||||
public NvConnectionListener connListener;
|
public NvConnectionListener connListener;
|
||||||
public SecretKey riKey;
|
public SecretKey riKey;
|
||||||
public int riKeyId;
|
public int riKeyId;
|
||||||
|
|
||||||
public int serverGeneration;
|
|
||||||
|
|
||||||
// This is the version quad from the appversion tag of /serverinfo
|
// This is the version quad from the appversion tag of /serverinfo
|
||||||
public int[] serverAppVersion;
|
public String serverAppVersion;
|
||||||
|
public String serverGfeVersion;
|
||||||
|
|
||||||
public int negotiatedVideoFormat;
|
public int negotiatedVideoFormat;
|
||||||
public int negotiatedWidth, negotiatedHeight;
|
public int negotiatedWidth, negotiatedHeight;
|
||||||
|
@ -19,6 +19,8 @@ import com.limelight.nvstream.http.LimelightCryptoProvider;
|
|||||||
import com.limelight.nvstream.http.NvApp;
|
import com.limelight.nvstream.http.NvApp;
|
||||||
import com.limelight.nvstream.http.NvHTTP;
|
import com.limelight.nvstream.http.NvHTTP;
|
||||||
import com.limelight.nvstream.http.PairingManager;
|
import com.limelight.nvstream.http.PairingManager;
|
||||||
|
import com.limelight.nvstream.input.MouseButtonPacket;
|
||||||
|
import com.limelight.nvstream.jni.MoonBridge;
|
||||||
|
|
||||||
public class NvConnection {
|
public class NvConnection {
|
||||||
// Context parameters
|
// Context parameters
|
||||||
@ -27,14 +29,13 @@ public class NvConnection {
|
|||||||
private String uniqueId;
|
private String uniqueId;
|
||||||
private ConnectionContext context;
|
private ConnectionContext context;
|
||||||
|
|
||||||
public NvConnection(String host, String uniqueId, NvConnectionListener listener, StreamConfiguration config, LimelightCryptoProvider cryptoProvider)
|
public NvConnection(String host, String uniqueId, StreamConfiguration config, LimelightCryptoProvider cryptoProvider)
|
||||||
{
|
{
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.cryptoProvider = cryptoProvider;
|
this.cryptoProvider = cryptoProvider;
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
|
|
||||||
this.context = new ConnectionContext();
|
this.context = new ConnectionContext();
|
||||||
this.context.connListener = listener;
|
|
||||||
this.context.streamConfig = config;
|
this.context.streamConfig = config;
|
||||||
try {
|
try {
|
||||||
// This is unique per connection
|
// This is unique per connection
|
||||||
@ -62,58 +63,28 @@ public class NvConnection {
|
|||||||
return new SecureRandom().nextInt();
|
return new SecureRandom().nextInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop() {
|
||||||
{
|
MoonBridge.stopConnection();
|
||||||
|
MoonBridge.cleanupBridge();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean startApp() throws XmlPullParserException, IOException
|
private boolean startApp() throws XmlPullParserException, IOException
|
||||||
{
|
{
|
||||||
NvHTTP h = new NvHTTP(context.serverAddress, uniqueId, null, cryptoProvider);
|
NvHTTP h = new NvHTTP(context.serverAddress, uniqueId, null, cryptoProvider);
|
||||||
|
|
||||||
String serverInfo = h.getServerInfo();
|
String serverInfo = h.getServerInfo();
|
||||||
|
|
||||||
context.serverAppVersion = h.getServerAppVersionQuad(serverInfo);
|
context.serverAppVersion = h.getServerVersion(serverInfo);
|
||||||
if (context.serverAppVersion == null) {
|
if (context.serverAppVersion == null) {
|
||||||
context.connListener.displayMessage("Server version malformed");
|
context.connListener.displayMessage("Server version malformed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int majorVersion = context.serverAppVersion[0];
|
context.serverGfeVersion = h.getGfeVersion(serverInfo);
|
||||||
LimeLog.info("Server major version: "+majorVersion);
|
if (context.serverGfeVersion == null) {
|
||||||
|
context.connListener.displayMessage("Server GFE version malformed");
|
||||||
if (majorVersion == 0) {
|
|
||||||
context.connListener.displayMessage("Server version malformed");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (majorVersion < 3) {
|
|
||||||
// Even though we support major version 3 (2.1.x), GFE 2.2.2 is preferred.
|
|
||||||
context.connListener.displayMessage("This app requires GeForce Experience 2.2.2 or later. Please upgrade GFE on your PC and try again.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (majorVersion > 7) {
|
|
||||||
// Warn the user but allow them to continue
|
|
||||||
context.connListener.displayTransientMessage("This version of GFE is not currently supported. You may experience issues until this app is updated.");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (majorVersion) {
|
|
||||||
case 3:
|
|
||||||
context.serverGeneration = ConnectionContext.SERVER_GENERATION_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
context.serverGeneration = ConnectionContext.SERVER_GENERATION_4;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
context.serverGeneration = ConnectionContext.SERVER_GENERATION_5;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
context.serverGeneration = ConnectionContext.SERVER_GENERATION_6;
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
default:
|
|
||||||
context.serverGeneration = ConnectionContext.SERVER_GENERATION_7;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (h.getPairState(serverInfo) != PairingManager.PairState.PAIRED) {
|
if (h.getPairState(serverInfo) != PairingManager.PairState.PAIRED) {
|
||||||
context.connListener.displayMessage("Device not paired with computer");
|
context.connListener.displayMessage("Device not paired with computer");
|
||||||
@ -251,12 +222,14 @@ public class NvConnection {
|
|||||||
context.connListener.stageFailed(appName, 0);
|
context.connListener.stageFailed(appName, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MoonBridge.startConnection(context.serverAddress.getHostAddress(),
|
||||||
|
context.serverAppVersion, context.serverGfeVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(AudioRenderer audioRenderer, VideoDecoderRenderer videoDecoderRenderer)
|
public void start(AudioRenderer audioRenderer, VideoDecoderRenderer videoDecoderRenderer, NvConnectionListener connectionListener)
|
||||||
{
|
{
|
||||||
this.context.videoDecoderRenderer = videoDecoderRenderer;
|
MoonBridge.setupBridge(videoDecoderRenderer, audioRenderer, connectionListener);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
@ -273,17 +246,17 @@ public class NvConnection {
|
|||||||
|
|
||||||
public void sendMouseMove(final short deltaX, final short deltaY)
|
public void sendMouseMove(final short deltaX, final short deltaY)
|
||||||
{
|
{
|
||||||
|
MoonBridge.sendMouseMove(deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMouseButtonDown(final byte mouseButton)
|
public void sendMouseButtonDown(final byte mouseButton)
|
||||||
{
|
{
|
||||||
|
MoonBridge.sendMouseButton(MouseButtonPacket.PRESS_EVENT, mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMouseButtonUp(final byte mouseButton)
|
public void sendMouseButtonUp(final byte mouseButton)
|
||||||
{
|
{
|
||||||
|
MoonBridge.sendMouseButton(MouseButtonPacket.RELEASE_EVENT, mouseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendControllerInput(final short controllerNumber,
|
public void sendControllerInput(final short controllerNumber,
|
||||||
@ -292,7 +265,7 @@ public class NvConnection {
|
|||||||
final short leftStickX, final short leftStickY,
|
final short leftStickX, final short leftStickY,
|
||||||
final short rightStickX, final short rightStickY)
|
final short rightStickX, final short rightStickY)
|
||||||
{
|
{
|
||||||
|
MoonBridge.sendMultiControllerInput(controllerNumber, activeGamepadMask, buttonFlags, leftTrigger, rightTrigger, leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendControllerInput(final short buttonFlags,
|
public void sendControllerInput(final short buttonFlags,
|
||||||
@ -300,15 +273,15 @@ public class NvConnection {
|
|||||||
final short leftStickX, final short leftStickY,
|
final short leftStickX, final short leftStickY,
|
||||||
final short rightStickX, final short rightStickY)
|
final short rightStickX, final short rightStickY)
|
||||||
{
|
{
|
||||||
|
MoonBridge.sendControllerInput(buttonFlags, leftTrigger, rightTrigger, leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendKeyboardInput(final short keyMap, final byte keyDirection, final byte modifier) {
|
public void sendKeyboardInput(final short keyMap, final byte keyDirection, final byte modifier) {
|
||||||
|
MoonBridge.sendKeyboardInput(keyMap, keyDirection, modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMouseScroll(final byte scrollClicks) {
|
public void sendMouseScroll(final byte scrollClicks) {
|
||||||
|
MoonBridge.sendMouseScroll(scrollClicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getActiveVideoFormat() {
|
public int getActiveVideoFormat() {
|
||||||
|
@ -377,6 +377,10 @@ public class NvHTTP {
|
|||||||
public String getGpuType(String serverInfo) throws XmlPullParserException, IOException {
|
public String getGpuType(String serverInfo) throws XmlPullParserException, IOException {
|
||||||
return getXmlString(serverInfo, "gputype");
|
return getXmlString(serverInfo, "gputype");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getGfeVersion(String serverInfo) throws XmlPullParserException, IOException {
|
||||||
|
return getXmlString(serverInfo, "GfeVersion");
|
||||||
|
}
|
||||||
|
|
||||||
public boolean supports4K(String serverInfo) throws XmlPullParserException, IOException {
|
public boolean supports4K(String serverInfo) throws XmlPullParserException, IOException {
|
||||||
// serverinfo returns supported resolutions in descending order, so getting the first
|
// serverinfo returns supported resolutions in descending order, so getting the first
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.limelight.nvstream.input;
|
package com.limelight.nvstream.input;
|
||||||
|
|
||||||
public class MouseButtonPacket {
|
public class MouseButtonPacket {
|
||||||
private static final byte PRESS_EVENT = 0x07;
|
public static final byte PRESS_EVENT = 0x07;
|
||||||
private static final byte RELEASE_EVENT = 0x08;
|
public static final byte RELEASE_EVENT = 0x08;
|
||||||
|
|
||||||
public static final byte BUTTON_LEFT = 0x01;
|
public static final byte BUTTON_LEFT = 0x01;
|
||||||
public static final byte BUTTON_MIDDLE = 0x02;
|
public static final byte BUTTON_MIDDLE = 0x02;
|
||||||
|
@ -106,5 +106,40 @@ public class MoonBridge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setupBridge(VideoDecoderRenderer videoRenderer, AudioRenderer audioRenderer, NvConnectionListener connectionListener) {
|
||||||
|
MoonBridge.videoRenderer = videoRenderer;
|
||||||
|
MoonBridge.audioRenderer = audioRenderer;
|
||||||
|
MoonBridge.connectionListener = connectionListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void cleanupBridge() {
|
||||||
|
MoonBridge.videoRenderer = null;
|
||||||
|
MoonBridge.audioRenderer = null;
|
||||||
|
MoonBridge.connectionListener = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static native void startConnection(String address, String serverInfoAppVersion, String serverInfoGfeVersion);
|
||||||
|
|
||||||
|
public static native void stopConnection();
|
||||||
|
|
||||||
|
public static native void sendMouseMove(short deltaX, short deltaY);
|
||||||
|
|
||||||
|
public static native void sendMouseButton(byte buttonEvent, byte mouseButton);
|
||||||
|
|
||||||
|
public static native void sendMultiControllerInput(short controllerNumber,
|
||||||
|
short activeGamepadMask, short buttonFlags,
|
||||||
|
byte leftTrigger, byte rightTrigger,
|
||||||
|
short leftStickX, short leftStickY,
|
||||||
|
short rightStickX, short rightStickY);
|
||||||
|
|
||||||
|
public static native void sendControllerInput(short buttonFlags,
|
||||||
|
byte leftTrigger, byte rightTrigger,
|
||||||
|
short leftStickX, short leftStickY,
|
||||||
|
short rightStickX, short rightStickY);
|
||||||
|
|
||||||
|
public static native void sendKeyboardInput(short keyMap, byte keyDirection, byte modifier);
|
||||||
|
|
||||||
|
public static native void sendMouseScroll(byte scrollClicks);
|
||||||
|
|
||||||
public static native String getStageName(int stage);
|
public static native String getStageName(int stage);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user