Skip to content

feat(camera2): add optional secondarySurface fan-out to Camera2Source - #2242

Open
Mike-the-one wants to merge 1 commit into
pedroSG94:masterfrom
Mike-the-one:pr/camera2-secondary-surface
Open

Mike-the-one wants to merge 1 commit into
pedroSG94:masterfrom
Mike-the-one:pr/camera2-secondary-surface

Conversation

@Mike-the-one

Copy link
Copy Markdown

Summary

Adds setSecondarySurface(surface: Surface?) to Camera2Source and Camera2ApiManager so callers can fan out Camera2 frames directly to a second Surface alongside RootEncoder's primary SurfaceTexture.

Motivation

When feeding an external consumer in parallel with RootEncoder (for example, a WebRTC SurfaceTextureHelper or another hardware Surface), tapping via a GL filter shares RootEncoder's single GL thread and encoder/preview cadence. Adding a secondary target Surface directly to the Camera2 CaptureSession lets Camera2 deliver frames natively to both surfaces without extra GL passes or thread contention.

Changes

  • Camera2ApiManager:
    • Added @Volatile private var secondarySurface: Surface? and fun setSecondarySurface(surface: Surface?).
    • Validates surface?.takeIf { it.isValid } before updating and before adding to listSurfaces in startPreview().
    • When Camera2 is already running, posts a capture session restart on cameraHandler (guarded by isRunning and cameraDevice != null) so the secondary surface can be attached/detached dynamically.
    • Caller retains ownership of secondarySurface (closeCamera() does not release it).
  • Camera2Source:
    • Exposed fun setSecondarySurface(surface: Surface?) delegating to Camera2ApiManager.

Testing

  • Verified with publishToMavenLocal and an Android app (GenericStream + Camera2Source) dynamically attaching/detaching a WebRTC SurfaceTextureHelper Surface while streaming/recording at 1080p30.

This branch has not been deployed

No deployments
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