Synchronize HDR metadata updates

This commit is contained in:
Cameron Gutman committed 2026-11-11 14:44:50 -06:00
1 parent 274ec03d85
commit 74a61b9f27
1 file changed
+23 -6
+23 -6
View File
@@ -114,8 +114,9 @@ static uint32_t lastSeenFrame;
static bool stopping;
static bool disconnectPending;
static bool encryptedControlStream;
static bool hdrEnabled;
static atomic_bool hdrEnabled;
static SS_HDR_METADATA hdrMetadata;
static PLT_MUTEX hdrMutex;
static int intervalGoodFrameCount;
static int intervalTotalFrameCount;
@@ -320,6 +321,7 @@ int initializeControlStream(void) {
LbqInitializeLinkedBlockingQueue(&frameFecStatusQueue, 8); // Limits number of frame status reports per periodic ping interval
LbqInitializeLinkedBlockingQueue(&asyncCallbackQueue, 30);
PltCreateMutex(&enetMutex);
PltCreateMutex(&hdrMutex);
encryptedControlStream = APP_VERSION_AT_LEAST(7, 1, 431);
@@ -369,7 +371,7 @@ int initializeControlStream(void) {
usePeriodicPing = APP_VERSION_AT_LEAST(7, 1, 415);
encryptionCtx = PltCreateCryptoContext(0);
decryptionCtx = PltCreateCryptoContext(CTRL_CHANNEL_COUNT);
hdrEnabled = false;
atomic_store_explicit(&hdrEnabled, false, memory_order_relaxed);
memset(&hdrMetadata, 0, sizeof(hdrMetadata));
return 0;
@@ -395,6 +397,7 @@ void destroyControlStream(void) {
freeBasicLbqList(LbqDestroyLinkedBlockingQueue(&frameFecStatusQueue));
freeBasicLbqList(LbqDestroyLinkedBlockingQueue(&asyncCallbackQueue));
PltDeleteMutex(&hdrMutex);
PltDeleteMutex(&enetMutex);
}
@@ -1173,7 +1176,7 @@ static void asyncCallbackThreadFunc(void* context) {
queuedCb = nextCb;
}
ListenerCallbacks.setHdrMode(hdrEnabled);
ListenerCallbacks.setHdrMode(LiGetCurrentHostDisplayHdrMode());
break;
case IDX_SET_MOTION_EVENT:
@@ -1475,6 +1478,8 @@ static void controlReceiveThreadFunc(void* context) {
BbInitializeWrappedBuffer(&bb, (char*)ctlHdr, sizeof(*ctlHdr), packetLength - sizeof(*ctlHdr), BYTE_ORDER_LITTLE);
PltLockMutex(&hdrMutex);
BbGet8(&bb, &enableByte);
if (IS_SUNSHINE()) {
// Zero the metadata buffer to properly handle older servers if we have to add new fields
@@ -1494,7 +1499,9 @@ static void controlReceiveThreadFunc(void* context) {
BbGet16(&bb, &hdrMetadata.maxFullFrameLuminance);
}
hdrEnabled = (enableByte != 0);
atomic_store_explicit(&hdrEnabled, enableByte != 0, memory_order_release);
PltUnlockMutex(&hdrMutex);
}
// Process client callbacks in a separate thread
@@ -2278,14 +2285,24 @@ int startControlStream(void) {
}
bool LiGetCurrentHostDisplayHdrMode(void) {
return hdrEnabled;
return atomic_load_explicit(&hdrEnabled, memory_order_acquire);
}
bool LiGetHdrMetadata(PSS_HDR_METADATA metadata) {
if (!IS_SUNSHINE() || !hdrEnabled) {
if (!IS_SUNSHINE() || !atomic_load_explicit(&hdrEnabled, memory_order_acquire)) {
return false;
}
PltLockMutex(&hdrMutex);
// Check again inside the lock to make sure HDR is still enabled
if (!atomic_load_explicit(&hdrEnabled, memory_order_relaxed)) {
PltUnlockMutex(&hdrMutex);
return false;
}
*metadata = hdrMetadata;
PltUnlockMutex(&hdrMutex);
return true;
}