Multi-channel Management
Introduces methods and callbacks related to multi-channels.
The Agora RTC SDK enables users to join multiple channels at the same time and receive the audio and video streams of all the channels.
addVideoWatermarkEx
Adds a watermark image to the local video.
virtual int addVideoWatermarkEx(const char* watermarkUrl,
const WatermarkOptions& options,
const RtcConnection& connection) = 0;
This method adds a PNG watermark image to the local video in the live streaming. Once the watermark image is added, all the audience in the channel (CDN audience included), and the capturing device can see and capture it. Agora supports adding only one watermark image onto the local video, and the newly watermark image replaces the previous one.
- If the orientation mode of the encoding video (ORIENTATION_MODE) is fixed landscape mode or the adaptive landscape mode, the watermark uses the landscape orientation.
- If the orientation mode of the encoding video (ORIENTATION_MODE) is fixed portrait mode or the adaptive portrait mode, the watermark uses the portrait orientation.
- When setting the watermark position, the region must be less than the setVideoEncoderConfigurationEx dimensions set in the method; otherwise, the watermark image will be cropped.
- Ensure that you have called enableVideo before calling this method.
- This method supports adding a watermark image in the PNG file format only. Supported pixel formats of the PNG image are RGBA, RGB, Palette, Gray, and Alpha_gray.
- If the dimensions of the PNG image differ from your settings in this method, the image will be cropped or zoomed to conform to your settings.
- If you have enabled the local video preview by calling the startPreview [1/2] method, you can use the
visibleInPreview
member to set whether or not the watermark is visible in the preview. - If you have enabled the mirror mode for the local video, the watermark on the local video is also mirrored. To avoid mirroring the watermark, Agora recommends that you do not use the mirror and watermark functions for the local video at the same time. You can implement the watermark function in your application layer.
Parameters
- watermarkUrl
- The local file path of the watermark image to be added. This method supports adding a watermark image from the local absolute or relative file path.
- options
- The options of the watermark image to be added. For details, see WatermarkOptions.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
adjustUserPlaybackSignalVolumeEx
Adjusts the playback signal volume of a specified remote user.
virtual int adjustUserPlaybackSignalVolumeEx(unsigned int uid, int volume, const RtcConnection& connection) = 0;
- Since
- v4.1.0
You can call this method to adjust the playback volume of a specified remote user. To adjust the playback volume of different remote users, call the method as many times, once for each remote user.
- Call this method after joining a channel.
- The playback volume here refers to the mixed volume of a specified remote user.
Parameters
- uid
- The user ID of the remote user.
- volume
- Audio mixing volume. The value ranges between 0 and 100. The default value is 100, which means the original volume.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
clearVideoWatermarkEx
Removes the watermark image from the video stream.
virtual int clearVideoWatermarkEx(const RtcConnection& connection) = 0;
Parameters
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
createDataStreamEx [1/2]
Creates a data stream.
virtual int createDataStreamEx(int* streamId, bool reliable, bool ordered, const RtcConnection& connection) = 0;
- Deprecated:
- This method is deprecated. Use createDataStreamEx [2/2] instead.
You can call this method to create a data stream and improve the reliability and ordering of data transmission.
- Ensure that you set the same value for reliable and ordered.
- Each user can create up to five data streams during the lifecycle of IRtcEngine.
- The data channel allows a data delay of up to 5 seconds. If the receiver does not receive the data stream within 5 seconds, the data channel reports an error.
Parameters
- streamId
- Output parameter. Pointer to the ID of the created data stream.
- reliable
-
Sets whether the recipients are guaranteed to receive the data stream from the sender within five seconds:
true
: The recipients receive the data stream from the sender within five seconds. If the recipient does not receive the data stream within five seconds, an error is reported to the application.false
: There is no guarantee that the recipients receive the data stream from the sender within five seconds. The SDK does not report errors if reception is delayed or data is lost.
- ordered
-
Sets whether the recipients receive the data stream in the sent order:
true
: The recipients receive the data stream in the sent order.false
: There is no guarantee that the recipients receive the data stream in the sent order.
- connection
- The connection information. See RtcConnection.
Returns
- 0: The data stream is successfully created.
- < 0: Fails to create the data stream.
createDataStreamEx [2/2]
Creates a data stream.
virtual int createDataStreamEx(int* streamId, DataStreamConfig& config, const RtcConnection& connection) = 0;
Creates a data stream. Each user can create up to five data streams in a single channel.
Compared with createDataStreamEx [1/2] , this method does not support data reliability. If a data packet is not received five seconds after it was sent, the SDK directly discards the data.
Parameters
- streamId
- Output parameter. Pointer to the ID of the created data stream.
- config
- The configurations for the data stream. See DataStreamConfig.
- connection
- The connection information. See RtcConnection.
Returns
- 0: The data stream is successfully created.
- < 0: Failure.
enableAudioVolumeIndicationEx
Enables the reporting of users' volume indication.
virtual int enableAudioVolumeIndicationEx(int interval, int smooth, bool reportVad, const RtcConnection& connection) = 0;
This method enables the SDK to regularly report the volume information to the app of the local user who sends a stream and remote users (three users at most) whose instantaneous volumes are the highest. Once you call this method and users send streams in the channel, the SDK triggers the onAudioVolumeIndication callback at the time interval set in this method.
Parameters
- interval
- Sets the time interval between two consecutive volume indications:
- ≤ 0: Disables the volume indication.
- > 0: Time interval (ms) between two consecutive volume indications. You need to set this parameter to an integer multiple of 200. If the value is lower than 200, the SDK automatically adjusts the value to 200.
- smooth
- The smoothing factor sets the sensitivity of the audio volume indicator. The value ranges between 0 and 10. The recommended value is 3. The greater the value, the more sensitive the indicator.
- reportVad
-
true
: Enable the voice activity detection of the local user. Once it is enabled,the vad parameter of the onAudioVolumeIndication callback reports the voice activity status of the local user.false
: (Default) Disable the voice activity detection of the local user. Once it is disabled, the vad parameter of the onAudioVolumeIndication callback does not report the voice activity status of the local user, except for the scenario where the engine automatically detects the voice activity of the local user.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
enableDualStreamModeEx
Enables or disables dual-stream mode on the sender side.
virtual int enableDualStreamModeEx(bool enabled, const SimulcastStreamConfig& streamConfig,
const RtcConnection& connection) = 0;
- Since
- v4.0.1
- High-quality video stream: High bitrate, high resolution.
- Low-quality video stream: Low bitrate, low resolution.
After you enable dual-stream mode, you can call setRemoteVideoStreamType to choose to receive either the high-quality video stream or the low-quality video stream on the subscriber side.
Parameters
- enabled
-
Whether to enable dual-stream mode:
true
: Enable dual-stream mode.false
: (Default) Disable dual-stream mode.
- streamConfig
-
The configuration of the low-quality video stream. See SimulcastStreamConfig.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
enableLoopbackRecordingEx
Enables loopback audio capturing.
virtual int enableLoopbackRecordingEx(const RtcConnection& connection, bool enabled, const char* deviceName = NULL) = 0;
If you enable loopback audio capturing, the output of the sound card is mixed into the audio stream sent to the other end.
- This method applies to the macOS and Windows platforms only.
- macOS does not support loopback audio capture of the default sound card. If you need to use this method, use a virtual sound card and pass its name in the deviceName parameter. Agora recommends that you use Soundflower for loopback audio capture.
- You can call this method either before or after joining a channel.
Parameters
- connection
- The connection information. See RtcConnection.
- enabled
- Sets whether to enable loopback audio capture:
true
: Enable loopback audio capturing.false
: (Default) Disable loopback audio capturing.
Returns
- 0: Success.
- < 0: Failure.
getConnectionStateEx
Gets the current connection state of the SDK.
virtual CONNECTION_STATE_TYPE getConnectionStateEx(const RtcConnection& connection) = 0;
You can call this method either before or after joining a channel.
Parameters
- connection
- The connection information. See RtcConnection.
Returns
The current connection state. For details, see CONNECTION_STATE_TYPE.
joinChannelEx
Joins a channel with the connection ID.
virtual int joinChannelEx(const char* token, const RtcConnection& connection,
const ChannelMediaOptions& options,
IRtcEngineEventHandler* eventHandler) = 0;
You can call this method multiple times to join more than one channel.
- If you are already in a channel, you cannot rejoin it with the same user ID.
- If you want to join the same channel from different devices, ensure that the user IDs are different for all devices.
- Ensure that the app ID you use to generate the token is the same asIRtcEngine the app ID used when creating the instance.
- In a multi-camera capture scenario, you need to call the method after calling this method startPreview [2/2]to set the sourceType to VIDEO_SOURCE_CAMERA_SECONDARY, to ensure that the second camera captures normally.
Parameters
- token
- The token generated on your server for authentication. See .
- connection
- The connection information. See RtcConnection.
- options
- The channel media options. See ChannelMediaOptions.
- eventHandler
- IRtcEngineExThe callback class of . For details, see IRtcEngineEventHandler.
Returns
- 0: Success.
- < 0: Failure.
- -2: The parameter is invalid. For example, the token is invalid, the uid parameter is not set to an integer, or the value of a member in the ChannelMediaOptions structure is invalid. You need to pass in a valid parameter and join the channel again.
- -3: Failes to initialize the IRtcEngine object. You need to reinitialize the IRtcEngine object.
- -7: The IRtcEngine object has not been initialized. You need to initialize the IRtcEngine object before calling this method.
- -8: IRtcEngineThe internal state of the object is wrong. The typical cause is that you call this method to join the channel without calling stopEchoTest to stop the test after calling startEchoTest [2/3] to start a call loop test. You need to call stopEchoTest before calling this method.
- -17: The request to join the channel is rejected. The typical cause is that the user is in the channel. Agora recommends using the onConnectionStateChanged callback to get whether the user is in the channel. Do not call this method to join the channel unless you receive the CONNECTION_STATE_DISCONNECTED(1) state.
- -102: The channel name is invalid. You need to pass in a valid channel name inchannelId to rejoin the channel.
- -121: The user ID is invalid. You need to pass in a valid user ID in uid to rejoin the channel.
joinChannelWithUserAccountEx
Joins the channel with a user account, and configures whether to automatically subscribe to audio or video streams after joining the channel.
virtual int joinChannelWithUserAccountEx(const char* token, const char* channelId,
const char* userAccount, const ChannelMediaOptions& options,
IRtcEngineEventHandler* eventHandler) = 0;
- The local client: onLocalUserRegistered, onJoinChannelSuccess and onConnectionStateChanged callbacks.
- The remote client: The onUserJoined callback if the user is in the COMMUNICATION profile, and the onUserInfoUpdated callback if the user is a host in the LIVE_BROADCASTING profile.
Once a user joins the channel, the user subscribes to the audio and video streams of all the other users in the channel by default, giving rise to usage and billing calculation. To stop subscribing to a specified stream or all remote streams, call the corresponding mute methods.
Parameters
- token
- The token generated on your server for authentication. See .
- channelId
-
The channel name. This parameter signifies the channel in which users engage in real-time audio and video interaction. Under the premise of the same App ID, users who fill in the same channel ID enter the same channel for audio and video interaction. The string length must be less than 64 bytes. Supported characters:
- All lowercase English letters: a to z.
- All uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- userAccount
-
The user account. This parameter is used to identify the user in the channel for real-time audio and video engagement. You need to set and manage user accounts yourself and ensure that each user account in the same channel is unique. The maximum length of this parameter is 255 bytes. Ensure that you set this parameter and do not set it as NULL. Supported characters are (89 in total):
- The 26 lowercase English letters: a to z.
- The 26 uppercase English letters: A to Z.
- All numeric characters: 0 to 9.
- Space
- "!", "#", "$", "%", "&", "(", ")", "+", "-", ":", ";", "<", "= ", ".", ">", "?", "@", "[", "]", "^", "_", "{", "}", "|", "~", ","
- options
- The channel media options. See ChannelMediaOptions.
- eventHandler
- IRtcEngineExThe callback class of . For details, see IRtcEngineEventHandler.
Returns
- 0: Success.
- < 0: Failure.
leaveChannelEx [1/2]
Leaves a channel.
virtual int leaveChannelEx(const RtcConnection& connection) = 0;
This method lets the user leave the channel, for example, by hanging up or exiting the call.
After calling joinChannelEx to join the channel, this method must be called to end the call before starting the next call.
This method can be called whether or not a call is currently in progress. This method releases all resources related to the session.
This method call is asynchronous. When this method returns, it does not necessarily mean that the user has left the channel. After you leave the channel, the SDK triggers the onLeaveChannel callback.
A successful call of this method triggers the following callbacks: The local client: onLeaveChannel.The remote client: onUserOffline, if the user joining the channel is in the COMMUNICATION profile, or is a host in the LIVE_BROADCASTING profile.
- If you call release immediately after calling this method, the SDK does not trigger the onLeaveChannel callback.
- Calling leaveChannel [1/2] will leave the channels when calling joinChannel [2/2] and joinChannelEx at the same time.
Parameters
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
leaveChannelEx [2/2]
Sets channel options and leaves the channel.
virtual int leaveChannelEx(const RtcConnection& connection, const LeaveChannelOptions& options) = 0;
This method lets the user leave the channel, for example, by hanging up or exiting the call.
After calling joinChannelEx to join the channel, this method must be called to end the call before starting the next call.
This method can be called whether or not a call is currently in progress. This method releases all resources related to the session.
This method call is asynchronous. When this method returns, it does not necessarily mean that the user has left the channel. After you leave the channel, the SDK triggers the onLeaveChannel callback.
A successful call of this method triggers the following callbacks: The local client: onLeaveChannel.The remote client: onUserOffline, if the user joining the channel is in the COMMUNICATION profile, or is a host in the LIVE_BROADCASTING profile.
- If you call release immediately after calling this method, the SDK does not trigger the onLeaveChannel callback.
- Calling leaveChannel [1/2] will leave the channels when calling joinChannel [2/2] and joinChannelEx at the same time.
Parameters
- connection
- The connection information. See RtcConnection.
- options
-
- Since
- v4.1.0
The options for leaving the channel. See LeaveChannelOptions.
Note: This parameter only supports the stopMicrophoneRecording member in the LeaveChannelOptions settings; setting other members does not take effect.
Returns
- 0: Success.
- < 0: Failure.
muteAllRemoteAudioStreamsEx
Stops or resumes subscribing to the audio streams of all remote users.
virtual int muteAllRemoteAudioStreamsEx(bool mute, const RtcConnection& connection) = 0;
After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including the ones who join the channel subsequent to this call.
- Call this method after joining a channel.
- If you do not want to subscribe the audio streams of remote users before joining a channel, you can set autoSubscribeAudio as
false
when calling joinChannel [2/2]. - See recommended settings in Set the Subscribing State.
Parameters
- mute
-
Whether to stop subscribing to the audio streams of all remote users:
true
: Stops subscribing to the audio streams of all remote users.false
: (Default) Subscribes to the audio streams of all remote users.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
muteAllRemoteVideoStreamsEx
Stops or resumes subscribing to the video streams of all remote users.
virtual int muteAllRemoteVideoStreamsEx(bool mute, const RtcConnection& connection) = 0;
- Since
- v4.1.0
After successfully calling this method, the local user stops or resumes subscribing to the audio streams of all remote users, including all subsequent users.
Parameters
- mute
-
Whether to stop subscribing to the video streams of all remote users.
true
: Stop subscribing to the video streams of all remote users.false
: (Default) Subscribe to the audio streams of all remote users by default.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
muteLocalAudioStreamEx
Stops or resumes publishing the local audio stream.
virtual int muteLocalAudioStreamEx(bool mute, const RtcConnection& connection) = 0;
Parameters
- mute
-
Whether to stop publishing the local audio stream:
true
: Stops publishing the local audio stream.false
: (Default) Resumes publishing the local audio stream.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
muteLocalVideoStreamEx
Stops or resumes publishing the local video stream.
virtual int muteLocalVideoStreamEx(bool mute, const RtcConnection& connection) = 0;
- Since
- v4.1.0
A successful call of this method triggers the onUserMuteVideo callback on the remote client.
- This method does not affect any ongoing video recording, because it does not disable the camera.
Parameters
- mute
-
Whether to stop publishing the local video stream.
true
: Stop publishing the local video stream.false
: (Default) Publish the local video stream.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
muteRemoteAudioStreamEx
Stops or resumes receiving the audio stream of a specified user.
virtual int muteRemoteAudioStreamEx(uid_t uid, bool mute, const RtcConnection& connection) = 0;
Parameters
- uid
- The ID of the specified user.
- mute
-
Whether to stop receiving the audio stream of the specified user:
true
: Stop receiving the audio stream of the specified user.false
: (Default) Resume receiving the audio stream of the specified user.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
muteRemoteVideoStreamEx
Stops or resumes receiving the video stream of a specified user.
virtual int muteRemoteVideoStreamEx(uid_t uid, bool mute, const RtcConnection& connection) = 0;
This method is used to stops or resumes receiving the video stream of a specified user. You can call this method before or after joining a channel. If a user leaves a channel, the settings in this method become invalid.
Parameters
- uid
-
The user ID of the remote user.
- mute
-
Whether to stop receiving the video stream of the specified user:
true
: Stop receiving the video stream of the specified user.false
: (Default) Resume receiving the video stream of the specified user.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
pauseAllChannelMediaRelayEx
Pauses the media stream relay to all destination channels.
virtual int pauseAllChannelMediaRelayEx(const RtcConnection& connection) = 0;
After the cross-channel media stream relay starts, you can call this method to pause relaying media streams to all destination channels; after the pause, if you want to resume the relay, call resumeAllChannelMediaRelay.
After a successful method call, the SDK triggers the onChannelMediaRelayEvent callback to report whether the media stream relay is successfully paused.
Parameters
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
resumeAllChannelMediaRelayEx
Resumes the media stream relay to all destination channels.
virtual int resumeAllChannelMediaRelayEx(const RtcConnection& connection) = 0;
After calling the pauseAllChannelMediaRelayEx method, you can call this method to resume relaying media streams to all destination channels.
After a successful method call, the SDK triggers the onChannelMediaRelayEvent callback to report whether the media stream relay is successfully resumed.
Parameters
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
sendCustomReportMessageEx
Agora supports reporting and analyzing customized messages.
virtual int sendCustomReportMessageEx(const char* id, const char* category, const char* event, const char* label,
int value, const RtcConnection& connection) = 0;
Agora supports reporting and analyzing customized messages. This function is in the beta stage with a free trial. The ability provided in its beta test version is reporting a maximum of 10 message pieces within 6 seconds, with each message piece not exceeding 256 bytes and each string not exceeding 100 bytes. To try out this function, contact support@agora.io and discuss the format of customized messages with us.
sendStreamMessageEx
Sends data stream messages.
virtual int sendStreamMessageEx(int streamId, const char* data, size_t length, const RtcConnection& connection) = 0;
After calling createDataStreamEx [2/2], you can call this method to send data stream messages to all users in the channel.
- Up to 30 packets can be sent per second in a channel with each packet having a maximum size of 1 kB.
- Each client can send up to 6 KB of data per second.
- Each user can have up to five data streams simultaneously.
A successful method call triggers the onStreamMessage callback on the remote client, from which the remote user gets the stream message. A failed method call triggers the onStreamMessageError callback on the remote client.
- Ensure that you call createDataStreamEx [2/2] to create a data channel before calling this method.
- This method applies only to the COMMUNICATION profile or to the hosts in the LIVE_BROADCASTING profile. If an audience in the LIVE_BROADCASTING profile calls this method, the audience may be switched to a host.
Parameters
- streamId
- The data stream ID. You can get the data stream ID by calling createDataStreamEx [2/2].
- data
- The data to be sent.
- length
- The length of the data.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setDualStreamModeEx
Sets dual-stream mode on the sender side.
virtual int setDualStreamModeEx(SIMULCAST_STREAM_MODE mode,
const SimulcastStreamConfig& streamConfig,
const RtcConnection& connection) = 0;
- Since
- v4.0.1
The SDK enables the low-quality video stream auto mode on the sender by default, which is equivalent to calling this method and setting the mode to AUTO_SIMULCAST_STREAM. If you want to modify this behavior, you can call this method and modify the mode to DISABLE_SIMULCAST_STREAM(never sends low-quality video streams) or ENABLE_SIMULCAST_STREAM(sends low-quality video streams).
- When calling this method and setting mode to DISABLE_SIMULCAST_STREAM, it has the same effect as
enableDualStreamModeEx(false)
. - When calling this method and setting mode to ENABLE_SIMULCAST_STREAM, it has the same effect as
enableDualStreamModeEx(true)
. - Both methods can be called before and after joining a channel. If they are used at the same time, the settings in the method called later shall prevail.
Parameters
- mode
- The mode in which the video stream is sent. See SIMULCAST_STREAM_MODE.
- streamConfig
-
The configuration of the low-quality video stream. See SimulcastStreamConfig.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setRemoteVideoStreamTypeEx
Sets the stream type of the remote video.
virtual int setRemoteVideoStreamTypeEx(uid_t uid, VIDEO_STREAM_TYPE streamType, const RtcConnection& connection) = 0;
Under limited network conditions, if the publisher has not disabled the dual-stream mode using enableDualStreamModeEx(false)
, the receiver can choose to receive either the high-quality video stream or the low-quality video stream. The high-quality video stream has a higher resolution and bitrate, and the low-quality video stream has a lower resolution and bitrate.
By default, users receive the high-quality video stream. Call this method if you want to switch to the low-quality video stream. This method allows the app to adjust the corresponding video stream type based on the size of the video window to reduce the bandwidth and resources. The aspect ratio of the low-quality video stream is the same as the high-quality video stream. Once the resolution of the high-quality video stream is set, the system automatically sets the resolution, frame rate, and bitrate of the low-quality video stream.
The SDK enables the low-quality video stream auto mode on the sender by default (not actively sending low-quality video streams). The host at the receiving end can call this method to initiate a low-quality video stream stream request on the receiving end, and the sender automatically switches to the low-quality video stream mode after receiving the request.
The result of this method returns in the onApiCallExecuted callback.
Parameters
- uid
- The user ID.
- streamType
-
The video stream type: VIDEO_STREAM_TYPE.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setRemoteVideoSubscriptionOptionsEx
Options for subscribing to remote video streams.
virtual int setRemoteVideoSubscriptionOptionsEx(uid_t uid, const VideoSubscriptionOptions& options, const RtcConnection& connection) = 0;
When a remote user has enabled dual-stream mode, you can call this method to choose the option for subscribing to the video streams sent by the remote user.
Parameters
- uid
- The user ID of the remote user.
- options
- The video subscription options. See VideoSubscriptionOptions.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setRemoteVoicePositionEx
Sets the 2D position (the position on the horizontal plane) of the remote user's voice.
virtual int setRemoteVoicePositionEx(uid_t uid, double pan, double gain, const RtcConnection& connection) = 0;
This method sets the voice position and volume of a remote user.
When the local user calls this method to set the voice position of a remote user, the voice difference between the left and right channels allows the local user to track the real-time position of the remote user, creating a sense of space. This method applies to massive multiplayer online games, such as Battle Royale games.
- For the best voice positioning, Agora recommends using a wired headset.
- Call this method after joining a channel.
Parameters
- uid
- The user ID of the remote user.
- pan
- The voice position of the remote user. The value ranges from -1.0 to 1.0:
- -1.0: The remote voice comes from the left.
- 0.0: (Default) The remote voice comes from the front.
- 1.0: The remote voice comes from the right.
- gain
- The volume of the remote user. The value ranges from 0.0 to 100.0. The default value is 100.0 (the original volume of the remote user). The smaller the value, the lower the volume.
- connection
- The connection information. See RtcConnection.
Returns
>- 0: Success.
- < 0: Failure.
setSubscribeAudioAllowlistEx
Sets the allowlist of subscriptions for audio streams.
virtual int setSubscribeAudioAllowlistEx(uid_t* uidList, int uidNumber, const RtcConnection& connection) = 0;
You can call this method to specify the audio streams of a user that you want to subscribe to.
- You can call this method either before or after joining a channel.
- The allowlist is not affected by the setting in muteRemoteAudioStream, muteAllRemoteAudioStreams and autoSubscribeAudio in ChannelMediaOptions.
- Once the allowlist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
- If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.
Parameters
- uidList
-
The user ID list of users that you want to subscribe to.
If you want to specify the audio streams of a user for subscription, add the user ID in this list. If you want to remove a user from the allowlist, you need to call the setSubscribeAudioAllowlist method to update the user ID list; this means you only add the uid of users that you want to subscribe to in the new user ID list.
- uidNumber
- The number of users in the user ID list.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setSubscribeAudioBlocklistEx
Set the blocklist of subscriptions for audio streams.
virtual int setSubscribeAudioBlocklistEx(uid_t* uidList, int uidNumber, const RtcConnection& connection) = 0;
You can call this method to specify the audio streams of a user that you do not want to subscribe to.
- You can call this method either before or after joining a channel.
- The blocklist is not affected by the setting in muteRemoteAudioStream,muteAllRemoteAudioStreams, and autoSubscribeAudio in ChannelMediaOptions.
- Once the blocklist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
- If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.
Parameters
- uidList
-
The user ID list of users that you do not want to subscribe to.
If you want to specify the audio streams of a user that you do not want to subscribe to, add the user ID in this list. If you want to remove a user from the blocklist, you need to call the setSubscribeAudioBlocklist method to update the user ID list; this means you only add the uid of users that you do not want to subscribe to in the new user ID list.
- uidNumber
- The number of users in the user ID list.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setSubscribeVideoAllowlistEx
Set the allowlist of subscriptions for video streams.
virtual int setSubscribeVideoAllowlistEx(uid_t* uidList, int uidNumber, const RtcConnection& connection) = 0;
You can call this method to specify the video streams of a user that you want to subscribe to.
- You can call this method either before or after joining a channel.
- The allowlist is not affected by the setting in muteRemoteVideoStream, muteAllRemoteVideoStreams and autoSubscribeAudio in ChannelMediaOptions.
- Once the allowlist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
- If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.
Parameters
- uidList
-
The user ID list of users that you want to subscribe to.
If you want to specify the video streams of a user for subscription, add the user ID of that user in this list. If you want to remove a user from the allowlist, you need to call the setSubscribeVideoAllowlist method to update the user ID list; this means you only add the uid of users that you want to subscribe to in the new user ID list.
- uidNumber
- The number of users in the user ID list.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setSubscribeVideoBlocklistEx
Set the blocklist of subscriptions for video streams.
virtual int setSubscribeVideoBlocklistEx(uid_t* uidList, int uidNumber, const RtcConnection& connection) = 0;
You can call this method to specify the video streams of a user that you do not want to subscribe to.
- You can call this method either before or after joining a channel.
- The blocklist is not affected by the setting in muteRemoteVideoStream, muteAllRemoteVideoStreams and autoSubscribeAudio in ChannelMediaOptions.
- Once the blocklist of subscriptions is set, it is effective even if you leave the current channel and rejoin the channel.
- If a user is added in the allowlist and blocklist at the same time, only the blocklist takes effect.
Parameters
- uidList
-
The user ID list of users that you do not want to subscribe to.
If you want to specify the video streams of a user that you do not want to subscribe to, add the user ID of that user in this list. If you want to remove a user from the blocklist, you need to call the setSubscribeVideoBlocklist method to update the user ID list; this means you only add the uid of users that you do not want to subscribe to in the new user ID list.
- uidNumber
- The number of users in the user ID list.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setupRemoteVideoEx
Initializes the video view of a remote user.
virtual int setupRemoteVideoEx(const VideoCanvas& canvas, const RtcConnection& connection) = 0;
This method initializes the video view of a remote stream on the local device. It affects only the video view that the local user sees. Call this method to bind the remote video stream to a video view and to set the rendering and mirror modes of the video view.
The application specifies the uid of the remote video in the VideoCanvas method before the remote user joins the channel.
If the remote uid is unknown to the application, set it after the application receives the onUserJoined callback. If the Video Recording function is enabled, the Video Recording Service joins the channel as a dummy client, causing other clients to also receive the onUserJoined
callback. Do not bind the dummy client to the application view because the dummy client does not send any video streams.
To unbind the remote user from the view, set the view parameter to NULL.
Once the remote user leaves the channel, the SDK unbinds the remote user.
Parameters
- canvas
-
The remote video view settings. See VideoCanvas.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
setVideoEncoderConfigurationEx
Sets the encoder configuration for the local video.
virtual int setVideoEncoderConfigurationEx(const VideoEncoderConfiguration& config, const RtcConnection& connection) = 0;
Each configuration profile corresponds to a set of video parameters, including the resolution, frame rate, and bitrate.
The config specified in this method is the maximum values under ideal network conditions. If the network condition is not good, the video engine cannot use the config renders local video, which automatically reduces to an appropriate video parameter setting.
Parameters
- config
- Video profile. See VideoEncoderConfiguration.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
startChannelMediaRelayEx
Starts relaying media streams across channels. This method can be used to implement scenarios such as co-host across channels.
virtual int startChannelMediaRelayEx(const ChannelMediaRelayConfiguration& configuration, const RtcConnection& connection) = 0;
- If the onChannelMediaRelayStateChanged callback returns RELAY_STATE_RUNNING (2) and RELAY_OK (0), and the onChannelMediaRelayEvent callback returns RELAY_EVENT_PACKET_SENT_TO_DEST_CHANNEL (4), it means that the SDK starts relaying media streams between the source channel and the destination channel.
- If the onChannelMediaRelayStateChanged callback returnsRELAY_STATE_FAILURE (3), an exception occurs during the media stream relay.
- Call this method after joining the channel.
- This method takes effect only when you are a host in a live streaming channel.
- After a successful method call, if you want to call this method again, ensure that you call the stopChannelMediaRelayEx method to quit the current relay.
- The relaying media streams across channels function needs to be technical support enabled.
- We do not support string user accounts in this API.
Parameters
- configuration
- The configuration of the media stream relay. See ChannelMediaRelayConfiguration.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
- -1: A general error occurs (no specified reason).
- -2: The parameter is invalid.
- -7: The method call was rejected. It may be because the SDK has not been initialized successfully, or the user role is not an host.
- -8: Internal state error. Probably because the user is not an audience member.
startRtmpStreamWithoutTranscodingEx
Starts pushing media streams to a CDN without transcoding.
virtual int startRtmpStreamWithoutTranscodingEx(const char* url, const RtcConnection& connection) = 0;
- Since
- v4.1.0
You can call this method to push an audio or video stream to the specified CDN address. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.
- Ensure that you enable the media push service before using this function.
- Call this method after joining a channel.
- Only hosts in the LIVE_BROADCASTING profile can call this method.
- If you want to retry pushing streams after a failed push, make sure to call stopRtmpStream first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.
Parameters
- url
- The address of media push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
startRtmpStreamWithTranscodingEx
Starts Media Push and sets the transcoding configuration.
virtual int startRtmpStreamWithTranscodingEx(const char* url, const LiveTranscoding& transcoding, const RtcConnection& connection) = 0;
- Since
- v4.1.0
You can call this method to push a live audio-and-video stream to the specified CDN address and set the transcoding configuration. This method can push media streams to only one CDN address at a time, so if you need to push streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.
- Ensure that you enable the Media Push service before using this function.
- Call this method after joining a channel.
- Only hosts in the LIVE_BROADCASTING profile can call this method.
- If you want to retry pushing streams after a failed push, make sure to call stopRtmpStreamEx first, then call this method to retry pushing streams; otherwise, the SDK returns the same error code as the last failed push.
Parameters
- url
- The address of media push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
- transcoding
-
The transcoding configuration for media push. See LiveTranscoding.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
stopChannelMediaRelayEx
Stops the media stream relay. Once the relay stops, the host quits all the destination channels.
virtual int stopChannelMediaRelayEx(const RtcConnection& connection) = 0;
After a successful method call, the SDK triggers the onChannelMediaRelayStateChanged callback. If the callback reports RELAY_STATE_IDLE (0) and RELAY_OK (0), the host successfully stops the relay.
Parameters
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
stopRtmpStreamEx
Stops pushing media streams to a CDN.
virtual int stopRtmpStreamEx(const char* url, const RtcConnection& connection) = 0;
You can call this method to stop the live stream on the specified CDN address. This method can stop pushing media streams to only one CDN address at a time, so if you need to stop pushing streams to multiple addresses, call this method multiple times.
After you call this method, the SDK triggers the onRtmpStreamingStateChanged callback on the local client to report the state of the streaming.
Parameters
- url
- The address of media push. The format is RTMP or RTMPS. The character length cannot exceed 1024 bytes. Special characters such as Chinese characters are not supported.
Returns
- 0: Success.
- < 0: Failure.
takeSnapshotEx
Takes a snapshot of a video stream.
virtual int takeSnapshotEx(const RtcConnection& connection, uid_t uid, const char* filePath) = 0;
This method takes a snapshot of a video stream from the specified user, generates a JPG image, and saves it to the specified path.
The method is asynchronous, and the SDK has not taken the snapshot when the method call returns. After a successful method call, the SDK triggers the onSnapshotTaken callback to report whether the snapshot is successfully taken, as well as the details for that snapshot.
- Call this method after the joinChannelEx method.
- This method takes a snapshot of the published video stream specified in ChannelMediaOptions.
- If the user's video has been preprocessed, for example, watermarked or beautified, the resulting snapshot includes the pre-processing effect.
Parameters
- connection
- The connection information. See RtcConnection.
- uid
- The user ID. Set uid as 0 if you want to take a snapshot of the local user's video.
- filePath
-
The local path (including filename extensions) of the snapshot. For example:
- Windows:
C:\Users\<user_name>\AppData\Local\Agora\<process_name>\example.jpg
- iOS:
/App Sandbox/Library/Caches/example.jpg
- macOS:
~/Library/Logs/example.jpg
- Android:
/storage/emulated/0/Android/data/<package name>/files/example.jpg
- Windows:
Returns
- 0: Success.
- < 0: Failure.
updateChannelMediaOptionsEx
Updates the channel media options after joining the channel.
virtual int updateChannelMediaOptionsEx(const ChannelMediaOptions& options, const RtcConnection& connection) = 0;
Parameters
- options
- The channel media options. See ChannelMediaOptions.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
- -2: The value of a member in the ChannelMediaOptions structure is invalid. For example, the token or the user ID is invalid. You need to fill in a valid parameter.
- -7: The IRtcEngine object has not been initialized. You need to initialize the IRtcEngine object before calling this method.
- -8: The internal state of the IRtcEngine object is wrong. The possible reason is that the user is not in the channel. Agora recommends using the onConnectionStateChanged callback to get whether the user is in the channel. If you receive the CONNECTION_STATE_DISCONNECTED (1) or CONNECTION_STATE_FAILED (5) state, the user is not in the channel. You need to call joinChannel [2/2] to join a channel before calling this method.
updateChannelMediaRelayEx
Updates the channels for media stream relay.
virtual int updateChannelMediaRelayEx(const ChannelMediaRelayConfiguration& configuration, const RtcConnection& connection) = 0;
After the media relay starts, if you want to relay the media stream to more channels, or leave the current relay channel, you can call the updateChannelMediaRelay method.
After a successful method call, the SDK triggers the onChannelMediaRelayEvent callback with the RELAY_EVENT_PACKET_UPDATE_DEST_CHANNEL (7) state code.
onChannelMediaRelayStateChanged(RELAY_STATE_RUNNING, RELAY_OK)
; otherwise, the method call fails.Parameters
- configuration
- The configuration of the media stream relay. See ChannelMediaRelayConfiguration.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.
updateRtmpTranscodingEx
Updates the transcoding configuration.
virtual int updateRtmpTranscodingEx(const LiveTranscoding& transcoding, const RtcConnection& connection) = 0;
After you start pushing media streams to CDN with transcoding, you can dynamically update the transcoding configuration according to the scenario. The SDK triggers the onTranscodingUpdated callback after the transcoding configuration is updated.
Parameters
- transcoding
-
The transcoding configuration for media push. See LiveTranscoding.
- connection
- The connection information. See RtcConnection.
Returns
- 0: Success.
- < 0: Failure.