Source and Layer Selection
So now that you have the ability to publish multiple sources in a stream and detect those events within the viewer, the next step is to specify the source you want to receive.
For each audio and video track you can select and switch sources from the Dolby.io Real-time Streaming server and then forward the selected media to the viewer.
This is accomplished using the project
command. You can specify the sourceId
that you want to project, use the trackId
of the source (received on the active
event) for each track, and the mid
of the transceiver object for the media you want to receive.
Here is an example of an activate
event:
{
"name": "active",
"data": {
"streamId": "accoundId/streamName",
"sourceId": "mysource",
"tracks": [{
"trackId": "audio0",
"media": "audio"
}
{
"trackId": "video0",
"media": "video"
}
]
}
}
You can send a project
command to start receiving either of the tracks from the source in one or more of the transceivers you have already setup on the peerconnection:
viewer.project("mysource",[
{
trackId: "audio0",
mediaId: audioTransceiver.mid
},
{
trackId: "video0",
mediaId: videoTransceiver.mid
}
]);
If you want to stop receiving media from one of the sources, you can either send a “project” command to replace the media with a different source, or use the “unproject” command to stop receiving media for that transceiver:
viewer.unproject([videoTransceiver.mid])
By default, the Dolby.io Real-time Streaming server, will choose which is the best Simulcast or SVC layer to forward to the viewer based on the bandwidth estimation calculated by the server.
In addition to selecting the origin source for the media, it is also possible to choose the specific Simulcast and/or SVC layer for each video track delivered by the Dolby.io Real-time Streaming server. You can do that either by specifying the layer
attribute on the project
command or using the select
command for the main video track:
viewer.project("mysource",[
{
trackId: "video0",
mediaId: videoTransceiver.mid
layer:
{
encodingId : "L",
temporalLayerId : 1
}
}
]);
The layer information available for each video source is provided periodically by the layers
event as shown above. If you want to switch back to the automatic layer selection, you would just need to send a project
or select
command with empty layer information.
Note that Dolby.io Real-time Streaming will not limit the number of tracks that a viewer is able to receive, but will limit the maximum bitrate per viewer to a maximum of 12 Mbps across all media tracks. You should configure the Simulcast/SVC bitrate of all the sources carefully within your Applications so they can receive the desired amount of video tracks in the viewer session.
Updated 3 months ago