UPDATE:2018-09-07
RasPBX maintainer includes Opus & PLC support with Asterisk 13.23.0 upgrade on current Stretch based image!
ORIGINALPOST:
This howto will describe a solution to get opus translation (encode/decode) support along the already (dumb) passthrough format support in RasPBX 2018-04-04 (asterisk 13.22.0/freepbx 14.03.13). Extended features like Opus FEC(Forward error correction) / PLC(Packet loss concealment) may/will need additional patching not yet described/tested!
With RasPBX its current implementation (2018-04-04) its only possible to make opus to opus calls, since translating from/to other codecs (g722>opus/opus>g722) misses the opus codec. Therefor features like conferences/musiconhold/queues/anouncements/etc with other native codec than opus will not work (silent).
The multi cpu architecture supported Asterisk has a little different codebase for x86(pc-hardware) compared to arm(raspberry-pi) when it comes to Opus support. During the compiling of Asterisk on "x86" enabled with Opus support it will download pre-compiled x86 binaries from digium (since there is no source code included) and include it in your application. For "arm" these pre-compiled binaries are missing even so its source-code, so there is no easy/direct way of enabling opus and compile it. Searching different sourceforge discussions show that things are awkwardly missing.
It first looked impossible, but when noticing that there was a native debian arm asterisk-opus package in some repo I was convinced it was possible. Additional searching lead up to missing opus source code for asterisk on github and build instructions for freepbx for debian.
First I tested it on debian8 x86-64 than on debian9 on x86-64 (php7 problems fixed by adding debian8 apt sources). Than tried it compiling again using the exact Asterisk version which RasPBX was using, also with success. Than I went to Raspbian 9 stretch lite on raspberry pi 3 (notice I'm still not talking RasPBX yet as a distro but pure debian/raspbian)! After some minor differences/changes it also started working. Than finally I tried to compile Asterisk on RasPBX 2018-04-04 and only copy the custom compiled "codec_opus_open_source.so" module to /usr/lib/asterisk/modules/, than enabled in FreePBX webinterface "checkbox opus codec" in asterisk_sip settings did a "fwconsole restart" which finally brought me to this modest successfull howto of today.
There is probably a lot of optimization needed, since the beginning first couple of seconds in a call are bad quality but eventually the quality will maxout to 4.9. Also use 16bit sources of audio otherwise additional codec resampling 8>16bit viceversa has to be done. Tested with softphone linphone on both Ubuntu18.04 mate 64 and Apple IOS 10.
In the second post a step by step guide is included, for freepbx on raspbian-lite (no RasPBX) which is just a combination of freepbx build plans and Alexander Traud its github page.
In the third post a step by step guide for RasPBX is included.
In the fourth posts just some thoughts/optimisation idea's.
The following 'asterisk -r' console commands will be showed "before" and "after" adding opus opensource codec module:
core show codecs
core show translation
module show like opus
module show like codec_resample
Example of RasPBX webinterface Asterisk Info log showing a active conference room call with two extensions which hear Announcements and Music On hold or talk to each other, which can be paused on both sides to test moh/interruption/resample/resume:
Chan_Sip Info
Chan_Sip Channel(s)
Peer User/ANR Call ID Format Hold Last Message Expiry Peer
192.168.90.254 301 1154109372 (opus) No Rx: ACK 301
192.168.90.249 302 8-JL02Cdux (ulaw) No Rx: ACK 302
2 active SIP dialogs
Last edit: Walter Sonius 2018-09-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Notice:
The following steps we're needed on pure raspbian-lite 9 stretch not RasPBX, doing these steps on RasPBX will install additional database and other unneeded/conflicting packages and slow down RasPBX hugly! Its actually a replacement of RasPBX, if you do all steps. RasPBX only steps will follow in post 3, along side further improvements.
So this is just a prove of concept, its a good idea to compile it on a seperate SDCARD and copy back the needed module(s) to your current RasPBX system, that way it will stay fast/clean.
Most of these steps are from Alexander Traud github page and FreePBX documentation.
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config #timezone
sudo nano /etc/apt/sources.list
#deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi
sudo apt-get update
apt-get install -y openssh-server apache2 mysql-server mysql-client mongodb bison flex php5 php5-curl php5-cli php5-mysql php-pear php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev libspandsp-dev sudo libmyodbc subversion libtool-bin python-dev dirmngr tcpdump nmap vlan net-tools libopus-dev libopusfile-dev build-essential autoconf libssl-dev libncurses-dev libnewt-dev libxml2-dev libsqlite3-dev uuid-dev libjansson-dev libblocksruntime-dev xmlstarlet
#pdo_mysql driver error choose php5 instead php7!
sudo update-alternatives --config php
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
#continue rest as root user
sudo -s
pear install Console_Getopt
cd /usr/src
#wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-14-current.tar.gz
#http://downloads.asterisk.org/pub/telephony/asterisk/old-releases/asterisk-13.22.0.tar.gz
#raspbx version???
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13.22.0.tar.gz
wget -O jansson.tar.gz https://github.com/akheron/jansson/archive/v2.7.tar.gz
cd /usr/src
tar vxfz jansson.tar.gz
rm -f jansson.tar.gz
cd jansson-*
autoreconf -i
./configure
make
make install
cd /usr/src
tar xvfz asterisk-13.22.0.tar.gz
rm -f asterisk-13.22.0.tar.gz
cd asterisk-13.22.0
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install #pkgconfig conflict
#phone countrycode libvpb1 austrialia 61 > nl 31
wget github.com/traud/asterisk-opus/archive/asterisk-13.7.tar.gz
tar zxf asterisk-13.7.tar.gz
rm asterisk-13.7.tar.gz
cp --verbose asterisk-opus*/include/asterisk/* include/asterisk
cp --verbose asterisk-opus*/codecs/* codecs
cp --verbose asterisk-opus*/res/* res
./configure --with-pjproject-bundled
#configure: WARNING: "CPU armv7l not recognized - proceed with caution!"
#configure: Package configured for:
#configure: OS type : linux-gnueabihf
#configure: Host CPU : armv7l
#configure: build-cpu:vendor:os: armv7l : unknown : linux-gnueabihf :
#configure: host-cpu:vendor:os: armv7l : unknown : linux-gnueabihf :
make menuselect #enable Add-ons > format_mp3 / Codec Translators > --Unspecified-- codec_opus_open_source / last 3 menu items > SLN16
make -j4
###Stop here if you are on RasPBX instead of Raspbian-lite
make install
make config
ldconfig
update-rc.d -f asterisk remove
useradd -m asterisk
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib/asterisk
rm -rf /var/www/html
sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
service apache2 restart
cat >> /etc/odbcinst.ini << EOF
[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libmyodbc.so
Setup = /usr/lib/arm-linux-gnueabihf/odbc/libodbcmyS.so
FileUsage = 1
EOF
cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3
EOF
cd /usr/src
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
tar vxfz freepbx-14.0-latest.tgz
rm -f freepbx-14.0-latest.tgz
cd freepbx
touch /etc/asterisk/ari.conf
./start_asterisk start
sleep 15
./install -n
a2enmod rewrite
service apache2 restart
#After reboot pi
fwconsole start
Asterisk>Advanced settings> conference confbridgen>netme sub apply netme>confbrige sub apply
Getting the build related packages only and following the asterisk compile instructions until "make -j4" will leave you with the following files after successfull build, don't do make install on RasPBX:
ls -l codecs/*opus*.so
-rwxr-xr-x 1 root root 245016 Aug 12 00:30 codecs/codec_opus_open_source.so
ls -l res/*opus*.so
-rwxr-xr-x 1 root root 207884 Aug 12 00:40 res/res_format_attr_opus.so
By only copying "codec_opus_open_source.so" to your current "/usr/lib/asterisk/modules" folder and enabling Opus checkbox in freepbx sip settings webinterface and restarting the system made it work.
If you only copy the codec module to a clean RasPBX system make sure its updated and using the same versions as the one you compiled for, no other packages are needed see attachment post 3.
Last edit: Walter Sonius 2018-08-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
RasPBX 18-04-04 only steps, probably still more packages than needed but it works all steps may require less than an hour on Pi3:
raspi-config #enlarge boot partition 7>A1 & reboot
raspbx-upgrade #will update asterisk to 13.22.0
#press 'y' and 'q' when asked
#don't forget to update FreePBX modules from the webinterface aswell!
#Admin>Module Admin> "Check Online / Upgrade all / Process / Confirm" or
#fwconsole ma upgradeall
apt-get install bison flex php5 php5-curl php5-cli php5-mysql php-pear php5-gd curl sox libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev automake libtool autoconf git unixodbc-dev uuid uuid-dev libasound2-dev libogg-dev libvorbis-dev libicu-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev libspandsp-dev libmyodbc libtool-bin python-dev dirmngr libopus-dev libopusfile-dev build-essential autoconf libssl-dev libncurses-dev libnewt-dev libxml2-dev libsqlite3-dev uuid-dev libjansson-dev libblocksruntime-dev xmlstarlet
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13.22.0.tar.gz
tar xvfz asterisk-13.22.0.tar.gz
rm -f asterisk-13.22.0.tar.gz
cd asterisk-13.22.0
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install #pkgconfig conflict
#phone countrycode austrialia 61 > nl 31 > your country?
wget github.com/traud/asterisk-opus/archive/asterisk-13.7.tar.gz
tar zxf asterisk-13.7.tar.gz
rm asterisk-13.7.tar.gz
cp --verbose asterisk-opus*/include/asterisk/* include/asterisk
cp --verbose asterisk-opus*/codecs/* codecs
cp --verbose asterisk-opus*/res/* res
./configure --with-pjproject-bundled
make menuselect #enable / Add-ons > format_mp3 / Codec Translators > --Unspecified-- codec_opus_open_source
make -j4 #On pi3 takes about 20 Minutes
md5sum codecs/codec_opus_open_source.so 30de7a431a273ff66d4b71d0542132fb
cp codecs/codec_opus_open_source.so /usr/lib/asterisk/modules/
#FreePBXwebinterface
Settings> Asterisk IAX/SIP settings > "Codec Settings/Codecs"
Checkbox opus
#ssh / console
fwconsole restart
asterisk -r # check output of following commands
core show codecs
core show translation
module show like opus
module show like codec_resample
Now its time to setup a conference room with some music on hold and two extensions each using a other codec. Only tested sip protocol.
PS:Also previous Debian 8 Jessie based version of RasPBX with FreePBX 13.0.195.4 / asterisk 13.17.1 works with these steps. However it requires its own Asterisk version specific opus module. See attachments:
Opus FEC/PLC???
Atlhough I have been able to apply the PLC and Format patches from Alexander Traud his github page into building asterisk on raspbian-lite. I'm uncertain where/which asterisk components/modules also are affected by these patches except the opus related codec/format since the source patches apply to main/translate.c functions and don't know if it can be swapped/blend into RasPBX.
I'm also not familair howto to even correctly test this FEC/PLC stuff except bad wifi connections with multi arch / OS / Softphone clients.
Maybe audio quality errors also arise since Conferencerooms mix 8bit and 16bit but I haven't found yet if it mixes by default in 16bit or 8bit?
Finally, with the help of Walter's amazing instructions, the Opus codec has found it's way into the RasPBX Asterisk build. With version 13.23.0 the codec_opus_opensource.so module is included in the asterisk13 package. Users get it automatically when upgrading a Stretch based image.
When building the module I've also applied the experimental PLC patch to Asterisk. According to some user comments this patch might have undesired effects on other codecs. In case anyone has problems please report them here. If necessary, I can disable the patch again on one of the next builds.
Thanks again to Walter for his very detailed instructions, which made it easy for me to add the module.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for including support in current RasPBX build, especially Alexander Traud for his detailed and updated github page. I wouldn't have done it without it.
I do have to test though if upgrading to a newer Asterisk will overwrite custom compiled opus module or just reject the old one since it has a different version fingerprint?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
UPDATE:2018-09-07
RasPBX maintainer includes Opus & PLC support with Asterisk 13.23.0 upgrade on current Stretch based image!
ORIGINALPOST:
This howto will describe a solution to get opus translation (encode/decode) support along the already (dumb) passthrough format support in RasPBX 2018-04-04 (asterisk 13.22.0/freepbx 14.03.13). Extended features like Opus FEC(Forward error correction) / PLC(Packet loss concealment) may/will need additional patching not yet described/tested!
With RasPBX its current implementation (2018-04-04) its only possible to make opus to opus calls, since translating from/to other codecs (g722>opus/opus>g722) misses the opus codec. Therefor features like conferences/musiconhold/queues/anouncements/etc with other native codec than opus will not work (silent).
The multi cpu architecture supported Asterisk has a little different codebase for x86(pc-hardware) compared to arm(raspberry-pi) when it comes to Opus support. During the compiling of Asterisk on "x86" enabled with Opus support it will download pre-compiled x86 binaries from digium (since there is no source code included) and include it in your application. For "arm" these pre-compiled binaries are missing even so its source-code, so there is no easy/direct way of enabling opus and compile it. Searching different sourceforge discussions show that things are awkwardly missing.
sohail
Alaa
Guido Harlow
Guido Harlow
It first looked impossible, but when noticing that there was a native debian arm asterisk-opus package in some repo I was convinced it was possible. Additional searching lead up to missing opus source code for asterisk on github and build instructions for freepbx for debian.
First I tested it on debian8 x86-64 than on debian9 on x86-64 (php7 problems fixed by adding debian8 apt sources). Than tried it compiling again using the exact Asterisk version which RasPBX was using, also with success. Than I went to Raspbian 9 stretch lite on raspberry pi 3 (notice I'm still not talking RasPBX yet as a distro but pure debian/raspbian)! After some minor differences/changes it also started working. Than finally I tried to compile Asterisk on RasPBX 2018-04-04 and only copy the custom compiled "codec_opus_open_source.so" module to /usr/lib/asterisk/modules/, than enabled in FreePBX webinterface "checkbox opus codec" in asterisk_sip settings did a "fwconsole restart" which finally brought me to this modest successfull howto of today.
There is probably a lot of optimization needed, since the beginning first couple of seconds in a call are bad quality but eventually the quality will maxout to 4.9. Also use 16bit sources of audio otherwise additional codec resampling 8>16bit viceversa has to be done. Tested with softphone linphone on both Ubuntu18.04 mate 64 and Apple IOS 10.
In the second post a step by step guide is included, for freepbx on raspbian-lite (no RasPBX) which is just a combination of freepbx build plans and Alexander Traud its github page.
In the third post a step by step guide for RasPBX is included.
In the fourth posts just some thoughts/optimisation idea's.
The following 'asterisk -r' console commands will be showed "before" and "after" adding opus opensource codec module:
Before adding opus codec module:
After adding opus codec module support:
Example of RasPBX webinterface Asterisk Info log showing a active conference room call with two extensions which hear Announcements and Music On hold or talk to each other, which can be paused on both sides to test moh/interruption/resample/resume:
Last edit: Walter Sonius 2018-09-12
Notice:
The following steps we're needed on pure raspbian-lite 9 stretch not RasPBX, doing these steps on RasPBX will install additional database and other unneeded/conflicting packages and slow down RasPBX hugly! Its actually a replacement of RasPBX, if you do all steps. RasPBX only steps will follow in post 3, along side further improvements.
So this is just a prove of concept, its a good idea to compile it on a seperate SDCARD and copy back the needed module(s) to your current RasPBX system, that way it will stay fast/clean.
Most of these steps are from Alexander Traud github page and FreePBX documentation.
Getting the build related packages only and following the asterisk compile instructions until "make -j4" will leave you with the following files after successfull build, don't do make install on RasPBX:
By only copying "codec_opus_open_source.so" to your current "/usr/lib/asterisk/modules" folder and enabling Opus checkbox in freepbx sip settings webinterface and restarting the system made it work.
If you only copy the codec module to a clean RasPBX system make sure its updated and using the same versions as the one you compiled for, no other packages are needed see attachment post 3.
Last edit: Walter Sonius 2018-08-15
RasPBX 18-04-04 only steps, probably still more packages than needed but it works all steps may require less than an hour on Pi3:
Now its time to setup a conference room with some music on hold and two extensions each using a other codec. Only tested sip protocol.
PS:Also previous Debian 8 Jessie based version of RasPBX with FreePBX 13.0.195.4 / asterisk 13.17.1 works with these steps. However it requires its own Asterisk version specific opus module. See attachments:
Last edit: Walter Sonius 2018-08-24
@Walter Sonius 👍
Thanks for your excellent guide. It worked for me.
Tried on pi2 (home) and pi3 (remote). What I did:
Downloaded the module “codec_opus_open_source.so” that you have provided.
cd /usr/lib/asterisk/modules/
wget https://sourceforge.net/p/raspbx/discussion/tutorials/thread/855b8b02/c915/attachment/codec_opus_open_source.so
Enabled the Opus codec in FreePBX, > Setting > Asterisk Sip Setting > General Sip Setting > Audio Codec.
And finally
fwconsole restart
Tested using Jitsi on Mac and Linphone on iPhone. 🙌
Good to hear you got it working and thanks for summarizing the steps.
Opus FEC/PLC???
Atlhough I have been able to apply the PLC and Format patches from Alexander Traud his github page into building asterisk on raspbian-lite. I'm uncertain where/which asterisk components/modules also are affected by these patches except the opus related codec/format since the source patches apply to main/translate.c functions and don't know if it can be swapped/blend into RasPBX.
I'm also not familair howto to even correctly test this FEC/PLC stuff except bad wifi connections with multi arch / OS / Softphone clients.
Maybe audio quality errors also arise since Conferencerooms mix 8bit and 16bit but I haven't found yet if it mixes by default in 16bit or 8bit?
URL's:
https://issues.asterisk.org/jira/browse/ASTERISK-25629
https://blogs.asterisk.org/2017/04/12/asterisk-opus-packet-loss-fec/
https://blogs.asterisk.org/2017/01/18/configuring-opus-encoder-asterisk/
https://wiki.asterisk.org/wiki/display/AST/Requirements+for+PLC+Use
Last edit: Walter Sonius 2018-08-25
Finally, with the help of Walter's amazing instructions, the Opus codec has found it's way into the RasPBX Asterisk build. With version 13.23.0 the codec_opus_opensource.so module is included in the asterisk13 package. Users get it automatically when upgrading a Stretch based image.
When building the module I've also applied the experimental PLC patch to Asterisk. According to some user comments this patch might have undesired effects on other codecs. In case anyone has problems please report them here. If necessary, I can disable the patch again on one of the next builds.
Thanks again to Walter for his very detailed instructions, which made it easy for me to add the module.
Thanks for including support in current RasPBX build, especially Alexander Traud for his detailed and updated github page. I wouldn't have done it without it.
I do have to test though if upgrading to a newer Asterisk will overwrite custom compiled opus module or just reject the old one since it has a different version fingerprint?