Fix thread safety issues in VideoStream

Several fixes for race conditions and resource management in VideoStream:

  • pendingFrames mutex: Add pendingFramesMutex to protect pendingFrames which is accessed from both the frame submission thread (sendFrame inserts) and the FreeRDP callback thread (onFrameAcknowledge removes).

  • Atomic requestedFrameRate: Make requestedFrameRate atomic since it is read by the frame submission thread and written by the main thread via updateRequestedFrameRate().

  • Destructor cleanup: Call close() in the destructor to ensure the frame submission thread is stopped and resources are cleaned up.

  • close() ordering: Stop the frame submission thread BEFORE closing the GFX context to prevent use-after-free. Clear pending state and reset gfxContext to prevent double-close.

  • Frame submission guard: Don't dequeue frames until CapsAdvertise has completed and the GFX channel is ready. Without this, the initial I-frame (keyframe) could be dequeued and dropped before the channel is ready, causing a black screen until the next keyframe.

Tested with: Windows 11 mstsc → KDE Plasma 6.6.1 (Wayland)

Merge request reports

Loading