mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-17 17:05:50 +00:00
Revert "Remove decoding thread like in Java common"
This reverts commit 50733f6d7af941fb0771b1e4ad77b85183261715.
This commit is contained in:
parent
125f81118f
commit
f2af6c8bd9
@ -23,6 +23,7 @@ void terminateRtspHandshake(void);
|
||||
void initializeVideoDepacketizer(int pktSize);
|
||||
void destroyVideoDepacketizer(void);
|
||||
void processRtpPayload(PNV_VIDEO_PACKET videoPacket, int length);
|
||||
int getNextDecodeUnit(PDECODE_UNIT *du);
|
||||
void freeDecodeUnit(PDECODE_UNIT decodeUnit);
|
||||
void queueRtpPacket(PRTP_PACKET rtpPacket, int length);
|
||||
|
||||
|
@ -29,12 +29,14 @@ typedef void(*DecoderRendererSetup)(int width, int height, int redrawRate, void*
|
||||
typedef void(*DecoderRendererStart)(void);
|
||||
typedef void(*DecoderRendererStop)(void);
|
||||
typedef void(*DecoderRendererRelease)(void);
|
||||
typedef void(*DecoderRendererSubmitDecodeUnit)(PDECODE_UNIT decodeUnit);
|
||||
|
||||
typedef struct _DECODER_RENDERER_CALLBACKS {
|
||||
DecoderRendererSetup setup;
|
||||
DecoderRendererStart start;
|
||||
DecoderRendererStop stop;
|
||||
DecoderRendererRelease release;
|
||||
DecoderRendererSubmitDecodeUnit submitDecodeUnit;
|
||||
} DECODER_RENDERER_CALLBACKS, *PDECODER_RENDERER_CALLBACKS;
|
||||
|
||||
typedef void(*AudioRendererInit)(void);
|
||||
@ -90,8 +92,6 @@ int LiStartConnection(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PCONN
|
||||
PDECODER_RENDERER_CALLBACKS drCallbacks, PAUDIO_RENDERER_CALLBACKS arCallbacks, void* renderContext, int drFlags);
|
||||
void LiStopConnection(void);
|
||||
const char* LiGetStageName(int stage);
|
||||
int LiGetNextDecodeUnit(PDECODE_UNIT *du);
|
||||
int LiPollNextDecodeUnit(PDECODE_UNIT *du);
|
||||
|
||||
int LiSendMouseMoveEvent(short deltaX, short deltaY);
|
||||
|
||||
|
@ -71,38 +71,6 @@ int LbqOfferQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data) {
|
||||
return LBQ_SUCCESS;
|
||||
}
|
||||
|
||||
int LbqPollQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) {
|
||||
PLINKED_BLOCKING_QUEUE_ENTRY entry;
|
||||
|
||||
PltLockMutex(&queueHead->mutex);
|
||||
|
||||
if (queueHead->head == NULL) {
|
||||
PltUnlockMutex(&queueHead->mutex);
|
||||
return LBQ_EMPTY;
|
||||
}
|
||||
|
||||
entry = queueHead->head;
|
||||
queueHead->head = entry->flink;
|
||||
queueHead->currentSize--;
|
||||
if (queueHead->head == NULL) {
|
||||
LC_ASSERT(queueHead->currentSize == 0);
|
||||
queueHead->tail = NULL;
|
||||
PltClearEvent(&queueHead->containsDataEvent);
|
||||
}
|
||||
else {
|
||||
LC_ASSERT(queueHead->currentSize != 0);
|
||||
queueHead->head->blink = NULL;
|
||||
}
|
||||
|
||||
PltUnlockMutex(&queueHead->mutex);
|
||||
|
||||
*data = entry->data;
|
||||
|
||||
free(entry);
|
||||
|
||||
return LBQ_SUCCESS;
|
||||
}
|
||||
|
||||
int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) {
|
||||
PLINKED_BLOCKING_QUEUE_ENTRY entry;
|
||||
int err;
|
||||
@ -133,12 +101,12 @@ int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) {
|
||||
queueHead->head->blink = NULL;
|
||||
}
|
||||
|
||||
PltUnlockMutex(&queueHead->mutex);
|
||||
|
||||
*data = entry->data;
|
||||
|
||||
free(entry);
|
||||
|
||||
PltUnlockMutex(&queueHead->mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
#define LBQ_INTERRUPTED 1
|
||||
#define LBQ_BOUND_EXCEEDED 2
|
||||
#define LBQ_NO_MEMORY 3
|
||||
#define LBQ_EMPTY 4
|
||||
|
||||
typedef struct _LINKED_BLOCKING_QUEUE_ENTRY {
|
||||
struct _LINKED_BLOCKING_QUEUE_ENTRY *flink;
|
||||
@ -27,5 +26,4 @@ typedef struct _LINKED_BLOCKING_QUEUE {
|
||||
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound);
|
||||
int LbqOfferQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data);
|
||||
int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data);
|
||||
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead);
|
||||
int LbqPollQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data);
|
||||
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead);
|
@ -134,7 +134,7 @@ static void reassembleFrame(int frameNumber) {
|
||||
}
|
||||
}
|
||||
|
||||
int LiGetNextDecodeUnit(PDECODE_UNIT *du) {
|
||||
int getNextDecodeUnit(PDECODE_UNIT *du) {
|
||||
int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)du);
|
||||
if (err == LBQ_SUCCESS) {
|
||||
return 1;
|
||||
@ -144,17 +144,6 @@ int LiGetNextDecodeUnit(PDECODE_UNIT *du) {
|
||||
}
|
||||
}
|
||||
|
||||
int LiPollNextDecodeUnit(PDECODE_UNIT *du) {
|
||||
int err = LbqPollQueueElement(&decodeUnitQueue, (void**) du);
|
||||
if (err == LBQ_SUCCESS) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
LC_ASSERT(err == LBQ_EMPTY);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void freeDecodeUnit(PDECODE_UNIT decodeUnit) {
|
||||
PLENTRY lastEntry;
|
||||
|
||||
|
@ -18,6 +18,7 @@ static SOCKET firstFrameSocket = INVALID_SOCKET;
|
||||
|
||||
static PLT_THREAD udpPingThread;
|
||||
static PLT_THREAD receiveThread;
|
||||
static PLT_THREAD decoderThread;
|
||||
|
||||
void initializeVideoStream(IP_ADDRESS host, PSTREAM_CONFIGURATION streamConfig, PDECODER_RENDERER_CALLBACKS drCallbacks,
|
||||
PCONNECTION_LISTENER_CALLBACKS clCallbacks) {
|
||||
@ -82,6 +83,20 @@ static void ReceiveThreadProc(void* context) {
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static void DecoderThreadProc(void* context) {
|
||||
PDECODE_UNIT du;
|
||||
while (!PltIsThreadInterrupted(&decoderThread)) {
|
||||
if (!getNextDecodeUnit(&du)) {
|
||||
printf("Decoder thread terminating\n");
|
||||
return;
|
||||
}
|
||||
|
||||
callbacks.submitDecodeUnit(du);
|
||||
|
||||
freeDecodeUnit(du);
|
||||
}
|
||||
}
|
||||
|
||||
int readFirstFrame(void) {
|
||||
char* firstFrame;
|
||||
int err;
|
||||
@ -118,6 +133,7 @@ void stopVideoStream(void) {
|
||||
|
||||
PltInterruptThread(&udpPingThread);
|
||||
PltInterruptThread(&receiveThread);
|
||||
PltInterruptThread(&decoderThread);
|
||||
|
||||
if (firstFrameSocket != INVALID_SOCKET) {
|
||||
closesocket(firstFrameSocket);
|
||||
@ -130,9 +146,11 @@ void stopVideoStream(void) {
|
||||
|
||||
PltJoinThread(&udpPingThread);
|
||||
PltJoinThread(&receiveThread);
|
||||
PltJoinThread(&decoderThread);
|
||||
|
||||
PltCloseThread(&udpPingThread);
|
||||
PltCloseThread(&receiveThread);
|
||||
PltCloseThread(&decoderThread);
|
||||
}
|
||||
|
||||
int startVideoStream(void* rendererContext, int drFlags) {
|
||||
@ -158,6 +176,11 @@ int startVideoStream(void* rendererContext, int drFlags) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
callbacks.start();
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user