mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-18 06:41:06 +00:00
Fix many bugs in the initial code
This commit is contained in:
@@ -39,6 +39,8 @@ int initializeControlStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfigP
|
|||||||
|
|
||||||
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
|
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
|
||||||
|
|
||||||
|
PltCreateEvent(&resyncEvent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,11 +64,13 @@ static PNVCTL_PACKET_HEADER readNvctlPacket(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memcpy(fullPacket, &staticHeader, sizeof(staticHeader));
|
memcpy(fullPacket, &staticHeader, sizeof(staticHeader));
|
||||||
|
if (staticHeader.payloadLength != 0) {
|
||||||
err = recv(ctlSock, (char*) (fullPacket + 1), staticHeader.payloadLength, 0);
|
err = recv(ctlSock, (char*) (fullPacket + 1), staticHeader.payloadLength, 0);
|
||||||
if (err != staticHeader.payloadLength) {
|
if (err != staticHeader.payloadLength) {
|
||||||
free(fullPacket);
|
free(fullPacket);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fullPacket;
|
return fullPacket;
|
||||||
}
|
}
|
||||||
@@ -150,6 +154,7 @@ static void resyncThreadFunc(void* context) {
|
|||||||
payload[0] = 0;
|
payload[0] = 0;
|
||||||
payload[1] = 0xFFFFF;
|
payload[1] = 0xFFFFF;
|
||||||
|
|
||||||
|
printf("Sending resync packet\n");
|
||||||
err = send(ctlSock, (char*) payload, sizeof(payload), 0);
|
err = send(ctlSock, (char*) payload, sizeof(payload), 0);
|
||||||
if (err != sizeof(payload)) {
|
if (err != sizeof(payload)) {
|
||||||
Limelog("Resync thread terminating #2\n");
|
Limelog("Resync thread terminating #2\n");
|
||||||
@@ -183,27 +188,27 @@ int startControlStream(void) {
|
|||||||
configSize = getConfigDataSize(&streamConfig);
|
configSize = getConfigDataSize(&streamConfig);
|
||||||
config = allocateConfigDataForStreamConfig(&streamConfig);
|
config = allocateConfigDataForStreamConfig(&streamConfig);
|
||||||
if (config == NULL) {
|
if (config == NULL) {
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send config
|
// Send config
|
||||||
err = send(ctlSock, config, configSize, 0);
|
err = send(ctlSock, config, configSize, 0);
|
||||||
free(config);
|
free(config);
|
||||||
if (err != configSize) {
|
if (err != configSize) {
|
||||||
return NULL;
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping pong
|
// Ping pong
|
||||||
response = sendNoPayloadAndReceive(PTYPE_HEARTBEAT, PPAYLEN_HEARTBEAT);
|
response = sendNoPayloadAndReceive(PTYPE_KEEPALIVE, PPAYLEN_KEEPALIVE);
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
return NULL;
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
free(response);
|
free(response);
|
||||||
|
|
||||||
// 1405
|
// 1405
|
||||||
response = sendNoPayloadAndReceive(PTYPE_1405, PPAYLEN_1405);
|
response = sendNoPayloadAndReceive(PTYPE_1405, PPAYLEN_1405);
|
||||||
if (response == NULL) {
|
if (response == NULL) {
|
||||||
return NULL;
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
free(response);
|
free(response);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
#include "PlatformSockets.h"
|
#include "PlatformSockets.h"
|
||||||
|
#include "PlatformThreads.h"
|
||||||
|
|
||||||
const char HELLO [] = {
|
const char HELLO [] = {
|
||||||
0x07, 0x00, 0x00, 0x00,
|
0x07, 0x00, 0x00, 0x00,
|
||||||
@@ -36,6 +37,8 @@ int performHandshake(IP_ADDRESS host) {
|
|||||||
return LastSocketError();
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableNoDelay(s);
|
||||||
|
|
||||||
err = send(s, HELLO, sizeof(HELLO), 0);
|
err = send(s, HELLO, sizeof(HELLO), 0);
|
||||||
if (err == SOCKET_ERROR) {
|
if (err == SOCKET_ERROR) {
|
||||||
goto CleanupError;
|
goto CleanupError;
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) {
|
|||||||
if (decodingAvc) {
|
if (decodingAvc) {
|
||||||
PLENTRY entry = (PLENTRY) malloc(sizeof(*entry));
|
PLENTRY entry = (PLENTRY) malloc(sizeof(*entry));
|
||||||
if (entry != NULL) {
|
if (entry != NULL) {
|
||||||
|
entry->next = NULL;
|
||||||
entry->length = currentPos.offset - start;
|
entry->length = currentPos.offset - start;
|
||||||
entry->data = (char*) malloc(entry->length);
|
entry->data = (char*) malloc(entry->length);
|
||||||
if (entry->data == NULL) {
|
if (entry->data == NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user