Skip to content

Commit e73893a

Browse files
committed
Calls: Add Simulcast documentation text
1 parent b9a1071 commit e73893a

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
pcx_content_type: get-started
3+
title: Simulcast
4+
sidebar:
5+
order: 8
6+
---
7+
8+
Simulcast is a feature of WebRTC that allows a publisher to send multiple streams of the same media at different qualities. For example, this is useful for scenarios where you want to send a high quality stream for desktop users and a lower quality stream for mobile users.
9+
10+
```mermaid
11+
graph LR
12+
A[Publisher] -->|Low quality| B[Cloudflare Calls SFU]
13+
A -->|Medium quality| B
14+
A -->|High quality| B
15+
B -->|Low quality| C@{ shape: procs, label: "Subscribers"}
16+
B -->|Medium quality| D@{ shape: procs, label: "Subscribers"}
17+
B -->|High quality| E@{ shape: procs, label: "Subscribers"}
18+
19+
```
20+
21+
### How it works
22+
23+
Simulcast in WebRTC allows a single media source, like a camera or screen share, to be encoded at multiple quality levels and sent simultaneously, which is beneficial for subscribers with varying network conditions and device capabilities. The media source is encoded into multiple streams, each identified by RIDs (RTP Stream Identifiers) for different quality levels, such as low, medium, and high. These simulcast streams are described in the SDP you send to Cloudflare Calls SFU. It's the responsibility of the Cloudflare Calls SFU to ensure that the appropriate quality stream is delivered to each subscriber based on their network conditions and device capabilities.
24+
25+
Cloudflare Calls SFU will automatically handle the simulcast configuration based on the SDP you send to it from the publisher. The SFU will then automatically switch between the different quality levels based on the subscriber's network conditions. You can control the quality switching behavior using the `simulcast` configuration object when you send an API call to start pulling a remote track.
26+
27+
### Quality Control
28+
29+
The `simulcast` configuration object in the API call when you start pulling a remote track allows you to specify:
30+
31+
- `preferredRid`: The preferred stream (RID for the simulcast stream. [RIDs can be specified by the publisher.](https://developer.mozilla.org/en-US/docs/Web/API/RTCRtpSender/setParameters#encodings))
32+
- `priorityOrdering`: Controls how the SFU handles bandwidth constraints
33+
- `none`: Keep sending the preferred layer even if there's not enough bandwidth
34+
- `asciibetical`: Use alphabetical ordering (a-z) to determine priority, where 'a' is most desirable and 'z' is least desirable
35+
- `ridUnavailableStrategy`: Controls what happens when the preferred RID is no longer available, for example when the publisher stops sending it
36+
37+
- `none`: Do nothing
38+
- `nextPriority`: Switch to the next available RID based on the priority ordering
39+
40+
You will likely want to order the asciibetical RIDs based on your desired metric, such as higest resoltion to lowest or highest bandwidth to lowest.
41+
42+
### Bandwidth Management across media tracks
43+
44+
Cloudflare Calls treats all media tracks equally at the transport level. For example, if you have multiple video tracks (cameras, screen shares, etc.), they all have equal priority for bandwidth allocation. This means:
45+
46+
1. Each track's simulcast configuration is handled independently
47+
1. The SFU performs automatic bandwidth estimation and layer switching based on network conditions independently for each track
48+
49+
### Layer Switching Behavior
50+
51+
When a layer switch is requested (through updating `preferredRid`) with the `/tracks/update` API:
52+
53+
1. The SFU will automatically generate a Picture Loss Indication (PLI)
54+
2. Layer switching only occurs when a keyframe arrives on the target layer
55+
3. PLI generation is debounced to prevent excessive requests
56+
57+
### Publisher Configuration
58+
59+
For publishers (local tracks), you only need to include the simulcast attributes in your SDP. The SFU will automatically handle the simulcast configuration based on the SDP. For example, the SDP should contain a section like this:
60+
61+
```sdp
62+
a=simulcast:send f;h;q
63+
a=rid:f send
64+
a=rid:h send
65+
a=rid:q send
66+
```
67+
68+
## Example
69+
70+
Here's an example of how to use simulcast with Cloudflare Calls:
71+
72+
1. Create a new local track with simulcast configuration. There should be a section in the SDP with `a=simulcast:send`.
73+
2. Use the [Cloudflare Calls API](/calls/https-api) to push this local track, by calling the /tracks/new endpoint.
74+
3. Use the [Cloudflare Calls API](/calls/https-api) to start pulling a remote track (from another browser or device), by calling the /tracks/new endpoint and specifying the `simulcast` configuration object along with the remote track ID you get from step 2.
75+
76+
For more examples, check out the [Calls Examples GitHub repository](https://github.com/cloudflare/calls-examples/tree/main/simulcast).

0 commit comments

Comments
 (0)