Migrate from Voice SDK 3.x

Updated

Upgrade to the latest version of Voice Calling.

Agora SDK v4.0.0 is a new version of the SDK that you can use to embed real-time video and audio into your app. It supports large-scale real-time interactive activities and provides better real-time interactive effects. For details, see Product overview.

This page introduces the main steps to upgrade the SDK from v3.x (v3.7.0.3 and earlier) to v4.0.0, as well as the related changes.

Migration steps

This section introduces the main steps to upgrade the SDK from v3.x to v4.0.0.

1. Integrate the SDK

When you have downloaded the Agora v4.0.0 Unity SDK, you see a .unitypackage file which can be imported directly into your project in Unity Editor. Once the SDK is successfully integrated, you see an Agora-Video-SDK-Plugin directory in the Assets of your project.

Refer to the quickstart to integrate the v4.0.0 SDK into your project.

2. Update the Agora code in your app

The v4.0.0 SDK has optimized or modified the implementation of some functions, resulting in incompatibility with the v3.x SDK. In order to retain Agora functionality in your app, update the code in your app according to What has changed.

What has changed

This section is based on v3.x and introduces the main changes of v4.0.0 compared to v3.x in the following categories. You need to update the code of your app according to your business use-case.

  • Breaking changes: Introduces API compatibility changes. You need to spend significant time modifying the related implementation.
  • Behavior changes: Introduces changes caused by reasonable optimization of the SDK default behavior and API behavior. Less time is required to modify the related implementation, if any.
  • Function gaps: Introduces functions that were supported in v3.x but are not supported in v4.0.0. However, these functions are intended to be added in a future release.
  • Removed APIs: Introduces APIs that were supported in v3.x but removed in v4.0.0. Most of these APIs have alternatives in v4.0.0. Modifying the related implementation should require less time.
  • Naming and data type changes: Introduces the naming and data type changes of the main APIs. You can update the relevant implementation according to the error message in the IDE, which is expected to take less time.

Breaking changes

After upgrading from v3.x to v4.0.0, the way the APIs implement some functions is different. This section introduces compatibility changes for these APIs and the logic for updating the code of your app.

Multiple channels

In v3.x, the SDK provides the AgoraChannel class and Channel delegate to implement multi-channel control. The v3.x SDK supports subscribing to the audio and video streams of multiple channels, but only supports publishing one group of audio and video streams in one channel.

v4.0.0 introduces the following changes:

  • The SDK supports one IRtcEngine instance to collect multiple audio and video sources at the same time and publish them to the remote users by setting IRtcEngineEx and ChannelMediaOptions.
  • After calling JoinChannel to join the first channel, call JoinChannelEx multiple times to join multiple channels, and publish the specified stream to different channels through different user ID (localUid) and ChannelMediaOptions settings.
  • You can simultaneously publish multiple sets of video streams captured by multiple cameras or screen sharing by setting publishSecondaryCameraTrack and publishSecondaryScreenTrack in ChannelMediaOptions. (Windows)

Combined with the multi-channel capability, you can also experience the following functions:

  • Publish multiple groups of audio and video streams to the remote user through different localUids.
  • Mix multiple audio streams and publish them to the remote user through one localUid.
  • Mix multiple video streams and publish them to the remote user through one localUid.

AgoraChannel and IRtcEngine of v3.x are partially duplicated and overlap in their functionality, so v4.0.0 hides the IChannel and IChannelEventHandler classes. See the sample project for more details on how to replace AgoraChannel with JoinChannel and ChannelMediaOptions. The expected migration cost is one day or less.

If you need to continue to use the AgoraChannel class and Channel delegate, contact support@agora.io. The decision whether to maintain compatibility in a future release is based on your feedback.

Media stream publishing control

In v4.0.0, the SDK gathers more channel-related settings into ChannelMediaOptions, including publishing of audio and video streams from different sources, automatic subscribing of audio and video streams, user role switching, token updating, and default dual stream options. You can determine the media stream publishing and subscribing behavior by calling JoinChannel or JoinChannelEx when joining a channel, or you can flexibly update the media options by calling UpdateChannelMediaOptions after joining a channel, such as switching video sources.

Warning codes

In v3.x, the SDK returns warning codes through the OnWarning callbacks.

To facilitate locating and troubleshooting issues, v4.0.0 reports problems and causes through the return values of APIs or different callbacks for listening to states. For example:

  • OnConnectionStateChanged: Reports the network connection state.
  • OnLocalAudioStateChanged: Reports the local audio state.
  • OnLocalVideoStateChanged: Reports the local video state.
  • OnRemoteAudioStateChanged: Reports the remote audio state.
  • OnRemoteVideoStateChanged: Reports the remote video state.

As a consequence, v4.0.0 removes the OnWarning callback.

In addition to the breaking changes listed here relative to v3.x, v4.0.0 has a small number of breaking changes relative to the v4.0.0 Beta release. For example:

  • In v4.0.0, replace publishAudioTrack in ChannelMediaOptions with publishMicrophoneTrack.

If you used this feature in v4.0.0 Beta and wish to upgrade to v4.0.0, modify the implementation code of the feature after upgrading the SDK.

Behavior changes

This section introduces changes caused by reasonable optimization of the SDK default behavior and API behavior.

Initialize the IRtcEngine

In v3.x, you obtain and initialize the IRtcEngine through the GetEngine (appId) or GetEngine (engineConfig) method.

In v4.0.0, you create an IRtcEngine instance through CreateAgoraRtcEngine or RtcEngine.Instance. You initialize the IRtcEngine through the Initialize method and at the same time, you can also set the channel profile and audio scenario, and config the log files through RtcEngineContext.

Register callback events

In v3.x, you can register callback events with C# delegates.

In v4.0.0, delegates are encapsulated in Agora.Rtc.RtcEngineEventHandler. You can also register callback events through the InitEventHandler method: you need to inherited Agora base classes and implement your own EventHandler class, and register an EventHandler instance through the InitEventHandler.

Release resources

If you need to release all the resources used by the Agora Unity SDK:

In v3.x, you need to call the Destroy method.

In v4.0.0, you need to call the Dispose method.

Channel profile

In v3.x, the default channel profile is CHANNEL_PROFILE_COMMUNICATION (the communication profile).

Because the interactive streaming profile supports seamless switching from one-to-one calls to multi-user interaction, since v3.0.0, Agora has changed the internal transmission protocol and the ability to resist poor network conditions in the communication profile to be consistent with the interactive streaming profile. In v4.0.0, Agora also changed the default channel profile to CHANNEL_PROFILE_LIVE_BROADCASTING (the interactive streaming profile).

Default log file

In v3.x, when the SDK creates multiple log files, the earlier files are named in a agorasdk_x.log format, such as agorasdk_1.log.

v4.0.0 modified the naming format to agorasdk.x.log, such as agorasdk.1.log. Additionally, v4.0.0 adds the agoraapi.log file to record API logs.

Fast channel switching

In v3.x, you need to call SwitchChannel to quickly switch a channel.

In v4.0.0, you can achieve the same switching speed as SwitchChannel in v3.x by switching a channel through LeaveChannel and JoinChannel. Therefore, v4.0.0 removes SwitchChannel. If you call SwitchChannel to quickly switch a channel in v3.x, you need to call LeaveChannel to leave the current channel in v4.0.0 and JoinChannel to join the second channel instead.

Media options

There are differences in the behavior of the SDK when setting channel media options while joining a channel between v3.7.0 and v4.0.0:

  • In v3.7.0, if you set publishLocalAudio in ChannelMediaOptions to false, it will stop publishing the local audio stream within the channel.
  • In v4.0.0, if you set publishMicrophoneTrack in ChannelMediaOptions to false, it will not only stop publishing the local audio stream within the channel but also stop local microphone capture.

Video information change event (iOS)

If the video capture device is adjusted to landscape or portrait mode during video capture, in v3.7.0 and v4.0.0, the following differences exist in the video information change events reported by the SDK:

  • In v3.7.0, the rotation parameter in the OnVideoSizeChanged callback displays the current device rotation information.
  • In v4.0.0, the rotation parameter in the OnVideoSizeChanged callback is always 0.

Agora self-developed extensions

v4.0.0 adds the feature of automatically loading self-developed dynamic libraries based on v4.0.0 Beta. As of this release, when using an Agora self-developed extension, you do not need to manually integrate the dynamic library in the project. The SDK automatically loads the dynamic library during the initialization phase of IRtcEngine. You can directly call the corresponding method of the extension to enable this feature.

APIExtension type
EnableVirtualBackgroundVirtual background extension
  • SetBeautyEffectOptions

  • SetVideoDenoiserOptions

  • SetLowlightEnhanceOptions

  • SetColorEnhanceOptions

Video enhancement extension
EnableRemoteSuperResolutionSuper resolution extension
  • SetAudioEffectPreset

  • SetVoiceBeautifierPreset

  • SetVoiceConversionPreset

Voice beautifier extension
EnableSpatialAudioSpatial audio extensionE
EnableContentInspectContent moderation extension

Virtual metronome

When you call StartRhythmPlayer, the SDK publishes the sound of the virtual metronome to the remote by default. If you do not want the remote users to hear the virtual metronome, refer to the following operations:

In v3.x, call the ConfigRhythmPlayer, and set publish to false. In v4.0.0, set publishRhythmPlayerTrack in ChannelMediaOptions to false.

Volume indication

You can call the EnableAudioVolumeIndication method to enable the user's volume indication function. There is a difference in the definition of the interval parameter in the EnableAudioVolumeIndication method between v3.x and v4.0.0, as follows:

In v3.x, Agora recommends that you set the interval to be greater than 200 ms. The minimum is 10 ms; otherwise, the OnAudioVolumeIndication callback is not received. In v4.0.0, you must set the interval to an integer that is a multiple of 200 ms. If the value of interval is lower than 200, the SDK automatically adjusts it to 200.

When the user's volume indication is enabled, the SDK triggers the OnAudioVolumeIndication callback at the time interval set in this method. If the local user calls MuteLocalAudioStream to mute themselves, the SDK behaves inconsistently between v3.x and v4.0.0:

In v3.x, the SDK immediately stops reporting the local user's volume indication callback. In v4.0.0, the SDK continues to report the local user's volume indication callback.

Device permissions

In v3.x, LOCAL_AUDIO_STREAM_ERROR_DEVICE_NO_PERMISSION in OnLocalAudioStateChanged reports that there is no permission to start the capture device, and LOCAL_VIDEO_STREAM_ERROR_DEVICE_NO_PERMISSION in OnLocalVideoStateChanged reports that there is no permission to start the video capture device.

In v4.0.0, the permission statuses of the audio and video capture devices are both reported in the OnPermissionError callback.

Pre-call network test

If you need to start or stop the network connection quality test, note the following:

In v3.x, you can call EnableLastmileTest to start the network quality test. If you want to stop the network test, you need to call DisableLastmileTest.

In v4.0.0, you can call StartLastmileProbeTest to enable network quality testing. If you want to stop network testing, you need to call StopLastmileProbeTest.

Raw audio and video data

In v3.x, you can manage raw audio and video data through the APIs in AudioRawDataManager and VideoRawDataManager respectively.

In v4.0.0, you call the RegisterAudioFrameObserver or RegisterVideoFrameObserver in the IRtcEngine class to register an audio or video frame observer and monitor the audio or video data, or you can also inherit the IRtcEngine class to implement data monitoring.

Remote media event triggering mechanism In the following use-cases, the mechanism of triggering remote media events is changed:

  • Use-case 1: When the host calls MuteLocalAudioStream or MuteLocalVideoStream outside the channel to change the publishing status of the local audio or video stream and then joins the channel.
  • Use-case 2: When the host calls MuteLocalAudioStream or MuteLocalVideoStream within the channel to change the publishing status of the local audio or video stream, and then other users join the channel.

The behavior differences of Agora SDK between v3.7.0 and v4.0.0 are listed as follow:

  • In v3.7.0, the local user receives the OnRemoteAudioStateChanged or OnRemoteVideoStateChanged callback, which reports the status changes of the remote host's audio or video streams.
  • In v4.0.0, instead of the OnRemoteAudioStateChanged or OnRemoteVideoStateChanged callback, the local user receives the OnUserMuteAudio or OnUserMuteVideo callback, which reports the changes in the remote host's publishing status.

Function gaps

This section introduces functions that were supported in v3.x but are no longer supported or behave inconsistently in v4.0.0. Plans exist to support them or make them consistent in a future release, however.

Audio application scenarios

v4.0.0 reconstructs the audio application scenarios, which can replace most of the audio application scenarios of v3.x. The following table shows the correspondence of audio application scenarios in the two releases:

v3.xv4.0.0
AUDIO_SCENARIO_DEFAULTAUDIO_SCENARIO_DEFAULT
AUDIO_SCENARIO_CHATROOM_ENTERTAINMENTAUDIO_SCENARIO_CHATROOM
AUDIO_SCENARIO_EDUCATIONAUDIO_SCENARIO_DEFAULT
AUDIO_SCENARIO_GAME_STREAMINGAUDIO_SCENARIO_GAME_STREAMING or AUDIO_SCENARIO_HIGH_DEFINITION
AUDIO_SCENARIO_SHOWROOMAUDIO_SCENARIO_DEFAULT
AUDIO_SCENARIO_CHATROOM_GAMINGAUDIO_SCENARIO_CHATROOM
AUDIO_SCENARIO_IOTAUDIO_SCENARIO_DEFAULT
AUDIO_SCENARIO_MEETINGAUDIO_SCENARIO_MEETING

Unsupported functions

Compared to v3.x, some features are not supported or only partially supported in v4.0.0. This section shows the APIs currently unsupported but for which support is planned in a future release.

Remote video stream fallback:

  • SetRemoteUserPriority

Screen sharing:

  • OnScreenCaptureInfoUpdated

Removed APIs

The v4.0.0 removes deprecated or unrecommended APIs. Alternatives to the removed API or reasons for their removal are shown as follows:

  • VideoRawDataManager: Use the APIs in the IVideoFrameObserver class instead.

  • AudioRawDataManager: Use the APIs in the IAudioFrameObserver class instead.

  • PacketObserver: Rarely used in v3.x.

  • EnableFilpTextureApply: Agora recommends you implementing this function by yourself.

  • SetGameFps: Agora recommends you implementing this function by yourself.

  • VirtualBackgroundSourceEnabled: Use the return value of EnableVirtualBackground instead.

  • OnUserSuperResolutionEnabled: Use the OnRemoteVideoStats member of the superResolutionType class instead.

  • SetAudioMixingPlaybackSpeed: Use the relevant API under the IMediaPlayer class instead.

  • SetExternalAudioSourceVolume: Use AdjustCustomAudioPublishVolume instead.

  • GetAudioFileInfo and OnRequestAudioFileInfo: Use GetDuration instead.

  • OnAudioDeviceTestVolumeIndication:Use OnAudioVolumeIndication instead.

  • SetLocalPublishFallbackOption and OnLocalPublishFallbackToAudioOnly: Rarely used in v3.x.

  • RENDER_MODE_FILL(4) in RENDER_MODE_TYPE: This mode can cause image overstretch and is not recommended.

  • The following enumerations in AUDIO_MIXING_REASON_TYPE: Rarely used in v3.x.

    • AUDIO_MIXING_REASON_STARTED_BY_USER
    • AUDIO_MIXING_REASON_START_NEW_LOOP
    • AUDIO_MIXING_REASON_PAUSED_BY_USER
    • AUDIO_MIXING_REASON_RESUMED_BY_USER
  • OnAudioMixingFinished: Use OnAudioMixingStateChanged instead.

  • EnableDeepLearningDenoise: The SDK adds deep-learning noise reduction as one of its capability in a future release instead of implementing through an API.

  • The channel parameter in TakeSnapshot and OnSnapshotTaken: The parameter is redundant.

  • SetDefaultMuteAllRemoteVideoStreams: UseautoSubscribeVideo in the ChannelMediaOptions instead.

  • SetDefaultMuteAllRemoteAudioStreams:Use autoSubscribeAudio in the ChannelMediaOptions instead.

  • LOCAL_VIDEO_STREAM_ERROR_SCREEN_CAPTURE_WINDOW_NOT_SUPPORTED in LOCAL_VIDEO_STREAM_ERROR:Deprecated in v3.x.

  • The replace parameter in StartAudioMixing: Use publishMicrophoneTrack in the ChannelMediaOptions instead.

Naming changes

The naming changes in v4.0.0 cause error messages in the IDE when you compile your project, and you need to update the code of your app according to each error message.

Namespace

  • namespace agora_gaming_rtc is renamed as namespace Agora.Rtc

Classes

  • AudioPlaybackDeviceManager and AudioRecordingDeviceManager are both included in IAudioDeviceManager
  • VideoDeviceManager is changed to IVideoDeviceManager
  • MediaRecorder is changed to IMediaRecorder
  • MetadataObserver is changed to IMetadataObserver
  • AgoraCallback is changed to IRtcEngineEventHandler

APIs and parameters

  • AdjustLoopbackRecordingSignalVolume is changed to AdjustLoopbackSignalVolume.
  • OnFirstLocalAudioFrame is changed to OnFirstLocalAudioFramePublished.
  • The fileSize member in LogConfig is renamed to fileSizeInKB.
  • The options parameter in JoinChannel[2/2] is changed to mediaOptions.
  • The report_vad parameter in enableAudioVolumeIndication is changed to reportVad.