Skip to content

Conversation

@rohitsangwan01
Copy link

@rohitsangwan01 rohitsangwan01 commented Aug 31, 2025

Am not able to compile scap on windows, because of this typo

Summary by CodeRabbit

  • New Features

    • Public API now exposes target/display dimensions.
    • Frame payloads unified under a single video frame representation for consistent handling.
  • Bug Fixes

    • Improved frame timing accuracy and reduced capture/playback drift by correcting elapsed-time calculation and standardizing display-time sourcing across platforms.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Aug 31, 2025

Walkthrough

Swapped timestamp source for elapsed/display time in Windows capturer; added a public re-export get_target_dimensions; refactored frame emissions to wrap payloads in a new VideoFrame type and emit Frame::Video(...) with SystemTime::now() in the Linux capturer.

Changes

Cohort / File(s) Summary
Windows capturer timing
src/capturer/engine/win/mod.rs
In on_frame_arrived, elapsed/display time calculation now uses frame.timestamp().Duration instead of frame.timespan().Duration; surrounding logic unchanged.
Public API re-exports
src/lib.rs
Re-exported get_target_dimensions from the targets module alongside get_all_targets and get_main_display; no implementation changes.
Linux capturer framing & time source
src/capturer/engine/linux/mod.rs, crate::frame (added type)
Introduced a new public VideoFrame type and changed Frame emissions to Frame::Video(VideoFrame::<...>); frame payload variants (RGBx/RGB/XBGR/BGRx) are wrapped in VideoFrame. Replaced timestamp-based display_time with SystemTime::now() for video frames; imports adjusted accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Potential review focus:

  • src/capturer/engine/linux/mod.rs — correctness of VideoFrame construction and all match arms producing Frame::Video.
  • crate::frame — public VideoFrame type signature and its compatibility with existing consumers.
  • src/capturer/engine/win/mod.rs — confirm change from timespan() to timestamp() yields intended units/semantics.
  • src/lib.rs — ensure re-export matches module visibility and documentation.

Poem

I twitch my whiskers, hop with glee,
Timestamps swapped and frames set free.
A new VideoFrame curls in my paw,
Exports parade without a flaw.
🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title addresses a Windows compilation fix related to a timestamp typo, which aligns with the primary change in src/capturer/engine/win/mod.rs where frame.timespan() was corrected to frame.timestamp().
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

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

⚠️ Outside diff range comments (1)
src/capturer/engine/win/mod.rs (1)

79-86: Fix time-unit mismatch (100ns TimeSpan vs QPC counts) in elapsed/display_time.

frame.timestamp().Duration is in 100ns ticks, while self.start_time.0 is raw QPC counts. Subtracting them directly and then dividing by perf_freq mixes units and can skew timestamps (and A/V sync). Convert both to seconds (or both to 100ns) before differencing.

Apply this minimal, localized diff:

-        let elapsed = frame.timestamp().Duration - self.start_time.0;
-        let display_time = self
-            .start_time
-            .1
-            .checked_add(Duration::from_secs_f64(
-                elapsed as f64 / self.perf_freq as f64,
-            ))
-            .unwrap();
+        // Convert both timelines to seconds before differencing:
+        let frame_secs = frame.timestamp().Duration as f64 / 10_000_000.0;
+        let start_secs = self.start_time.0 as f64 / self.perf_freq as f64;
+        let elapsed_secs = (frame_secs - start_secs).max(0.0);
+        let display_time = self
+            .start_time
+            .1
+            .checked_add(Duration::from_secs_f64(elapsed_secs))
+            .unwrap();

Reference: Direct3D11CaptureFrame.SystemRelativeTime reports QPC time represented as a TimeSpan (100ns units). (github.com)

🧹 Nitpick comments (1)
src/capturer/engine/win/mod.rs (1)

79-86: Optional: simplify by anchoring to the first frame’s timestamp (avoid QPC entirely).

Store the first frame’s timestamp().Duration and compute deltas purely in 100ns, then add to start_time.1. This removes QPC math and frequency assumptions.

Example (outside the shown hunk):

// in Capturer:
start_ts_100ns: Option<i64>,

// in on_frame_arrived:
let base = *self.start_ts_100ns.get_or_insert(frame.timestamp().Duration);
let elapsed_100ns = (frame.timestamp().Duration - base).max(0);
let display_time = self.start_time.1.checked_add(
    Duration::from_secs_f64(elapsed_100ns as f64 / 10_000_000.0)
).unwrap();
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c03f15a and 3a0d159.

📒 Files selected for processing (1)
  • src/capturer/engine/win/mod.rs (1 hunks)
🔇 Additional comments (2)
src/capturer/engine/win/mod.rs (2)

79-79: Good catch: switch to timestamp() matches the current windows-capture API.

The crate exposes Frame::timestamp() -> TimeSpan in recent versions; older versions had timespan(). This change unblocks Windows builds against newer windows-capture. (docs.rs)


79-79: API rename sanity check passed No .timespan() calls remain—only .timestamp() is in use.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/lib.rs (1)

9-9: Gate or document the new re-export to avoid unconditional panic on Linux.

Re-exporting get_target_dimensions makes it part of the public API. On Linux, the current implementation in targets::mod is unreachable!(), so exposing it at the crate root can lead to guaranteed panics at runtime on that platform. Consider gating the re-export to macOS/Windows (or documenting the Linux limitation clearly). Also, adding doc(cfg) helps docs reflect platform availability.

Proposed diff:

-// Helper Methods
-pub use targets::{get_all_targets, get_main_display, get_target_dimensions};
+// Helper Methods
+pub use targets::{get_all_targets, get_main_display};
+#[cfg(any(target_os = "macos", target_os = "windows"))]
+#[cfg_attr(docsrs, doc(cfg(any(target_os = "macos", target_os = "windows"))))]
+pub use targets::get_target_dimensions;

Follow-ups:

  • If you intend to keep it cross-platform in the root API, consider returning a Result on Linux instead of unreachable!().
  • Adding a new public item is a semver-minor change; ensure the next release version reflects this.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3a0d159 and 834eca4.

📒 Files selected for processing (1)
  • src/lib.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lib.rs (3)
src/targets/mac/mod.rs (1)
  • get_target_dimensions (103-117)
src/targets/mod.rs (1)
  • get_target_dimensions (77-86)
src/targets/win/mod.rs (1)
  • get_target_dimensions (83-105)

@jinzhongjia
Copy link

can someone merge this ?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/capturer/engine/linux/mod.rs (1)

8-8: Timestamp semantics changed to SystemTime::now(); consider cleaning up unused PTS and double‑check cross‑platform expectations

Using SystemTime::now() for display_time and wrapping payloads as Frame::Video(VideoFrame::RGBx/RGB/XBGR/BGRx) looks consistent with the new VideoFrame API and compiles cleanly for Linux.

Two follow‑ups seem worthwhile:

  • Unused PipeWire PTS: get_timestamp(buffer) is still called (assigned to timestamp) but no longer used when constructing VideoFrame. This means we pay the cost of the unsafe meta walk every frame without benefit. If you don’t plan to use the PipeWire PTS any more, consider either:
    • Removing the call entirely, e.g.:

  •        let timestamp = unsafe { get_timestamp(buffer) };
    
  •        let system_time = SystemTime::now();
    
  •        let system_time = SystemTime::now();
    
    - And, if not used anywhere else, deleting `get_timestamp` as well.
    
    Or, if you want to keep it around for future work, at least acknowledge it as intentionally unused to avoid lint noise:
    
    ```diff
    
  •        let timestamp = unsafe { get_timestamp(buffer) };
    
  •        let _timestamp = unsafe { get_timestamp(buffer) };
    
    
    
  • Meaning of display_time: Previously this likely represented the stream/capture timestamp derived from PipeWire’s PTS; now it’s wall‑clock SystemTime. If any downstream code assumes display_time is tied to the capture clock (e.g., for sync with audio or to align Linux/Windows behavior), it may be worth:
    • Confirming Windows and Linux backends now use the same notion of time, and
    • Adding a brief comment on VideoFrame::display_time documenting that it is wall‑clock time at delivery, not the underlying PipeWire PTS.

These are non‑blocking but will reduce confusion around the Windows timestamp fix and keep the Linux side tidy.

Also applies to: 34-35, 122-161

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 834eca4 and 2b00ea1.

📒 Files selected for processing (1)
  • src/capturer/engine/linux/mod.rs (4 hunks)

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.

2 participants