Version: v2.2.3
This Java API is a data encapsulation of the C++ sample code with JNI, and is therefore slightly different from that of the C++ API in structure. The Agora SDK (sample code shared by C++ and Java) implements the C++ recording API methods and callbacks, goes through data encapsulation in the JNI layer, and then works as the Java interface and class of the Native SDK through the JNI proxy.

Interface Description
Native Interface Main methods that can be invoked by your app.
Callbacks Callbacks returned to your app.

Native Interface

The Native Interface provides main methods that can be invoked by your app.

Creates a Channel (createChannel)

This method creates a channel and enables the app to join the channel.

public native boolean createChannel(String appId, String token, String name, int uid, RecordingConfig config, int logLevel, int logModules);
名称 描述
appId The App ID used in the communication to be recorded. For details, see Getting an App ID.
token The token used in the communication to be recorded. For details, see Security Keys.
name Name of the channel to be recorded.
uid

User ID. A 32-bit unsigned integer ranging from 1 to (2^32-1) that is unique in a channel. Two Settings:

  • Set to 0, the system will automatically assign a uid.
  • Set a unique uid (cannot be repeated with any uid in the current channel).
config Detailed recording configuration. See the definition in the table below.
logLevel Generate the level of the log. After setting up, only logs with a level lower than logLevel will be generated. See Sets the Log Level (setLogLevel) .
logModules Generate the Module of the log. After setting up, only the log of the specified module will be generated. See Enables the Module Log (enableModuleLog) .
Returns:
  • 0: Success.
  • < 0: Failure.
  • In the Recording SDK, requestToken and renewToken are private interfaces. Make sure that you set expireTimestamp as 0 when generating a token, which means that the privilege, once generated, never expires.
  • A channel does not accept duplicate uids. Otherwise, there will be unpredictable behaviors.

The structure of RecordingConfig:

public class RecordingConfig {
  public RecordingConfig() {
    isAudioOnly = false;
    isVideoOnly = false;
    isMixingEnabled = false;
    mixedVideoAudio = MIXED_AV_CODEC_TYPE.MIXED_AV_DEFAULT;

    mixResolution = "";
    decryptionMode = "";
    secret = "";
    appliteDir = "";
    recordFileRootDir = "";
    cfgFilePath = "";
    proxyServer = "";
    defaultVideoBgPath = "";
    defaultUserBgPath = "";

    lowUdpPort = 0;//40000;
    highUdpPort = 0;//40004;
    idleLimitSec = 300;
    captureInterval = 5;
    triggerMode = 0;
    audioIndicationInterval = 0;
    audioProfile = 0;

    decodeVideo = VIDEO_FORMAT_TYPE.VIDEO_FORMAT_DEFAULT_TYPE;
    decodeAudio = AUDIO_FORMAT_TYPE.AUDIO_FORMAT_DEFAULT_TYPE;
    channelProfile = CHANNEL_PROFILE_TYPE.CHANNEL_PROFILE_COMMUNICATION;
    streamType = REMOTE_VIDEO_STREAM_TYPE.REMOTE_VIDEO_STREAM_HIGH;
  }

  public boolean isAudioOnly;
  public boolean isVideoOnly;
  public boolean isMixingEnabled;
  public MIXED_AV_CODEC_TYPE mixedVideoAudio;
  public String mixResolution;
  public String decryptionMode;
  public String secret;
  public String appliteDir;
  public String recordFileRootDir;
  public String cfgFilePath;
  //decodeVideo: default 0 (0:save as file, 1:h.264, 2:yuv, 3:jpg buffer, 4:jpg file, 5:jpg file and video file)
  public VIDEO_FORMAT_TYPE decodeVideo;
  //decodeAudio:  (default 0 (0:save as file, 1:aac frame, 2:pcm frame, 3:mixed pcm frame) (Can't combine with isMixingEnabled) /option)
  public AUDIO_FORMAT_TYPE decodeAudio;
  public int lowUdpPort;
  public int highUdpPort;
  public int idleLimitSec;
  public int captureInterval;
  public int audioIndicationInterval;
  //channelProfile:0 braodacast, 1:communicate; default is 1
  public CHANNEL_PROFILE_TYPE channelProfile;
  //streamType:0:get high stream 1:get low stream; default is 0
  public REMOTE_VIDEO_STREAM_TYPE streamType;
  public int triggerMode;
  public String proxyServer; //format ipv4:port
  public int audioProfile;
  public String defaultVideoBgPath;
  public String defaultUserBgPath;
}
Name Description
isAudioOnly

Sets whether or not to record audio only:

  • true: Enables audio recording only.
  • false: (Default) Records both audio and video.
isVideoOnly

Sets whether or not to record video only:

  • true: Enables video recording only.
  • false: (Default) Records both audio and video.
isMixingEnabled

Enables the audio- or video-mixing mode:

  • false: (Default) Enables the individual mode (audio). The bitrate and audio channel number of the recording file are the same as those of the original audio stream.
  • true: Enables the composite mode (video). The sample rate, bitrate, and audio channel number of the recording file are the same as the highest level of those of the original audio streams.

If the composite mode is enabled:

  • If isAudioOnly is true and isVideoOnly is false, only the audio is recorded.
  • If isAudioOnly is false and isVideoOnly is true, only the video is recorded.
  • If both isAudioOnly and isVideoOnly are false, voice and video mixing are enabled (the audio and video of all uids are recorded respectively).
  • isVideoOnly and isVideoOnly cannot be set as true at the same time.
mixedVideoAudio

If you set isMixingEnabled as true, mixedVideoAudio allows you to mix the audio and video in real time:

  • 0: (Default) Mixes the audio and video respectively.
  • 1: Mixes the audio and video in real time into an MPEG-4 file. Supports limited players.
mixResolution [1] If you set isMixingEnabled as true, mixResolution allows you to set the resolution in the format of width, height, fps, and Kbps; representing the width, height, frame rate, and bitrate of the video stream.
decryptionMode

When the whole channel is encrypted, the recording SDK uses decryptionMode to enable the built-in decryption function:

  • “aes-128-xts”: AES-128, XTS mode
  • “aes-128-ecb”: AES-128, ECB mode
  • “aes-256-xts”: AES-256, XTS mode
secret The decryption password when decryption mode is enabled. The default value is NULL.
appliteDir The directory of AgoraCoreService. The default value is NULL.
recordFilrRootDir The root directory of the recording files. The default value is NULL. The sub-path will be generated automatically.
cfgFilePath The path of the configuration file. The default value is NULL. The content in the configuration file must be in JSON format. In this configuration file, you can set the absolute path of the recording file, such as {“Recording_Dir” : “<recording path>”}, but the sub-path will not be generated automatically.
decodeAudio [2]

Audio decoding format:

  • 0: Default audio format (AUDIO_FORMAT_DEFAULT_TYPE).
  • 1: AAC format (AUDIO_FORMAT_AAC_FRAME_TYPE).
  • 2: PCM format (AUDIO_FORMAT_PCM_FRAME_TYPE).
  • 3: PCM audio-mixing format (AUDIO_FORMAT_MIXED_PCM_FRAME_TYPE).
decodeVideo [2]

Video decoding format:

  • 0: Default video format (VIDEO_FORMAT_DEFAULT_TYPE).
  • 1: H.264 format (VIDEO_FORMAT_H264_FRAME_TYPE).
  • 2: YUV format (VIDEO_FORMAT_YUV_FRAME_TYPE).
  • 3: JPEG format (VIDEO_FORMAT_JPG_FRAME_TYPE).
  • 4: JPEG file format (VIDEO_FORMAT_JPG_FILE_TYPE).
  • 5: JPEG video file format (VIDEO_FORMAT_JPG_VIDEO_FILE_TYPE).
  • Individual Mode (isMixingEnabled is set as false): MPEG-4 video and JPEG files are supported.
  • Mixing Mode (isMixingEnabled is set as true): MPEG-4 video files for combined streams and JPEG files for individual streams are supported.
lowUdpPort The lowest UDP port. The default value is 0. Ensure that the value of highUdpPort - lowUdpPort ≥ 4.
highUdpPort The highest UDP port. The default value is 0. Ensure that the value of highUdpPort - lowUdpPort ≥ 4.
idleLimitSec The Agora Recording SDK automatically stops recording when there is no user in the recorded channel after a time period of idleLimitSec. The value must be ≥ three seconds. The default value is 300 seconds.
captureInterval Time interval of the screen capture. The value ranges between one second and five seconds. You need to use captureInterval with decodeVideo = 3/4 when joining the channel. See joinChannel to allow a user to join a channel.
audioIndicationInterval

Whether or not to detect the speakers:

  • ≤ 0: Disables detecting the speakers.
  • > 0: The time interval (ms) of detecting the speakers. When an active speaker is found, the SDK returns the user ID of the speaker in the onActiveSpeaker callback.
channelProfile

Sets the channel mode:

  • 0: (Default) Communication mode (CHANNEL_PROFILE_COMMUNICATION). This is used in one-on-one or group calls, where all users in the channel can talk freely.
  • 1: Live broadcast (CHANNEL_PROFILE_LIVE_BROADCAST). The host sends and receives voice/video, while the audience only receives voice/video. Host and audience roles can be set by calling setClientRole.
The Recording SDK must use the same channel profile as the Agora Native/Web SDK, otherwise issues may occur.
streamType streamType takes effect only when the Agora Native SDK has enabled the dual-stream mode (high stream by default).
triggerMode

Sets whether to record automatically or manually upon joining the channel:

  • 0: Automatically
  • 1: Manually

If you wish to call startRecording and stopRecording, then choose Manually.

proxyserver proxyserver allows you to record the content with the Intranet server. For details, please contact sales@agora.io.
audioProfile

Audio profile of the recording file:

  • 0: (Default) Sampling rate of 48 kHz, communication encoding, mono (AUDIO_PROFILE_DEFAULT).
  • 4: Sampling rate of 48 kHz, music encoding, mono, and a bitrate of up to 128 Kbps (AUDIO_PROFILE_MUSIC_HIGH_QUALITY).
  • 5: Sampling rate of 48 kHz, music encoding, stereo, and a bitrate of up to 192 Kbps (AUDIO_PROFILE_MUSIC_HIGH_QUALITY_STEREO).
defaultVideoBgPath The default background image of the video.
defaultUserBgPath The default background image of the user.

[1] The isAudioOnly and isVideoOnly parameters are disabled by default. Do not set isAudioOnly and isVideoOnly as true at the same time.

[2] If the raw data is enabled:

  • Only audio mixing is supported. Video mixing is not supported.
  • Only raw video data in H.264 for the Web SDK is supported. VP8 is not supported.

Video Profile for the Communication Mode:

Resolution Frame Rate (fps) Minimum Bitrate (Kbps) Maximum Bitrate (Kbps) Recommended Bitrate (Kbps)
3840 × 2160 15 3000 9000 6000
2560 × 1440 15 1600 4800 3200
1920 × 1080 15 1000 3000 2000
1280 × 720 15 600 1800 1200
960 × 720 15 480 1440 960
848 × 480 15 300 900 600
640 × 480 15 250 750 500
480 × 480 15 200 600 400
640 × 360 15 200 600 400
360 × 360 15 130 390 260
424 × 240 15 110 330 220
320 × 240 15 90 270 180
240 × 240 15 70 210 140
320 × 180 15 70 210 140
240 × 180 15 60 180 120
180 × 180 15 50 150 100
160 × 120 15 30 90 60
120 × 120 15 25 75 50

Video Profile for the Live Broadcast Mode:

Resolution Frame Rate (fps) Minimum Bitrate (Kbps) Maximum Bitrate (Kbps) Recommended Bitrate (Kbps)
3840 × 2160 15 6000 18000 12000
2560 × 1440 15 3200 9600 6400
1920 × 1080 15 2000 6000 4000
1280 × 720 15 1200 3600 2400
960 × 720 15 960 2880 1920
848 × 480 15 600 1800 1200
640 × 480 15 500 1500 1000
480 × 480 15 400 1200 800
640 × 360 15 400 1200 800
360 × 360 15 260 780 520
424 × 240 15 220 660 440
320 × 240 15 180 540 360
240 × 240 15 140 420 280
320 × 180 15 140 420 280
240 × 180 15 120 360 240
180 × 180 15 100 300 200
160 × 120 15 60 180 120
120 × 120 15 50 150 100

Supported Players:

Platform Player/Explorer mixedVideoAudio=0 mixedVideoAudio=1
Linux Default Player Supported Supported
Linux VLC Media Player Supported Supported
Linux ffplay Supported Supported
Windows Media Player Supported Supported
Windows KMPlayer Supported Supported
Windows VLC Player Supported Supported
Windows Chrome (49.0.2623+) Supported Supported
macOS QuickTime Player Supported Supported
macOS Movist Supported Supported
macOS MPlayerX Supported Supported
macOS KMPlayer Not Supported Not Supported
macOS Chrome (47.0.2526.111+) Supported Supported
macOS Safari (11.0.3+) Supported Supported
iOS Default Player Supported Supported
iOS VLC Not Supported Supported
iOS KMPlayer Supported Supported
iOS Safari (9.0+) Supported Supported
Android Default Player Supported Supported
Android MXPlayer Supported Supported
Android VLC for Android Supported Supported
Android KMPlayer Supported Supported
Android Chrome (49.0.2623+) Supported Supported

Sets the Video Mixing Layout (setVideoMixingLayout)

This method sets the video mixing layout.

private native int setVideoMixingLayout(long nativeObject, VideoMixingLayout layout);

The structure of VideoMixingLayout:

public class VideoMixingLayout
{
  public int canvasWidth;
  public int canvasHeight;
  public String backgroundColor;//e.g. "#C0C0C0" in RGB
  public int regionCount;
  public Region[] regions;
  public String appData;
  public int appDataLength;
  public class Region {
    public long uid;
    public double x;//[0,1]
    public double y;//[0,1]
    public double width;//[0,1]
    public double height;//[0,1]
    public int zOrder; //optional, [0, 100] //0 (default): bottom most, 100: top most
    //Optional
    //[0, 1.0] where 0 means transparent, 1.0 means opaque
    public double alpha;
    public int renderMode;//RENDER_MODE_HIDDEN: Crop, RENDER_MODE_FIT: Zoom to fit
    public Region(){
      uid = 0;
      x = 0;
      y = 0;
      width = 0;
      height = 0;
      zOrder = 0;
      alpha = 1.0;
      renderMode = 0;
    }
  }
  public VideoMixingLayout() {
    canvasWidth = 0;
    canvasHeight = 0;
    backgroundColor = "";
    regionCount = 0;
    //regions = 0;
    appData = "";
    appDataLength = 0;
  }
}
Name Description
canvasWidth Width of the canvas (the display window or screen).
canvasHeight Height of the canvas (the display window or screen).
backgroundColor The background color of the canvas (the display window or screen) in RGB hex value.
regionCount The number of the hosts in the channel.
regions

The host list of VideoMixingLayout. Each host in the channel has a region to display the video on the screen with the following parameters to be set:

  • uid: User ID of the host displaying the video in the region.
  • x: Relative horizontal position of the top-left corner of the region. The value is between 0.0 and 1.0.
  • y: Relative vertical position of the top-left corner of the region. The value is between 0.0 and 1.0.
  • width: Relative width of the region. The value is between 0.0 and 1.0.
  • height: Actual height of the region. The value is between 0.0 and 1.0.
  • zOrder: The index of the layer. The value is between 1 (bottom layer) and 100 (top layer).
  • alpha: The transparency of the image. The value is between 0.0 (transparent) and 1.0 (opaque).
  • renderMode: Render mode:
    • 1: Cropped (RENDER_MODE_HIDDEN).
    • 2: Proportionate (RENDER_MODE_FIT).
appData User-defined data.
appDataLength The length of the user-defined data.
Returns
  • 0: Success.
  • < 0: Failure.

Here is an example to show the position and size of the host’s head portrait. x, y, width, and height are 0.5, 0.4, 0.2, and 0.3 respectively.

../_images/sei_overview.png

Allows the App to Leave the Channel (leaveChannel)

This method allows the recording app to leave the channel and release the thread resources.

private native boolean leaveChannel(long nativeObject);
Returns
  • 0: Success.
  • < 0: Failure.

Retrieves the Properties (getProperties)

This method allows you to retrieve the recording properties without joining a channel.

  • The recording properties only include the path of the recording files.
  • This method is different from onUserJoined. You must call onUserJoined after joining the channel.
private native RecordingEngineProperties getProperties(long nativeHandle);

Starts a Recording (startService)

This method manually starts a recording.

The method is only valid when you set triggerMode to 1 (manually) when joining the channel. For more information, see Creates a Channel (createChannel) on triggerMode.

private native void startService(long nativeHandle);
Returns
  • 0: Success.
  • < 0: Failure.

Stops the Recording (stopService)

This method manually stops the recording.

The method is only valid when you set triggerMode to 1 (manually) when joining the channel. For more information, see Create a Channel (createChannel) on triggerMode.

private native void stopService(long nativeHandle);
Returns
  • 0: Success.
  • < 0: Failure.

Sets the User Background Image (setUserBackground)

This method sets the background image of a specified user.

private native int setUserBackground(long nativeHandle, int uid, String image_path);
Name Description
uid The user ID of the user for the background image to be set.
image_path The path of the image file.
Returns
  • 0: Success.
  • < 0: Failure.

Sets the Log Level (setLogLevel)

private native void setLogLevel(long vativeHandle, int level)

This method sets the log level. Only log levels preceding the selected level are generated. The default value of level is 6.

Name Description
level Log levels:
  • 2: AGORA_LOG_LEVEL_FATAL
  • 3: AGORA_LOG_LEVEL_ERROR
  • 4: AGORA_LOG_LEVEL_WARN
  • 5: AGORA_LOG_LEVEL_NOTICE
  • 6: AGORA_LOG_LEVEL_INFO
  • 7: AGORA_LOG_LEVEL_DEBUG

Enables the Module Log (enableModuleLog)

private native void enableLogModule(long vativeHandle, int module, int enable)

This method enables/disables generating logs for specified modules.

Name Description
module Module:
  • 0x1: AGORA_LOG_MODULE_MEDIA_FILE
  • 0x2: AGORA_LOG_MDOULE_RECORDING_ENGINE
  • 0x4: AGORA_LOG_MODULE_RTMP_RENDER
  • 0x8: AGORA_LOG_MODULE_IPC
  • 0x10: AGORA_LOG_MODULE_CORE_SERVGICE_HANDLER
  • 0: AGORA_LOG_MODULE_ANY
enable Whether or not to generate the module log:
  • true: Generates the module log.
  • false: Does not generate the module log.

Callbacks

The following callbacks are available to your app:

Returns the JNI Instance (nativeObjectRef)

This callback returns the JNI instance. You need to pass this JNI instance when calling each main method, except Creates a Channel (createChannel).

private void nativeObjectRef(long nativeHandle){
  //your code
}

An Error has Occurred During SDK Runtime (onError)

This callback is triggered when an error has occurred during SDK runtime.

The SDK cannot fix the issue or resume running, which requires intervention from the app and informs the user on the issue.

private void onError(int error, int stat_code) {
  //your code
}
Name Description
error

Error codes:

  • 0: No error (ERR_OK).
  • 1: General error with no classified reason (ERR_FAILED).
  • 2: Invalid parameter is called (ERR_INVALID_ARGUMENT). For example, the specific channel name contains illegal characters.
  • 3: The SDK module is not ready (ERR_NOT_READY). Agora recommends the following methods to solve this error:
    • Check the audio device.
    • Check the completeness of the app.
    • Re-initialize the SDK.
stat_code

State codes:

  • 1: Error from the engine (STAT_ERR_FROM_ENGINE).
  • 2: Failure to join the channel (STAT_ERR_ARS_JOIN_CHANNEL).
  • 3: Failure to create a process (STAT_ERR_CREATE_PROCESS).
  • 4: Failure to mix the video (STAT_ERR_MIXED_INVALID_VIDEO_PARAM).
  • 5: Null pointer (STAT_ERR_NULL_POINTER = 5).
  • 6: Invalid parameters of the proxy server (STAT_ERR_PROXY_SERVER_INVALID_PARAM).
  • 0x8: Error in polling (STAT_POLL_ERR).
  • 0x10: Polling hangs up (STAT_POLL_HANG_UP).
  • 0x20: Invalid polling request (STAT_POLL_NVAL).

A Warning has Occurred During SDK Runtime (onWarning)

This callback is triggered when a warning has occurred during SDK runtime.

In most cases, the app can ignore the warnings reported by the SDK because the SDK can usually fix the issue and resume running.

public void onWarning(int warn) {
//your code
}
Name Description
warn

Warning codes:

  • 103: No channel resources are available (WARN_NO_AVAILABLE_CHANNEL). Maybe because the server cannot allocate any channel resource.
  • 104: A timeout when looking up the channel (WARN_LOOKUP_CHANNEL_TIMEOUT). When joining a channel, the SDK looks up the specified channel. This warning usually occurs when the network conditions are too poor to connect to the server.
  • 105: The server rejected the request to look up the channel (WARN_LOOKUP_CHANNEL_REJECTED). The server cannot process this request or the request is illegal.
  • 106: A timeout occurred when opening the channel (WARN_OPEN_CHANNEL_TIMEOUT). Once the specific channel is found, the SDK opens the channel. This warning usually occurs when the network condition is too poor to connect to the server.
  • 107: The server rejected the request to open the channel (WARN_OPEN_CHANNEL_REJECTED). The server cannot process this request or the request is illegal.

The User has Left the Channel (onLeaveChannel)

private void onLeaveChannel(int reason){
  // your code
}

This callback is triggered when a user has left the channel.

Name Description
code
Reason:
  • 0: Initialization failure (LEAVE_CODE_INIT).
  • 1: Signal triggered exit (LEAVE_CODE_SIG).
  • 2: There is no user in the channel except for the recording app (LEAVE_CODE_NO_USERS).
  • 3: Timer catch exit (LEAVE_CODE_TIMER_CATCH).
  • 4: The client leaves the channel (LEAVE_CODE_CLIENT_LEAVE).

The User/Host has Joined the Channel (onUserJoined)

This callback is triggered when another user has joined the channel.

If other users are already in the channel, the SDK reports to the app on the existing users as well. This callback is called as many times as the number of users in the channel.

private void onUserJoined(long uid, String recordingDir){
  //your code
}
Name Description
uid User ID of the user.
recordingDir Directory of the recorded files.

A User has Left the Channel or Gone Offline (onUserOffline)

This callback is triggered when a user has left the channel or gone offline.

The SDK reads the timeout data to determine if a user has left the channel (or has gone offline). If no data package is received from the user within 15 seconds, the SDK assumes the user is offline. A poor network connection may lead to false detections, so use signaling for reliable offline detection.

private void onUserOffline(long uid, int reason) {
  //your code
}
Name Description
uid User ID of the user.
reason

Reason:

  • 0: The user has quit the call (USER_OFFLINE_QUIT).
  • 1: The SDK timed out and the user dropped offline because it has not received any data packet for a period of time (USER_OFFLINE_DROPPED). If a user quits the call and the message is not passed to the SDK (due to an unreliable channel), the SDK assumes the user has dropped offline.
  • 2: The client role has changed from the host to the audience (USER_OFFLINE_BECOME_AUDIENCE). The option is only valid when you set the channel profile as live broadcast when calling joinChannel.

The Raw Audio Data has Been Received (audioFrameReceived)

This callback is triggered when the raw audio data has been received.

private void audioFrameReceived(long uid, int type, AudioFrame frame) {
 //your code
}
Name Description
uid User ID of the remote user.
type

Format of the received raw audio data:

  • 0: PCM
  • 1: AAC
frame Received raw audio data in PCM or AAC format.

The structure of AudioFrame:

public class AudioFrame {
  public AUDIO_FRAME_TYPE type;
  public AudioPcmFrame pcm;
  public AudioAacFrame aac;
}

AudioPcmFrame

The structure of AudioPcmFrame:

public class AudioPcmFrame {
  public AudioPcmFrame(long frame_ms, long sample_rates, long samples) {
  }
  public long frame_ms;
  public long channels; // 1
  public long sample_bits; // 16
  public long sample_rates; // 8k, 16k, 32k
  public long samples;

  public ByteBuffer pcmBuf;
  public long pcmBufSize;
}
Name Description
frame_ms Timestamp of the frame.
channels Number of audio channels.
sample_bits Bitrate of the sampling data.
sample_rates Sampling rate.
samples Number of samples of the frame.
pcmBuf Audio frame buffer.
pcmBufSize Size of the audio frame buffer.

AudioAacFrame

The structure of AudioAacFrame:

public class AudioAacFrame {
  public AudioAacFrame(long framems) {
    frame_ms = framems;
    aacBufSize = 0;
  }
  public ByteBuffer aacBuf;
  public long frame_ms;
  public long aacBufSize;
}
Name Description
frame_ms Timestamp of the frame.
aacBuf Audio frame buffer.
aacBufSize Size of the audio frame buffer.

The Raw Video Data has Been Received (videoFrameReceived)

This callback is triggered when the raw video data has been received.

This callback is triggered for every received raw video frame and can be used to detect sexually explicit content, if necessary.

Agora recommends capturing the i frame only and neglecting the others.

private void videoFrameReceived(long uid, int type, VideoFrame frame, int rotation) {
 //your code
}
Name Description
uid User ID of the remote user as specified in the createChannel() method. If no uid is previously assigned, the Agora server automatically assigns a uid.
type

The format of the received video data:

  • 0: YUV
  • 1: H.264
  • 2: JPEG
frame Received video data in YUV, H264, or JPEG format.
rotation Rotational angle: 0, 90, 180, or 270.

The structure of VideoFrame:

public class VideoFrame {
  public VideoYuvFrame yuv;
  public VideoH264Frame h264;
  public VideoJpgFrame jpg;
  public int rotation; // 0, 90, 180, 270
}

VideoYuvFrame

The structure of VideoYuvFrame:

public class VideoYuvFrame {
  VideoYuvFrame(long framems, int width, int height, int ystride,int ustride, int vstride){
    this.frame_ms = framems;
    this.width = width;
    this.height = height;
    this.ystride = ystride;
    this.ustride = ustride;
    this.vstride = vstride;
  }
  public long frame_ms;

  public ByteBuffer ybuf;
  public ByteBuffer ubuf;
  public ByteBuffer vbuf;

  public int width;
  public int height;

  public int ystride;
  public int ustride;
  public int vstride;
  //all
  public ByteBuffer buf;
  public long bufSize;
}
Name Description
frame_ms Timestamp of the frame.
ybuf Y buffer pointer.
ubuf U buffer pointer.
vbuf V buffer pointer.
width Width of the video in the number of pixels.
height Height of the video in the number of pixels.
ystride Line span of the Y buffer.
ustride Line span of the U buffer.
vstride Line span of the V buffer.
buf Video frame buffer.
bufSize Size of the video frame buffer.

VideoH264Frame

The structure of VideoH264Frame:

public class VideoH264Frame {
  VideoH264Frame(){
    frame_ms = 0;
    frame_num = 0;
    bufSize = 0;
  }
  public long frame_ms;
  public long frame_num;
  public ByteBuffer buf;
  public long bufSize;
}
Name Description
frame_ms Timestamp of the frame.
frame_num Index of the frame.
buf Video frame buffer.
bufSize Size of the video frame buffer.

VideoJpgFrame

The structure of VideoJpgFrame:

public class VideoJpgFrame {
  VideoJpgFrame(){
    frame_ms = 0;
    bufSize = 0;
  }
  public long frame_ms;
  public ByteBuffer buf;
  public long bufSize;
}
Name Description
frame_ms Timestamp of the frame.
buf Video frame buffer.
bufSize Size of the video frame buffer.

Indicates the Speaker in the Channel (onActiveSpeaker)

void onActiveSpeaker(long uid){
 //your code
}

This callback returns the user ID of the active speaker.

Name Description
uid The user ID of the active speaker.

Error Codes and Warning Codes

See Error Codes and Warning Codes.