Agora Java API Reference for Android
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
io.agora.rtc.mediaio.TextureSource Class Referenceabstract
Inheritance diagram for io.agora.rtc.mediaio.TextureSource:
io.agora.rtc.mediaio.IVideoSource io.agora.rtc.mediaio.SurfaceTextureHelper.OnTextureFrameAvailableListener io.agora.rtc.mediaio.AgoraTextureCamera

Public Member Functions

 TextureSource (EglBase.Context sharedContext, int width, int height)
 
boolean onInitialize (IVideoFrameConsumer observer)
 
boolean onStart ()
 
void onStop ()
 
void onDispose ()
 
int getBufferType ()
 
void onTextureFrameAvailable (int oesTextureId, float[] transformMatrix, long timestampNs)
 
SurfaceTexture getSurfaceTexture ()
 
EglBase.Context getEglContext ()
 
void release ()
 

Protected Member Functions

abstract boolean onCapturerOpened ()
 
abstract boolean onCapturerStarted ()
 
abstract void onCapturerStopped ()
 
abstract void onCapturerClosed ()
 

Protected Attributes

WeakReference< IVideoFrameConsumermConsumer
 
SurfaceTextureHelper mSurfaceTextureHelper
 
int mWidth
 
int mHeight
 
int mPixelFormat
 

Detailed Description

The TextureSource interface includes SurfaceTextureHelper and IVideoFrameConsumer methods to implement customized textured video source operations.

SurfaceTexture can be created by SurfaceTextureHelper, and used to capture a video frame and convert it into a texture to be sent to RtcEngine. With the TextureSource interface, you only need to care about the following:

Member Function Documentation

◆ onInitialize()

boolean io.agora.rtc.mediaio.TextureSource.onInitialize ( IVideoFrameConsumer  observer)

Initializes the video source.

You can enable the camera or initialize the video source and then pass the return value to inform the media engine whether the video source is ready.

Parameters
mConsumerThe IVideoFrameConsumer object that the media engine passes to you. You need to reserve this object, and pass the video frame to the media engine through this object once the video source is initialized.
Returns
You need to pass the return value to the media engine to inform it if the video source is ready:
  • true: The external video source is initialized.
  • false: The external video source is not ready or fails to be initialized; the media engine stops and reports the error.

Implements io.agora.rtc.mediaio.IVideoSource.

◆ onStart()

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

Enables the video source.

The SDK triggers this callback when the underlying media engine is ready to start video streaming. You should start the video source to capture the video frame. Once the frame is ready, use IVideoFrameConsumer to consume the video frame.

Returns
You need to pass the return value to the media engine to inform it if the video source is enabled:
  • true: The external video source is enabled and IVideoFrameConsumer is called to receive video frames.
  • false: The external video source is not ready or fails to be enabled; the media engine stops and reports the error.

Implements io.agora.rtc.mediaio.IVideoSource.

◆ onStop()

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

Stops the video source.

The SDK triggers this callback when the media engine stops streaming. You should then stop capturing and consuming the video frame. After calling this method, the video frames are discarded by the media engine.

Implements io.agora.rtc.mediaio.IVideoSource.

◆ onDispose()

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

Releases the video source.

The SDK triggers this callback when IVideoFrameConsumer is released by the media engine. You can now release the video source as well as IVideoFrameconsumer.

Implements io.agora.rtc.mediaio.IVideoSource.

◆ getBufferType()

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

Gets the buffer type.

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

Returns
AgoraVideoFrame.BUFFER_TYPE_TEXTURE

Implements io.agora.rtc.mediaio.IVideoSource.

◆ onTextureFrameAvailable()

void io.agora.rtc.mediaio.TextureSource.onTextureFrameAvailable ( int  oesTextureId,
float []  transformMatrix,
long  timestampNs 
)

Monitors SurfaceTexture.

This method creates a listener to monitor the new video frame of SurfaceTexture, and starts or ends monitoring by calling startListening or stopListening.

Implements io.agora.rtc.mediaio.SurfaceTextureHelper.OnTextureFrameAvailableListener.

◆ getSurfaceTexture()

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

Gets SurfaceTexture.

This method gets the created texture. If you are in the GL environment or a thread is required, call getEglContext and getHandler.

Returns
The created texture.

◆ getEglContext()

EglBase.Context io.agora.rtc.mediaio.TextureSource.getEglContext ( )

Gets EGLContextHandle.

The SDK triggers this callback to return the native handle of EGLContext if you are using OpenGL and have your own EGLContxt. You can share your EGLContext using the Texture ID returned by the SDK in your own EGLContext.

Returns
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 returns the Texture ID.

◆ release()

void io.agora.rtc.mediaio.TextureSource.release ( )

Releases SurfaceTexture.

Call this method to release relevant resources when SurfaceTexture is no longer needed.