公司要做网络通话及网络视频,初试,希望各位多多指点,有做过的希望联系一下我,有些不懂得地方还望指教。首先先谈一下PJSIP的编译,及在编译中我所遇到的问题。
1. 去官网下载http://www.pjsip.org(pjproject-2.6.tar.bz2),并解压
2. 在pjlib/include/pj/目录下,建立一个config_site.h的文件
cd /Users/eleccomm/Downloads/pjproject-2.6/pjlib/include/pj
vi config_site.h
根据官方说明文档,我们的文件内容定义如下:
#define PJ_CONFIG_IPHONE 1
#include
对于小白可能不太熟悉怎样终端插入,按i开始插入内容,输入完成后Esc退出插入,输入:wq回车即可退出编辑状态,然后起还到主目录下,即包含pjlib、pjlib-util、pjmedia、pjnath的目录下
3. 编译静态库
i386,依次执行下面三行:
export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
ARCH="-arch i386" CFLAGS="-O2 -m64 -mios-simulator-version-min=8.0" LDFLAGS="-O2 -m64 -mios-simulator-version-min=8.0" ./configure-iphone
make dep && make clean && make
成功后,模拟器编译好的静态库会存在于
pjlib/lib
pjlib-util/lib
pjmedia/lib
pjnath/lib
pjsip/lib
third_party/lib
armv7,关闭刚刚的终端,重新回到主目录,依次执行以下命令:
ARCH='-arch armv7' ./configure-iphone
make dep && make clean && make
armv7s直接执行以下命令:
ARCH='-arch armv7s' ./configure-iphone
make dep && make clean && make
arm64执行以下命令
ARCH='-arch arm64' ./configure-iphone
make dep && make clean && make
也可以这样编译静态库回到主目录,创建一个文件夹
mkdir sip
编译静态库armv7
sudo ARCH='-arch armv7' ./configure-iphone --prefix=/Users/eleccomm/Downloads/pjproject-2.6/sip/armv7
make dep && make clean && make
make install
armv7s
sudo ARCH='-arch armv7s' ./configure-iphone --prefix=/Users/eleccomm/Downloads/pjproject-2.6/sip/armv7s
make dep && make clean && make
make install
arm64
sudo ARCH='-arch arm64' ./configure-iphone --prefix=/Users/eleccomm/Downloads/pjproject-2.6/sip/arm64
make dep && make clean && make
make install
编译模拟器库的时候需要先在主目录下的configure-iphone中添加几行代码
vim configure-iphone
在第一个if前面添加上如是代码:
if [ "$ARCH" = "-arch x86_64" ]; then DEVPATH="/Applications/XCode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer" echo "$F: Simulator 64bit, using ${DEVPATH}" fi
if [ "$ARCH" = "-arch i386" ]; then DEVPATH="/Applications/XCode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer" echo "$F: Simulator 32bit, using ${DEVPATH}" fi
i386
sudo ARCH="-arch i386" CFLAGS="-O2 -m64 -mios-simulator-version-min=7.0" LDFLAGS="-O2 -m64 -mios-simulator-version-min=7.0" ./configure-iphone --prefix=/Users/eleccomm/Downloads/pjproject-2.6/sip/x86
make dep && make clean && make
make install
x64
sudo ARCH="-arch x86_64" CFLAGS="-O2 -m64 -mios-simulator-version-min=7.0" LDFLAGS="-O2 -m64 -mios-simulator-version-min=7.0" ./configure-iphone --prefix=/Users/eleccomm/Downloads/pjproject-2.6/sip/x64
make dep && make clean && make
make install
4. 合并静态库
mkdir sip/all
mkdir sip/all/lib
cd /Users/eleccomm/Downloads/pjproject-2.6/sip
合并静态库
lipo -create arm64/lib/libg7221codec-arm64-apple-darwin_ios.a armv7/lib/libg7221codec-armv7-apple-darwin_ios.a armv7s/lib/libg7221codec-armv7s-apple-darwin_ios.a x64/lib/libg7221codec-x86_64-apple-darwin_ios.a x86/lib/libg7221codec-i386-apple-darwin_ios.a -output all/lib/libg7221codec.a
lipo -create arm64/lib/libgsmcodec-arm64-apple-darwin_ios.a armv7/lib/libgsmcodec-armv7-apple-darwin_ios.a armv7s/lib/libgsmcodec-armv7s-apple-darwin_ios.a x64/lib/libgsmcodec-x86_64-apple-darwin_ios.a x86/lib/libgsmcodec-i386-apple-darwin_ios.a -output all/lib/libgsmcodec.a
lipo -create arm64/lib/libilbccodec-arm64-apple-darwin_ios.a armv7/lib/libilbccodec-armv7-apple-darwin_ios.a armv7s/lib/libilbccodec-armv7s-apple-darwin_ios.a x64/lib/libilbccodec-x86_64-apple-darwin_ios.a x86/lib/libilbccodec-i386-apple-darwin_ios.a -output all/lib/libilbccodec.a
lipo -create arm64/lib/libpj-arm64-apple-darwin_ios.a armv7/lib/libpj-armv7-apple-darwin_ios.a armv7s/lib/libpj-armv7s-apple-darwin_ios.a x64/lib/libpj-x86_64-apple-darwin_ios.a x86/lib/libpj-i386-apple-darwin_ios.a -output all/lib/libpj.a
lipo -create arm64/lib/libpjlib-util-arm64-apple-darwin_ios.a armv7/lib/libpjlib-util-armv7-apple-darwin_ios.a armv7s/lib/libpjlib-util-armv7s-apple-darwin_ios.a x64/lib/libpjlib-util-x86_64-apple-darwin_ios.a x86/lib/libpjlib-util-i386-apple-darwin_ios.a -output all/lib/libpjlib-util.a
lipo -create arm64/lib/libpjmedia-audiodev-arm64-apple-darwin_ios.a armv7/lib/libpjmedia-audiodev-armv7-apple-darwin_ios.a armv7s/lib/libpjmedia-audiodev-armv7s-apple-darwin_ios.a x64/lib/libpjmedia-audiodev-x86_64-apple-darwin_ios.a x86/lib/libpjmedia-audiodev-i386-apple-darwin_ios.a -output all/lib/libpjmedia-audiodev.a
lipo -create arm64/lib/libpjmedia-arm64-apple-darwin_ios.a armv7/lib/libpjmedia-armv7-apple-darwin_ios.a armv7s/lib/libpjmedia-armv7s-apple-darwin_ios.a x64/lib/libpjmedia-x86_64-apple-darwin_ios.a x86/lib/libpjmedia-i386-apple-darwin_ios.a -output all/lib/libpjmedia.a
lipo -create arm64/lib/libpjmedia-codec-arm64-apple-darwin_ios.a armv7/lib/libpjmedia-codec-armv7-apple-darwin_ios.a armv7s/lib/libpjmedia-codec-armv7s-apple-darwin_ios.a x64/lib/libpjmedia-codec-x86_64-apple-darwin_ios.a x86/lib/libpjmedia-codec-i386-apple-darwin_ios.a -output all/lib/libpjmedia-codec.a
lipo -create arm64/lib/libpjmedia-videodev-arm64-apple-darwin_ios.a armv7/lib/libpjmedia-videodev-armv7-apple-darwin_ios.a armv7s/lib/libpjmedia-videodev-armv7s-apple-darwin_ios.a x64/lib/libpjmedia-videodev-x86_64-apple-darwin_ios.a x86/lib/libpjmedia-videodev-i386-apple-darwin_ios.a -output all/lib/libpjmedia-videodev.a
lipo -create arm64/lib/libpjnath-arm64-apple-darwin_ios.a armv7/lib/libpjnath-armv7-apple-darwin_ios.a armv7s/lib/libpjnath-armv7s-apple-darwin_ios.a x64/lib/libpjnath-x86_64-apple-darwin_ios.a x86/lib/libpjnath-i386-apple-darwin_ios.a -output all/lib/libpjnath.a
lipo -create arm64/lib/libpjsip-arm64-apple-darwin_ios.a armv7/lib/libpjsip-armv7-apple-darwin_ios.a armv7s/lib/libpjsip-armv7s-apple-darwin_ios.a x64/lib/libpjsip-x86_64-apple-darwin_ios.a x86/lib/libpjsip-i386-apple-darwin_ios.a -output all/lib/libpjsip.a
lipo -create arm64/lib/libpjsip-simple-arm64-apple-darwin_ios.a armv7/lib/libpjsip-simple-armv7-apple-darwin_ios.a armv7s/lib/libpjsip-simple-armv7s-apple-darwin_ios.a x64/lib/libpjsip-simple-x86_64-apple-darwin_ios.a x86/lib/libpjsip-simple-i386-apple-darwin_ios.a -output all/lib/libpjsip-simple.a
lipo -create arm64/lib/libpjsip-ua-arm64-apple-darwin_ios.a armv7/lib/libpjsip-ua-armv7-apple-darwin_ios.a armv7s/lib/libpjsip-ua-armv7s-apple-darwin_ios.a x64/lib/libpjsip-ua-x86_64-apple-darwin_ios.a x86/lib/libpjsip-ua-i386-apple-darwin_ios.a -output all/lib/libpjsip-ua.a
lipo -create arm64/lib/libpjsua-arm64-apple-darwin_ios.a armv7/lib/libpjsua-armv7-apple-darwin_ios.a armv7s/lib/libpjsua-armv7s-apple-darwin_ios.a x64/lib/libpjsua-x86_64-apple-darwin_ios.a x86/lib/libpjsua-i386-apple-darwin_ios.a -output all/lib/libpjsua.a
lipo -create arm64/lib/libpjsua2-arm64-apple-darwin_ios.a armv7/lib/libpjsua2-armv7-apple-darwin_ios.a armv7s/lib/libpjsua2-armv7s-apple-darwin_ios.a x64/lib/libpjsua2-x86_64-apple-darwin_ios.a x86/lib/libpjsua2-i386-apple-darwin_ios.a -output all/lib/libpjsua2.a
lipo -create arm64/lib/libresample-arm64-apple-darwin_ios.a armv7/lib/libresample-armv7-apple-darwin_ios.a armv7s/lib/libresample-armv7s-apple-darwin_ios.a x64/lib/libresample-x86_64-apple-darwin_ios.a x86/lib/libresample-i386-apple-darwin_ios.a -output all/lib/libresample.a
lipo -create arm64/lib/libspeex-arm64-apple-darwin_ios.a armv7/lib/libspeex-armv7-apple-darwin_ios.a armv7s/lib/libspeex-armv7s-apple-darwin_ios.a x64/lib/libspeex-x86_64-apple-darwin_ios.a x86/lib/libspeex-i386-apple-darwin_ios.a -output all/lib/libspeex.a
lipo -create arm64/lib/libsrtp-arm64-apple-darwin_ios.a armv7/lib/libsrtp-armv7-apple-darwin_ios.a armv7s/lib/libsrtp-armv7s-apple-darwin_ios.a x64/lib/libsrtp-x86_64-apple-darwin_ios.a x86/lib/libsrtp-i386-apple-darwin_ios.a -output all/lib/libsrtp.a
lipo -create arm64/lib/libyuv-arm64-apple-darwin_ios.a armv7/lib/libyuv-armv7-apple-darwin_ios.a armv7s/lib/libyuv-armv7s-apple-darwin_ios.a x64/lib/libyuv-x86_64-apple-darwin_ios.a x86/lib/libyuv-i386-apple-darwin_ios.a -output all/lib/libyuv.a
将arm64中的include文件夹copy到all目录下
5. 将编译好的库导入到项目中去配置
Header Search Paths ——> $(PROJECT_DIR)/phone/all/include;
Other Linker Flags: -ObjC;
Preprocessor Macros: PJ_AUTOCONF=1
在Build Phases中的Link Binary With Libraries中添加Framework:AudioToolbox、AVFoundation
最后,附上小demo:https://github.com/SexiZhang/PJSIP
注:由于CSDN网络总是很不稳定,故预将CSDN博客迁入至,原CSDN地址:http://blog.csdn.net/zyy416243653/article/details/52814019