Kotlin

Starting capture: wiring into the Publisher lifecycle

  1. Using the custom capturer in the Publisher

Wherever you create your publisher (e.g., in MainActivity or a dedicated call manager), you pass an instance of the custom capturer into the Publisher.Builder:

    publisher = Publisher.Builder(this@MainActivity)
                .capturer(
                    MirrorVideoCapturer(
                        this@MainActivity,
                        Publisher.CameraCaptureResolution.HIGH,
                        Publisher.CameraCaptureFrameRate.FPS_30
                    )
                )
                .build()

After you build a Publisher and provide your MirrorVideoCapturer instance - all outgoing video for that publisher comes from your custom capturer instead of the default one.

  1. Once you create a Publisher with your custom capturer and call session.publish(publisher), the SDK will call into your capturer’s startCapture() method.
    @Synchronized
    override fun startCapture(): Int {
        Log.d(TAG, "startCapture() enter (cameraState: $cameraState)")
        val resume = Runnable {
            initCamera()
            scheduleStartCapture()
        }
        when (cameraState) {
            CameraState.CLOSING -> executeAfterClosed = resume
            CameraState.CLOSED -> resume.run()
            else -> scheduleStartCapture()
        }
        Log.d(TAG, "startCapture() exit")
        return 0
    }

The high‑level flow is as follows:

Check camera state: ensure the underlying camera resource is initialized and ready. Start capture loop: Open the camera (if not already open). Start a repeating capture request (Camera2) or start the preview pipeline (CameraX / Camera1). Handle “not ready yet” cases: If camera setup is still in progress, queue the actual start until the camera is opened (avoids race conditions). Error handling: If something is fundamentally wrong (e.g., startCapture called too early), throw or signal an error.

After startCapture() succeeds, your capturer starts receiving camera frames and pushing them to the SDK.