From f2af6c8bd90b3c93d9a654b91bc19bf1ef1b293e Mon Sep 17 00:00:00 2001 From: Michelle Bergeron Date: Sun, 29 Jun 2014 17:36:03 -0700 Subject: [PATCH] Revert "Remove decoding thread like in Java common" This reverts commit 50733f6d7af941fb0771b1e4ad77b85183261715. --- limelight-common/Limelight-internal.h | 1 + limelight-common/Limelight.h | 4 +-- limelight-common/LinkedBlockingQueue.c | 36 ++------------------------ limelight-common/LinkedBlockingQueue.h | 4 +-- limelight-common/VideoDepacketizer.c | 13 +--------- limelight-common/VideoStream.c | 23 ++++++++++++++++ 6 files changed, 30 insertions(+), 51 deletions(-) diff --git a/limelight-common/Limelight-internal.h b/limelight-common/Limelight-internal.h index 28d536b..8e4733a 100644 --- a/limelight-common/Limelight-internal.h +++ b/limelight-common/Limelight-internal.h @@ -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); diff --git a/limelight-common/Limelight.h b/limelight-common/Limelight.h index d162cc5..b6c2068 100644 --- a/limelight-common/Limelight.h +++ b/limelight-common/Limelight.h @@ -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); diff --git a/limelight-common/LinkedBlockingQueue.c b/limelight-common/LinkedBlockingQueue.c index 09471fc..8804665 100644 --- a/limelight-common/LinkedBlockingQueue.c +++ b/limelight-common/LinkedBlockingQueue.c @@ -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; } diff --git a/limelight-common/LinkedBlockingQueue.h b/limelight-common/LinkedBlockingQueue.h index a56df32..1f03efe 100644 --- a/limelight-common/LinkedBlockingQueue.h +++ b/limelight-common/LinkedBlockingQueue.h @@ -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); \ No newline at end of file +PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead); \ No newline at end of file diff --git a/limelight-common/VideoDepacketizer.c b/limelight-common/VideoDepacketizer.c index 202fca6..3452dd0 100644 --- a/limelight-common/VideoDepacketizer.c +++ b/limelight-common/VideoDepacketizer.c @@ -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; diff --git a/limelight-common/VideoStream.c b/limelight-common/VideoStream.c index 09f88f7..28172ca 100644 --- a/limelight-common/VideoStream.c +++ b/limelight-common/VideoStream.c @@ -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;