Increase the receive window size. Fix endianness issue with RTP sequence numbers. More bug fixes!

This commit is contained in:
Cameron Gutman
2014-01-19 01:41:27 -05:00
parent 979a439504
commit 44228d1296
4 changed files with 22 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);