Commit of common limelight core with bindings based on HEAD of RenderScript-Renderer

This commit is contained in:
Cameron Gutman
2013-12-05 12:57:49 -05:00
parent 41d2f6b0e2
commit ce1494895e
29 changed files with 2560 additions and 0 deletions
@@ -0,0 +1,89 @@
package com.limelight.nvstream.input;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class ControllerPacket extends InputPacket {
public static final byte[] HEADER =
{
0x0A,
0x00,
0x00,
0x00,
0x00,
0x14
};
public static final byte[] TAIL =
{
(byte)0x9C,
0x00,
0x00,
0x00,
0x55,
0x00
};
public static final int PACKET_TYPE = 0x18;
public static final short A_FLAG = 0x1000;
public static final short B_FLAG = 0x2000;
public static final short X_FLAG = 0x4000;
public static final short Y_FLAG = (short)0x8000;
public static final short UP_FLAG = 0x0001;
public static final short DOWN_FLAG = 0x0002;
public static final short LEFT_FLAG = 0x0004;
public static final short RIGHT_FLAG = 0x0008;
public static final short LB_FLAG = 0x0100;
public static final short RB_FLAG = 0x0200;
public static final short PLAY_FLAG = 0x0010;
public static final short BACK_FLAG = 0x0020;
public static final short LS_CLK_FLAG = 0x0040;
public static final short RS_CLK_FLAG = 0x0080;
public static final short SPECIAL_BUTTON_FLAG = 0x0400;
public static final short PAYLOAD_LENGTH = 24;
public static final short PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH;
private short buttonFlags;
private byte leftTrigger;
private byte rightTrigger;
private short leftStickX;
private short leftStickY;
private short rightStickX;
private short rightStickY;
public ControllerPacket(short buttonFlags, byte leftTrigger, byte rightTrigger,
short leftStickX, short leftStickY,
short rightStickX, short rightStickY)
{
super(PACKET_TYPE);
this.buttonFlags = buttonFlags;
this.leftTrigger = leftTrigger;
this.rightTrigger = rightTrigger;
this.leftStickX = leftStickX;
this.leftStickY = leftStickY;
this.rightStickX = rightStickX;
this.rightStickY = rightStickY;
}
public byte[] toWire()
{
ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH).order(ByteOrder.LITTLE_ENDIAN);
bb.put(toWireHeader());
bb.put(HEADER);
bb.putShort(buttonFlags);
bb.put(leftTrigger);
bb.put(rightTrigger);
bb.putShort(leftStickX);
bb.putShort(leftStickY);
bb.putShort(rightStickX);
bb.putShort(rightStickY);
bb.put(TAIL);
return bb.array();
}
}
@@ -0,0 +1,26 @@
package com.limelight.nvstream.input;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public abstract class InputPacket {
public static final int HEADER_LENGTH = 0x4;
protected int packetType;
public InputPacket(int packetType)
{
this.packetType = packetType;
}
public abstract byte[] toWire();
public byte[] toWireHeader()
{
ByteBuffer bb = ByteBuffer.allocate(4).order(ByteOrder.BIG_ENDIAN);
bb.putInt(packetType);
return bb.array();
}
}
@@ -0,0 +1,36 @@
package com.limelight.nvstream.input;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class MouseButtonPacket extends InputPacket {
private byte buttonEventType;
public static final int PACKET_TYPE = 0x5;
public static final int PAYLOAD_LENGTH = 5;
public static final int PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH;
public static final byte PRESS_EVENT = 0x07;
public static final byte RELEASE_EVENT = 0x08;
public MouseButtonPacket(boolean leftButtonDown)
{
super(PACKET_TYPE);
buttonEventType = leftButtonDown ?
PRESS_EVENT : RELEASE_EVENT;
}
@Override
public byte[] toWire() {
ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH).order(ByteOrder.BIG_ENDIAN);
bb.put(toWireHeader());
bb.put(buttonEventType);
bb.putInt(1); // FIXME: button index?
return bb.array();
}
}
@@ -0,0 +1,42 @@
package com.limelight.nvstream.input;
import java.nio.ByteBuffer;
public class MouseMovePacket extends InputPacket {
private static final byte[] HEADER =
{
0x06,
0x00,
0x00,
0x00
};
public static final int PACKET_TYPE = 0x8;
public static final int PAYLOAD_LENGTH = 8;
public static final int PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH;
private short deltaX;
private short deltaY;
public MouseMovePacket(short deltaX, short deltaY)
{
super(PACKET_TYPE);
this.deltaX = deltaX;
this.deltaY = deltaY;
}
@Override
public byte[] toWire() {
ByteBuffer bb = ByteBuffer.allocate(PACKET_LENGTH);
bb.put(toWireHeader());
bb.put(HEADER);
bb.putShort(deltaX);
bb.putShort(deltaY);
return bb.array();
}
}
@@ -0,0 +1,65 @@
package com.limelight.nvstream.input;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
public class NvController {
public final static int PORT = 35043;
public final static int CONTROLLER_TIMEOUT = 3000;
private InetAddress host;
private Socket s;
private OutputStream out;
public NvController(InetAddress host)
{
this.host = host;
}
public void initialize() throws IOException
{
s = new Socket();
s.connect(new InetSocketAddress(host, PORT), CONTROLLER_TIMEOUT);
s.setTcpNoDelay(true);
out = s.getOutputStream();
}
public void close()
{
try {
s.close();
} catch (IOException e) {}
}
public void sendControllerInput(short buttonFlags, byte leftTrigger, byte rightTrigger,
short leftStickX, short leftStickY, short rightStickX, short rightStickY) throws IOException
{
out.write(new ControllerPacket(buttonFlags, leftTrigger,
rightTrigger, leftStickX, leftStickY,
rightStickX, rightStickY).toWire());
out.flush();
}
public void sendMouseButtonDown() throws IOException
{
out.write(new MouseButtonPacket(true).toWire());
out.flush();
}
public void sendMouseButtonUp() throws IOException
{
out.write(new MouseButtonPacket(false).toWire());
out.flush();
}
public void sendMouseMove(short deltaX, short deltaY) throws IOException
{
out.write(new MouseMovePacket(deltaX, deltaY).toWire());
out.flush();
}
}