Agora Java API Reference for Android

Public Member Functions | Public Attributes | List of all members
io.agora.rtc2.video.IVideoFrameObserver Interface Reference

## Public Member Functions
boolean | onCaptureVideoFrame (int sourceType, VideoFrame videoFrame)
boolean | onPreEncodeVideoFrame (int sourceType, VideoFrame videoFrame)
boolean | onMediaPlayerVideoFrame (VideoFrame videoFrame, int mediaPlayerId)
int | getVideoFrameProcessMode ()
int | getVideoFormatPreference ()
boolean | getRotationApplied ()
boolean | getMirrorApplied ()
int | getObservedFramePosition ()
boolean | onRenderVideoFrame (String channelId, int uid, VideoFrame videoFrame)

## Public Attributes
int | PROCESS_MODE_READ_ONLY = 0
int | PROCESS_MODE_READ_WRITE = 1
int | POSITION_POST_CAPTURER = 1
int | POSITION_PRE_RENDERER = 1 << 1
int | POSITION_PRE_ENCODER = 1 << 2
int | VIDEO_PIXEL_DEFAULT = 0
int | VIDEO_PIXEL_I420 = 1
int | VIDEO_PIXEL_BGRA = 2
int | VIDEO_PIXEL_NV21 = 3
int | VIDEO_PIXEL_RGBA = 4
int | VIDEO_PIXEL_NV12 = 8
int | VIDEO_TEXTURE_2D = 10
int | VIDEO_TEXTURE_OES = 11
int | VIDEO_PIXEL_I422 = 16

## Member Function Documentation

## ◆ onCaptureVideoFrame()

boolean io.agora.rtc2.video.IVideoFrameObserver.onCaptureVideoFrame | ( | int | sourceType,
|  | VideoFrame | videoFrame
| ) |  |

Occurs each time the SDK receives a video frame captured by the local camera.

After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is received. In this callback, you can get the video data captured by the local camera. You can then pre-process the data according to your scenarios.

After pre-processing, you can send the processed video data back to the SDK by setting the `videoFrame` parameter in this callback.

Note
  This callback does not support sending processed RGBA video data back to the SDK.

Parameters

  sourceType | - The video source type.
  videoFrame | A pointer to the video frame.

Returns
  Determines whether to ignore the current video frame if the pre-processing fails:
  - true: Do not ignore.
  - false: Ignore, in which case this method does not send the current video frame to the SDK.

## ◆ onPreEncodeVideoFrame()

boolean io.agora.rtc2.video.IVideoFrameObserver.onPreEncodeVideoFrame | ( | int | sourceType,
|  | VideoFrame | videoFrame
| ) |  |

Occurs each time the SDK receives a video frame before encoding.

After you successfully register the video frame observer, the SDK triggers this callback each time when it receives a video frame. In this callback, you can get the video data before encoding. You can then process the data according to your particular scenarios.

After processing, you can send the processed video data back to the SDK by setting the `videoFrame` parameter in this callback.

The video data that this callback gets has been pre-processed, with its content cropped, rotated, and the image enhanced.

Parameters

  sourceType | - The video source type.
  videoFrame | A pointer to the video frame: VideoFrame

Returns
  Determines whether to ignore the current video frame if the pre-processing fails:
  - true: Do not ignore.
  - false: Ignore, in which case this method does not sent the current video frame to the SDK.

## ◆ onMediaPlayerVideoFrame()

boolean io.agora.rtc2.video.IVideoFrameObserver.onMediaPlayerVideoFrame | ( | VideoFrame | videoFrame,
|  | int | mediaPlayerId
| ) |  |

Occurs each time the SDK receives a video frame decoded by the MediaPlayer.

After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is decoded. In this callback, you can get the video data decoded by the MediaPlayer. You can then pre-process the data according to your scenarios.

After pre-processing, you can send the processed video data back to the SDK by setting the `videoFrame` parameter in this callback.

Note
  - This callback will not be affected by the return values of getVideoFrameProcessMode, getRotationApplied, getMirrorApplied, getObservedFramePosition.
  - On Android, this callback is not affected by the return value of getVideoFormatPreference

Parameters

  videoFrame | A pointer to the video frame: VideoFrame
  mediaPlayerId | of the mediaPlayer.

Returns
  Determines whether to ignore the current video frame if the pre-processing fails:
  - true: Do not ignore.
  - false: Ignore, in which case this method does not sent the current video frame to the SDK.

## ◆ getVideoFrameProcessMode()

int io.agora.rtc2.video.IVideoFrameObserver.getVideoFrameProcessMode | ( |  | ) |

Indicate the video frame mode of the observer.

Returns
  PROCESS_MODE_READ_ONLY or PROCESS_MODE_READ_WRITE

## ◆ getRotationApplied()

boolean io.agora.rtc2.video.IVideoFrameObserver.getRotationApplied | ( |  | ) |

Occurs each time needs to get rotation angle.

Returns
  rotation angle.

## ◆ getMirrorApplied()

boolean io.agora.rtc2.video.IVideoFrameObserver.getMirrorApplied | ( |  | ) |

Occurs each time needs to get whether mirror is applied or not.

Returns
  Determines whether to mirror.
  - true: need to mirror.
  - false: no mirror.

## ◆ getObservedFramePosition()

int io.agora.rtc2.video.IVideoFrameObserver.getObservedFramePosition | ( |  | ) |

Sets the frame position for the video observer.

After you successfully register the video observer, the SDK triggers this callback each time it receives a video frame. You can determine which position to observe by setting the return value. The SDK provides 3 positions for observer. Each position corresponds to a callback function:

POSITION_POST_CAPTURER(1 << 0): The position after capturing the video data, which corresponds to the onCaptureVideoFrame callback. POSITION_PRE_RENDERER(1 << 1): The position before receiving the remote video data, which corresponds to the onRenderVideoFrame callback. POSITION_PRE_ENCODER(1 << 2): The position before encoding the video data, which corresponds to the onPreEncodeVideoFrame callback.

To observe multiple frame positions, use '|' (the OR operator). This callback observes POSITION_POST_CAPTURER(1 << 0) and POSITION_PRE_RENDERER(1 << 1) by default. To conserve the system consumption, you can reduce the number of frame positions that you want to observe.

Returns
  A bit mask that controls the frame position of the video observer: VIDEO_OBSERVER_POSITION.

## ◆ onRenderVideoFrame()

boolean io.agora.rtc2.video.IVideoFrameObserver.onRenderVideoFrame | ( | String | channelId,
|  | int | uid,
|  | VideoFrame | videoFrame
| ) |  |

Occurs each time the SDK receives a video frame sent by the remote user.

After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is received. In this callback, you can get the video data sent by the remote user. You can then post-process the data according to your scenarios.

After post-processing, you can send the processed data back to the SDK by setting the `videoFrame` parameter in this callback.

Note
  This callback does not support sending processed RGBA video data back to the SDK.

Parameters

  channelId | Channel name.
  uid | ID of the remote user who sends the current video frame.
  videoFrame | A pointer to the video frame.

Returns
  Determines whether to ignore the current video frame if the post-processing fails:
  - true: Do not ignore.
  - false: Ignore, in which case this method does not send the current video frame to the SDK.

## Member Data Documentation

## ◆ PROCESS_MODE_READ_ONLY

int io.agora.rtc2.video.IVideoFrameObserver.PROCESS_MODE_READ_ONLY = 0

Observer works as a pure renderer and will not modify the original frame.

## ◆ PROCESS_MODE_READ_WRITE

int io.agora.rtc2.video.IVideoFrameObserver.PROCESS_MODE_READ_WRITE = 1

Observer works as a filter that will process the video frame and affect the following frame processing in SDK.

## ◆ POSITION_POST_CAPTURER

int io.agora.rtc2.video.IVideoFrameObserver.POSITION_POST_CAPTURER = 1

The position after capturing the video data, which corresponds to the onCaptureVideoFrame callback.

## ◆ POSITION_PRE_RENDERER

int io.agora.rtc2.video.IVideoFrameObserver.POSITION_PRE_RENDERER = 1 << 1

The position before receiving the remote video data, which corresponds to the onRenderVideoFrame callback.

## ◆ POSITION_PRE_ENCODER

int io.agora.rtc2.video.IVideoFrameObserver.POSITION_PRE_ENCODER = 1 << 2

The position before encoding the video data, which corresponds to the onPreEncodeVideoFrame callback.

## ◆ VIDEO_PIXEL_DEFAULT

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_DEFAULT = 0

0: Default format.

## ◆ VIDEO_PIXEL_I420

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_I420 = 1

1: I420.

## ◆ VIDEO_PIXEL_BGRA

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_BGRA = 2

2: BGRA.

## ◆ VIDEO_PIXEL_NV21

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_NV21 = 3

3: NV21.

## ◆ VIDEO_PIXEL_RGBA

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_RGBA = 4

4: RGBA.

## ◆ VIDEO_PIXEL_NV12

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_NV12 = 8

8: NV12.

## ◆ VIDEO_TEXTURE_2D

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_TEXTURE_2D = 10

10: GL_TEXTURE_2D

## ◆ VIDEO_TEXTURE_OES

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_TEXTURE_OES = 11

11: GL_TEXTURE_OES

## ◆ VIDEO_PIXEL_I422

int io.agora.rtc2.video.IVideoFrameObserver.VIDEO_PIXEL_I422 = 16

16: I422.