Skip to end of metadata
Go to start of metadata

Overview 

Asterisk 12 and later versions contain two SIP stacks: one, the original chan_sip SIP channel driver that has been present in all previous releases of Asterisk, and a new SIP stack that is based on pjproject. For more information on configuring the new SIP stack, see Configuring res_pjsip.

Because earlier releases of pjproject cannot build shared object libraries, some changes were required in order to use it with Asterisk 12. As such, Asterisk requires pjproject version 2.4 or later. Alternatively, an Asterisk compatible version of pjproject is available on  github , or - depending on your Linux distribution - available as a package.

Earlier versions of pjproject downloaded from www.pjsip.org will not work with Asterisk 12. 

Icon

Asterisk 11 uses an embedded pjproject for the ICE, STUN and TURN libraries in its RTP engine for WebSockets support. Therefore you do not need to follow the instructions here for Asterisk 11.
Asterisk 12 and 13
dynamically link to pjproject.
Asterisk >= 13.8.0 can dynamically link to pjproject but also contains a bundled version of pjproject. See Using the Bundled Version of pjproject

On this Page

Building and Installing pjproject from Source

If you're using Asterisk 13.8.0 or greater, consider using the Bundled Version of pjproject.

Icon

If you have previously installed a version of pjproject, you must remove that version of pjproject prior to building and installing the Asterisk 12 compatible version of pjproject. See Uninstalling pjproject for more information.

Downloading pjproject

Obtaining pjproject from Teluu:

  1. Use wget to pull the latest version from www.pjsip.org. Note that the instructions assume that this is 2.4.5; for the latest version, refer to www.pjsip.org:

    # wget http://www.pjsip.org/release/2.4.5/pjproject-2.4.5.tar.bz2
    
    # tar -xjvf pjproject-2.4.5.tar.bz2

Obtaining the latest pjproject from the svn repo:

  1. Use  svn to install the latest version from  www.pjsip.org.

    # svn co http://svn.pjsip.org/repos/pjproject/trunk/ pjproject-trunk

Obtaining (old asterisk) pjproject from the github repo:

  1. If you do not have git, install git on your local machine.

    Icon

    Downloading and installing git is beyond the scope of these instructions, but for Debian/Ubuntu systems, it should be as simple as:

    apt-get install git

    And for RedHat/CentOS systems:

    yum install git
  2. Checkout the Asterisk 12-compatible pjproject from the Asterisk github repo:

    # git clone https://github.com/asterisk/pjproject pjproject

    And that's it!

Building and Installing pjproject

The first step in building and installing pjproject is configuring it using configure. For Asterisk, this is arguably the most important step in this process. pjproject embeds a number of third party libraries which can conflict with versions of those libraries that may already be installed on your system. Asterisk will not use the embedded third party libraries within pjproject. As an example, if you are going to build the res_srtp module in Asterisk, then you must specify "--with-external-srtp" when configuring pjproject to point to an external srtp library.

Additionally, Asterisk REQUIRES two or three options to be passed to configure:

  • --enable-shared - Instruct pjproject to build shared object libraries. Asterisk will only use shared objects from pjproject.
  • --prefix - Specify root install directory for pjproject. This will be dependent on your distribution of Linux; typically this is /usr for most systems. The default is /usr/local
  • --libdir - Specify the installation location for object code libraries. This may need to be set to /usr/lib64 for some 64-bit systems such as CentOS.

 

Icon

Failure to build Asterisk with shared pjproject object libraries WILL result in seemingly random crashes. For Asterisk to work properly with pjproject, pjproject MUST be built with shared object libraries.

Compiler DEFINEs

  • Users who expect to deal with Contact URIs longer than 256 characters or hostnames longer than 128 characters should set PJSIP_MAX_URL_SIZE and PJ_MAX_HOSTNAME as appropriate.

  • IPv6 support in pjproject is, by default, disabled. To enable it, set PJ_HAS_IPV6 to 1.
  • The default configuration of pjproject enables "assert" functions which can cause Asterisk to crash unexpectedly. To disable the asserts, set NDEBUG to 1.
  • The default number of TCP/TLS incoming connections allowed is 64. If you plan on having more than that you'll need to set PJ_IOQUEUE_MAX_HANDLES to the new limit.

With the exception of PJ_IOQUEUE_MAX_HANDLES, the options can be set in CFLAGS and passed to configure as follows: './configure CFLAGS="-DNDEBUG=1 -DPJ_HAS_IPV6=1"', etc. A better way is to create or edit the pjlib/include/pj/config_site.h file and set them all there. Here's a reasonable starting point that also includes some performance tunings...

pjlib/include/pj/config_site.h

 

Other common configure options needed for pjproject are listed below:

LibraryConfigure optionNotes
libspeex shared objects--with-external-speexMake sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
libsrtp shared objects--with-external-srtpMake sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
GSM codec--with-external-gsmMake sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
Disable sound--disable-soundLet Asterisk perform sound manipulations.
Disable resampling--disable-resample

Let Asterisk perform resample operations.

Disable video--disable-videoDisable video support in pjproject's media libraries. This is not used by Asterisk.
Disable AMR--disable-opencore-amrDisable AMR codec support. This is not used by Asterisk

These are some of the more common options used to disable third party libraries in pjproject. However, other options may be needed depending on your system - see  configure --help for a full list of configure options you can pass to pjproject.


  1. Now that you understand the pjproject configure options available, change directories to the pjproject source directory:

    # cd pjproject
  2. In the pjproject source directory, run the configure script with the options needed for your system:

    # ./configure --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr CFLAGS='-O2 -DNDEBUG'

    A few recommended options are shown. That includes setting a couple important CFLAGS, -O2 for common optimizations and -DNDEBUG to disable debugging code and assertions.

  3. Build pjproject:

    # make dep
    # make
    
  4. Install pjproject

    # make install
  5. Update shared library links.

    # ldconfig
  6. Verify that pjproject has been installed in the target location by looking for, and finding the various pjproject modules:

    # ldconfig -p | grep pj
    	libpjsua.so (libc6,x86-64) => /usr/lib/libpjsua.so
    	libpjsip.so (libc6,x86-64) => /usr/lib/libpjsip.so
    	libpjsip-ua.so (libc6,x86-64) => /usr/lib/libpjsip-ua.so
    	libpjsip-simple.so (libc6,x86-64) => /usr/lib/libpjsip-simple.so
    	libpjnath.so (libc6,x86-64) => /usr/lib/libpjnath.so
    	libpjmedia.so (libc6,x86-64) => /usr/lib/libpjmedia.so
    	libpjmedia-videodev.so (libc6,x86-64) => /usr/lib/libpjmedia-videodev.so
    	libpjmedia-codec.so (libc6,x86-64) => /usr/lib/libpjmedia-codec.so
    	libpjmedia-audiodev.so (libc6,x86-64) => /usr/lib/libpjmedia-audiodev.so
    	libpjlib-util.so (libc6,x86-64) => /usr/lib/libpjlib-util.so
    	libpj.so (libc6,x86-64) => /usr/lib/libpj.so
  7. Finally, verify that Asterisk detects the pjproject libraries. In your Asterisk source directory:

    # ./configure
    # make menuselect
  8. Browse to the Resource Modules category and verify that the res_pjsip modules are enabled:
  9. You're all done!  Now, build and install Asterisk as your normally would.

Troubleshooting

First, if you're using Asterisk 13.8.0 or greater, consider switching to the Bundled Version of pjproject

Asterisk fails to detect pjproject libraries

After building and installing pjproject, Asterisk fails to detect any of the libraries - the various res_pjsip components cannot be selected in Asterisk's menuselect

Solution

Verify that Asterisk's config.log shows the following:

configure:23029: checking for PJPROJECT
configure:23036: $PKG_CONFIG --exists --print-errors "libpjproject"
Package libpjproject was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpjproject.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpjproject' found
  1. Make sure you have pkg-config installed on your system.
  2. pjproject will install the package config file in /usr/lib/pkgconfig . Some distributions, notably Fedora, will instead look for the library in /usr/lib64 . Update your PKG_CONFIG_PATH environment variable with /usr/lib/pkgconfig and re-run Asterisk's configure script.

pjproject fails to build: errors related to opencore_amr

When building pjproject, errors about opencore_amr are displayed, e.g.:

output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x60): multiple definition of `pjmedia_codec_amrnb_framelenbits'
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x60): first defined here
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x80): multiple definition of `pjmedia_codec_amrnb_framelen'
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x80): first defined here
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x20): multiple definition of `pjmedia_codec_amrwb_framelenbits'
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x20): first defined here
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x40): multiple definition of `pjmedia_codec_amrwb_framelen'
output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x40): first defined here
...

Solution

You already have the AMR codec installed. Run  configure  with the  --disable-opencore-amr  option specified.

pjproject fails to build: video linker errors

When building pjproject, linker errors referring to various video methods are displayed, e.g.:

/home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_format_init_video'
/home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia.so: undefined reference to `pjmedia_video_format_mgr_instance'
/home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_format_get_video_format_detail'
/home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_get_video_format_info'

Solution

Run  configure  with either or both  --disable-video  or  --disable-v4l2

ldconfig fails to display pjproject libraries

After building pjproject, the dump provided by  ldconfig -p  doesn't display any libraries.

Solution

Run  ldconfig  to re-configure dynamic linker run-time bindings. This will need to be run with super user permissions.

pjproject fails to build on Raspberry Pi

pjproject/Asterisk fails to compile on your Raspberry Pi (raspbian) due to pjproject configure scripts not detecting endianness:

/usr/include/pj/config.h:243:6: error: #error Endianness must be declared for this processor
In file included from /usr/include/pj/types.h:33:0,
                 from /usr/include/pjsip/sip_config.h:27,
                 from /usr/include/pjsip/sip_types.h:34,
                 from /usr/include/pjsip.h:24,
                 from conftest.c:290:
/usr/include/pj/config.h:1161:4: error: #error "PJ_IS_LITTLE_ENDIAN is not defined!"
/usr/include/pj/config.h:1165:4: error: #error "PJ_IS_BIG_ENDIAN is not defined!"

Solution

  1. Edit /usr/include/pj/config.h (using the editor of your choice)
  2. Replace this code:

With this:

Then recompile. This workaround was taken from issue ASTERISK-23315.

 

Uninstalling a Previous Version of pjproject

Typically, other versions of pjproject will be installed as static libraries. These libraries are not compatible with Asterisk and can confuse the build process for Asterisk 12. As such, any static libraries must be removed prior to installing the compatible version of pjproject.

pjproject provides an uninstall make target that will remove previous installations. It can be called from the pjproject source directory like:

# make uninstall

If you don't have an "uninstall" make target, you may need to fetch and merge the latest pjproject from https://github.com/asterisk/pjproject

Alternatively, the following should also remove all previously installed static libraries:

# rm -f /usr/lib/libpj*.a /usr/lib/libmilenage*.a /usr/lib/pkgconfig/libpjproject.pc

Finally, you will need to update shared library links:

# ldconfig

If you want to run a sanity check, you can verify that pjproject has been uninstalled by ensuring no pjproject modules remain on the system:

# ldconfig -p | grep pj

If running the above command yields no results, that's it! You have successfully uninstalled pjproject from your system.

Using the Bundled Version of pjproject

Beginning with Asterisk 13.8.0, a stable version of pjproject is included in Asterisk's ./third-party directory.

Why would you want to do this?  Several reasons:

  • Predictability:  When built with the bundled pjproject, you're always certain of the version you're running against, no matter where it's installed.
  • Scalability:  The default pjproject configuration is optimized for client applications. The bundled version's configuration is optimized for server use.
  • Usability:  Several feature patches, which have been submitted upstream to pjproject but not yet released, have been included in the bundled version.
  • Safety:  If a security or critical issue is identified in pjproject, it can be patched and made available with a new release of Asterisk instead of having to waiting for a new release of pjproject.
  • Maintainability:  You don't need to build and install separate packages.
  • Supportability:  When asking others for help, there's no question about which version of pjproject you're using and what options it was compiled with.
  • Compatibility:  This is especially important from a development perspective because it means we can be sure that new pjproject APIs that have been introduced or old ones that have been deprecated,
     are handled and tested appropriately in Asterisk.
  • Reliability:  You can be sure that Asterisk was tested against the bundled version.

Usage:

First, run ./contrib/scripts/install_prereq.  Building the bundled pjproject requires the python development libraries which install_prereq has already installed.  All you have to do now is add the --with-pjproject-bundled option to your Asterisk ./configure command line and remove any other --with-pjproject option you may have specified. 

# cd /path/asterisk-source-dir
# ./configure --with-pjproject-bundled
# make && make install

The configure and make processes will download the correct version of pjproject, patch it, configure it, build it, and finally link Asterisk to it statically.  No changes in runtime configuration are required.  You can leave your system-installed version of pjproject in place if needed; once compiled with the --with-pjproject-bundled option, Asterisk will ignore any other installed versions of pjproject. 


  • No labels

14 Comments

  1. If You have pjproject installed not system wide (for example, not in /usr but --prefix=/opt/asterisk), then set 

    export PKG_CONFIG_PATH=/opt/asterisk/lib/pkgconfig/

    before running Asterisk configure --prefix=/opt/asterisk --with-pjproject=/opt/asterisk

    Otherwise configure fails.

  2. I ran in to problems using the above instructions when installing on 64-bit CentOS. When I got to step 6 and ran 'ldconfig -p | grep pj' no libraries were displayed.

    I fixed by running step 2 with '–prefix=/usr --libdir=/usr/lib64'

    e.g. ./configure --libdir=/usr/lib64 --prefix=/usr --enable-shared --disable-sound --disable-resample --disable-video --disable-opencore-amr 

  3. Maybe someone here is smarter then me and can explain if this is a bug in the pjproject source?

    When building pjproject with ./configure --prefix=/usr/lib64

    all seams fine when I runldconfig but asterisk's menuselect does not see pjsip.

    it turns out that instead of placing libpjproject.pc in /usr/lib64/pkgconfig it gets placed in /usr/lib64/lib/pkgconfig

    but if I then just move the libpjproject.pc back to lib64/pkgconfig and update the path it works?

    it gave me some trouble.

    1. Typically --prefix is used to set the root install path.  So on a 64bit system things will get installed in <prefix>/bin, <prefix>/lib64, <prefix>/share, etc. The pjproject default is /usr/local.  If you want everything installed directly in /usr, just specify --prefix=/usr.  If you really want to specify the lib directory, use --libdir.

       

  4. I ran in to problems using the above instructions when installing on 64-bit CentOS.When i try to load pjsip modules, displayed this error for example :

    Unable to load module chan_pjsip.so
    Command 'module load chan_pjsip.so ' failed.
    [2016-03-14 12:46:43] WARNING[26117]: loader.c:595 load_dynamic_module: Error loading module 'chan_pjsip.so': /usr/lib64/asterisk/modules/chan_pjsip.so: undefined symbol: ast_sip_send_request
    [2016-03-14 12:46:43] WARNING[26117]: loader.c:1079 load_resource: Module 'chan_pjsip.so' could not be loaded.

    1. What version of Asterisk?
      What version of pjproject?  Bundled or Shared install?

       

      chan_pjsip is dependent on res_pjsip.  Did it load? Were there any other load failures?  Do you have autoload=yes in modules.conf?  If not, make sure all of the res_pjsip* modules are loaded before chan_pjsip.

       

       

  5. [pjproject] Unpacking /tmp/pjproject-2.4.5.tar.bz2
    [pjproject] Applying patches
    [pjproject] Applying config_site.h
    [pjproject] Applying user.mak
    [pjproject] Configuring with --prefix=/opt/pjproject --with-external-speex --with-external-gsm --with-external-srtp --with-external-pa --disable-video --disable-v4l2 --disable-sound --disable-opencore-amr --disable-ilbc-codec --without-libyuv --disable-g7221-codec --enable-epoll
    aconfigure: error: Unable to use external Speex library. If Speex development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths
    Makefile:85: recipe for target 'build.mak' failed
    make: *** [build.mak] Error 1
    failed
    configure: Unable to configure third-party/pjproject
    configure: error: Run "make -C third-party/pjproject NOISY_BUILD=yes configure" to see error details.

     

    I shouldn't have to worry about trying to figure out all the prerequisites I need to install with something that is a 'bundle'.  Just my opinion.

    1. "I shouldn't have to worry about trying to figure out all the prerequisites I need to install with something that is a 'bundle'.  Just my opinion."

      No you shouldn't.  Let me look into it.

       

    2. Try running ./contrib/scripts/install_prereq and see if it fixes the issue.

       

      1. This brings up a Window that says: ITU-T telephone code and gives examples for Australia and France. Seems like something that should be automated.

        Also this does not fix the issue:

        [pjproject] Configuring with --prefix=/opt/pjproject --with-external-speex --with-external-gsm --with-external-srtp --with-external-pa --disable-video --disable-v4l2 --disable-sound --disable-opencore-amr --disable-ilbc-codec --without-libyuv --disable-g7221-codec --enable-epoll
        aconfigure: error: Unable to use SRTP. If SRTP development files are not available in the default locations, use CFLAGS and LDFLAGS env var to set the include/lib paths
        Makefile:85: recipe for target 'build.mak' failed
        make: *** [build.mak] Error 1
        failed
        configure: Unable to configure third-party/pjproject
        configure: error: Run "make -C third-party/pjproject NOISY_BUILD=yes configure" to see error details.

        1. Unfortunately that window is from libspeex, not Asterisk or pjproject.

          What platform are you running on?  libsrtp should have been installed by install_prereq.

           

          1. I am on Debian 8.3 x64

    3. I used to have the same issue just install this libraries you will be fine speex libspeex1 libspeex-dev libspeexdsp1 libspeexdsp-dev , Regards

      1. This kills the whole point of a bundle.  I might as well just install it manually like I have been doing using my config script that disables those codecs but thats going backwards.

        Going to see what install_prereq does.