Skip to content

feat(render): add true two-step PTS pacing experiment - #73

Merged
qiin2333 merged 4 commits into
masterfrom
codex/true-two-step-pts-ab
Jul 24, 2026
Merged

feat(render): add true two-step PTS pacing experiment#73
qiin2333 merged 4 commits into
masterfrom
codex/true-two-step-pts-ab

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 在帧进入解码器前按 host PTS 准备呈现目标,解码输出后再按 PTS 精确取回,不依赖 FIFO 或 buffer index
  • 使用固定 64 项目标表;缺失、过期或过远目标立即呈现,避免杂鱼目标继续堆 Surface 延迟
  • 同步解码恢复有界 drain-to-latest,突发输出只把最新帧交给二步调度器
  • 保持异步 L2/L4/L5 策略与 fix(render): restore direct PTS pacing #72 基线一致,不把额外丢帧策略混进这次 A/B
  • 补齐 NTSC、PTS 跳变、重复/缺失目标、容量边界和 120 Hz 对比测试

为啥要改

#72 的后置 PTS 版本已经得到不错的用户反馈,所以它继续作为稳定基线。这次只验证真正二步是否能让解码耗时消耗已有呈现余量,并在同步解码突发时避免把一串旧帧排入 Surface,而不是再叠动态余量、额外一帧缓存或新的恢复状态机。

合成 120 Hz 场景中,平均解码后等待从约 8333 us 降到 6333 us。主要设备风险仍是同步 drain-to-latest 会主动丢弃已经过时的解码输出,需要实机 A/B 判断 120 Hz 流畅度和操作延迟是否真正改善。

验证

  • presentation_scheduler_test:通过
  • presentation_observability_test:通过
  • two_step_presentation_scheduler_test(ASan/UBSan):通过
  • node hvigorw.js assembleApp --mode project -p product=default -p buildMode=debug --no-daemon:通过
  • git diff --check origin/master...HEAD:通过

Summary by CodeRabbit

  • 新功能

    • 引入两阶段画面呈现调度,优化主机节奏模式下的帧准备、呈现与丢弃。
    • 改善解码帧与目标呈现时间的匹配,支持对过期、缺失、过远及非连续帧进行处理。
    • 增强视频输出结束及丢帧场景下的呈现状态管理。
  • 测试

    • 新增多种帧率、时间间隔、重复帧和异常时序场景的调度验证。

@coderabbitai

coderabbitai Bot commented Jul 23, 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: 20 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 Plus

Run ID: d9d654ff-1e60-4338-9d69-bba099631527

📥 Commits

Reviewing files that changed from the base of the PR and between 6f3eb54 and f8f5537.

📒 Files selected for processing (13)
  • entry/src/main/ets/components/StreamSessionReport.ets
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/pages/StreamPage.ets
  • entry/src/main/ets/service/SettingsService.ets
  • entry/src/main/ets/service/streaming/StreamingSession.ets
  • nativelib/src/main/cpp/moonlight_bridge.cpp
  • nativelib/src/main/cpp/native_render.cpp
  • nativelib/src/main/cpp/native_render.h
  • nativelib/src/main/cpp/two_step_presentation_scheduler.cpp
  • nativelib/src/main/cpp/two_step_presentation_scheduler.h
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/main/cpp/video_decoder.h
  • nativelib/src/test/cpp/two_step_presentation_scheduler_test.cpp
📝 Walkthrough

Walkthrough

新增 TwoStepPresentationScheduler,将 host-paced 呈现流程改为解码前准备目标、解码后生成计划,并在解码器提交成功、回退、EOS 与丢帧路径中同步维护目标状态。

Changes

两阶段呈现调度

Layer / File(s) Summary
调度器契约与核心规划
nativelib/src/main/cpp/two_step_presentation_scheduler.*, nativelib/src/main/cpp/presentation_scheduler.h
新增两阶段规划接口、目标缓存及针对过期、未来目标、缺失目标和非单调 PTS 的处理逻辑。
调度行为验证
nativelib/src/test/cpp/two_step_presentation_scheduler_test.cpp
新增测试覆盖解码耗时、不同帧率、目标容量、时间不连续及重复输出等行为。
NativeRender 两阶段接入
nativelib/src/main/cpp/native_render.*, nativelib/src/main/cpp/CMakeLists.txt
NativeRender 改用两阶段调度器,并新增呈现目标准备、丢弃及解码后规划流程;新实现加入构建目标。
解码器目标生命周期管理
nativelib/src/main/cpp/video_decoder.cpp
通过 RAII guard 管理目标提交与回退,并在同步/异步提交、EOS 和 drain-to-latest 丢帧路径中清理目标。

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次渲染相关的核心变更:引入真正的两步式 PTS pacing 实验。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/true-two-step-pts-ab

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.

@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/test/cpp/two_step_presentation_scheduler_test.cpp (1)

4-7: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

建议显式包含 <iterator>

代码中多处使用 std::size(...)(如106、140行),但未包含声明该符号的 <iterator> 头文件,当前依赖其它头文件的传递包含。虽然当前构建可通过,但并非标准保证的可移植写法。

♻️ 建议修改
 `#include` <cassert>
 `#include` <cmath>
 `#include` <cstdint>
+#include <iterator>
 `#include` <iostream>
🤖 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/test/cpp/two_step_presentation_scheduler_test.cpp` around lines
4 - 7, 在 two_step_presentation_scheduler_test.cpp 的头文件区域显式添加 <iterator>,确保使用
std::size 的测试代码具备直接且可移植的声明来源;不要依赖其他头文件的传递包含。
🤖 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/video_decoder.cpp`:
- Around line 1062-1073: Update PresentationTargetGuard and the
presentation-target APIs so PreparePresentationFrame returns an opaque
generation/target handle, which the guard stores when preparation succeeds.
Change cleanup to discard by that handle rather than only pts_, and ensure
DiscardPresentationFrame ignores stale handles after reset, disable/re-enable,
or replacement. Preserve committed guards’ behavior and prevent an older guard
from removing a newer target with the same PTS.

---

Nitpick comments:
In `@nativelib/src/test/cpp/two_step_presentation_scheduler_test.cpp`:
- Around line 4-7: 在 two_step_presentation_scheduler_test.cpp 的头文件区域显式添加
<iterator>,确保使用 std::size 的测试代码具备直接且可移植的声明来源;不要依赖其他头文件的传递包含。
🪄 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 Plus

Run ID: 8aca4ade-63b8-4724-aef1-2a3c5de9da85

📥 Commits

Reviewing files that changed from the base of the PR and between 4b5b7a0 and 6f3eb54.

📒 Files selected for processing (8)
  • nativelib/src/main/cpp/CMakeLists.txt
  • nativelib/src/main/cpp/native_render.cpp
  • nativelib/src/main/cpp/native_render.h
  • nativelib/src/main/cpp/presentation_scheduler.h
  • nativelib/src/main/cpp/two_step_presentation_scheduler.cpp
  • nativelib/src/main/cpp/two_step_presentation_scheduler.h
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/test/cpp/two_step_presentation_scheduler_test.cpp

Comment thread nativelib/src/main/cpp/video_decoder.cpp Outdated
@qiin2333
qiin2333 merged commit 291164e into master Jul 24, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/true-two-step-pts-ab branch July 24, 2026 07:04
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