IVideoFrameObserver
The IVideoFrameObserver class.
You can call registerVideoFrameObserver to register or unregister an IVideoFrameObserver object.
getMirrorApplied
Occurs each time the SDK receives a video frame and prompts you whether or not to mirror the captured video.
virtual bool getMirrorApplied() { return false; }
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.
Returns
true
: Mirror the captured video.false
: (Default) Do not mirror the captured video.
getObservedFramePosition
Sets the frame position for the video observer.
virtual uint32_t getObservedFramePosition() { return base::POSITION_POST_CAPTURER | base::POSITION_PRE_RENDERER; }
After successfully registering the video data observer, the SDK uses this callback to determine whether to trigger onCaptureVideoFrame , onRenderVideoFrame and onPreEncodeVideoFrame 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 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.
- Use '|' (the OR operator) to observe multiple frame positions.
- This callback observesPOSITION_POST_CAPTURER (1 << 0) andPOSITION_PRE_RENDERER (1 << 1) by default.
- To conserve the system consumption, 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 getMirrorApplied 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. See VIDEO_MODULE_POSITION.
getRotationApplied
Occurs each time the SDK receives a video frame, and prompts you whether to rotate the captured video.
virtual bool getRotationApplied() { return false; }
If you want to rotate the captured video according to the rotation member in the VideoFrame 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.
- 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 or YUV420.
Returns
true
: Rotate the captured video.false
: (Default) Do not rotate the captured video.
getVideoFormatPreference
Sets the format of the raw video data output by the SDK.
virtual VIDEO_PIXEL_FORMAT getVideoFormatPreference() { return VIDEO_PIXEL_DEFAULT; }
If you want to get raw video data in a color encoding format other than YUV 420, 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 your preferred video data in the return value of this callback.
Returns
Sets the video format. See VIDEO_PIXEL_FORMAT.
getVideoFrameProcessMode
Occurs each time the SDK receives a video frame and prompts you to set the process mode of the video frame.
virtual VIDEO_FRAME_PROCESS_MODE getVideoFrameProcessMode() { return PROCESS_MODE_READ_ONLY; }
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
onCaptureVideoFrame
Occurs each time the SDK receives a video frame captured by the local camera.
virtual bool onCaptureVideoFrame(VideoFrame& videoFrame) = 0;
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 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 through this callback.
- The video data that this callback gets has not been pre-processed, and is not watermarked, cropped, rotated or beautified.
- If the video data type you get is RGBA, Agora does not support processing the data of the alpha channel.
Parameters
- videoFrame
- The video frame. See VideoFrame.
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.
onFrame
Occurs each time the player receives a video frame.
virtual void onFrame(const VideoFrame* frame) = 0;
public virtual bool OnFrame(VideoFrame audioFrame, VideoFrameBufferConfig config)
{
return true;
}
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 VideoFrame.
onMediaPlayerVideoFrame
Gets the video data of the media player.
virtual bool onMediaPlayerVideoFrame(VideoFrame& videoFrame, int mediaPlayerId) = 0;
After you successfully register the video frame observer and calling the createMediaPlayer method, the SDK triggers this callback each time when it receives a video frame. In this callback, you can get the video data of the media player. You can then process the data according to your particular scenarios.
After pre-processing, you can send the processed video data back to the SDK through this callback.
Parameters
- videoFrame
- The video frame. See VideoFrame.
- mediaPlayerId
- The ID of the media player.
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.
onPreEncodeVideoFrame
Occurs each time the SDK receives a video frame before encoding.
virtual bool onPreEncodeVideoFrame(VideoFrame& videoFrame) = 0;
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.
- 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 getObservedFramePosition.
- The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.
Parameters
- videoFrame
- The video frame. See VideoFrame.
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.
onPreEncodeScreenVideoFrame
Gets the video data captured from the screen before encoding.
virtual bool onPreEncodeScreenVideoFrame(VideoFrame& videoFrame) = 0;
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 captured from the screen 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.
- 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 getObservedFramePosition.
- The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.
- This callback does not support sending processed RGBA video data back to the SDK.
Parameters
- videoFrame
- The video frame. See VideoFrame.
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.
onSecondaryPreEncodeScreenVideoFrame
Gets the video data captured from the second screen before encoding.
virtual bool onSecondaryPreEncodeScreenVideoFrame(VideoFrame& videoFrame) = 0;
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 captured from the second screen 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.
- This callback is for Windows only.
- You need to set POSITION_PRE_ENCODER (1 << 2) as a frame position by getObservedFramePosition before you can get the video data captured from the second screen before encoding.
- The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.
- This callback does not support sending processed RGBA video data back to the SDK.
Parameters
- videoFrame
- The video frame. See VideoFrame.
Returns
true
: Sets the SDK to receive the video frame.false
: Sets the SDK to discard the video frame.
onSecondaryPreEncodeCameraVideoFrame
Gets the video data captured from the second camera before encoding.
virtual bool onSecondaryPreEncodeCameraVideoFrame(VideoFrame& videoFrame) = 0;
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 captured from the second camera 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.
- This callback is for Windows only.
- You need to set POSITION_PRE_ENCODER (1 << 2) as a frame position through getObservedFramePosition before you can use this callback to get the video data captured from the second screen and before encoding.
- The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.
- This callback does not support sending processed RGBA video data back to the SDK.
Parameters
- videoFrame
- The video frame. See VideoFrame.
Returns
true
: Sets the SDK to receive the video frame.false
: Sets the SDK to discard the video frame.
onScreenCaptureVideoFrame
Occurs each time the SDK receives a video frame captured by the screen.
virtual bool onScreenCaptureVideoFrame(VideoFrame& videoFrame) = 0;
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 for screen sharing. 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 through this callback.
- This callback does not support sending processed RGBA video data back to the SDK.
- The video data that this callback gets has not been pre-processed, and is not watermarked, cropped, rotated or beautified.
Parameters
- videoFrame
- The video frame. See VideoFrame.
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.
onRenderVideoFrame
Occurs each time the SDK receives a video frame sent by the remote user.
virtual bool onRenderVideoFrame(const char* channelId, rtc::uid_t remoteUid, VideoFrame& videoFrame) = 0;
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. You can then process the data according to your particular scenarios.
- If the video data type you get is RGBA, Agora does not support processing the data of the alpha channel.
- This function only applies to the scenarios where the video processing mode is PROCESS_MODE_READ_ONLY.
Parameters
- remoteUid
- The user ID of the remote user who sends the current video frame.
- videoFrame
- The video frame. See VideoFrame.
- 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.