diff --git a/limelight-common/Limelight-internal.h b/limelight-common/Limelight-internal.h index dec0db6..b58dfef 100644 --- a/limelight-common/Limelight-internal.h +++ b/limelight-common/Limelight-internal.h @@ -20,7 +20,6 @@ void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket); 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 d7058c1..b549057 100644 --- a/limelight-common/Limelight.h +++ b/limelight-common/Limelight.h @@ -29,14 +29,12 @@ 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); @@ -92,6 +90,8 @@ 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 8804665..09471fc 100644 --- a/limelight-common/LinkedBlockingQueue.c +++ b/limelight-common/LinkedBlockingQueue.c @@ -71,6 +71,38 @@ 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; @@ -101,12 +133,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 1f03efe..a56df32 100644 --- a/limelight-common/LinkedBlockingQueue.h +++ b/limelight-common/LinkedBlockingQueue.h @@ -7,6 +7,7 @@ #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; @@ -26,4 +27,5 @@ 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); \ No newline at end of file +PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead); +int LbqPollQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data); \ No newline at end of file diff --git a/limelight-common/VideoDepacketizer.c b/limelight-common/VideoDepacketizer.c index fc3406b..10a8161 100644 --- a/limelight-common/VideoDepacketizer.c +++ b/limelight-common/VideoDepacketizer.c @@ -134,7 +134,7 @@ static void reassembleFrame(int frameNumber) { } } -int getNextDecodeUnit(PDECODE_UNIT *du) { +int LiGetNextDecodeUnit(PDECODE_UNIT *du) { int err = LbqWaitForQueueElement(&decodeUnitQueue, (void**)du); if (err == LBQ_SUCCESS) { return 1; @@ -144,6 +144,17 @@ int getNextDecodeUnit(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 28172ca..09f88f7 100644 --- a/limelight-common/VideoStream.c +++ b/limelight-common/VideoStream.c @@ -18,7 +18,6 @@ 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) { @@ -83,20 +82,6 @@ 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; @@ -133,7 +118,6 @@ void stopVideoStream(void) { PltInterruptThread(&udpPingThread); PltInterruptThread(&receiveThread); - PltInterruptThread(&decoderThread); if (firstFrameSocket != INVALID_SOCKET) { closesocket(firstFrameSocket); @@ -146,11 +130,9 @@ void stopVideoStream(void) { PltJoinThread(&udpPingThread); PltJoinThread(&receiveThread); - PltJoinThread(&decoderThread); PltCloseThread(&udpPingThread); PltCloseThread(&receiveThread); - PltCloseThread(&decoderThread); } int startVideoStream(void* rendererContext, int drFlags) { @@ -176,11 +158,6 @@ int startVideoStream(void* rendererContext, int drFlags) { return err; } - err = PltCreateThread(DecoderThreadProc, NULL, &decoderThread); - if (err != 0) { - return err; - } - callbacks.start(); return 0;