SurfaceTextureHelper

tee3.webrtc

## 类 SurfaceTextureHelper

- java.lang.Object
- - tee3.webrtc.SurfaceTextureHelper

-     public class SurfaceTextureHelper
      extends java.lang.Object

  Helper class to create and synchronize access to a SurfaceTexture. The caller will get notified of new frames in onTextureFrameAvailable(), and should call returnTextureFrame() when done with the frame. Only one texture frame can be in flight at once, so returnTextureFrame() must be called in order to receive a new frame. Call stopListening() to stop receiveing new frames. Call dispose to release all resources once the texture frame is returned. Note that there is a C++ counter part of this class that optionally can be used. It is used for wrapping texture frames into webrtc::VideoFrames and also handles calling returnTextureFrame() when the webrtc::VideoFrame is no longer used.

- - ### 嵌套类概要

    嵌套类
    限定符和类型 | 类和说明
    --- | ---
    `static interface` | `SurfaceTextureHelper.OnTextureFrameAvailableListener` Callback interface for being notified that a new texture frame is available.

  - ### 方法概要

    所有方法 静态方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `static SurfaceTextureHelper` | `create(java.lang.String threadName, EglBase.Context sharedContext)` Construct a new SurfaceTextureHelper sharing OpenGL resources with |sharedContext|.
    `VideoFrame.TextureBuffer` | `createTextureBuffer(int width, int height, android.graphics.Matrix transformMatrix)` Creates a VideoFrame buffer backed by this helper's texture.
    `void` | `dispose()` Call disconnect() to stop receiving frames.
    `android.os.Handler` | `getHandler()` Retrieve the handler that calls onTextureFrameAvailable().
    `android.graphics.SurfaceTexture` | `getSurfaceTexture()` Retrieve the underlying SurfaceTexture.
    `boolean` | `isTextureInUse()`
    `void` | `returnTextureFrame()` Call this function to signal that you are done with the frame received in onTextureFrameAvailable().
    `void` | `startListening(SurfaceTextureHelper.OnTextureFrameAvailableListener listener)` Start to stream textures to the given |listener|.
    `void` | `stopListening()` Stop listening.
    `VideoFrame.I420Buffer` | `textureToYuv(VideoFrame.TextureBuffer textureBuffer)` Posts to the correct thread to convert |textureBuffer| to I420.

    - ### 从类继承的方法 java.lang.Object

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

- - ### 方法详细资料

    - #### create

          public static SurfaceTextureHelper create(java.lang.String threadName,
                                                    EglBase.Context sharedContext)

      Construct a new SurfaceTextureHelper sharing OpenGL resources with |sharedContext|. A dedicated thread and handler is created for handling the SurfaceTexture. May return null if EGL fails to initialize a pixel buffer surface and make it current.

    - #### startListening

          public void startListening(SurfaceTextureHelper.OnTextureFrameAvailableListener listener)

      Start to stream textures to the given |listener|. If you need to change listener, you need to call stopListening() first.

    - #### stopListening

          public void stopListening()

      Stop listening. The listener set in startListening() is guaranteded to not receive any more onTextureFrameAvailable() callbacks after this function returns.

    - #### getSurfaceTexture

          public android.graphics.SurfaceTexture getSurfaceTexture()

      Retrieve the underlying SurfaceTexture. The SurfaceTexture should be passed in to a video producer such as a camera or decoder.

    - #### getHandler

          public android.os.Handler getHandler()

      Retrieve the handler that calls onTextureFrameAvailable(). This handler is valid until dispose() is called.

    - #### returnTextureFrame

          public void returnTextureFrame()

      Call this function to signal that you are done with the frame received in onTextureFrameAvailable(). Only one texture frame can be in flight at once, so you must call this function in order to receive a new frame.

    - #### isTextureInUse

          public boolean isTextureInUse()

    - #### dispose

          public void dispose()

      Call disconnect() to stop receiving frames. OpenGL resources are released and the handler is stopped when the texture frame has been returned by a call to returnTextureFrame(). You are guaranteed to not receive any more onTextureFrameAvailable() after this function returns.

    - #### textureToYuv

          public VideoFrame.I420Buffer textureToYuv(VideoFrame.TextureBuffer textureBuffer)

      Posts to the correct thread to convert |textureBuffer| to I420.

    - #### createTextureBuffer

          public VideoFrame.TextureBuffer createTextureBuffer(int width,
                                                              int height,
                                                              android.graphics.Matrix transformMatrix)

      Creates a VideoFrame buffer backed by this helper's texture. The |width| and |height| should match the dimensions of the data placed in the texture. The correct |transformMatrix| may be obtained from callbacks to OnTextureFrameAvailableListener. The returned TextureBuffer holds a reference to the SurfaceTextureHelper that created it. The buffer calls returnTextureFrame() when it is released.