If Real-Time Communication (RTC) SDK is not properly configured or used, the time consumed in the use of RTC SDK may be prolonged. This topic describes how to reduce the time consumed in the use of RTC SDK.
Properly configure automatic subscription and automatic stream ingest
- If you want to ingest streams right after you join a channel, we recommend that you enable automatic stream ingest.
- If you want to subscribe to streams right after you join a channel, we recommend that you enable automatic subscription. This way, the ingested streams are automatically subscribed to after you receive a stream ingest callback notification. This saves a large amount of time.
To enable automatic subscription and automatic stream ingest, call the following method:
setAutoPublish: specifies whether to enable automatic subscription and automatic stream ingest. By default, the two features are enabled. You must call this method before you join a channel.
- (int)setAutoPublish:(BOOL)autoPub withAutoSubscribe:(BOOL)autoSub;Properly call the publish and subscribe methods
- You can call the publish and subscribe methods to manually ingest and subscribe to streams and modify the configurations of stream ingest and subscription.
- The publish method takes effect only if you call the configLocalCameraPublish, configLocalScreenPublish, and configLocalAudioPublish methods.
- The subscribe method takes effect only if you call the configRemoteCameraTrack, configRemoteScreenTrack, and configRemoteAudio methods.
- Ingest the major and minor streams of a video track based on your requirements. By default, the minor stream is ingested. If the minor stream is not required, we recommend that you modify the configurations to disable stream ingest for the minor stream.
- You can call the publish or subscribe method after you modify all the configurations. You do not need to call the publish or subscribe method every time you modify a configuration item. For example, to enable stream ingest for an audio track and a camera track, and disable stream ingest for a screen track, you can call the following methods:
- Correct example:
[self.engine configLocalAudioPublish:YES]; [self.engine configLocalCameraPublish:YES]; [self.engine configLocalScreenPublish:NO]; [self.engine configLocalSimulcast:NO forTrack:AliRtcVideoTrackCamera]; [self.engine publish:^(int err) { // Perform operations on the UI. }]; - Incorrect example:
[self.engine configLocalAudioPublish:YES]; [self.engine publish:^(int err) { // Perform operations on the UI. }]; [self.engine configLocalCameraPublish:YES]; [self.engine publish:^(int err) { // Perform operations on the UI. }]; [self.engine configLocalScreenPublish:NO]; [self.engine publish:^(int err) { // Perform operations on the UI. }]; [self.engine configLocalSimulcast:NO forTrack:AliRtcVideoTrackCamera]; [self.engine publish:^(int err) { // Perform operations on the UI. }];
- Correct example:
Avoid frequently switching between channels or joining and leaving a channel
- When you use RTC SDK, you can avoid frequently creating and destroying instances. This saves the time consumed in the use of RTC SDK. You can switch between channels by letting an instance join or leave a channel.
- You can start an audio device in advance to save the time consumed by joining or leaving the channel. For example, after you create an instance, you can call the startAudioPlayer method to enable audio playback before you join an audio live streaming channel. Then, you can call the stopAudioPlayer method to disable audio playback before you destroy the instance. You do not need to call the methods when you switch between channels or join or leave a channel. The following code provides examples on how to call the startAudioPlayer and stopAudioPlayer methods:
startAudioPlayer: enables audio playback.
- (void)startAudioPlayer;Important You can enable audio playback in advance. If you do not set this parameter, the SDK enables audio playback when the subscription succeeds.stopAudioPlayer: Disables audio playback.
- (void)stopAudioPlayer;Important This operation is called before joining.
- You can also decide whether to enable audio collection in advance based on your business requirements.
startAudioCapture: enables audio collection.
- (void)startAudioCapture;Important You can enable audio collection in advance. If you do not set this parameter, the SDK enables audio collection when stream ingest starts.stopAudioCapture: Disables audio collection.
- (void)stopAudioCapture;
该文章对您有帮助吗?