DefaultScreenCaptureSource

class DefaultScreenCaptureSource(context: Context, logger: Logger, surfaceTextureCaptureSourceFactory: SurfaceTextureCaptureSourceFactory, activityResultCode: Int, activityData: Intent, displayManager: DisplayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager, mediaProjectionManager: MediaProjectionManager = context.getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager) : VideoCaptureSource, VideoSink

DefaultScreenCaptureSource uses MediaProjection to create a VirtualDisplay to capture the device screen. It will render the captured frames to a Surface provided by a SurfaceTextureCaptureSourceFactory.

Builders will need to get permission from users to obtain the activityResultCode and activityData arguments, required to create an internal MediaProjection object. Read content share guide for more information.

Note that you must finish starting the foreground service before calling start. Otherwise start will fail to succeed despite having the user grant permission and despite having created a foreground service for the MediaProjection. CaptureSourceObserver.onCaptureFailed will be called with CaptureSourceError.SystemFailure in this case.

If the MediaProjection could not be obtained with the activityResultCode and activityData, CaptureSourceObserver.onCaptureFailed will be called with CaptureSourceError.ConfigurationFailure.

Constructors

Link copied to clipboard
constructor(context: Context, logger: Logger, surfaceTextureCaptureSourceFactory: SurfaceTextureCaptureSourceFactory, activityResultCode: Int, activityData: Intent, displayManager: DisplayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager, mediaProjectionManager: MediaProjectionManager = context.getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager)

Properties

Link copied to clipboard
open override val contentHint: VideoContentHint

Content hint for downstream processing

Functions

Link copied to clipboard
open override fun addCaptureSourceObserver(observer: CaptureSourceObserver)

Add a capture source observer to receive callbacks from the source on lifecycle events which can be used to trigger UI. This observer is entirely optional.

Link copied to clipboard
open override fun addVideoSink(sink: VideoSink)

Add a video sink which will immediately begin to receive new frames.

Link copied to clipboard
open override fun onVideoFrameReceived(frame: VideoFrame)

Receive a video frame from some upstream source. The VideoSink may render, store, process, and forward the frame, among other applications.

Link copied to clipboard
fun release()
Link copied to clipboard

Remove a capture source observer

Link copied to clipboard
open override fun removeVideoSink(sink: VideoSink)

Remove a video sink which will no longer receive new frames on return

Link copied to clipboard
open override fun setMaxResolution(maxResolution: VideoResolution)

Set max resolution for video capture source DefaultCameraCaptureSource and DefaultScreenCaptureSource call this function to set max resolution for camera and screen capture

Link copied to clipboard
open override fun start()

Start capturing on this source and emitting video frames

Link copied to clipboard
open override fun stop()

Stop capturing on this source and cease emitting video frames