Better commenting on methods

This commit is contained in:
Michelle Bergeron 2014-10-23 01:16:35 -04:00
parent affcb84d36
commit d9f55e9c8f
10 changed files with 63 additions and 2 deletions

View File

@ -8,6 +8,7 @@ void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int le
buff->byteOrder = byteOrder;
}
/* Get the long long in the correct byte order */
static long long byteSwapLongLong(PBYTE_BUFFER buff, long long l) {
if (buff->byteOrder == BYTE_ORDER_BIG) {
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) {
if (buff->byteOrder == BYTE_ORDER_BIG) {
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) {
if (buff->byteOrder == BYTE_ORDER_BIG) {
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) {
if (buff->position + sizeof(*c) > buff->length) {
return 0;
@ -46,6 +50,7 @@ int BbGet(PBYTE_BUFFER buff, char *c) {
return 1;
}
/* Get a short from the byte buffer */
int BbGetShort(PBYTE_BUFFER buff, short *s) {
if (buff->position + sizeof(*s) >= buff->length) {
return 0;
@ -59,6 +64,7 @@ int BbGetShort(PBYTE_BUFFER buff, short *s) {
return 1;
}
/* Get an int from the byte buffer */
int BbGetInt(PBYTE_BUFFER buff, int *i) {
if (buff->position + sizeof(*i) > buff->length) {
return 0;
@ -72,6 +78,7 @@ int BbGetInt(PBYTE_BUFFER buff, int *i) {
return 1;
}
/* Get a long from the byte buffer */
int BbGetLong(PBYTE_BUFFER buff, long long *l) {
if (buff->position + sizeof(*l) > buff->length) {
return 0;
@ -85,6 +92,7 @@ int BbGetLong(PBYTE_BUFFER buff, long long *l) {
return 1;
}
/* Put an int into the byte buffer */
int BbPutInt(PBYTE_BUFFER buff, int i) {
if (buff->position + sizeof(i) > buff->length) {
return 0;
@ -98,6 +106,7 @@ int BbPutInt(PBYTE_BUFFER buff, int i) {
return 1;
}
/* Put a long into the byte buffer */
int BbPutLong(PBYTE_BUFFER buff, long long l) {
if (buff->position + sizeof(l) > buff->length) {
return 0;
@ -111,6 +120,7 @@ int BbPutLong(PBYTE_BUFFER buff, long long l) {
return 1;
}
/* Put a short into the byte buffer */
int BbPutShort(PBYTE_BUFFER buff, short s) {
if (buff->position + sizeof(s) > buff->length) {
return 0;
@ -124,6 +134,7 @@ int BbPutShort(PBYTE_BUFFER buff, short s) {
return 1;
}
/* Put a byte into the buffer */
int BbPut(PBYTE_BUFFER buff, char c) {
if (buff->position + sizeof(c) > buff->length) {
return 0;

View File

@ -7,6 +7,7 @@ static CONNECTION_LISTENER_CALLBACKS originalCallbacks;
static int alreadyTerminated;
/* Connection stages */
static const char* stageNames[STAGE_MAX] = {
"none",
"platform initialization",
@ -21,10 +22,12 @@ static const char* stageNames[STAGE_MAX] = {
"input stream establishment"
};
/* Get the name of the current stage based on its number */
const char* LiGetStageName(int stage) {
return stageNames[stage];
}
/* Stop the connection by undoing the step at the current stage and those before it */
void LiStopConnection(void) {
if (stage == STAGE_INPUT_STREAM_START) {
Limelog("Stopping input stream...");
@ -131,6 +134,7 @@ void ClInternalDisplayTransientMessage(char* message)
originalCallbacks.displayTransientMessage(message);
}
/* Starts the connection to the streaming machine */
int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks, void* renderContext, int drFlags) {
int err;

View File

@ -4,6 +4,7 @@
#include "ByteBuffer.h"
/* NV control stream packet header */
typedef struct _NVCTL_PACKET_HEADER {
unsigned short type;
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
/* Initializes the control stream */
int initializeControlStream(IP_ADDRESS addr, PSTREAM_CONFIGURATION streamConfigPtr, PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
memcpy(&streamConfig, streamConfigPtr, sizeof(*streamConfigPtr));
@ -49,28 +51,34 @@ int initializeControlStream(IP_ADDRESS addr, PSTREAM_CONFIGURATION streamConfigP
return 0;
}
/* Cleans up control stream */
void destroyControlStream(void) {
PltCloseEvent(&resyncEvent);
}
/* Resync if the connection is too slow */
void connectionSinkTooSlow(int startFrame, int endFrame) {
// FIXME: Send ranges
PltSetEvent(&resyncEvent);
}
/* Resync if we're losing frames */
void connectionDetectedFrameLoss(int startFrame, int endFrame) {
// FIXME: Send ranges
PltSetEvent(&resyncEvent);
}
/* When we receive a frame, update the number of our current frame */
void connectionReceivedFrame(int frameIndex) {
currentFrame = frameIndex;
}
/* When we lose packets, update our packet loss count */
void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket) {
lossCountSinceLastReport += (nextReceivedPacket - lastReceivedPacket) - 1;
}
/* Reads an NV control stream packet */
static PNVCTL_PACKET_HEADER readNvctlPacket(void) {
NVCTL_PACKET_HEADER staticHeader;
PNVCTL_PACKET_HEADER fullPacket;
@ -195,6 +203,7 @@ static void resyncThreadFunc(void* context) {
}
}
/* Stops the control stream */
int stopControlStream(void) {
PltInterruptThread(&lossStatsThread);
PltInterruptThread(&resyncThread);
@ -213,6 +222,7 @@ int stopControlStream(void) {
return 0;
}
/* Starts the control stream */
int startControlStream(void) {
int err;

View File

@ -18,6 +18,7 @@ static OAES_CTX* oaesContext;
#define MAX_INPUT_PACKET_SIZE 128
/* Contains input stream packets */
typedef struct _PACKET_HOLDER {
int packetLength;
union {
@ -29,6 +30,7 @@ typedef struct _PACKET_HOLDER {
} packet;
} PACKET_HOLDER, *PPACKET_HOLDER;
/* Initializes the input stream */
int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCallbacks,
char* aesKeyData, int aesKeyDataLength, char* aesIv, int aesIvLength) {
host = addr;
@ -65,6 +67,7 @@ int initializeInputStream(IP_ADDRESS addr, PCONNECTION_LISTENER_CALLBACKS clCall
return 0;
}
/* Destroys and cleans up the input stream */
void destroyInputStream(void) {
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
@ -87,6 +90,7 @@ void destroyInputStream(void) {
initialized = 0;
}
/* Input thread proc */
static void inputSendThreadProc(void* context) {
SOCK_RET err;
PPACKET_HOLDER holder;
@ -135,6 +139,7 @@ static void inputSendThreadProc(void* context) {
}
}
/* Begin the input stream */
int startInputStream(void) {
int err;
@ -153,6 +158,7 @@ int startInputStream(void) {
return err;
}
/* Stops the input stream */
int stopInputStream(void) {
PltInterruptThread(&inputSendThread);
@ -167,6 +173,7 @@ int stopInputStream(void) {
return 0;
}
/* Send a mouse move event to the streaming machine */
int LiSendMouseMoveEvent(short deltaX, short deltaY) {
PPACKET_HOLDER holder;
int err;
@ -194,6 +201,7 @@ int LiSendMouseMoveEvent(short deltaX, short deltaY) {
return err;
}
/* Send a mouse button event to the streaming machine */
int LiSendMouseButtonEvent(char action, int button) {
PPACKET_HOLDER holder;
int err;
@ -220,6 +228,7 @@ int LiSendMouseButtonEvent(char action, int button) {
return err;
}
/* Send a key press event to the streaming machine */
int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) {
PPACKET_HOLDER holder;
int err;
@ -249,6 +258,7 @@ int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) {
return err;
}
/* Send a controller event to the streaming machine */
int LiSendControllerEvent(short buttonFlags, char leftTrigger, char rightTrigger,
short leftStickX, short leftStickY, short rightStickX, short rightStickY)
{
@ -285,6 +295,7 @@ int LiSendControllerEvent(short buttonFlags, char leftTrigger, char rightTrigger
return err;
}
/* Send a scroll event to the streaming machine */
int LiSendScrollEvent(char scrollClicks) {
PPACKET_HOLDER holder;
int err;

View File

@ -1,5 +1,6 @@
#include "LinkedBlockingQueue.h"
/* Destroy the linked blocking queue and associated mutex and event */
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead) {
PltDeleteMutex(&queueHead->mutex);
PltCloseEvent(&queueHead->containsDataEvent);
@ -7,6 +8,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEU
return queueHead->head;
}
/* Flush the queue */
PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead) {
PLINKED_BLOCKING_QUEUE_ENTRY head;
@ -26,6 +28,7 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead
return head;
}
/* Linked blocking queue init */
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
int err;

View File

@ -168,6 +168,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
return -1;
}
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);
if (thread->handle == NULL) {
CloseHandle(thread->termevent);
@ -182,6 +183,7 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
PltUnlockMutex(&thread_list_lock);
// Now the thread can run
// TODO can't use ResumeThread in kernel32.dll
ResumeThread(thread->handle);
err = 0;

View File

@ -79,7 +79,7 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
return 1;
}
/* Returns 1 on success, 0 otherwise */
/* Send RTSP message and get response */
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response) {
SOCK_RET err;
int ret = 0;

View File

@ -14,6 +14,7 @@ typedef struct _SDP_OPTION {
struct _SDP_OPTION *next;
} SDP_OPTION, *PSDP_OPTION;
/* Cleanup the attribute list */
static void freeAttributeList(PSDP_OPTION head) {
PSDP_OPTION next;
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) {
PSDP_OPTION currentEntry = head;
int size = 0;
@ -38,6 +40,7 @@ static int getSerializedAttributeListSize(PSDP_OPTION head) {
return size;
}
/* Populate the serialized attribute list into a string */
static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
PSDP_OPTION currentEntry = head;
int offset = 0;
@ -52,6 +55,7 @@ static int fillSerializedAttributeList(char* buffer, PSDP_OPTION head) {
return offset;
}
/* Add an attribute */
static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload, int payloadLen) {
PSDP_OPTION option, currentOption;
@ -80,6 +84,7 @@ static int addAttributeBinary(PSDP_OPTION *head, char* name, const void* payload
return 0;
}
/* Add an attribute string */
static int addAttributeString(PSDP_OPTION *head, char* name, const char* payload) {
// We purposefully omit the null terminating character
return addAttributeBinary(head, name, payload, (int)strlen(payload));
@ -166,6 +171,7 @@ static PSDP_OPTION getAttributesList(PSTREAM_CONFIGURATION streamConfig, struct
return NULL;
}
/* Populate the SDP header with required information */
static int fillSdpHeader(char* buffer, struct in_addr targetAddress) {
return sprintf(buffer,
"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));
}
/* Populate the SDP tail with required information */
static int fillSdpTail(char* buffer) {
return sprintf(buffer,
"t=0 0\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) {
PSDP_OPTION attributeList;
int offset;

View File

@ -52,11 +52,13 @@ static void cleanupAvcFrameState(void) {
nalChainDataLength = 0;
}
/* Cleanup AVC frame state and set that we're waiting for an IDR Frame*/
static void dropAvcFrameState(void) {
waitingForIdrFrame = 1;
cleanupAvcFrameState();
}
/* Cleanup the list of decode units */
static void freeDecodeUnitList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
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) {
BUFFER_DESC specialSeq;
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) {
BUFFER_DESC currentPos, specialSeq;
int frameIndex;

View File

@ -20,6 +20,7 @@ static PLT_THREAD udpPingThread;
static PLT_THREAD receiveThread;
static PLT_THREAD decoderThread;
/* Initialize the video stream */
void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PDECODER_RENDERER_CALLBACKS drCallbacks,
PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
memcpy(&callbacks, drCallbacks, sizeof(callbacks));
@ -30,12 +31,14 @@ void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig,
initializeVideoDepacketizer(configuration.packetSize);
}
/* Clean up the video stream */
void destroyVideoStream(void) {
callbacks.release();
destroyVideoDepacketizer();
}
/* UDP Ping proc */
static void UdpPingThreadProc(void *context) {
char pingData [] = { 0x50, 0x49, 0x4E, 0x47 };
struct sockaddr_in saddr;
@ -58,6 +61,7 @@ static void UdpPingThreadProc(void *context) {
}
}
/* Receive thread proc */
static void ReceiveThreadProc(void* context) {
SOCK_RET err;
int bufferSize;
@ -86,6 +90,7 @@ static void ReceiveThreadProc(void* context) {
free(buffer);
}
/* Decoder thread proc */
static void DecoderThreadProc(void* context) {
PDECODE_UNIT du;
while (!PltIsThreadInterrupted(&decoderThread)) {
@ -100,6 +105,7 @@ static void DecoderThreadProc(void* context) {
}
}
/* Read the first frame of the video stream */
int readFirstFrame(void) {
char* firstFrame;
SOCK_RET err;
@ -131,6 +137,7 @@ int readFirstFrame(void) {
return 0;
}
/* Terminate the video stream */
void stopVideoStream(void) {
callbacks.stop();
@ -156,6 +163,7 @@ void stopVideoStream(void) {
PltCloseThread(&decoderThread);
}
/* Start the video stream */
int startVideoStream(void* rendererContext, int drFlags) {
int err;
@ -182,7 +190,7 @@ int startVideoStream(void* rendererContext, int drFlags) {
return err;
}
// This must be called before the decoder thread starts submitting
//This must be called before the decoder thread starts submitting
// decode units
callbacks.start();