mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-12-03 19:51:33 +00:00
Use relaxed atomic for receivedDataFromPeer
This commit is contained in:
1 parent
edb4e9e05f
commit
e44e4290ed
2 files changed
+10
-12
No files matched your search
+5
-6
@@ -15,7 +15,7 @@ static uint32_t avRiKeyId;
|
|||||||
static unsigned short lastSeq;
|
static unsigned short lastSeq;
|
||||||
|
|
||||||
static bool pingThreadStarted;
|
static bool pingThreadStarted;
|
||||||
static bool receivedDataFromPeer;
|
static atomic_bool receivedDataFromPeer; // Read by stopAudioStream()
|
||||||
static uint64_t firstReceiveTime;
|
static uint64_t firstReceiveTime;
|
||||||
|
|
||||||
#ifdef LC_DEBUG
|
#ifdef LC_DEBUG
|
||||||
@@ -69,7 +69,7 @@ int initializeAudioStream(void) {
|
|||||||
LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
|
LbqInitializeLinkedBlockingQueue(&packetQueue, 30);
|
||||||
RtpaInitializeQueue(&rtpAudioQueue);
|
RtpaInitializeQueue(&rtpAudioQueue);
|
||||||
lastSeq = 0;
|
lastSeq = 0;
|
||||||
receivedDataFromPeer = false;
|
atomic_store_explicit(&receivedDataFromPeer, false, memory_order_relaxed);
|
||||||
pingThreadStarted = false;
|
pingThreadStarted = false;
|
||||||
firstReceiveTime = 0;
|
firstReceiveTime = 0;
|
||||||
audioDecryptionCtx = PltCreateCryptoContext(0);
|
audioDecryptionCtx = PltCreateCryptoContext(0);
|
||||||
@@ -277,7 +277,7 @@ static void AudioReceiveThreadProc(void* context) {
|
|||||||
else if (packet->header.size == 0) {
|
else if (packet->header.size == 0) {
|
||||||
// Receive timed out; try again
|
// Receive timed out; try again
|
||||||
|
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_load_explicit(&receivedDataFromPeer, memory_order_relaxed)) {
|
||||||
waitingForAudioMs += UDP_RECV_POLL_TIMEOUT_MS;
|
waitingForAudioMs += UDP_RECV_POLL_TIMEOUT_MS;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -295,8 +295,7 @@ static void AudioReceiveThreadProc(void* context) {
|
|||||||
|
|
||||||
rtp = (PRTP_PACKET)&packet->data[0];
|
rtp = (PRTP_PACKET)&packet->data[0];
|
||||||
|
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_exchange_explicit(&receivedDataFromPeer, true, memory_order_relaxed)) {
|
||||||
receivedDataFromPeer = true;
|
|
||||||
Limelog("Received first audio packet after %d ms\n", waitingForAudioMs);
|
Limelog("Received first audio packet after %d ms\n", waitingForAudioMs);
|
||||||
|
|
||||||
if (firstReceiveTime != 0) {
|
if (firstReceiveTime != 0) {
|
||||||
@@ -401,7 +400,7 @@ static void AudioDecoderThreadProc(void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stopAudioStream(void) {
|
void stopAudioStream(void) {
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_load_explicit(&receivedDataFromPeer, memory_order_relaxed)) {
|
||||||
Limelog("No audio traffic was ever received from the host!\n");
|
Limelog("No audio traffic was ever received from the host!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-6
@@ -16,7 +16,7 @@ static PLT_THREAD udpPingThread;
|
|||||||
static PLT_THREAD receiveThread;
|
static PLT_THREAD receiveThread;
|
||||||
static PLT_THREAD decoderThread;
|
static PLT_THREAD decoderThread;
|
||||||
|
|
||||||
static bool receivedDataFromPeer;
|
static atomic_bool receivedDataFromPeer; // Read by stopVideoStream()
|
||||||
static uint64_t firstDataTimeMs;
|
static uint64_t firstDataTimeMs;
|
||||||
static bool receivedFullFrame;
|
static bool receivedFullFrame;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ void initializeVideoStream(void) {
|
|||||||
initializeVideoDepacketizer(StreamConfig.packetSize);
|
initializeVideoDepacketizer(StreamConfig.packetSize);
|
||||||
RtpvInitializeQueue(&rtpQueue);
|
RtpvInitializeQueue(&rtpQueue);
|
||||||
decryptionCtx = PltCreateCryptoContext(0);
|
decryptionCtx = PltCreateCryptoContext(0);
|
||||||
receivedDataFromPeer = false;
|
atomic_store_explicit(&receivedDataFromPeer, false, memory_order_relaxed);
|
||||||
firstDataTimeMs = 0;
|
firstDataTimeMs = 0;
|
||||||
receivedFullFrame = false;
|
receivedFullFrame = false;
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ static void VideoReceiveThreadProc(void* context) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (err == 0) {
|
else if (err == 0) {
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_load_explicit(&receivedDataFromPeer, memory_order_relaxed)) {
|
||||||
// If we wait many seconds without ever receiving a video packet,
|
// If we wait many seconds without ever receiving a video packet,
|
||||||
// assume something is broken and terminate the connection.
|
// assume something is broken and terminate the connection.
|
||||||
waitingForVideoMs += UDP_RECV_POLL_TIMEOUT_MS;
|
waitingForVideoMs += UDP_RECV_POLL_TIMEOUT_MS;
|
||||||
@@ -161,8 +161,7 @@ static void VideoReceiveThreadProc(void* context) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_exchange_explicit(&receivedDataFromPeer, true, memory_order_relaxed)) {
|
||||||
receivedDataFromPeer = true;
|
|
||||||
Limelog("Received first video packet after %d ms\n", waitingForVideoMs);
|
Limelog("Received first video packet after %d ms\n", waitingForVideoMs);
|
||||||
|
|
||||||
firstDataTimeMs = PltGetMillis();
|
firstDataTimeMs = PltGetMillis();
|
||||||
@@ -279,7 +278,7 @@ int readFirstFrame(void) {
|
|||||||
|
|
||||||
// Terminate the video stream
|
// Terminate the video stream
|
||||||
void stopVideoStream(void) {
|
void stopVideoStream(void) {
|
||||||
if (!receivedDataFromPeer) {
|
if (!atomic_load_explicit(&receivedDataFromPeer, memory_order_relaxed)) {
|
||||||
Limelog("No video traffic was ever received from the host!\n");
|
Limelog("No video traffic was ever received from the host!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user