一、Linux上编译PJSIP
PJSIP是一个开源的多媒体通信库,支持SIP、SDP、RTP、STUN、TURN和ICE协议。以下是在Linux系统上编译PJSIP的步骤:
准备工作
-
安装依赖项:
bash
sudo apt-get update sudo apt-get install build-essential python3 libssl-dev libasound2-dev libv4l-dev libopus-dev libsdl2-dev libavcodec-dev libavformat-dev libswscale-dev libavdevice-dev
-
下载PJSIP:
从官网下载最新版本或使用git克隆:bash
git clone https://github.com/pjsip/pjproject.git cd pjproject
配置和编译
-
配置编译选项:
bash
./configure --enable-shared --disable-opencore-amr --disable-resample --disable-sound --disable-video --disable-l16-codec --disable-gsm-codec --disable-g722-codec --disable-g7221-codec --disable-speex-codec --disable-ilbc-codec --disable-sdl --disable-ffmpeg --disable-v4l2 --disable-openh264 --disable-resample-dll --disable-libwebrtc
(根据你的需求调整这些选项,上述命令禁用了许多可选功能以简化编译)
-
开始编译:
bash
make dep make
-
安装:
bash
sudo make install
可选配置
-
启用更多功能:
如果需要视频支持或其他编解码器,可以修改配置选项,例如:bash
./configure --enable-video --with-external-speex --with-external-gsm --with-external-pa
-
Python绑定:
如果需要Python支持:bash
cd pjsip-apps/src/python sudo python3 setup.py install
测试安装
编译并安装完成后,可以运行简单测试:
bash
cd pjsip-apps/bin
./pjsua-x86_64-unknown-linux-gnu
常见问题解决
-
缺少依赖项:
如果编译失败,检查错误信息并安装相应的开发包。 -
权限问题:
确保你有足够的权限写入安装目录(通常需要sudo)。 -
版本兼容性:
如果遇到问题,尝试使用较旧版本的PJSIP。 -
自定义安装路径:
使用--prefix
选项指定安装路径:bash
./configure --prefix=/your/custom/path
二、Windows上编译PJSIP
在Windows平台上编译PJSIP需要一些额外的准备工作。以下是详细的步骤:
准备工作
1. 安装必要的工具
-
Visual Studio:推荐使用VS2015/2017/2019/2022(社区版即可)
-
Python:安装Python 3.x(用于生成构建文件)
-
DirectX SDK(可选,如果需要音频支持)
-
NASM(如果需要汇编优化)
2. 下载源代码
cmd
git clone https://github.com/pjsip/pjproject.git
cd pjproject
编译步骤
方法1:使用Visual Studio解决方案
-
打开Visual Studio命令行工具(如"x64 Native Tools Command Prompt")
-
配置项目:
cmd
cd pjproject configure nmake
或者指定Visual Studio版本:
cmd
configure --vs2019 nmake
方法2:使用CMake(推荐)
-
创建build目录并进入:
cmd
mkdir build cd build
-
生成Visual Studio项目:
cmd
cmake -G "Visual Studio 16 2019" -A x64 ..
(根据你的VS版本调整"Visual Studio 16 2019")
-
编译:
cmd
cmake --build . --config Release
配置选项
在Windows上常用的配置选项:
cmd
configure --disable-sound --disable-video --disable-opencore-amr --enable-shared
常用选项说明:
-
--disable-sound
:禁用声音支持 -
--disable-video
:禁用视频支持 -
--enable-shared
:构建动态链接库 -
--target=x86_64
:指定64位目标平台
安装
编译完成后,库文件和可执行文件会生成在pjproject/pjsip/lib
和pjproject/pjsip/bin
目录中。
常见问题解决
-
Python路径问题:
确保Python在系统PATH中,或使用:cmd
set PATH=C:\Python39;%PATH%
-
Visual Studio版本不匹配:
使用--vs20XX
选项指定正确的VS版本 -
缺少Windows SDK:
通过Visual Studio Installer安装最新Windows SDK -
64位编译:
确保使用x64 Native Tools Command Prompt -
OpenSSL支持:
如果需要SSL支持,先安装OpenSSL并指定路径:cmd
configure --with-ssl=C:\OpenSSL-Win64
测试
编译完成后,可以运行pjsua测试:
cmd
cd pjsip-apps/bin
pjsua-x86_64-windows-vc14-Debug.exe
注意事项
-
推荐使用Visual Studio 2019或更高版本
-
对于生产环境,使用
Release
配置而非Debug
-
64位应用已成为标准,建议优先考虑x64构建
-
如果只需要核心SIP功能,可以禁用音视频以减少依赖