本文にスキップする
Under translation
このページは現在翻訳中です。
Version: 5.5

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.

Note

PlanetKit does not control the camera device while using a custom video source.

Supported call typeMinimum 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

Create a class that inherits from PlanetKitCustomCamera and implement the methods.

import PlanetKit

class CustomCamera: PlanetKitCustomCamera {
static var shared = CustomCamera()

// Implement the abstract method to handle FPS limit updates
override func processFpsLimitUpdate(enabled: Bool, fps: Int32) {
// Handle the FPS limit update
// If `enabled` is true, adjust your frame generation logic to according to the `fps`
}

// Method to simulate video buffer processing
func processVideoBuffer(buffer: CMSampleBuffer) {
guard let targetBuffer = PlanetKitVideoBuffer.getPreferredSampleBuffer(buffer) else {
return
}

let timestamp = CMSampleBufferGetPresentationTimeStamp(targetBuffer)

// Check if video buffer can be sent. If false, drop the buffer.
guard isVideoSendAvailable(timestamp: timestamp) else { return }


let videoBuffer = PlanetKitVideoBuffer(sampleBuffer: targetBuffer,
timestamp: timestamp,
rotation: .rotation0,
position: .unknown,
sender: nil,
source: .camera)

sendVideo(videoBuffer: videoBuffer)
}
}

Use a custom video source

To use a custom video source, call setCustomCamera() of PlanetKitCameraManager with an object of the implemented custom video source.

PlanetKitCameraManager.shared.setCustomCamera(CustomCamera.shared)

Switch back to the camera from a custom video source

To switch back to the camera from a custom video source, call resetToDefaultCamera() of PlanetKitCameraManager.

PlanetKitCameraManager.shared.resetToDefaultCamera()

APIs related to the custom video source feature are as follows:

  • PlanetKitCustomCamera iOS, macOS
  • PlanetKitCameraManagersetCustomCamera() iOS, macOS
  • PlanetKitCameraManagerresetToDefaultCamera() iOS, macOS

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