Agora Java API Reference for Android
Classes | Public Member Functions | Static Public Member Functions | List of all members
io.agora.rtc.mediaio.SurfaceTextureHelper Class Reference

Classes

interface  OnTextureFrameAvailableListener
 

Public Member Functions

EglBase.Context getEglContext ()
 
void startListening (final OnTextureFrameAvailableListener listener)
 
void stopListening ()
 
SurfaceTexture getSurfaceTexture ()
 
Handler getHandler ()
 
void returnTextureFrame ()
 
boolean isTextureInUse ()
 
void dispose ()
 
VideoFrame.I420Buffer textureToYuv (final VideoFrame.TextureBuffer textureBuffer)
 
VideoFrame.TextureBuffer createTextureBuffer (int width, int height, Matrix transformMatrix)
 

Static Public Member Functions

static SurfaceTextureHelper create (final String threadName, final EglBase.Context sharedContext)
 

Detailed Description

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.

Member Function Documentation

◆ create()

static SurfaceTextureHelper io.agora.rtc.mediaio.SurfaceTextureHelper.create ( final String  threadName,
final EglBase.Context  sharedContext 
)
static

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()

void io.agora.rtc.mediaio.SurfaceTextureHelper.startListening ( final OnTextureFrameAvailableListener  listener)

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

◆ stopListening()

void io.agora.rtc.mediaio.SurfaceTextureHelper.stopListening ( )

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

◆ getSurfaceTexture()

SurfaceTexture io.agora.rtc.mediaio.SurfaceTextureHelper.getSurfaceTexture ( )

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

◆ getHandler()

Handler io.agora.rtc.mediaio.SurfaceTextureHelper.getHandler ( )

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

◆ returnTextureFrame()

void io.agora.rtc.mediaio.SurfaceTextureHelper.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.

◆ dispose()

void io.agora.rtc.mediaio.SurfaceTextureHelper.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()

VideoFrame.I420Buffer io.agora.rtc.mediaio.SurfaceTextureHelper.textureToYuv ( final VideoFrame.TextureBuffer  textureBuffer)

Posts to the correct thread to convert |textureBuffer| to I420. Must only be called with textures generated by this SurfaceTextureHelper.

◆ createTextureBuffer()

VideoFrame.TextureBuffer io.agora.rtc.mediaio.SurfaceTextureHelper.createTextureBuffer ( int  width,
int  height,
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.