diff --git a/limelight-common/ByteBuffer.cpp b/limelight-common/ByteBuffer.cpp index 330ba52..27ee05b 100644 --- a/limelight-common/ByteBuffer.cpp +++ b/limelight-common/ByteBuffer.cpp @@ -27,23 +27,23 @@ static int byteSwapShort(PBYTE_BUFFER buff, short s) { } int BbGet(PBYTE_BUFFER buff, char *c) { - if (buff->position + sizeof(c) >= buff->length) { + if (buff->position + sizeof(*c) > buff->length) { return 0; } memcpy(c, &buff->buffer[buff->position], sizeof(*c)); - buff->position += sizeof(c); + buff->position += sizeof(*c); return 1; } int BbGetShort(PBYTE_BUFFER buff, short *s) { - if (buff->position + sizeof(s) >= buff->length) { + if (buff->position + sizeof(*s) >= buff->length) { return 0; } memcpy(s, &buff->buffer[buff->position], sizeof(*s)); - buff->position += sizeof(s); + buff->position += sizeof(*s); *s = byteSwapShort(buff, *s); @@ -51,12 +51,12 @@ int BbGetShort(PBYTE_BUFFER buff, short *s) { } int BbGetInt(PBYTE_BUFFER buff, int *i) { - if (buff->position + sizeof(i) >= buff->length) { + if (buff->position + sizeof(*i) > buff->length) { return 0; } memcpy(i, &buff->buffer[buff->position], sizeof(*i)); - buff->position += sizeof(i); + buff->position += sizeof(*i); *i = byteSwapInt(buff, *i); @@ -64,7 +64,7 @@ int BbGetInt(PBYTE_BUFFER buff, int *i) { } int BbPutInt(PBYTE_BUFFER buff, int i) { - if (buff->position + sizeof(i) >= buff->length) { + if (buff->position + sizeof(i) > buff->length) { return 0; } @@ -77,7 +77,7 @@ int BbPutInt(PBYTE_BUFFER buff, int i) { } int BbPutShort(PBYTE_BUFFER buff, short s) { - if (buff->position + sizeof(s) >= buff->length) { + if (buff->position + sizeof(s) > buff->length) { return 0; } @@ -90,7 +90,7 @@ int BbPutShort(PBYTE_BUFFER buff, short s) { } int BbPut(PBYTE_BUFFER buff, char c) { - if (buff->position + sizeof(c) >= buff->length) { + if (buff->position + sizeof(c) > buff->length) { return 0; } diff --git a/limelight-common/PlatformSockets.cpp b/limelight-common/PlatformSockets.cpp index 8f9cb25..612e81f 100644 --- a/limelight-common/PlatformSockets.cpp +++ b/limelight-common/PlatformSockets.cpp @@ -1,8 +1,10 @@ #include "PlatformSockets.h" +#include "Limelight.h" SOCKET bindUdpSocket(unsigned short port) { SOCKET s; struct sockaddr_in addr; + int val; s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (s == INVALID_SOCKET) { @@ -17,6 +19,9 @@ SOCKET bindUdpSocket(unsigned short port) { return INVALID_SOCKET; } + val = 65536; + int err = setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char*) &val, sizeof(val)); + return s; } diff --git a/limelight-common/VideoDepacketizer.cpp b/limelight-common/VideoDepacketizer.cpp index a544d3a..a0c3621 100644 --- a/limelight-common/VideoDepacketizer.cpp +++ b/limelight-common/VideoDepacketizer.cpp @@ -208,6 +208,9 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) { } void queueRtpPacket(PRTP_PACKET rtpPacket, int length) { + + rtpPacket->sequenceNumber = htons(rtpPacket->sequenceNumber); + if (lastSequenceNumber != 0 && (unsigned short) (lastSequenceNumber + 1) != rtpPacket->sequenceNumber) { Limelog("Received OOS video data (expected %d, but got %d)\n", lastSequenceNumber + 1, rtpPacket->sequenceNumber); diff --git a/limelight-common/VideoStream.cpp b/limelight-common/VideoStream.cpp index 3895061..9ac52f0 100644 --- a/limelight-common/VideoStream.cpp +++ b/limelight-common/VideoStream.cpp @@ -60,11 +60,14 @@ static void ReceiveThreadProc(void* context) { Limelog("Receive thread terminating #2\n"); return; } + + queueRtpPacket((PRTP_PACKET) &buffer[sizeof(int)], err); memcpy(buffer, &err, sizeof(err)); if (!offerQueueItem(&packetQueue, buffer)) { free(buffer); + Limelog("Packet queue overflow\n"); } } } @@ -101,6 +104,7 @@ int readFirstFrame(void) { return LastSocketError(); } + Limelog("Waiting for first frame\n"); for (;;) { err = recv(s, &firstFrame[offset], sizeof(firstFrame) - offset, 0); if (err <= 0) { @@ -109,6 +113,7 @@ int readFirstFrame(void) { offset += err; } + Limelog("Read %d bytes\n", offset); processRtpPayload((PNV_VIDEO_PACKET) firstFrame, offset);