mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 11:33:06 +00:00
Use a single byte buffer to serialize input packets
This commit is contained in:
parent
330f40cc18
commit
c9d003ca6d
@ -69,13 +69,9 @@ public class ControllerPacket extends InputPacket {
|
|||||||
this.rightStickY = rightStickY;
|
this.rightStickY = rightStickY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteOrder getPayloadByteOrder() {
|
|
||||||
return ByteOrder.LITTLE_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toWirePayload(ByteBuffer bb) {
|
public void toWirePayload(ByteBuffer bb) {
|
||||||
|
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
bb.put(HEADER);
|
bb.put(HEADER);
|
||||||
bb.putShort(buttonFlags);
|
bb.putShort(buttonFlags);
|
||||||
bb.put(leftTrigger);
|
bb.put(leftTrigger);
|
||||||
|
@ -35,8 +35,7 @@ public class ControllerStream {
|
|||||||
private Thread inputThread;
|
private Thread inputThread;
|
||||||
private LinkedBlockingQueue<InputPacket> inputQueue = new LinkedBlockingQueue<InputPacket>();
|
private LinkedBlockingQueue<InputPacket> inputQueue = new LinkedBlockingQueue<InputPacket>();
|
||||||
|
|
||||||
private ByteBuffer littleEndianBuffer = ByteBuffer.allocate(128).order(ByteOrder.LITTLE_ENDIAN);
|
private ByteBuffer stagingBuffer = ByteBuffer.allocate(128);
|
||||||
private ByteBuffer bigEndianBuffer = ByteBuffer.allocate(128).order(ByteOrder.BIG_ENDIAN);
|
|
||||||
private ByteBuffer sendBuffer = ByteBuffer.allocate(128).order(ByteOrder.BIG_ENDIAN);
|
private ByteBuffer sendBuffer = ByteBuffer.allocate(128).order(ByteOrder.BIG_ENDIAN);
|
||||||
|
|
||||||
public ControllerStream(InetAddress host, SecretKey riKey, int riKeyId, NvConnectionListener listener)
|
public ControllerStream(InetAddress host, SecretKey riKey, int riKeyId, NvConnectionListener listener)
|
||||||
@ -234,18 +233,8 @@ public class ControllerStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(InputPacket packet) throws IOException {
|
private void sendPacket(InputPacket packet) throws IOException {
|
||||||
ByteBuffer toWireBuffer;
|
|
||||||
|
|
||||||
// Choose which byte order we'll be using for converting to wire form
|
|
||||||
if (packet.getPayloadByteOrder() == ByteOrder.BIG_ENDIAN) {
|
|
||||||
toWireBuffer = bigEndianBuffer;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
toWireBuffer = littleEndianBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the packet in wire form in the byte buffer
|
// Store the packet in wire form in the byte buffer
|
||||||
packet.toWire(toWireBuffer);
|
packet.toWire(stagingBuffer);
|
||||||
int packetLen = packet.getPacketLength();
|
int packetLen = packet.getPacketLength();
|
||||||
|
|
||||||
// Pad to 16 byte chunks
|
// Pad to 16 byte chunks
|
||||||
@ -255,7 +244,7 @@ public class ControllerStream {
|
|||||||
sendBuffer.rewind();
|
sendBuffer.rewind();
|
||||||
sendBuffer.putInt(paddedLength);
|
sendBuffer.putInt(paddedLength);
|
||||||
try {
|
try {
|
||||||
encryptAesInputData(toWireBuffer.array(), packetLen, sendBuffer.array(), 4);
|
encryptAesInputData(stagingBuffer.array(), packetLen, sendBuffer.array(), 4);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Should never happen
|
// Should never happen
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -13,20 +13,14 @@ public abstract class InputPacket {
|
|||||||
this.packetType = packetType;
|
this.packetType = packetType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract ByteOrder getPayloadByteOrder();
|
|
||||||
|
|
||||||
public abstract void toWirePayload(ByteBuffer bb);
|
public abstract void toWirePayload(ByteBuffer bb);
|
||||||
|
|
||||||
public abstract int getPacketLength();
|
public abstract int getPacketLength();
|
||||||
|
|
||||||
public void toWireHeader(ByteBuffer bb)
|
public void toWireHeader(ByteBuffer bb)
|
||||||
{
|
{
|
||||||
// We don't use putInt() here because it will be subject to the byte order
|
bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
// of the byte buffer. We just write it as a big endian int.
|
bb.putInt(packetType);
|
||||||
bb.put((byte)(packetType >> 24));
|
|
||||||
bb.put((byte)(packetType >> 16));
|
|
||||||
bb.put((byte)(packetType >> 8));
|
|
||||||
bb.put((byte)(packetType & 0xFF));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toWire(ByteBuffer bb)
|
public void toWire(ByteBuffer bb)
|
||||||
|
@ -25,13 +25,9 @@ public class KeyboardPacket extends InputPacket {
|
|||||||
this.modifier = modifier;
|
this.modifier = modifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteOrder getPayloadByteOrder() {
|
|
||||||
return ByteOrder.LITTLE_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toWirePayload(ByteBuffer bb) {
|
public void toWirePayload(ByteBuffer bb) {
|
||||||
|
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
bb.put(keyDirection);
|
bb.put(keyDirection);
|
||||||
bb.putShort((short)0);
|
bb.putShort((short)0);
|
||||||
bb.putShort((short)0);
|
bb.putShort((short)0);
|
||||||
|
@ -30,13 +30,9 @@ public class MouseButtonPacket extends InputPacket {
|
|||||||
PRESS_EVENT : RELEASE_EVENT;
|
PRESS_EVENT : RELEASE_EVENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteOrder getPayloadByteOrder() {
|
|
||||||
return ByteOrder.BIG_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toWirePayload(ByteBuffer bb) {
|
public void toWirePayload(ByteBuffer bb) {
|
||||||
|
bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
bb.put(buttonEventType);
|
bb.put(buttonEventType);
|
||||||
bb.putInt(mouseButton);
|
bb.putInt(mouseButton);
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,9 @@ public class MouseMovePacket extends InputPacket {
|
|||||||
this.deltaY = deltaY;
|
this.deltaY = deltaY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteOrder getPayloadByteOrder() {
|
|
||||||
return ByteOrder.BIG_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toWirePayload(ByteBuffer bb) {
|
public void toWirePayload(ByteBuffer bb) {
|
||||||
|
bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
bb.put(HEADER);
|
bb.put(HEADER);
|
||||||
bb.putShort(deltaX);
|
bb.putShort(deltaX);
|
||||||
bb.putShort(deltaY);
|
bb.putShort(deltaY);
|
||||||
|
@ -17,13 +17,10 @@ public class MouseScrollPacket extends InputPacket {
|
|||||||
this.scroll = (short)(scrollClicks * 120);
|
this.scroll = (short)(scrollClicks * 120);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ByteOrder getPayloadByteOrder() {
|
|
||||||
return ByteOrder.BIG_ENDIAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toWirePayload(ByteBuffer bb) {
|
public void toWirePayload(ByteBuffer bb) {
|
||||||
|
bb.order(ByteOrder.BIG_ENDIAN);
|
||||||
|
|
||||||
bb.put((byte) 0x09);
|
bb.put((byte) 0x09);
|
||||||
bb.put((byte) 0);
|
bb.put((byte) 0);
|
||||||
bb.put((byte) 0);
|
bb.put((byte) 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user