Advanced
Learn how to mute audio, disable video, switch camera, share your screen, configure media settings, etc.
Mute audio
Mute the audio by calling localMediaStream.audioTrack.enabled()
method. Using this method, we can tell SDK to send/not send audio data either from a local or remote peer in the specified call session.
Mute remote audio
You can always get remote audio tracks for a specific user ID in the call using the below-specified QBRTCSession
methods (assuming that they are existent).
You can also mute remote media tracks on your side by changing the value of enabled property for a specific remote media track.
QBRTCAudioTrack
class (that represents remote audio track for a specific user) supports audio data sink through QBRTCAudioTrackSinkInterface
protocol. In order to access audio data in a real time simply subscribe to sink interface using methods below.
Now, you can handle the protocol method to access audio data.
This interface provides AudioBufferList with audio data, AudioStreamBasicDescription description of audio data, a number of frames in the current packet, and current media time that conforms to each packet.
Disable video
Turn off/turn on the video by calling localMediaStream.videoTrack.enabled()
. Using this method, we can tell SDK not to send video data either from a local or remote peer in the specified call session.
Due to webrtc restrictions black frames will be placed into stream content if video is disabled.
Switch camera
You can switch the video camera during a call. (Default: front camera)
Manage audio session
QuickbloxWebRTC has its own audio session management which you need to use. It’s located in the QBRTCAudioSession
class. This class is represented as singleton and you can always access a shared session by calling the instance()
method.
See the QBRTCAudioSession
class header for more information.
Configure
You can configure an audio session using the setConfiguration()
method.
The setConfiguration()
method accepts the configuration
argument of the object type with the following fields:
Field | Required | Description |
---|---|---|
categoryOptions | no | Audio session category options allow to tailor the behavior of the active audio session category. Default: allowBluetooth. See Apple documentation to learn about supported values. |
mode | no | Audio session mode allows to assign specialized behavior to an audio session category. Default: videoChat. See Apple documentation to learn about supported values. |
Activate
Activate an audio session before every call.
The setActive()
, method accepts the following argument:
Agrument | Required | Description |
---|---|---|
isActive | yes | Boolean paramater. Set the true to activate an audio session. |
The setConfiguration()
accepts the following arguments:
Argument | Required | Description |
---|---|---|
configuration | yes | Audio session configuration object. You can set the configuration object fields. See this section to learn how to set audio session configuration. |
isActive | yes | Boolean paramater. Set the true to activate an audio session. |
Deactivate
Deactivate an audio session after the call ends.
Argument | Required | Description |
---|---|---|
isActive | yes | Boolean paramater. Set the true to activate an audio session. |
Set audio output
You can output audio either from the receiver unless you set the AVAudioSessionModeVideoChat
mode or speaker.
Argument | Required | Descriotion |
---|---|---|
receiver/speaker | yes | State for the current audio category. |
Screen sharing
Screen sharing allows you to share information from your application to all of your opponents. It gives you the ability to promote your product, share a screen with formulas to students, distribute podcasts, share video/audio/photo moments of your life in real-time all over the world.
To implement this feature in your application, we give you the ability to create custom video capture.
Video capture is a base class you should inherit from in order to send frames to your opponents. There are two ways to implement this feature in your application.
Due to Apple iOS restrictions, screen sharing feature works only within the app it is used in.
1. iOS 11 and newer.
With iOS 11, Apple has introduced a new way to capture your in-app screen using ReplayKit’s RPScreenRecorder class. This is the most optimal way to share screen and requires minimum resources as this is handled by iOS itself. However, the minimum requirement is iOS 11.
The self.screenCapture
should be a property of QBRTCVideoCapture
class type.
30 fps is a maximum rate for WebRTC, even though RPScreenRecorder
supports 60 fps, you must set it to 30 or lower.
2. iOS 10 and older.
This way is a little bit tricky and you will not be able to achieve resource-free 30 fps screen sharing. The maximum fps rate we recommend here is 5 as this a very resource-heavy operation.
QBRTCVideoCapture
class allows sending frames to your opponents. By inheriting this class you are able to provide custom logic to create frames, modify them, and then send to your opponents. Below you can find an example of how to implement a custom video capture and send frames to your opponents (this class is designed to share 5 screenshots per second).
WebRTC stats reporting
Stats reporting is an insanely powerful tool which can help to debug a call if there are any problems with it (e.g. lags, missing audio/video etc). To enable stats report you should first set stats reporting frequency using setStatsReportTimeInterval()
method below.
Now you will be able to receive a client delegate callback and perform operations with QBRTCStatsReport
instance for the current period of time.
By calling statsString()
, you will receive a generic report string, which will contain the most useful data to debug a call, for example:
CN
Connection info.
*VS
Video sent.VR
Video received.AvgQP
Average quantization parameter (only valid for video; it is calculated as a fraction of the current delta sum over the current delta of encoded frames; low value corresponds with good quality; the range of the value per frame is defined by the codec being used).AS
Audio sent.AR
Audio received.
You can also use stats reporting to see who is currently talking in a group call. You must use audioReceivedOutputLevel
for that.
Take a look at the QBRTCStatsReport
header file to see all of the other stats properties that can be useful for you.
Calling offline users (CallKit)
Before starting you need to configure APNS and/or VOIP push certificate in your admin panel. Use this guide to add push notifications feature to your QuickBlox application.
Generic push notifications
You can send a regular push notification to users you call, this will notify them about your call (if they have subscribed to push notifications in their app, see Push notifications guide).
Apple CallKit using VOIP push notifications
QuickbloxWebRTC fully supports Apple CallKit. In this block, we will guide you through the most important things you need to know when integrating CallKit into your application. To learn more about this process, review the above-specified link.
Project preparations
In your Xcode project, make sure that your app supports Voice over IP services. For that open your Info.plist and make sure you have a specific line in Required background modes array:
Now you are ready to integrate CallKit methods using Apple guide here.
Managing audio session
CallKit requires you to manage Audio session by yourself. Use QBRTCAudioSession
instance for that task. See Manage audio session section for more information.
Initializing audio session
You must initialize audio session every time before you call the reportNewIncomingCall(with:update:completion:)
method of CXProvider
showing the incoming call screen. Before initializing the audio session, set useManualAudio
property value to YES
. This will not activate WebRTC audio before iOS allows it. You will need to activate audio manually later. See Manage audio session section for more information.
Managing audio session activations
CXProviderDelegate
has 2 delegate methods that you must conform to:
provider(_:didActivate:)
provider(_:didDeactivate:)
Using QBRTCAudioSessionActivationDelegate
protocol of QBRTCAudioSession
class, you need to notify that the session was activated outside of it. The provider(_:didActivate:)
is a CXProviderDelegate
where we need to activate our audio manually. Set audioEnabled
property of QBRTCAudioSession
class in here, to enable WebRTC audio as iOS has pushed audio session priority of our app to the top.
Deinitializing audio session
Deinitialize audio session every time CXProvider
deactivates it in provider(_:didDeactivate)
of CXProviderDelegate
. Deinitializing audio session earlier would lead to issues with the audio session.
If you also have the deinitialization code of QBRTCAudioSession
somewhere else in your app, you can check and ignore it with QBRTCAudioSessionActivationDelegate
audioSessionIsActivatedOutside()
method. By this, you will know for sure that CallKit is in charge of your audio session. Do not forget to restore QBRTCAudioSession
properties to default values in provider(_:perform:)
method of CXProviderDelegate
.
General settings
You can change different settings for your calls using QBRTCConfig
class. All of them are listed below.
Answer time interval
If an opponent hasn’t answered you within an answer time interval, then session(_:userDidNotRespond:)
and session(_:connectionClosedForUser:)
delegate methods will be called. The answer time interval shows how much time an opponent has to answer your call. Set the answer time interval using the code snippet below.
- By default, the answer time interval is 45 seconds.
- The maximum values is 60 seconds.
- The minimum value is 10 seconds.
Dialing time interval
Dialing time interval indicates how often to notify your opponents about your call. Set the dialing time interval using the code snippet below.
- By default, the dialing time interval is 5 seconds.
- The minimum value is 3 seconds.
Datagram Transport Layer Security
Datagram Transport Layer Security (DTLS) is used to provide communications privacy for datagram protocols. This fosters a secure signaling channel that cannot be tampered with. In other words, no eavesdropping or message forgery can occur on a DTLS encrypted connection.
By default, DTLS is enabled.
Custom ICE servers
You can customize a list of ICE servers. By default, WebRTC module will use internal ICE servers that are usually enough, but you can always set your own. WebRTC engine will choose the TURN relay with the lowest round-trip time. Thus, setting multiple TURN servers allows your application to scale-up in terms of bandwidth and number of users. Review our Setup guide to learn how to configure custom ICE servers.
Media settings
You can configure a variety of media settings such as video/audio codecs, camera resolution, etc.
Video codecs
You can choose video codecs from available values:
QBRTCVideoCodecVP8
- VP8 video codecQBRTCVideoCodecH264Baseline
- h264 baseline video codecQBRTCVideoCodecH264High
- h264 high video codec
VP8 is a software-supported video codec on Apple devices, which means it is the most demanding among all available ones.
H264 is a hardware-supported video codec, which means that it is the most optimal one for use when performing video codec. Using hardware acceleration, you can always guarantee the best performance when encoding and decoding video frames. There are two options available:
- baseline is the most suited one for video calls as it has a low cost (default value).
- high is mainly suited for broadcast to ensure you have the best picture possible. Takes more resources to encode/decode for the same resolution you set.
This will set your preferred codec as WebRTC will always choose the most suitable one for both sides in a call through negotiations.
Video quality
Video quality depends on the hardware you use. iPhone 4s will not handle FullHD rendering, but iPhone 6+ will. It also depends on the network you use and how many connections you have. For multi-calls, set lower video quality. For 1 to 1 calls, you can set a higher quality.
You can use our formatsWithPosition()
method in order to get all supported formats for a current device.
WebRTC has auto-scaling of video resolution and quality to keep network connection active. To get the best quality and performance, you should use the h264-baseline codec as your preferred one.
- If some opponent user does not support h264, then automatically VP8 will be used.
- If both caller and callee have h264 support, then h264 will be used.
Camera resolution
It’s possible to set custom video resolution using QBRTCVideoFormat
.
Parameters | Description |
---|---|
width | Video width. Default: 640. |
height | Video hight. Default: 480. |
frameRate | Video frames per second. Default: 30. |
pixelFormat | Video pixel format. Default: QBRTCPixelFormat420f |
You can also get a list of available resolution formats using formats(with:)
. Set a needed one from the list using the snippet below,
Audio codecs
You can choose audio codecs from available values:
QBRTCAudioCodecOpus
QBRTCAudioCodecISAC
QBRTCAudioCodeciLBC
By default, QBRTCAudioCodecOpus
is set.
Opus
In the latest versions of Firefox and Chrome. This codec is used by default for encoding audio streams. This codec is relatively new (released in 2012). It implements lossy audio compression. Opus can be used for both low and high bitrates.
- Supported bitrate: constant and variable, from 6 kbit/s to 510 kbit/s.
- Supported sampling rates: from 8 kHz to 48 kHz.
If you develop a Calls application that is supposed to work with high-quality audio, the only choice on audio codecs is OPUS. OPUS has the best quality, but it also requires a good internet connection.
iSAC
This codec was developed specifically for VoIP applications and audio streaming.
- Supported bitrates: adaptive and variable. From 10 kbit/s to 52 kbit/s.
- Supported sampling rates: 32 kHz.
A good choice for the voice data, but not nearly as good as OPUS.
iLBC
This audio codec is well-known. It was released in 2004 and became part of the WebRTC project in 2011 when Google acquired Global IP Solutions (the company that developed iLIBC).
When you have very bad channels and low bandwidth, you definitely should try iLBC. It should be strong in such cases.
- Supported bitrates: fixed bitrate. 15.2 kbit/s or 13.33 kbit/s
- Supported sampling rate: 8 kHz.
Thus, when you have a strong reliable and good internet connection, then use OPUS. If you use calls on 3g networks, use iSAC. If you still have problems, try iLBC.
Was this page helpful?