Rate this page:

Custom video sources

This article explains how to use a custom video source in calls and conferences.

SDK versions

This article provides examples only for Android SDK v2. Code examples for up-to-date SDKs will be provided soon.

Making a video call

This article assumes that you already know how to make and process video calls in Voximplant SDKs. To learn about video calls, refer to the Processing video calls in SDKs in the Calls section of this documentation.

Configure the SDK

While initializing the SDK, create an EglBase instance via the EglBase.create() API, and add it into ClientConfig before calling Voximplant.getClientInstance().

val eglBase = EglBase.create()
val clientConfig = ClientConfig()
clientConfig.eglBase = eglBase
val client = Voximplant.getClientInstance(
    /* executor = */ Executors.newSingleThreadExecutor(),
    /* context = */ applicationContext,
    /* clientConfig = */ clientConfig,
)

Set up a custom video source

  1. Create a SurfaceTextureHelper instance with the eglBase from the previous step as an argument:
SurfaceTextureHelper.create(eglBase.eglBaseContext)
  1. Create a custom video source instance via the Voximplant.getCustomVideoSource() API.
  2. Apply the SurfaceTextureHelper created in the step 1 to the ICustomVideoSource instance via the ICustomVideoSource.setSurfaceTextureHelper() API.
  3. Subscribe to the custom video source events via ICustomVideoSource.setCustomVideoSourceListener() API and render your custom video frames to the surface texture of the SurafceTextureHelper instance.
val surfaceTextureHelper: SurfaceTextureHelper? = SurfaceTextureHelper.create(
    "SurfaceTextureHelper",
    eglBase.eglBaseContext,
)
surfaceTextureHelper?.setTextureSize(frameWidth, frameHeight)

val customVideoSource = Voximplant.getCustomVideoSource()
customVideoSource.setSurfaceTextureHelper(surfaceTextureHelper)
customVideoSource.setCustomVideoSourceListener(object : ICustomVideoSourceListener {
    override fun onStarted() {
        if (surfaceTextureHelper?.surfaceTexture != null) {
            // render to the surfaceTexture
        }
    }

    override fun onStopped() {
      // stop rendering to the surfaceTexture
    }
})

Use the custom video source in a call

To use the custom video source in a call, apply it via the ICall.useCustomVideoSource() API before ICall.start() or ICall.answer().

val callSettings = CallSettings()
callSettings.videoFlags = VideoFlags(true, true)
val call: ICall? = client.call(user, callSettings)
call?.useCustomVideoSource(customVideoSource)
try {
    call!!.start()
} catch (callException: CallException) {
    // handle error
}

To see the complete code example, refer to the GitHub demo of this feature.