Agora C++ API Reference for All Platforms
Classes | Public Types | Public Member Functions | List of all members
agora::media::IVideoFrameObserver Class Referenceabstract

#include <IAgoraMediaEngine.h>

Classes

struct  VideoFrame
 

Public Types

enum  VIDEO_FRAME_TYPE { FRAME_TYPE_YUV420 = 0, FRAME_TYPE_YUV422 = 1, FRAME_TYPE_RGBA = 2 }
 
enum  VIDEO_OBSERVER_POSITION { POSITION_POST_CAPTURER = 1 << 0, POSITION_PRE_RENDERER = 1 << 1, POSITION_PRE_ENCODER = 1 << 2 }
 

Public Member Functions

virtual bool onCaptureVideoFrame (VideoFrame &videoFrame)=0
 
virtual bool onPreEncodeVideoFrame (VideoFrame &videoFrame)
 
virtual bool onRenderVideoFrame (unsigned int uid, VideoFrame &videoFrame)=0
 
virtual VIDEO_FRAME_TYPE getVideoFormatPreference ()
 
virtual bool getRotationApplied ()
 
virtual bool getMirrorApplied ()
 
virtual bool getSmoothRenderingEnabled ()
 
virtual uint32_t getObservedFramePosition ()
 

Detailed Description

The IVideoFrameObserver class.

Member Enumeration Documentation

◆ VIDEO_FRAME_TYPE

The video frame type.

Enumerator
FRAME_TYPE_YUV420 

0: YUV420

FRAME_TYPE_YUV422 

1: YUV422

FRAME_TYPE_RGBA 

2: RGBA

◆ VIDEO_OBSERVER_POSITION

The frame position of the video observer.

Enumerator
POSITION_POST_CAPTURER 

1: The post-capturer position, which corresponds to the video data in the onCaptureVideoFrame callback.

POSITION_PRE_RENDERER 

2: The pre-renderer position, which corresponds to the video data in the onRenderVideoFrame callback.

POSITION_PRE_ENCODER 

4: The pre-encoder position, which corresponds to the video data in the onPreEncodeVideoFrame callback.

Member Function Documentation

◆ onCaptureVideoFrame()

virtual bool agora::media::IVideoFrameObserver::onCaptureVideoFrame ( VideoFrame videoFrame)
pure virtual

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
videoFramePointer to VideoFrame.
Returns
Whether or not to ignore the current video frame if the pre-processing fails:
  • true: Do not ignore.
  • false: Ignore the current video frame, and do not send it back to the SDK.

◆ onPreEncodeVideoFrame()

virtual bool agora::media::IVideoFrameObserver::onPreEncodeVideoFrame ( VideoFrame videoFrame)
inlinevirtual

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.

Note
  • As of v3.0.1, if you want to receive this callback, you also need to set POSITION_PRE_ENCODE(1 << 2) as a frame position in the getObservedFramePosition callback.
  • The video data that this callback gets has been pre-processed, with its content cropped, rotated, and the image enhanced.
  • This callback does not support sending processed RGBA video data back to the SDK.
Parameters
videoFrameA pointer to VideoFrame
Returns
Whether to ignore the current video frame if the processing fails:
  • true: Do not ignore the current video frame.
  • false: Ignore the current video frame, and do not send it back to the SDK.

◆ onRenderVideoFrame()

virtual bool agora::media::IVideoFrameObserver::onRenderVideoFrame ( unsigned int  uid,
VideoFrame videoFrame 
)
pure virtual

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
uidID of the remote user who sends the current video frame.
videoFramePointer to VideoFrame.
Returns
Whether or not to ignore the current video frame if the post-processing fails:
  • true: Do not ignore.
  • false: Ignore the current video frame, and do not send it back to the SDK.

◆ getVideoFormatPreference()

virtual VIDEO_FRAME_TYPE agora::media::IVideoFrameObserver::getVideoFormatPreference ( )
inlinevirtual

Occurs each time the SDK receives a video frame and prompts you to set the video format.

YUV420 is the default video format. If you want to receive other video formats, register this callback in the IVideoFrameObserver class.

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: VIDEO_FRAME_TYPE

◆ getRotationApplied()

virtual bool agora::media::IVideoFrameObserver::getRotationApplied ( )
inlinevirtual

Occurs each time the SDK receives a video frame and prompts you whether or not to rotate the captured video according to the rotation member in the VideoFrame class.

The SDK does not rotate the captured video by default. If you want to rotate the captured video according to the rotation member in the VideoFrame class, register this callback in the IVideoFrameObserver class.

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 rotate the video frame in the return value of this callback.

Note
This callback applies to RGBA video data only.
Returns
Sets whether or not to rotate the captured video:
  • true: Rotate.
  • false: (Default) Do not rotate.

◆ getMirrorApplied()

virtual bool agora::media::IVideoFrameObserver::getMirrorApplied ( )
inlinevirtual

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

The SDK does not mirror the captured video by default. Register this callback in the IVideoFrameObserver class if you want to mirror the captured video.

After you successfully register the video frame observer, the SDK triggers this callback each time a video frame is received. You need to set whether or not to mirror the captured video in the return value of this callback.

Note
This callback applies to RGBA video data only.
Returns
Sets whether or not to mirror the captured video:
  • true: Mirror.
  • false: (Default) Do not mirror.

◆ getSmoothRenderingEnabled()

virtual bool agora::media::IVideoFrameObserver::getSmoothRenderingEnabled ( )
inlinevirtual

Sets whether to output the acquired video frame smoothly.

If you want the video frames acquired from onRenderVideoFrame to be more evenly spaced, you can register the getSmoothRenderingEnabled callback in the IVideoFrameObserver class and set its return value as true.

Note
  • Register this callback before joining a channel.
  • This callback applies to scenarios where the acquired video frame is self-rendered after being processed, not to scenarios where the video frame is sent back to the SDK after being processed.
Returns
Set whether or not to smooth the video frames:
  • true: Smooth the video frame.
  • false: (Default) Do not smooth.

◆ getObservedFramePosition()

virtual uint32_t agora::media::IVideoFrameObserver::getObservedFramePosition ( )
inlinevirtual

Sets the frame position for the video observer.

Since
v3.0.1

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.
Note
  • 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 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.