From cfe75eb56952718cdf0855a813b3b7d46d920ae5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 17 Jan 2022 21:56:06 -0600 Subject: [PATCH] Add workaround for keyboard and UTF-8 events interfering with each other --- src/ControlStream.c | 14 ++++++++++++++ src/InputStream.c | 11 +++++++++++ src/Limelight-internal.h | 1 + 3 files changed, 26 insertions(+) diff --git a/src/ControlStream.c b/src/ControlStream.c index acd5c20..1647c67 100644 --- a/src/ControlStream.c +++ b/src/ControlStream.c @@ -1116,6 +1116,20 @@ int sendInputPacketOnControlStream(unsigned char* data, int length) { return 0; } +bool isControlDataInTransit(void) { + bool ret = false; + + PltLockMutex(&enetMutex); + if (peer != NULL && peer->state == ENET_PEER_STATE_CONNECTED) { + if (peer->reliableDataInTransit != 0) { + ret = true; + } + } + PltUnlockMutex(&enetMutex); + + return ret; +} + bool LiGetEstimatedRttInfo(uint32_t* estimatedRtt, uint32_t* estimatedRttVariance) { bool ret = false; diff --git a/src/InputStream.c b/src/InputStream.c index fb3c661..684f918 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -386,6 +386,17 @@ static void inputSendThreadProc(void* context) { uint32_t totalLength = PAYLOAD_SIZE(holder) - sizeof(uint32_t); uint32_t i = 0; + // HACK: This is a workaround for the fact that GFE doesn't appear to synchronize keyboard + // and UTF-8 text events with each other. We need to make sure any previous keyboard events + // have been processed prior to sending these UTF-8 events to avoid interference between + // the two (especially with modifier keys). + while (!PltIsThreadInterrupted(&inputSendThread) && isControlDataInTransit()) { + PltSleepMs(10); + } + + // Finally, sleep an additional 50 ms to allow the events to be processed by Windows + PltSleepMs(50); + // We send each Unicode code point individually. This way we can always ensure they will // never straddle a packet boundary (which will cause a parsing error on the host). while (i < totalLength) { diff --git a/src/Limelight-internal.h b/src/Limelight-internal.h index 9402a43..1181223 100644 --- a/src/Limelight-internal.h +++ b/src/Limelight-internal.h @@ -89,6 +89,7 @@ void connectionReceivedCompleteFrame(int frameIndex); void connectionSawFrame(int frameIndex); void connectionLostPackets(int lastReceivedPacket, int nextReceivedPacket); int sendInputPacketOnControlStream(unsigned char* data, int length); +bool isControlDataInTransit(void); int performRtspHandshake(void);