com.brightcove.player.video360

## Class RenderThread

- java.lang.Object
- - java.lang.Thread
  - - android.os.HandlerThread
    - - com.brightcove.player.video360.RenderThread

- All Implemented Interfaces:
    java.lang.Runnable

      @RequiresApi(api=17)
      public class RenderThread
      extends android.os.HandlerThread

  RenderThread waits for the SphericalVideoPlayer's SurfaceTexture to be available then sets up a GL rendering context, creates an external texture for the video decoder to output to, asks for vsync updates from the Choreographer, attaches a frame available listener the video decode SurfaceTexture, then begins video playback.

  Drag events from the main thread will be forwarded to the RenderThread's message queue so that it may update the view state.

  SphericalSceneRenderer draws the 360 video scene each frame using the latest latched video texture frame.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static float` | `FOVY`
    `static int` | `MSG_FRAME_AVAILABLE`
    `static int` | `MSG_ON_SCROLL`
    `static int` | `MSG_SET_POSITION`
    `static int` | `MSG_SURFACE_AVAILABLE`
    `static int` | `MSG_SURFACE_CHANGED`
    `static int` | `MSG_SURFACE_DESTROYED`
    `static int` | `MSG_VSYNC`
    `static float` | `Z_FAR`
    `static float` | `Z_NEAR`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RenderThread(RenderView renderView)` Constructs a new 360 video renderer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `android.view.Surface` | `getVideoDecodeSurface()` Creates a new `Surface` that will be used to render the 360 video.
    `boolean` | `isVrMode()` Checks whether the renderer is currently configured to render the video in Google VR mode.
    `void` | `notifySurfaceAvailable(java.lang.Object surface, int width, int height)` Notifies the video render thread that the surface is available.
    `void` | `notifySurfaceChanged(android.view.Surface surface, int width, int height)` Notifies the video render thread that the surface has changed.
    `void` | `notifySurfaceDestroyed()` Notifies the video render thread that the surface has been destroyed.
    `void` | `setOnFrameAvailableListener(android.graphics.SurfaceTexture.OnFrameAvailableListener onFrameAvailableListener)`
    `void` | `setVrMode(boolean vrMode)` Sets whether the renderer should render the video in Google VR mode.
    `void` | `start()` Starts the render thread to run asynchronously.

    - ### Methods inherited from class android.os.HandlerThread

      `getLooper, getThreadId, onLooperPrepared, quit, quitSafely, run`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### MSG_SURFACE_AVAILABLE

          public static final int MSG_SURFACE_AVAILABLE

      See Also:
        Constant Field Values

    - #### MSG_SURFACE_CHANGED

          public static final int MSG_SURFACE_CHANGED

      See Also:
        Constant Field Values

    - #### MSG_SURFACE_DESTROYED

          public static final int MSG_SURFACE_DESTROYED

      See Also:
        Constant Field Values

    - #### MSG_FRAME_AVAILABLE

          public static final int MSG_FRAME_AVAILABLE

      See Also:
        Constant Field Values

    - #### MSG_VSYNC

          public static final int MSG_VSYNC

      See Also:
        Constant Field Values

    - #### MSG_ON_SCROLL

          public static final int MSG_ON_SCROLL

      See Also:
        Constant Field Values

    - #### MSG_SET_POSITION

          public static final int MSG_SET_POSITION

      See Also:
        Constant Field Values

    - #### FOVY

          public static final float FOVY

      See Also:
        Constant Field Values

    - #### Z_NEAR

          public static final float Z_NEAR

      See Also:
        Constant Field Values

    - #### Z_FAR

          public static final float Z_FAR

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### RenderThread

          public RenderThread(@NonNull
                              RenderView renderView)

      Constructs a new 360 video renderer.
      Parameters:
        `renderView` - reference the surface view that owns this render thread.
      Throws:
        `java.lang.NullPointerException` - if the render view is null.

  - ### Method Detail

    - #### isVrMode

          public boolean isVrMode()

      Checks whether the renderer is currently configured to render the video in Google VR mode.
      Returns:
        true if Google VR mode is enabled, otherwise false.
      See Also:
        `setVrMode(boolean)`

    - #### setVrMode

          public void setVrMode(boolean vrMode)

      Sets whether the renderer should render the video in Google VR mode.
      Parameters:
        `vrMode` - true if Google VR mode should be enabled, otherwise false.
      See Also:
        `isVrMode()`

    - #### notifySurfaceAvailable

          public void notifySurfaceAvailable(java.lang.Object surface,
                                             int width,
                                             int height)

      Notifies the video render thread that the surface is available.
      Parameters:
        `surface` - reference to a `SurfaceView` or {`TextureView`
        `width` - the width of the surface.
        `height` - the height of the surface.

    - #### notifySurfaceChanged

          public void notifySurfaceChanged(android.view.Surface surface,
                                           int width,
                                           int height)

      Notifies the video render thread that the surface has changed.
      Parameters:
        `surface` - reference to a `SurfaceView` or {`TextureView`
        `width` - the new width of the surface.
        `height` - the new height of the surface.

    - #### notifySurfaceDestroyed

          public void notifySurfaceDestroyed()

      Notifies the video render thread that the surface has been destroyed.

    - #### start

          public void start()

      Starts the render thread to run asynchronously. Overrides the base implementation to
      Overrides:
        `start` in class `java.lang.Thread`

    - #### getVideoDecodeSurface

          public android.view.Surface getVideoDecodeSurface()

      Creates a new `Surface` that will be used to render the 360 video.
      Returns:
        reference to the surface.
      Throws:
        `java.lang.IllegalStateException` - exception if the surface cannot be created.

    - #### setOnFrameAvailableListener

          public void setOnFrameAvailableListener(android.graphics.SurfaceTexture.OnFrameAvailableListener onFrameAvailableListener)