Fix many bugs in the initial code

This commit is contained in:
Cameron Gutman
2014-01-19 01:20:54 -05:00
parent 2e971e102a
commit 979a439504
3 changed files with 14 additions and 5 deletions

View File

@@ -39,6 +39,8 @@ int initializeControlStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfigP
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
PltCreateEvent(&resyncEvent);
return 0;
}
@@ -62,11 +64,13 @@ static PNVCTL_PACKET_HEADER readNvctlPacket(void) {
}
memcpy(fullPacket, &staticHeader, sizeof(staticHeader));
if (staticHeader.payloadLength != 0) {
err = recv(ctlSock, (char*) (fullPacket + 1), staticHeader.payloadLength, 0);
if (err != staticHeader.payloadLength) {
free(fullPacket);
return NULL;
}
}
return fullPacket;
}
@@ -150,6 +154,7 @@ static void resyncThreadFunc(void* context) {
payload[0] = 0;
payload[1] = 0xFFFFF;
printf("Sending resync packet\n");
err = send(ctlSock, (char*) payload, sizeof(payload), 0);
if (err != sizeof(payload)) {
Limelog("Resync thread terminating #2\n");
@@ -183,27 +188,27 @@ int startControlStream(void) {
configSize = getConfigDataSize(&streamConfig);
config = allocateConfigDataForStreamConfig(&streamConfig);
if (config == NULL) {
return NULL;
return -1;
}
// Send config
err = send(ctlSock, config, configSize, 0);
free(config);
if (err != configSize) {
return NULL;
return LastSocketError();
}
// Ping pong
response = sendNoPayloadAndReceive(PTYPE_HEARTBEAT, PPAYLEN_HEARTBEAT);
response = sendNoPayloadAndReceive(PTYPE_KEEPALIVE, PPAYLEN_KEEPALIVE);
if (response == NULL) {
return NULL;
return LastSocketError();
}
free(response);
// 1405
response = sendNoPayloadAndReceive(PTYPE_1405, PPAYLEN_1405);
if (response == NULL) {
return NULL;
return LastSocketError();
}
free(response);

View File

@@ -1,5 +1,6 @@
#include "PlatformSockets.h"
#include "PlatformThreads.h"
const char HELLO [] = {
0x07, 0x00, 0x00, 0x00,
@@ -36,6 +37,8 @@ int performHandshake(IP_ADDRESS host) {
return LastSocketError();
}
enableNoDelay(s);
err = send(s, HELLO, sizeof(HELLO), 0);
if (err == SOCKET_ERROR) {
goto CleanupError;

View File

@@ -178,6 +178,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) {
if (decodingAvc) {
PLENTRY entry = (PLENTRY) malloc(sizeof(*entry));
if (entry != NULL) {
entry->next = NULL;
entry->length = currentPos.offset - start;
entry->data = (char*) malloc(entry->length);
if (entry->data == NULL) {