fix(mac): align native audio startup timestamps - #343
Conversation
|
Warning Review limit reached
Next review available in: 14 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe audio mixer now aligns each source’s bounded startup delay to the writer session start. It waits for enabled sources before draining, supports stall fallback, and writes through readiness and append callbacks. XCTest coverage validates alignment and mixing behavior. ChangesAudio start alignment
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AudioSource
participant AudioTrackMixer
participant WriterInput
AudioSource->>AudioTrackMixer: provide audio buffer
AudioTrackMixer->>AudioTrackMixer: align timestamp to session start
AudioTrackMixer->>AudioTrackMixer: wait for enabled sources or stall tolerance
AudioTrackMixer->>WriterInput: check readiness
AudioTrackMixer->>WriterInput: append mixed output
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 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 |
|
@coderabbitai review |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift (1)
7-76: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the lower and inclusive warm-up boundaries.
The tests cover 160 ms and 500 ms startup delays. They do not cover a zero offset, a negative offset, or the inclusive 250 ms limit. Add cases that compensate zero and exactly 250 ms, and preserve a negative offset.
🤖 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 `@electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift` around lines 7 - 76, Add boundary-focused tests alongside the existing AudioStartAlignment tests: verify zero offset and exactly 250 ms after sessionStart are aligned to sessionStart, while a negative offset remains unchanged. Use AudioStartAlignment.align and retain the existing assertions for subsequent deltas and out-of-window behavior.
🤖 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
`@electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/AudioTrackMixer.swift`:
- Around line 156-169: Update the mixer’s drain readiness flow so emission and
cursor advancement remain blocked until every enabled source has supplied and
aligned its first buffer. Add a bounded fallback for an enabled source that
never delivers, then preserve the existing drain behavior once readiness is
satisfied; ensure SourceTimeline.dropFrames does not discard a late source’s
frame-zero samples. Add a mixer-level regression test covering system audio
arriving before microphone audio and verifying the microphone’s initial samples
remain at frame zero.
---
Nitpick comments:
In
`@electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift`:
- Around line 7-76: Add boundary-focused tests alongside the existing
AudioStartAlignment tests: verify zero offset and exactly 250 ms after
sessionStart are aligned to sessionStart, while a negative offset remains
unchanged. Use AudioStartAlignment.align and retain the existing assertions for
subsequent deltas and out-of-window behavior.
🪄 Autofix
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 52c54a76-ec0a-4516-90ef-a1993fb44543
📒 Files selected for processing (3)
electron/native/screencapturekit/Package.swiftelectron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/AudioTrackMixer.swiftelectron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift
|
|
@coderabbitai review |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift (1)
6-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd negative-offset and exact-limit alignment tests.
Add coverage for a source timestamp before
sessionStart. Add coverage for a first timestamp exactly 250 ms aftersessionStart. These cases protect the lower bound and inclusive upper bound inAudioStartAlignment.align.🤖 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 `@electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift` around lines 6 - 54, Extend AudioStartAlignmentTests with cases where the first source timestamp precedes sessionStart and where it is exactly 250 ms after sessionStart. Assert AudioStartAlignment.align handles the negative offset and accepts the inclusive 250 ms upper limit, matching the expected alignment behavior.
🤖 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
`@electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/AudioTrackMixer.swift`:
- Around line 123-127: The microphoneGain sanitization in both AudioTrackMixer
initializers must clamp the finite Double to the Float-representable range
before converting to Float, while retaining the existing non-finite and negative
handling. Add a regression test using Double.greatestFiniteMagnitude that
verifies initialization and mixing do not produce invalid samples or trap, and
manually smoke-test on macOS or Windows.
---
Nitpick comments:
In
`@electron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift`:
- Around line 6-54: Extend AudioStartAlignmentTests with cases where the first
source timestamp precedes sessionStart and where it is exactly 250 ms after
sessionStart. Assert AudioStartAlignment.align handles the negative offset and
accepts the inclusive 250 ms upper limit, matching the expected alignment
behavior.
🪄 Autofix
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 32b9736a-1303-4843-a61d-eadc1049f72d
📒 Files selected for processing (2)
electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/AudioTrackMixer.swiftelectron/native/screencapturekit/Tests/OpenScreenScreenCaptureKitHelperTests/AudioStartAlignmentTests.swift
|
Follow-up commit 27a256b adds the requested startup-boundary coverage: zero offset, negative offset, and the inclusive 250 ms compensation boundary. Clean isolated SwiftPM verification passed all 9 AudioStartAlignment tests, and an independent verifier passed the exact diff. |
What changed
Why
Real native macOS recordings showed audio beginning 159–166 ms after video even though packet cadence was stable. The offset came from per-source startup warm-up, not ongoing drift.
Impact
New native macOS recordings start audio and video on the same timeline. The correction is deliberately bounded and does not alter spacing between audio packets.
Validation
Summary by CodeRabbit
Bug Fixes
Tests