由于公司是做网络电话的,这段时间要求加入网络直拨的功能。经理要我们研究PJSIP,然后把直拨功能。由于网上有很多关于PJSIP的原来的资料这里就不多说了,有兴趣的朋友可以自己搜索,这里就说说PJSIP的编译,编译在android平台使用的。
当然在PJSIP的官网www.pjsip.org上有比较健全的文档,我也是按照文档一步步编译的。
首先当然是下载pjsip的源码包,然后就开始编译。下面按照文档看看:
Requirements
- Besides the Android SDK, you will also need the Android NDK (minimum version r8b).
- Optional if you want to build and and run the sample application PJSUA:
- SWIG (minimum version 2.0.5)
- Eclipse with ADT Plugin.
- Telnet application to interact with PJSUA command line. If you are not familiar with telnet, please find a tutorial suitable for your development platform.
Build Preparation¶
1. Get the sourcecode from repository, if you haven't already. This tutorial appliesto PJSIP version 2.2 and above (or the 2.1 from SVN trunk dated 2013/04/24 orlater).
2. Set yourconfig_site.hto the following:
3. #definePJ_CONFIG_ANDROID 1
4. #include<pj/config_site_sample.h>
This will activate Android specificsettings in theconfig_site_sample.h.
这里是说设置config_site.h,但是源码的文件这么多,到底是哪个路径??只能网上找办法,是在pjlib/include/pj/路径下,但是没有看到config_site.h这个文件,继续找办法,原来是要自己创建一个config_site.h,然后把上面的内容写进去,这在编译的时候会触发config_site_sample.h里设置的内容。
接下来
Building PJSIP¶
Just run:
$ cd /path/to/your/pjsip/dir
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
$ ./configure-android
$ make dep && make clean && make
这里的步骤意思是先cd /path/to/your/pjsip/dir进入pjsip的源码包路径,再
设置android NDK的路径exportANDROID_NDK_ROOT=/path_to_android_ndk_dir,其中path_to_android_ndk_dir是android NDK的路径,当然android NDK要下载后放到Linux里面,注意android NDK是分版本的,下载的时候要注意。接下来./configure-android就是配置各种设置的,前期都是参数的配置,最后一个makedep && make clean && make就是激动人心的编译啦。
这里多少几句我自己犯的错误,由于自己没有现成的Linux环境,于是使用windows下的cygwin模拟Linux环境,编译的时候出现了C C++编译器没有起作用的错误提示,编译终止。在网上查到的方法都没有解决,最后只能在家里使用wm虚拟机里面的Linux编译终于通过了。看来cygwin只适合平时练习敲命令,其它的只能用更加接近真实环境的Linux环境。
编译完成之后接下来就是按照自己的开发android应用平台生成一个例程,pjsip有pjsua2和pjsua两种,当然pjsua2功能会更多一些。所以就编译了一个pjsua2的例程
先来看看官方文档:
Building and running pjsua2 sampleapplication¶
Another sample application, which is basedonpjsua2 high-level APIwithSWIG binding, is located underpjsip-apps/src/swig/java/android. It is not built bydefault, and you needSWIG to build it.
Follow these steps to build pjsua2 sampleapplication:
1. Make sure SWIG is in the build environmentPATH.
2. Runmakefrom directory$PJDIR/pjsip-apps/src/swig(note that theAndroid NDK root should be in the PATH), e.g:
3. $ cd/path/to/your/pjsip/dir
4. $ cdpjsip-apps/src/swig
5. $ make
注意这里说了,要编译例程,要在Linux里装SWIG,由于自己家里的Linux是ubuntu11,而且没有装SWIG,安装SWIG时找不到源,又在网络上搜索了一通,然后尝试了网络上的各种source.list源都没有用。第二天到公司了,直接装个了vm并装了一个最新的ubuntu14,终于安装上SWIG,另外插一句,Linux系统要配置java的编译环境,官方的文档没有说。最后一下子编译通过,在pjsip的源码目录/pjsip-apps/src/pjsua下就生成了android的pjsip例程。
下面是编译好的PJSIP例程,有需要的朋友自行下载。
http://download.csdn.net/detail/luoshishou/8007683