Skip to content

Fix local track dimensions during device rotation#950

Open
pblazej wants to merge 4 commits intomainfrom
blaze/rotation-dimension-freeze
Open

Fix local track dimensions during device rotation#950
pblazej wants to merge 4 commits intomainfrom
blaze/rotation-dimension-freeze

Conversation

@pblazej
Copy link
Contributor

@pblazej pblazej commented Mar 16, 2026

Resolves #949

My initial speculation was that the orientation (dimensions) is unstable between the capturer/track/publication - so we need more debounce - during the actual rotation.

Probably the reason is simpler, disabling isDebugMode also disables fpsTimer that may resolve the dimensions "automatically" (in non-smooth way).

Note: this is only reproducible with UIKit (uikit-minimal example), SwiftUI does the layout thing implicitly.

No exact change that could have caused that (maybe still m137 regression - order of operations?).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pblazej pblazej force-pushed the blaze/rotation-dimension-freeze branch from 841f4c8 to c5c724d Compare March 17, 2026 08:01
Trigger setNeedsLayout() when track dimensions change so performLayout()
recomputes the renderer frame. Since WebRTC m137 the Metal renderer no
longer does this internally, causing stale/distorted video after rotation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pblazej pblazej force-pushed the blaze/rotation-dimension-freeze branch from 6bf7e10 to e040846 Compare March 17, 2026 08:08
@pblazej pblazej marked this pull request as ready for review March 17, 2026 13:21
@pblazej pblazej requested a review from hiroshihorie March 17, 2026 13:21
@pblazej
Copy link
Contributor Author

pblazej commented Mar 17, 2026

@hiroshihorie the change is totally additive, but I'll wait till it's confirmed to work (multiple moving parts here).

…tion

On certain devices (e.g. iPhone 11), the accelerometer oscillates at
landscape orientation boundaries, causing WebRTC's RTCCameraVideoCapturer
to alternate frame rotation between portrait and landscape on every frame.
This produced continuous dimension toggling (1280x720 ↔ 720x1280) that
thrashed encoder parameters, layout, and Metal drawable sizing—freezing
the local video preview permanently.

- Require 3 consecutive frames with the same dimensions before accepting
  a change in VideoCapturer.set(dimensions:) (first value and nil still
  propagate immediately)
- VideoView.render() reads capturer.dimensions (stabilized) for local
  tracks instead of computing from raw frame rotation
- Guard rotationOverride setter in performLayout() to avoid transient
  zero drawableSize on every layout pass

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Local video track freezes in landscape or loses aspect ratio (even is sample app)

1 participant