Skip to content

Comments

[Enhancement]Improve frame rendering#70

Merged
ipavlidakis merged 4 commits intodevelopfrom
iliaspavlidakis/improve-frame-rendering
Feb 3, 2026
Merged

[Enhancement]Improve frame rendering#70
ipavlidakis merged 4 commits intodevelopfrom
iliaspavlidakis/improve-frame-rendering

Conversation

@ipavlidakis
Copy link
Contributor

@ipavlidakis ipavlidakis commented Jan 28, 2026

Summary

This PR introduces an opt‑in shared Metal rendering backend and NV12 frame‑buffer policies for iOS, behind the stream_enable_rendering_backend build flag (default false). It adds NV12 buffer wrappers, policy‑driven bridging for ObjC frame buffers, and a new RTCVideoRenderingView that can select between the default Metal view and the shared backend. Existing behavior is preserved when the flag is disabled.

Key Changes

  • NV12 buffer support (ObjC): Adds RTCNV12Buffer protocol and RTCNativeNV12Buffer wrapper to expose NV12 data to ObjC consumers.
  • Policy‑driven frame buffer bridging: Adds RTCFrameBufferPolicy on RTCPeerConnectionFactory to control how decoded buffers are bridged to ObjC:
    • None (default) → I420 only
    • WrapOnlyExistingNV12 → wrap NV12 if already available
    • CopyToNV12 → copy to NV12
    • ConvertWithPoolToNV12 → pooled NV12 conversion
  • Stream‑specific ObjC frame buffer implementation: Introduces objc_frame_buffer_stream.mm compiled only when stream_enable_rendering_backend is enabled, leaving the default WebRTC file untouched.
  • Shared Metal rendering backend (iOS only): Adds a shared rendering context, adapter, and view (RTCSharedMetalRenderingContext, RTCSharedMetalRenderAdapter, RTCSharedMetalVideoView) to reduce per‑view Metal overhead. XR (visionOS) is excluded until validated.
  • New rendering view wrapper: RTCVideoRenderingView selects either default Metal rendering or shared Metal when available, with fallback to RTCMTLVideoView if shared context fails.
  • Documentation updates: Clarifies frameBufferPolicy per‑frame behavior and mid‑call changes, and notes property access is not synchronized.
  • Logging improvement: Logs a one‑time error when the shared Metal context fails to initialize and fallback is used for the process lifetime.

Behavior & Compatibility

  • Off by default: stream_enable_rendering_backend = false ensures existing consumers see no changes unless they opt in.
  • Runtime policy changes are supported but may cause per‑frame format mixing; documented accordingly.
  • XR (visionOS) excluded intentionally until validated.

Introduce stream_enable_rendering_backend GN arg to isolate Stream-specific
rendering changes. When enabled, build a new shared Metal backend target and
swap in an NV12-capable ObjC frame buffer bridge; otherwise keep upstream
objc_frame_buffer unchanged.

- add RTCSharedMetal* view/context/adapter and wire RTCVideoRenderingView
  to use it on iOS when RTC_STREAM_RENDERING_BACKEND is set
- add maxInFlightFrames to RTCVideoRenderingView and forward to backend
- gate NV12 wrappers and ObjC frame-buffer policy to stream builds only
- move NV12 policy implementation to objc_frame_buffer_stream.mm and keep
  objc_frame_buffer.mm clean
- export NV12 headers only when the stream flag is enabled
- add comments to clarify gating and platform behavior
Copy link

@martinmitrevski martinmitrevski left a comment

Choose a reason for hiding this comment

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

check the feedback shared via slack, if there's something meaningful there. Other than that, we're good ✅

@ipavlidakis ipavlidakis marked this pull request as ready for review February 3, 2026 10:49
@ipavlidakis ipavlidakis merged commit 95791a8 into develop Feb 3, 2026
@ipavlidakis ipavlidakis deleted the iliaspavlidakis/improve-frame-rendering branch February 3, 2026 10:54
santhoshvai added a commit to GetStream/react-native-webrtc that referenced this pull request Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants