カスタムビデオソース
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ではなくアプリケーションで直接したいとき