首页 > 其他分享 >SIP UserAgent (B2BUA client)——pjsip

SIP UserAgent (B2BUA client)——pjsip

时间:2023-10-31 15:04:52浏览次数:40  
标签:pjsua SIP https -- pjsip install linux UserAgent arm

1. sip stacks

pjsip/bell-sip/sofia-sip/libeXosip/libre

https://github.com/staskobzar/sip_stacks_examples

 

2. sip user agent and server network architecture

3. Installing pjsip on Ubuntu

https://www.pjsip.org

sudo apt-get install libasound2-dev

Linux system has two audio drivers: alsa and oss,oss is old,pjsip supports both,deflaut is oss.

如果目标系统内核使用的是alsa驱动,运行例子程序的时候会出现以下问题。

alsa_dev.c ! ca_thread_func: error reading data!   解决方法 修改config_site.h文件 在pjproject\pjlib\include\pj目录下

add #define PJMEDIA_AUDIO_DEV_HAS_ALSA 1 

 

4. cross-compile 

_install.sh

复制代码
#compiler setup
if [[ $1 = 'arm' ]]; then
compiler=`CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++`
host=arm-linux-gnueabihf
elif [[ $1 = 'himix100' ]]; then
compiler=`CC=arm-himix100-linux-gcc CXX=arm-himix100-linux-g++`
host=arm-himix100-linux
elif [[ $1 = 'himix200' ]]; then
compiler=`CC=arm-himix200-linux-gcc CXX=arm-himix200-linux-g++`
host=arm-himix200-linux
else
:
fi

#Preinstalled directory
install=${HOME}/_install

#Delete installed directory
rm -rf ${install}

#library path
pkg_config=${install}/lib/pkgconfig
lib_config=`CPPFLAGS=-I${install}/include CFLAGS=-I${install}/include LDFLAGS=-L${install}/lib`

#Delete compiled directory
for i in `ls .`
    do
    if [ -d $i ];then
    rm -rf $i
    fi
done

tar xvf alsa-lib-*
cd alsa-lib-*
./configure ${compiler} --prefix=${install} --host=${host}
make && make install
cd ..

tar xvf alsa-utils-*
cd alsa-utils-*
./configure ${compiler} --prefix=${install} --host=${host} PKG_CONFIG_PATH=${pkg_config} ${lib_config} --enable-static --enable-shared --disable-alsamixer --disable-xmlto
touch ./alsaconf/po/t-ja.gmo
touch ./alsaconf/po/t-ru.gmo
make && make install
cd ..

tar xvf pjproject-*
cd pjproject-*
./configure ${compiler} --prefix=${install} --host=${host} PKG_CONFIG_PATH=${pkg_config} ${lib_config} --enable-static --enable-shared --disable-libwebrtc
make dep
make && make install
cd ..

export PATH=$PATH:${install}/bin
export LD_LIBRARY_PATH=${install}/lib:$LD_LIBRARY_PATH
export ALSA_CONFIG_PATH=${install}/share/alsa/alsa.conf
复制代码

dong@ubuntu:~/pjsip$ su
Password:
root@ubuntu:/home/dong/pjsip# ./_install.sh arm
root@ubuntu:~# tar cvf _install.tar.gz _install/
root@ubuntu:~# mv _install.tar.gz /home/dong/
dong@ubuntu:~$ sudo chmod 777 _install.tar.gz

4)如果用的海思arm-himix200-linux-gcc编译器,如果报错的话,可能需要将

alsa-utils-1.1.9/alsamixer/alsa-utils-1.1.9/alsamixer/volume_mapping.c里的三行exp10改成exp

 

5)声卡设备验证

#查看音频设备

dong@dong-ubuntu:~$ arecord -l
**** CAPTURE 硬體裝置清單 ****
card 0: PCH [HDA Intel PCH], device 0: ALC255 Analog [ALC255 Analog]
  子设备: 1/1
  子设备 #0: subdevice #0

#列举出机器所有的声卡
dong@dong-ubuntu:~$ cat /proc/asound/cards
 0 [PCH            ]: HDA-Intel - HDA Intel PCH
                      HDA Intel PCH at 0xa4220000 irq 132

#列举每个声卡的card number和device number
dong@dong-ubuntu:~$ aplay -l
**** PLAYBACK 硬體裝置清單 ****
card 0: PCH [HDA Intel PCH], device 0: ALC255 Analog [ALC255 Analog]
  子设备: 1/1
  子设备 #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  子设备: 1/1
  子设备 #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  子设备: 1/1
  子设备 #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  子设备: 1/1
  子设备 #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  子设备: 1/1
  子设备 #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  子设备: 1/1
  子设备 #0: subdevice #0

#录音
dong@dong-ubuntu:~$ arecord -D "plughw:0,0" -f S16_LE -r 16000 -d 5 -t wav file.wav
正在录音 WAVE 'file.wav' : Signed 16 bit Little Endian, 频率16000Hz, Mono

#播放录音文件
dong@dong-ubuntu:~$ aplay file.wav
正在播放 WAVE 'file.wav' : Signed 16 bit Little Endian, 频率16000Hz, Mono

 

一般alsa设置了一个defaults设备,音频播放软件默认使用defaults设备输出声音。defaults设备定义在alsa.conf中,内容如下:

[plain]  
#  
# defaults  
#  
  
# show all name hints also for definitions without hint {} section  
defaults.namehint.showall off  
# show just basic name hints  
defaults.namehint.basic on  
# show extended name hints  
defaults.namehint.extended off  
#  
defaults.ctl.card 0  
defaults.pcm.card 0  
defaults.pcm.device 0  
defaults.pcm.subdevice -1  
……   

defaults会默认匹配card number和device number比较小的声卡。
如果要修改,则修改/etc/asound.conf或~/.asoundrc。比如我要把defaults匹配到card 1,device 3上,则添加一下几行:

[plain]  
$ sudo vim /etc/asound.conf   
defaults.pcm.card 1  
defaults.pcm.device 3  
defaults.ctl.card 1   

5) 添加声卡节点

if [ ! -d /dev/snd/ ]; then
    echo "make snd node."
    mkdir /dev/snd
    ln -s /dev/pcmC0D0c  /dev/snd/pcmC0D0c
    ln -s /dev/pcmC0D0p /dev/snd/pcmC0D0p
    ln -s /dev/timer /dev/snd/timer
    ln -s /dev/controlC0 /dev/snd/controlC0
    ln -s /dev/mixer /dev/snd/mixer
fi

5) 录音播音测试
arecord -D "plughw:0,0" -f S16_LE -r 16000 -d 5 -t wav file.wav
aplay file.wav

arecord -d 10 -f cd -r 8000 -c 2 -t wav test.wav
arecord -D "plughw:0,0" -f U16_LE -r 16000 -d 5 -t wav file.wav
arecord -d 10 -t raw -f S16_LE test.pcm
aplay -t raw -c 1 -f S16_LE -r 8000 test.pcm
arecord -d 10 -t raw -f U16_LE test.pcm
aplay -t raw -c 1 -f U16_LE -r 8000 test.pcm
arecord -d 10 -t raw -f U8 test.pcm
aplay -t raw -c 1 -f U8 -r 8000 test.pcm
aplay -t raw -r 8000 test.g711
arecord -D "plughw:0,0" -f U16_LE -r 16000 -d 5 -t wav file.wav
arecord -f S16_LE | aplay -f S16_LE

 

3、pjsua应用实例

pjsua Manual Page

https://www.pjsip.org/pjsua.htm

1) register --- make call
./pjsua-x86_64-unknown-linux-gnu --config-file paul.cfg
m
sip:[email protected]:5060

2) peer to peer
./pjsua-x86_64-unknown-linux-gnu --null-audio
./pjsua-x86_64-unknown-linux-gnu sip:120.78.180.208 --null-audio

3) register cli
>>> +a
Your SIP URL: (empty to cancel):sip:[email protected]:5060
URL of the registrar: (empty to cancel):sip:120.78.180.208:5060
Auth Realm: (empty to cancel): *
Auth Username: (empty to cancel): 100
Auth Password: (empty to cancel): 100
 

sip:[email protected]

 

4) alice.cfg

# This is a comment in the config file.
--id sip:[email protected]:5060
--registrar sip:xx.xxx.xx.236:5060
--realm *
--username alice
--password secret

启动程序,自动应答

./pjsua-arm-unknown-linux-gnueabihf --config-file alice.cfg --auto-answer 200

指定“紧凑模式”(去掉SIP协议的一些非必须的字段),采样率和编码优先级,我在cortex-a5上以默认参数启动,会出现pb和ca线程不同步underrun!

./pjsua-arm-unknown-linux-gnueabihf --config-file alice.cfg --use-compact-form --clock-rate=8000 --add-codec=pcmu --auto-answer 200

其他配置参考官网应用手册https://www.pjsip.org/pjsua.htm

 

5) 临时建群,多方通话

查看pjsua应用手册https://www.pjsip.org/pjsua.htm

的Call Commands和Conference Commands

M

Make multiple calls Make multiple calls to the same destination.

 

cl

Conference List List all the ports registered to the conference bridge, and show the interconnection among these ports.

cc

Conference Connect Create a unidirectional connection between two ports. For example, if you have a WAV player connected at slot #1 and a call connected at slot #2, you can stream WAV file to the call by specifying this command: cc 1 2.

cl查看已拨号的通道, 0是拨号的主叫号码本身,1和2分别是ringback和ring,3和4是被叫号码

M

2

sip:[email protected]:5060

sip:[email protected]:5060

cc 3 4

cc 4 3

 

6) freepbx语音会议

配置好freepbx语音会议后,直接拨号会议号,然后输入密码进入会议室

./pjsua-x86_64-unknown-linux-gnu --config-file 106.cfg --use-compact-form --clock-rate=8000 --add-codec=pcmu --auto-answer 200

也可以自动登陆会议室,auto-conf是自动登陆会议室

./pjsua-x86_64-unknown-linux-gnu --config-file 106.cfg --use-compact-form --clock-rate=8000 --add-codec=pcmu --auto-answer 200 --auto-conf sip:[email protected]:5060

PC/android/ios也是一样的操作

 

 

4、 py_pjsua应用实例

https://trac.pjsip.org/repos/wiki/Py_PJSUA

python实例在pjsip-apps/src/python/samples/

 

5、Python_SIP编译安装
1) ./configure CFLAGS='-O2 -fPIC' --enable-shared
https://trac.pjsip.org/repos/wiki/Python_SIP/Build_Install

 2) pjsua2安装

sudo apt-get install -y software-properties-common # To make add-apt-repository work
sudo add-apt-repository ppa:dennis.guse/sip-tools 
sudo apt-get update 
sudo apt-get install python-pjsua
sudo apt-get install python-pjsua2

To check if everything went well:

python
import pjsua 
https://stackoverflow.com/questions/20195542/python-how-to-get-the-import-pjsua-giving-no-module-named-pjsua

3)Building PJSUA2 and SWIG

The PJSUA2 C++ library will be built by default by PJSIP build system. Standard C++ library is required. If you intend to use Python SWIG module (see below), you need to configure PJSIP with --enable-shared option, i.e.:

./configure --enable-shared
make dep & make
sudo make install
https://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html#building-python-and-java-swig-modules

装好pjsua2就可以启动pygui测试了拨号了,这个例子带图形界面,ui用的Tkinter,另外一个带gui的例子是vidgui,ui用的qt

  

 

6、Using OpenCORE AMR NB and WB Codecs

https://trac.pjsip.org/repos/wiki/Using-OpenCORE-AMR-NB-WB-Codec

#opencore-amr 和 vo-amrwbenc
./configure --prefix=$(pwd)/_install --host=arm-linux-gnueabihf CC=/usr/local/arm/gcc-4.9.4-arm-buildroot-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc
make
make install

装好之后将两个库的_install目录合并,合并到opencore-amr-0.1.3/_install

#pjproject
./configure --prefix=/home/dong/pjproject-2.8/_install --host=arm-linux-gnueabihf CC=/usr/local/arm/gcc-4.9.4-arm-buildroot-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc --disable-libwebrtc CFLAGS=-I/home/dong/alsa/include LDFLAGS=-L/home/dong/alsa/lib --with-opencore-amr=$(pwd)/third_party/opencore-amr-0.1.3/_install

make dep
make
make install

 

 ln -s libopencore-amrnb.so.0.0.3 libopencore-amrnb.so.0
 ln -s libopencore-amrwb.so.0.0.3 libopencore-amrwb.so.0
 ln -s libvo-amrwbenc.so.0.0.4 libvo-amrwbenc.so.0

 

7、Ubuntu 16.04 下编译pjsip,支持视频通话

https://blog.csdn.net/wywf4/article/details/82260582

https://blog.csdn.net/SUKHOI27SMK/article/details/18667465

https://github.com/sxcong/pjsipvideo_demo

 

 

2. js sip user agent

http://www.jssip.net/

https://sipjs.com/

 

基于pjsip实现p2p语音对讲

https://blog.csdn.net/voidreturn/article/details/65634390

Pjsip中一些有用的基本函数实现

https://blog.csdn.net/croop520/article/details/84634160

pjsua播放rtp音频包问题

https://blog.csdn.net/rankun1/article/details/52034323

可以推荐一些基于Sip协议的开源IP电话客户端吗?

https://www.zhihu.com/question/20093472?sort=created

 

freepbx对接gms网关

https://blog.csdn.net/weixin_30656145/article/details/97707013

 freeswitch对接asterisk案例

https://blog.csdn.net/educast/article/details/25310819

end

标签:pjsua,SIP,https,--,pjsip,install,linux,UserAgent,arm
From: https://www.cnblogs.com/kn-zheng/p/17800207.html

相关文章

  • MicroSIP-3.21.3+pjproject-2.13.1+ opus-1.3.1+VS2019
    本文记录了我通过VS2019编译MicroSIP-3.21.3开源项目的过程。Microsip:MicroSIPsourcecodepjproject:DownloadPJSIP-OpenSourceSIP,Media,andNATTraversallibraryopus:Downloads–OpusCodec(opus-codec.org)下载并解压后如图: 用vs2019将microsip的平......
  • sipp3.6多方案压测脚本
     概述SIP压测工具sipp,免费,开源,功能足够强大,配置灵活,优点多。有时候我们需要模拟现网的生产环境来压测,就需要同时有多个sipp脚本运行,并且需要不断的调整呼叫并发。通过python脚本的子进程功能,我们可以很方便的实现sipp的多方案压测功能。环境centos7.9freeswitch1.10.7si......
  • pjsip内存优化及提升视频呼叫并发数
      工作上的一个上层调度台应用(Windows7),业务功能上有并发调取多个视频的需求,发现调取30左右路D1视频后会导致崩溃,日志提示:except.c !!!FATAL:unhandledexceptionPJLIB/Nomemory!,内存不足,在开发环境下验证发现内存占用已经达到2G以上(32位程序默认最高给2G内存,通过配置能......
  • 使用三方摄像头,实现pjsip的视频通话功能
    提要:近期一直在做视频通话功能,主要基于pjsip来实现的,将这些过程记录下来,可能对做同类型工作的同学有所帮助!实现思路,参考pjsip原来设备采集视频、编码并rtp组包发送的思路,再在原有流程中做修改!主要关键点:1、摄像头采集完成后已经是已编码的H264/H265的流,不需要再开启pjsip的编......
  • mac 苹果电脑关闭安全限制SIP
    关机10s之后按住指纹模块直到出现加载,进入设置,选择终端在终端中输入csrutildisable关闭sipcsrutilstatus查看关闭是否成功......
  • P7782 「MCOI-Zero / AC6-M03」 Sipli Field
    P7782「MCOI-Zero/AC6-M03」SipliField更好的阅读体验单log淀粉做法。回想正常淀粉计算的是树上的路径问题,但题目中要求计算经过每个点的答案,这样我们选取重心后一棵子树对另一棵子树的答案就会少算,所以我们淀粉时不仅要算根的答案,也要考虑子树间的相互贡献。首先以根......
  • navigator.userAgent 判断当前浏览器所处的环境
    场景1:判断页面是在手机端还是PC端打开window.location.href=/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)?"http://localhost:8888/mobile_web":"http://localhost:8888/PC";场景2:判断页面是在手机端,平板端还是PC端打开varos=function(){va......
  • 技术解码 | GB28181/SIP/SDP 协议--EasyGBS国标GB28181平台国标视频技术SIP解析
    EasyGBS国标视频云服务是基于国标GB/T28181协议的视频能力平台,可实现的视频功能包括:实时监控直播、录像、检索与回看、语音对讲、云存储、告警、平台级联等功能。平台部署简单、可拓展性强,支持将接入的视频流进行全终端、全平台分发,分发的视频流包括RTSP、RTMP、FLV、HLS、WebRTC等......
  • 日常分享专栏系列之:Gossip protocol
    日常分享专栏系列之:Gossipprotocol一、认识Gossipprotocol二、Gossipprotocol特点三、Cassandra数据库对Gossip协议的应用四、Gossipprotocol官方文档一、认识GossipprotocolGossipprotocol是一种分布式系统中用于信息传播和一致性维护的通信协议。它是一种通过节点之间相......
  • 直播平台开发协议分析篇(一):会话初始化协议SIP
    在现代科技的推动下,直播平台被开发出来,成为了全世界人们分享与传播内容的重要渠道,直播平台越来越受欢迎,也督促了开发者要开发出更优质的直播平台,大部分人都明白,要想开发出更优质的直播平台,离不开的是各种优质功能技术,但是,在直播平台开发过程中,还有一个关键的东西需要开发者用心地......