Package tvi.webrtc

Class ScreenCapturerAndroid

java.lang.Object
tvi.webrtc.ScreenCapturerAndroid
All Implemented Interfaces:
VideoCapturer, VideoSink

public class ScreenCapturerAndroid extends Object implements VideoCapturer, VideoSink
An implementation of VideoCapturer to capture the screen content as a video stream. Capturing is done by MediaProjection on a SurfaceTexture. We interact with this SurfaceTexture using a SurfaceTextureHelper. The SurfaceTextureHelper is created by the native code and passed to this capturer in VideoCapturer.initialize(). On receiving a new frame, this capturer passes it as a texture to the native code via CapturerObserver.onFrameCaptured(). This takes place on the HandlerThread of the given SurfaceTextureHelper. When done with each frame, the native code returns the buffer to the SurfaceTextureHelper to be used for new frames. At any time, at most one frame is being processed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ScreenCapturerAndroid(android.content.Intent mediaProjectionPermissionResultData, android.media.projection.MediaProjection.Callback mediaProjectionCallback)
    Constructs a new Screen Capturer.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    changeCaptureFormat(int width, int height, int ignoredFramerate)
    Changes output video format.
    void
    Perform any final cleanup here.
    android.media.projection.MediaProjection
     
    long
     
    void
    initialize(SurfaceTextureHelper surfaceTextureHelper, android.content.Context applicationContext, CapturerObserver capturerObserver)
    This function is used to initialize the camera thread, the android application context, and the capture observer.
    boolean
     
    void
    Implementations should call frame.retain() if they need to hold a reference to the frame after this function returns.
    void
    startCapture(int width, int height, int ignoredFramerate)
    Start capturing frames in a format that is as close as possible to width x height and framerate.
    void
    Stop capturing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ScreenCapturerAndroid

      public ScreenCapturerAndroid(android.content.Intent mediaProjectionPermissionResultData, android.media.projection.MediaProjection.Callback mediaProjectionCallback)
      Constructs a new Screen Capturer.
      Parameters:
      mediaProjectionPermissionResultData - the result data of MediaProjection permission activity; the calling app must validate that result code is Activity.RESULT_OK before calling this method.
      mediaProjectionCallback - MediaProjection callback to implement application specific logic in events such as when the user revokes a previously granted capture permission.
  • Method Details

    • getMediaProjection

      @Nullable public android.media.projection.MediaProjection getMediaProjection()
    • initialize

      public void initialize(SurfaceTextureHelper surfaceTextureHelper, android.content.Context applicationContext, CapturerObserver capturerObserver)
      Description copied from interface: VideoCapturer
      This function is used to initialize the camera thread, the android application context, and the capture observer. It will be called only once and before any startCapture() request. The camera thread is guaranteed to be valid until dispose() is called. If the VideoCapturer wants to deliver texture frames, it should do this by rendering on the SurfaceTexture in surfaceTextureHelper, register itself as a listener, and forward the frames to CapturerObserver.onFrameCaptured(). The caller still has ownership of surfaceTextureHelper and is responsible for making sure surfaceTextureHelper.dispose() is called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new VideoCapturer once the previous VideoCapturer has been disposed.
      Specified by:
      initialize in interface VideoCapturer
    • startCapture

      public void startCapture(int width, int height, int ignoredFramerate)
      Description copied from interface: VideoCapturer
      Start capturing frames in a format that is as close as possible to width x height and framerate.
      Specified by:
      startCapture in interface VideoCapturer
    • stopCapture

      public void stopCapture()
      Description copied from interface: VideoCapturer
      Stop capturing. This function should block until capture is actually stopped.
      Specified by:
      stopCapture in interface VideoCapturer
    • dispose

      public void dispose()
      Description copied from interface: VideoCapturer
      Perform any final cleanup here. No more capturing will be done after this call.
      Specified by:
      dispose in interface VideoCapturer
    • changeCaptureFormat

      public void changeCaptureFormat(int width, int height, int ignoredFramerate)
      Changes output video format. This method can be used to scale the output video, or to change orientation when the captured screen is rotated for example.
      Specified by:
      changeCaptureFormat in interface VideoCapturer
      Parameters:
      width - new output video width
      height - new output video height
      ignoredFramerate - ignored
    • onFrame

      public void onFrame(VideoFrame frame)
      Description copied from interface: VideoSink
      Implementations should call frame.retain() if they need to hold a reference to the frame after this function returns. Each call to retain() should be followed by a call to frame.release() when the reference is no longer needed.
      Specified by:
      onFrame in interface VideoSink
    • isScreencast

      public boolean isScreencast()
      Specified by:
      isScreencast in interface VideoCapturer
      Returns:
      true if-and-only-if this is a screen capturer.
    • getNumCapturedFrames

      public long getNumCapturedFrames()