createCameraVideoTrack

suspend fun createCameraVideoTrack(encoderConfig: CustomCameraTrackConfig? = null, facingMode: FacingMode? = null, multiStream: Boolean = true, cameraId: String? = null, maxLayer: EncodingLayer? = null, bitrateMode: BitrateMode? = null, codec: VideoCodec? = null): CustomStreamTrack

Creates a camera track and opens the camera for a self-view: pass CustomStreamTrack.track to VideoView.addTrack to preview before join, and the track to createRoom / Room.enableCam(track) to publish that camera without reopening it.

One camera pipeline per process: while the camera publishes, a new track shares its frames and otherwise waits with no frames until used; a previous unpublished track's preview stops and that track ends. CustomStreamTrack.stop closes the camera.

Failures throw a VideoSDKException and are never reported on onError: 3071 for an unknown cameraId, 3021 when there is no camera, 3017 when CAMERA is not granted, 3053 for any other failure to set the track up.

Suspends until the camera opens, for at most 3 s. An open that fails in that time throws 3023 when another app holds the camera, 3019 when device policy disables it, or 3026 for any other device fault. An open still pending after 3 s returns the track anyway, and a camera that fails later ends the track, reaching CustomStreamTrack.onEnded. The work runs on a background thread, so it is safe to call from the main thread.

The factory never asks for CAMERA and never waits for it: request it first with checkPermissions.

Return

the track; a failure throws instead.

Parameters

encoderConfig

the capture size and frame rate; null means CustomCameraTrackConfig.H720P_W1280P.

facingMode

the camera to open; null means FacingMode.front.

multiStream

true publishes a simulcast ladder so each viewer can take the layer its link affords; false sends one stream.

cameraId

the deviceId of a camera from getCameras, or null for facingMode's camera.

maxLayer

how many simulcast layers to publish; null means EncodingLayer.MAX_LAYER_3.

bitrateMode

how aggressively the encoder spends bitrate; null means BitrateMode.BALANCED.

codec

the codec to publish with; null means VideoCodec.VP8. Read VideoCodec before choosing another: it costs simulcast.

Throws

if initialize has not been called.