mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-18 06:41:06 +00:00
Better commenting on methods
This commit is contained in:
@@ -8,6 +8,7 @@ void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int le
|
|||||||
buff->byteOrder = byteOrder;
|
buff->byteOrder = byteOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the long long in the correct byte order */
|
||||||
static long long byteSwapLongLong(PBYTE_BUFFER buff, long long l) {
|
static long long byteSwapLongLong(PBYTE_BUFFER buff, long long l) {
|
||||||
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
||||||
return HTONLL(l);
|
return HTONLL(l);
|
||||||
@@ -17,6 +18,7 @@ static long long byteSwapLongLong(PBYTE_BUFFER buff, long long l) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the int in the correct byte order */
|
||||||
static int byteSwapInt(PBYTE_BUFFER buff, int i) {
|
static int byteSwapInt(PBYTE_BUFFER buff, int i) {
|
||||||
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
||||||
return htonl(i);
|
return htonl(i);
|
||||||
@@ -26,6 +28,7 @@ static int byteSwapInt(PBYTE_BUFFER buff, int i) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the short in the correct byte order */
|
||||||
static int byteSwapShort(PBYTE_BUFFER buff, short s) {
|
static int byteSwapShort(PBYTE_BUFFER buff, short s) {
|
||||||
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
if (buff->byteOrder == BYTE_ORDER_BIG) {
|
||||||
return htons(s);
|
return htons(s);
|
||||||
@@ -35,6 +38,7 @@ static int byteSwapShort(PBYTE_BUFFER buff, short s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a byte from the byte buffer */
|
||||||
int BbGet(PBYTE_BUFFER buff, char *c) {
|
int BbGet(PBYTE_BUFFER buff, char *c) {
|
||||||
if (buff->position + sizeof(*c) > buff->length) {
|
if (buff->position + sizeof(*c) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -46,6 +50,7 @@ int BbGet(PBYTE_BUFFER buff, char *c) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a short from the byte buffer */
|
||||||
int BbGetShort(PBYTE_BUFFER buff, short *s) {
|
int BbGetShort(PBYTE_BUFFER buff, short *s) {
|
||||||
if (buff->position + sizeof(*s) >= buff->length) {
|
if (buff->position + sizeof(*s) >= buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -59,6 +64,7 @@ int BbGetShort(PBYTE_BUFFER buff, short *s) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get an int from the byte buffer */
|
||||||
int BbGetInt(PBYTE_BUFFER buff, int *i) {
|
int BbGetInt(PBYTE_BUFFER buff, int *i) {
|
||||||
if (buff->position + sizeof(*i) > buff->length) {
|
if (buff->position + sizeof(*i) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -72,6 +78,7 @@ int BbGetInt(PBYTE_BUFFER buff, int *i) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get a long from the byte buffer */
|
||||||
int BbGetLong(PBYTE_BUFFER buff, long long *l) {
|
int BbGetLong(PBYTE_BUFFER buff, long long *l) {
|
||||||
if (buff->position + sizeof(*l) > buff->length) {
|
if (buff->position + sizeof(*l) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -85,6 +92,7 @@ int BbGetLong(PBYTE_BUFFER buff, long long *l) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Put an int into the byte buffer */
|
||||||
int BbPutInt(PBYTE_BUFFER buff, int i) {
|
int BbPutInt(PBYTE_BUFFER buff, int i) {
|
||||||
if (buff->position + sizeof(i) > buff->length) {
|
if (buff->position + sizeof(i) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -98,6 +106,7 @@ int BbPutInt(PBYTE_BUFFER buff, int i) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Put a long into the byte buffer */
|
||||||
int BbPutLong(PBYTE_BUFFER buff, long long l) {
|
int BbPutLong(PBYTE_BUFFER buff, long long l) {
|
||||||
if (buff->position + sizeof(l) > buff->length) {
|
if (buff->position + sizeof(l) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -111,6 +120,7 @@ int BbPutLong(PBYTE_BUFFER buff, long long l) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Put a short into the byte buffer */
|
||||||
int BbPutShort(PBYTE_BUFFER buff, short s) {
|
int BbPutShort(PBYTE_BUFFER buff, short s) {
|
||||||
if (buff->position + sizeof(s) > buff->length) {
|
if (buff->position + sizeof(s) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -124,6 +134,7 @@ int BbPutShort(PBYTE_BUFFER buff, short s) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Put a byte into the buffer */
|
||||||
int BbPut(PBYTE_BUFFER buff, char c) {
|
int BbPut(PBYTE_BUFFER buff, char c) {
|
||||||
if (buff->position + sizeof(c) > buff->length) {
|
if (buff->position + sizeof(c) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ static CONNECTION_LISTENER_CALLBACKS originalCallbacks;
|
|||||||
|
|
||||||
static int alreadyTerminated;
|
static int alreadyTerminated;
|
||||||
|
|
||||||
|
/* Connection stages */
|
||||||
static const char* stageNames[STAGE_MAX] = {
|
static const char* stageNames[STAGE_MAX] = {
|
||||||
"none",
|
"none",
|
||||||
"platform initialization",
|
"platform initialization",
|
||||||
@@ -21,10 +22,12 @@ static const char* stageNames[STAGE_MAX] = {
|
|||||||
"input stream establishment"
|
"input stream establishment"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
void LiStopConnection(void) {
|
void LiStopConnection(void) {
|
||||||
if (stage == STAGE_INPUT_STREAM_START) {
|
if (stage == STAGE_INPUT_STREAM_START) {
|
||||||
Limelog("Stopping input stream...");
|
Limelog("Stopping input stream...");
|
||||||
@@ -131,6 +134,7 @@ void ClInternalDisplayTransientMessage(char* message)
|
|||||||
originalCallbacks.displayTransientMessage(message);
|
originalCallbacks.displayTransientMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Starts the connection to the streaming machine */
|
||||||
int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
||||||
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks, void* renderContext, int drFlags) {
|
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks, void* renderContext, int drFlags) {
|
||||||
int err;
|
int err;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -38,6 +39,7 @@ static const int PPAYLOAD_START_STREAM_B[4] = { 0, 0, 0, 0xa }; // FIXME: Little
|
|||||||
|
|
||||||
#define LOSS_REPORT_INTERVAL_MS 50
|
#define LOSS_REPORT_INTERVAL_MS 50
|
||||||
|
|
||||||
|
/* Initializes the control stream */
|
||||||
int initializeControlStream(IP_ADDRESS addr, PSTREAM_CONFIGURATION streamConfigPtr, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
int initializeControlStream(IP_ADDRESS addr, PSTREAM_CONFIGURATION streamConfigPtr, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
||||||
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
|
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
|
||||||
|
|
||||||
@@ -49,28 +51,34 @@ int initializeControlStream(IP_ADDRESS addr, PSTREAM_CONFIGURATION streamConfigP
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cleans up control stream */
|
||||||
void destroyControlStream(void) {
|
void destroyControlStream(void) {
|
||||||
PltCloseEvent(&resyncEvent);
|
PltCloseEvent(&resyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Resync if the connection is too slow */
|
||||||
void connectionSinkTooSlow(int startFrame, int endFrame) {
|
void connectionSinkTooSlow(int startFrame, int endFrame) {
|
||||||
// FIXME: Send ranges
|
// FIXME: Send ranges
|
||||||
PltSetEvent(&resyncEvent);
|
PltSetEvent(&resyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Resync if we're losing frames */
|
||||||
void connectionDetectedFrameLoss(int startFrame, int endFrame) {
|
void connectionDetectedFrameLoss(int startFrame, int endFrame) {
|
||||||
// FIXME: Send ranges
|
// FIXME: Send ranges
|
||||||
PltSetEvent(&resyncEvent);
|
PltSetEvent(&resyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
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 */
|
||||||
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;
|
||||||
@@ -195,6 +203,7 @@ static void resyncThreadFunc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stops the control stream */
|
||||||
int stopControlStream(void) {
|
int stopControlStream(void) {
|
||||||
PltInterruptThread(&lossStatsThread);
|
PltInterruptThread(&lossStatsThread);
|
||||||
PltInterruptThread(&resyncThread);
|
PltInterruptThread(&resyncThread);
|
||||||
@@ -213,6 +222,7 @@ int stopControlStream(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Starts the control stream */
|
||||||
int startControlStream(void) {
|
int startControlStream(void) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ static OAES_CTX* oaesContext;
|
|||||||
|
|
||||||
#define MAX_INPUT_PACKET_SIZE 128
|
#define MAX_INPUT_PACKET_SIZE 128
|
||||||
|
|
||||||
|
/* Contains input stream packets */
|
||||||
typedef struct _PACKET_HOLDER {
|
typedef struct _PACKET_HOLDER {
|
||||||
int packetLength;
|
int packetLength;
|
||||||
union {
|
union {
|
||||||
@@ -29,6 +30,7 @@ typedef struct _PACKET_HOLDER {
|
|||||||
} packet;
|
} packet;
|
||||||
} PACKET_HOLDER, *PPACKET_HOLDER;
|
} PACKET_HOLDER, *PPACKET_HOLDER;
|
||||||
|
|
||||||
|
/* Initializes the input stream */
|
||||||
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
|
||||||
char* aesKeyData, int aesKeyDataLength, char* aesIv, int aesIvLength) {
|
char* aesKeyData, int aesKeyDataLength, char* aesIv, int aesIvLength) {
|
||||||
host = addr;
|
host = addr;
|
||||||
@@ -65,6 +67,7 @@ int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCall
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
@@ -87,6 +90,7 @@ void destroyInputStream(void) {
|
|||||||
initialized = 0;
|
initialized = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -135,6 +139,7 @@ static void inputSendThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Begin the input stream */
|
||||||
int startInputStream(void) {
|
int startInputStream(void) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -153,6 +158,7 @@ int startInputStream(void) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stops the input stream */
|
||||||
int stopInputStream(void) {
|
int stopInputStream(void) {
|
||||||
PltInterruptThread(&inputSendThread);
|
PltInterruptThread(&inputSendThread);
|
||||||
|
|
||||||
@@ -167,6 +173,7 @@ int stopInputStream(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -194,6 +201,7 @@ int LiSendMouseMoveEvent(short deltaX, short deltaY) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -220,6 +228,7 @@ int LiSendMouseButtonEvent(char action, int button) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -249,6 +258,7 @@ int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Send a controller event to the streaming machine */
|
||||||
int LiSendControllerEvent(short buttonFlags, char leftTrigger, char rightTrigger,
|
int LiSendControllerEvent(short buttonFlags, char leftTrigger, char rightTrigger,
|
||||||
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
|
||||||
{
|
{
|
||||||
@@ -285,6 +295,7 @@ int LiSendControllerEvent(short buttonFlags, char leftTrigger, char rightTrigger
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Send a scroll event to the streaming machine */
|
||||||
int LiSendScrollEvent(char scrollClicks) {
|
int LiSendScrollEvent(char scrollClicks) {
|
||||||
PPACKET_HOLDER holder;
|
PPACKET_HOLDER holder;
|
||||||
int err;
|
int err;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "LinkedBlockingQueue.h"
|
#include "LinkedBlockingQueue.h"
|
||||||
|
|
||||||
|
/* 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);
|
||||||
@@ -7,6 +8,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEU
|
|||||||
return queueHead->head;
|
return queueHead->head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Linked blocking queue init */
|
||||||
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
thread->cancelled = 0;
|
thread->cancelled = 0;
|
||||||
|
// TODO we aren't allowed to use CreateThread API in kernel32.dll
|
||||||
thread->handle = CreateThread(NULL, 0, ThreadProc, ctx, CREATE_SUSPENDED, &thread->tid);
|
thread->handle = CreateThread(NULL, 0, ThreadProc, ctx, CREATE_SUSPENDED, &thread->tid);
|
||||||
if (thread->handle == NULL) {
|
if (thread->handle == NULL) {
|
||||||
CloseHandle(thread->termevent);
|
CloseHandle(thread->termevent);
|
||||||
@@ -182,6 +183,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
|
|||||||
PltUnlockMutex(&thread_list_lock);
|
PltUnlockMutex(&thread_list_lock);
|
||||||
|
|
||||||
// Now the thread can run
|
// Now the thread can run
|
||||||
|
// TODO can't use ResumeThread in kernel32.dll
|
||||||
ResumeThread(thread->handle);
|
ResumeThread(thread->handle);
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns 1 on success, 0 otherwise */
|
/* Send RTSP message and get response */
|
||||||
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response) {
|
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response) {
|
||||||
SOCK_RET err;
|
SOCK_RET err;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|||||||
@@ -14,6 +14,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 */
|
||||||
static void freeAttributeList(PSDP_OPTION head) {
|
static void freeAttributeList(PSDP_OPTION head) {
|
||||||
PSDP_OPTION next;
|
PSDP_OPTION next;
|
||||||
while (head != NULL) {
|
while (head != NULL) {
|
||||||
@@ -23,6 +24,7 @@ static void freeAttributeList(PSDP_OPTION head) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@@ -38,6 +40,7 @@ static int getSerializedAttributeListSize(PSDP_OPTION head) {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -52,6 +55,7 @@ static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
|
|||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
@@ -80,6 +84,7 @@ static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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));
|
||||||
@@ -166,6 +171,7 @@ static PSDP_OPTION getAttributesList(PSTREAM_CONFIGURATION streamConfig, struct
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Populate the SDP header with required information */
|
||||||
static int fillSdpHeader(char* buffer, struct in_addr targetAddress) {
|
static int fillSdpHeader(char* buffer, struct in_addr targetAddress) {
|
||||||
return sprintf(buffer,
|
return sprintf(buffer,
|
||||||
"v=0\r\n"
|
"v=0\r\n"
|
||||||
@@ -173,12 +179,14 @@ static int fillSdpHeader(char* buffer, struct in_addr targetAddress) {
|
|||||||
"s=NVIDIA Streaming Client\r\n", inet_ntoa(targetAddress));
|
"s=NVIDIA Streaming Client\r\n", inet_ntoa(targetAddress));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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"
|
||||||
"m=video 47996 \r\n");
|
"m=video 47996 \r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the SDP attributes for the stream config */
|
||||||
char* getSdpPayloadForStreamConfig(PSTREAM_CONFIGURATION streamConfig, struct in_addr targetAddress, int *length) {
|
char* getSdpPayloadForStreamConfig(PSTREAM_CONFIGURATION streamConfig, struct in_addr targetAddress, int *length) {
|
||||||
PSDP_OPTION attributeList;
|
PSDP_OPTION attributeList;
|
||||||
int offset;
|
int offset;
|
||||||
|
|||||||
@@ -52,11 +52,13 @@ static void cleanupAvcFrameState(void) {
|
|||||||
nalChainDataLength = 0;
|
nalChainDataLength = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Cleanup AVC frame state and set that we're waiting for an IDR Frame*/
|
||||||
static void dropAvcFrameState(void) {
|
static void dropAvcFrameState(void) {
|
||||||
waitingForIdrFrame = 1;
|
waitingForIdrFrame = 1;
|
||||||
cleanupAvcFrameState();
|
cleanupAvcFrameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|
||||||
@@ -213,6 +215,7 @@ static void queueFragment(char *data, int offset, int length) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
@@ -310,6 +313,7 @@ static int isBeforeSigned(int numA, int numB, int ambiguousCase) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ static PLT_THREAD udpPingThread;
|
|||||||
static PLT_THREAD receiveThread;
|
static PLT_THREAD receiveThread;
|
||||||
static PLT_THREAD decoderThread;
|
static PLT_THREAD decoderThread;
|
||||||
|
|
||||||
|
/* Initialize the video stream */
|
||||||
void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PDECODER_RENDERER_CALLBACKS drCallbacks,
|
void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PDECODER_RENDERER_CALLBACKS drCallbacks,
|
||||||
PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
||||||
memcpy(&callbacks, drCallbacks, sizeof(callbacks));
|
memcpy(&callbacks, drCallbacks, sizeof(callbacks));
|
||||||
@@ -30,12 +31,14 @@ void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig,
|
|||||||
initializeVideoDepacketizer(configuration.packetSize);
|
initializeVideoDepacketizer(configuration.packetSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clean up the video stream */
|
||||||
void destroyVideoStream(void) {
|
void destroyVideoStream(void) {
|
||||||
callbacks.release();
|
callbacks.release();
|
||||||
|
|
||||||
destroyVideoDepacketizer();
|
destroyVideoDepacketizer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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_in saddr;
|
struct sockaddr_in saddr;
|
||||||
@@ -58,6 +61,7 @@ static void UdpPingThreadProc(void *context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Receive thread proc */
|
||||||
static void ReceiveThreadProc(void* context) {
|
static void ReceiveThreadProc(void* context) {
|
||||||
SOCK_RET err;
|
SOCK_RET err;
|
||||||
int bufferSize;
|
int bufferSize;
|
||||||
@@ -86,6 +90,7 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Decoder thread proc */
|
||||||
static void DecoderThreadProc(void* context) {
|
static void DecoderThreadProc(void* context) {
|
||||||
PDECODE_UNIT du;
|
PDECODE_UNIT du;
|
||||||
while (!PltIsThreadInterrupted(&decoderThread)) {
|
while (!PltIsThreadInterrupted(&decoderThread)) {
|
||||||
@@ -100,6 +105,7 @@ static void DecoderThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Read the first frame of the video stream */
|
||||||
int readFirstFrame(void) {
|
int readFirstFrame(void) {
|
||||||
char* firstFrame;
|
char* firstFrame;
|
||||||
SOCK_RET err;
|
SOCK_RET err;
|
||||||
@@ -131,6 +137,7 @@ int readFirstFrame(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Terminate the video stream */
|
||||||
void stopVideoStream(void) {
|
void stopVideoStream(void) {
|
||||||
callbacks.stop();
|
callbacks.stop();
|
||||||
|
|
||||||
@@ -156,6 +163,7 @@ void stopVideoStream(void) {
|
|||||||
PltCloseThread(&decoderThread);
|
PltCloseThread(&decoderThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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