Skip to content

perf(sender): space keyframes and cap peak rate for 5K 60 - #231

Merged
swellweb merged 1 commit into
swellweb:maint-3.6from
ziyadasghar-GIT:pr/sender-5k60-encoder
Nov 12, 2026
Merged

swellweb merged 1 commit into
swellweb:maint-3.6from
ziyadasghar-GIT:pr/sender-5k60-encoder

Conversation

@ziyadasghar-GIT

Copy link
Copy Markdown

Problem

The experimental 5K 60 profile (native5k60Experimental) emitted a keyframe every second. Each one is a large burst that pushes receiver decode past its frame budget, so the stream stalled exactly at keyframes.

Change (5K 60 only)

  • Keyframe every 4 s: maxKeyFrameIntervalDuration 1 → 4, maxKeyFrameInterval 60 → 240.
  • New peakBitRate of 1.5 × average (225 Mb/s), applied through kVTCompressionPropertyKey_DataRateLimits over a 1 s window. If the encoder rejects it, the sender logs and carries on with average-only (the old behaviour).

All other profiles keep their previous tuning. This is covered by the new testStableProfilesKeepPreviousEncoderTuning, alongside test5K60SpacesKeyframesAndCapsPeakRate.

Deliberately not included: an earlier version of this change also switched the direct CGDisplayStream capture path from BGRA to NV12/BT.709. That affects every profile on the headless mirror path, and I couldn't test it on hardware, so I've left it out.

Testing

Hardware: MacBook Air M5 (macOS 27.0.1) → iMac18,3 27" 5K 2017, macOS Ventura 13.7.8, Thunderbolt Bridge.

  • The M5 encoder accepted DataRateLimits; no fallback log line appeared.
  • Stream bitrate at 5K 60 roughly halved: scroll 229 → 115–120 Mbit/s, video 307 → 152 Mbit/s.
  • Delivered fps and the receiver numbers are in the companion receiver PR. Both changes were tested together, so I'm not claiming a separate fps figure for this one.

CI-equivalent checks on maint-3.6 + this commit:

  • build_targetbridge_sender_app.sh: BUILD SUCCEEDED.
  • xcodebuild test: 183 tests, 0 failures, including both new tests.
  • test_video_queue_budget.rb: pass.
  • test_permission_status.rb sender: pass.
  • check_localizations.sh: pass.

Credits

Patch prepared by Ziyad Asghar. Split from the original change, rebased onto maint-3.6, built, tested on hardware and measured with Claude Opus 5.5 (Anthropic), credited via the Co-Authored-By trailer.

The 5K 60 profile emitted a keyframe every second. Each one is a large
burst that pushes receiver decode past its frame budget, so the stream
stalled exactly at keyframes. For native5k60Experimental only:

- keyframe every 4 s (maxKeyFrameIntervalDuration 1 -> 4,
  maxKeyFrameInterval 60 -> 240)
- peak bit rate of 1.5x average (225 Mb/s) via
  kVTCompressionPropertyKey_DataRateLimits over a 1 s window; if the
  encoder rejects it we log and continue with average-only (old behaviour)

Stable profiles keep their previous tuning (covered by
testStableProfilesKeepPreviousEncoderTuning).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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