Skip to content

fix(render): restore direct PTS pacing - #72

Merged
qiin2333 merged 2 commits into
masterfrom
codex/restore-direct-pts-pacing
Jul 22, 2026
Merged

fix(render): restore direct PTS pacing#72
qiin2333 merged 2 commits into
masterfrom
codex/restore-direct-pts-pacing

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 恢复 PR fix(render): bound host-paced latency #63 之前的直接 PTS 呈现模型:host PTS 映射到连续本地时间后直接交给 RenderOutputBufferAtTime
  • 保留一帧加 2 ms 的稳定储备;120 FPS 常态目标提前约 10.33 ms,不再动态缩小这层必要余量
  • 恢复严重迟到恢复语义:第一张过期帧丢弃,连续第二张迟到时用更新帧重锚,避免把旧内容的延迟继续传下去
  • 小迟到只累积明确的相位债;解码恢复后只偿还这部分额外延迟,不侵蚀稳定储备
  • 删除提交回调中的 NativeVSync 采样、槽位推演、逐帧诊断统计和周期日志,杂鱼观测逻辑不再堵解码输出热路径
  • RenderOutputBufferAtTime 调用移出呈现状态锁;渲染 FPS 滚动计算移到统计读取路径
  • 保留 30/59.94/60/90/119.88/120 FPS、burst、周期抖动、NTSC、时钟漂移和异常 PTS 覆盖,并新增相位债回收、严重迟到丢旧帧和单次尖峰恢复测试

为啥要改

上一版严重迟到时把旧帧重新排到未来,会让内容年龄继续增加;逐帧 VSync 观测又在最敏感的解码输出回调中加锁、取样和计算。两者都可能让“看起来更精确”的杂鱼状态实际更粘。

这版严格回到已经验证的恢复边界:稳态余量不冒险压缩,只在确认延迟已经产生时动态回收。单次严重尖峰丢一张旧帧;持续迟到才重锚;小相位偏移只偿还自己的债,不再引入自适应队列、VSync 槽位或动态容量状态机。

验证

  • c++ -std=c++17 -Wall -Wextra -Werror -I nativelib/src/main/cpp nativelib/src/main/cpp/presentation_scheduler.cpp nativelib/src/test/cpp/presentation_scheduler_test.cpp -o /tmp/moonlight-presentation-scheduler-test && /tmp/moonlight-presentation-scheduler-test: passed
  • c++ -std=c++17 -Wall -Wextra -Werror -I nativelib/src/main/cpp nativelib/src/main/cpp/rolling_frame_rate.cpp nativelib/src/test/cpp/presentation_observability_test.cpp -o /tmp/moonlight-presentation-observability-test && /tmp/moonlight-presentation-observability-test: passed
  • DEVECO_SDK_HOME=/Users/mac/ohos-sdk-cache/6.1-Release-mac/sdk-ci-shape JAVA_HOME=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home PATH=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home/bin:$PATH node hvigorw.js assembleApp --mode project -p product=default -p buildMode=debug --no-daemon: BUILD SUCCESSFUL
  • git diff --check: passed

Summary by CodeRabbit

  • 改进
    • 基于 PTS 的呈现调度更新:提升节奏稳定性,收敛慢时钟漂移,并对重复/不连续/异常时间戳提供更明确的相位偏移、重缓冲与恢复策略,减少不必要的丢帧。
    • 渲染帧率统计采样时机调整为读取路径,降低同步开销。
  • 变更
    • 移除呈现诊断统计相关功能与输出。
  • 测试
    • 更新并扩展调度与观测用例,覆盖抖动、持续突发、延迟恢复以及异常时间戳场景。

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

PTS 调度器从基于 VSync 槽位和队列的规划方式改为基于 PTS 时间线的直接调度,并新增相位偏移、重缓冲等事件。NativeRender、帧率统计、诊断依赖和相关测试同步更新。

Changes

PTS 调度与呈现集成

Layer / File(s) Summary
调度接口与时序参数
nativelib/src/main/cpp/presentation_scheduler.*
更新事件枚举、PlanFrame 接口和 lead 参数,移除 VSync 槽位、队列管理及重锚重试状态。
PTS 帧规划流程
nativelib/src/main/cpp/presentation_scheduler.cpp
根据 PTS 有效性、锚定状态、相位债务和迟到程度返回调度、相位偏移、丢帧或重缓冲计划。
NativeRender 集成与诊断清理
nativelib/src/main/cpp/native_render.*, nativelib/src/main/cpp/presentation_diagnostics.*, nativelib/src/main/cpp/CMakeLists.txt
Host-paced 路径改用新的规划调用,调整精确统计和 VSync 状态,并移除呈现诊断实现、声明及构建依赖。
帧率统计采样调整
nativelib/src/main/cpp/video_decoder.*
将渲染帧率记录移至 GetStats(),并移除 presented 路径中的专用互斥量更新。
调度行为测试
nativelib/src/test/cpp/presentation_scheduler_test.cpp, nativelib/src/test/cpp/presentation_observability_test.cpp
以 PTS 时间线覆盖突发帧、抖动、再锚定、重复与不连续 PTS、NTSC cadence、时钟漂移及剩余滚动帧率测试。

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 15.63% 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次恢复直接按 PTS 驱动渲染节奏的主要变更。
✨ 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/restore-direct-pts-pacing

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

🤖 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/test/cpp/presentation_scheduler_test.cpp`:
- Around line 144-161: Update TestSevereLateFrameDropsThenReanchorsNextFrame and
the scheduler’s consecutive severe-lateness threshold logic so the first
severely late frame immediately returns REBUFFER and reanchors, rather than
returning LATE_DROP. Adjust the assertions and subsequent-frame expectations to
reflect immediate reanchoring while preserving the required lateness and
target-time 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: 7e51016e-4d63-4f1b-b483-845e23abebad

📥 Commits

Reviewing files that changed from the base of the PR and between 126c646 and e666bef.

📒 Files selected for processing (11)
  • 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_diagnostics.cpp
  • nativelib/src/main/cpp/presentation_diagnostics.h
  • nativelib/src/main/cpp/presentation_scheduler.cpp
  • nativelib/src/main/cpp/presentation_scheduler.h
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/main/cpp/video_decoder.h
  • nativelib/src/test/cpp/presentation_observability_test.cpp
  • nativelib/src/test/cpp/presentation_scheduler_test.cpp
💤 Files with no reviewable changes (5)
  • nativelib/src/main/cpp/presentation_diagnostics.h
  • nativelib/src/main/cpp/presentation_diagnostics.cpp
  • nativelib/src/main/cpp/CMakeLists.txt
  • nativelib/src/test/cpp/presentation_observability_test.cpp
  • nativelib/src/main/cpp/native_render.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • nativelib/src/main/cpp/presentation_scheduler.cpp
  • nativelib/src/main/cpp/presentation_scheduler.h

Comment thread nativelib/src/test/cpp/presentation_scheduler_test.cpp
@qiin2333
qiin2333 merged commit 4b5b7a0 into master Jul 22, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/restore-direct-pts-pacing branch July 22, 2026 14:36
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