Custom video sources
This article explains how to use a custom video source in calls and conferences.
This article provides examples only for Android SDK v2. Code examples for up-to-date SDKs will be provided soon.
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
- Create a
SurfaceTextureHelperinstance with theeglBasefrom the previous step as an argument:
SurfaceTextureHelper.create(eglBase.eglBaseContext)
- Create a custom video source instance via the Voximplant.getCustomVideoSource() API.
- Apply the
SurfaceTextureHelpercreated in the step 1 to theICustomVideoSourceinstance via the ICustomVideoSource.setSurfaceTextureHelper() API. - 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.