Fix packet type for legacy controller packets and privatize some constants to prevent this bug from happening again

This commit is contained in:
Cameron Gutman 2015-02-02 18:06:05 -05:00
parent 51343a171d
commit ec39f22ad8
9 changed files with 53 additions and 34 deletions

View File

@ -13,11 +13,10 @@ import com.limelight.nvstream.av.RtpPacket;
import com.limelight.nvstream.av.RtpReorderQueue; import com.limelight.nvstream.av.RtpReorderQueue;
public class AudioStream { public class AudioStream {
public static final int RTP_PORT = 48000; private static final int RTP_PORT = 48000;
public static final int RTCP_PORT = 47999;
public static final int RTP_RECV_BUFFER = 64 * 1024; private static final int RTP_RECV_BUFFER = 64 * 1024;
public static final int MAX_PACKET_SIZE = 100; private static final int MAX_PACKET_SIZE = 100;
private DatagramSocket rtp; private DatagramSocket rtp;

View File

@ -15,22 +15,21 @@ import com.limelight.nvstream.av.RtpPacket;
import com.limelight.nvstream.av.RtpReorderQueue; import com.limelight.nvstream.av.RtpReorderQueue;
public class VideoStream { public class VideoStream {
public static final int RTP_PORT = 47998; private static final int RTP_PORT = 47998;
public static final int RTCP_PORT = 47999; private static final int FIRST_FRAME_PORT = 47996;
public static final int FIRST_FRAME_PORT = 47996;
public static final int FIRST_FRAME_TIMEOUT = 5000; private static final int FIRST_FRAME_TIMEOUT = 5000;
public static final int RTP_RECV_BUFFER = 256 * 1024; private static final int RTP_RECV_BUFFER = 256 * 1024;
// We can't request an IDR frame until the depacketizer knows // We can't request an IDR frame until the depacketizer knows
// that a packet was lost. This timeout bounds the time that // that a packet was lost. This timeout bounds the time that
// the RTP queue will wait for missing/reordered packets. // the RTP queue will wait for missing/reordered packets.
public static final int MAX_RTP_QUEUE_DELAY_MS = 10; private static final int MAX_RTP_QUEUE_DELAY_MS = 10;
// The ring size MUST be greater than or equal to // The ring size MUST be greater than or equal to
// the maximum number of packets in a fully // the maximum number of packets in a fully
// presentable frame // presentable frame
public static final int VIDEO_RING_SIZE = 384; private static final int VIDEO_RING_SIZE = 384;
private DatagramSocket rtp; private DatagramSocket rtp;
private Socket firstFrameSocket; private Socket firstFrameSocket;

View File

@ -15,9 +15,9 @@ import com.limelight.nvstream.av.ConnectionStatusListener;
public class ControlStream implements ConnectionStatusListener { public class ControlStream implements ConnectionStatusListener {
public static final int PORT = 47995; private static final int PORT = 47995;
public static final int CONTROL_TIMEOUT = 5000; private static final int CONTROL_TIMEOUT = 5000;
private static final int IDX_START_A = 0; private static final int IDX_START_A = 0;
private static final int IDX_START_B = 1; private static final int IDX_START_B = 1;

View File

@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
public class ControllerPacket extends MultiControllerPacket { public class ControllerPacket extends MultiControllerPacket {
public static final byte[] HEADER = private static final byte[] HEADER =
{ {
0x0A, 0x0A,
0x00, 0x00,
@ -14,7 +14,7 @@ public class ControllerPacket extends MultiControllerPacket {
0x14 0x14
}; };
public static final byte[] TAIL = private static final byte[] TAIL =
{ {
(byte)0x9C, (byte)0x9C,
0x00, 0x00,
@ -24,7 +24,7 @@ public class ControllerPacket extends MultiControllerPacket {
0x00 0x00
}; };
public static final int PACKET_TYPE = 0x18; private static final int PACKET_TYPE = 0x18;
public static final short A_FLAG = 0x1000; public static final short A_FLAG = 0x1000;
public static final short B_FLAG = 0x2000; public static final short B_FLAG = 0x2000;
@ -42,15 +42,15 @@ public class ControllerPacket extends MultiControllerPacket {
public static final short RS_CLK_FLAG = 0x0080; public static final short RS_CLK_FLAG = 0x0080;
public static final short SPECIAL_BUTTON_FLAG = 0x0400; public static final short SPECIAL_BUTTON_FLAG = 0x0400;
public static final short PAYLOAD_LENGTH = 24; private static final short PAYLOAD_LENGTH = 24;
public static final short PACKET_LENGTH = PAYLOAD_LENGTH + private static final short PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH; InputPacket.HEADER_LENGTH;
public ControllerPacket(short buttonFlags, byte leftTrigger, byte rightTrigger, public ControllerPacket(short buttonFlags, byte leftTrigger, byte rightTrigger,
short leftStickX, short leftStickY, short leftStickX, short leftStickY,
short rightStickX, short rightStickY) short rightStickX, short rightStickY)
{ {
super((short) 0, buttonFlags, leftTrigger, rightTrigger, leftStickX, super(PACKET_TYPE, (short) 0, buttonFlags, leftTrigger, rightTrigger, leftStickX,
leftStickY, rightStickX, rightStickY); leftStickY, rightStickX, rightStickY);
this.buttonFlags = buttonFlags; this.buttonFlags = buttonFlags;

View File

@ -20,9 +20,9 @@ import com.limelight.nvstream.ConnectionContext;
public class ControllerStream { public class ControllerStream {
public final static int PORT = 35043; private final static int PORT = 35043;
public final static int CONTROLLER_TIMEOUT = 3000; private final static int CONTROLLER_TIMEOUT = 3000;
private ConnectionContext context; private ConnectionContext context;

View File

@ -5,7 +5,7 @@ import java.nio.ByteOrder;
public class KeyboardPacket extends InputPacket { public class KeyboardPacket extends InputPacket {
private static final int PACKET_TYPE = 0x0A; private static final int PACKET_TYPE = 0x0A;
public static final int PACKET_LENGTH = 14; private static final int PACKET_LENGTH = 14;
public static final byte KEY_DOWN = 0x03; public static final byte KEY_DOWN = 0x03;
public static final byte KEY_UP = 0x04; public static final byte KEY_UP = 0x04;

View File

@ -8,13 +8,13 @@ public class MouseButtonPacket extends InputPacket {
byte buttonEventType; byte buttonEventType;
byte mouseButton; byte mouseButton;
public static final int PACKET_TYPE = 0x5; private static final int PACKET_TYPE = 0x5;
public static final int PAYLOAD_LENGTH = 5; private static final int PAYLOAD_LENGTH = 5;
public static final int PACKET_LENGTH = PAYLOAD_LENGTH + private static final int PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH; InputPacket.HEADER_LENGTH;
public static final byte PRESS_EVENT = 0x07; private static final byte PRESS_EVENT = 0x07;
public static final byte RELEASE_EVENT = 0x08; private 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;

View File

@ -4,9 +4,9 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
public class MouseScrollPacket extends InputPacket { public class MouseScrollPacket extends InputPacket {
public static final int PACKET_TYPE = 0xa; private static final int PACKET_TYPE = 0xa;
public static final int PAYLOAD_LENGTH = 10; private static final int PAYLOAD_LENGTH = 10;
public static final int PACKET_LENGTH = PAYLOAD_LENGTH + private static final int PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH; InputPacket.HEADER_LENGTH;
short scroll; short scroll;

View File

@ -4,7 +4,7 @@ import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
public class MultiControllerPacket extends InputPacket { public class MultiControllerPacket extends InputPacket {
public static final byte[] TAIL = private static final byte[] TAIL =
{ {
(byte)0x9C, (byte)0x9C,
0x00, 0x00,
@ -14,10 +14,10 @@ public class MultiControllerPacket extends InputPacket {
0x00 0x00
}; };
public static final int PACKET_TYPE = 0x1e; private static final int PACKET_TYPE = 0x1e;
public static final short PAYLOAD_LENGTH = 30; private static final short PAYLOAD_LENGTH = 30;
public static final short PACKET_LENGTH = PAYLOAD_LENGTH + private static final short PACKET_LENGTH = PAYLOAD_LENGTH +
InputPacket.HEADER_LENGTH; InputPacket.HEADER_LENGTH;
short controllerNumber; short controllerNumber;
@ -48,6 +48,27 @@ public class MultiControllerPacket extends InputPacket {
this.rightStickY = rightStickY; this.rightStickY = rightStickY;
} }
public MultiControllerPacket(int packetType,
short controllerNumber, short buttonFlags,
byte leftTrigger, byte rightTrigger,
short leftStickX, short leftStickY,
short rightStickX, short rightStickY)
{
super(packetType);
this.controllerNumber = controllerNumber;
this.buttonFlags = buttonFlags;
this.leftTrigger = leftTrigger;
this.rightTrigger = rightTrigger;
this.leftStickX = leftStickX;
this.leftStickY = leftStickY;
this.rightStickX = rightStickX;
this.rightStickY = rightStickY;
}
@Override @Override
public void toWirePayload(ByteBuffer bb) { public void toWirePayload(ByteBuffer bb) {
bb.order(ByteOrder.LITTLE_ENDIAN); bb.order(ByteOrder.LITTLE_ENDIAN);