Repository navigation
fix(windows,webrtc): RemoteIdd capture crash and pacing, stream fitted to the TV's link - #12
Merged
Merged
Conversation
The RemoteIdd snapshot took the driver's shared texture first and then waited, with it held, for a free image and for the encoder to release that image's capture texture. When the encoder ran late, every frame the driver presented in that window found the texture busy and was dropped, which showed up as an occasional skip of one or two frames, more often while the image pool was still being filled at the start of a stream. Get the destination image ready and locked before taking the driver's texture, so it is held only for the copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qpc_time_difference multiplied the tick difference by the counter frequency instead of dividing by it, so with the usual 10 MHz counter every difference came out ten thousand times too small. Frame timestamps were therefore the moment of capture rather than the present, and so were the RTP timestamps and the host latency reported to clients. Convert in floating point: ticks times 1e9 overflows int64 after about 15 minutes at 10 MHz. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the client Only Desktop Duplication set display_refresh_rate, and display_base_t left it uninitialized, so with RemoteIdd capture() never knew the display rate and sampled a client-rate grid. A seat at 120 Hz streamed at 60 fps then lined the grid up with the display ticks: whether a slot took the odd or the even frame depended on timer and delivery jitter, so the stream mixed one- and three-frame steps (measured: 30-50% of frames) and the capture grabbed the driver's texture just as the driver published the next frame. RemoteIdd now reads the refresh rate of its display, so capture() sends frames as they arrive, capped at the client rate. With timestamps on the display ticks the limiter tolerates half a tick instead of a whole one: a whole tick puts every other frame exactly on its slot boundary and the same flip comes back. The rate fields now start at zero for backends that do not set them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep the copy of SharedFrame.h in step with the driver, which now waits up to half a millisecond for the consumer to release the texture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The limiter only took over at 1.5 times the client rate, so a seat at 120 Hz streamed at 90 fps stayed on the grid. There it sent runs of consecutive frames, fell behind and skipped, instead of three frames out of four in a steady 1-1-2. With timestamps on the display ticks the limiter keeps that pattern at any rate clearly above the client's (1.1 times); composed timestamps keep the old 1.5 threshold. The capture tests now stream a 120 Hz seat at 60 and at 90 fps and check the content steps of the frames sent. They tolerate 2% of stray steps for a busy machine; the grid broke the pattern far more often. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At 4K and 80 Mbps a Samsung TV on its 100 Mbps Ethernet port lost parts of large frames, asked for a keyframe, and every PLI was answered with a new 1-3 MB IDR: up to 26 a second, which overflowed the link and the PC's UDP send buffer (25,000 packets dropped in a second) and left the picture black for seconds. - One keyframe on its way at a time: requests while one is being encoded or sent, and for 250 ms after it has gone out, are taken as having crossed it. - Retransmission history of 4096 packets instead of 512, enough for a whole 4K keyframe, so a lost packet is resent instead of a new IDR. - The TV may report its link (network.type, network.linkKbps). Video is then paced at 90 % of the link instead of 800 Mbps, the bitrate is kept to 60 % of it, and retransmissions are charged to the same budget. TVs that report nothing are paced as before. - RTP payloads of 1380 bytes on Ethernet or Wi-Fi instead of 1220. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first TV test, with a TV that did not report its link, was worse than before: 109,000 packets dropped in six minutes and IDRs of up to 5 MB. The larger NACK history let a single request resend megabytes at once from the network thread, outside the pacer, overflowing the 1 MiB UDP send buffer; and 250 ms between keyframes was not enough while the TV kept losing them. - Retransmissions are queued (once per packet, at most 1 MiB) and sent by the pacer at the paced rate, ahead of the frame being sent and, between frames, from the video sender thread. - The wait after a keyframe doubles, up to 2 s, each time the TV asks again soon after one; five quiet seconds start over at 250 ms. - Tests use tests_common.h. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
capture() lowered the client rate to a fractional display rate with client_frame_rate % display_refresh_rate_rounded whenever the refresh-rate denominator was above 1. Only Desktop Duplication set those fields, and display_ridd_vram_t has its own constructor, so with RemoteIdd capture they held whatever was on the heap. A denominator above 1 with a rounded rate of 0 crashed Sunshine with STATUS_INTEGER_DIVIDE_BY_ZERO on the first capture after a seat started (OpenstreamCo/OpenStreamMultiSeat#106). The fields already start at zero; the adjustment now also skips a rounded rate or client rate of zero. It moves to adjust_capture_rate() so it can be tested, and the client rate fields start at zero too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Seat capture fixes for OpenStreamMS and a WebRTC stream that fits the TV's network link.
Divide-by-zero on the first capture of a seat (refs OpenstreamCo/OpenStreamMultiSeat#106)
capture()lowered the client rate to a fractional display rate withclient_frame_rate % display_refresh_rate_rounded. Only Desktop Duplication set those fields, anddisplay_ridd_vram_thas its own constructor, so with RemoteIdd they held heap garbage: a denominator above 1 with a rounded rate of 0 crashed Sunshine withSTATUS_INTEGER_DIVIDE_BY_ZERO(the shipped 2.2.0/2.3.0 build, at RVA 0x1d422f).adjust_capture_rate()) skips a zero rate.RemoteIdd capture
qpc_time_differencemultiplied the tick difference by the counter frequency instead of dividing by it, so every difference came out ten thousand times too small and frame, RTP and host-latency timestamps were the capture time rather than the present.WebRTC: stream fitted to the TV's link
network.type,network.linkKbps): video is then paced at 90 % of it and the bitrate kept to 60 %. RTP payloads are 1380 bytes on Ethernet or Wi-Fi.Tests:
RemoteIdd*,Webrtc*,ConstructorContracts*,WindowsQpcTest*,FrameRateLimiterTests*,D3dkmtAbiTests*andFramerate*: 138 pass, 4 new for the capture rate. The WebRTC changes were tried on a Samsung TV over 4K at 80 Mbps; the first round was worse; the second (retransmission pacing and keyframe back-off) is in the OpenStreamMS preview and not yet confirmed on the TV.🤖 Generated with Claude Code