this document primarily introduces how to use RTC Room Engine SDK to implement video setting related features.
Prerequisites
Before using the video setting related features provided by RTC Room Engine SDK, you need to log in to the SDK. User Guide
Turn On/Off Local Camera
You can turn on or off your local camera by calling two APIs: openLocalCamera and closeLocalCamera.
The openLocalCamera API requires the input of two parameters: select front or rear camera isFront and video quality quality. isFront is a Boolean value, where true means opening the front camera and false means opening the rear camera. quality is an enumeration of type TUIVideoQuality.
|
quality360P | Low-definition 360P |
quality540P | Standard-definition 540P |
quality720P | HD 720P |
quality1080P | Ultra HD 1080P |
Below is an example code for opening the local microphone and closing the local camera, taking opening the front camera and setting the video quality to quality1080P as an example.
You can turn on or off your local camera by calling two APIs: openLocalCamera and closeLocalCamera.
The openLocalCamera API requires the input of two parameters: select front or rear camera isFront and video quality quality. isFront is a Boolean value, where true means opening the front camera and false means opening the rear camera. quality is an enumeration of type VideoQuality.
|
Q_360P | Low-definition 360P |
Q_540P | Standard-definition 540P |
Q_720P | HD 720P |
Q_1080P | Ultra HD 1080P |
Below is an example code for opening the local microphone and closing the local camera, taking opening the front camera and setting the video quality to Q_1080P as an example.
import RTCRoomEngine
let roomEngine = TUIRoomEngine.sharedInstance()
let isFrontCamera = true
let videoQuality: TUIVideoQuality = .quality1080P
roomEngine.openLocalCamera(isFront: isFrontCamera, quality: videoQuality) {
} onError: { code, message in
}
roomEngine.closeLocalCamera()
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();
boolean isFrontCamera = true;
TUIRoomDefine.VideoQuality videoQuality = TUIRoomDefine.VideoQuality.Q_1080P;
roomEngine.openLocalCamera(isFrontCamera, videoQuality, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
roomEngine.closeLocalCamera();
Set Local Video Image Mirror
The following is an example of turning on local video mirror. You can turn on/off the local video mirror through the following code.
import RTCRoomEngine
import TXLiteAVSDK_Professional
let trtcCloud = TUIRoomEngine.sharedInstance().getTRTCCloud()
let params = TRTCRenderParams()
params.mirrorType =.enable
trtcCloud.setLocalRenderParams(params)
trtcCloud.setVideoEncoderMirror(true)
TRTCCloud trtcCloud = TUIRoomEngine.sharedInstance().getTRTCCloud();
TRTCCloudDef.TRTCRenderParams params = new TRTCCloudDef.TRTCRenderParams();
params.mirrorType = TRTC_VIDEO_MIRROR_TYPE_ENABLE;
trtcCloud.setLocalRenderParams(params);
trtcCloud.setVideoEncoderMirror(true);
Switch Camera
When calling the switchCamera API to switch the camera, a Bool parameter frontCamera is required. Passing in true switches to the front-facing camera, and passing in false switches to the rear camera. The following is the example code for switching to the front-facing camera:
import RTCRoomEngine
TUIRoomEngine.sharedInstance().getMediaDeviceManager().switchCamera(true)
TUIRoomEngine.sharedInstance().getMediaDeviceManager().switchCamera(true);
Update Local Video Encoding Quality
When updating the local video encoding quality, the parameter type TUIVideoQuality required is the same as mentioned above. Below is an example of using the default mode to call the updateVideoQuality API to update the encoding quality of the local video:
import RTCRoomEngine
let videoQuality: TUIVideoQuality = .quality1080P
TUIRoomEngine.sharedInstance().updateVideoQuality(videoQuality)
When updating the local video encoding quality, the parameter type VideoQuality required is the same as mentioned above. Below is an example of using the default mode to call the updateVideoQuality API to update the encoding quality of the local video:
TUIRoomDefine.VideoQuality videoQuality = TUIRoomDefine.VideoQuality.Q_1080P;
TUIRoomEngine.sharedInstance().updateVideoQuality(videoQuality);
Set Encoding Parameters for Video Encoder
When setting the encoding parameters for the video encoder, the parameter type TUIRoomVideoEncoderParams is required. Below is an example of using the default mode to call the updateVideoQualityEx API to update the encoding quality of the local video:
Introduction to TUIRoomVideoEncoderParams Parameters
|
Resolution | videoResolution |
Frame Rate | fps |
Resolution Mode | resolutionMode |
Maximum Bit Rate | bitrate |
import RTCRoomEngine
let roomEngine = TUIRoomEngine.sharedInstance()
let params = TUIRoomVideoEncoderParams()
params.fps = 10
params.resolutionMode =.portrait
params.bitrate =.1600
params.videoResolution =.quality720P
roomEngine.updateVideoQualityEx(streamType: .screenStream, params: params)
When setting the encoding parameters for the video encoder, the parameter type TUIRoomDefine.RoomVideoEncoderParams is required. Below is an example of using the default mode to call the updateVideoQualityEx API to update the encoding quality of the local video:
Introduction to TUIRoomDefine.RoomVideoEncoderParams Parameters
|
Resolution | videoResolution |
Frame Rate | fps |
Resolution Mode | resolutionMode |
Maximum Bit Rate | bitrate |
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();
TUIRoomDefine.RoomVideoEncoderParams params = new TUIRoomDefine.RoomVideoEncoderParams();
params.videoResolution = TUIRoomDefine.VideoQuality.Q_720P;
params.bitrate = 1600;
params.fps = 10;
params.resolutionMode = TUIRoomDefine.ResolutionMode.PORTRAIT;
roomEngine.updateVideoQualityEx(TUIRoomDefine.RoomVideoEncoderParams params)
Start/Stop Pushing Local Video
When you are in the live streaming room, you may need to start/stop pushing your local video. You can achieve this by calling the following APIs:
import RTCRoomEngine
let roomEngine = TUIRoomEngine.sharedInstance()
roomEngine.startPushLocalVideo()
roomEngine.stopPushLocalVideo()
TUIRoomEngine roomEngine = TUIRoomEngine.sharedInstance();
roomEngine.startPushLocalVideo();
roomEngine.stopPushLocalVideo();
Note:
Inside the room, if you have already opened your camera and called the above API to start/stop pushing local video, the SDK will notify users in the room through TUIRoomObserver with the onUserVideoStateChanged callback.