IVideoFrameObserver

The IVideoFrameObserver class.

You can call RegisterVideoFrameObserver to register or unregister an IVideoFrameObserver object.

FGetMirrorApplied

Occurs each time the SDK receives a video frame and prompts you whether or not to mirror the captured video.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGetMirrorApplied);

If the video data you want to obtain is a mirror image of the original video, you need to register this callback when calling RegisterVideoFrameObserver. After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. You need to set whether or not to mirror the video frame in the return value of this callback.

Attention:
  • This function only supports video data in RGBA and YUV420.
  • Both this method and the SetVideoEncoderConfiguration method support setting the mirroring effect. Agora recommends that you only choose one method to set it up. Using both methods at the same time causes the mirroring effect to overlap, and the mirroring settings fail.

Returns

Sets whether or not to mirror the captured video:
  • true: Mirror the captured video.
  • false: (Default) Do not mirror the captured video.

FGetObservedFramePosition

Sets the frame position for the video observer.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGetObservedFramePosition);

After successfully registering the video data observer, the SDK uses this callback to determine whether to trigger FOnCaptureVideoFrame, FOnRenderVideoFrame and FOnPreEncodeVideoFrame callback at each specific video frame processing position, so that you can observe the locally collected video data, the video data sent by the remote end, and the video data before encoding. You can set one or more positions you need to observe by modifying the return value according to your scenario:

  • POSITION_POST_CAPTURER(1 << 0): The position after capturing the video data, which corresponds to the FOnCaptureVideoFrame callback.
  • POSITION_PRE_RENDERER(1 << 1): The position of the received remote video data before rendering, which corresponds to the FOnRenderVideoFrame callback.
  • POSITION_PRE_ENCODER(1 << 2): The position before encoding the video data, which corresponds to the FOnPreEncodeVideoFrame callback.
Attention:
  • Use '|' (the OR operator) to observe multiple frame positions.
  • This callback observes POSITION_POST_CAPTURER(1 << 0) and POSITION_PRE_RENDERER(1 << 1) by default.
  • To conserve system resources, you can reduce the number of frame positions that you want to observe.
  • When the video processing mode is PROCESS_MODE_READ_WRITE and the observation position is set to POSITION_PRE_ENCODER | POSITION_POST_CAPTURER, the FGetMirrorApplied does not take effect; you need to modify the video processing mode or the position of the observer.

Returns

A bit mask that controls the frame position of the video observer.
  • POSITION_POST_CAPTURER(1 << 0): The position after capturing the video data, which corresponds to the FOnCaptureVideoFrame callback.
  • POSITION_PRE_RENDERER(1 << 1): The position of the received remote video data before rendering, which corresponds to the FOnRenderVideoFrame callback.
  • POSITION_PRE_ENCODER(1 << 2): The position before encoding the video data, which corresponds to the FOnPreEncodeVideoFrame callback.

FGetRotationApplied

Occurs each time the SDK receives a video frame, and prompts you whether to rotate the captured video.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGetRotationApplied);

If you want to rotate the captured video according to the rotation member in the FVideoFrame class, ensure that you register this callback when calling RegisterVideoFrameObserver. After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. You need to set whether to rotate the video frame in the return value of this callback.

Attention:
  • This function only applies to the scenarios where the video processing mode is PROCESS_MODE_READ_ONLY.
  • This function only supports video data in RGBA and YUV420.

Returns

Sets whether to rotate the captured video:
  • true: Rotate the captured video.
  • false: (Default) Do not rotate the captured video.

FGetVideoFormatPreference

Sets the format of the raw video data output by the SDK.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGetVideoFormatPreference);

You need to register the callback when calling the RegisterVideoFrameObserver method. After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. You need to set your preferred video data in the return value of this callback.

Note: The default types of pixel format (VIDEO_PIXEL_DEFAULT) for the raw video are as follows:
  • On the Android platform, the default video frame type may be I420Buffer or TextureBuffer. As of v4.2.3, the texture formats of TextureBuffer type no longer include OES format, only RGB format is available. You need to add support for I420 and RGB texture formats when processing video data. The cases where the video frame type is fixed as I420Buffer include but are not limited to:
    • Specific devices, such as: LG G5 SE (H848), Google Pixel 4a, Samsung Galaxy A7, or Xiaomi Mi Max.
    • Image enhancement extension has been integrated and video noise reduction or low-light enhancement function has been enabled.
  • On iOS and macOS platforms, the default video frame type may be I420 or CVPixelBufferRef.
  • On Windows platforms, the default video frame type is YUV420.

Returns

Sets the raw data format of the SDK output. See EVIDEO_PIXEL_FORMAT.

FGetVideoFrameProcessMode

Occurs each time the SDK receives a video frame and prompts you to set the process mode of the video frame.

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FGetVideoFrameProcessMode);

After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. You need to set your preferred process mode in the return value of this callback.

Returns

The process mode of the video frame:
  • PROCESS_MODE_READ_ONLY(0): (Default) Only reads the video frame.
  • PROCESS_MODE_READ_WRITE(1): Reads and writes the video frame.

FOnCaptureVideoFrame

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

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnCaptureVideoFrame, EVIDEO_SOURCE_TYPE, sourceType, const FVideoFrame&, videoFrame);

You can get raw video data collected by the local device through this callback and preprocess it as needed. Once the preprocessing is complete, you can directly modify videoFrame in this callback, and set the return value to true to send the modified video data to the SDK.

If you need to send the preprocessed data to the SDK, you need to call FGetVideoFrameProcessMode(0) first to set the video processing mode to read and write mode.

Applicable scenarios

  • Preprocess the locally collected video data before it is processed by the SDK. For example, get video data through this callback and process it with filters, watermarks, cropping, rotation, etc.
  • Get information about the locally collected video data before it is processed by the SDK. For example, the original width, height, frame rate of the video frame, etc.

Trigger timing

After the successful registration of the video data observer, each time the SDK captures a video frame.

Restrictions

  • The video data you get here is the raw video data, that is, video data that has not undergone preprocessing such as watermarking, cropping, and rotation.
  • If the video data type you get is RGBA, the SDK does not support processing the data of the alpha channel.

Parameters

sourceType
Video source types, including cameras, screens, or media player. See EVIDEO_SOURCE_TYPE.
videoFrame
The video frame. See FVideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420

Returns

  • When the video processing mode is PROCESS_MODE_READ_ONLY:
    • true: Reserved for future use.
    • false: Reserved for future use.
  • When the video processing mode is PROCESS_MODE_READ_WRITE:
    • true: Sets the SDK to receive the video frame.
    • false: Sets the SDK to discard the video frame.

FOnFrame

Occurs each time the player receives a video frame.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnFrame, const FAudioPcmFrame&, pcmFrame);

After registering the video frame observer, the callback occurs every time the player receives a video frame, reporting the detailed information of the video frame.

Parameters

frame
The video frame information. See FVideoFrame.

FOnPreEncodeVideoFrame

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

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnPreEncodeVideoFrame, EVIDEO_SOURCE_TYPE, sourceType, const FVideoFrame&, videoFrame);

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

After processing, you can send the processed video data back to the SDK in this callback.

Attention:
  • To get the video data captured from the second screen before encoding, you need to set POSITION_PRE_ENCODER (1 << 2) as a frame position through FGetObservedFramePosition.
  • The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.

Parameters

sourceType

The type of the video source. See EVIDEO_SOURCE_TYPE.

videoFrame
The video frame. See FVideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420

Returns

  • When the video processing mode is PROCESS_MODE_READ_ONLY:
    • true: Reserved for future use.
    • false: Reserved for future use.
  • When the video processing mode is PROCESS_MODE_READ_WRITE:
    • true: Sets the SDK to receive the video frame.
    • false: Sets the SDK to discard the video frame.

FOnRenderVideoFrame

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

DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnRenderVideoFrame, const FString, channelId, int64, remoteUid, const FVideoFrame&, videoFrame);

After you successfully register the video frame observer, the SDK triggers this callback each time it receives a video frame. In this callback, you can get the video data sent from the remote end before rendering, and then process it according to the particular scenarios.

Attention:
  • If the video data type you get is RGBA, the SDK does not support processing the data of the alpha channel.

Parameters

remoteUid
The user ID of the remote user who sends the current video frame.
videoFrame
The video frame. See FVideoFrame.
Note: The default value of the video frame data format obtained through this callback is as follows:
  • Android: I420 or RGB (GLES20.GL_TEXTURE_2D)
  • iOS: I420 or CVPixelBufferRef
  • macOS: I420 or CVPixelBufferRef
  • Windows: YUV420
channelId
The channel ID.

Returns

  • When the video processing mode is PROCESS_MODE_READ_ONLY:
    • true: Reserved for future use.
    • false: Reserved for future use.
  • When the video processing mode is PROCESS_MODE_READ_WRITE:
    • true: Sets the SDK to receive the video frame.
    • false: Sets the SDK to discard the video frame.

VIDEO_FRAME_PROCESS_MODE

The process mode of the video frame:

Enumerator

PROCESS_MODE_READ_ONLY

Read-only mode.

In this mode, you do not modify the video frame. The video frame observer is a renderer.

PROCESS_MODE_READ_WRITE

Read and write mode.

In this mode, you modify the video frame. The video frame observer is a video filter.