Class SurfaceViewRenderer

java.lang.Object
android.view.View
android.view.SurfaceView
com.telnyx.webrtc.lib.SurfaceViewRenderer
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, SurfaceHolder.Callback, RendererCommon.RendererEvents, VideoSink

public class SurfaceViewRenderer extends SurfaceView implements SurfaceHolder.Callback, VideoSink, RendererCommon.RendererEvents
Display the video stream on a SurfaceView.
  • Constructor Details

    • SurfaceViewRenderer

      public SurfaceViewRenderer(Context context)
      Standard View constructor. In order to render something, you must first call init().
    • SurfaceViewRenderer

      public SurfaceViewRenderer(Context context, AttributeSet attrs)
      Standard View constructor. In order to render something, you must first call init().
  • Method Details

    • init

      public void init(EglBase.Context sharedContext, RendererCommon.RendererEvents rendererEvents)
      Initialize this class, sharing resources with `sharedContext`. It is allowed to call init() to reinitialize the renderer after a previous init()/release() cycle.
    • init

      public void init(EglBase.Context sharedContext, RendererCommon.RendererEvents rendererEvents, int[] configAttributes, RendererCommon.GlDrawer drawer)
      Initialize this class, sharing resources with `sharedContext`. The custom `drawer` will be used for drawing frames on the EGLSurface. This class is responsible for calling release() on `drawer`. It is allowed to call init() to reinitialize the renderer after a previous init()/release() cycle.
    • release

      public void release()
      Block until any pending frame is returned and all GL resources released, even if an interrupt occurs. If an interrupt occurs during release(), the interrupt flag will be set. This function should be called before the Activity is destroyed and the EGLContext is still valid. If you don't call this function, the GL resources might leak.
    • addFrameListener

      public void addFrameListener(EglRenderer.FrameListener listener, float scale, RendererCommon.GlDrawer drawerParam)
      Register a callback to be invoked when a new video frame has been received.
      Parameters:
      listener - The callback to be invoked. The callback will be invoked on the render thread. It should be lightweight and must not call removeFrameListener.
      scale - The scale of the Bitmap passed to the callback, or 0 if no Bitmap is required.
      drawer - Custom drawer to use for this frame listener.
    • addFrameListener

      public void addFrameListener(EglRenderer.FrameListener listener, float scale)
      Register a callback to be invoked when a new video frame has been received. This version uses the drawer of the EglRenderer that was passed in init.
      Parameters:
      listener - The callback to be invoked. The callback will be invoked on the render thread. It should be lightweight and must not call removeFrameListener.
      scale - The scale of the Bitmap passed to the callback, or 0 if no Bitmap is required.
    • removeFrameListener

      public void removeFrameListener(EglRenderer.FrameListener listener)
    • setEnableHardwareScaler

      public void setEnableHardwareScaler(boolean enabled)
      Enables fixed size for the surface. This provides better performance but might be buggy on some devices. By default this is turned off.
    • setMirror

      public void setMirror(boolean mirror)
      Set if the video stream should be mirrored or not.
    • setScalingType

      public void setScalingType(RendererCommon.ScalingType scalingType)
      Set how the video will fill the allowed layout area.
    • setScalingType

      public void setScalingType(RendererCommon.ScalingType scalingTypeMatchOrientation, RendererCommon.ScalingType scalingTypeMismatchOrientation)
    • setFpsReduction

      public void setFpsReduction(float fps)
      Limit render framerate.
      Parameters:
      fps - Limit render framerate to this value, or use Float.POSITIVE_INFINITY to disable fps reduction.
    • disableFpsReduction

      public void disableFpsReduction()
    • pauseVideo

      public void pauseVideo()
    • 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
    • surfaceCreated

      public void surfaceCreated(SurfaceHolder holder)
      Specified by:
      surfaceCreated in interface SurfaceHolder.Callback
    • surfaceDestroyed

      public void surfaceDestroyed(SurfaceHolder holder)
      Specified by:
      surfaceDestroyed in interface SurfaceHolder.Callback
    • surfaceChanged

      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
      Specified by:
      surfaceChanged in interface SurfaceHolder.Callback
    • clearImage

      public void clearImage()
      Post a task to clear the SurfaceView to a transparent uniform color.
    • onFirstFrameRendered

      public void onFirstFrameRendered()
      Description copied from interface: RendererCommon.RendererEvents
      Callback fired once first frame is rendered.
      Specified by:
      onFirstFrameRendered in interface RendererCommon.RendererEvents
    • onFrameResolutionChanged

      public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation)
      Description copied from interface: RendererCommon.RendererEvents
      Callback fired when rendered frame resolution or rotation has changed.
      Specified by:
      onFrameResolutionChanged in interface RendererCommon.RendererEvents