In a previous post some of the upcoming changes made for Asterisk 15 have been discussed. Specifically, one of the items mentioned is the beginnings of a multi-stream media framework. Starting in 15, groundwork has been laid that greatly enhances media flow in Asterisk. Taking advantage of this new architecture, changes have also been made that now allow Asterisk to act as a selective forwarding unit (SFU) with regards to video.
Stream the Streams
In Asterisk, streams are simply logical flows of media. In previous versions, prior to 15, only a single pipe is used to exchange media between endpoints for a session. And while different media types are handled (audio/video/text), only a single instance of each type is supported. For instance, only one flow of video is allowed, thus limiting its usefulness in conferencing applications.
However, in Asterisk 15 the single pipe has been swapped for multiple ones. For supported channel drivers (currently only PJSIP) it’s now possible to convey multiple streams of media for multiple media types. For example with regards to video, a signaling single session is now capable of negotiating, and then sending and receiving both VP8 and H.264.
To enable multi-stream support in the PSJIP channel driver you’ll need to set max_audio_streams and max_video_streams options for a given endpoint to something greater than “1”, which is the default. Note, there is hard limit, set within pjproject, to the total number of streams allowed (for all combinations). If using “pjproject bundled” for Asterisk this number is currently set to 16.
Selective Forwarding Unit
So that multi-streaming stuff is all good, but what’s a practical use case? I’m glad you asked. As mentioned, with respect to video, Asterisk can now act as a selective forwarding unit (SFU). Meaning it is capable of processing multiple video streams, and then selecting which video streams are forwarded to which endpoint. This of course is directly applicable to video conferencing.
By configuring app_confbridge correctly, and setting the video_mode appropriately (to “sfu”) you can enable multi-user video conferencing within Asterisk that allows each participant to see all other participants:
Stop, Demo Time
We created a demo/example WebRTC application called:
Or CMP2K for short. And while you can’t touch the Hammer I encourage you to download and interact with the demo. To do so, start by configuring your Asterisk 15+ server for WebRTC and set up one or more PJSIP endpoints. If you are unsure how to do that then this guide will show you how. However, instead of using SIPML5 we’ll be using CMP2K as the client instead. To begin, here is the http configuration settings I used (http.conf):
[general] enabled=yes bindaddr=0.0.0.0 bindport=8088 tlsenable=yes tlsbindaddr=0.0.0.0:8089 tlscertfile=/etc/asterisk/keys/asterisk.pem
Here is the pjsip configuration I used – don’t forget to set the max_audio_streams and max_video_streams options as mentioned above (pjsip.conf):
[transport_wss] type=transport bind=0.0.0.0 protocol=wss [guest] type=aor max_contacts=5 [guest] type=endpoint context=default direct_media=no allow=!all,ulaw,vp8,h264 aors=guest max_audio_streams=10 max_video_streams=10 webrtc=yes dtls_cert_file=/etc/asterisk/keys/asterisk.pem dtls_ca_file=/etc/asterisk/keys/ca.crt
Next configure a confbridge and set the video_mode to “sfu” (confbridge.conf):
[general] [default_bridge] type=bridge video_mode=sfu [default_user] type=user music_on_hold_when_empty=yes music_on_hold_class=default
Lastly add some dialplan to call into the StreamEcho application and/or the conference (extensions.conf):
[default] exten => echo,1,Answer() same => n,StreamEcho(3) same => n,Hangup() exten => video-conference,1,Answer() same => n,ConfBridge(guest) same => n,Hangup()
Now that Asterisk has been setup, start it, and then open the “index.html” file (in either Firefox or a Chrome/Chromium browser) that’s in the top level directory of CMP2K. You should see something like the following:
It’s quite a fancy application I know! Press the “account” button and enter your PJSIP endpoint information as well as the extension to dial. Note, the grey text in the account settings are the defaults used. If you specified different values for your endpoint configuration you’ll need enter a value overriding the default. “ID” is your endpoint name. I didn’t attach any authorization settings to my endpoint so the name and password are not applicable.
Close the window and press the “connect” button. You should now be connected to Asterisk via a websocket, and registered if your endpoint settings required it.
[dropshadowbox align=”none” effect=”lifted-both” width=”auto” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]NOTE: Having trouble connecting? You may need to import your self-signed certificate into your browser’s keychain. However, for now it’s probably easier to just open a separate browser tab and point it to Asterisk’s HTTP server’s TLS port and WS path, e.g. http://[ ip of asterisk server ]:8089/ws, and you can manually confirm the security exception from there.[/dropshadowbox]
Press the “call” button. If you dialed the echo application you should see “n” number of video streams being echoed back to you:
If you called the video-conference extension (If you didn’t try now. Hangup, open the account settings again, and enter the new extension) you should see yourself only. At least until others show up. I found a couple of friends willing to join my conference:
In the above you’ll note that there is an “Audio Only” section with no video. This is the audio stream of the conference bridge. Muting it mutes the audio on the bridge itself. Meaning you’ll stop hearing audio from Asterisk.
Where to From Here
As indicated earlier, the new multi-stream media work in Asterisk 15 is a great start. A solid foundation has been established, and we’ve just seen that Asterisk can now act as an SFU giving users a nice video conferencing experience. More work is surely to come in this area and others as the 15 branch continues to be developed, so be sure to keep a close eye on things.