Skip to content

fix(vrr): limit input boost to keyboard events#727

Merged
qiin2333 merged 1 commit into
masterfrom
codex/fix-controller-boost-renewal
Jun 13, 2026
Merged

fix(vrr): limit input boost to keyboard events#727
qiin2333 merged 1 commit into
masterfrom
codex/fix-controller-boost-renewal

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

改了啥呀

  • VRR input activity boost 现在只响应键盘相关输入:KEY_DOWN_EVENT_MAGICKEY_UP_EVENT_MAGICUTF8_TEXT_EVENT_MAGIC
  • 鼠标移动/点击、滚轮、touch、pen、controller 都不再触发 boost,避免高频输入流把 stale-frame encode 持续拉起来。
  • activity_tracker 已简化为无状态判断,删除了 controller 追踪状态和 reset API;之前 review 提到的 reset/evaluate 并发访问点因此不再存在。
  • 仍保留 boost event 在 OS 输入派发之后触发,避免编码线程先抢到还没应用输入的旧帧。

为啥要改

#722 的 boost 会在 VRR 无新帧时临时 encode stale frame,用来改善静态画面下输入后的视觉反馈。但手柄实测已经证明,连续输入流触发这个机制会和 RD / 游戏渲染争资源,导致 Android / 鸿蒙客户端出现输入响应变慢、RD 帧率突然下降又恢复。

为了先拿到稳定、低风险的行为,这版只保留键盘事件触发 boost。键盘输入是离散事件,基本不会被高频流持续续命;鼠标/touch/pen/controller 这些可能高频连续的输入先全部排除,杂鱼高频事件不要再拖着编码跑呀。

验证

  • git diff --check -- src/input.cpp src/input_activity.cpp src/input_activity.h
  • cmake --build build --target sunshine --parallel
  • build/cpack_artifacts/_CPack_Packages/win64/ZIP/Sunshine/sunshine.exe --help
  • cpack -G ZIP --config .\CPackConfig.cmake --verbose,生成 build/cpack_artifacts/Sunshine.zip

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b2875c2-838d-4d44-b23d-6712311a4b77

📥 Commits

Reviewing files that changed from the base of the PR and between 1d432ba and d67fae8.

📒 Files selected for processing (3)
  • src/input.cpp
  • src/input_activity.cpp
  • src/input_activity.h
💤 Files with no reviewable changes (2)
  • src/input_activity.h
  • src/input_activity.cpp
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.{cpp,c,h}

⚙️ CodeRabbit configuration file

src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

Files:

  • src/input.cpp
🔇 Additional comments (3)
src/input.cpp (3)

1585-1588: LGTM!


1636-1639: LGTM!


1656-1679: 核对 input::reset() 的 PR 描述与实现是否一致

  • src/input.cpp(1656-1679)中的 reset() 仅取消重复按键/超时任务,并通过 task_pool.push 在 lambda 内处理 mouse_press/key_press 的平台释放逻辑,未包含 activity_tracker.reset() 或任何 tracker 重置调用。
  • 仓库中在(仅 .cpp 范围)未找到 activity_tracker\.resettracker_t 形态的 reset 也未命中,但仍需进一步确认 tracker 是否在其它文件类型/不同命名下实现,以及 task_pool.push 是否提供“等待完成”的同步机制。
    若 PR 目标确有“同一 task_pool 上调度并等待”,则需要补实现(或同步语义)/同步更新 PR 描述以匹配当前代码行为。

Summary by CodeRabbit

发行说明

  • 改进
    • 在批处理并实际分发输入后再上报输入活动,降低误报率。
    • 活动检测现仅对键盘/文本类输入生效,特定控制器路径不再触发活动检测,提升稳定性。
    • 重置流程改为异步排队执行并由调用方等待,改善并发一致性并避免直接重置追踪器。

Walkthrough

收缩 activity tracker 为仅处理键盘事件;将 input_activity_event 的触发从入队时移至 passthrough_next_message 批处理并分发后;头文件移除 reset 与控制器状态相关声明,入队处即时 evaluate/raise 被移除。

输入活动检测与信号时机重构

Layer / File(s) Summary
活动检测声明缩减与头文件调整
src/input_activity.h
删除 tracker_t::reset()、控制器相关私有类型与成员,仅保留 bool evaluate(_NV_INPUT_HEADER *payload); 的声明。
活动检测实现简化(仅键盘)
src/input_activity.cpp
tracker_t::evaluate 的 magic 分派收缩到仅处理键盘事件(KEY_DOWN/KEY_UP/UTF8_TEXT),对应路径返回 config::input.keyboard,其余 magic 返回 false;删除不再需要的头文件包含。
事件触发时机迁移与入队逻辑删减
src/input.cpp
passthrough_next_message 中新增 should_raise_input_activity(基于 config::video.input_activity_boostactivity_tracker.evaluate(payload)),在完成 switch 分发后按条件调用 input->input_activity_event->raise(...);移除 passthrough(... ) 入队处的即时 activity_tracker.evaluate/raise 调用。

Sequence Diagram(s)

sequenceDiagram
  participant EnqueueThread as 入队线程
  participant WorkerThread as 工作线程
  participant ActivityEvent as input_activity_event
  participant PlatformSwitch as 平台分发

  EnqueueThread->>WorkerThread: enqueue payload (passthrough)
  WorkerThread->>WorkerThread: 批处理并计算最终 payload
  WorkerThread->>WorkerThread: activity_tracker.evaluate(payload)(受 config::video.input_activity_boost 控制)
  WorkerThread->>ActivityEvent: raise(steady_clock::now()) 若 should_raise_input_activity 为真
  WorkerThread->>PlatformSwitch: 分发 / switch 调用完成
Loading

🎯 代码审查工作量评估

🎯 3 (中等) | ⏱️ ~20 分钟

可能相关的 PR

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'fix(vrr): limit input boost to keyboard events' accurately reflects the main change: restricting the VRR input activity boost to only keyboard-related events.
Description check ✅ Passed The pull request description comprehensively explains what was changed (limiting boost to keyboard events), why it was necessary (controller input caused resource contention), and provides validation steps.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-controller-boost-renewal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@qiin2333 qiin2333 marked this pull request as ready for review June 12, 2026 14:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/input.cpp (1)

1585-1639: ⚠️ Potential issue | 🟠 Major

修正:活动时机逻辑正确,但 activity_tracker 需要同步以避免数据竞争

  • should_raise_input_activity 在批处理后的最终 payload 上评估,OS 分发完成后再触发 input_activity_event->raise(),时序符合 PR 目标。
  • 线程安全问题:activity_tracker.evaluate()(src/input.cpp 1587)在 task_pool worker 中执行,而 activity_tracker.reset()(src/input.cpp 1661)在 stream::session::join() 调用 input::reset() 的线程直接执行;tracker_t(src/input_activity.h/.cpp)仅通过 controllers_ 成员读写且未加锁/原子,因此若 passthrough_next_message()reset() 重叠会产生未同步的并发访问(UB)。
  • 建议:将 activity_tracker.reset() 也通过 task_pool 串行化执行并等待完成;或在 tracker_t 内部加入互斥/原子保护,并确保会话停用时不会再有未完成的 passthrough_next_message() 任务与 reset 并发运行。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/input.cpp` around lines 1585 - 1639, The activity_tracker is accessed
concurrently (activity_tracker.evaluate() in passthrough_next_message/task_pool
and activity_tracker.reset() called directly in
input::reset()/stream::session::join()), causing data races on
tracker_t/controllers_; fix by serializing reset on the same task_pool: change
input::reset() (called from stream::session::join()) to post a
synchronous/waiting task to the same task_pool that runs
activity_tracker.reset(), or otherwise dispatch a task that performs
activity_tracker.reset() and wait for its completion before returning;
alternatively, protect tracker_t internal state with a mutex/atomics, but prefer
posting reset to the task_pool to ensure no
passthrough_next_message()/activity_tracker.evaluate() tasks run concurrently
with reset (reference symbols: activity_tracker.evaluate,
activity_tracker.reset, passthrough_next_message, input::reset,
stream::session::join, tracker_t).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/input.cpp`:
- Around line 1585-1639: The activity_tracker is accessed concurrently
(activity_tracker.evaluate() in passthrough_next_message/task_pool and
activity_tracker.reset() called directly in
input::reset()/stream::session::join()), causing data races on
tracker_t/controllers_; fix by serializing reset on the same task_pool: change
input::reset() (called from stream::session::join()) to post a
synchronous/waiting task to the same task_pool that runs
activity_tracker.reset(), or otherwise dispatch a task that performs
activity_tracker.reset() and wait for its completion before returning;
alternatively, protect tracker_t internal state with a mutex/atomics, but prefer
posting reset to the task_pool to ensure no
passthrough_next_message()/activity_tracker.evaluate() tasks run concurrently
with reset (reference symbols: activity_tracker.evaluate,
activity_tracker.reset, passthrough_next_message, input::reset,
stream::session::join, tracker_t).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98c71e97-e893-4461-9d71-5b56bb372666

📥 Commits

Reviewing files that changed from the base of the PR and between 9499469 and 1301ba3.

📒 Files selected for processing (2)
  • src/input.cpp
  • src/input_activity.cpp
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.{cpp,c,h}

⚙️ CodeRabbit configuration file

src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

Files:

  • src/input_activity.cpp
  • src/input.cpp
🔇 Additional comments (3)
src/input_activity.cpp (2)

20-44: LGTM!


78-87: LGTM!

src/input.cpp (1)

1647-1654: LGTM!

@qiin2333 qiin2333 force-pushed the codex/fix-controller-boost-renewal branch 2 times, most recently from 9a76a01 to 1d432ba Compare June 12, 2026 15:34
@qiin2333 qiin2333 changed the title fix(vrr): avoid controller analog boost renewal fix(vrr): avoid controller input boost stalls Jun 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/input_activity.cpp (1)

129-130: ⚡ Quick win

建议添加注释说明禁用控制器活动检测的原因。

SS_CONTROLLER_TOUCH_MAGIC(第 119-122 行)有详细注释解释为何返回 false,而 MULTI_CONTROLLER_MAGIC_GEN5 缺少类似说明。鉴于此更改完全禁用了控制器输入对 boost 窗口的影响,建议添加注释以便后续维护者理解设计意图。

♻️ 建议的修改
       case MULTI_CONTROLLER_MAGIC_GEN5:
+        // Controller input is disabled from activity boost to avoid the boost window
+        // being continuously renewed by analog stick/trigger jitter, which competes
+        // with game rendering and causes input lag. See PR `#727`.
         return false;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/input_activity.cpp` around lines 129 - 130, 在 input_activity.cpp 的 switch
分支中针对 case MULTI_CONTROLLER_MAGIC_GEN5 添加一段简短注释,说明为什么要返回 false 并禁用该控制器对 boost
窗口的输入影响;注释风格应与现有的 SS_CONTROLLER_TOUCH_MAGIC(第 119-122
行)的注释一致,包含设计意图和任何相关硬件/兼容性或行为理由,以便后续维护者理解此决策;确保注释放在 return false 之前并清晰指明
MULTI_CONTROLLER_MAGIC_GEN5 的特殊处理。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/input_activity.cpp`:
- Around line 78-87: tracker_t::evaluate_controller is dead code because
tracker_t::evaluate() immediately returns false in the
MULTI_CONTROLLER_MAGIC_GEN5 branch; either call evaluate_controller from that
branch and return its result so multi-controller trigger logic runs (look for
tracker_t::evaluate() and invoke
evaluate_controller(_NV_MULTI_CONTROLLER_PACKET*) where the branch currently
returns), or remove the unused evaluate_controller function (or add a clear
comment explaining why it is intentionally kept) so the codebase has no
unreachable functions.

---

Nitpick comments:
In `@src/input_activity.cpp`:
- Around line 129-130: 在 input_activity.cpp 的 switch 分支中针对 case
MULTI_CONTROLLER_MAGIC_GEN5 添加一段简短注释,说明为什么要返回 false 并禁用该控制器对 boost
窗口的输入影响;注释风格应与现有的 SS_CONTROLLER_TOUCH_MAGIC(第 119-122
行)的注释一致,包含设计意图和任何相关硬件/兼容性或行为理由,以便后续维护者理解此决策;确保注释放在 return false 之前并清晰指明
MULTI_CONTROLLER_MAGIC_GEN5 的特殊处理。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b6a2b3a7-c313-4899-889b-209bdf3c1126

📥 Commits

Reviewing files that changed from the base of the PR and between 9a76a01 and 1d432ba.

📒 Files selected for processing (2)
  • src/input.cpp
  • src/input_activity.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/input.cpp
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.{cpp,c,h}

⚙️ CodeRabbit configuration file

src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

Files:

  • src/input_activity.cpp
🔇 Additional comments (3)
src/input_activity.cpp (3)

25-46: LGTM!


119-122: LGTM!


136-141: LGTM!

Comment thread src/input_activity.cpp Outdated
@qiin2333 qiin2333 force-pushed the codex/fix-controller-boost-renewal branch from 1d432ba to d67fae8 Compare June 12, 2026 16:37
@qiin2333 qiin2333 changed the title fix(vrr): avoid controller input boost stalls fix(vrr): limit input boost to keyboard events Jun 12, 2026
@qiin2333 qiin2333 merged commit 2f3442e into master Jun 13, 2026
4 checks passed
@qiin2333 qiin2333 deleted the codex/fix-controller-boost-renewal branch June 13, 2026 04:45
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