Skip to content

feat: iOS video renderer improvements - #77

Open
Brazol wants to merge 3 commits into
mainfrom
chore/ios-render-improvements
Open

feat: iOS video renderer improvements#77
Brazol wants to merge 3 commits into
mainfrom
chore/ios-render-improvements

Conversation

@Brazol

@Brazol Brazol commented Jul 22, 2026

Copy link
Copy Markdown

Summary by CodeRabbit

  • Performance Improvements
    • Improved video rendering efficiency through zero-copy frame delivery where supported.
    • Reduced visual processing overhead by reusing video buffers and optimizing rotation, cropping, and scaling.
  • Bug Fixes
    • Corrected video-track switching to properly detach the previous track before attaching a new one.
  • Rendering
    • Updated iOS platform-view rendering for smoother, more consistent video playback.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Brazol, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7a3a605-e1c6-4743-906d-4c9c2d98607b

📥 Commits

Reviewing files that changed from the base of the PR and between 1c8a212 and 0ba15ef.

📒 Files selected for processing (2)
  • ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m
  • macos/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m
📝 Walkthrough

Walkthrough

The changes replace iOS sample-buffer rendering with WebRTC shared Metal rendering, correct previous-track detachment, and update iOS/macOS texture renderers to reuse buffers, optimize NV12 delivery, handle rotation efficiently, and retain the current frame buffer.

Changes

Video rendering pipeline

Layer / File(s) Summary
Platform view and track integration
ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoPlatformView.m, ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoPlatformViewController.m
The iOS platform view forwards layout, size, and frames to RTCVideoRenderingView using the shared Metal backend, while track replacement detaches an existing previous track.
Reusable renderer buffers and rotation
ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m, macos/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m
Renderers retain the current output buffer, reuse NV12, crop, and rotated I420 buffers, and release the added resources during disposal.
NV12 and texture frame delivery
ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m, macos/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m
Frame handling attempts zero-copy or reused NV12 output before falling back to I420 conversion, then publishes the selected buffer through the texture registry.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RTCVideoFrame
  participant FlutterRTCVideoRenderer
  participant FlutterTextureRegistry
  RTCVideoFrame->>FlutterRTCVideoRenderer: provide video frame
  FlutterRTCVideoRenderer->>FlutterRTCVideoRenderer: select zero-copy, NV12, or I420 output
  FlutterRTCVideoRenderer->>FlutterTextureRegistry: mark texture frame available
  FlutterTextureRegistry->>FlutterRTCVideoRenderer: request current pixel buffer
  FlutterRTCVideoRenderer-->>FlutterTextureRegistry: return retained current buffer
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the renderer-focused improvements, though it understates that macOS changes are included too.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/ios-render-improvements

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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
`@ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m`:
- Around line 70-84: Update ensureNV12BufferWithWidth:height: to accept the
source pixel format and use it when creating _nv12BufferRef, rather than always
selecting kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange. Pass renderFrame:’s
fmt through this method so both video-range and full-range NV12 frames retain
their correct color range.

In
`@macos/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m`:
- Around line 70-84: Update ensureNV12BufferWithWidth:height: to accept the
source fmt, create _nv12BufferRef with that format, and include fmt in the
reuse-validity check so a format change recreates the buffer. Propagate fmt from
the crop path and validate the CVPixelBufferCreate result before retaining or
using the buffer.
- Around line 245-293: Double-buffer the cropped NV12 output used by the
renderer: replace the single _nv12BufferRef handoff in cropAndScaleTo: with two
reusable NV12 pixel buffers, selecting the buffer not currently published as
_currentBuffer before each crop. Update ensureNV12BufferWithWidth:height: and
the cleanup/state handling so both buffers are allocated, reused, and released
safely, while preserving the existing zero-copy path for unpadded IOSurface
frames.
🪄 Autofix (Beta)

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

Run ID: f6e08697-bff9-4151-a880-c4d2358bde28

📥 Commits

Reviewing files that changed from the base of the PR and between d7098ba and 1c8a212.

📒 Files selected for processing (4)
  • ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoPlatformView.m
  • ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoPlatformViewController.m
  • ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m
  • macos/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m

Comment thread ios/stream_webrtc_flutter/Sources/stream_webrtc_flutter/FlutterRTCVideoRenderer.m Outdated
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