diff --git a/limelight-common/Limelight.h b/limelight-common/Limelight.h index 545b2b5..dc73443 100644 --- a/limelight-common/Limelight.h +++ b/limelight-common/Limelight.h @@ -7,6 +7,10 @@ typedef struct _STREAM_CONFIGURATION { int fps; } STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION; +typedef struct _LENTRY { + struct _LENTRY *next; +} LENTRY, *PLENTRY; + #include #define Limelog printf diff --git a/limelight-common/LinkedBlockingQueue.cpp b/limelight-common/LinkedBlockingQueue.cpp new file mode 100644 index 0000000..1030d7a --- /dev/null +++ b/limelight-common/LinkedBlockingQueue.cpp @@ -0,0 +1,84 @@ +#include "LinkedBlockingQueue.h" + +int initializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) { + int err; + + err = PltCreateEvent(&queueHead->containsDataEvent); + if (err != 0) { + return err; + } + + err = PltCreateMutex(&queueHead->mutex); + if (err != 0) { + return err; + } + + queueHead->head = NULL; + queueHead->sizeBound = sizeBound; + + return 0; +} + +int offerQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data) { + PLINKED_BLOCKING_QUEUE_ENTRY entry, lastEntry; + + entry = (PLINKED_BLOCKING_QUEUE_ENTRY) malloc(sizeof(*entry)); + if (entry == NULL) { + return 0; + } + + entry->next = NULL; + entry->data = data; + + PltLockMutex(queueHead->mutex); + + if (queueHead->head == NULL) { + queueHead->head = entry; + } + else { + lastEntry = queueHead->head; + while (lastEntry->next != NULL) { + lastEntry = lastEntry->next; + } + lastEntry->next = entry; + } + + PltSetEvent(queueHead->containsDataEvent); + + PltUnlockMutex(queueHead->mutex); + + return 1; +} + +void* waitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead) { + PLINKED_BLOCKING_QUEUE_ENTRY entry; + void* data; + + for (;;) { + PltWaitForEvent(queueHead->containsDataEvent); + + PltLockMutex(queueHead->mutex); + + if (queueHead->head == NULL) { + PltUnlockMutex(queueHead->mutex); + continue; + } + + entry = queueHead->head; + queueHead->head = entry->next; + + data = entry->data; + + free(entry); + + if (queueHead->head == NULL) { + PltClearEvent(queueHead->containsDataEvent); + } + + PltUnlockMutex(queueHead->mutex); + + break; + } + + return data; +} diff --git a/limelight-common/LinkedBlockingQueue.h b/limelight-common/LinkedBlockingQueue.h new file mode 100644 index 0000000..23ff559 --- /dev/null +++ b/limelight-common/LinkedBlockingQueue.h @@ -0,0 +1,18 @@ +#include "platform.h" +#include "PlatformThreads.h" + +typedef struct _LINKED_BLOCKING_QUEUE_ENTRY { + struct _LINKED_BLOCKING_QUEUE_ENTRY *next; + void* data; +} LINKED_BLOCKING_QUEUE_ENTRY, *PLINKED_BLOCKING_QUEUE_ENTRY; + +typedef struct _LINKED_BLOCKING_QUEUE { + PLT_MUTEX mutex; + PLT_EVENT containsDataEvent; + int sizeBound; + PLINKED_BLOCKING_QUEUE_ENTRY head; +} LINKED_BLOCKING_QUEUE, *PLINKED_BLOCKING_QUEUE; + +int initializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound); +int offerQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data); +void* waitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead); \ No newline at end of file diff --git a/limelight-common/PlatformThreads.cpp b/limelight-common/PlatformThreads.cpp index 9b81208..18af15d 100644 --- a/limelight-common/PlatformThreads.cpp +++ b/limelight-common/PlatformThreads.cpp @@ -30,23 +30,23 @@ int PltCreateMutex(PLT_MUTEX *mutex) { #endif } -void PltDeleteMutex(PLT_MUTEX *mutex) { +void PltDeleteMutex(PLT_MUTEX mutex) { #ifdef _WIN32 - CloseHandle(*mutex); + CloseHandle(mutex); #else #endif } -void PltLockMutex(PLT_MUTEX *mutex) { +void PltLockMutex(PLT_MUTEX mutex) { #ifdef _WIN32 - WaitForSingleObject(*mutex, INFINITE); + WaitForSingleObject(mutex, INFINITE); #else #endif } -void PltUnlockMutex(PLT_MUTEX *mutex) { +void PltUnlockMutex(PLT_MUTEX mutex) { #ifdef _WIN32 - ReleaseMutex(*mutex); + ReleaseMutex(mutex); #else #endif } @@ -93,4 +93,54 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) { #endif return err; -} \ No newline at end of file +} + +int PltCreateEvent(PLT_EVENT *event) { +#ifdef _WIN32 + *event = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!*event) { + return -1; + } + + return 0; +#else +#endif +} + +void PltCloseEvent(PLT_EVENT event) { +#ifdef _WIN32 + CloseHandle(event); +#else +#endif +} + +void PltSetEvent(PLT_EVENT event) { +#ifdef _WIN32 + SetEvent(event); +#else +#endif +} + +void PltClearEvent(PLT_EVENT event) { +#ifdef _WIN32 + ResetEvent(event); +#else +#endif +} + +void PltPulseEvent(PLT_EVENT event) { +#ifdef _WIN32 + PulseEvent(event); +#else +#endif +} + +void PltWaitForEvent(PLT_EVENT event) { +#ifdef _WIN32 + WaitForSingleObject(event, INFINITE); +#else +#endif +} + + + diff --git a/limelight-common/PlatformThreads.h b/limelight-common/PlatformThreads.h index 269f1da..64e7010 100644 --- a/limelight-common/PlatformThreads.h +++ b/limelight-common/PlatformThreads.h @@ -5,14 +5,22 @@ typedef void (*ThreadEntry)(void *context); #ifdef _WIN32 typedef HANDLE PLT_THREAD; typedef HANDLE PLT_MUTEX; +typedef HANDLE PLT_EVENT; #else #endif int PltCreateMutex(PLT_MUTEX *mutex); -void PltDeleteMutex(PLT_MUTEX *mutex); -void PltLockMutex(PLT_MUTEX *mutex); -void PltUnlockMutex(PLT_MUTEX *mutex); +void PltDeleteMutex(PLT_MUTEX mutex); +void PltLockMutex(PLT_MUTEX mutex); +void PltUnlockMutex(PLT_MUTEX mutex); int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread); void PltCloseThread(PLT_THREAD thread); void PltJoinThread(PLT_THREAD thread); + +int PltCreateEvent(PLT_EVENT *event); +void PltCloseEvent(PLT_EVENT event); +void PltSetEvent(PLT_EVENT event); +void PltClearEvent(PLT_EVENT event); +void PltPulseEvent(PLT_EVENT event); +void PltWaitForEvent(PLT_EVENT event); \ No newline at end of file diff --git a/limelight-common/VideoDepacketizer.cpp b/limelight-common/VideoDepacketizer.cpp index e69de29..85e1a55 100644 --- a/limelight-common/VideoDepacketizer.cpp +++ b/limelight-common/VideoDepacketizer.cpp @@ -0,0 +1,9 @@ +#include "Platform.h" +#include "Limelight.h" +#include "LinkedBlockingQueue.h" + +LENTRY *nalChainHead; +int nalChainDataLength; +int decodingAvc; + +LINKED_BLOCKING_QUEUE decodeUnitQueue; \ No newline at end of file diff --git a/limelight-common/limelight-common.vcxproj b/limelight-common/limelight-common.vcxproj index a44955e..f18cbcf 100644 --- a/limelight-common/limelight-common.vcxproj +++ b/limelight-common/limelight-common.vcxproj @@ -78,6 +78,7 @@ + @@ -85,6 +86,7 @@ + diff --git a/limelight-common/limelight-common.vcxproj.filters b/limelight-common/limelight-common.vcxproj.filters index 226b809..d441d51 100644 --- a/limelight-common/limelight-common.vcxproj.filters +++ b/limelight-common/limelight-common.vcxproj.filters @@ -39,6 +39,9 @@ Source Files + + Source Files + @@ -56,5 +59,8 @@ Source Files + + Source Files + \ No newline at end of file