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

    • Added a public API to retrieve target/display dimensions.
  • Bug Fixes

    • Improved frame timing accuracy by correcting elapsed-time calculation, reducing capture/playback drift and jitter.

Copy link

coderabbitai bot commented Aug 31, 2025

Walkthrough

Replaced frame.timespan().Duration with frame.timestamp().Duration in on_frame_arrived (Windows capturer). Added a public re-export of get_target_dimensions in src/lib.rs. No other control flow, logic, or public signatures were modified.

Changes

Cohort / File(s) Summary
Windows capturer timing
src/capturer/engine/win/mod.rs
In on_frame_arrived, compute elapsed/display time using 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 existing get_all_targets and get_main_display; no implementation changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my nose at ticking frames,
I swapped a stamp and called new names.
Exports now hop into the light—
Tiny changes, tidy flight.
🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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)

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