1.首先下载swig:https://www.swig.org/
进入你下载的swig文件
在根目录执行 configure
make
make install
能查出来版本说明安装好了 Swig -version
2.安装好后,创建一个目录 /PJSUA2/pjproject/src
在src目录下执行 wget http://svn.pjsip.org/repos/pjproject/trunk pjproject
也可以去官网下载下载下来如下:
下载好后进入这个project
cd pjproject
./configure --enable-shared CFLAGS=“-fPIC”
在pjproject执行
make dep
make
make install
最好前面加sudo
再进入python目录 cd pjsip-apps/src/swig/python
make dep
make
make install
mkdir /PJSUA2/pjproject/src
wget http://svn.pjsip.org/repos/pjproject/trunk pjproject
cd pjproject
./configure --enable-shared CFLAGS=“-fPIC”
make dep
make
make install
官网的代码:
import pjsua2 as pj
# Subclass to extend the Account and get notifications etc.
class Account(pj.Account):
def onRegState(self, prm):
print("***OnRegState: " + prm.reason)
# pjsua2 test function
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig();
sipTpConfig.port = 5060;
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig);
# Start the library
ep.libStart();
acfg = pj.AccountConfig();
acfg.idUri = "sip:test@sip.pjsip.org";
acfg.regConfig.registrarUri = "sip:sip.pjsip.org";
cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest");
acfg.sipConfig.authCreds.append( cred );
# Create the account
acc = Account();
acc.create(acfg);
# Here we don't have anything else to do..
time.sleep(10);
# Destroy the library
ep.libDestroy()
#
# main()
#
if __name__ == "__main__":
pjsua2_test()
参考:
https://www.cnblogs.com/lianghe01/p/7577182.html