Agora Java API Reference for Android
Public Member Functions | Protected Member Functions | List of all members
io.agora.rtc.mediaio.AgoraTextureView Class Reference
Inheritance diagram for io.agora.rtc.mediaio.AgoraTextureView:
io.agora.rtc.mediaio.IVideoSink io.agora.rtc.mediaio.IVideoFrameConsumer

Public Member Functions

 AgoraTextureView (Context context)
 
 AgoraTextureView (Context context, AttributeSet attrs)
 
void init (EglBase.Context sharedContext)
 
void init (final EglBase.Context sharedContext, final int[] configAttributes, RendererCommon.GlDrawer drawer)
 
long getEGLContextHandle ()
 
void setBufferType (MediaIO.BufferType bufferType)
 
void setPixelFormat (MediaIO.PixelFormat pixelFormat)
 
void setMirror (final boolean mirror)
 
boolean onInitialize ()
 
boolean onStart ()
 
void onStop ()
 
void onDispose ()
 
void consumeTextureFrame (int texId, int format, int width, int height, int rotation, long ts, float[] matrix)
 
void consumeByteBufferFrame (ByteBuffer buffer, int format, int width, int height, int rotation, long ts)
 
void consumeByteArrayFrame (byte[] data, int format, int width, int height, int rotation, long ts)
 
int getBufferType ()
 
int getPixelFormat ()
 
void onSurfaceTextureAvailable (SurfaceTexture surface, int width, int height)
 
void onSurfaceTextureSizeChanged (SurfaceTexture surface, int width, int height)
 
boolean onSurfaceTextureDestroyed (SurfaceTexture surface)
 
void onSurfaceTextureUpdated (SurfaceTexture surface)
 

Protected Member Functions

void onLayout (boolean changed, int left, int top, int right, int bottom)
 

Detailed Description

AgoraTextureView inherits TextureView and implements the IVideoSink interface to render video frames in YUV, RGB, and Texture (2D/OES).

Member Function Documentation

◆ init() [1/2]

void io.agora.rtc.mediaio.AgoraTextureView.init ( EglBase.Context  sharedContext)

Initialize this class, sharing resources with |sharedContext|. It is allowed to call init() to reinitialize the renderer after a previous init()/release() cycle.

◆ init() [2/2]

void io.agora.rtc.mediaio.AgoraTextureView.init ( final EglBase.Context  sharedContext,
final 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.

◆ getEGLContextHandle()

long io.agora.rtc.mediaio.AgoraTextureView.getEGLContextHandle ( )

Gets EGLContextHandle.

This callback returns the native handle of EGLContext if you use OpenGL and have your own EGLContext. You can share your EGLContext using the Texture ID returned by the SDK in your own EGLContext. If you do not have EGLContext, this callback returns 0; if the buffer type is set to Texture, the media engine creates EGLContext internally and return the Texture ID.

Returns
EGLContext

Implements io.agora.rtc.mediaio.IVideoSink.

◆ onInitialize()

boolean io.agora.rtc.mediaio.AgoraTextureView.onInitialize ( )

Initializes the video sink.

This callback initializes the video sink. You can also initialize the video sink before calling this callback and return @ true to the media engine in this callback. You need to pass true or false in this callback to tell the media engine if the video sink is initialized.

Returns
Pass one of the following return values to the media engine:
  • true: If the video sink is initialized.
  • false: If the video sink is not ready or fails to initialize, the media engine stops and reports the error.

Implements io.agora.rtc.mediaio.IVideoSink.

◆ onStart()

boolean io.agora.rtc.mediaio.AgoraTextureView.onStart ( )

Enables the video sink.

This SDK triggers this callback when the media engine starts streaming.

Returns
  • true: If the video sink is ready.
  • false: If the video sink is not ready.

Implements io.agora.rtc.mediaio.IVideoSink.

◆ onStop()

void io.agora.rtc.mediaio.AgoraTextureView.onStop ( )

Stops the video sink.

The SDK triggers this callback when the media engine stops video streaming. You should then stop the video sink.

Implements io.agora.rtc.mediaio.IVideoSink.

◆ onDispose()

void io.agora.rtc.mediaio.AgoraTextureView.onDispose ( )

Releases the video source.

The SDK triggers this callback when the media engine wants to release the video sink.

Implements io.agora.rtc.mediaio.IVideoSink.

◆ consumeTextureFrame()

void io.agora.rtc.mediaio.AgoraTextureView.consumeTextureFrame ( int  textureId,
int  format,
int  width,
int  height,
int  rotation,
long  timestamp,
float []  matrix 
)

Receives the video frame in texture.

Parameters
textureIdID of the texture
formatPixel format of the video frame:
widthWidth of the video frame
heightHeight of the video frame
rotationClockwise rotating angle (0, 90, 180, and 270 degrees) of the video frame
timestampTimestamp of the video frame. For each video frame, you need to set a timestamp
matrixMatrix of the texture. The float value is between 0 and 1, such as 0.1, 0.2, and so on

Implements io.agora.rtc.mediaio.IVideoFrameConsumer.

◆ consumeByteBufferFrame()

void io.agora.rtc.mediaio.AgoraTextureView.consumeByteBufferFrame ( ByteBuffer  buffer,
int  format,
int  width,
int  height,
int  rotation,
long  timestamp 
)

Receives the video frame in a byte buffer.

Parameters
bufferVideo in the format of ByteBuffer
formatPixel format of the video frame:
widthWidth of the video frame
heightHeight of the video frame
rotationClockwise rotating angle (0, 90, 180, and 270 degrees) of the video frame
timestampTimestamp of the video frame. For each video frame, you need to set a timestamp

Implements io.agora.rtc.mediaio.IVideoFrameConsumer.

◆ consumeByteArrayFrame()

void io.agora.rtc.mediaio.AgoraTextureView.consumeByteArrayFrame ( byte []  data,
int  format,
int  width,
int  height,
int  rotation,
long  timestamp 
)

Receives the video frame in a byte array.

Parameters
dataVideo in the format of ByteArray
formatPixel format of the video frame:
widthWidth of the video frame
heightHeight of the video frame
rotationClockwise rotating angle (0, 90, 180, and 270 degrees) of the video frame
timestampTimestamp of the video frame. For each video frame, you need to set a timestamp

Implements io.agora.rtc.mediaio.IVideoFrameConsumer.

◆ getBufferType()

int io.agora.rtc.mediaio.AgoraTextureView.getBufferType ( )

Gets the buffer type.

The SDK triggers this callback to get the buffer type of the video frame when it is being initialized. You need to specify one buffer type and then pass it to the media engine.

Returns
Video buffer type

Implements io.agora.rtc.mediaio.IVideoSink.

◆ getPixelFormat()

int io.agora.rtc.mediaio.AgoraTextureView.getPixelFormat ( )

Gets the pixel format.

The SDK triggers this callback to get the pixel format of the video frame when it is being initialized. You need to specify one pixel format and then pass it to the media engine. Choose the YUV (YUV420P) or RGBA format if the custom sink expects ByteArray or ByteBuffer; choose Texture of the custom expects textured frames.

Returns
Pixel format

Implements io.agora.rtc.mediaio.IVideoSink.