mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 14:21:30 +00:00
Initial work for depacketizer
This commit is contained in:
@@ -7,6 +7,10 @@ typedef struct _STREAM_CONFIGURATION {
|
|||||||
int fps;
|
int fps;
|
||||||
} STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION;
|
} STREAM_CONFIGURATION, *PSTREAM_CONFIGURATION;
|
||||||
|
|
||||||
|
typedef struct _LENTRY {
|
||||||
|
struct _LENTRY *next;
|
||||||
|
} LENTRY, *PLENTRY;
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define Limelog printf
|
#define Limelog printf
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltDeleteMutex(PLT_MUTEX *mutex) {
|
void PltDeleteMutex(PLT_MUTEX mutex) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
CloseHandle(*mutex);
|
CloseHandle(mutex);
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltLockMutex(PLT_MUTEX *mutex) {
|
void PltLockMutex(PLT_MUTEX mutex) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
WaitForSingleObject(*mutex, INFINITE);
|
WaitForSingleObject(mutex, INFINITE);
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void PltUnlockMutex(PLT_MUTEX *mutex) {
|
void PltUnlockMutex(PLT_MUTEX mutex) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ReleaseMutex(*mutex);
|
ReleaseMutex(mutex);
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -94,3 +94,53 @@ int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread) {
|
|||||||
|
|
||||||
return err;
|
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
|
#ifdef _WIN32
|
||||||
typedef HANDLE PLT_THREAD;
|
typedef HANDLE PLT_THREAD;
|
||||||
typedef HANDLE PLT_MUTEX;
|
typedef HANDLE PLT_MUTEX;
|
||||||
|
typedef HANDLE PLT_EVENT;
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int PltCreateMutex(PLT_MUTEX *mutex);
|
int PltCreateMutex(PLT_MUTEX *mutex);
|
||||||
void PltDeleteMutex(PLT_MUTEX *mutex);
|
void PltDeleteMutex(PLT_MUTEX mutex);
|
||||||
void PltLockMutex(PLT_MUTEX *mutex);
|
void PltLockMutex(PLT_MUTEX mutex);
|
||||||
void PltUnlockMutex(PLT_MUTEX *mutex);
|
void PltUnlockMutex(PLT_MUTEX mutex);
|
||||||
|
|
||||||
int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread);
|
int PltCreateThread(ThreadEntry entry, void* context, PLT_THREAD *thread);
|
||||||
void PltCloseThread(PLT_THREAD thread);
|
void PltCloseThread(PLT_THREAD thread);
|
||||||
void PltJoinThread(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="Config.cpp" />
|
||||||
<ClCompile Include="ControlStream.cpp" />
|
<ClCompile Include="ControlStream.cpp" />
|
||||||
<ClCompile Include="Handshake.cpp" />
|
<ClCompile Include="Handshake.cpp" />
|
||||||
|
<ClCompile Include="LinkedBlockingQueue.cpp" />
|
||||||
<ClCompile Include="PlatformSockets.cpp" />
|
<ClCompile Include="PlatformSockets.cpp" />
|
||||||
<ClCompile Include="PlatformThreads.cpp" />
|
<ClCompile Include="PlatformThreads.cpp" />
|
||||||
<ClCompile Include="VideoDepacketizer.cpp" />
|
<ClCompile Include="VideoDepacketizer.cpp" />
|
||||||
@@ -85,6 +86,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="ByteBuffer.h" />
|
<ClInclude Include="ByteBuffer.h" />
|
||||||
<ClInclude Include="Limelight.h" />
|
<ClInclude Include="Limelight.h" />
|
||||||
|
<ClInclude Include="LinkedBlockingQueue.h" />
|
||||||
<ClInclude Include="Platform.h" />
|
<ClInclude Include="Platform.h" />
|
||||||
<ClInclude Include="PlatformSockets.h" />
|
<ClInclude Include="PlatformSockets.h" />
|
||||||
<ClInclude Include="PlatformThreads.h" />
|
<ClInclude Include="PlatformThreads.h" />
|
||||||
|
|||||||
@@ -39,6 +39,9 @@
|
|||||||
<ClCompile Include="VideoDepacketizer.cpp">
|
<ClCompile Include="VideoDepacketizer.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="LinkedBlockingQueue.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="PlatformSockets.h">
|
<ClInclude Include="PlatformSockets.h">
|
||||||
@@ -56,5 +59,8 @@
|
|||||||
<ClInclude Include="PlatformThreads.h">
|
<ClInclude Include="PlatformThreads.h">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="LinkedBlockingQueue.h">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user