mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-10 17:56:06 +00:00
Initial work for depacketizer
This commit is contained in:
@@ -7,6 +7,10 @@ typedef struct _STREAM_CONFIGURATION {
|
||||
int fps;
|
||||
} STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION;
|
||||
|
||||
typedef struct _LENTRY {
|
||||
struct _LENTRY *next;
|
||||
} LENTRY, *PLENTRY;
|
||||
|
||||
#include <stdio.h>
|
||||
#define Limelog printf
|
||||
|
||||
|
||||
84
limelight-common/LinkedBlockingQueue.cpp
Normal file
84
limelight-common/LinkedBlockingQueue.cpp
Normal file
@@ -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;
|
||||
}
|
||||
18
limelight-common/LinkedBlockingQueue.h
Normal file
18
limelight-common/LinkedBlockingQueue.h
Normal file
@@ -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);
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "Platform.h"
|
||||
#include "Limelight.h"
|
||||
#include "LinkedBlockingQueue.h"
|
||||
|
||||
LENTRY *nalChainHead;
|
||||
int nalChainDataLength;
|
||||
int decodingAvc;
|
||||
|
||||
LINKED_BLOCKING_QUEUE decodeUnitQueue;
|
||||
@@ -78,6 +78,7 @@
|
||||
<ClCompile Include="Config.cpp" />
|
||||
<ClCompile Include="ControlStream.cpp" />
|
||||
<ClCompile Include="Handshake.cpp" />
|
||||
<ClCompile Include="LinkedBlockingQueue.cpp" />
|
||||
<ClCompile Include="PlatformSockets.cpp" />
|
||||
<ClCompile Include="PlatformThreads.cpp" />
|
||||
<ClCompile Include="VideoDepacketizer.cpp" />
|
||||
@@ -85,6 +86,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ByteBuffer.h" />
|
||||
<ClInclude Include="Limelight.h" />
|
||||
<ClInclude Include="LinkedBlockingQueue.h" />
|
||||
<ClInclude Include="Platform.h" />
|
||||
<ClInclude Include="PlatformSockets.h" />
|
||||
<ClInclude Include="PlatformThreads.h" />
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
<ClCompile Include="VideoDepacketizer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="LinkedBlockingQueue.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="PlatformSockets.h">
|
||||
@@ -56,5 +59,8 @@
|
||||
<ClInclude Include="PlatformThreads.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="LinkedBlockingQueue.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user