Custom video source
By default, PlanetKit automatically detects and controls the camera device when a video call starts, and uses the video captured from the camera for the video call. However, depending on the requirements of your application, you may need to change this. One example is to display video from an external source instead of the user's video.
To meet these needs, PlanetKit provides a custom video source feature that allows users to directly supply the video frames they want. This feature allows users to render the video frames they want to the PlanetKit module and send the video frames to the peer.
PlanetKit does not control the camera device while using a custom video source.
Supported call type | Minimum SDK version |
---|---|
1-to-1 call, group call (conference) | PlanetKit 5.5 |
Implementation steps
To implement the custom video source feature, follow these steps.
Implement a custom video source class
Extend PlanetKitCustomVideoSource
and implement the methods.
package com.example.videosource
import com.linecorp.planetkit.video.PlanetKitCustomVideoSource
import com.linecorp.planetkit.ui.PlanetKitVideoView
// Example implementation of a custom video source
class MyCustomVideoSource : PlanetKitCustomVideoSource() {
// Implement the abstract method to handle FPS limit updates
override fun onMaxFpsLimitUpdated(isLimitEnabled: Boolean, maxFps: Int) {
// Handle the FPS limit update
// If isLimitEnabled is true, adjust your frame generation logic to respect the maxFps
if (isLimitEnabled) {
// Adjust frame generation logic here
} else {
// No FPS limit, generate frames as needed
}
}
// Method to simulate video frame generation
fun generateVideoFrame() {
// Check if posting frame data is available
if (postingFrameDataAvailable()) {
// Create a new frame data instance
val frameData = object : FrameData() {
// Implement any additional frame data properties or methods if needed
}
// Post the frame data to PlanetKit
val accepted = postFrameData(frameData)
if (accepted) {
// Frame data accepted
} else {
// Frame data dropped
}
} else {
// Cannot post frame data at this time
}
}
}
Render to PlanetKit through a custom video source
To render video to PlanetKit through a custom video source, call addMyVideoView()
of PlanetKitCustomVideoSource
.
val myCustomVideoSource = MyCustomVideoSource()
fun attachVideoViewToMyCustomVideoSource(videoView: PlanetKitVideoView) {
myCustomVideoSource.addMyVideoView(videoView)
}
Send video to the peer through a custom video source
To send video to the peer through a custom video source, call setVideoSource()
of PlanetKitCall
or PlanetKitConference
with the PlanetKitCustomVideoSource
object.
val myCustomVideoSource = MyCustomVideoSource()
// For 1-to-1 call
fun useCustomVideoSourceForCall(call: PlanetKitCall) {
call.setVideoSource(myCustomVideoSource)
}
// For group call
fun useCustomVideoSourceForConference(conference: PlanetKitConference) {
conference.setVideoSource(myCustomVideoSource)
}
Switch back to the camera from a custom video source
To switch back to the camera from a custom video source, call clearVideoSoSource()
of PlanetKitCall
or PlanetKitConference
.
// For 1-to-1 call
fun useDefaultCameraVideoSourceForCall(call: PlanetKitCall) {
call.clearVideoSource()
}
// For group call
fun useDefaultCameraVideoSourceForConference(conference: PlanetKitConference) {
conference.clearVideoSource()
}
Related API
APIs related to the custom video source feature are as follows:
-
PlanetKitCustomVideoSource
-
addMyVideoView()
ofPlanetKitCustomVideoSource
-
setVideoSource()
ofPlanetKitCall
-
clearVideoSource()
ofPlanetKitCall
-
setVideoSource()
ofPlanetKitConference
-
clearVideoSource()
ofPlanetKitConference
Use cases
You can use the custom video source feature for the following application requirements:
- Using a video file as a video source
- Receiving live streaming or web streaming and use it as a video source
- Directly controlling the camera device from the application, rather than through PlanetKit