Package tvi.webrtc

Class EglRenderer

java.lang.Object
tvi.webrtc.EglRenderer
All Implemented Interfaces:
VideoSink
Direct Known Subclasses:
SurfaceEglRenderer

public class EglRenderer extends Object implements VideoSink
Implements VideoSink by displaying the video stream on an EGL Surface. This class is intended to be used as a helper class for rendering on SurfaceViews and TextureViews.
  • Field Details

    • name

      protected final String name
  • Constructor Details

    • EglRenderer

      public EglRenderer(String name)
      Standard constructor. The name will be used for the render thread name and included when logging. In order to render something, you must first call init() and createEglSurface.
    • EglRenderer

      public EglRenderer(String name, VideoFrameDrawer videoFrameDrawer)
  • Method Details

    • init

      public void init(@Nullable EglBase.Context sharedContext, int[] configAttributes, RendererCommon.GlDrawer drawer, boolean usePresentationTimeStamp)
      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. If usePresentationTimeStamp is true, eglPresentationTimeANDROID will be set with the frame timestamps, which specifies desired presentation time and might be useful for e.g. syncing audio and video.
    • init

      public void init(@Nullable EglBase.Context sharedContext, int[] configAttributes, RendererCommon.GlDrawer drawer)
      Same as above with usePresentationTimeStamp set to false.
      See Also:
    • createEglSurface

      public void createEglSurface(android.view.Surface surface)
    • createEglSurface

      public void createEglSurface(android.graphics.SurfaceTexture surfaceTexture)
    • 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.
    • printStackTrace

      public void printStackTrace()
    • setMirror

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

      public void setMirrorVertically(boolean mirrorVertically)
      Set if the video stream should be mirrored vertically or not.
    • setLayoutAspectRatio

      public void setLayoutAspectRatio(float layoutAspectRatio)
      Set layout aspect ratio. This is used to crop frames when rendering to avoid stretched video. Set this to 0 to disable cropping.
    • 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()
    • 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.
    • 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.
      drawerParam - Custom drawer to use for this frame listener or null to use the default one.
    • addFrameListener

      public void addFrameListener(EglRenderer.FrameListener listener, float scale, @Nullable RendererCommon.GlDrawer drawerParam, boolean applyFpsReduction)
      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.
      drawerParam - Custom drawer to use for this frame listener or null to use the default one.
      applyFpsReduction - This callback will not be called for frames that have been dropped by FPS reduction.
    • removeFrameListener

      public void removeFrameListener(EglRenderer.FrameListener listener)
      Remove any pending callback that was added with addFrameListener. If the callback is not in the queue, nothing happens. It is ensured that callback won't be called after this method returns.
      Parameters:
      listener - The callback to remove.
    • setErrorCallback

      public void setErrorCallback(EglRenderer.ErrorCallback errorCallback)
      Can be set in order to be notified about errors encountered during rendering.
    • 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
    • releaseEglSurface

      public void releaseEglSurface(Runnable completionCallback)
      Release EGL surface. This function will block until the EGL surface is released.
    • clearImage

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

      public void clearImage(float r, float g, float b, float a)
      Post a task to clear the surface to a specific color.