Code cleanup: use stdbool.h

This commit is contained in:
Cameron Gutman
2020-11-30 20:38:13 -06:00
parent e9ee868da4
commit 5f9f7ce407
27 changed files with 286 additions and 299 deletions
+9 -9
View File
@@ -15,7 +15,7 @@ static PLT_THREAD decoderThread;
static unsigned short lastSeq; static unsigned short lastSeq;
static int receivedDataFromPeer; static bool receivedDataFromPeer;
#define RTP_PORT 48000 #define RTP_PORT 48000
@@ -42,7 +42,7 @@ void initializeAudioStream(void) {
LbqInitializeLinkedBlockingQueue(&packetQueue, 30); LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
RtpqInitializeQueue(&rtpReorderQueue, RTPQ_DEFAULT_MAX_SIZE, RTPQ_DEFAULT_QUEUE_TIME); RtpqInitializeQueue(&rtpReorderQueue, RTPQ_DEFAULT_MAX_SIZE, RTPQ_DEFAULT_QUEUE_TIME);
lastSeq = 0; lastSeq = 0;
receivedDataFromPeer = 0; receivedDataFromPeer = false;
} }
static void freePacketList(PLINKED_BLOCKING_QUEUE_ENTRY entry) { static void freePacketList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
@@ -86,7 +86,7 @@ static void UdpPingThreadProc(void* context) {
} }
} }
static int queuePacketToLbq(PQUEUED_AUDIO_PACKET* packet) { static bool queuePacketToLbq(PQUEUED_AUDIO_PACKET* packet) {
int err; int err;
err = LbqOfferQueueItem(&packetQueue, *packet, &(*packet)->q.lentry); err = LbqOfferQueueItem(&packetQueue, *packet, &(*packet)->q.lentry);
@@ -99,10 +99,10 @@ static int queuePacketToLbq(PQUEUED_AUDIO_PACKET* packet) {
freePacketList(LbqFlushQueueItems(&packetQueue)); freePacketList(LbqFlushQueueItems(&packetQueue));
} }
else if (err == LBQ_INTERRUPTED) { else if (err == LBQ_INTERRUPTED) {
return 0; return false;
} }
return 1; return true;
} }
static void decodeInputData(PQUEUED_AUDIO_PACKET packet) { static void decodeInputData(PQUEUED_AUDIO_PACKET packet) {
@@ -124,7 +124,7 @@ static void ReceiveThreadProc(void* context) {
PRTP_PACKET rtp; PRTP_PACKET rtp;
PQUEUED_AUDIO_PACKET packet; PQUEUED_AUDIO_PACKET packet;
int queueStatus; int queueStatus;
int useSelect; bool useSelect;
int packetsToDrop = 500 / AudioPacketDuration; int packetsToDrop = 500 / AudioPacketDuration;
int waitingForAudioMs; int waitingForAudioMs;
@@ -132,11 +132,11 @@ static void ReceiveThreadProc(void* context) {
if (setNonFatalRecvTimeoutMs(rtpSocket, UDP_RECV_POLL_TIMEOUT_MS) < 0) { if (setNonFatalRecvTimeoutMs(rtpSocket, UDP_RECV_POLL_TIMEOUT_MS) < 0) {
// SO_RCVTIMEO failed, so use select() to wait // SO_RCVTIMEO failed, so use select() to wait
useSelect = 1; useSelect = true;
} }
else { else {
// SO_RCVTIMEO timeout set for recv() // SO_RCVTIMEO timeout set for recv()
useSelect = 0; useSelect = false;
} }
waitingForAudioMs = 0; waitingForAudioMs = 0;
@@ -181,7 +181,7 @@ static void ReceiveThreadProc(void* context) {
} }
if (!receivedDataFromPeer) { if (!receivedDataFromPeer) {
receivedDataFromPeer = 1; receivedDataFromPeer = true;
Limelog("Received first audio packet after %d ms\n", waitingForAudioMs); Limelog("Received first audio packet after %d ms\n", waitingForAudioMs);
} }
+27 -27
View File
@@ -37,32 +37,32 @@ static int byteSwapShort(PBYTE_BUFFER buff, short s) {
} }
} }
int BbAdvanceBuffer(PBYTE_BUFFER buff, int offset) { bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset) {
if (buff->position + offset > buff->length) { if (buff->position + offset > buff->length) {
return 0; return false;
} }
buff->position += offset; buff->position += offset;
return 1; return true;
} }
// Get a byte from the byte buffer // Get a byte from the byte buffer
int BbGet(PBYTE_BUFFER buff, char* c) { bool BbGet(PBYTE_BUFFER buff, char* c) {
if (buff->position + sizeof(*c) > buff->length) { if (buff->position + sizeof(*c) > buff->length) {
return 0; return false;
} }
memcpy(c, &buff->buffer[buff->position], sizeof(*c)); memcpy(c, &buff->buffer[buff->position], sizeof(*c));
buff->position += sizeof(*c); buff->position += sizeof(*c);
return 1; return true;
} }
// Get a short from the byte buffer // Get a short from the byte buffer
int BbGetShort(PBYTE_BUFFER buff, short* s) { bool BbGetShort(PBYTE_BUFFER buff, short* s) {
if (buff->position + sizeof(*s) > buff->length) { if (buff->position + sizeof(*s) > buff->length) {
return 0; return false;
} }
memcpy(s, &buff->buffer[buff->position], sizeof(*s)); memcpy(s, &buff->buffer[buff->position], sizeof(*s));
@@ -70,13 +70,13 @@ int BbGetShort(PBYTE_BUFFER buff, short* s) {
*s = byteSwapShort(buff, *s); *s = byteSwapShort(buff, *s);
return 1; return true;
} }
// Get an int from the byte buffer // Get an int from the byte buffer
int BbGetInt(PBYTE_BUFFER buff, int* i) { bool BbGetInt(PBYTE_BUFFER buff, int* i) {
if (buff->position + sizeof(*i) > buff->length) { if (buff->position + sizeof(*i) > buff->length) {
return 0; return false;
} }
memcpy(i, &buff->buffer[buff->position], sizeof(*i)); memcpy(i, &buff->buffer[buff->position], sizeof(*i));
@@ -84,13 +84,13 @@ int BbGetInt(PBYTE_BUFFER buff, int* i) {
*i = byteSwapInt(buff, *i); *i = byteSwapInt(buff, *i);
return 1; return true;
} }
// Get a long from the byte buffer // Get a long from the byte buffer
int BbGetLong(PBYTE_BUFFER buff, long long* l) { bool BbGetLong(PBYTE_BUFFER buff, long long* l) {
if (buff->position + sizeof(*l) > buff->length) { if (buff->position + sizeof(*l) > buff->length) {
return 0; return false;
} }
memcpy(l, &buff->buffer[buff->position], sizeof(*l)); memcpy(l, &buff->buffer[buff->position], sizeof(*l));
@@ -98,13 +98,13 @@ int BbGetLong(PBYTE_BUFFER buff, long long* l) {
*l = byteSwapLongLong(buff, *l); *l = byteSwapLongLong(buff, *l);
return 1; return true;
} }
// Put an int into the byte buffer // Put an int into the byte buffer
int BbPutInt(PBYTE_BUFFER buff, int i) { bool BbPutInt(PBYTE_BUFFER buff, int i) {
if (buff->position + sizeof(i) > buff->length) { if (buff->position + sizeof(i) > buff->length) {
return 0; return false;
} }
i = byteSwapInt(buff, i); i = byteSwapInt(buff, i);
@@ -112,13 +112,13 @@ int BbPutInt(PBYTE_BUFFER buff, int i) {
memcpy(&buff->buffer[buff->position], &i, sizeof(i)); memcpy(&buff->buffer[buff->position], &i, sizeof(i));
buff->position += sizeof(i); buff->position += sizeof(i);
return 1; return true;
} }
// Put a long into the byte buffer // Put a long into the byte buffer
int BbPutLong(PBYTE_BUFFER buff, long long l) { bool BbPutLong(PBYTE_BUFFER buff, long long l) {
if (buff->position + sizeof(l) > buff->length) { if (buff->position + sizeof(l) > buff->length) {
return 0; return false;
} }
l = byteSwapLongLong(buff, l); l = byteSwapLongLong(buff, l);
@@ -126,13 +126,13 @@ int BbPutLong(PBYTE_BUFFER buff, long long l) {
memcpy(&buff->buffer[buff->position], &l, sizeof(l)); memcpy(&buff->buffer[buff->position], &l, sizeof(l));
buff->position += sizeof(l); buff->position += sizeof(l);
return 1; return true;
} }
// Put a short into the byte buffer // Put a short into the byte buffer
int BbPutShort(PBYTE_BUFFER buff, short s) { bool BbPutShort(PBYTE_BUFFER buff, short s) {
if (buff->position + sizeof(s) > buff->length) { if (buff->position + sizeof(s) > buff->length) {
return 0; return false;
} }
s = byteSwapShort(buff, s); s = byteSwapShort(buff, s);
@@ -140,17 +140,17 @@ int BbPutShort(PBYTE_BUFFER buff, short s) {
memcpy(&buff->buffer[buff->position], &s, sizeof(s)); memcpy(&buff->buffer[buff->position], &s, sizeof(s));
buff->position += sizeof(s); buff->position += sizeof(s);
return 1; return true;
} }
// Put a byte into the buffer // Put a byte into the buffer
int BbPut(PBYTE_BUFFER buff, char c) { bool BbPut(PBYTE_BUFFER buff, char c) {
if (buff->position + sizeof(c) > buff->length) { if (buff->position + sizeof(c) > buff->length) {
return 0; return false;
} }
memcpy(&buff->buffer[buff->position], &c, sizeof(c)); memcpy(&buff->buffer[buff->position], &c, sizeof(c));
buff->position += sizeof(c); buff->position += sizeof(c);
return 1; return true;
} }
+9 -9
View File
@@ -25,14 +25,14 @@ typedef struct _BYTE_BUFFER {
} BYTE_BUFFER, *PBYTE_BUFFER; } BYTE_BUFFER, *PBYTE_BUFFER;
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder); void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
int BbAdvanceBuffer(PBYTE_BUFFER buff, int offset); bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
int BbGet(PBYTE_BUFFER buff, char* c); bool BbGet(PBYTE_BUFFER buff, char* c);
int BbGetShort(PBYTE_BUFFER buff, short* s); bool BbGetShort(PBYTE_BUFFER buff, short* s);
int BbGetInt(PBYTE_BUFFER buff, int* i); bool BbGetInt(PBYTE_BUFFER buff, int* i);
int BbGetLong(PBYTE_BUFFER buff, long long* l); bool BbGetLong(PBYTE_BUFFER buff, long long* l);
int BbPutInt(PBYTE_BUFFER buff, int i); bool BbPutInt(PBYTE_BUFFER buff, int i);
int BbPutShort(PBYTE_BUFFER buff, short s); bool BbPutShort(PBYTE_BUFFER buff, short s);
int BbPut(PBYTE_BUFFER buff, char c); bool BbPut(PBYTE_BUFFER buff, char c);
int BbPutLong(PBYTE_BUFFER buff, long long l); bool BbPutLong(PBYTE_BUFFER buff, long long l);
+9 -9
View File
@@ -3,7 +3,7 @@
static int stage = STAGE_NONE; static int stage = STAGE_NONE;
static ConnListenerConnectionTerminated originalTerminationCallback; static ConnListenerConnectionTerminated originalTerminationCallback;
static int alreadyTerminated; static bool alreadyTerminated;
static PLT_THREAD terminationCallbackThread; static PLT_THREAD terminationCallbackThread;
static int terminationCallbackErrorCode; static int terminationCallbackErrorCode;
@@ -17,9 +17,9 @@ CONNECTION_LISTENER_CALLBACKS ListenerCallbacks;
DECODER_RENDERER_CALLBACKS VideoCallbacks; DECODER_RENDERER_CALLBACKS VideoCallbacks;
AUDIO_RENDERER_CALLBACKS AudioCallbacks; AUDIO_RENDERER_CALLBACKS AudioCallbacks;
int NegotiatedVideoFormat; int NegotiatedVideoFormat;
volatile int ConnectionInterrupted; volatile bool ConnectionInterrupted;
int HighQualitySurroundSupported; bool HighQualitySurroundSupported;
int HighQualitySurroundEnabled; bool HighQualitySurroundEnabled;
OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig; OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig;
OPUS_MULTISTREAM_CONFIGURATION HighQualityOpusConfig; OPUS_MULTISTREAM_CONFIGURATION HighQualityOpusConfig;
int OriginalVideoBitrate; int OriginalVideoBitrate;
@@ -50,13 +50,13 @@ const char* LiGetStageName(int stage) {
// so it is not safe to start another connection before LiStartConnection() returns. // so it is not safe to start another connection before LiStartConnection() returns.
void LiInterruptConnection(void) { void LiInterruptConnection(void) {
// Signal anyone waiting on the global interrupted flag // Signal anyone waiting on the global interrupted flag
ConnectionInterrupted = 1; ConnectionInterrupted = true;
} }
// Stop the connection by undoing the step at the current stage and those before it // Stop the connection by undoing the step at the current stage and those before it
void LiStopConnection(void) { void LiStopConnection(void) {
// Disable termination callbacks now // Disable termination callbacks now
alreadyTerminated = 1; alreadyTerminated = true;
// Set the interrupted flag // Set the interrupted flag
LiInterruptConnection(); LiInterruptConnection();
@@ -153,7 +153,7 @@ static void ClInternalConnectionTerminated(int errorCode)
} }
terminationCallbackErrorCode = errorCode; terminationCallbackErrorCode = errorCode;
alreadyTerminated = 1; alreadyTerminated = true;
// Invoke the termination callback on a separate thread // Invoke the termination callback on a separate thread
err = PltCreateThread("AsyncTerm", terminationCallbackThreadFunc, NULL, &terminationCallbackThread); err = PltCreateThread("AsyncTerm", terminationCallbackThreadFunc, NULL, &terminationCallbackThread);
@@ -235,8 +235,8 @@ int LiStartConnection(PSERVER_INFORMATION serverInfo, PSTREAM_CONFIGURATION stre
goto Cleanup; goto Cleanup;
} }
alreadyTerminated = 0; alreadyTerminated = false;
ConnectionInterrupted = 0; ConnectionInterrupted = false;
Limelog("Initializing platform..."); Limelog("Initializing platform...");
ListenerCallbacks.stageStarting(STAGE_PLATFORM_INIT); ListenerCallbacks.stageStarting(STAGE_PLATFORM_INIT);
+2 -2
View File
@@ -72,7 +72,7 @@ unsigned short LiGetPortFromPortFlagIndex(int portFlagIndex)
return 48010; return 48010;
default: default:
LC_ASSERT(0); LC_ASSERT(false);
return 0; return 0;
} }
} }
@@ -115,7 +115,7 @@ unsigned int LiTestClientConnectivity(const char* testServer, unsigned short ref
sockets[i] = createSocket(address.ss_family, sockets[i] = createSocket(address.ss_family,
LiGetProtocolFromPortFlagIndex(i) == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM, LiGetProtocolFromPortFlagIndex(i) == IPPROTO_UDP ? SOCK_DGRAM : SOCK_STREAM,
LiGetProtocolFromPortFlagIndex(i), LiGetProtocolFromPortFlagIndex(i),
1); true);
if (sockets[i] == INVALID_SOCKET) { if (sockets[i] == INVALID_SOCKET) {
err = LastSocketFail(); err = LastSocketFail();
Limelog("Failed to create socket: %d\n", err); Limelog("Failed to create socket: %d\n", err);
+42 -42
View File
@@ -26,7 +26,7 @@ static SOCKET ctlSock = INVALID_SOCKET;
static ENetHost* client; static ENetHost* client;
static ENetPeer* peer; static ENetPeer* peer;
static PLT_MUTEX enetMutex; static PLT_MUTEX enetMutex;
static int usePeriodicPing; static bool usePeriodicPing;
static PLT_THREAD lossStatsThread; static PLT_THREAD lossStatsThread;
static PLT_THREAD invalidateRefFramesThread; static PLT_THREAD invalidateRefFramesThread;
@@ -35,8 +35,8 @@ static PLT_EVENT invalidateRefFramesEvent;
static int lossCountSinceLastReport; static int lossCountSinceLastReport;
static long lastGoodFrame; static long lastGoodFrame;
static long lastSeenFrame; static long lastSeenFrame;
static int stopping; static bool stopping;
static int disconnectPending; static bool disconnectPending;
static int intervalGoodFrameCount; static int intervalGoodFrameCount;
static int intervalTotalFrameCount; static int intervalTotalFrameCount;
@@ -44,7 +44,7 @@ static uint64_t intervalStartTimeMs;
static int lastIntervalLossPercentage; static int lastIntervalLossPercentage;
static int lastConnectionStatusUpdate; static int lastConnectionStatusUpdate;
static int idrFrameRequired; static bool idrFrameRequired;
static LINKED_BLOCKING_QUEUE invalidReferenceFrameTuples; static LINKED_BLOCKING_QUEUE invalidReferenceFrameTuples;
#define CONN_IMMEDIATE_POOR_LOSS_RATE 30 #define CONN_IMMEDIATE_POOR_LOSS_RATE 30
@@ -172,7 +172,7 @@ static char**preconstructedPayloads;
// Initializes the control stream // Initializes the control stream
int initializeControlStream(void) { int initializeControlStream(void) {
stopping = 0; stopping = false;
PltCreateEvent(&invalidateRefFramesEvent); PltCreateEvent(&invalidateRefFramesEvent);
LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20); LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20);
PltCreateMutex(&enetMutex); PltCreateMutex(&enetMutex);
@@ -198,11 +198,11 @@ int initializeControlStream(void) {
preconstructedPayloads = (char**)preconstructedPayloadsGen7; preconstructedPayloads = (char**)preconstructedPayloadsGen7;
} }
idrFrameRequired = 0; idrFrameRequired = false;
lastGoodFrame = 0; lastGoodFrame = 0;
lastSeenFrame = 0; lastSeenFrame = 0;
lossCountSinceLastReport = 0; lossCountSinceLastReport = 0;
disconnectPending = 0; disconnectPending = false;
intervalGoodFrameCount = 0; intervalGoodFrameCount = 0;
intervalTotalFrameCount = 0; intervalTotalFrameCount = 0;
intervalStartTimeMs = 0; intervalStartTimeMs = 0;
@@ -250,15 +250,15 @@ void queueFrameInvalidationTuple(int startFrame, int endFrame) {
if (LbqOfferQueueItem(&invalidReferenceFrameTuples, qfit, &qfit->entry) == LBQ_BOUND_EXCEEDED) { if (LbqOfferQueueItem(&invalidReferenceFrameTuples, qfit, &qfit->entry) == LBQ_BOUND_EXCEEDED) {
// Too many invalidation tuples, so we need an IDR frame now // Too many invalidation tuples, so we need an IDR frame now
free(qfit); free(qfit);
idrFrameRequired = 1; idrFrameRequired = true;
} }
} }
else { else {
idrFrameRequired = 1; idrFrameRequired = true;
} }
} }
else { else {
idrFrameRequired = 1; idrFrameRequired = true;
} }
PltSetEvent(&invalidateRefFramesEvent); PltSetEvent(&invalidateRefFramesEvent);
@@ -266,7 +266,7 @@ void queueFrameInvalidationTuple(int startFrame, int endFrame) {
// Request an IDR frame on demand by the decoder // Request an IDR frame on demand by the decoder
void requestIdrOnDemand(void) { void requestIdrOnDemand(void) {
idrFrameRequired = 1; idrFrameRequired = true;
PltSetEvent(&invalidateRefFramesEvent); PltSetEvent(&invalidateRefFramesEvent);
} }
@@ -345,7 +345,7 @@ static PNVCTL_TCP_PACKET_HEADER readNvctlPacketTcp(void) {
return fullPacket; return fullPacket;
} }
static int sendMessageEnet(short ptype, short paylen, const void* payload) { static bool sendMessageEnet(short ptype, short paylen, const void* payload) {
PNVCTL_ENET_PACKET_HEADER packet; PNVCTL_ENET_PACKET_HEADER packet;
ENetPacket* enetPacket; ENetPacket* enetPacket;
int err; int err;
@@ -354,7 +354,7 @@ static int sendMessageEnet(short ptype, short paylen, const void* payload) {
enetPacket = enet_packet_create(NULL, sizeof(*packet) + paylen, ENET_PACKET_FLAG_RELIABLE); enetPacket = enet_packet_create(NULL, sizeof(*packet) + paylen, ENET_PACKET_FLAG_RELIABLE);
if (enetPacket == NULL) { if (enetPacket == NULL) {
return 0; return false;
} }
packet = (PNVCTL_ENET_PACKET_HEADER)enetPacket->data; packet = (PNVCTL_ENET_PACKET_HEADER)enetPacket->data;
@@ -367,17 +367,17 @@ static int sendMessageEnet(short ptype, short paylen, const void* payload) {
if (err < 0) { if (err < 0) {
Limelog("Failed to send ENet control packet\n"); Limelog("Failed to send ENet control packet\n");
enet_packet_destroy(enetPacket); enet_packet_destroy(enetPacket);
return 0; return false;
} }
PltLockMutex(&enetMutex); PltLockMutex(&enetMutex);
enet_host_flush(client); enet_host_flush(client);
PltUnlockMutex(&enetMutex); PltUnlockMutex(&enetMutex);
return 1; return true;
} }
static int sendMessageTcp(short ptype, short paylen, const void* payload) { static bool sendMessageTcp(short ptype, short paylen, const void* payload) {
PNVCTL_TCP_PACKET_HEADER packet; PNVCTL_TCP_PACKET_HEADER packet;
SOCK_RET err; SOCK_RET err;
@@ -385,7 +385,7 @@ static int sendMessageTcp(short ptype, short paylen, const void* payload) {
packet = malloc(sizeof(*packet) + paylen); packet = malloc(sizeof(*packet) + paylen);
if (packet == NULL) { if (packet == NULL) {
return 0; return false;
} }
packet->type = ptype; packet->type = ptype;
@@ -396,14 +396,14 @@ static int sendMessageTcp(short ptype, short paylen, const void* payload) {
free(packet); free(packet);
if (err != sizeof(*packet) + paylen) { if (err != sizeof(*packet) + paylen) {
return 0; return false;
} }
return 1; return true;
} }
static int sendMessageAndForget(short ptype, short paylen, const void* payload) { static bool sendMessageAndForget(short ptype, short paylen, const void* payload) {
int ret; bool ret;
// Unlike regular sockets, ENet sockets aren't safe to invoke from multiple // Unlike regular sockets, ENet sockets aren't safe to invoke from multiple
// threads at once. We have to synchronize them with a lock. // threads at once. We have to synchronize them with a lock.
@@ -417,29 +417,29 @@ static int sendMessageAndForget(short ptype, short paylen, const void* payload)
return ret; return ret;
} }
static int sendMessageAndDiscardReply(short ptype, short paylen, const void* payload) { static bool sendMessageAndDiscardReply(short ptype, short paylen, const void* payload) {
if (AppVersionQuad[0] >= 5) { if (AppVersionQuad[0] >= 5) {
if (!sendMessageEnet(ptype, paylen, payload)) { if (!sendMessageEnet(ptype, paylen, payload)) {
return 0; return false;
} }
} }
else { else {
PNVCTL_TCP_PACKET_HEADER reply; PNVCTL_TCP_PACKET_HEADER reply;
if (!sendMessageTcp(ptype, paylen, payload)) { if (!sendMessageTcp(ptype, paylen, payload)) {
return 0; return false;
} }
// Discard the response // Discard the response
reply = readNvctlPacketTcp(); reply = readNvctlPacketTcp();
if (reply == NULL) { if (reply == NULL) {
return 0; return false;
} }
free(reply); free(reply);
} }
return 1; return true;
} }
// This intercept function drops disconnect events to allow us to process // This intercept function drops disconnect events to allow us to process
@@ -452,7 +452,7 @@ static int ignoreDisconnectIntercept(ENetHost* host, ENetEvent* event) {
if ((disconnect->header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT) { if ((disconnect->header.command & ENET_PROTOCOL_COMMAND_MASK) == ENET_PROTOCOL_COMMAND_DISCONNECT) {
Limelog("ENet disconnect event pending\n"); Limelog("ENet disconnect event pending\n");
disconnectPending = 1; disconnectPending = true;
if (event) { if (event) {
event->type = ENET_EVENT_TYPE_NONE; event->type = ENET_EVENT_TYPE_NONE;
} }
@@ -750,7 +750,7 @@ static void invalidateRefFramesFunc(void* context) {
} }
// Send an IDR frame request // Send an IDR frame request
idrFrameRequired = 0; idrFrameRequired = false;
requestIdrFrame(); requestIdrFrame();
} }
else { else {
@@ -762,7 +762,7 @@ static void invalidateRefFramesFunc(void* context) {
// Stops the control stream // Stops the control stream
int stopControlStream(void) { int stopControlStream(void) {
stopping = 1; stopping = true;
LbqSignalQueueShutdown(&invalidReferenceFrameTuples); LbqSignalQueueShutdown(&invalidReferenceFrameTuples);
PltSetEvent(&invalidateRefFramesEvent); PltSetEvent(&invalidateRefFramesEvent);
@@ -830,7 +830,7 @@ int startControlStream(void) {
// Create a client that can use 1 outgoing connection and 1 channel // Create a client that can use 1 outgoing connection and 1 channel
client = enet_host_create(address.address.ss_family, NULL, 1, 1, 0, 0); client = enet_host_create(address.address.ss_family, NULL, 1, 1, 0, 0);
if (client == NULL) { if (client == NULL) {
stopping = 1; stopping = true;
return -1; return -1;
} }
@@ -839,7 +839,7 @@ int startControlStream(void) {
// Connect to the host // Connect to the host
peer = enet_host_connect(client, &address, 1, 0); peer = enet_host_connect(client, &address, 1, 0);
if (peer == NULL) { if (peer == NULL) {
stopping = 1; stopping = true;
enet_host_destroy(client); enet_host_destroy(client);
client = NULL; client = NULL;
return -1; return -1;
@@ -849,7 +849,7 @@ int startControlStream(void) {
if (serviceEnetHost(client, &event, CONTROL_STREAM_TIMEOUT_SEC * 1000) <= 0 || if (serviceEnetHost(client, &event, CONTROL_STREAM_TIMEOUT_SEC * 1000) <= 0 ||
event.type != ENET_EVENT_TYPE_CONNECT) { event.type != ENET_EVENT_TYPE_CONNECT) {
Limelog("Failed to connect to UDP port 47999\n"); Limelog("Failed to connect to UDP port 47999\n");
stopping = 1; stopping = true;
enet_peer_reset(peer); enet_peer_reset(peer);
peer = NULL; peer = NULL;
enet_host_destroy(client); enet_host_destroy(client);
@@ -867,7 +867,7 @@ int startControlStream(void) {
ctlSock = connectTcpSocket(&RemoteAddr, RemoteAddrLen, ctlSock = connectTcpSocket(&RemoteAddr, RemoteAddrLen,
47995, CONTROL_STREAM_TIMEOUT_SEC); 47995, CONTROL_STREAM_TIMEOUT_SEC);
if (ctlSock == INVALID_SOCKET) { if (ctlSock == INVALID_SOCKET) {
stopping = 1; stopping = true;
return LastSocketFail(); return LastSocketFail();
} }
@@ -876,7 +876,7 @@ int startControlStream(void) {
err = PltCreateThread("ControlRecv", controlReceiveThreadFunc, NULL, &controlReceiveThread); err = PltCreateThread("ControlRecv", controlReceiveThreadFunc, NULL, &controlReceiveThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = true;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
closeSocket(ctlSock); closeSocket(ctlSock);
ctlSock = INVALID_SOCKET; ctlSock = INVALID_SOCKET;
@@ -896,13 +896,13 @@ int startControlStream(void) {
preconstructedPayloads[IDX_START_A])) { preconstructedPayloads[IDX_START_A])) {
Limelog("Start A failed: %d\n", (int)LastSocketError()); Limelog("Start A failed: %d\n", (int)LastSocketError());
err = LastSocketFail(); err = LastSocketFail();
stopping = 1; stopping = true;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
shutdownTcpSocket(ctlSock); shutdownTcpSocket(ctlSock);
} }
else { else {
ConnectionInterrupted = 1; ConnectionInterrupted = true;
} }
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
@@ -928,13 +928,13 @@ int startControlStream(void) {
preconstructedPayloads[IDX_START_B])) { preconstructedPayloads[IDX_START_B])) {
Limelog("Start B failed: %d\n", (int)LastSocketError()); Limelog("Start B failed: %d\n", (int)LastSocketError());
err = LastSocketFail(); err = LastSocketFail();
stopping = 1; stopping = true;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
shutdownTcpSocket(ctlSock); shutdownTcpSocket(ctlSock);
} }
else { else {
ConnectionInterrupted = 1; ConnectionInterrupted = true;
} }
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
@@ -956,13 +956,13 @@ int startControlStream(void) {
err = PltCreateThread("LossStats", lossStatsThreadFunc, NULL, &lossStatsThread); err = PltCreateThread("LossStats", lossStatsThreadFunc, NULL, &lossStatsThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = true;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
shutdownTcpSocket(ctlSock); shutdownTcpSocket(ctlSock);
} }
else { else {
ConnectionInterrupted = 1; ConnectionInterrupted = true;
} }
PltInterruptThread(&controlReceiveThread); PltInterruptThread(&controlReceiveThread);
@@ -984,13 +984,13 @@ int startControlStream(void) {
err = PltCreateThread("InvRefFrames", invalidateRefFramesFunc, NULL, &invalidateRefFramesThread); err = PltCreateThread("InvRefFrames", invalidateRefFramesFunc, NULL, &invalidateRefFramesThread);
if (err != 0) { if (err != 0) {
stopping = 1; stopping = true;
if (ctlSock != INVALID_SOCKET) { if (ctlSock != INVALID_SOCKET) {
shutdownTcpSocket(ctlSock); shutdownTcpSocket(ctlSock);
} }
else { else {
ConnectionInterrupted = 1; ConnectionInterrupted = true;
} }
PltInterruptThread(&lossStatsThread); PltInterruptThread(&lossStatsThread);
+8 -8
View File
@@ -8,9 +8,9 @@
static SOCKET inputSock = INVALID_SOCKET; static SOCKET inputSock = INVALID_SOCKET;
static unsigned char currentAesIv[16]; static unsigned char currentAesIv[16];
static int initialized; static bool initialized;
static EVP_CIPHER_CTX* cipherContext; static EVP_CIPHER_CTX* cipherContext;
static int cipherInitialized; static bool cipherInitialized;
static LINKED_BLOCKING_QUEUE packetQueue; static LINKED_BLOCKING_QUEUE packetQueue;
static PLT_THREAD inputSendThread; static PLT_THREAD inputSendThread;
@@ -45,7 +45,7 @@ int initializeInputStream(void) {
memcpy(currentAesIv, StreamConfig.remoteInputAesIv, sizeof(currentAesIv)); memcpy(currentAesIv, StreamConfig.remoteInputAesIv, sizeof(currentAesIv));
// Initialized on first packet // Initialized on first packet
cipherInitialized = 0; cipherInitialized = false;
LbqInitializeLinkedBlockingQueue(&packetQueue, 30); LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
@@ -58,7 +58,7 @@ void destroyInputStream(void) {
if (cipherInitialized) { if (cipherInitialized) {
EVP_CIPHER_CTX_free(cipherContext); EVP_CIPHER_CTX_free(cipherContext);
cipherInitialized = 0; cipherInitialized = false;
} }
entry = LbqDestroyLinkedBlockingQueue(&packetQueue); entry = LbqDestroyLinkedBlockingQueue(&packetQueue);
@@ -95,7 +95,7 @@ static int encryptData(const unsigned char* plaintext, int plaintextLen,
if ((cipherContext = EVP_CIPHER_CTX_new()) == NULL) { if ((cipherContext = EVP_CIPHER_CTX_new()) == NULL) {
return -1; return -1;
} }
cipherInitialized = 1; cipherInitialized = true;
} }
// Gen 7 servers use 128-bit AES GCM // Gen 7 servers use 128-bit AES GCM
@@ -153,7 +153,7 @@ static int encryptData(const unsigned char* plaintext, int plaintextLen,
ret = -1; ret = -1;
goto cbc_cleanup; goto cbc_cleanup;
} }
cipherInitialized = 1; cipherInitialized = true;
// Prior to Gen 7, 128-bit AES CBC is used for encryption // Prior to Gen 7, 128-bit AES CBC is used for encryption
if (EVP_EncryptInit_ex(cipherContext, EVP_aes_128_cbc(), NULL, if (EVP_EncryptInit_ex(cipherContext, EVP_aes_128_cbc(), NULL,
@@ -421,7 +421,7 @@ int startInputStream(void) {
} }
// Allow input packets to be queued now // Allow input packets to be queued now
initialized = 1; initialized = true;
// GFE will not send haptics events without this magic packet first // GFE will not send haptics events without this magic packet first
sendEnableHaptics(); sendEnableHaptics();
@@ -432,7 +432,7 @@ int startInputStream(void) {
// Stops the input stream // Stops the input stream
int stopInputStream(void) { int stopInputStream(void) {
// No more packets should be queued now // No more packets should be queued now
initialized = 0; initialized = false;
// Signal the input send thread // Signal the input send thread
LbqSignalQueueShutdown(&packetQueue); LbqSignalQueueShutdown(&packetQueue);
+4 -4
View File
@@ -19,9 +19,9 @@ extern CONNECTION_LISTENER_CALLBACKS ListenerCallbacks;
extern DECODER_RENDERER_CALLBACKS VideoCallbacks; extern DECODER_RENDERER_CALLBACKS VideoCallbacks;
extern AUDIO_RENDERER_CALLBACKS AudioCallbacks; extern AUDIO_RENDERER_CALLBACKS AudioCallbacks;
extern int NegotiatedVideoFormat; extern int NegotiatedVideoFormat;
extern volatile int ConnectionInterrupted; extern volatile bool ConnectionInterrupted;
extern int HighQualitySurroundSupported; extern bool HighQualitySurroundSupported;
extern int HighQualitySurroundEnabled; extern bool HighQualitySurroundEnabled;
extern OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig; extern OPUS_MULTISTREAM_CONFIGURATION NormalQualityOpusConfig;
extern OPUS_MULTISTREAM_CONFIGURATION HighQualityOpusConfig; extern OPUS_MULTISTREAM_CONFIGURATION HighQualityOpusConfig;
extern int OriginalVideoBitrate; extern int OriginalVideoBitrate;
@@ -54,7 +54,7 @@ extern int AudioPacketDuration;
int serviceEnetHost(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs); int serviceEnetHost(ENetHost* client, ENetEvent* event, enet_uint32 timeoutMs);
int extractVersionQuadFromString(const char* string, int* quad); int extractVersionQuadFromString(const char* string, int* quad);
int isReferenceFrameInvalidationEnabled(void); bool isReferenceFrameInvalidationEnabled(void);
void* extendBuffer(void* ptr, size_t newSize); void* extendBuffer(void* ptr, size_t newSize);
void fixupMissingCallbacks(PDECODER_RENDERER_CALLBACKS* drCallbacks, PAUDIO_RENDERER_CALLBACKS* arCallbacks, void fixupMissingCallbacks(PDECODER_RENDERER_CALLBACKS* drCallbacks, PAUDIO_RENDERER_CALLBACKS* arCallbacks,
+1
View File
@@ -5,6 +5,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
+1 -1
View File
@@ -52,7 +52,7 @@ int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeB
} }
void LbqSignalQueueShutdown(PLINKED_BLOCKING_QUEUE queueHead) { void LbqSignalQueueShutdown(PLINKED_BLOCKING_QUEUE queueHead) {
queueHead->shutdown = 1; queueHead->shutdown = true;
PltSetEvent(&queueHead->containsDataEvent); PltSetEvent(&queueHead->containsDataEvent);
} }
+1 -1
View File
@@ -19,7 +19,7 @@ typedef struct _LINKED_BLOCKING_QUEUE {
PLT_EVENT containsDataEvent; PLT_EVENT containsDataEvent;
int sizeBound; int sizeBound;
int currentSize; int currentSize;
int shutdown; bool shutdown;
int lifetimeSize; int lifetimeSize;
PLINKED_BLOCKING_QUEUE_ENTRY head; PLINKED_BLOCKING_QUEUE_ENTRY head;
PLINKED_BLOCKING_QUEUE_ENTRY tail; PLINKED_BLOCKING_QUEUE_ENTRY tail;
+1 -1
View File
@@ -71,7 +71,7 @@ void* extendBuffer(void* ptr, size_t newSize) {
return newBuf; return newBuf;
} }
int isReferenceFrameInvalidationEnabled(void) { bool isReferenceFrameInvalidationEnabled(void) {
LC_ASSERT(NegotiatedVideoFormat != 0); LC_ASSERT(NegotiatedVideoFormat != 0);
return ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H264) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC)) || return ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H264) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC)) ||
((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H265) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC)); ((NegotiatedVideoFormat & VIDEO_FORMAT_MASK_H265) && (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC));
+12 -12
View File
@@ -91,7 +91,7 @@ void* ThreadProc(void* context) {
ctx->entry(ctx->context); ctx->entry(ctx->context);
#if defined(__vita__) #if defined(__vita__)
ctx->thread->alive = 0; ctx->thread->alive = false;
#else #else
free(ctx); free(ctx);
#endif #endif
@@ -159,7 +159,7 @@ void PltLockMutex(PLT_MUTEX* mutex) {
int err; int err;
err = WaitForSingleObjectEx(*mutex, INFINITE, FALSE); err = WaitForSingleObjectEx(*mutex, INFINITE, FALSE);
if (err != WAIT_OBJECT_0) { if (err != WAIT_OBJECT_0) {
LC_ASSERT(FALSE); LC_ASSERT(false);
} }
#elif defined(__vita__) #elif defined(__vita__)
sceKernelLockMutex(*mutex, 1, NULL); sceKernelLockMutex(*mutex, 1, NULL);
@@ -202,12 +202,12 @@ void PltCloseThread(PLT_THREAD* thread) {
#endif #endif
} }
int PltIsThreadInterrupted(PLT_THREAD* thread) { bool PltIsThreadInterrupted(PLT_THREAD* thread) {
return thread->cancelled; return thread->cancelled;
} }
void PltInterruptThread(PLT_THREAD* thread) { void PltInterruptThread(PLT_THREAD* thread) {
thread->cancelled = 1; thread->cancelled = true;
} }
int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread) { int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread) {
@@ -222,7 +222,7 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
ctx->context = context; ctx->context = context;
ctx->name = name; ctx->name = name;
thread->cancelled = 0; thread->cancelled = false;
#if defined(LC_WINDOWS) #if defined(LC_WINDOWS)
{ {
@@ -234,7 +234,7 @@ int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THRE
} }
#elif defined(__vita__) #elif defined(__vita__)
{ {
thread->alive = 1; thread->alive = true;
thread->context = ctx; thread->context = ctx;
ctx->thread = thread; ctx->thread = thread;
thread->handle = sceKernelCreateThread(name, ThreadProc, 0, 0x40000, 0, 0, NULL); thread->handle = sceKernelCreateThread(name, ThreadProc, 0, 0x40000, 0, 0, NULL);
@@ -275,11 +275,11 @@ int PltCreateEvent(PLT_EVENT* event) {
sceKernelDeleteMutex(event->mutex); sceKernelDeleteMutex(event->mutex);
return -1; return -1;
} }
event->signalled = 0; event->signalled = false;
#else #else
pthread_mutex_init(&event->mutex, NULL); pthread_mutex_init(&event->mutex, NULL);
pthread_cond_init(&event->cond, NULL); pthread_cond_init(&event->cond, NULL);
event->signalled = 0; event->signalled = false;
#endif #endif
activeEvents++; activeEvents++;
return 0; return 0;
@@ -303,12 +303,12 @@ void PltSetEvent(PLT_EVENT* event) {
SetEvent(*event); SetEvent(*event);
#elif defined(__vita__) #elif defined(__vita__)
sceKernelLockMutex(event->mutex, 1, NULL); sceKernelLockMutex(event->mutex, 1, NULL);
event->signalled = 1; event->signalled = true;
sceKernelUnlockMutex(event->mutex, 1); sceKernelUnlockMutex(event->mutex, 1);
sceKernelSignalCondAll(event->cond); sceKernelSignalCondAll(event->cond);
#else #else
pthread_mutex_lock(&event->mutex); pthread_mutex_lock(&event->mutex);
event->signalled = 1; event->signalled = true;
pthread_mutex_unlock(&event->mutex); pthread_mutex_unlock(&event->mutex);
pthread_cond_broadcast(&event->cond); pthread_cond_broadcast(&event->cond);
#endif #endif
@@ -318,7 +318,7 @@ void PltClearEvent(PLT_EVENT* event) {
#if defined(LC_WINDOWS) #if defined(LC_WINDOWS)
ResetEvent(*event); ResetEvent(*event);
#else #else
event->signalled = 0; event->signalled = false;
#endif #endif
} }
@@ -331,7 +331,7 @@ int PltWaitForEvent(PLT_EVENT* event) {
return PLT_WAIT_SUCCESS; return PLT_WAIT_SUCCESS;
} }
else { else {
LC_ASSERT(0); LC_ASSERT(false);
return -1; return -1;
} }
#elif defined(__vita__) #elif defined(__vita__)
+20 -19
View File
@@ -147,7 +147,7 @@ int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs) {
#endif #endif
} }
int recvUdpSocket(SOCKET s, char* buffer, int size, int useSelect) { int recvUdpSocket(SOCKET s, char* buffer, int size, bool useSelect) {
int err; int err;
do { do {
@@ -207,7 +207,7 @@ SOCKET bindUdpSocket(int addrfamily, int bufferSize) {
LC_ASSERT(addrfamily == AF_INET || addrfamily == AF_INET6); LC_ASSERT(addrfamily == AF_INET || addrfamily == AF_INET6);
s = createSocket(addrfamily, SOCK_DGRAM, IPPROTO_UDP, 0); s = createSocket(addrfamily, SOCK_DGRAM, IPPROTO_UDP, false);
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
return INVALID_SOCKET; return INVALID_SOCKET;
} }
@@ -267,7 +267,8 @@ SOCKET bindUdpSocket(int addrfamily, int bufferSize) {
return s; return s;
} }
int setSocketNonBlocking(SOCKET s, int val) { int setSocketNonBlocking(SOCKET s, bool enabled) {
int val = enabled ? 1 : 0;
#if defined(__vita__) #if defined(__vita__)
return setsockopt(s, SOL_SOCKET, SO_NONBLOCK, (char*)&val, sizeof(val)); return setsockopt(s, SOL_SOCKET, SO_NONBLOCK, (char*)&val, sizeof(val));
#elif defined(FIONBIO) #elif defined(FIONBIO)
@@ -277,7 +278,7 @@ int setSocketNonBlocking(SOCKET s, int val) {
#endif #endif
} }
SOCKET createSocket(int addressFamily, int socketType, int protocol, int nonBlocking) { SOCKET createSocket(int addressFamily, int socketType, int protocol, bool nonBlocking) {
SOCKET s; SOCKET s;
s = socket(addressFamily, socketType, protocol); s = socket(addressFamily, socketType, protocol);
@@ -295,7 +296,7 @@ SOCKET createSocket(int addressFamily, int socketType, int protocol, int nonBloc
#endif #endif
if (nonBlocking) { if (nonBlocking) {
setSocketNonBlocking(s, 1); setSocketNonBlocking(s, true);
} }
return s; return s;
@@ -309,7 +310,7 @@ SOCKET connectTcpSocket(struct sockaddr_storage* dstaddr, SOCKADDR_LEN addrlen,
int val; int val;
// Create a non-blocking TCP socket // Create a non-blocking TCP socket
s = createSocket(dstaddr->ss_family, SOCK_STREAM, IPPROTO_TCP, 1); s = createSocket(dstaddr->ss_family, SOCK_STREAM, IPPROTO_TCP, true);
if (s == INVALID_SOCKET) { if (s == INVALID_SOCKET) {
return INVALID_SOCKET; return INVALID_SOCKET;
} }
@@ -397,7 +398,7 @@ SOCKET connectTcpSocket(struct sockaddr_storage* dstaddr, SOCKADDR_LEN addrlen,
} }
// Disable non-blocking I/O now that the connection is established // Disable non-blocking I/O now that the connection is established
setSocketNonBlocking(s, 0); setSocketNonBlocking(s, false);
Exit: Exit:
if (err != 0) { if (err != 0) {
@@ -492,20 +493,20 @@ int resolveHostName(const char* host, int family, int tcpTestPort, struct sockad
return -1; return -1;
} }
int isInSubnetV6(struct sockaddr_in6* sin6, unsigned char* subnet, int prefixLength) { bool isInSubnetV6(struct sockaddr_in6* sin6, unsigned char* subnet, int prefixLength) {
int i; int i;
for (i = 0; i < prefixLength; i++) { for (i = 0; i < prefixLength; i++) {
unsigned char mask = 1 << (i % 8); unsigned char mask = 1 << (i % 8);
if ((sin6->sin6_addr.s6_addr[i / 8] & mask) != (subnet[i / 8] & mask)) { if ((sin6->sin6_addr.s6_addr[i / 8] & mask) != (subnet[i / 8] & mask)) {
return 0; return false;
} }
} }
return 1; return true;
} }
int isPrivateNetworkAddress(struct sockaddr_storage* address) { bool isPrivateNetworkAddress(struct sockaddr_storage* address) {
// We only count IPv4 addresses as possibly private for now // We only count IPv4 addresses as possibly private for now
if (address->ss_family == AF_INET) { if (address->ss_family == AF_INET) {
@@ -516,19 +517,19 @@ int isPrivateNetworkAddress(struct sockaddr_storage* address) {
// 10.0.0.0/8 // 10.0.0.0/8
if ((addr & 0xFF000000) == 0x0A000000) { if ((addr & 0xFF000000) == 0x0A000000) {
return 1; return true;
} }
// 172.16.0.0/12 // 172.16.0.0/12
else if ((addr & 0xFFF00000) == 0xAC100000) { else if ((addr & 0xFFF00000) == 0xAC100000) {
return 1; return true;
} }
// 192.168.0.0/16 // 192.168.0.0/16
else if ((addr & 0xFFFF0000) == 0xC0A80000) { else if ((addr & 0xFFFF0000) == 0xC0A80000) {
return 1; return true;
} }
// 169.254.0.0/16 // 169.254.0.0/16
else if ((addr & 0xFFFF0000) == 0xA9FE0000) { else if ((addr & 0xFFFF0000) == 0xA9FE0000) {
return 1; return true;
} }
} }
else if (address->ss_family == AF_INET6) { else if (address->ss_family == AF_INET6) {
@@ -539,19 +540,19 @@ int isPrivateNetworkAddress(struct sockaddr_storage* address) {
// fe80::/10 // fe80::/10
if (isInSubnetV6(sin6, linkLocalPrefix, 10)) { if (isInSubnetV6(sin6, linkLocalPrefix, 10)) {
return 1; return true;
} }
// fec0::/10 // fec0::/10
else if (isInSubnetV6(sin6, siteLocalPrefix, 10)) { else if (isInSubnetV6(sin6, siteLocalPrefix, 10)) {
return 1; return true;
} }
// fc00::/7 // fc00::/7
else if (isInSubnetV6(sin6, uniqueLocalPrefix, 7)) { else if (isInSubnetV6(sin6, uniqueLocalPrefix, 7)) {
return 1; return true;
} }
} }
return 0; return false;
} }
// Enable platform-specific low latency options (best-effort) // Enable platform-specific low latency options (best-effort)
+4 -4
View File
@@ -68,18 +68,18 @@ typedef socklen_t SOCKADDR_LEN;
#define URLSAFESTRING_LEN (INET6_ADDRSTRLEN+2) #define URLSAFESTRING_LEN (INET6_ADDRSTRLEN+2)
void addrToUrlSafeString(struct sockaddr_storage* addr, char* string); void addrToUrlSafeString(struct sockaddr_storage* addr, char* string);
SOCKET createSocket(int addressFamily, int socketType, int protocol, int nonBlocking); SOCKET createSocket(int addressFamily, int socketType, int protocol, bool nonBlocking);
SOCKET connectTcpSocket(struct sockaddr_storage* dstaddr, SOCKADDR_LEN addrlen, unsigned short port, int timeoutSec); SOCKET connectTcpSocket(struct sockaddr_storage* dstaddr, SOCKADDR_LEN addrlen, unsigned short port, int timeoutSec);
int sendMtuSafe(SOCKET s, char* buffer, int size); int sendMtuSafe(SOCKET s, char* buffer, int size);
SOCKET bindUdpSocket(int addrfamily, int bufferSize); SOCKET bindUdpSocket(int addrfamily, int bufferSize);
int enableNoDelay(SOCKET s); int enableNoDelay(SOCKET s);
int setSocketNonBlocking(SOCKET s, int val); int setSocketNonBlocking(SOCKET s, bool enabled);
int recvUdpSocket(SOCKET s, char* buffer, int size, int useSelect); int recvUdpSocket(SOCKET s, char* buffer, int size, bool useSelect);
void shutdownTcpSocket(SOCKET s); void shutdownTcpSocket(SOCKET s);
int setNonFatalRecvTimeoutMs(SOCKET s, int timeoutMs); int setNonFatalRecvTimeoutMs(SOCKET s, int timeoutMs);
void setRecvTimeout(SOCKET s, int timeoutSec); void setRecvTimeout(SOCKET s, int timeoutSec);
void closeSocket(SOCKET s); void closeSocket(SOCKET s);
int isPrivateNetworkAddress(struct sockaddr_storage* address); bool isPrivateNetworkAddress(struct sockaddr_storage* address);
int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs); int pollSockets(struct pollfd* pollFds, int pollFdsCount, int timeoutMs);
#define TCP_PORT_MASK 0xFFFF #define TCP_PORT_MASK 0xFFFF
+6 -6
View File
@@ -10,31 +10,31 @@ typedef HANDLE PLT_MUTEX;
typedef HANDLE PLT_EVENT; typedef HANDLE PLT_EVENT;
typedef struct _PLT_THREAD { typedef struct _PLT_THREAD {
HANDLE handle; HANDLE handle;
int cancelled; bool cancelled;
} PLT_THREAD; } PLT_THREAD;
#elif defined(__vita__) #elif defined(__vita__)
typedef int PLT_MUTEX; typedef int PLT_MUTEX;
typedef struct _PLT_EVENT { typedef struct _PLT_EVENT {
int mutex; int mutex;
int cond; int cond;
int signalled; bool signalled;
} PLT_EVENT; } PLT_EVENT;
typedef struct _PLT_THREAD { typedef struct _PLT_THREAD {
int handle; int handle;
int cancelled; int cancelled;
void *context; void *context;
int alive; bool alive;
} PLT_THREAD; } PLT_THREAD;
#elif defined (LC_POSIX) #elif defined (LC_POSIX)
typedef pthread_mutex_t PLT_MUTEX; typedef pthread_mutex_t PLT_MUTEX;
typedef struct _PLT_EVENT { typedef struct _PLT_EVENT {
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond; pthread_cond_t cond;
int signalled; bool signalled;
} PLT_EVENT; } PLT_EVENT;
typedef struct _PLT_THREAD { typedef struct _PLT_THREAD {
pthread_t thread; pthread_t thread;
int cancelled; bool cancelled;
} PLT_THREAD; } PLT_THREAD;
#else #else
#error Unsupported platform #error Unsupported platform
@@ -48,7 +48,7 @@ void PltUnlockMutex(PLT_MUTEX* mutex);
int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread); int PltCreateThread(const char* name, ThreadEntry entry, void* context, PLT_THREAD* thread);
void PltCloseThread(PLT_THREAD* thread); void PltCloseThread(PLT_THREAD* thread);
void PltInterruptThread(PLT_THREAD* thread); void PltInterruptThread(PLT_THREAD* thread);
int PltIsThreadInterrupted(PLT_THREAD* thread); bool PltIsThreadInterrupted(PLT_THREAD* thread);
void PltJoinThread(PLT_THREAD* thread); void PltJoinThread(PLT_THREAD* thread);
int PltCreateEvent(PLT_EVENT* event); int PltCreateEvent(PLT_EVENT* event);
+5 -5
View File
@@ -25,7 +25,7 @@ void RtpfCleanupQueue(PRTP_FEC_QUEUE queue) {
} }
// newEntry is contained within the packet buffer so we free the whole entry by freeing entry->packet // newEntry is contained within the packet buffer so we free the whole entry by freeing entry->packet
static int queuePacket(PRTP_FEC_QUEUE queue, PRTPFEC_QUEUE_ENTRY newEntry, int head, PRTP_PACKET packet, int length, int isParity) { static bool queuePacket(PRTP_FEC_QUEUE queue, PRTPFEC_QUEUE_ENTRY newEntry, bool head, PRTP_PACKET packet, int length, bool isParity) {
PRTPFEC_QUEUE_ENTRY entry; PRTPFEC_QUEUE_ENTRY entry;
LC_ASSERT(!isBefore16(packet->sequenceNumber, queue->nextContiguousSequenceNumber)); LC_ASSERT(!isBefore16(packet->sequenceNumber, queue->nextContiguousSequenceNumber));
@@ -41,7 +41,7 @@ static int queuePacket(PRTP_FEC_QUEUE queue, PRTPFEC_QUEUE_ENTRY newEntry, int h
entry = queue->bufferHead; entry = queue->bufferHead;
while (entry != NULL) { while (entry != NULL) {
if (entry->packet->sequenceNumber == packet->sequenceNumber) { if (entry->packet->sequenceNumber == packet->sequenceNumber) {
return 0; return false;
} }
entry = entry->next; entry = entry->next;
@@ -79,7 +79,7 @@ static int queuePacket(PRTP_FEC_QUEUE queue, PRTPFEC_QUEUE_ENTRY newEntry, int h
} }
queue->bufferSize++; queue->bufferSize++;
return 1; return true;
} }
#define PACKET_RECOVERY_FAILURE() \ #define PACKET_RECOVERY_FAILURE() \
@@ -295,7 +295,7 @@ cleanup_packets:
// it may be a legitimate part of the H.264 bytestream. // it may be a legitimate part of the H.264 bytestream.
LC_ASSERT(isBefore16(rtpPacket->sequenceNumber, queue->bufferFirstParitySequenceNumber)); LC_ASSERT(isBefore16(rtpPacket->sequenceNumber, queue->bufferFirstParitySequenceNumber));
queuePacket(queue, queueEntry, 0, rtpPacket, StreamConfig.packetSize + dataOffset, 0); queuePacket(queue, queueEntry, false, rtpPacket, StreamConfig.packetSize + dataOffset, false);
} else if (packets[i] != NULL) { } else if (packets[i] != NULL) {
free(packets[i]); free(packets[i]);
} }
@@ -464,7 +464,7 @@ int RtpfAddPacket(PRTP_FEC_QUEUE queue, PRTP_PACKET packet, int length, PRTPFEC_
LC_ASSERT((nvPacket->fecInfo & 0xFFC00000) >> 22 == queue->bufferDataPackets); LC_ASSERT((nvPacket->fecInfo & 0xFFC00000) >> 22 == queue->bufferDataPackets);
LC_ASSERT((nvPacket->flags & FLAG_EOF) || length - dataOffset == StreamConfig.packetSize); LC_ASSERT((nvPacket->flags & FLAG_EOF) || length - dataOffset == StreamConfig.packetSize);
if (!queuePacket(queue, packetEntry, 0, packet, length, !isBefore16(packet->sequenceNumber, queue->bufferFirstParitySequenceNumber))) { if (!queuePacket(queue, packetEntry, false, packet, length, !isBefore16(packet->sequenceNumber, queue->bufferFirstParitySequenceNumber))) {
return RTPF_RET_REJECTED; return RTPF_RET_REJECTED;
} }
else { else {
+1 -1
View File
@@ -5,7 +5,7 @@
typedef struct _RTPFEC_QUEUE_ENTRY { typedef struct _RTPFEC_QUEUE_ENTRY {
PRTP_PACKET packet; PRTP_PACKET packet;
int length; int length;
int isParity; bool isParity;
unsigned long long receiveTimeMs; unsigned long long receiveTimeMs;
unsigned int presentationTimeMs; unsigned int presentationTimeMs;
+9 -9
View File
@@ -18,7 +18,7 @@ void RtpqCleanupQueue(PRTP_REORDER_QUEUE queue) {
} }
// newEntry is contained within the packet buffer so we free the whole entry by freeing entry->packet // newEntry is contained within the packet buffer so we free the whole entry by freeing entry->packet
static int queuePacket(PRTP_REORDER_QUEUE queue, PRTP_QUEUE_ENTRY newEntry, int head, PRTP_PACKET packet) { static bool queuePacket(PRTP_REORDER_QUEUE queue, PRTP_QUEUE_ENTRY newEntry, bool head, PRTP_PACKET packet) {
PRTP_QUEUE_ENTRY entry; PRTP_QUEUE_ENTRY entry;
LC_ASSERT(!isBefore16(packet->sequenceNumber, queue->nextRtpSequenceNumber)); LC_ASSERT(!isBefore16(packet->sequenceNumber, queue->nextRtpSequenceNumber));
@@ -27,7 +27,7 @@ static int queuePacket(PRTP_REORDER_QUEUE queue, PRTP_QUEUE_ENTRY newEntry, int
entry = queue->queueHead; entry = queue->queueHead;
while (entry != NULL) { while (entry != NULL) {
if (entry->packet->sequenceNumber == packet->sequenceNumber) { if (entry->packet->sequenceNumber == packet->sequenceNumber) {
return 0; return false;
} }
entry = entry->next; entry = entry->next;
@@ -64,7 +64,7 @@ static int queuePacket(PRTP_REORDER_QUEUE queue, PRTP_QUEUE_ENTRY newEntry, int
} }
queue->queueSize++; queue->queueSize++;
return 1; return true;
} }
static void updateOldestQueued(PRTP_REORDER_QUEUE queue) { static void updateOldestQueued(PRTP_REORDER_QUEUE queue) {
@@ -126,7 +126,7 @@ static void removeEntry(PRTP_REORDER_QUEUE queue, PRTP_QUEUE_ENTRY entry) {
} }
static PRTP_QUEUE_ENTRY enforceQueueConstraints(PRTP_REORDER_QUEUE queue) { static PRTP_QUEUE_ENTRY enforceQueueConstraints(PRTP_REORDER_QUEUE queue) {
int dequeuePacket = 0; bool dequeuePacket = false;
// Empty queue is fine // Empty queue is fine
if (queue->queueHead == NULL) { if (queue->queueHead == NULL) {
@@ -136,7 +136,7 @@ static PRTP_QUEUE_ENTRY enforceQueueConstraints(PRTP_REORDER_QUEUE queue) {
// Check that the queue's time constraint is satisfied // Check that the queue's time constraint is satisfied
if (PltGetMillis() - queue->oldestQueuedTimeMs > queue->maxQueueTimeMs) { if (PltGetMillis() - queue->oldestQueuedTimeMs > queue->maxQueueTimeMs) {
Limelog("Returning RTP packet queued for too long\n"); Limelog("Returning RTP packet queued for too long\n");
dequeuePacket = 1; dequeuePacket = true;
} }
// Check that the queue's size constraint is satisfied. We subtract one // Check that the queue's size constraint is satisfied. We subtract one
@@ -144,7 +144,7 @@ static PRTP_QUEUE_ENTRY enforceQueueConstraints(PRTP_REORDER_QUEUE queue) {
// the current packet is enqueued. // the current packet is enqueued.
if (!dequeuePacket && queue->queueSize == queue->maxSize - 1) { if (!dequeuePacket && queue->queueSize == queue->maxSize - 1) {
Limelog("Returning RTP packet after queue overgrowth\n"); Limelog("Returning RTP packet after queue overgrowth\n");
dequeuePacket = 1; dequeuePacket = true;
} }
if (dequeuePacket) { if (dequeuePacket) {
@@ -172,7 +172,7 @@ int RtpqAddPacket(PRTP_REORDER_QUEUE queue, PRTP_PACKET packet, PRTP_QUEUE_ENTRY
} }
else { else {
// Queue is empty currently so we'll put this packet on there // Queue is empty currently so we'll put this packet on there
if (!queuePacket(queue, packetEntry, 0, packet)) { if (!queuePacket(queue, packetEntry, false, packet)) {
return 0; return 0;
} }
else { else {
@@ -204,7 +204,7 @@ int RtpqAddPacket(PRTP_REORDER_QUEUE queue, PRTP_PACKET packet, PRTP_QUEUE_ENTRY
// Queue has data inside, so we need to see where this packet fits // Queue has data inside, so we need to see where this packet fits
if (packet->sequenceNumber == queue->nextRtpSequenceNumber) { if (packet->sequenceNumber == queue->nextRtpSequenceNumber) {
// It fits in a hole where we need a packet, now we have some ready // It fits in a hole where we need a packet, now we have some ready
if (!queuePacket(queue, packetEntry, 0, packet)) { if (!queuePacket(queue, packetEntry, false, packet)) {
return 0; return 0;
} }
else { else {
@@ -212,7 +212,7 @@ int RtpqAddPacket(PRTP_REORDER_QUEUE queue, PRTP_PACKET packet, PRTP_QUEUE_ENTRY
} }
} }
else { else {
if (!queuePacket(queue, packetEntry, 0, packet)) { if (!queuePacket(queue, packetEntry, false, packet)) {
return 0; return 0;
} }
else { else {
+1
View File
@@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h>
#define TYPE_REQUEST 0 #define TYPE_REQUEST 0
#define TYPE_RESPONSE 1 #define TYPE_RESPONSE 1
+45 -45
View File
@@ -8,10 +8,10 @@
static int currentSeqNumber; static int currentSeqNumber;
static char rtspTargetUrl[256]; static char rtspTargetUrl[256];
static char* sessionIdString; static char* sessionIdString;
static int hasSessionId; static bool hasSessionId;
static int rtspClientVersion; static int rtspClientVersion;
static char urlAddr[URLSAFESTRING_LEN]; static char urlAddr[URLSAFESTRING_LEN];
static int useEnet; static bool useEnet;
static SOCKET sock = INVALID_SOCKET; static SOCKET sock = INVALID_SOCKET;
static ENetHost* client; static ENetHost* client;
@@ -48,21 +48,21 @@ static POPTION_ITEM createOptionItem(char* option, char* content)
} }
// Add an option to the RTSP Message // Add an option to the RTSP Message
static int addOption(PRTSP_MESSAGE msg, char* option, char* content) static bool addOption(PRTSP_MESSAGE msg, char* option, char* content)
{ {
POPTION_ITEM item = createOptionItem(option, content); POPTION_ITEM item = createOptionItem(option, content);
if (item == NULL) { if (item == NULL) {
return 0; return false;
} }
insertOption(&msg->options, item); insertOption(&msg->options, item);
msg->flags |= FLAG_ALLOCATED_OPTION_ITEMS; msg->flags |= FLAG_ALLOCATED_OPTION_ITEMS;
return 1; return true;
} }
// Create an RTSP Request // Create an RTSP Request
static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target) static bool initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
{ {
char sequenceNumberStr[16]; char sequenceNumberStr[16];
char clientVersionStr[16]; char clientVersionStr[16];
@@ -77,14 +77,14 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
!addOption(msg, "X-GS-ClientVersion", clientVersionStr) || !addOption(msg, "X-GS-ClientVersion", clientVersionStr) ||
(!useEnet && !addOption(msg, "Host", urlAddr))) { (!useEnet && !addOption(msg, "Host", urlAddr))) {
freeMessage(msg); freeMessage(msg);
return 0; return false;
} }
return 1; return true;
} }
// Send RTSP message and get response over ENet // Send RTSP message and get response over ENet
static int transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int expectingPayload, int* error) { static bool transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE response, bool expectingPayload, int* error) {
ENetEvent event; ENetEvent event;
char* serializedMessage; char* serializedMessage;
int messageLen; int messageLen;
@@ -92,11 +92,11 @@ static int transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE response
ENetPacket* packet; ENetPacket* packet;
char* payload; char* payload;
int payloadLength; int payloadLength;
int ret; bool ret;
char* responseBuffer; char* responseBuffer;
*error = -1; *error = -1;
ret = 0; ret = false;
responseBuffer = NULL; responseBuffer = NULL;
// We're going to handle the payload separately, so temporarily set the payload to NULL // We're going to handle the payload separately, so temporarily set the payload to NULL
@@ -183,7 +183,7 @@ static int transactRtspMessageEnet(PRTSP_MESSAGE request, PRTSP_MESSAGE response
if (parseRtspMessage(response, responseBuffer, offset) == RTSP_ERROR_SUCCESS) { if (parseRtspMessage(response, responseBuffer, offset) == RTSP_ERROR_SUCCESS) {
// Successfully parsed response // Successfully parsed response
ret = 1; ret = true;
} }
else { else {
Limelog("Failed to parse RTSP response\n"); Limelog("Failed to parse RTSP response\n");
@@ -208,9 +208,9 @@ Exit:
} }
// Send RTSP message and get response over TCP // Send RTSP message and get response over TCP
static int transactRtspMessageTcp(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int expectingPayload, int* error) { static bool transactRtspMessageTcp(PRTSP_MESSAGE request, PRTSP_MESSAGE response, bool expectingPayload, int* error) {
SOCK_RET err; SOCK_RET err;
int ret; bool ret;
int offset; int offset;
char* serializedMessage = NULL; char* serializedMessage = NULL;
int messageLen; int messageLen;
@@ -218,7 +218,7 @@ static int transactRtspMessageTcp(PRTSP_MESSAGE request, PRTSP_MESSAGE response,
int responseBufferSize; int responseBufferSize;
*error = -1; *error = -1;
ret = 0; ret = false;
responseBuffer = NULL; responseBuffer = NULL;
sock = connectTcpSocket(&RemoteAddr, RemoteAddrLen, 48010, RTSP_TIMEOUT_SEC); sock = connectTcpSocket(&RemoteAddr, RemoteAddrLen, 48010, RTSP_TIMEOUT_SEC);
@@ -276,7 +276,7 @@ static int transactRtspMessageTcp(PRTSP_MESSAGE request, PRTSP_MESSAGE response,
if (parseRtspMessage(response, responseBuffer, offset) == RTSP_ERROR_SUCCESS) { if (parseRtspMessage(response, responseBuffer, offset) == RTSP_ERROR_SUCCESS) {
// Successfully parsed response // Successfully parsed response
ret = 1; ret = true;
} }
else { else {
Limelog("Failed to parse RTSP response\n"); Limelog("Failed to parse RTSP response\n");
@@ -296,7 +296,7 @@ Exit:
return ret; return ret;
} }
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, int expectingPayload, int* error) { static bool transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, bool expectingPayload, int* error) {
if (useEnet) { if (useEnet) {
return transactRtspMessageEnet(request, response, expectingPayload, error); return transactRtspMessageEnet(request, response, expectingPayload, error);
} }
@@ -306,15 +306,15 @@ static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response, in
} }
// Send RTSP OPTIONS request // Send RTSP OPTIONS request
static int requestOptions(PRTSP_MESSAGE response, int* error) { static bool requestOptions(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; bool ret;
*error = -1; *error = -1;
ret = initializeRtspRequest(&request, "OPTIONS", rtspTargetUrl); ret = initializeRtspRequest(&request, "OPTIONS", rtspTargetUrl);
if (ret != 0) { if (ret) {
ret = transactRtspMessage(&request, response, 0, error); ret = transactRtspMessage(&request, response, false, error);
freeMessage(&request); freeMessage(&request);
} }
@@ -322,22 +322,22 @@ static int requestOptions(PRTSP_MESSAGE response, int* error) {
} }
// Send RTSP DESCRIBE request // Send RTSP DESCRIBE request
static int requestDescribe(PRTSP_MESSAGE response, int* error) { static bool requestDescribe(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; bool ret;
*error = -1; *error = -1;
ret = initializeRtspRequest(&request, "DESCRIBE", rtspTargetUrl); ret = initializeRtspRequest(&request, "DESCRIBE", rtspTargetUrl);
if (ret != 0) { if (ret) {
if (addOption(&request, "Accept", if (addOption(&request, "Accept",
"application/sdp") && "application/sdp") &&
addOption(&request, "If-Modified-Since", addOption(&request, "If-Modified-Since",
"Thu, 01 Jan 1970 00:00:00 GMT")) { "Thu, 01 Jan 1970 00:00:00 GMT")) {
ret = transactRtspMessage(&request, response, 1, error); ret = transactRtspMessage(&request, response, true, error);
} }
else { else {
ret = 0; ret = false;
} }
freeMessage(&request); freeMessage(&request);
} }
@@ -346,18 +346,18 @@ static int requestDescribe(PRTSP_MESSAGE response, int* error) {
} }
// Send RTSP SETUP request // Send RTSP SETUP request
static int setupStream(PRTSP_MESSAGE response, char* target, int* error) { static bool setupStream(PRTSP_MESSAGE response, char* target, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; bool ret;
char* transportValue; char* transportValue;
*error = -1; *error = -1;
ret = initializeRtspRequest(&request, "SETUP", target); ret = initializeRtspRequest(&request, "SETUP", target);
if (ret != 0) { if (ret) {
if (hasSessionId) { if (hasSessionId) {
if (!addOption(&request, "Session", sessionIdString)) { if (!addOption(&request, "Session", sessionIdString)) {
ret = 0; ret = false;
goto FreeMessage; goto FreeMessage;
} }
} }
@@ -375,10 +375,10 @@ static int setupStream(PRTSP_MESSAGE response, char* target, int* error) {
if (addOption(&request, "Transport", transportValue) && if (addOption(&request, "Transport", transportValue) &&
addOption(&request, "If-Modified-Since", addOption(&request, "If-Modified-Since",
"Thu, 01 Jan 1970 00:00:00 GMT")) { "Thu, 01 Jan 1970 00:00:00 GMT")) {
ret = transactRtspMessage(&request, response, 0, error); ret = transactRtspMessage(&request, response, false, error);
} }
else { else {
ret = 0; ret = false;
} }
FreeMessage: FreeMessage:
@@ -389,19 +389,19 @@ static int setupStream(PRTSP_MESSAGE response, char* target, int* error) {
} }
// Send RTSP PLAY request // Send RTSP PLAY request
static int playStream(PRTSP_MESSAGE response, char* target, int* error) { static bool playStream(PRTSP_MESSAGE response, char* target, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; bool ret;
*error = -1; *error = -1;
ret = initializeRtspRequest(&request, "PLAY", target); ret = initializeRtspRequest(&request, "PLAY", target);
if (ret != 0) { if (ret != 0) {
if (addOption(&request, "Session", sessionIdString)) { if (addOption(&request, "Session", sessionIdString)) {
ret = transactRtspMessage(&request, response, 0, error); ret = transactRtspMessage(&request, response, false, error);
} }
else { else {
ret = 0; ret = false;
} }
freeMessage(&request); freeMessage(&request);
} }
@@ -410,17 +410,17 @@ static int playStream(PRTSP_MESSAGE response, char* target, int* error) {
} }
// Send RTSP ANNOUNCE message // Send RTSP ANNOUNCE message
static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) { static bool sendVideoAnnounce(PRTSP_MESSAGE response, int* error) {
RTSP_MESSAGE request; RTSP_MESSAGE request;
int ret; bool ret;
int payloadLength; int payloadLength;
char payloadLengthStr[16]; char payloadLengthStr[16];
*error = -1; *error = -1;
ret = initializeRtspRequest(&request, "ANNOUNCE", "streamid=video"); ret = initializeRtspRequest(&request, "ANNOUNCE", "streamid=video");
if (ret != 0) { if (ret) {
ret = 0; ret = false;
if (!addOption(&request, "Session", sessionIdString) || if (!addOption(&request, "Session", sessionIdString) ||
!addOption(&request, "Content-type", "application/sdp")) { !addOption(&request, "Content-type", "application/sdp")) {
@@ -439,7 +439,7 @@ static int sendVideoAnnounce(PRTSP_MESSAGE response, int* error) {
goto FreeMessage; goto FreeMessage;
} }
ret = transactRtspMessage(&request, response, 0, error); ret = transactRtspMessage(&request, response, false, error);
FreeMessage: FreeMessage:
freeMessage(&request); freeMessage(&request);
@@ -484,7 +484,7 @@ static int parseOpusConfigFromParamString(char* paramStr, int channelCount, POPU
// Parses the Opus configuration from an RTSP DESCRIBE response // Parses the Opus configuration from an RTSP DESCRIBE response
static int parseOpusConfigurations(PRTSP_MESSAGE response) { static int parseOpusConfigurations(PRTSP_MESSAGE response) {
HighQualitySurroundSupported = 0; HighQualitySurroundSupported = false;
memset(&NormalQualityOpusConfig, 0, sizeof(NormalQualityOpusConfig)); memset(&NormalQualityOpusConfig, 0, sizeof(NormalQualityOpusConfig));
memset(&HighQualityOpusConfig, 0, sizeof(HighQualityOpusConfig)); memset(&HighQualityOpusConfig, 0, sizeof(HighQualityOpusConfig));
@@ -549,7 +549,7 @@ static int parseOpusConfigurations(PRTSP_MESSAGE response) {
} }
// We can request high quality audio // We can request high quality audio
HighQualitySurroundSupported = 1; HighQualitySurroundSupported = true;
} }
} }
else { else {
@@ -603,7 +603,7 @@ int performRtspHandshake(void) {
useEnet = (AppVersionQuad[0] >= 5) && (AppVersionQuad[0] <= 7) && (AppVersionQuad[2] < 404); useEnet = (AppVersionQuad[0] >= 5) && (AppVersionQuad[0] <= 7) && (AppVersionQuad[2] < 404);
sprintf(rtspTargetUrl, "rtsp%s://%s:48010", useEnet ? "ru" : "", urlAddr); sprintf(rtspTargetUrl, "rtsp%s://%s:48010", useEnet ? "ru" : "", urlAddr);
currentSeqNumber = 1; currentSeqNumber = 1;
hasSessionId = 0; hasSessionId = false;
switch (AppVersionQuad[0]) { switch (AppVersionQuad[0]) {
case 3: case 3:
@@ -777,7 +777,7 @@ int performRtspHandshake(void) {
goto Exit; goto Exit;
} }
hasSessionId = 1; hasSessionId = true;
freeMessage(&response); freeMessage(&response);
} }
+5 -10
View File
@@ -1,13 +1,8 @@
#include "Rtsp.h" #include "Rtsp.h"
// Check if String s begins with the given prefix // Check if String s begins with the given prefix
static int startsWith(const char* s, const char* prefix) { static bool startsWith(const char* s, const char* prefix) {
if (strncmp(s, prefix, strlen(prefix)) == 0) { return strncmp(s, prefix, strlen(prefix)) == 0;
return 1;
}
else {
return 0;
}
} }
// Gets the length of the message // Gets the length of the message
@@ -65,7 +60,7 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
char* command; char* command;
char* sequence; char* sequence;
char flag; char flag;
char messageEnded = 0; bool messageEnded = false;
char* payload = NULL; char* payload = NULL;
char* opt = NULL; char* opt = NULL;
@@ -175,13 +170,13 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
// See if we've hit the end of the message. The first \r is missing because it's been tokenized // See if we've hit the end of the message. The first \r is missing because it's been tokenized
if (startsWith(endCheck, "\n") && endCheck[1] == '\0') { if (startsWith(endCheck, "\n") && endCheck[1] == '\0') {
// RTSP over ENet doesn't always have the second CRLF for some reason // RTSP over ENet doesn't always have the second CRLF for some reason
messageEnded = 1; messageEnded = true;
break; break;
} }
else if (startsWith(endCheck, "\n\r\n")) { else if (startsWith(endCheck, "\n\r\n")) {
// We've encountered the end of the message - mark it thus // We've encountered the end of the message - mark it thus
messageEnded = 1; messageEnded = true;
// The payload is the remainder of messageBuffer. If none, then payload = null // The payload is the remainder of messageBuffer. If none, then payload = null
if (endCheck[3] != '\0') if (endCheck[3] != '\0')
+3 -3
View File
@@ -365,14 +365,14 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) {
// Let the audio stream code know that it needs to disable coupled streams when // Let the audio stream code know that it needs to disable coupled streams when
// decoding this audio stream. // decoding this audio stream.
HighQualitySurroundEnabled = 1; HighQualitySurroundEnabled = true;
// Use 5 ms frames since we don't have a slow decoder // Use 5 ms frames since we don't have a slow decoder
AudioPacketDuration = 5; AudioPacketDuration = 5;
} }
else { else {
err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0"); err |= addAttributeString(&optionHead, "x-nv-audio.surround.AudioQuality", "0");
HighQualitySurroundEnabled = 0; HighQualitySurroundEnabled = false;
if ((AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) != 0) { if ((AudioCallbacks.capabilities & CAPABILITY_SLOW_OPUS_DECODER) != 0) {
// Use 20 ms packets for slow decoders to save CPU time // Use 20 ms packets for slow decoders to save CPU time
@@ -397,7 +397,7 @@ static PSDP_OPTION getAttributesList(char*urlSafeAddr) {
AudioPacketDuration = 5; AudioPacketDuration = 5;
// High quality audio mode not supported on legacy servers // High quality audio mode not supported on legacy servers
HighQualitySurroundEnabled = 0; HighQualitySurroundEnabled = false;
} }
if (AppVersionQuad[0] >= 7) { if (AppVersionQuad[0] >= 7) {
+2 -2
View File
@@ -104,12 +104,12 @@ int LiFindExternalAddressIP4(const char* stunServer, unsigned short stunPort, un
// Wait UDP_RECV_POLL_TIMEOUT_MS before moving on to the next server to // Wait UDP_RECV_POLL_TIMEOUT_MS before moving on to the next server to
// avoid having to spam the other STUN servers if we find a working one. // avoid having to spam the other STUN servers if we find a working one.
bytesRead = recvUdpSocket(sock, resp.buf, sizeof(resp.buf), 1); bytesRead = recvUdpSocket(sock, resp.buf, sizeof(resp.buf), true);
} }
} }
else { else {
// This waits in UDP_RECV_POLL_TIMEOUT_MS increments // This waits in UDP_RECV_POLL_TIMEOUT_MS increments
bytesRead = recvUdpSocket(sock, resp.buf, sizeof(resp.buf), 1); bytesRead = recvUdpSocket(sock, resp.buf, sizeof(resp.buf), true);
} }
} }
+1 -1
View File
@@ -8,7 +8,7 @@ typedef struct _QUEUED_DECODE_UNIT {
} QUEUED_DECODE_UNIT, *PQUEUED_DECODE_UNIT; } QUEUED_DECODE_UNIT, *PQUEUED_DECODE_UNIT;
void completeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu, int drStatus); void completeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu, int drStatus);
int getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT* qdu); bool getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT* qdu);
#pragma pack(push, 1) #pragma pack(push, 1)
+48 -59
View File
@@ -9,15 +9,15 @@ static int nalChainDataLength;
static unsigned int nextFrameNumber; static unsigned int nextFrameNumber;
static unsigned int startFrameNumber; static unsigned int startFrameNumber;
static int waitingForNextSuccessfulFrame; static bool waitingForNextSuccessfulFrame;
static int waitingForIdrFrame; static bool waitingForIdrFrame;
static unsigned int lastPacketInStream; static unsigned int lastPacketInStream;
static int decodingFrame; static bool decodingFrame;
static int strictIdrFrameWait; static bool strictIdrFrameWait;
static unsigned long long firstPacketReceiveTime; static unsigned long long firstPacketReceiveTime;
static unsigned int firstPacketPresentationTime; static unsigned int firstPacketPresentationTime;
static int dropStatePending; static bool dropStatePending;
static int idrFrameProcessed; static bool idrFrameProcessed;
#define DR_CLEANUP -1000 #define DR_CLEANUP -1000
@@ -43,14 +43,14 @@ void initializeVideoDepacketizer(int pktSize) {
nextFrameNumber = 1; nextFrameNumber = 1;
startFrameNumber = 0; startFrameNumber = 0;
waitingForNextSuccessfulFrame = 0; waitingForNextSuccessfulFrame = false;
waitingForIdrFrame = 1; waitingForIdrFrame = true;
lastPacketInStream = UINT32_MAX; lastPacketInStream = UINT32_MAX;
decodingFrame = 0; decodingFrame = false;
firstPacketReceiveTime = 0; firstPacketReceiveTime = 0;
firstPacketPresentationTime = 0; firstPacketPresentationTime = 0;
dropStatePending = 0; dropStatePending = false;
idrFrameProcessed = 0; idrFrameProcessed = false;
strictIdrFrameWait = !isReferenceFrameInvalidationEnabled(); strictIdrFrameWait = !isReferenceFrameInvalidationEnabled();
} }
@@ -75,12 +75,12 @@ static void dropFrameState(void) {
LC_ASSERT(!decodingFrame); LC_ASSERT(!decodingFrame);
// We're dropping frame state now // We're dropping frame state now
dropStatePending = 0; dropStatePending = false;
// We'll need an IDR frame now if we're in strict mode // We'll need an IDR frame now if we're in strict mode
// or if we've never seen one before // or if we've never seen one before
if (strictIdrFrameWait || !idrFrameProcessed) { if (strictIdrFrameWait || !idrFrameProcessed) {
waitingForIdrFrame = 1; waitingForIdrFrame = true;
} }
// Count the number of consecutive frames dropped // Count the number of consecutive frames dropped
@@ -94,7 +94,7 @@ static void dropFrameState(void) {
consecutiveFrameDrops = 0; consecutiveFrameDrops = 0;
// Request an IDR frame // Request an IDR frame
waitingForIdrFrame = 1; waitingForIdrFrame = true;
requestIdrOnDemand(); requestIdrOnDemand();
} }
@@ -125,25 +125,21 @@ void destroyVideoDepacketizer(void) {
cleanupFrameState(); cleanupFrameState();
} }
// Returns 1 if candidate is a frame start and 0 otherwise static bool isSeqFrameStart(PBUFFER_DESC candidate) {
static int isSeqFrameStart(PBUFFER_DESC candidate) {
return (candidate->length == 4 && candidate->data[candidate->offset + candidate->length - 1] == 1); return (candidate->length == 4 && candidate->data[candidate->offset + candidate->length - 1] == 1);
} }
// Returns 1 if candidate is an Annex B start and 0 otherwise static bool isSeqAnnexBStart(PBUFFER_DESC candidate) {
static int isSeqAnnexBStart(PBUFFER_DESC candidate) {
return (candidate->data[candidate->offset + candidate->length - 1] == 1); return (candidate->data[candidate->offset + candidate->length - 1] == 1);
} }
// Returns 1 if candidate is padding and 0 otherwise static bool isSeqPadding(PBUFFER_DESC candidate) {
static int isSeqPadding(PBUFFER_DESC candidate) {
return (candidate->data[candidate->offset + candidate->length - 1] == 0); return (candidate->data[candidate->offset + candidate->length - 1] == 0);
} }
// Returns 1 on success, 0 otherwise static bool getSpecialSeq(PBUFFER_DESC current, PBUFFER_DESC candidate) {
static int getSpecialSeq(PBUFFER_DESC current, PBUFFER_DESC candidate) {
if (current->length < 3) { if (current->length < 3) {
return 0; return false;
} }
if (current->data[current->offset] == 0 && if (current->data[current->offset] == 0 &&
@@ -155,14 +151,14 @@ static int getSpecialSeq(PBUFFER_DESC current, PBUFFER_DESC candidate) {
candidate->data = current->data; candidate->data = current->data;
candidate->offset = current->offset; candidate->offset = current->offset;
candidate->length = 4; candidate->length = 4;
return 1; return true;
} }
else { else {
// Padding // Padding
candidate->data = current->data; candidate->data = current->data;
candidate->offset = current->offset; candidate->offset = current->offset;
candidate->length = 3; candidate->length = 3;
return 1; return true;
} }
} }
else if (current->data[current->offset + 2] == 1) { else if (current->data[current->offset + 2] == 1) {
@@ -170,22 +166,17 @@ static int getSpecialSeq(PBUFFER_DESC current, PBUFFER_DESC candidate) {
candidate->data = current->data; candidate->data = current->data;
candidate->offset = current->offset; candidate->offset = current->offset;
candidate->length = 3; candidate->length = 3;
return 1; return true;
} }
} }
return 0; return false;
} }
// Get the first decode unit available // Get the first decode unit available
int getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT* qdu) { bool getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT* qdu) {
int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)qdu); int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)qdu);
if (err == LBQ_SUCCESS) { return (err == LBQ_SUCCESS);
return 1;
}
else {
return 0;
}
} }
// Cleanup a decode unit by freeing the buffer chain and the holder // Cleanup a decode unit by freeing the buffer chain and the holder
@@ -199,7 +190,7 @@ void completeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu, int drStatus) {
else if (drStatus == DR_OK && qdu->decodeUnit.frameType == FRAME_TYPE_IDR) { else if (drStatus == DR_OK && qdu->decodeUnit.frameType == FRAME_TYPE_IDR) {
// Remember that the IDR frame was processed. We can now use // Remember that the IDR frame was processed. We can now use
// reference frame invalidation. // reference frame invalidation.
idrFrameProcessed = 1; idrFrameProcessed = true;
} }
while (qdu->decodeUnit.bufferList != NULL) { while (qdu->decodeUnit.bufferList != NULL) {
@@ -214,8 +205,7 @@ void completeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu, int drStatus) {
} }
} }
// Returns 1 if the special sequence describes an I-frame static bool isSeqReferenceFrameStart(PBUFFER_DESC specialSeq) {
static int isSeqReferenceFrameStart(PBUFFER_DESC specialSeq) {
switch (specialSeq->data[specialSeq->offset + specialSeq->length]) { switch (specialSeq->data[specialSeq->offset + specialSeq->length]) {
case 0x20: case 0x20:
case 0x22: case 0x22:
@@ -224,19 +214,18 @@ static int isSeqReferenceFrameStart(PBUFFER_DESC specialSeq) {
case 0x28: case 0x28:
case 0x2A: case 0x2A:
// H265 // H265
return 1; return true;
case 0x65: case 0x65:
// H264 // H264
return 1; return true;
default: default:
return 0; return false;
} }
} }
// Returns 1 if this buffer describes an IDR frame static bool isIdrFrameStart(PBUFFER_DESC buffer) {
static int isIdrFrameStart(PBUFFER_DESC buffer) {
BUFFER_DESC specialSeq; BUFFER_DESC specialSeq;
return getSpecialSeq(buffer, &specialSeq) && return getSpecialSeq(buffer, &specialSeq) &&
isSeqFrameStart(&specialSeq) && isSeqFrameStart(&specialSeq) &&
@@ -399,7 +388,7 @@ static void queueFragment(PLENTRY_INTERNAL* existingEntry, char* data, int offse
// Process an RTP Payload using the slow path that handles multiple NALUs per packet // Process an RTP Payload using the slow path that handles multiple NALUs per packet
static void processRtpPayloadSlow(PBUFFER_DESC currentPos, PLENTRY_INTERNAL* existingEntry) { static void processRtpPayloadSlow(PBUFFER_DESC currentPos, PLENTRY_INTERNAL* existingEntry) {
BUFFER_DESC specialSeq; BUFFER_DESC specialSeq;
int decodingVideo = 0; bool decodingVideo = false;
// We should not have any NALUs when processing the first packet in an IDR frame // We should not have any NALUs when processing the first packet in an IDR frame
LC_ASSERT(nalChainHead == NULL); LC_ASSERT(nalChainHead == NULL);
@@ -407,27 +396,27 @@ static void processRtpPayloadSlow(PBUFFER_DESC currentPos, PLENTRY_INTERNAL* exi
while (currentPos->length != 0) { while (currentPos->length != 0) {
int start = currentPos->offset; int start = currentPos->offset;
int containsPicData = 0; bool containsPicData = false;
if (getSpecialSeq(currentPos, &specialSeq)) { if (getSpecialSeq(currentPos, &specialSeq)) {
if (isSeqAnnexBStart(&specialSeq)) { if (isSeqAnnexBStart(&specialSeq)) {
// Now we're decoding video // Now we're decoding video
decodingVideo = 1; decodingVideo = true;
if (isSeqFrameStart(&specialSeq)) { if (isSeqFrameStart(&specialSeq)) {
// Now we're working on a frame // Now we're working on a frame
decodingFrame = 1; decodingFrame = true;
if (isSeqReferenceFrameStart(&specialSeq)) { if (isSeqReferenceFrameStart(&specialSeq)) {
// No longer waiting for an IDR frame // No longer waiting for an IDR frame
waitingForIdrFrame = 0; waitingForIdrFrame = false;
// Cancel any pending IDR frame request // Cancel any pending IDR frame request
waitingForNextSuccessfulFrame = 0; waitingForNextSuccessfulFrame = false;
// Use the cached LENTRY for this NALU since it will be // Use the cached LENTRY for this NALU since it will be
// the bulk of the data in this packet. // the bulk of the data in this packet.
containsPicData = 1; containsPicData = true;
} }
} }
@@ -437,7 +426,7 @@ static void processRtpPayloadSlow(PBUFFER_DESC currentPos, PLENTRY_INTERNAL* exi
} }
else { else {
// Not decoding video // Not decoding video
decodingVideo = 0; decodingVideo = false;
// Just skip this byte // Just skip this byte
currentPos->length--; currentPos->length--;
@@ -472,7 +461,7 @@ static void processRtpPayloadSlow(PBUFFER_DESC currentPos, PLENTRY_INTERNAL* exi
// an IDR frame // an IDR frame
void requestDecoderRefresh(void) { void requestDecoderRefresh(void) {
// Wait for the next IDR frame // Wait for the next IDR frame
waitingForIdrFrame = 1; waitingForIdrFrame = true;
// Flush the decode unit queue // Flush the decode unit queue
freeDecodeUnitList(LbqFlushQueueItems(&decodeUnitQueue)); freeDecodeUnitList(LbqFlushQueueItems(&decodeUnitQueue));
@@ -481,7 +470,7 @@ void requestDecoderRefresh(void) {
// on the next call. We can't do it here because // on the next call. We can't do it here because
// it may be trying to queue DUs and we'll nuke // it may be trying to queue DUs and we'll nuke
// the state out from under it. // the state out from under it.
dropStatePending = 1; dropStatePending = true;
// Request the IDR frame // Request the IDR frame
requestIdrOnDemand(); requestIdrOnDemand();
@@ -535,9 +524,9 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
if (isBefore24(streamPacketIndex, U24(lastPacketInStream + 1)) || if (isBefore24(streamPacketIndex, U24(lastPacketInStream + 1)) ||
(!firstPacket && streamPacketIndex != U24(lastPacketInStream + 1))) { (!firstPacket && streamPacketIndex != U24(lastPacketInStream + 1))) {
Limelog("Depacketizer detected corrupt frame: %d", frameIndex); Limelog("Depacketizer detected corrupt frame: %d", frameIndex);
decodingFrame = 0; decodingFrame = false;
nextFrameNumber = frameIndex + 1; nextFrameNumber = frameIndex + 1;
waitingForNextSuccessfulFrame = 1; waitingForNextSuccessfulFrame = true;
dropFrameState(); dropFrameState();
return; return;
} }
@@ -557,7 +546,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
nextFrameNumber = frameIndex; nextFrameNumber = frameIndex;
// Wait until next complete frame // Wait until next complete frame
waitingForNextSuccessfulFrame = 1; waitingForNextSuccessfulFrame = true;
dropFrameState(); dropFrameState();
} }
else { else {
@@ -565,7 +554,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
} }
// We're now decoding a frame // We're now decoding a frame
decodingFrame = 1; decodingFrame = true;
firstPacketReceiveTime = receiveTimeMs; firstPacketReceiveTime = receiveTimeMs;
firstPacketPresentationTime = presentationTimeMs; firstPacketPresentationTime = presentationTimeMs;
} }
@@ -631,7 +620,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
if (flags & FLAG_EOF) { if (flags & FLAG_EOF) {
// Move on to the next frame // Move on to the next frame
decodingFrame = 0; decodingFrame = false;
nextFrameNumber = frameIndex + 1; nextFrameNumber = frameIndex + 1;
// If waiting for next successful frame and we got here // If waiting for next successful frame and we got here
@@ -639,7 +628,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
if (waitingForNextSuccessfulFrame) { if (waitingForNextSuccessfulFrame) {
// This is the next successful frame after a loss event // This is the next successful frame after a loss event
connectionDetectedFrameLoss(startFrameNumber, frameIndex - 1); connectionDetectedFrameLoss(startFrameNumber, frameIndex - 1);
waitingForNextSuccessfulFrame = 0; waitingForNextSuccessfulFrame = false;
} }
// If we need an IDR frame first, then drop this frame // If we need an IDR frame first, then drop this frame
@@ -662,7 +651,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length,
// otherwise we'll lose this IDR frame without another in flight // otherwise we'll lose this IDR frame without another in flight
// and have to wait until we hit our consecutive drop limit to // and have to wait until we hit our consecutive drop limit to
// request a new one (potentially several seconds). // request a new one (potentially several seconds).
dropStatePending = 0; dropStatePending = false;
} }
else { else {
dropFrameState(); dropFrameState();
+9 -9
View File
@@ -20,9 +20,9 @@ static PLT_THREAD udpPingThread;
static PLT_THREAD receiveThread; static PLT_THREAD receiveThread;
static PLT_THREAD decoderThread; static PLT_THREAD decoderThread;
static int receivedDataFromPeer; static bool receivedDataFromPeer;
static uint64_t firstDataTimeMs; static uint64_t firstDataTimeMs;
static int receivedFullFrame; static bool receivedFullFrame;
// 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
@@ -34,9 +34,9 @@ static int receivedFullFrame;
void initializeVideoStream(void) { void initializeVideoStream(void) {
initializeVideoDepacketizer(StreamConfig.packetSize); initializeVideoDepacketizer(StreamConfig.packetSize);
RtpfInitializeQueue(&rtpQueue); //TODO RTP_QUEUE_DELAY RtpfInitializeQueue(&rtpQueue); //TODO RTP_QUEUE_DELAY
receivedDataFromPeer = 0; receivedDataFromPeer = false;
firstDataTimeMs = 0; firstDataTimeMs = 0;
receivedFullFrame = 0; receivedFullFrame = false;
} }
// Clean up the video stream // Clean up the video stream
@@ -72,7 +72,7 @@ static void ReceiveThreadProc(void* context) {
int bufferSize, receiveSize; int bufferSize, receiveSize;
char* buffer; char* buffer;
int queueStatus; int queueStatus;
int useSelect; bool useSelect;
int waitingForVideoMs; int waitingForVideoMs;
receiveSize = StreamConfig.packetSize + MAX_RTP_HEADER_SIZE; receiveSize = StreamConfig.packetSize + MAX_RTP_HEADER_SIZE;
@@ -81,11 +81,11 @@ static void ReceiveThreadProc(void* context) {
if (setNonFatalRecvTimeoutMs(rtpSocket, UDP_RECV_POLL_TIMEOUT_MS) < 0) { if (setNonFatalRecvTimeoutMs(rtpSocket, UDP_RECV_POLL_TIMEOUT_MS) < 0) {
// SO_RCVTIMEO failed, so use select() to wait // SO_RCVTIMEO failed, so use select() to wait
useSelect = 1; useSelect = true;
} }
else { else {
// SO_RCVTIMEO timeout set for recv() // SO_RCVTIMEO timeout set for recv()
useSelect = 0; useSelect = false;
} }
waitingForVideoMs = 0; waitingForVideoMs = 0;
@@ -124,7 +124,7 @@ static void ReceiveThreadProc(void* context) {
} }
if (!receivedDataFromPeer) { if (!receivedDataFromPeer) {
receivedDataFromPeer = 1; receivedDataFromPeer = true;
Limelog("Received first video packet after %d ms\n", waitingForVideoMs); Limelog("Received first video packet after %d ms\n", waitingForVideoMs);
firstDataTimeMs = PltGetMillis(); firstDataTimeMs = PltGetMillis();
@@ -165,7 +165,7 @@ void submitFrame(PQUEUED_DECODE_UNIT qdu) {
completeQueuedDecodeUnit(qdu, ret); completeQueuedDecodeUnit(qdu, ret);
// Remember that we got a full frame successfully // Remember that we got a full frame successfully
receivedFullFrame = 1; receivedFullFrame = true;
} }
// Decoder thread proc // Decoder thread proc