mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 14:21:30 +00:00
Major code cleanup: comment style & run CodeMaid
This commit is contained in:
@@ -191,7 +191,8 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
// An exit signal was received
|
// An exit signal was received
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
decodeInputData(packet);
|
decodeInputData(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +210,8 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
// An exit signal was received
|
// An exit signal was received
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
decodeInputData(packet);
|
decodeInputData(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ CONNECTION_LISTENER_CALLBACKS ListenerCallbacks;
|
|||||||
DECODER_RENDERER_CALLBACKS VideoCallbacks;
|
DECODER_RENDERER_CALLBACKS VideoCallbacks;
|
||||||
AUDIO_RENDERER_CALLBACKS AudioCallbacks;
|
AUDIO_RENDERER_CALLBACKS AudioCallbacks;
|
||||||
|
|
||||||
/* Connection stages */
|
// Connection stages
|
||||||
static const char* stageNames[STAGE_MAX] = {
|
static const char* stageNames[STAGE_MAX] = {
|
||||||
"none",
|
"none",
|
||||||
"platform initialization",
|
"platform initialization",
|
||||||
@@ -32,12 +32,12 @@ static const char* stageNames[STAGE_MAX] = {
|
|||||||
"input stream establishment"
|
"input stream establishment"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Get the name of the current stage based on its number */
|
// Get the name of the current stage based on its number
|
||||||
const char* LiGetStageName(int stage) {
|
const char* LiGetStageName(int stage) {
|
||||||
return stageNames[stage];
|
return stageNames[stage];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 = 1;
|
||||||
@@ -171,7 +171,7 @@ static int resolveHostName(const char *host)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Starts the connection to the streaming machine */
|
// Starts the connection to the streaming machine
|
||||||
int LiStartConnection(const char* host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
int LiStartConnection(const char* host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
||||||
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks,
|
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks,
|
||||||
void* renderContext, int drFlags, int _serverMajorVersion) {
|
void* renderContext, int drFlags, int _serverMajorVersion) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
/* NV control stream packet header */
|
// NV control stream packet header
|
||||||
typedef struct _NVCTL_PACKET_HEADER {
|
typedef struct _NVCTL_PACKET_HEADER {
|
||||||
unsigned short type;
|
unsigned short type;
|
||||||
unsigned short payloadLength;
|
unsigned short payloadLength;
|
||||||
@@ -83,7 +83,7 @@ static char **preconstructedPayloads;
|
|||||||
|
|
||||||
#define LOSS_REPORT_INTERVAL_MS 50
|
#define LOSS_REPORT_INTERVAL_MS 50
|
||||||
|
|
||||||
/* Initializes the control stream */
|
// Initializes the control stream
|
||||||
int initializeControlStream(void) {
|
int initializeControlStream(void) {
|
||||||
PltCreateEvent(&invalidateRefFramesEvent);
|
PltCreateEvent(&invalidateRefFramesEvent);
|
||||||
LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20);
|
LbqInitializeLinkedBlockingQueue(&invalidReferenceFrameTuples, 20);
|
||||||
@@ -116,7 +116,7 @@ void freeFrameInvalidationList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleans up control stream */
|
// Cleans up control stream
|
||||||
void destroyControlStream(void) {
|
void destroyControlStream(void) {
|
||||||
PltCloseEvent(&invalidateRefFramesEvent);
|
PltCloseEvent(&invalidateRefFramesEvent);
|
||||||
freeFrameInvalidationList(LbqDestroyLinkedBlockingQueue(&invalidReferenceFrameTuples));
|
freeFrameInvalidationList(LbqDestroyLinkedBlockingQueue(&invalidReferenceFrameTuples));
|
||||||
@@ -128,7 +128,6 @@ int getNextFrameInvalidationTuple(PQUEUED_FRAME_INVALIDATION_TUPLE *qfit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void queueFrameInvalidationTuple(int startFrame, int endFrame) {
|
void queueFrameInvalidationTuple(int startFrame, int endFrame) {
|
||||||
|
|
||||||
if (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION) {
|
if (VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION) {
|
||||||
PQUEUED_FRAME_INVALIDATION_TUPLE qfit;
|
PQUEUED_FRAME_INVALIDATION_TUPLE qfit;
|
||||||
qfit = malloc(sizeof(*qfit));
|
qfit = malloc(sizeof(*qfit));
|
||||||
@@ -152,33 +151,33 @@ void queueFrameInvalidationTuple(int startFrame, int endFrame) {
|
|||||||
PltSetEvent(&invalidateRefFramesEvent);
|
PltSetEvent(&invalidateRefFramesEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 = 1;
|
||||||
PltSetEvent(&invalidateRefFramesEvent);
|
PltSetEvent(&invalidateRefFramesEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalidate reference frames if the decoder is too slow */
|
// Invalidate reference frames if the decoder is too slow
|
||||||
void connectionSinkTooSlow(int startFrame, int endFrame) {
|
void connectionSinkTooSlow(int startFrame, int endFrame) {
|
||||||
queueFrameInvalidationTuple(startFrame, endFrame);
|
queueFrameInvalidationTuple(startFrame, endFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invalidate reference frames lost by the network */
|
// Invalidate reference frames lost by the network
|
||||||
void connectionDetectedFrameLoss(int startFrame, int endFrame) {
|
void connectionDetectedFrameLoss(int startFrame, int endFrame) {
|
||||||
queueFrameInvalidationTuple(startFrame, endFrame);
|
queueFrameInvalidationTuple(startFrame, endFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When we receive a frame, update the number of our current frame */
|
// When we receive a frame, update the number of our current frame
|
||||||
void connectionReceivedFrame(int frameIndex) {
|
void connectionReceivedFrame(int frameIndex) {
|
||||||
currentFrame = frameIndex;
|
currentFrame = frameIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When we lose packets, update our packet loss count */
|
// When we lose packets, update our packet loss count
|
||||||
void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket) {
|
void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket) {
|
||||||
lossCountSinceLastReport += (nextReceivedPacket - lastReceivedPacket) - 1;
|
lossCountSinceLastReport += (nextReceivedPacket - lastReceivedPacket) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reads an NV control stream packet */
|
// Reads an NV control stream packet
|
||||||
static PNVCTL_PACKET_HEADER readNvctlPacket(void) {
|
static PNVCTL_PACKET_HEADER readNvctlPacket(void) {
|
||||||
NVCTL_PACKET_HEADER staticHeader;
|
NVCTL_PACKET_HEADER staticHeader;
|
||||||
PNVCTL_PACKET_HEADER fullPacket;
|
PNVCTL_PACKET_HEADER fullPacket;
|
||||||
@@ -371,14 +370,15 @@ static void invalidateRefFramesFunc(void* context) {
|
|||||||
// Send an IDR frame request
|
// Send an IDR frame request
|
||||||
idrFrameRequired = 0;
|
idrFrameRequired = 0;
|
||||||
requestIdrFrame();
|
requestIdrFrame();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Otherwise invalidate reference frames
|
// Otherwise invalidate reference frames
|
||||||
requestInvalidateReferenceFrames();
|
requestInvalidateReferenceFrames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stops the control stream */
|
// Stops the control stream
|
||||||
int stopControlStream(void) {
|
int stopControlStream(void) {
|
||||||
PltInterruptThread(&lossStatsThread);
|
PltInterruptThread(&lossStatsThread);
|
||||||
PltInterruptThread(&invalidateRefFramesThread);
|
PltInterruptThread(&invalidateRefFramesThread);
|
||||||
@@ -397,7 +397,7 @@ int stopControlStream(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Starts the control stream */
|
// Starts the control stream
|
||||||
int startControlStream(void) {
|
int startControlStream(void) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ static OAES_CTX* oaesContext;
|
|||||||
|
|
||||||
#define MAX_INPUT_PACKET_SIZE 128
|
#define MAX_INPUT_PACKET_SIZE 128
|
||||||
|
|
||||||
/* Contains input stream packets */
|
// Contains input stream packets
|
||||||
typedef struct _PACKET_HOLDER {
|
typedef struct _PACKET_HOLDER {
|
||||||
int packetLength;
|
int packetLength;
|
||||||
union {
|
union {
|
||||||
@@ -30,7 +30,7 @@ typedef struct _PACKET_HOLDER {
|
|||||||
LINKED_BLOCKING_QUEUE_ENTRY entry;
|
LINKED_BLOCKING_QUEUE_ENTRY entry;
|
||||||
} PACKET_HOLDER, *PPACKET_HOLDER;
|
} PACKET_HOLDER, *PPACKET_HOLDER;
|
||||||
|
|
||||||
/* Initializes the input stream */
|
// Initializes the input stream
|
||||||
int initializeInputStream(char* aesKeyData, int aesKeyDataLength,
|
int initializeInputStream(char* aesKeyData, int aesKeyDataLength,
|
||||||
char* aesIv, int aesIvLength) {
|
char* aesIv, int aesIvLength) {
|
||||||
if (aesIvLength != OAES_BLOCK_SIZE)
|
if (aesIvLength != OAES_BLOCK_SIZE)
|
||||||
@@ -64,7 +64,7 @@ int initializeInputStream(char* aesKeyData, int aesKeyDataLength,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destroys and cleans up the input stream */
|
// Destroys and cleans up the input stream
|
||||||
void destroyInputStream(void) {
|
void destroyInputStream(void) {
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
|
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ static int checkDirs(short currentVal, short newVal, int* dir) {
|
|||||||
|
|
||||||
#define OAES_DATA_OFFSET 32
|
#define OAES_DATA_OFFSET 32
|
||||||
|
|
||||||
/* Input thread proc */
|
// Input thread proc
|
||||||
static void inputSendThreadProc(void* context) {
|
static void inputSendThreadProc(void* context) {
|
||||||
SOCK_RET err;
|
SOCK_RET err;
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
@@ -268,7 +268,7 @@ static void inputSendThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Begin the input stream */
|
// Begin the input stream
|
||||||
int startInputStream(void) {
|
int startInputStream(void) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -287,7 +287,7 @@ int startInputStream(void) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stops the input stream */
|
// Stops the input stream
|
||||||
int stopInputStream(void) {
|
int stopInputStream(void) {
|
||||||
PltInterruptThread(&inputSendThread);
|
PltInterruptThread(&inputSendThread);
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ int stopInputStream(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a mouse move event to the streaming machine */
|
// Send a mouse move event to the streaming machine
|
||||||
int LiSendMouseMoveEvent(short deltaX, short deltaY) {
|
int LiSendMouseMoveEvent(short deltaX, short deltaY) {
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
int err;
|
int err;
|
||||||
@@ -330,7 +330,7 @@ int LiSendMouseMoveEvent(short deltaX, short deltaY) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a mouse button event to the streaming machine */
|
// Send a mouse button event to the streaming machine
|
||||||
int LiSendMouseButtonEvent(char action, int button) {
|
int LiSendMouseButtonEvent(char action, int button) {
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
int err;
|
int err;
|
||||||
@@ -357,7 +357,7 @@ int LiSendMouseButtonEvent(char action, int button) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a key press event to the streaming machine */
|
// Send a key press event to the streaming machine
|
||||||
int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) {
|
int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) {
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
int err;
|
int err;
|
||||||
@@ -447,7 +447,7 @@ static int sendControllerEventInternal(short controllerNumber, short buttonFlags
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a controller event to the streaming machine */
|
// Send a controller event to the streaming machine
|
||||||
int LiSendControllerEvent(short buttonFlags, unsigned char leftTrigger, unsigned char rightTrigger,
|
int LiSendControllerEvent(short buttonFlags, unsigned char leftTrigger, unsigned char rightTrigger,
|
||||||
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
||||||
{
|
{
|
||||||
@@ -455,7 +455,7 @@ int LiSendControllerEvent(short buttonFlags, unsigned char leftTrigger, unsigned
|
|||||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a controller event to the streaming machine */
|
// Send a controller event to the streaming machine
|
||||||
int LiSendMultiControllerEvent(short controllerNumber, short buttonFlags, unsigned char leftTrigger, unsigned char rightTrigger,
|
int LiSendMultiControllerEvent(short controllerNumber, short buttonFlags, unsigned char leftTrigger, unsigned char rightTrigger,
|
||||||
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
||||||
{
|
{
|
||||||
@@ -463,7 +463,7 @@ int LiSendMultiControllerEvent(short controllerNumber, short buttonFlags, unsign
|
|||||||
leftStickX, leftStickY, rightStickX, rightStickY);
|
leftStickX, leftStickY, rightStickX, rightStickY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send a scroll event to the streaming machine */
|
// Send a scroll event to the streaming machine
|
||||||
int LiSendScrollEvent(signed char scrollClicks) {
|
int LiSendScrollEvent(signed char scrollClicks) {
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
int err;
|
int err;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "LinkedBlockingQueue.h"
|
#include "LinkedBlockingQueue.h"
|
||||||
|
|
||||||
/* Destroy the linked blocking queue and associated mutex and event */
|
// Destroy the linked blocking queue and associated mutex and event
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead) {
|
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead) {
|
||||||
PltDeleteMutex(&queueHead->mutex);
|
PltDeleteMutex(&queueHead->mutex);
|
||||||
PltCloseEvent(&queueHead->containsDataEvent);
|
PltCloseEvent(&queueHead->containsDataEvent);
|
||||||
@@ -8,7 +8,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEU
|
|||||||
return queueHead->head;
|
return queueHead->head;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush the queue */
|
// Flush the queue
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead) {
|
PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead) {
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY head;
|
PLINKED_BLOCKING_QUEUE_ENTRY head;
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Linked blocking queue init */
|
// Linked blocking queue init
|
||||||
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|||||||
@@ -195,7 +195,6 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
|
|||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
// 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 int startsWith(const char* s, const char* prefix) {
|
||||||
|
|
||||||
if (strncmp(s, prefix, strlen(prefix)) == 0) {
|
if (strncmp(s, prefix, strlen(prefix)) == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -140,7 +139,6 @@ int parseRtspMessage(PRTSP_MESSAGE msg, char* rtspMessage, int length) {
|
|||||||
{
|
{
|
||||||
token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end);
|
token = strtok(NULL, typeFlag == TOKEN_OPTION ? optDelim : end);
|
||||||
if (token != NULL) {
|
if (token != NULL) {
|
||||||
|
|
||||||
if (typeFlag == TOKEN_OPTION) {
|
if (typeFlag == TOKEN_OPTION) {
|
||||||
opt = token;
|
opt = token;
|
||||||
}
|
}
|
||||||
@@ -165,7 +163,6 @@ 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\r\n")) {
|
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 = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ typedef struct _SDP_OPTION {
|
|||||||
struct _SDP_OPTION *next;
|
struct _SDP_OPTION *next;
|
||||||
} SDP_OPTION, *PSDP_OPTION;
|
} SDP_OPTION, *PSDP_OPTION;
|
||||||
|
|
||||||
/* Cleanup the attribute list */
|
// Cleanup the attribute list
|
||||||
static void freeAttributeList(PSDP_OPTION head) {
|
static void freeAttributeList(PSDP_OPTION head) {
|
||||||
PSDP_OPTION next;
|
PSDP_OPTION next;
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
@@ -28,7 +28,7 @@ static void freeAttributeList(PSDP_OPTION head) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the size of the attribute list */
|
// Get the size of the attribute list
|
||||||
static int getSerializedAttributeListSize(PSDP_OPTION head) {
|
static int getSerializedAttributeListSize(PSDP_OPTION head) {
|
||||||
PSDP_OPTION currentEntry = head;
|
PSDP_OPTION currentEntry = head;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
@@ -44,7 +44,7 @@ static int getSerializedAttributeListSize(PSDP_OPTION head) {
|
|||||||
return (int)size;
|
return (int)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Populate the serialized attribute list into a string */
|
// Populate the serialized attribute list into a string
|
||||||
static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
|
static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
|
||||||
PSDP_OPTION currentEntry = head;
|
PSDP_OPTION currentEntry = head;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
@@ -59,7 +59,7 @@ static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an attribute */
|
// Add an attribute
|
||||||
static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload, int payloadLen) {
|
static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload, int payloadLen) {
|
||||||
PSDP_OPTION option, currentOption;
|
PSDP_OPTION option, currentOption;
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an attribute string */
|
// Add an attribute string
|
||||||
static int addAttributeString(PSDP_OPTION *head, char* name, const char* payload) {
|
static int addAttributeString(PSDP_OPTION *head, char* name, const char* payload) {
|
||||||
// We purposefully omit the null terminating character
|
// We purposefully omit the null terminating character
|
||||||
return addAttributeBinary(head, name, payload, (int)strlen(payload));
|
return addAttributeBinary(head, name, payload, (int)strlen(payload));
|
||||||
@@ -104,7 +104,6 @@ static int addGen3Options(PSDP_OPTION *head, char* addrStr) {
|
|||||||
err |= addAttributeBinary(head,
|
err |= addAttributeBinary(head,
|
||||||
"x-nv-general.featureFlags", &payloadInt, sizeof(payloadInt));
|
"x-nv-general.featureFlags", &payloadInt, sizeof(payloadInt));
|
||||||
|
|
||||||
|
|
||||||
payloadInt = htonl(0x41514141);
|
payloadInt = htonl(0x41514141);
|
||||||
err |= addAttributeBinary(head,
|
err |= addAttributeBinary(head,
|
||||||
"x-nv-video[0].transferProtocol", &payloadInt, sizeof(payloadInt));
|
"x-nv-video[0].transferProtocol", &payloadInt, sizeof(payloadInt));
|
||||||
@@ -227,7 +226,8 @@ static PSDP_OPTION getAttributesList(char *urlSafeAddr) {
|
|||||||
if (StreamConfig.streamingRemotely) {
|
if (StreamConfig.streamingRemotely) {
|
||||||
err |= addAttributeString(&optionHead, "x-nv-vqos[0].qosTrafficType", "0");
|
err |= addAttributeString(&optionHead, "x-nv-vqos[0].qosTrafficType", "0");
|
||||||
err |= addAttributeString(&optionHead, "x-nv-aqos.qosTrafficType", "0");
|
err |= addAttributeString(&optionHead, "x-nv-aqos.qosTrafficType", "0");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
err |= addAttributeString(&optionHead, "x-nv-vqos[0].qosTrafficType", "5");
|
err |= addAttributeString(&optionHead, "x-nv-vqos[0].qosTrafficType", "5");
|
||||||
err |= addAttributeString(&optionHead, "x-nv-aqos.qosTrafficType", "4");
|
err |= addAttributeString(&optionHead, "x-nv-aqos.qosTrafficType", "4");
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ static PSDP_OPTION getAttributesList(char *urlSafeAddr) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Populate the SDP header with required information */
|
// Populate the SDP header with required information
|
||||||
static int fillSdpHeader(char* buffer, int rtspClientVersion, char *urlSafeAddr) {
|
static int fillSdpHeader(char* buffer, int rtspClientVersion, char *urlSafeAddr) {
|
||||||
return sprintf(buffer,
|
return sprintf(buffer,
|
||||||
"v=0\r\n"
|
"v=0\r\n"
|
||||||
@@ -258,7 +258,7 @@ static int fillSdpHeader(char* buffer, int rtspClientVersion, char *urlSafeAddr)
|
|||||||
urlSafeAddr);
|
urlSafeAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Populate the SDP tail with required information */
|
// Populate the SDP tail with required information
|
||||||
static int fillSdpTail(char* buffer) {
|
static int fillSdpTail(char* buffer) {
|
||||||
return sprintf(buffer,
|
return sprintf(buffer,
|
||||||
"t=0 0\r\n"
|
"t=0 0\r\n"
|
||||||
@@ -266,7 +266,7 @@ static int fillSdpTail(char* buffer) {
|
|||||||
ServerMajorVersion < 4 ? 47996 : 47998);
|
ServerMajorVersion < 4 ? 47996 : 47998);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the SDP attributes for the stream config */
|
// Get the SDP attributes for the stream config
|
||||||
char* getSdpPayloadForStreamConfig(int rtspClientVersion, int *length) {
|
char* getSdpPayloadForStreamConfig(int rtspClientVersion, int *length) {
|
||||||
PSDP_OPTION attributeList;
|
PSDP_OPTION attributeList;
|
||||||
int offset;
|
int offset;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ typedef struct _BUFFER_DESC {
|
|||||||
unsigned int length;
|
unsigned int length;
|
||||||
} BUFFER_DESC, *PBUFFER_DESC;
|
} BUFFER_DESC, *PBUFFER_DESC;
|
||||||
|
|
||||||
/* Init */
|
// Init
|
||||||
void initializeVideoDepacketizer(int pktSize) {
|
void initializeVideoDepacketizer(int pktSize) {
|
||||||
if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
LbqInitializeLinkedBlockingQueue(&decodeUnitQueue, 15);
|
LbqInitializeLinkedBlockingQueue(&decodeUnitQueue, 15);
|
||||||
@@ -46,7 +46,7 @@ void initializeVideoDepacketizer(int pktSize) {
|
|||||||
strictIdrFrameWait = !(VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION);
|
strictIdrFrameWait = !(VideoCallbacks.capabilities & CAPABILITY_REFERENCE_FRAME_INVALIDATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free malloced memory in AvcFrameState*/
|
// Free malloced memory in AvcFrameState*/
|
||||||
static void cleanupAvcFrameState(void) {
|
static void cleanupAvcFrameState(void) {
|
||||||
PLENTRY lastEntry;
|
PLENTRY lastEntry;
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ static void cleanupAvcFrameState(void) {
|
|||||||
nalChainDataLength = 0;
|
nalChainDataLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup AVC frame state and set that we're waiting for an IDR Frame*/
|
// Cleanup AVC frame state and set that we're waiting for an IDR Frame*/
|
||||||
static void dropAvcFrameState(void) {
|
static void dropAvcFrameState(void) {
|
||||||
// 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
|
||||||
if (strictIdrFrameWait) {
|
if (strictIdrFrameWait) {
|
||||||
@@ -84,7 +84,7 @@ static void dropAvcFrameState(void) {
|
|||||||
cleanupAvcFrameState();
|
cleanupAvcFrameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup the list of decode units */
|
// Cleanup the list of decode units
|
||||||
static void freeDecodeUnitList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
static void freeDecodeUnitList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY nextEntry;
|
PLINKED_BLOCKING_QUEUE_ENTRY nextEntry;
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ static void freeDecodeUnitList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup video depacketizer and free malloced memory */
|
// Cleanup video depacketizer and free malloced memory
|
||||||
void destroyVideoDepacketizer(void) {
|
void destroyVideoDepacketizer(void) {
|
||||||
if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
if ((VideoCallbacks.capabilities & CAPABILITY_DIRECT_SUBMIT) == 0) {
|
||||||
freeDecodeUnitList(LbqDestroyLinkedBlockingQueue(&decodeUnitQueue));
|
freeDecodeUnitList(LbqDestroyLinkedBlockingQueue(&decodeUnitQueue));
|
||||||
@@ -106,22 +106,22 @@ void destroyVideoDepacketizer(void) {
|
|||||||
cleanupAvcFrameState();
|
cleanupAvcFrameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 1 if candidate is a frame start and 0 otherwise */
|
// Returns 1 if candidate is a frame start and 0 otherwise
|
||||||
static int 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 an AVC start and 0 otherwise */
|
// Returns 1 if candidate an AVC start and 0 otherwise
|
||||||
static int isSeqAvcStart(PBUFFER_DESC candidate) {
|
static int isSeqAvcStart(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 */
|
// Returns 1 if candidate is padding and 0 otherwise
|
||||||
static int 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 */
|
// Returns 1 on success, 0 otherwise
|
||||||
static int 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 0;
|
||||||
@@ -158,7 +158,7 @@ static int getSpecialSeq(PBUFFER_DESC current, PBUFFER_DESC candidate) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the first decode unit available */
|
// Get the first decode unit available
|
||||||
int getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT *qdu) {
|
int getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT *qdu) {
|
||||||
int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)qdu);
|
int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)qdu);
|
||||||
if (err == LBQ_SUCCESS) {
|
if (err == LBQ_SUCCESS) {
|
||||||
@@ -169,7 +169,7 @@ int getNextQueuedDecodeUnit(PQUEUED_DECODE_UNIT *qdu) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup a decode unit by freeing the buffer chain and the holder */
|
// Cleanup a decode unit by freeing the buffer chain and the holder
|
||||||
void freeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu) {
|
void freeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu) {
|
||||||
PLENTRY lastEntry;
|
PLENTRY lastEntry;
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ void freeQueuedDecodeUnit(PQUEUED_DECODE_UNIT qdu) {
|
|||||||
free(qdu);
|
free(qdu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reassemble the frame with the given frame number */
|
// Reassemble the frame with the given frame number
|
||||||
static void reassembleAvcFrame(int frameNumber) {
|
static void reassembleAvcFrame(int frameNumber) {
|
||||||
if (nalChainHead != NULL) {
|
if (nalChainHead != NULL) {
|
||||||
PQUEUED_DECODE_UNIT qdu = (PQUEUED_DECODE_UNIT)malloc(sizeof(*qdu));
|
PQUEUED_DECODE_UNIT qdu = (PQUEUED_DECODE_UNIT)malloc(sizeof(*qdu));
|
||||||
@@ -212,7 +212,8 @@ static void reassembleAvcFrame(int frameNumber) {
|
|||||||
connectionSinkTooSlow(0, frameNumber);
|
connectionSinkTooSlow(0, frameNumber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
int ret = VideoCallbacks.submitDecodeUnit(&qdu->decodeUnit);
|
int ret = VideoCallbacks.submitDecodeUnit(&qdu->decodeUnit);
|
||||||
|
|
||||||
freeQueuedDecodeUnit(qdu);
|
freeQueuedDecodeUnit(qdu);
|
||||||
@@ -258,7 +259,7 @@ static void queueFragment(char *data, int offset, int length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process an RTP Payload */
|
// Process an RTP Payload
|
||||||
static void processRtpPayloadSlow(PNV_VIDEO_PACKET videoPacket, PBUFFER_DESC currentPos) {
|
static void processRtpPayloadSlow(PNV_VIDEO_PACKET videoPacket, PBUFFER_DESC currentPos) {
|
||||||
BUFFER_DESC specialSeq;
|
BUFFER_DESC specialSeq;
|
||||||
int decodingAvc = 0;
|
int decodingAvc = 0;
|
||||||
@@ -323,7 +324,7 @@ static void processRtpPayloadSlow(PNV_VIDEO_PACKET videoPacket, PBUFFER_DESC cur
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return 1 if packet is the first one in the frame */
|
// Return 1 if packet is the first one in the frame
|
||||||
static int isFirstPacket(char flags) {
|
static int isFirstPacket(char flags) {
|
||||||
// Clear the picture data flag
|
// Clear the picture data flag
|
||||||
flags &= ~FLAG_CONTAINS_PIC_DATA;
|
flags &= ~FLAG_CONTAINS_PIC_DATA;
|
||||||
@@ -333,12 +334,12 @@ static int isFirstPacket(char flags) {
|
|||||||
flags == FLAG_SOF);
|
flags == FLAG_SOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adds a fragment directly to the queue */
|
// Adds a fragment directly to the queue
|
||||||
static void processRtpPayloadFast(BUFFER_DESC location) {
|
static void processRtpPayloadFast(BUFFER_DESC location) {
|
||||||
queueFragment(location.data, location.offset, location.length);
|
queueFragment(location.data, location.offset, location.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process an RTP Payload */
|
// Process an RTP Payload
|
||||||
void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) {
|
void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) {
|
||||||
BUFFER_DESC currentPos, specialSeq;
|
BUFFER_DESC currentPos, specialSeq;
|
||||||
int frameIndex;
|
int frameIndex;
|
||||||
@@ -486,7 +487,7 @@ void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add an RTP Packet to the queue */
|
// Add an RTP Packet to the queue
|
||||||
void queueRtpPacket(PRTP_PACKET rtpPacket, int length) {
|
void queueRtpPacket(PRTP_PACKET rtpPacket, int length) {
|
||||||
int dataOffset;
|
int dataOffset;
|
||||||
|
|
||||||
|
|||||||
@@ -25,19 +25,19 @@ static PLT_THREAD decoderThread;
|
|||||||
// the RTP queue will wait for missing/reordered packets.
|
// the RTP queue will wait for missing/reordered packets.
|
||||||
#define RTP_QUEUE_DELAY 10
|
#define RTP_QUEUE_DELAY 10
|
||||||
|
|
||||||
/* Initialize the video stream */
|
// Initialize the video stream
|
||||||
void initializeVideoStream(void) {
|
void initializeVideoStream(void) {
|
||||||
initializeVideoDepacketizer(StreamConfig.packetSize);
|
initializeVideoDepacketizer(StreamConfig.packetSize);
|
||||||
RtpqInitializeQueue(&rtpQueue, RTPQ_DEFAULT_MAX_SIZE, RTP_QUEUE_DELAY);
|
RtpqInitializeQueue(&rtpQueue, RTPQ_DEFAULT_MAX_SIZE, RTP_QUEUE_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up the video stream */
|
// Clean up the video stream
|
||||||
void destroyVideoStream(void) {
|
void destroyVideoStream(void) {
|
||||||
destroyVideoDepacketizer();
|
destroyVideoDepacketizer();
|
||||||
RtpqCleanupQueue(&rtpQueue);
|
RtpqCleanupQueue(&rtpQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UDP Ping proc */
|
// UDP Ping proc
|
||||||
static void UdpPingThreadProc(void *context) {
|
static void UdpPingThreadProc(void *context) {
|
||||||
char pingData[] = { 0x50, 0x49, 0x4E, 0x47 };
|
char pingData[] = { 0x50, 0x49, 0x4E, 0x47 };
|
||||||
struct sockaddr_in6 saddr;
|
struct sockaddr_in6 saddr;
|
||||||
@@ -58,7 +58,7 @@ static void UdpPingThreadProc(void *context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Receive thread proc */
|
// Receive thread proc
|
||||||
static void ReceiveThreadProc(void* context) {
|
static void ReceiveThreadProc(void* context) {
|
||||||
int err;
|
int err;
|
||||||
int bufferSize, receiveSize;
|
int bufferSize, receiveSize;
|
||||||
@@ -118,7 +118,7 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decoder thread proc */
|
// Decoder thread proc
|
||||||
static void DecoderThreadProc(void* context) {
|
static void DecoderThreadProc(void* context) {
|
||||||
PQUEUED_DECODE_UNIT qdu;
|
PQUEUED_DECODE_UNIT qdu;
|
||||||
while (!PltIsThreadInterrupted(&decoderThread)) {
|
while (!PltIsThreadInterrupted(&decoderThread)) {
|
||||||
@@ -137,7 +137,7 @@ static void DecoderThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the first frame of the video stream */
|
// Read the first frame of the video stream
|
||||||
int readFirstFrame(void) {
|
int readFirstFrame(void) {
|
||||||
// All that matters is that we close this socket.
|
// All that matters is that we close this socket.
|
||||||
// This starts the flow of video on Gen 3 servers.
|
// This starts the flow of video on Gen 3 servers.
|
||||||
@@ -148,7 +148,7 @@ int readFirstFrame(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Terminate the video stream */
|
// Terminate the video stream
|
||||||
void stopVideoStream(void) {
|
void stopVideoStream(void) {
|
||||||
PltInterruptThread(&udpPingThread);
|
PltInterruptThread(&udpPingThread);
|
||||||
PltInterruptThread(&receiveThread);
|
PltInterruptThread(&receiveThread);
|
||||||
@@ -180,7 +180,7 @@ void stopVideoStream(void) {
|
|||||||
VideoCallbacks.cleanup();
|
VideoCallbacks.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the video stream */
|
// Start the video stream
|
||||||
int startVideoStream(void* rendererContext, int drFlags) {
|
int startVideoStream(void* rendererContext, int drFlags) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user