fix(vdd): share producer probe for direct capture#736
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Summary by CodeRabbit
Walkthrough将 ChangesVDD 生产者探测逻辑集中化
Sequence Diagram(s)sequenceDiagram
participant display_vdd as display_vdd.cpp<br>resolve_vdd_monitor_index
participant wait_fn as wait_for_vdd_producer
participant probe_fn as probe_vdd_producer
participant shm as 共享内存<br>Global\ZakoVDD_Meta_i
rect rgba(70, 130, 180, 0.5)
display_vdd->>wait_fn: target_w, target_h, retry_window=2500ms, retry_delay=100ms
loop 重试直到 exact_match() 或超时
wait_fn->>probe_fn: target_w, target_h, max_probe=16
loop i = 0..max_probe-1
probe_fn->>shm: OpenFileMapping + MapViewOfFile
shm-->>probe_fn: SharedFrameMetadata {Magic, W, H, Format, HDR}
probe_fn->>probe_fn: 校验 VDD_META_MAGIC,更新有效计数与精确匹配索引
end
probe_fn-->>wait_fn: vdd_producer_probe_t (status, exact_index, valid_count)
wait_fn->>wait_fn: 若未精确匹配则 sleep(retry_delay)
end
wait_fn-->>display_vdd: vdd_producer_probe_t (last_result)
end
display_vdd->>display_vdd: last_result.exact_match() → 返回 exact_index
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/display_device/vdd_utils.cpp`:
- Around line 116-127: The validity check for the SharedFrameMetadata currently
only verifies the Magic field against VDD_META_MAGIC, which can lead to false
positives when the producer Version is incompatible. The probe phase should also
validate that meta->Version is compatible. Update the valid boolean variable
assignment to include an additional check for meta->Version along with the
existing Magic verification, ensuring that subsequent vdd_capture_t::init calls
will not fail due to version incompatibility and preventing inconsistency
between the probe result and actual usability.
- Around line 76-89: The SharedFrameMetadata struct is used for cross-process
shared memory and currently relies only on comments for binary compatibility.
Add compile-time assertions after the struct definition to enforce hard
constraints: use static_assert with std::is_standard_layout_v to verify the
struct has standard layout, assert the sizeof(SharedFrameMetadata) matches the
expected size to catch unexpected padding or alignment issues, and add offsetof
assertions for key fields (Magic, Width, Height, DxgiFormat, FrameCounter) to
ensure their memory positions remain stable across compiler versions and
platforms.
🪄 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: d989de6b-8e40-4520-9e6a-bf1c42845d9e
📒 Files selected for processing (3)
src/display_device/vdd_utils.cppsrc/display_device/vdd_utils.hsrc/platform/windows/display_vdd.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 (2)
src/**/*.{cpp,c,h}
⚙️ CodeRabbit configuration file
src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。
Files:
src/platform/windows/display_vdd.cppsrc/display_device/vdd_utils.hsrc/display_device/vdd_utils.cpp
src/platform/**
⚙️ CodeRabbit configuration file
src/platform/**: 平台抽象层代码(Windows/Linux/macOS)。确保各平台实现一致, 注意 Windows API 调用的错误处理和资源释放。
Files:
src/platform/windows/display_vdd.cpp
🔇 Additional comments (2)
src/display_device/vdd_utils.h (1)
60-83: LGTM!Also applies to: 137-150
src/platform/windows/display_vdd.cpp (1)
18-18: LGTM!Also applies to: 279-288, 321-322
There was a problem hiding this comment.
Pull request overview
This PR centralizes ZakoVDD shared-frame producer metadata probing into vdd_utils so both the display-device session layer and the VDD direct-capture backend can use the same logic to classify producers as exact / stale / missing / no-match, improving consistency and diagnosability when producer metadata lags behind the requested mode.
Changes:
- Moved VDD
Meta_*probing and retry/wait logic intodisplay_device::vdd_utils(probe_vdd_producer/wait_for_vdd_producer). - Updated the Windows VDD direct-capture backend to reuse the shared probe logic while still enforcing exact size matches (and refusing stale sole producers).
- Added ABI/layout assertions for the probed metadata struct to catch incompatible producer-side changes early.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/platform/windows/display_vdd.cpp | Replaces local VDD producer probing with vdd_utils::wait_for_vdd_producer while keeping exact-match enforcement. |
| src/display_device/vdd_utils.h | Adds public probe result types and declares probe/wait helpers for ZakoVDD metadata. |
| src/display_device/vdd_utils.cpp | Implements shared probing/waiting logic and adds struct layout checks for producer compatibility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Must stay binary-compatible with the producer-side struct in ZakoVDD. | ||
| struct SharedFrameMetadata { | ||
| UINT32 Magic; | ||
| UINT32 Version; | ||
| UINT32 Width; | ||
| UINT32 Height; | ||
| UINT32 DxgiFormat; | ||
| UINT32 IsHdr; | ||
| float MaxNits; | ||
| float MinNits; | ||
| float MaxFALL; | ||
| UINT64 FrameCounter; | ||
| UINT64 LastPresentQpc; | ||
| }; | ||
|
|
||
| static constexpr UINT32 VDD_META_MAGIC = 0x5A564446; // 'ZVDF' | ||
| static constexpr UINT32 VDD_META_VERSION = 1; | ||
|
|
改了啥呢
Meta_*探测结果抽到vdd_utils,让 capture backend 复用同一套exact / stale / missing / no match判断。display_vdd继续只接受尺寸精确匹配的 producer,保留 stale producer 的拒绝保护。为啥要改
用户日志里 VDD 已经切到
2584x1828,但 producer metadata 还停在3840x2160,于是 capture 初始化拒绝 stale producer 并结束会话。这个 PR 先把判断逻辑收口,避免后续 session/capture 各写一份探测规则,也让这个状态更容易诊断和扩展。验证
git diff --checksrc/display_device/vdd_utils.cpp和src/platform/windows/display_vdd.cpp用 CMake/Ninja 同等宏与 flags 做-fsyntax-only验证