mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Properly flush the DU queue when we hit the limit. Fixes extreme lag that occurs after streaming for a bit.
This commit is contained in:
parent
dc926946dd
commit
0ee1609cc4
@ -28,13 +28,8 @@ void initializeAudioStream(IP_ADDRESS host, PAUDIO_RENDERER_CALLBACKS arCallback
|
|||||||
LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
|
LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tear down the audio stream once we're done with it */
|
static void freePacketList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
||||||
void destroyAudioStream(void) {
|
PLINKED_BLOCKING_QUEUE_ENTRY nextEntry;
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
|
|
||||||
|
|
||||||
callbacks.release();
|
|
||||||
|
|
||||||
entry = LbqDestroyLinkedBlockingQueue(&packetQueue);
|
|
||||||
|
|
||||||
while (entry != NULL) {
|
while (entry != NULL) {
|
||||||
nextEntry = entry->flink;
|
nextEntry = entry->flink;
|
||||||
@ -44,6 +39,15 @@ void destroyAudioStream(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Tear down the audio stream once we're done with it */
|
||||||
|
void destroyAudioStream(void) {
|
||||||
|
callbacks.release();
|
||||||
|
|
||||||
|
freePacketList(LbqDestroyLinkedBlockingQueue(&packetQueue));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void UdpPingThreadProc(void *context) {
|
static void UdpPingThreadProc(void *context) {
|
||||||
/* Ping in ASCII */
|
/* Ping in ASCII */
|
||||||
char pingData[] = { 0x50, 0x49, 0x4E, 0x47 };
|
char pingData[] = { 0x50, 0x49, 0x4E, 0x47 };
|
||||||
@ -112,6 +116,7 @@ static void ReceiveThreadProc(void* context) {
|
|||||||
|
|
||||||
if (err == LBQ_BOUND_EXCEEDED) {
|
if (err == LBQ_BOUND_EXCEEDED) {
|
||||||
Limelog("Audio packet queue overflow\n");
|
Limelog("Audio packet queue overflow\n");
|
||||||
|
freePacketList(LbqFlushQueueItems(&packetQueue));
|
||||||
}
|
}
|
||||||
else if (err == LBQ_INTERRUPTED) {
|
else if (err == LBQ_INTERRUPTED) {
|
||||||
Limelog("Receive thread terminating #2\n");
|
Limelog("Receive thread terminating #2\n");
|
||||||
|
@ -7,6 +7,25 @@ PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEU
|
|||||||
return queueHead->head;
|
return queueHead->head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead) {
|
||||||
|
PLINKED_BLOCKING_QUEUE_ENTRY head;
|
||||||
|
|
||||||
|
PltLockMutex(&queueHead->mutex);
|
||||||
|
|
||||||
|
// Save the old head
|
||||||
|
head = queueHead->head;
|
||||||
|
|
||||||
|
// Reinitialize the queue to empty
|
||||||
|
queueHead->head = NULL;
|
||||||
|
queueHead->tail = NULL;
|
||||||
|
queueHead->currentSize = 0;
|
||||||
|
PltClearEvent(&queueHead->containsDataEvent);
|
||||||
|
|
||||||
|
PltUnlockMutex(&queueHead->mutex);
|
||||||
|
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -26,4 +26,5 @@ typedef struct _LINKED_BLOCKING_QUEUE {
|
|||||||
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound);
|
int LbqInitializeLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead, int sizeBound);
|
||||||
int LbqOfferQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data);
|
int LbqOfferQueueItem(PLINKED_BLOCKING_QUEUE queueHead, void* data);
|
||||||
int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data);
|
int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data);
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead);
|
PLINKED_BLOCKING_QUEUE_ENTRY LbqDestroyLinkedBlockingQueue(PLINKED_BLOCKING_QUEUE queueHead);
|
||||||
|
PLINKED_BLOCKING_QUEUE_ENTRY LbqFlushQueueItems(PLINKED_BLOCKING_QUEUE queueHead);
|
@ -59,16 +59,20 @@ static void dropAvcFrameState(void) {
|
|||||||
cleanupAvcFrameState();
|
cleanupAvcFrameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup video depacketizer and free malloced memory */
|
static void freeDecodeUnitList(PLINKED_BLOCKING_QUEUE_ENTRY entry) {
|
||||||
void destroyVideoDepacketizer(void) {
|
PLINKED_BLOCKING_QUEUE_ENTRY nextEntry;
|
||||||
PLINKED_BLOCKING_QUEUE_ENTRY entry, nextEntry;
|
|
||||||
|
|
||||||
entry = LbqDestroyLinkedBlockingQueue(&decodeUnitQueue);
|
|
||||||
while (entry != NULL) {
|
while (entry != NULL) {
|
||||||
nextEntry = entry->flink;
|
nextEntry = entry->flink;
|
||||||
|
free(entry->data);
|
||||||
free(entry);
|
free(entry);
|
||||||
entry = nextEntry;
|
entry = nextEntry;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup video depacketizer and free malloced memory */
|
||||||
|
void destroyVideoDepacketizer(void) {
|
||||||
|
freeDecodeUnitList(LbqDestroyLinkedBlockingQueue(&decodeUnitQueue));
|
||||||
|
|
||||||
cleanupAvcFrameState();
|
cleanupAvcFrameState();
|
||||||
}
|
}
|
||||||
@ -139,15 +143,19 @@ static void reassembleAvcFrame(int frameNumber) {
|
|||||||
if (LbqOfferQueueItem(&decodeUnitQueue, du) == LBQ_BOUND_EXCEEDED) {
|
if (LbqOfferQueueItem(&decodeUnitQueue, du) == LBQ_BOUND_EXCEEDED) {
|
||||||
Limelog("Decode unit queue overflow\n");
|
Limelog("Decode unit queue overflow\n");
|
||||||
|
|
||||||
|
// Clear frame state and wait for an IDR
|
||||||
nalChainHead = du->bufferList;
|
nalChainHead = du->bufferList;
|
||||||
nalChainDataLength = du->fullLength;
|
nalChainDataLength = du->fullLength;
|
||||||
|
dropAvcFrameState();
|
||||||
|
|
||||||
|
// Free the DU
|
||||||
free(du);
|
free(du);
|
||||||
|
|
||||||
|
// Flush the decode unit queue
|
||||||
|
freeDecodeUnitList(LbqFlushQueueItems(&decodeUnitQueue));
|
||||||
|
|
||||||
// FIXME: Get proper lower bound
|
// FIXME: Get proper lower bound
|
||||||
connectionSinkTooSlow(0, frameNumber);
|
connectionSinkTooSlow(0, frameNumber);
|
||||||
|
|
||||||
// Clear frame state and wait for an IDR
|
|
||||||
dropAvcFrameState();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user