Skip to content

feat(render): add optional two-step precise sync - #58

Merged
qiin2333 merged 4 commits into
masterfrom
codex/harmony-two-step-precise-sync
Jul 16, 2026
Merged

feat(render): add optional two-step precise sync#58
qiin2333 merged 4 commits into
masterfrom
codex/harmony-two-step-precise-sync

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 新增“二步精确同步(实验性)”开关,默认关闭,方便真机 A/B 对比
  • 第一步使用 common-c 的真实 host PTS,在帧进入解码管线时生成平滑的呈现目标
  • 第二步在解码输出时将目标对齐到本地 VSync,统一覆盖同步与异步解码路径
  • 新开关内部自动使用 VSync,不要求用户同时开启旧 VSync 选项

为啥要改

网络突发和解码耗时会让连续帧一起到达。只在解码输出时决定呈现时间,已经来不及恢复主机原本的节奏;只按目标时间呈现,又可能落在两个屏幕刷新点之间。

这次把两件事分开做:先把主机帧节奏整理平,再落到真实屏幕刷新点。这样帧不会因为一阵快、一阵慢就忽快忽慢,杂鱼抖动乖乖排队啦。

安全边界

  • 开关关闭时保留原有低延迟、旧 VSync、同步解码行为,避免污染基线
  • 预计算目标有 64 帧上限,丢帧、Flush、重连、Surface 切换时同步清理
  • VSync 周期、目标或定时呈现 API 异常时立即回退直接呈现,避免等待导致画面卡住
  • 系统周期不可用时按配置帧率生成保守周期

验证

  • node hvigorw.js assembleHar --mode module -p module=nativelib@default -p product=default -p buildMode=debug --no-daemon --stacktrace
  • node hvigorw.js assembleApp --mode project -p product=default -p buildMode=debug --no-daemon --stacktrace
  • git diff --check

以上均通过。

Summary by CodeRabbit

  • 新功能
    • 新增“二步精确同步(实验性)”开关,默认关闭,可在“性能与调试”中启用或关闭并自动保存设置。
    • 启用后,串流画面将结合主机节奏与本地 VSync 进行更精准的呈现时序控制。
  • 性能优化
    • 优化解码/呈现时间戳处理与 VSync 对齐,降低抖动、提升画面播放节奏。
    • 当条件不满足或出现失败时会自动回退,保障播放稳定性。

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@qiin2333, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bed18dcb-56ea-4b96-9bef-461dbee5b59b

📥 Commits

Reviewing files that changed from the base of the PR and between 9205af1 and 79e941f.

📒 Files selected for processing (3)
  • nativelib/src/main/cpp/native_render.cpp
  • nativelib/src/main/cpp/native_render.h
  • nativelib/src/main/cpp/video_decoder.cpp
📝 Walkthrough

Walkthrough

Changes

新增二步精确同步实验开关,贯通设置持久化、串流配置、NAPI 与 NativeRender;同时扩展解码器呈现时间输入,并实现基于 VSync 相位的预计算、对齐及回退流程。

二步精确同步配置与入口

Layer / File(s) Summary
配置与串流入口
entry/src/main/ets/model/StreamConfig.ets, entry/src/main/ets/pages/SettingsPageV2.ets, entry/src/main/ets/service/..., entry/src/main/ets/service/streaming/StreamingSession.ets
新增默认关闭的配置字段、设置项和持久化键,并在连接时将开关传递至原生模块。
原生开关接口
nativelib/src/main/cpp/moonlight_bridge.*, nativelib/src/main/cpp/napi_init.cpp
新增二步精确同步开关的 NAPI 接口及模块导出。
VSync 呈现时钟
nativelib/src/main/cpp/native_render.*
新增 VSync 相位缓存、呈现目标预计算、目标队列、相位对齐和 SubmitFrame 回退处理。
解码提交与输出集成
nativelib/src/main/cpp/video_decoder.*, nativelib/src/main/cpp/callbacks.cpp
解码提交接口增加呈现时间戳,使用 RAII 管理预呈现目标,并在丢帧、失败和生命周期切换时清理呈现状态。

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次新增的可选两步精确同步渲染能力。
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/harmony-two-step-precise-sync

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.

@qiin2333
qiin2333 marked this pull request as ready for review July 16, 2026 04:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
nativelib/src/main/cpp/native_render.cpp (1)

503-504: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

enqueueTimeMs 参数已成为死参数。

SubmitFrame 内部直接 (void)enqueueTimeMs;,二步/基线两条路径都不再使用它,仅在调用处(video_decoder.cpp 两处)继续传入。可考虑收拾掉签名,减少无用参数。

🤖 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 `@nativelib/src/main/cpp/native_render.cpp` around lines 503 - 504, Remove the
unused enqueueTimeMs parameter from NativeRender::SubmitFrame and delete its
(void) suppression. Update both SubmitFrame call sites in video_decoder.cpp to
stop passing enqueueTimeMs, while preserving the existing frame-submission
behavior.
🤖 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 `@nativelib/src/main/cpp/moonlight_bridge.cpp`:
- Line 2011: 在 nativelib/src/main/cpp/moonlight_bridge.cpp#L2011-L2011 的
SetTwoStepPreciseSyncEnabled 调用处获取 NativeRender::GetInstance() 的局部指针并判空后再调用;在
nativelib/src/main/cpp/moonlight_bridge.cpp#L2020-L2025 的
IsTwoStepPreciseSyncEnabled 调用处同样引入局部变量并判空,遵循 MoonBridge_SetVsyncEnabled
的安全调用模式。

---

Nitpick comments:
In `@nativelib/src/main/cpp/native_render.cpp`:
- Around line 503-504: Remove the unused enqueueTimeMs parameter from
NativeRender::SubmitFrame and delete its (void) suppression. Update both
SubmitFrame call sites in video_decoder.cpp to stop passing enqueueTimeMs, while
preserving the existing frame-submission behavior.
🪄 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: 786b8422-390f-41a8-a9e3-f6f5661843f9

📥 Commits

Reviewing files that changed from the base of the PR and between a9092a5 and 729853a.

📒 Files selected for processing (12)
  • entry/src/main/ets/model/StreamConfig.ets
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/service/SettingsService.ets
  • entry/src/main/ets/service/streaming/StreamingSession.ets
  • nativelib/src/main/cpp/callbacks.cpp
  • nativelib/src/main/cpp/moonlight_bridge.cpp
  • nativelib/src/main/cpp/moonlight_bridge.h
  • nativelib/src/main/cpp/napi_init.cpp
  • nativelib/src/main/cpp/native_render.cpp
  • nativelib/src/main/cpp/native_render.h
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/main/cpp/video_decoder.h

Comment thread nativelib/src/main/cpp/moonlight_bridge.cpp
@qiin2333
qiin2333 marked this pull request as draft July 16, 2026 05:51
@qiin2333
qiin2333 marked this pull request as ready for review July 16, 2026 07:18
@qiin2333
qiin2333 merged commit e1a6c99 into master Jul 16, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/harmony-two-step-precise-sync branch July 16, 2026 07:40
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