Compare commits

..

72 Commits

Author SHA1 Message Date
Cameron Gutman 7fb2f15f54 Re-release of 4.5.6 with fixed Gen 4 streaming 2016-03-29 23:37:03 -04:00
Cameron Gutman f93dbb4116 Update common jar again to fix streaming on Gen 4 and earlier 2016-03-29 23:34:31 -04:00
Cameron Gutman bc34fe3a9f Increment version to 4.5.6 2016-03-29 20:35:54 -04:00
Cameron Gutman bbe49491c1 Update common jar to support GFE 2.11.2.46+ 2016-03-29 20:17:35 -04:00
Cameron Gutman d5ccb80f26 Update to new Gradle for Android Studio 2.1 2016-03-29 20:15:45 -04:00
Cameron Gutman 50fd15379a Fix JNI compilation warnings 2016-03-10 15:28:42 -08:00
Cameron Gutman ed479f1155 Increment version to 4.5.5 2016-03-08 13:10:04 -08:00
Cameron Gutman 04db9ba714 Update common to fix RTSP handshake timeouts with ENet 2016-03-08 13:07:33 -08:00
Cameron Gutman 6a973e3248 Update version code for 4.5.4 r2 2016-03-07 15:01:58 -08:00
Cameron Gutman 96d9e4977b Update to ENet API to support IPv6 2016-03-07 14:37:01 -08:00
Cameron Gutman 5a3897f22a Update common jar to fix some ENet crashes 2016-03-07 13:16:55 -08:00
Cameron Gutman ceef00b79a Fail writePacket if enet_peer_send returns -1 2016-03-07 12:54:06 -08:00
Cameron Gutman 94ee24ea11 Update to 4.5.4 2016-03-06 21:52:54 -08:00
Cameron Gutman 1a201f2e94 Update gradle to latest beta 2016-03-06 21:51:48 -08:00
Cameron Gutman e0c6d41d4b Update libs again to fix duplicate files 2016-03-06 21:51:01 -08:00
Cameron Gutman 44a0ae86d2 Working ENet with new common jar and modified ENet library 2016-03-06 15:55:33 -08:00
Cameron Gutman 06822ad385 Add JNI library for ENet 2016-03-05 17:48:10 -06:00
Cameron Gutman 3be52280ba Update common to disable dynamic resolution switching 2016-02-28 14:52:07 -05:00
Cameron Gutman 5142f978cf Fixed polling resuming in the background in some cases 2016-02-23 23:47:49 -05:00
Cameron Gutman 667ffd4dfd Bump to version 4.5.3.2 2016-02-23 16:33:57 -05:00
Cameron Gutman 17626f1853 Update common to crash in mDNS discovery agent 2016-02-23 16:33:38 -05:00
Cameron Gutman 5c79567a2c Bump version to 4.5.3.1 2016-02-20 20:11:26 -05:00
Cameron Gutman 0f5fd9af62 Update common to fix mDNS running passively in the background 2016-02-20 20:11:00 -05:00
Cameron Gutman 99643537d1 Only disable missing translation Lint errors rather than ignoring all Lint errors 2016-02-20 20:10:14 -05:00
Cameron Gutman 47650386e0 Bump version code and update common to fix video issue on H265 2016-02-19 11:35:52 -05:00
Cameron Gutman aa3fc34646 Update version code and lint options for building releases with Gradle 2.0 2016-02-19 04:11:03 -05:00
Cameron Gutman 92f5f1ac71 Bump to 4.5.3 with support for GFE 2.10.2 2016-02-19 03:58:38 -05:00
Cameron Gutman eb739f73c7 Update Gradle and Gradle Wrapper for Android Studio 2.0 2016-02-06 16:44:00 -05:00
Cameron Gutman 20a646106b Fix duplicate file exceptions with newer versions of Gradle 2016-02-06 16:43:11 -05:00
Cameron Gutman 0dc14517cd Bump version to 4.5.2 2016-01-30 05:16:29 -05:00
Cameron Gutman 04713c007b Remove some hacks for Android TV 2016-01-30 05:10:47 -05:00
Cameron Gutman 1cac7660b8 Fix a null pointer exception reported by a user 2016-01-30 04:55:17 -05:00
Cameron Gutman edb286f9af Hide the mouse on the main thread just to be safe 2016-01-30 04:27:14 -05:00
Cameron Gutman fb15ff99ca Add support for the NVIDIA relative mouse extensions for Shield devices 2016-01-30 04:21:20 -05:00
Cameron Gutman a455e75e37 Fix recognition of mouse events on Shield Portable 2016-01-30 04:15:09 -05:00
Cameron Gutman 2b452e51f9 Bump version to 4.5.1 2016-01-28 13:02:46 -05:00
Cameron Gutman 9d2b6f8854 Make nextDeviceId non-static since the lifetime of ControllerHandler is also just the life of the connection 2016-01-28 13:02:30 -05:00
Cameron Gutman 3be10a1b59 Update preference string to include Xbox 360 2016-01-28 12:55:19 -05:00
Cameron Gutman 01950c25a8 Only claim Xbox 360 controllers if the kernel hasn't already 2016-01-28 12:35:16 -05:00
Cameron Gutman 7ad1ebd0e8 Fix Xbox 360 driver 2016-01-28 12:07:11 -05:00
Cameron Gutman ee01a8b5a0 Turn the XB360 controller LED on at init 2016-01-27 14:00:14 -05:00
Cameron Gutman 23c54f6813 Add support for wired Xbox 360 controllers (pending testing) 2016-01-27 13:45:04 -05:00
Cameron Gutman ceef4510fb Fix infinite app list loading spinner if the app list is actually empty 2016-01-24 02:51:06 -05:00
Cameron Gutman 042a6b943e Bump version to 4.5 2016-01-20 02:18:22 -05:00
Cameron Gutman e114b73654 Revert "Fix margins around analog sticks"
This reverts commit 5d84f8af43.
2016-01-20 01:35:30 -05:00
Cameron Gutman da0a505978 Shrink the text size in the buttons so the start button text fits on the Nexus 9 2016-01-20 01:30:48 -05:00
Cameron Gutman cb6d4a385c Leave a margin around the d-pad so the selection rectangle doesn't draw over the control itself 2016-01-20 01:12:53 -05:00
Cameron Gutman 2806aee0fc Fix drawing and placement of face buttons 2016-01-20 01:04:06 -05:00
Cameron Gutman 52736f5162 Increase the time allowed for a double click to activate the stick button 2016-01-20 00:28:33 -05:00
Cameron Gutman 6d45ad7fe8 Improve precision of joystick inputs by lifting the deadzone after 150 ms. This way it prevents false inputs when activation the stick buttons but allows for precise movements after confirming that the touch is intended. 2016-01-20 00:28:11 -05:00
Cameron Gutman 2fc53644bc Use a uniform stroke width based on screen size in pixels 2016-01-19 20:26:46 -05:00
Cameron Gutman b33eaec493 Temporarily disable the config dialog and just map a tap of a controller element to move 2016-01-19 19:58:11 -05:00
Cameron Gutman 63d6f3ac78 Fix snapping into the deadzone when using analog sticks 2016-01-19 19:54:52 -05:00
Cameron Gutman fd4caac013 Fix erratic joystick movement 2016-01-19 19:44:33 -05:00
Cameron Gutman ada875cdb0 Highlight the controls red when in configuration mode 2016-01-19 18:52:51 -05:00
Cameron Gutman 49ddfa573d Ignore inputs when the on-screen controls are in configuration mode 2016-01-19 18:31:00 -05:00
Cameron Gutman b58ac367ee Increase the size of the virtual controller settings button 2016-01-19 18:24:10 -05:00
Cameron Gutman cf62b4ed95 Select is slightly too long for the button so rename it to Backc 2016-01-19 18:13:16 -05:00
Cameron Gutman b05c62e141 Fix outside of each d-pad button being cut off by the end of the canvas 2016-01-19 18:01:30 -05:00
Cameron Gutman 095556106c Fix highlighting of selected controller element during configuration 2016-01-19 17:45:14 -05:00
Cameron Gutman 5cdd72a45c Disable printing controller output 2016-01-19 17:35:17 -05:00
Cameron Gutman 5d84f8af43 Fix margins around analog sticks 2016-01-19 17:34:52 -05:00
Cameron Gutman d9483d9214 Show a nicer configuration toast 2016-01-19 17:30:49 -05:00
Cameron Gutman 250475830f Draw the highlight border after the element so it doesn't get drawn over 2016-01-19 17:08:00 -05:00
Cameron Gutman b8a0a823e0 Raise d-pad and buttons slightly further from the analog sticks 2016-01-19 16:33:00 -05:00
Cameron Gutman 6a54d669a3 Fix capitalization of preference group 2016-01-19 16:31:06 -05:00
Cameron Gutman 62559c4e66 Merge branch 'master' of https://github.com/hop3l3ss/limelight-android 2016-01-19 16:23:56 -05:00
Cameron Gutman e04ecaaf7a Rework the face buttons to match the d-pad 2016-01-19 16:23:40 -05:00
Karim fa4706c95f fix on screen controls category typo 2016-01-09 12:56:39 +01:00
Karim 7067c0e02e show onscreen controls settings only on touchscreen devices 2016-01-09 12:49:12 +01:00
Cameron Gutman cc71ce6180 Fix crash in XB1 controller driver on Fire HD 6 after controller removal 2016-01-07 22:52:17 -06:00
Cameron Gutman f409a3583c Fix direct submit behavior in decoders since the addition of HEVC 2016-01-07 18:51:02 -06:00
33 changed files with 1004 additions and 510 deletions
+3
View File
@@ -0,0 +1,3 @@
[submodule "app/src/main/jni/jnienet/enet"]
path = app/src/main/jni/jnienet/enet
url = https://github.com/cgutman/enet.git
+13 -2
View File
@@ -11,8 +11,8 @@ android {
minSdkVersion 16
targetSdkVersion 23
versionName "4.0.4"
versionCode = 82
versionName "4.5.6"
versionCode = 95
}
productFlavors {
@@ -25,6 +25,10 @@ android {
}
}
lintOptions {
disable 'MissingTranslation'
}
buildTypes {
release {
minifyEnabled false
@@ -32,6 +36,13 @@ android {
}
}
// These lines are required to avoid dexing issues with the BouncyCastle library
// bundled with limelight-common.jar
packagingOptions {
exclude 'META-INF/BCKEY.SF'
exclude 'META-INF/BCKEY.DSA'
}
sourceSets.main.jni.srcDirs = []
//noinspection GroovyAssignabilityCheck,GroovyAssignabilityCheck
Binary file not shown.
Binary file not shown.
+3 -14
View File
@@ -12,17 +12,18 @@
<uses-feature android:name="android.hardware.wifi" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
<uses-feature android:name="android.software.leanback" android:required="false" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:banner="@drawable/atv_banner"
android:theme="@style/AppTheme" >
<!-- Samsung multi-window support -->
<uses-library android:name="com.sec.android.app.multiwindow" android:required="false" />
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
<!-- Launcher for traditional devices -->
<activity
android:name=".PcView"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection">
@@ -30,22 +31,10 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.MULTIWINDOW_LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="tv.ouya.intent.category.APP" />
</intent-filter>
</activity>
<!-- Launcher for Android TV devices -->
<activity
android:name=".PcViewTv"
android:logo="@drawable/atv_banner"
android:icon="@drawable/atv_banner"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AppView"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection" >
+5 -1
View File
@@ -50,6 +50,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
private String lastRawApplist;
private int lastRunningAppId;
private boolean suspendGridUpdates;
private boolean inForeground;
private final static int START_OR_RESUME_ID = 1;
private final static int QUIT_ID = 2;
@@ -108,7 +109,8 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
};
private void startComputerUpdates() {
if (managerBinder == null) {
// Don't start polling if we're not bound or in the foreground
if (managerBinder == null || !inForeground) {
return;
}
@@ -252,6 +254,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
protected void onResume() {
super.onResume();
inForeground = true;
startComputerUpdates();
}
@@ -259,6 +262,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
protected void onPause() {
super.onPause();
inForeground = false;
stopComputerUpdates();
}
+49 -10
View File
@@ -4,6 +4,7 @@ package com.limelight;
import com.limelight.binding.PlatformBinding;
import com.limelight.binding.input.ControllerHandler;
import com.limelight.binding.input.KeyboardTranslator;
import com.limelight.binding.input.NvMouseHelper;
import com.limelight.binding.input.TouchContext;
import com.limelight.binding.input.driver.UsbDriverService;
import com.limelight.binding.input.evdev.EvdevHandler;
@@ -422,11 +423,15 @@ public class Game extends Activity implements SurfaceHolder.Callback,
private final Runnable toggleGrab = new Runnable() {
@Override
public void run() {
if (evdevHandler != null) {
if (grabbedInput) {
if (grabbedInput) {
NvMouseHelper.setCursorVisibility(Game.this, true);
if (evdevHandler != null) {
evdevHandler.ungrabAll();
}
else {
}
else {
NvMouseHelper.setCursorVisibility(Game.this, false);
if (evdevHandler != null) {
evdevHandler.regrabAll();
}
}
@@ -616,7 +621,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
else if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0)
{
// This case is for mice
if (event.getSource() == InputDevice.SOURCE_MOUSE)
if (event.getSource() == InputDevice.SOURCE_MOUSE ||
(event.getPointerCount() >= 1 &&
event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE))
{
int changedButtons = event.getButtonState() ^ lastButtonState;
@@ -653,19 +660,38 @@ public class Game extends Activity implements SurfaceHolder.Callback,
}
}
// First process the history
for (int i = 0; i < event.getHistorySize(); i++) {
updateMousePosition((int)event.getHistoricalX(i), (int)event.getHistoricalY(i));
}
// Get relative axis values if we can
if (NvMouseHelper.eventHasRelativeMouseAxes(event)) {
// Send the deltas straight from the motion event
conn.sendMouseMove((short)NvMouseHelper.getRelativeAxisX(event),
(short)NvMouseHelper.getRelativeAxisY(event));
// Now process the current values
updateMousePosition((int)event.getX(), (int)event.getY());
// We have to also update the position Android thinks the cursor is at
// in order to avoid jumping when we stop moving or click.
lastMouseX = (int)event.getX();
lastMouseY = (int)event.getY();
}
else {
// First process the history
for (int i = 0; i < event.getHistorySize(); i++) {
updateMousePosition((int)event.getHistoricalX(i), (int)event.getHistoricalY(i));
}
// Now process the current values
updateMousePosition((int)event.getX(), (int)event.getY());
}
lastButtonState = event.getButtonState();
}
// This case is for touch-based input devices
else
{
if (virtualController != null &&
virtualController.getControllerMode() == VirtualController.ControllerMode.Configuration) {
// Ignore presses when the virtual controller is in configuration mode
return true;
}
int actionIndex = event.getActionIndex();
int eventX = (int)event.getX(actionIndex);
@@ -820,6 +846,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
evdevHandler.stop();
evdevHandler = null;
}
// Enable cursor visibility again
NvMouseHelper.setCursorVisibility(this, true);
}
@Override
@@ -859,6 +888,16 @@ public class Game extends Activity implements SurfaceHolder.Callback,
connecting = false;
connected = true;
runOnUiThread(new Runnable() {
@Override
public void run() {
// Hide the mouse cursor now. Doing it before
// dismissing the spinner seems to be undone
// when the spinner gets displayed.
NvMouseHelper.setCursorVisibility(Game.this, false);
}
});
hideSystemUi(1000);
}
+15 -17
View File
@@ -53,7 +53,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
private RelativeLayout noPcFoundLayout;
private PcGridAdapter pcGridAdapter;
private ComputerManagerService.ComputerManagerBinder managerBinder;
private boolean freezeUpdates, runningPolling, hasResumed;
private boolean freezeUpdates, runningPolling, inForeground;
private final ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder binder) {
final ComputerManagerService.ComputerManagerBinder localBinder =
@@ -161,11 +161,9 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
}
private void startComputerUpdates() {
if (managerBinder != null) {
if (runningPolling) {
return;
}
// Only allow polling to start if we're bound to CMS, polling is not already running,
// and our activity is in the foreground.
if (managerBinder != null && !runningPolling && inForeground) {
freezeUpdates = false;
managerBinder.startPolling(new ComputerManagerListener() {
@Override
@@ -215,7 +213,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
protected void onResume() {
super.onResume();
hasResumed = true;
inForeground = true;
startComputerUpdates();
}
@@ -223,7 +221,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
protected void onPause() {
super.onPause();
hasResumed = false;
inForeground = false;
stopComputerUpdates(false);
}
@@ -271,10 +269,9 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
@Override
public void onContextMenuClosed(Menu menu) {
// For some reason, this gets called again _after_ onPause() is called on this activity.
// We don't want to start computer updates again, so we need to keep track of whether we're paused.
if (hasResumed) {
startComputerUpdates();
}
// startComputerUpdates() manages this and won't actual start polling until the activity
// returns to the foreground.
startComputerUpdates();
}
private void doPair(final ComputerDetails computer) {
@@ -330,7 +327,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
Dialog.displayDialog(PcView.this, getResources().getString(R.string.pair_pairing_title),
getResources().getString(R.string.pair_pairing_msg)+" "+pinStr, false);
PairingManager.PairState pairState = httpConn.pair(pinStr);
PairingManager.PairState pairState = httpConn.pair(httpConn.getServerInfo(), pinStr);
if (pairState == PairingManager.PairState.PIN_WRONG) {
message = getResources().getString(R.string.pair_incorrect_pin);
}
@@ -368,14 +365,15 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
}
if (toastSuccess) {
// Open the app list after a successful pairing attemp
// Open the app list after a successful pairing attempt
doAppList(computer);
}
else {
// Start polling again if we're still in the foreground
startComputerUpdates();
}
}
});
// Start polling again
startComputerUpdates();
}
}).start();
}
@@ -1,6 +0,0 @@
package com.limelight;
/* This is a dummy class to allow for a separate icon
* and launcher for TV.
*/
public class PcViewTv extends PcView {}
@@ -0,0 +1,76 @@
package com.limelight.binding.input;
import android.content.Context;
import android.hardware.input.InputManager;
import android.view.MotionEvent;
import com.limelight.LimeLog;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
// NVIDIA extended the Android input APIs with support for using an attached mouse in relative
// mode without having to grab the input device (which requires root). The data comes in the form
// of new AXIS_RELATIVE_X and AXIS_RELATIVE_Y constants in the mouse's MotionEvent objects and
// a new function, InputManager.setCursorVisibility(), that allows the cursor to be hidden.
//
// http://docs.nvidia.com/gameworks/index.html#technologies/mobile/game_controller_handling_mouse.htm
public class NvMouseHelper {
private static boolean nvExtensionSupported;
private static Method methodSetCursorVisibility;
private static int AXIS_RELATIVE_X;
private static int AXIS_RELATIVE_Y;
static {
try {
methodSetCursorVisibility = InputManager.class.getMethod("setCursorVisibility", boolean.class);
Field fieldRelX = MotionEvent.class.getField("AXIS_RELATIVE_X");
Field fieldRelY = MotionEvent.class.getField("AXIS_RELATIVE_Y");
AXIS_RELATIVE_X = (Integer) fieldRelX.get(null);
AXIS_RELATIVE_Y = (Integer) fieldRelY.get(null);
nvExtensionSupported = true;
} catch (Exception e) {
LimeLog.info("NvMouseHelper not supported");
nvExtensionSupported = false;
}
}
public static boolean setCursorVisibility(Context context, boolean visible) {
if (!nvExtensionSupported) {
return false;
}
try {
methodSetCursorVisibility.invoke(context.getSystemService(Context.INPUT_SERVICE), visible);
return true;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
public static boolean eventHasRelativeMouseAxes(MotionEvent event) {
if (!nvExtensionSupported) {
return false;
}
return event.getAxisValue(AXIS_RELATIVE_X) != 0 ||
event.getAxisValue(AXIS_RELATIVE_Y) != 0;
}
public static float getRelativeAxisX(MotionEvent event) {
return event.getAxisValue(AXIS_RELATIVE_X);
}
public static float getRelativeAxisY(MotionEvent event) {
return event.getAxisValue(AXIS_RELATIVE_Y);
}
}
@@ -0,0 +1,55 @@
package com.limelight.binding.input.driver;
import android.hardware.usb.UsbEndpoint;
import com.limelight.LimeLog;
import com.limelight.binding.video.MediaCodecHelper;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public abstract class AbstractController {
private final int deviceId;
private UsbDriverListener listener;
protected short buttonFlags;
protected float leftTrigger, rightTrigger;
protected float rightStickX, rightStickY;
protected float leftStickX, leftStickY;
public int getControllerId() {
return deviceId;
}
protected void setButtonFlag(int buttonFlag, int data) {
if (data != 0) {
buttonFlags |= buttonFlag;
}
else {
buttonFlags &= ~buttonFlag;
}
}
protected void reportInput() {
listener.reportControllerState(deviceId, buttonFlags, leftStickX, leftStickY,
rightStickX, rightStickY, leftTrigger, rightTrigger);
}
public abstract boolean start();
public abstract void stop();
public AbstractController(int deviceId, UsbDriverListener listener) {
this.deviceId = deviceId;
this.listener = listener;
}
protected void notifyDeviceRemoved() {
listener.deviceRemoved(deviceId);
}
protected void notifyDeviceAdded() {
listener.deviceAdded(deviceId);
}
}
@@ -0,0 +1,149 @@
package com.limelight.binding.input.driver;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbEndpoint;
import android.hardware.usb.UsbInterface;
import com.limelight.LimeLog;
import com.limelight.binding.video.MediaCodecHelper;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public abstract class AbstractXboxController extends AbstractController {
protected final UsbDevice device;
protected final UsbDeviceConnection connection;
private Thread inputThread;
private boolean stopped;
protected UsbEndpoint inEndpt, outEndpt;
public AbstractXboxController(UsbDevice device, UsbDeviceConnection connection, int deviceId, UsbDriverListener listener) {
super(deviceId, listener);
this.device = device;
this.connection = connection;
}
private Thread createInputThread() {
return new Thread() {
public void run() {
while (!isInterrupted() && !stopped) {
byte[] buffer = new byte[64];
int res;
//
// There's no way that I can tell to determine if a device has failed
// or if the timeout has simply expired. We'll check how long the transfer
// took to fail and assume the device failed if it happened before the timeout
// expired.
//
do {
// Read the next input state packet
long lastMillis = MediaCodecHelper.getMonotonicMillis();
res = connection.bulkTransfer(inEndpt, buffer, buffer.length, 3000);
// If we get a zero length response, treat it as an error
if (res == 0) {
res = -1;
}
if (res == -1 && MediaCodecHelper.getMonotonicMillis() - lastMillis < 1000) {
LimeLog.warning("Detected device I/O error");
AbstractXboxController.this.stop();
break;
}
} while (res == -1 && !isInterrupted() && !stopped);
if (res == -1 || stopped) {
break;
}
if (handleRead(ByteBuffer.wrap(buffer, 0, res).order(ByteOrder.LITTLE_ENDIAN))) {
// Report input if handleRead() returns true
reportInput();
}
}
}
};
}
public boolean start() {
// Force claim all interfaces
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface iface = device.getInterface(i);
if (!connection.claimInterface(iface, true)) {
LimeLog.warning("Failed to claim interfaces");
return false;
}
}
// Find the endpoints
UsbInterface iface = device.getInterface(0);
for (int i = 0; i < iface.getEndpointCount(); i++) {
UsbEndpoint endpt = iface.getEndpoint(i);
if (endpt.getDirection() == UsbConstants.USB_DIR_IN) {
if (inEndpt != null) {
LimeLog.warning("Found duplicate IN endpoint");
return false;
}
inEndpt = endpt;
}
else if (endpt.getDirection() == UsbConstants.USB_DIR_OUT) {
if (outEndpt != null) {
LimeLog.warning("Found duplicate OUT endpoint");
return false;
}
outEndpt = endpt;
}
}
// Make sure the required endpoints were present
if (inEndpt == null || outEndpt == null) {
LimeLog.warning("Missing required endpoint");
return false;
}
// Run the init function
if (!doInit()) {
return false;
}
// Start listening for controller input
inputThread = createInputThread();
inputThread.start();
// Now report we're added
notifyDeviceAdded();
return true;
}
public void stop() {
if (stopped) {
return;
}
stopped = true;
// Stop the input thread
if (inputThread != null) {
inputThread.interrupt();
inputThread = null;
}
// Report the device removed
notifyDeviceRemoved();
// Close the USB connection
connection.close();
}
protected abstract boolean handleRead(ByteBuffer buffer);
protected abstract boolean doInit();
}
@@ -10,7 +10,9 @@ import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.view.InputDevice;
import com.limelight.LimeLog;
@@ -26,10 +28,10 @@ public class UsbDriverService extends Service implements UsbDriverListener {
private final UsbEventReceiver receiver = new UsbEventReceiver();
private final UsbDriverBinder binder = new UsbDriverBinder();
private final ArrayList<XboxOneController> controllers = new ArrayList<>();
private final ArrayList<AbstractController> controllers = new ArrayList<>();
private UsbDriverListener listener;
private static int nextDeviceId;
private int nextDeviceId;
@Override
public void reportControllerState(int controllerId, short buttonFlags, float leftStickX, float leftStickY, float rightStickX, float rightStickY, float leftTrigger, float rightTrigger) {
@@ -42,7 +44,7 @@ public class UsbDriverService extends Service implements UsbDriverListener {
@Override
public void deviceRemoved(int controllerId) {
// Remove the the controller from our list (if not removed already)
for (XboxOneController controller : controllers) {
for (AbstractController controller : controllers) {
if (controller.getControllerId() == controllerId) {
controllers.remove(controller);
break;
@@ -93,7 +95,7 @@ public class UsbDriverService extends Service implements UsbDriverListener {
// Report all controllerMap that already exist
if (listener != null) {
for (XboxOneController controller : controllers) {
for (AbstractController controller : controllers) {
listener.deviceAdded(controller.getControllerId());
}
}
@@ -102,7 +104,7 @@ public class UsbDriverService extends Service implements UsbDriverListener {
private void handleUsbDeviceState(UsbDevice device) {
// Are we able to operate it?
if (XboxOneController.canClaimDevice(device)) {
if (shouldClaimDevice(device)) {
// Do we have permission yet?
if (!usbManager.hasPermission(device)) {
// Let's ask for permission
@@ -117,8 +119,21 @@ public class UsbDriverService extends Service implements UsbDriverListener {
return;
}
// Try to initialize it
XboxOneController controller = new XboxOneController(device, connection, nextDeviceId++, this);
AbstractController controller;
if (XboxOneController.canClaimDevice(device)) {
controller = new XboxOneController(device, connection, nextDeviceId++, this);
}
else if (Xbox360Controller.canClaimDevice(device)) {
controller = new Xbox360Controller(device, connection, nextDeviceId++, this);
}
else {
// Unreachable
return;
}
// Start the controller
if (!controller.start()) {
connection.close();
return;
@@ -129,6 +144,34 @@ public class UsbDriverService extends Service implements UsbDriverListener {
}
}
private boolean isRecognizedInputDevice(UsbDevice device) {
// On KitKat and later, we can determine if this VID and PID combo
// matches an existing input device and defer to the built-in controller
// support in that case. Prior to KitKat, we'll always return true to be safe.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
for (int id : InputDevice.getDeviceIds()) {
InputDevice inputDev = InputDevice.getDevice(id);
if (inputDev.getVendorId() == device.getVendorId() &&
inputDev.getProductId() == device.getProductId()) {
return true;
}
}
return false;
}
else {
return true;
}
}
private boolean shouldClaimDevice(UsbDevice device) {
// We always bind to XB1 controllers but only bind to XB360 controllers
// if we know the kernel isn't already driving this device.
return XboxOneController.canClaimDevice(device) ||
(!isRecognizedInputDevice(device) && Xbox360Controller.canClaimDevice(device));
}
@Override
public void onCreate() {
this.usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
@@ -141,7 +184,7 @@ public class UsbDriverService extends Service implements UsbDriverListener {
// Enumerate existing devices
for (UsbDevice dev : usbManager.getDeviceList().values()) {
if (XboxOneController.canClaimDevice(dev)) {
if (shouldClaimDevice(dev)) {
// Start the process of claiming this device
handleUsbDeviceState(dev);
}
@@ -0,0 +1,166 @@
package com.limelight.binding.input.driver;
import android.hardware.usb.UsbConstants;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import com.limelight.LimeLog;
import com.limelight.nvstream.input.ControllerPacket;
import java.nio.ByteBuffer;
public class Xbox360Controller extends AbstractXboxController {
// This list is taken from the Xpad driver in the Linux kernel.
// I've excluded the devices that aren't "controllers" in the traditional sense, but
// if people really want to use their dancepads or fight sticks with Moonlight, I can
// put them in.
private static final DeviceIdTuple[] supportedDeviceTuples = {
new DeviceIdTuple(0x045e, 0x028e, "Microsoft X-Box 360 pad"),
new DeviceIdTuple(0x044f, 0xb326, "Thrustmaster Gamepad GP XID"),
new DeviceIdTuple(0x046d, 0xc21d, "Logitech Gamepad F310"),
new DeviceIdTuple(0x046d, 0xc21e, "Logitech Gamepad F510"),
new DeviceIdTuple(0x046d, 0xc21f, "Logitech Gamepad F710"),
new DeviceIdTuple(0x046d, 0xc242, "Logitech Chillstream Controller"),
new DeviceIdTuple(0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller"),
new DeviceIdTuple(0x0738, 0x4726, "Mad Catz Xbox 360 Controller"),
new DeviceIdTuple(0x0738, 0xb726, "Mad Catz Xbox controller - MW2"),
new DeviceIdTuple(0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad"),
new DeviceIdTuple(0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360"),
new DeviceIdTuple(0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0113, "Afterglow AX.1 Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller"),
new DeviceIdTuple(0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360"),
new DeviceIdTuple(0x0e6f, 0x0301, "Logic3 Controller"),
new DeviceIdTuple(0x0e6f, 0x0401, "Logic3 Controller"),
new DeviceIdTuple(0x12ab, 0x0301, "PDP AFTERGLOW AX.1"),
new DeviceIdTuple(0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller"),
new DeviceIdTuple(0x1532, 0x0037, "Razer Sabertooth"),
new DeviceIdTuple(0x15e4, 0x3f00, "Power A Mini Pro Elite"),
new DeviceIdTuple(0x15e4, 0x3f0a, "Xbox Airflo wired controller"),
new DeviceIdTuple(0x15e4, 0x3f10, "Batarang Xbox 360 controller"),
new DeviceIdTuple(0x162e, 0xbeef, "Joytech Neo-Se Take2"),
new DeviceIdTuple(0x1689, 0xfd00, "Razer Onza Tournament Edition"),
new DeviceIdTuple(0x1689, 0xfd01, "Razer Onza Classic Edition"),
new DeviceIdTuple(0x24c6, 0x5d04, "Razer Sabertooth"),
new DeviceIdTuple(0x1bad, 0xf016, "Mad Catz Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)"),
new DeviceIdTuple(0x1bad, 0xf900, "Harmonix Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf901, "Gamestop Xbox 360 Controller"),
new DeviceIdTuple(0x1bad, 0xf903, "Tron Xbox 360 controller"),
new DeviceIdTuple(0x24c6, 0x5300, "PowerA MINI PROEX Controller"),
new DeviceIdTuple(0x24c6, 0x5303, "Xbox Airflo wired controller"),
};
public static boolean canClaimDevice(UsbDevice device) {
for (DeviceIdTuple tuple : supportedDeviceTuples) {
if (device.getVendorId() == tuple.vid && device.getProductId() == tuple.pid) {
LimeLog.info("XB360 can claim device: " + tuple.name);
return true;
}
}
return false;
}
public Xbox360Controller(UsbDevice device, UsbDeviceConnection connection, int deviceId, UsbDriverListener listener) {
super(device, connection, deviceId, listener);
}
private int unsignByte(byte b) {
if (b < 0) {
return b + 256;
}
else {
return b;
}
}
@Override
protected boolean handleRead(ByteBuffer buffer) {
if (buffer.limit() < 14) {
LimeLog.severe("Read too small: "+buffer.limit());
return false;
}
// Skip first short
buffer.position(buffer.position() + 2);
// DPAD
byte b = buffer.get();
setButtonFlag(ControllerPacket.LEFT_FLAG, b & 0x04);
setButtonFlag(ControllerPacket.RIGHT_FLAG, b & 0x08);
setButtonFlag(ControllerPacket.UP_FLAG, b & 0x01);
setButtonFlag(ControllerPacket.DOWN_FLAG, b & 0x02);
// Start/Select
setButtonFlag(ControllerPacket.PLAY_FLAG, b & 0x10);
setButtonFlag(ControllerPacket.BACK_FLAG, b & 0x20);
// LS/RS
setButtonFlag(ControllerPacket.LS_CLK_FLAG, b & 0x40);
setButtonFlag(ControllerPacket.RS_CLK_FLAG, b & 0x80);
// ABXY buttons
b = buffer.get();
setButtonFlag(ControllerPacket.A_FLAG, b & 0x10);
setButtonFlag(ControllerPacket.B_FLAG, b & 0x20);
setButtonFlag(ControllerPacket.X_FLAG, b & 0x40);
setButtonFlag(ControllerPacket.Y_FLAG, b & 0x80);
// LB/RB
setButtonFlag(ControllerPacket.LB_FLAG, b & 0x01);
setButtonFlag(ControllerPacket.RB_FLAG, b & 0x02);
// Xbox button
setButtonFlag(ControllerPacket.SPECIAL_BUTTON_FLAG, b & 0x04);
// Triggers
leftTrigger = unsignByte(buffer.get()) / 255.0f;
rightTrigger = unsignByte(buffer.get()) / 255.0f;
// Left stick
leftStickX = buffer.getShort() / 32767.0f;
leftStickY = ~buffer.getShort() / 32767.0f;
// Right stick
rightStickX = buffer.getShort() / 32767.0f;
rightStickY = ~buffer.getShort() / 32767.0f;
// Return true to send input
return true;
}
private boolean sendLedCommand(byte command) {
byte[] commandBuffer = {0x01, 0x03, command};
int res = connection.bulkTransfer(outEndpt, commandBuffer, commandBuffer.length, 3000);
if (res != commandBuffer.length) {
LimeLog.warning("LED set transfer failed: "+res);
return false;
}
return true;
}
@Override
protected boolean doInit() {
// Turn the LED on corresponding to our device ID
sendLedCommand((byte)(2 + (getControllerId() % 4)));
// No need to fail init if the LED command fails
return true;
}
private static class DeviceIdTuple {
public final int vid;
public final int pid;
public final String name;
public DeviceIdTuple(int vid, int pid, String name) {
this.vid = vid;
this.pid = pid;
this.name = name;
}
}
}
@@ -13,19 +13,7 @@ import com.limelight.nvstream.input.ControllerPacket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class XboxOneController {
private final UsbDevice device;
private final UsbDeviceConnection connection;
private final int deviceId;
private Thread inputThread;
private UsbDriverListener listener;
private boolean stopped;
private short buttonFlags;
private float leftTrigger, rightTrigger;
private float rightStickX, rightStickY;
private float leftStickX, leftStickY;
public class XboxOneController extends AbstractXboxController {
private static final int MICROSOFT_VID = 0x045e;
private static final int XB1_IFACE_SUBCLASS = 71;
@@ -35,28 +23,7 @@ public class XboxOneController {
private static final byte[] XB1_INIT_DATA = {0x05, 0x20, 0x00, 0x01, 0x00};
public XboxOneController(UsbDevice device, UsbDeviceConnection connection, int deviceId, UsbDriverListener listener) {
this.device = device;
this.connection = connection;
this.deviceId = deviceId;
this.listener = listener;
}
public int getControllerId() {
return this.deviceId;
}
private void setButtonFlag(int buttonFlag, int data) {
if (data != 0) {
buttonFlags |= buttonFlag;
}
else {
buttonFlags &= ~buttonFlag;
}
}
private void reportInput() {
listener.reportControllerState(deviceId, buttonFlags, leftStickX, leftStickY,
rightStickX, rightStickY, leftTrigger, rightTrigger);
super(device, connection, deviceId, listener);
}
private void processButtons(ByteBuffer buffer) {
@@ -90,137 +57,24 @@ public class XboxOneController {
rightStickX = buffer.getShort() / 32767.0f;
rightStickY = ~buffer.getShort() / 32767.0f;
reportInput();
}
private void processPacket(ByteBuffer buffer) {
@Override
protected boolean handleRead(ByteBuffer buffer) {
switch (buffer.get())
{
case 0x20:
buffer.position(buffer.position()+3);
processButtons(buffer);
break;
return true;
case 0x07:
buffer.position(buffer.position() + 3);
setButtonFlag(ControllerPacket.SPECIAL_BUTTON_FLAG, buffer.get() & 0x01);
reportInput();
break;
}
}
private void startInputThread(final UsbEndpoint inEndpt) {
inputThread = new Thread() {
public void run() {
while (!isInterrupted() && !stopped) {
byte[] buffer = new byte[64];
int res;
//
// There's no way that I can tell to determine if a device has failed
// or if the timeout has simply expired. We'll check how long the transfer
// took to fail and assume the device failed if it happened before the timeout
// expired.
//
do {
// Read the next input state packet
long lastMillis = MediaCodecHelper.getMonotonicMillis();
res = connection.bulkTransfer(inEndpt, buffer, buffer.length, 3000);
if (res == -1 && MediaCodecHelper.getMonotonicMillis() - lastMillis < 1000) {
LimeLog.warning("Detected device I/O error");
XboxOneController.this.stop();
break;
}
} while (res == -1 && !isInterrupted() && !stopped);
if (res == -1 || stopped) {
break;
}
processPacket(ByteBuffer.wrap(buffer, 0, res).order(ByteOrder.LITTLE_ENDIAN));
}
}
};
inputThread.setName("Xbox One Controller - Input Thread");
inputThread.start();
}
public boolean start() {
// Force claim all interfaces
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface iface = device.getInterface(i);
if (!connection.claimInterface(iface, true)) {
LimeLog.warning("Failed to claim interfaces");
return false;
}
return true;
}
// Find the endpoints
UsbEndpoint outEndpt = null;
UsbEndpoint inEndpt = null;
UsbInterface iface = device.getInterface(0);
for (int i = 0; i < iface.getEndpointCount(); i++) {
UsbEndpoint endpt = iface.getEndpoint(i);
if (endpt.getDirection() == UsbConstants.USB_DIR_IN) {
if (inEndpt != null) {
LimeLog.warning("Found duplicate IN endpoint");
return false;
}
inEndpt = endpt;
}
else if (endpt.getDirection() == UsbConstants.USB_DIR_OUT) {
if (outEndpt != null) {
LimeLog.warning("Found duplicate OUT endpoint");
return false;
}
outEndpt = endpt;
}
}
// Make sure the required endpoints were present
if (inEndpt == null || outEndpt == null) {
LimeLog.warning("Missing required endpoint");
return false;
}
// Send the initialization packet
int res = connection.bulkTransfer(outEndpt, XB1_INIT_DATA, XB1_INIT_DATA.length, 3000);
if (res != XB1_INIT_DATA.length) {
LimeLog.warning("Initialization transfer failed: "+res);
return false;
}
// Start listening for controller input
startInputThread(inEndpt);
// Report this device added via the listener
listener.deviceAdded(deviceId);
return true;
}
public void stop() {
if (stopped) {
return;
}
stopped = true;
// Stop the input thread
if (inputThread != null) {
inputThread.interrupt();
inputThread = null;
}
// Report the device removed
listener.deviceRemoved(deviceId);
// Close the USB connection
connection.close();
return false;
}
public static boolean canClaimDevice(UsbDevice device) {
@@ -230,4 +84,16 @@ public class XboxOneController {
device.getInterface(0).getInterfaceSubclass() == XB1_IFACE_SUBCLASS &&
device.getInterface(0).getInterfaceProtocol() == XB1_IFACE_PROTOCOL;
}
@Override
protected boolean doInit() {
// Send the initialization packet
int res = connection.bulkTransfer(outEndpt, XB1_INIT_DATA, XB1_INIT_DATA.length, 3000);
if (res != XB1_INIT_DATA.length) {
LimeLog.warning("Initialization transfer failed: "+res);
return false;
}
return true;
}
}
@@ -33,7 +33,12 @@ public class AnalogStick extends VirtualControllerElement {
/**
* time frame for a double click
*/
public final static long timeoutDoubleClick = 250;
public final static long timeoutDoubleClick = 350;
/**
* touch down time until the deadzone is lifted to allow precise movements with the analog sticks
*/
public final static long timeoutDeadzone = 150;
/**
* Listener interface to update registered observers.
@@ -125,14 +130,6 @@ public class AnalogStick extends VirtualControllerElement {
private long timeLastClick = 0;
private static double getMovementRadius(float x, float y) {
// corner cases
if (x == 0) {
return y > 0 ? y : -y;
}
if (y == 0) {
return x > 0 ? x : -x;
}
// return hypotenuse (pythagoras)
return Math.sqrt(x * x + y * y);
}
@@ -210,11 +207,6 @@ public class AnalogStick extends VirtualControllerElement {
}
}
public void setColors(int normalColor, int pressedColor) {
this.normalColor = normalColor;
this.pressedColor = pressedColor;
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
// calculate new radius sizes depending
@@ -231,33 +223,28 @@ public class AnalogStick extends VirtualControllerElement {
canvas.drawColor(Color.TRANSPARENT);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(getPercent(getCorrectWidth() / 2, 2));
paint.setStrokeWidth(getDefaultStrokeWidth());
// draw outer circle
if (!isPressed() || click_state == CLICK_STATE.SINGLE) {
paint.setColor(normalColor);
paint.setColor(getDefaultColor());
} else {
paint.setColor(pressedColor);
}
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_complete, paint);
paint.setColor(normalColor);
paint.setColor(getDefaultColor());
// draw dead zone
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_dead_zone, paint);
// draw stick depending on state
switch (stick_state) {
case NO_MOVEMENT: {
paint.setColor(normalColor);
paint.setColor(getDefaultColor());
canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius_analog_stick, paint);
break;
}
case MOVED_IN_DEAD_ZONE: {
paint.setColor(normalColor);
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
break;
}
case MOVED_IN_DEAD_ZONE:
case MOVED_ACTIVE: {
paint.setColor(pressedColor);
canvas.drawCircle(position_stick_x, position_stick_y, radius_analog_stick, paint);
@@ -268,7 +255,7 @@ public class AnalogStick extends VirtualControllerElement {
private void updatePosition() {
// get 100% way
float complete = (radius_complete - radius_analog_stick - radius_dead_zone);
float complete = radius_complete - radius_analog_stick;
// calculate relative way
float correlated_y = (float) (Math.sin(Math.PI / 2 - movement_angle) * (movement_radius));
@@ -278,15 +265,18 @@ public class AnalogStick extends VirtualControllerElement {
position_stick_x = getWidth() / 2 - correlated_x;
position_stick_y = getHeight() / 2 - correlated_y;
// set active depending on dead zone
stick_state = movement_radius > radius_dead_zone ?
// Stay active even if we're back in the deadzone because we know the user is actively
// giving analog stick input and we don't want to snap back into the deadzone.
// We also release the deadzone if the user keeps the stick pressed for a bit to allow
// them to make precise movements.
stick_state = (stick_state == STICK_STATE.MOVED_ACTIVE ||
System.currentTimeMillis() - timeLastClick > timeoutDeadzone ||
movement_radius > radius_dead_zone) ?
STICK_STATE.MOVED_ACTIVE : STICK_STATE.MOVED_IN_DEAD_ZONE;
// trigger move event if state active
if (stick_state == STICK_STATE.MOVED_ACTIVE) {
notifyOnMovement(-(1 / complete) *
(correlated_x - (correlated_x > 0 ? radius_dead_zone : -radius_dead_zone)), (1 / complete) *
(correlated_y - (correlated_y > 0 ? radius_dead_zone : -radius_dead_zone)));
notifyOnMovement(-correlated_x / complete, correlated_y / complete);
}
}
@@ -144,13 +144,14 @@ public class DigitalButton extends VirtualControllerElement {
// set transparent background
canvas.drawColor(Color.TRANSPARENT);
paint.setTextSize(getPercent(getCorrectWidth(), 50));
paint.setTextSize(getPercent(getWidth(), 30));
paint.setTextAlign(Paint.Align.CENTER);
paint.setStrokeWidth(3);
paint.setStrokeWidth(getDefaultStrokeWidth());
paint.setColor(isPressed() ? pressedColor : normalColor);
paint.setColor(isPressed() ? pressedColor : getDefaultColor());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(1, 1, getWidth() - 1, getHeight() - 1, paint);
canvas.drawRect(paint.getStrokeWidth(), paint.getStrokeWidth(),
getWidth() - paint.getStrokeWidth(), getHeight() - paint.getStrokeWidth(), paint);
if (icon != -1) {
Drawable d = getResources().getDrawable(icon);
@@ -158,7 +159,8 @@ public class DigitalButton extends VirtualControllerElement {
d.draw(canvas);
} else {
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawText(text, getPercent(getWidth(), 50), getPercent(getHeight(), 73), paint);
paint.setStrokeWidth(getDefaultStrokeWidth()/2);
canvas.drawText(text, getPercent(getWidth(), 50), getPercent(getHeight(), 63), paint);
}
}
@@ -22,6 +22,8 @@ public class DigitalPad extends VirtualControllerElement {
public final static int DIGITAL_PAD_DIRECTION_DOWN = 8;
List<DigitalPadListener> listeners = new ArrayList<DigitalPadListener>();
private static final int DPAD_MARGIN = 5;
private final Paint paint = new Paint();
public DigitalPad(VirtualController controller, Context context) {
@@ -39,12 +41,12 @@ public class DigitalPad extends VirtualControllerElement {
paint.setTextSize(getPercent(getCorrectWidth(), 20));
paint.setTextAlign(Paint.Align.CENTER);
paint.setStrokeWidth(3);
paint.setStrokeWidth(getDefaultStrokeWidth());
if (direction == DIGITAL_PAD_DIRECTION_NO_DIRECTION) {
// draw no direction rect
paint.setStyle(Paint.Style.STROKE);
paint.setColor(normalColor);
paint.setColor(getDefaultColor());
canvas.drawRect(
getPercent(getWidth(), 36), getPercent(getHeight(), 36),
getPercent(getWidth(), 63), getPercent(getHeight(), 63),
@@ -54,34 +56,55 @@ public class DigitalPad extends VirtualControllerElement {
// draw left rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 ? pressedColor : normalColor);
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 ? pressedColor : getDefaultColor());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
0, getPercent(getHeight(), 33),
paint.getStrokeWidth()+DPAD_MARGIN, getPercent(getHeight(), 33),
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
paint
);
// draw up rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 ? pressedColor : getDefaultColor());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 33), paint.getStrokeWidth()+DPAD_MARGIN,
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
paint
);
// draw right rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 ? pressedColor : getDefaultColor());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
getWidth() - (paint.getStrokeWidth()+DPAD_MARGIN), getPercent(getHeight(), 66),
paint
);
// draw down rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 ? pressedColor : getDefaultColor());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
getPercent(getWidth(), 66), getHeight() - (paint.getStrokeWidth()+DPAD_MARGIN),
paint
);
// draw left up line
paint.setColor((
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0 &&
(direction & DIGITAL_PAD_DIRECTION_UP) > 0
) ? pressedColor : normalColor
) ? pressedColor : getDefaultColor()
);
paint.setStyle(Paint.Style.STROKE);
canvas.drawLine(
0, getPercent(getHeight(), 33),
getPercent(getWidth(), 33), 0,
paint
);
// draw up rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 ? pressedColor : normalColor);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 33), 0,
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
paint.getStrokeWidth()+DPAD_MARGIN, getPercent(getHeight(), 33),
getPercent(getWidth(), 33), paint.getStrokeWidth()+DPAD_MARGIN,
paint
);
@@ -89,22 +112,12 @@ public class DigitalPad extends VirtualControllerElement {
paint.setColor((
(direction & DIGITAL_PAD_DIRECTION_UP) > 0 &&
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0
) ? pressedColor : normalColor
) ? pressedColor : getDefaultColor()
);
paint.setStyle(Paint.Style.STROKE);
canvas.drawLine(
getPercent(getWidth(), 66), 0,
getPercent(getWidth(), 100), getPercent(getHeight(), 33),
paint
);
// draw right rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 ? pressedColor : normalColor);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 66), getPercent(getHeight(), 33),
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
getPercent(getWidth(), 66), paint.getStrokeWidth()+DPAD_MARGIN,
getWidth() - (paint.getStrokeWidth()+DPAD_MARGIN), getPercent(getHeight(), 33),
paint
);
@@ -112,22 +125,12 @@ public class DigitalPad extends VirtualControllerElement {
paint.setColor((
(direction & DIGITAL_PAD_DIRECTION_RIGHT) > 0 &&
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0
) ? pressedColor : normalColor
) ? pressedColor : getDefaultColor()
);
paint.setStyle(Paint.Style.STROKE);
canvas.drawLine(
getPercent(getWidth(), 100), getPercent(getHeight(), 66),
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
paint
);
// draw down rect
paint.setColor(
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 ? pressedColor : normalColor);
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(
getPercent(getWidth(), 33), getPercent(getHeight(), 66),
getPercent(getWidth(), 66), getPercent(getHeight(), 100),
getWidth()-paint.getStrokeWidth(), getPercent(getHeight(), 66),
getPercent(getWidth(), 66), getHeight()-(paint.getStrokeWidth()+DPAD_MARGIN),
paint
);
@@ -135,12 +138,12 @@ public class DigitalPad extends VirtualControllerElement {
paint.setColor((
(direction & DIGITAL_PAD_DIRECTION_DOWN) > 0 &&
(direction & DIGITAL_PAD_DIRECTION_LEFT) > 0
) ? pressedColor : normalColor
) ? pressedColor : getDefaultColor()
);
paint.setStyle(Paint.Style.STROKE);
canvas.drawLine(
getPercent(getWidth(), 33), getPercent(getHeight(), 100),
getPercent(getWidth(), 0), getPercent(getHeight(), 66),
getPercent(getWidth(), 33), getHeight()-(paint.getStrokeWidth()+DPAD_MARGIN),
paint.getStrokeWidth()+DPAD_MARGIN, getPercent(getHeight(), 66),
paint
);
}
@@ -5,6 +5,7 @@
package com.limelight.binding.input.virtual_controller;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
@@ -33,7 +34,7 @@ public class VirtualController {
Configuration
}
private static final boolean _PRINT_DEBUG_INFORMATION = true;
private static final boolean _PRINT_DEBUG_INFORMATION = false;
private NvConnection connection = null;
private Context context = null;
@@ -63,14 +64,23 @@ public class VirtualController {
buttonConfigure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String message;
if (currentMode == ControllerMode.Configuration) {
currentMode = ControllerMode.Active;
message = "Exiting configuration mode";
} else {
currentMode = ControllerMode.Configuration;
message = "Entering configuration mode";
}
Toast.makeText(context, "CHANGE MODE " + currentMode, Toast.LENGTH_SHORT).show();
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
relative_layout.invalidate();
for (VirtualControllerElement element : elements) {
element.invalidate();
}
}
});
}
@@ -104,7 +114,10 @@ public class VirtualController {
relative_layout.removeAllViews();
removeElements();
layoutParamsButtonConfigure = new RelativeLayout.LayoutParams(50, 50);
DisplayMetrics screen = context.getResources().getDisplayMetrics();
int buttonSize = (int)(screen.heightPixels*0.05f);
layoutParamsButtonConfigure = new RelativeLayout.LayoutParams(buttonSize, buttonSize);
relative_layout.addView(buttonConfigure, layoutParamsButtonConfigure);
VirtualControllerConfigurationLoader.createDefaultLayout(this, context);
@@ -138,79 +138,87 @@ public class VirtualControllerConfigurationLoader {
return new RightAnalogStick(controller, context);
}
private static final int BUTTON_BASE_X = 65;
private static final int BUTTON_BASE_Y = 5;
private static final int BUTTON_WIDTH = getPercent(30, 33);
private static final int BUTTON_HEIGHT = getPercent(40, 33);
public static void createDefaultLayout(final VirtualController controller, final Context context) {
DisplayMetrics screen = context.getResources().getDisplayMetrics();
// NOTE: Some of these getPercent() expressions seem like they can be combined
// into a single call. Due to floating point rounding, this isn't actually possible.
controller.addElement(createDigitalPad(controller, context),
getPercent(5, screen.widthPixels),
getPercent(10, screen.heightPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels),
getPercent(30, screen.widthPixels),
getPercent(40, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.A_FLAG, 0, 1, "A", -1, controller, context),
getPercent(75, screen.widthPixels),
getPercent(40, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels)+getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels)+2*getPercent(BUTTON_HEIGHT, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.B_FLAG, 0, 1, "B", -1, controller, context),
getPercent(85, screen.widthPixels),
getPercent(30, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels)+2*getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels)+getPercent(BUTTON_HEIGHT, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.X_FLAG, 0, 1, "X", -1, controller, context),
getPercent(65, screen.widthPixels),
getPercent(30, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels)+getPercent(BUTTON_HEIGHT, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.Y_FLAG, 0, 1, "Y", -1, controller, context),
getPercent(75, screen.widthPixels),
getPercent(20, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels)+getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createLeftTrigger(
0, "LT", -1, controller, context),
getPercent(65, screen.widthPixels),
getPercent(20, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
0, "LT", -1, controller, context),
getPercent(BUTTON_BASE_X, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createRightTrigger(
0, "RT", -1, controller, context),
getPercent(85, screen.widthPixels),
getPercent(20, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels)+2*getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.LB_FLAG, 0, 1, "LB", -1, controller, context),
getPercent(65, screen.widthPixels),
getPercent(40, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels)+2*getPercent(BUTTON_HEIGHT, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createDigitalButton(
ControllerPacket.RB_FLAG, 0, 1, "RB", -1, controller, context),
getPercent(85, screen.widthPixels),
getPercent(40, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
getPercent(BUTTON_BASE_X, screen.widthPixels)+2*getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_BASE_Y, screen.heightPixels)+2*getPercent(BUTTON_HEIGHT, screen.heightPixels),
getPercent(BUTTON_WIDTH, screen.widthPixels),
getPercent(BUTTON_HEIGHT, screen.heightPixels)
);
controller.addElement(createLeftStick(controller, context),
@@ -228,7 +236,7 @@ public class VirtualControllerConfigurationLoader {
);
controller.addElement(createDigitalButton(
ControllerPacket.BACK_FLAG, 0, 2, "SELECT", -1, controller, context),
ControllerPacket.BACK_FLAG, 0, 2, "BACK", -1, controller, context),
getPercent(40, screen.widthPixels),
getPercent(90, screen.heightPixels),
getPercent(10, screen.widthPixels),
@@ -237,7 +245,7 @@ public class VirtualControllerConfigurationLoader {
controller.addElement(createDigitalButton(
ControllerPacket.PLAY_FLAG, 0, 3, "START", -1, controller, context),
getPercent(50, screen.widthPixels),
getPercent(40, screen.widthPixels)+getPercent(10, screen.widthPixels),
getPercent(90, screen.heightPixels),
getPercent(10, screen.widthPixels),
getPercent(10, screen.heightPixels)
@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
@@ -20,8 +21,10 @@ public abstract class VirtualControllerElement extends View {
private final Paint paint = new Paint();
protected int normalColor = 0xF0888888;
private int normalColor = 0xF0888888;
protected int pressedColor = 0xF00000FF;
private int configNormalColor = 0xF0FF0000;
private int configSelectedColor = 0xF000FF00;
protected int startSize_x;
protected int startSize_y;
@@ -71,19 +74,18 @@ public abstract class VirtualControllerElement extends View {
@Override
protected void onDraw(Canvas canvas) {
if (virtualController.getControllerMode() == VirtualController.ControllerMode.
Configuration) {
paint.setColor(pressedColor);
paint.setStrokeWidth(3);
onElementDraw(canvas);
if (currentMode != Mode.Normal) {
paint.setColor(configSelectedColor);
paint.setStrokeWidth(getDefaultStrokeWidth());
paint.setStyle(Paint.Style.STROKE);
canvas.drawRect(0, 0,
getWidth(), getHeight(),
canvas.drawRect(paint.getStrokeWidth(), paint.getStrokeWidth(),
getWidth()-paint.getStrokeWidth(), getHeight()-paint.getStrokeWidth(),
paint);
}
onElementDraw(canvas);
super.onDraw(canvas);
}
@@ -132,6 +134,16 @@ public abstract class VirtualControllerElement extends View {
invalidate();
}
protected int getDefaultColor() {
return (virtualController.getControllerMode() == VirtualController.ControllerMode.Configuration) ?
configNormalColor : normalColor;
}
protected int getDefaultStrokeWidth() {
DisplayMetrics screen = getResources().getDisplayMetrics();
return (int)(screen.heightPixels*0.004f);
}
protected void showConfigurationDialog() {
try {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getContext());
@@ -201,6 +213,8 @@ public abstract class VirtualControllerElement extends View {
startSize_x = getWidth();
startSize_y = getHeight();
actionEnableMove();
return true;
}
case MotionEvent.ACTION_MOVE: {
@@ -230,8 +244,7 @@ public abstract class VirtualControllerElement extends View {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP: {
currentMode = Mode.Normal;
showConfigurationDialog();
actionCancel();
return true;
}
default: {
@@ -109,6 +109,20 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
else {
LimeLog.info("No HEVC decoder found");
}
// Set attributes that are queried in getCapabilities(). This must be done here
// because getCapabilities() may be called before setup() in current versions of the common
// library. The limitation of this is that we don't know whether we're using HEVC or AVC, so
// we just assume AVC. This isn't really a problem because the capabilities are usually
// shared between AVC and HEVC decoders on the same device.
if (avcDecoderName != null) {
directSubmit = MediaCodecHelper.decoderCanDirectSubmit(avcDecoderName);
adaptivePlayback = MediaCodecHelper.decoderSupportsAdaptivePlayback(avcDecoderName);
if (directSubmit) {
LimeLog.info("Decoder "+avcDecoderName+" will use direct submit");
}
}
}
@Override
@@ -171,14 +185,6 @@ public class MediaCodecDecoderRenderer extends EnhancedDecoderRenderer {
return false;
}
// Set decoder-specific attributes
directSubmit = MediaCodecHelper.decoderCanDirectSubmit(selectedDecoderName);
adaptivePlayback = MediaCodecHelper.decoderSupportsAdaptivePlayback(selectedDecoderName);
if (directSubmit) {
LimeLog.info("Decoder "+selectedDecoderName+" will use direct submit");
}
// Codecs have been known to throw all sorts of crazy runtime exceptions
// due to implementation problems
try {
@@ -37,6 +37,7 @@ public class ComputerManagerService extends Service {
private static final int MDNS_QUERY_PERIOD_MS = 1000;
private static final int FAST_POLL_TIMEOUT = 500;
private static final int OFFLINE_POLL_TRIES = 5;
private static final int EMPTY_LIST_THRESHOLD = 3;
private final ComputerManagerBinder binder = new ComputerManagerBinder();
@@ -232,8 +233,10 @@ public class ComputerManagerService extends Service {
@Override
public boolean onUnbind(Intent intent) {
// Stop mDNS autodiscovery
discoveryBinder.stopDiscovery();
if (discoveryBinder != null) {
// Stop mDNS autodiscovery
discoveryBinder.stopDiscovery();
}
// Stop polling
pollingActive = false;
@@ -661,6 +664,7 @@ public class ComputerManagerService extends Service {
thread = new Thread() {
@Override
public void run() {
int emptyAppListResponses = 0;
do {
InetAddress selectedAddr;
@@ -705,7 +709,15 @@ public class ComputerManagerService extends Service {
}
List<NvApp> list = NvHTTP.getAppListByReader(new StringReader(appList));
if (appList != null && !appList.isEmpty() && !list.isEmpty()) {
if (list.isEmpty()) {
LimeLog.warning("Empty app list received from "+computer.uuid);
// The app list might actually be empty, so if we get an empty response a few times
// in a row, we'll go ahead and believe it.
emptyAppListResponses++;
}
if (appList != null && !appList.isEmpty() &&
(!list.isEmpty() || emptyAppListResponses >= EMPTY_LIST_THRESHOLD)) {
// Open the cache file
OutputStream cacheOut = null;
try {
@@ -721,6 +733,11 @@ public class ComputerManagerService extends Service {
} catch (IOException ignored) {}
}
// Reset empty count if it wasn't empty this time
if (!list.isEmpty()) {
emptyAppListResponses = 0;
}
// Update the computer
computer.rawAppList = appList;
receivedAppList = true;
@@ -731,8 +748,8 @@ public class ComputerManagerService extends Service {
listener.notifyComputerUpdated(computer);
}
}
else {
LimeLog.warning("Empty app list received from "+computer.uuid);
else if (appList == null || appList.isEmpty()) {
LimeLog.warning("Null app list received from "+computer.uuid);
}
} catch (IOException e) {
e.printStackTrace();
@@ -21,7 +21,7 @@ public class PreferenceConfiguration {
private static final String ENABLE_51_SURROUND_PREF_STRING = "checkbox_51_surround";
private static final String USB_DRIVER_PREF_SRING = "checkbox_usb_driver";
private static final String VIDEO_FORMAT_PREF_STRING = "video_format";
private static final String ONSCREEN_CONTROLLER_PREF_STRING = "checkbox_onscreen_controller";
private static final String ONSCREEN_CONTROLLER_PREF_STRING = "checkbox_show_onscreen_controls";
private static final int BITRATE_DEFAULT_720_30 = 5;
private static final int BITRATE_DEFAULT_720_60 = 10;
@@ -2,12 +2,15 @@ package com.limelight.preferences;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.os.Bundle;
import android.app.Activity;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import com.limelight.PcView;
import com.limelight.R;
@@ -60,6 +63,15 @@ public class StreamSettings extends Activity {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
PreferenceScreen screen = getPreferenceScreen();
// hide on-screen controls category on non touch screen devices
if (!getActivity().getPackageManager().
hasSystemFeature("android.hardware.touchscreen")) {
PreferenceCategory category =
(PreferenceCategory) findPreference("category_onscreen_controls");
screen.removePreference(category);
}
// Add a listener to the FPS and resolution preference
// so the bitrate can be auto-adjusted
+25
View File
@@ -0,0 +1,25 @@
# Android.mk for Moonlight's ENet JNI binding
MY_LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
LOCAL_PATH := $(MY_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := jnienet
LOCAL_SRC_FILES := jnienet.c \
enet/callbacks.c \
enet/compress.c \
enet/host.c \
enet/list.c \
enet/packet.c \
enet/peer.c \
enet/protocol.c \
enet/unix.c \
enet/win32.c \
LOCAL_CFLAGS := -DHAS_SOCKLEN_T=1
LOCAL_C_INCLUDES := $(LOCAL_PATH)/enet/include
include $(BUILD_SHARED_LIBRARY)
+148
View File
@@ -0,0 +1,148 @@
#include "enet/enet.h"
#include <stdlib.h>
#include <string.h>
#include <jni.h>
#define CLIENT_TO_LONG(x) ((intptr_t)(x))
#define LONG_TO_CLIENT(x) ((ENetHost*)(intptr_t)(x))
#define PEER_TO_LONG(x) ((intptr_t)(x))
#define LONG_TO_PEER(x) ((ENetPeer*)(intptr_t)(x))
JNIEXPORT jint JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_initializeEnet(JNIEnv *env, jobject class) {
return enet_initialize();
}
JNIEXPORT jlong JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_createClient(JNIEnv *env, jobject class, jstring address) {
ENetAddress enetAddress;
const char *addrStr;
int err;
// Perform a lookup on the address to determine the address family
addrStr = (*env)->GetStringUTFChars(env, address, 0);
err = enet_address_set_host(&enetAddress, addrStr);
(*env)->ReleaseStringUTFChars(env, address, addrStr);
if (err < 0) {
return CLIENT_TO_LONG(NULL);
}
// Create a client that can use 1 outgoing connection and 1 channel
return CLIENT_TO_LONG(enet_host_create(enetAddress.address.ss_family, NULL, 1, 1, 0, 0));
}
JNIEXPORT jlong JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_connectToPeer(JNIEnv *env, jobject class, jlong client, jstring address, jint port, jint timeout) {
ENetPeer* peer;
ENetAddress enetAddress;
ENetEvent event;
const char *addrStr;
int err;
// Initialize the ENet address
addrStr = (*env)->GetStringUTFChars(env, address, 0);
err = enet_address_set_host(&enetAddress, addrStr);
enet_address_set_port(&enetAddress, port);
(*env)->ReleaseStringUTFChars(env, address, addrStr);
if (err < 0) {
return PEER_TO_LONG(NULL);
}
// Start the connection
peer = enet_host_connect(LONG_TO_CLIENT(client), &enetAddress, 1, 0);
if (peer == NULL) {
return PEER_TO_LONG(NULL);
}
// Wait for the connect to complete
if (enet_host_service(LONG_TO_CLIENT(client), &event, timeout) <= 0 || event.type != ENET_EVENT_TYPE_CONNECT) {
enet_peer_reset(peer);
return PEER_TO_LONG(NULL);
}
// Ensure the connect verify ACK is sent immediately
enet_host_flush(LONG_TO_CLIENT(client));
// Set the max peer timeout to 10 seconds
enet_peer_timeout(peer, ENET_PEER_TIMEOUT_LIMIT, ENET_PEER_TIMEOUT_MINIMUM, 10000);
return PEER_TO_LONG(peer);
}
JNIEXPORT jint JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_readPacket(JNIEnv *env, jobject class, jlong client, jbyteArray data, jint length, jint timeout) {
jint err;
jbyte* dataPtr;
ENetEvent event;
// Wait for a receive event, timeout, or disconnect
err = enet_host_service(LONG_TO_CLIENT(client), &event, timeout);
if (err <= 0) {
return err;
}
else if (event.type != ENET_EVENT_TYPE_RECEIVE) {
return -1;
}
// Check that the packet isn't too large
if (event.packet->dataLength > length) {
enet_packet_destroy(event.packet);
return event.packet->dataLength;
}
// Copy the packet data into the caller's buffer
dataPtr = (*env)->GetByteArrayElements(env, data, 0);
memcpy(dataPtr, event.packet->data, event.packet->dataLength);
err = event.packet->dataLength;
(*env)->ReleaseByteArrayElements(env, data, dataPtr, 0);
// Free the packet
enet_packet_destroy(event.packet);
return err;
}
JNIEXPORT jboolean JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_writePacket(JNIEnv *env, jobject class, jlong client, jlong peer, jbyteArray data, jint length, jint packetFlags) {
ENetPacket* packet;
jboolean ret;
jbyte* dataPtr;
dataPtr = (*env)->GetByteArrayElements(env, data, 0);
// Create the reliable packet that describes our outgoing message
packet = enet_packet_create(dataPtr, length, packetFlags);
if (packet != NULL) {
// Send the message to the peer
if (enet_peer_send(LONG_TO_PEER(peer), 0, packet) < 0) {
// This can fail if the peer has been disconnected
enet_packet_destroy(packet);
ret = JNI_FALSE;
}
else {
// Force the client to send the packet now
enet_host_flush(LONG_TO_CLIENT(client));
ret = JNI_TRUE;
}
}
else {
ret = JNI_FALSE;
}
(*env)->ReleaseByteArrayElements(env, data, dataPtr, JNI_ABORT);
return ret;
}
JNIEXPORT void JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_destroyClient(JNIEnv *env, jobject class, jlong client) {
enet_host_destroy(LONG_TO_CLIENT(client));
}
JNIEXPORT void JNICALL
Java_com_limelight_nvstream_enet_EnetConnection_disconnectPeer(JNIEnv *env, jobject class, jlong peer) {
enet_peer_disconnect_now(LONG_TO_PEER(peer), 0);
}
@@ -1,144 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Load Configuration"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save Configuration"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Unlock layout"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Color 1"/>
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Color 2"/>
<ImageView
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="analog stick time out"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAlignment="center"
android:text="250ms"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
+6 -2
View File
@@ -103,8 +103,12 @@
<string name="summary_checkbox_multi_controller">When unchecked, all controllers appear as one</string>
<string name="title_seekbar_deadzone">Adjust analog stick deadzone</string>
<string name="suffix_seekbar_deadzone">%</string>
<string name="title_checkbox_xb1_driver">Xbox One controller driver</string>
<string name="summary_checkbox_xb1_driver">Enables a built-in USB driver for devices without native Xbox One controller support.</string>
<string name="title_checkbox_xb1_driver">Xbox 360/One controller driver</string>
<string name="summary_checkbox_xb1_driver">Enables a built-in USB driver for devices without native Xbox controller support.</string>
<string name="category_on_screen_controls_settings">On-screen Controls Settings</string>
<string name="title_checkbox_show_onscreen_controls">Show on-screen controls</string>
<string name="summary_checkbox_show_onscreen_controls">Show virtual controller overlay on touchscreen</string>
<string name="category_ui_settings">UI Settings</string>
<string name="title_language_list">Language</string>
+8 -5
View File
@@ -50,11 +50,14 @@
android:title="@string/title_checkbox_xb1_driver"
android:summary="@string/summary_checkbox_xb1_driver"
android:defaultValue="true" />
<!--CheckBoxPreference
android:key="checkbox_onscreen_controller"
android:title="On-screen controls"
android:summary="Show virtual controller overlay on touchscreen"
android:defaultValue="false"/-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/category_on_screen_controls_settings"
android:key="category_onscreen_controls">
<CheckBoxPreference
android:key="checkbox_show_onscreen_controls"
android:title="@string/title_checkbox_show_onscreen_controls"
android:summary="@string/summary_checkbox_show_onscreen_controls"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/category_host_settings">
<CheckBoxPreference
+1 -1
View File
@@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.1.0-alpha4'
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
#Sun Dec 07 22:52:07 PST 2014
#Sat Feb 06 16:21:20 EST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip