커스텀 비디오 소스
기본적으로 PlanetKit은 영상 통화 시작 시 카메라 장치를 자동으로 감지하여 제어하며, 카메라에서 캡처한 비디오를 영상 통화에 사용합니다. 하지만 애플리케이션의 요구사항에 따라 이를 변경해야 할 필요가 있을 수 있습니다. 사용자의 비디오 대신 외부 소스에서 가져온 비디오를 화면에 보여주는 것이 한 가지 예입니다.
이러한 요구를 충족할 수 있도록 PlanetKit은 원하는 비디오 프레임을 직접 공급할 수 있는 커스텀 비디오 소스(custom video source) 기능을 제공합니다. 이 기능을 통해 사용자가 원하는 비디오 프레임을 직접 PlanetKit 모듈에 렌더링하고 상대방에게 전달할 수 있습니다.
커스텀 비디오 소스를 사용하는 동안은 PlanetKit이 카메라 장치를 제어하지 않습니다.
지원 통화 유형 | 최소 SDK 버전 |
---|---|
1대1 통화, 그룹 통화(컨퍼런스) | PlanetKit 5.5 |
구현 절차
커스텀 비디오 소스 기능을 구현하는 절차는 다음과 같습니다.
커스텀 비디오 소스 클래스 구현하기
PlanetKitCustomVideoSource
를 확장(extend)하고 메서드를 구현하세요.
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
}
}
}
커스텀 비디오 소스를 통해 PlanetKit에 렌더링하기
커스텀 비디오 소스를 통해 PlanetKit에 비디오를 렌더링하려면 PlanetKitCustomVideoSource
의 addMyVideoView()
를 호출하세요.
val myCustomVideoSource = MyCustomVideoSource()
fun attachVideoViewToMyCustomVideoSource(videoView: PlanetKitVideoView) {
myCustomVideoSource.addMyVideoView(videoView)
}
커스텀 비디오 소스를 통해 상대방에게 영상 전송하기
커스텀 비디오 소스를 통해 상대방에게 영상을 전송하려면 PlanetKitCustomVideoSource
객체를 인자로 PlanetKitCall
또는 PlanetKitConference
의 setVideoSource()
을 호출하세요.
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)
}
커스텀 비디오 소스를 카메라로 되돌려 놓기
커스텀 비디오 소스를 카메라로 되돌려 놓으려면 PlanetKitCall
또는 PlanetKitConference
의 clearVideoSource()
를 호출하세요.
// For 1-to-1 call
fun useDefaultCameraVideoSourceForCall(call: PlanetKitCall) {
call.clearVideoSource()
}
// For group call
fun useDefaultCameraVideoSourceForConference(conference: PlanetKitConference) {
conference.clearVideoSource()
}
관련 API
커스텀 비디오 소스 기능과 관련된 API는 다음과 같습니다.
-
PlanetKitCustomVideoSource
-
PlanetKitCustomVideoSource
의addMyVideoView()
-
PlanetKitCall
의setVideoSource()
-
PlanetKitCall
의clearVideoSource()
-
PlanetKitConference
의setVideoSource()
-
PlanetKitConference
의clearVideoSource()
활용 예시
아래와 같은 애플리케이션 요구사항이 있을 때 커스텀 비디오 소스를 활용하여 구현할 수 있습니다.
- 영상 파일을 비디오 소스로 사용하고자 할 때
- 라이브 이원 생중계나 웹 스트리밍을 받아서 비디오 소스로 사용하고자 할 때
- 카메라 장치에 대한 제어를 PlanetKit에서 하지 않고 애플리케이션에서 직접 하고 싶을 때