Skip to content

feat(stream): add adaptive NVENC bitrate control - #5460

Open
Dragon-kanji wants to merge 8 commits into
LizardByte:masterfrom
Dragon-kanji:feat/adaptive-bitrate
Open

feat(stream): add adaptive NVENC bitrate control#5460
Dragon-kanji wants to merge 8 commits into
LizardByte:masterfrom
Dragon-kanji:feat/adaptive-bitrate

Conversation

@Dragon-kanji

Copy link
Copy Markdown

Description

This PR adds an opt-in adaptive bitrate path for Sunshine's native NVENC encoder on Windows. It is disabled by default.

The reason I built it is pretty practical. I stream from a Windows desktop to a Steam Deck docked to my TV, and the Wi-Fi there is sometimes unstable. Fixed bitrate works well most of the time, but when the connection suddenly degrades, latency can climb very quickly and the stream can become almost unusable.

The new controller reduces the bitrate when packet loss persists, then recovers gradually once the connection looks healthy again. I tried to reuse the existing protocol and signals as much as possible. It uses Moonlight's existing SS_FRAME_FEC_STATUS reports, the frame-loss recovery signals Sunshine already handles, and ENet RTT samples. It does not add a new feedback protocol.

The implementation adds bounded per-session telemetry aggregation, the adaptive controller, and native NVENC runtime bitrate reconfiguration without restarting the encoder. The controller never exceeds the bitrate requested by Moonlight or Sunshine's configured max_bitrate ceiling. If the encoder is unsupported, or if the telemetry is missing or invalid, Sunshine keeps the normal fixed-bitrate behavior.

The PR also adds the Windows Audio/Video setting, documentation, and test coverage. I kept the telemetry, controller, and NVENC reconfiguration together because the individual pieces do not provide much value on their own, but I am fine splitting the work if that would make review easier.

Testing performed:

  • Built on Windows with an RTX 4090, BUILD_WERROR=ON, and the native NVENC SDK 11, 12, and 13 implementations
  • Passed all 62 targeted tests covering telemetry aggregation, the controller, NVENC reconfiguration, stream integration, and fallback behavior
  • Passed 408 tests in the broader deterministic suite, with 5 expected skips
  • Tested runtime reconfiguration with controlled packet loss: the bitrate decreased while the same encoder session remained active, without disconnecting the stream

The hardware encoder probe was excluded from the SSH-only test session because it requires an interactive Windows desktop.

Screenshot

The new setting is shown below in its default, disabled state.

Adaptive Bitrate disabled by default in the Windows Audio/Video settings

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

leandredesmaretz and others added 6 commits July 29, 2026 19:06
Signed-off-by: leandredesmaretz <leandre@eshot.io>
Signed-off-by: leandredesmaretz <leandre@eshot.io>
Signed-off-by: leandredesmaretz <leandre@eshot.io>
Signed-off-by: leandredesmaretz <leandre@eshot.io>
Signed-off-by: leandredesmaretz <leandre@eshot.io>
Signed-off-by: burnrazor <128198300+Dragon-kanji@users.noreply.github.com>
@Dragon-kanji
Dragon-kanji force-pushed the feat/adaptive-bitrate branch from 3c61e0f to 97937f2 Compare July 29, 2026 17:06
Signed-off-by: burnrazor <128198300+Dragon-kanji@users.noreply.github.com>
Signed-off-by: burnrazor <128198300+Dragon-kanji@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@Dragon-kanji
Dragon-kanji marked this pull request as ready for review July 29, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant