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.
26 Responses
it is great job!
looks great!
can be used with JsSIP? or are there some requirements?
So I have a WebRTC program that I am working on, but am stuck on the bandwidth issue. The program can show from 1 to 5 streams at a time. Picture a news broadcast or talk show with the host broadcaster and up to 4 guests. Broadcaster and guests can see and talk to each other.
The possibility of hundreds or even thousands of viewers. Viewers would be one-way only for audio and video.
Would Asterisk 15 be able to handle this? And how would I interface my existing code to Asterisk?
Thanks,
Ray
Yes it can be used with JsSIP. As a matter of fact that’s the library we used when building CMP2K. If you take a look in the “lib” directory in CMP2K’s source you’ll see it as a dependency.
In theory, Asterisk 15 should be able to handle that scenario. The functionality is in place, however for the specified use case it has not been tested. That being said you are still going to run up against bandwidth issues. You’d probably be better off using something like a CDN (Content Delivery Network) instead to deliver the video.
I think it’s better to add MCU function…
Hi,
I followed your steps for video conferencing and reached up to connect pjsip endpoint with Asterisk in UI but not able to call.(call button not working for me).
in cyber_mega_phone.js on the line number 78 it stuck:
console.log(‘new session – ‘ + rtc.direction + ‘ – ‘ + rtc);
please guide
It’s hard to tell what your problem could be. If you can’t click the call button at all (disabled) then either you are not connected (websocket failed) or you are not registered (if setup to register). If you can click the call button, but it fails then you need to look at the SDPs going to/from browser and Asterisk.
This comment section is not conducive to these types of discussions. If you’d like to follow up please post your question on https://community.asterisk.org/
Hangs up after a few seconds with: Reason: SIP ;cause=408; text=”RTP Timeout”
I use the same webrtc enabled endpoint for other tests and I know it works. I can connect and see my video for a few seconds before getting disconnected. I cannot hear any audio at all while the connection is active. Any pointers on where to check for a solution?
I’m not sure what could be wrong. I’d suggest posting your question on https://community.asterisk.org/ along with a debug log trace of the call and your configuration.
Can you please give an example of the info should be filled in CMP2K combo box? This will be helpful
There is an example in the the one picture but it might be hard to tell since it doesn’t resize well. Also if you bring the page up it should have default values (grey-ish text) that also act as example input. Here’s some example input though:
ID: alice
Authorization Name: alice
Authorization Password: 1234
Host IP/Name: localhost
Extension: 500
Nice job !! By the way, do you happen to know if there is a posibility to join a conference from a SIP conference room video equipment
It depends on the equipment, but if it speaks SIP and you can configure it appropriately then it should be able to join.
Im new in asterisk, and i have a project where i have to use the asterisk pbx to make a video conference, in the web GUI i cant find an option to create one, can i perform this process and have same results?
CyberMegaPhone of course is meant to be an example/demo, but yes you should be able to create something in your own application that acts in much the same way.
My teammates told me to use asterisknow and they have a problem with video conferences, video wont show up, in the GUI we cant find and option to show video, is this configured at the asterisknow cmd in the pc (i have it in a virtual machine)
AsteriskNOW is a distribution comprising of Asterisk and FreePBX. There is nothing built in for this video conference support, any changes would likely need to be done manually which may conflict with FreePBX. There are no guides for doing this and it is recommended to use Asterisk standalone.
If i install asterisk will i have to create an app from scratch to make phone calls and video conference? Or will it be like in asterisknow where once installed i can make phone calls videocalls and conferences? I’ve only worked with asterisknow
The only way to get the kind of video conferencing client support shown here in this post is either to:
I’ll tell this to my teammates, thanks for the help, if i have any question ill surely ask here. Thanks
After I followed this article, the video conference still didn’t work, but I found a solution for your reference.
Jcolp:The chan_sip module is not supported for SFU. You would need to disable loading it in modules.conf by using “noload => chan_sip.so”
https://community.asterisk.org/t/webrtc-setup-on-master-branch-not-working/73528
Why does my cyber mega phone only only has two video stremas?
Asterisk version: 15.4.1
Ubuntu version: 14.04
pjsip.conf:
[transport-wss]
type=transport
bind=0.0.0.0
protocol=wss
[199]
type=aor
max_contacts=5
;remove_existing=no
[199]
type=auth
auth_type=userpass
username=199
password=199 ; This is a completely insecure password. Do NOT expose this
; system to the Internet without utilizing a better password.
[199]
type=endpoint
context=default
direct_media=no
allow=all
aors=199
max_audio_streams=10
max_video_streams=10
webrtc=yes
dtls_ca_file=/etc/asterisk/keys/ca.crt
dtls_cert_file=/etc/asterisk/keys/asterisk.pem
sip.conf:
[general]
udpbindaddr=0.0.0.0:5060
realm=freeswitch.ml
transport=udp,ws,wss
videosupport=yes
[199]
host=dynamic
secret=199
context=default
type=friend
encryption=yes
avpf=yes
force_avp=yes
icesupport=yes
directmedia=no
;disallow=all
;allow=opus
;allow=ulaw
;allow=vp8
allow=all
dtlsenable=yes
dtlsverify=fingerprint
dtlscertfile=/etc/asterisk/keys/asterisk.pem
dtlscafile=/etc/asterisk/keys/ca.crt
dtlssetup=actpass
rtcp_mux=yes
extension.conf:
[default]
exten => echo,1,Answer()
same => n,StreamEcho(3)
same => n,Hangup()
exten => video-conference,1,Answer()
same => n,ConfBridge(199)
same => n,Hangup()
exten => 200,1,Answer()
same => n,Playback(demo-congrats)
same => n,Hangup()
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
I’d suggest using the community site at https://community.asterisk.org/ for seeking help with this but it is likely that chan_sip is receiving the call and not chan_pjsip, which does not support multistream.
can i use asterisk to make one video call. and then update mediastream. such as add a new video stream?
I don’t know it has support?
please i need your help. I started a conference with two members but I have a problem with the display screens; because they are not well carded. I would like them to be well positioned like the ones in your example above. I am not familiar with the modifications to be made in index.html of the / var / lib / asterisk / static-http / cyber_mega_phone_2k directory