pjsip

来源:互联网 发布:mysql的全文索引 编辑:程序博客网 时间:2024/04/29 23:52

Sip开发

Pjsip介绍

官网:        https://trac.pjsip.org/repos/

   源码下载:   http://www.pjsip.org/download.htm

Pjsip组成

1).PJSIP - Open Source SIP Stack[开源的SIP协议栈]

2).PJMEDIA - Open Source Media Stack[开源的媒体栈]

3).PJNATH - Open Source NAT Traversal Helper Library[开源的NAT-T辅助库]

4).PJLIB-UTIL - Auxiliary Library[辅助工具库]

5).PJLIB - Ultra Portable Base Framework Library[基础框架库]

 

而在最上层库的目录分为:(可以使用tree -d-L 1查看)

 

  $TOP/build                 [包含Makefile]

  $TOP/build.symbian         [针对symbianMakefile]

  $TOP/pjlib                  [参考上面]

  $TOP/pjlib-util           [参考上面]

  $TOP/pjnath              [参考上面]

  $TOP/pjmedia           [参考上面]

  $TOP/pjsip                 [参考上面]

  $TOP/pjsip-apps

  $TOP/third_party

 

而在每个子目录,可以看到分为:

  bin                                         [编译后产生的二进制文件]

  build                                               [Makefile]

            build/output

            build/wince-evc4

  docs                                      [doxygen的文档,doxygendocs/doxygen.cfg产生]

  include                                           [头文件]

  lib                                          [编译后产生的库]

  src                                         [源代码]

 

Pjsip特点

1).非动态内存分配[No Dynamic Memory Allocations]

  实现了内存池,获取内存是从与分配的内存池中获取,高性能程序多会自己构造内存池,后面我们会解释该内存池的使用以及基本的原理。根据作者的比较,是常规的 malloc()/free()函数的30倍。

           

2).OS抽象[Operating System Abstraction]

实现OS抽象的根本原因在与可移植性,毋庸置疑:).涉及到:

  a).线程[Threads.]

  b).线程本地存储[ThreadLocal Storage.]

  c).互斥[Mutexes.]

  d).信号灯[Semaphores.]

  e).原子变量[AtomicVariables.]

  f).临届区[Criticalsections.]

  g).锁对象[LockObjects.]

  h).事件对象[EventObject.]

  i).时间管理[TimeData Type and Manipulation.]

  j).高解析的时间戳[HighResolution Timestamp.]

等等,这些我们后面分析代码时一一看来:)

           

3).低层的网络相关IO[Low-Level Network I/O]

 这涉及到:

    a).Socket抽象[SocketAbstraction.]

    b).网络地址解析[NetworkAddress Resolution.]

    c).实现针对SocketselectAPI[Socket select() API.]

     

4).时间管理[Timer Management]

  这主要涉及到两个部分,一个时定时器的管理,还有就是时间解析的精度(举例说来,就是能精确到哪个时间等级,比如 POSIX sleep(),就只能以秒为单位,而使用select()则可以实现毫秒级别的计时)

 

5).各种数据结构[Various Data Structures]

  主要有:

  a).针对字符串的操作[StringOperations]

  b).数组辅助[Arrayhelper]

  c).Hash[Hash Tabl]

  d).链表[LinkedList]

  e).红黑平衡树[Red/BlackBalanced Tree]

           

6).异常处理[Exception Construct]

  使用的是TRY/CATCH,知道C++/JAVA之类面向对象语言的人看过会宛而一笑:)

             

7).LOG机制[Logging Facility]

  很显然,一个良好的程序,好的LOG机制不可少。这能很方便的让你去调试程序,对此我是深有体会,任何时候,不要忘记好的程序,是架构出来的;而能跑的程序,是调试出来的:)”

           

8).随机数以及GUID的产生[Random and GUID Generation]

  GUID指的是"globallyunique identifier",只是一个标识而已,比如说你的省份证,算的上是一个GUID,当然,准确说来是“china unique identifier”:).

 

Pjsip编译

centOS上编译pjsip

tar jxvf pjproject-2.5.5.tar.bz2

 

./configure--prefix=/home/mpc8306/pjsip/pjsip_linux --disable-libyuv --disable-sound

 

说明:不支持音视频

 

make dep

 

make clean

 

make

 

make install

 

遇到问题:

问题1centOS编译pjsip库时,make时错误(Add libyuv to third party component

../../yuv/source/row_common.cc: In function‘void libyuv::YuvPixel(uint8, uint8, uint8, uint8*, uint8*, uint8*, constlibyuv::YuvConstants*)’:

../../yuv/source/row_common.cc:1256: error:invalid types ‘const signed char __vector__[int]’ for array subscript

解决:use GCC 4.8 or newer, or if you don't need video feature, justdisable libyuv (i.e: using configure script param --disable-libyuv or--disable-video).

 

问题2centOS编译pjsip库时,make时错误

../src/pjmedia-audiodev/alsa_dev.c:988:error: ‘struct alsa_stream’ has no member named ‘ca_pcm’

解决:yum install libasound2-dev

powerpc-e300c3-linux-gnu-gcc交叉编译pjsip

1、在/pjproject-2.5.5/pjlib/include/pj目录下打开config.h这个文件,并添加内容

 

#define PJ_IS_LITTLE_ENDIAN 1

#define PJ_IS_BIG_ENDIAN 0

 

2 tar jxvfpjproject-2.5.5.tar.bz2

 

3./configure--prefix=/home/mpc8306/pjsip/pjsip_powerpc --host=powerpc-e300c3-linux--target=powerpc-e300c3-linux         CC=powerpc-e300c3-linux-gnu-gcc          CXX=powerpc-e300c3-linux-gnu-g++--disable-libyuv --disable-libyuv --disable-sound

说明:不支持音视频

 

4 make clean

 

5 make dep

 

6 make

 

7 make install

遇到问题

问题1

output/pjsua2-test-powerpc-e300c3-linux-gnu/main.o:could not read symbols: File in wrong format

collect2: ld returned 1 exit status

make[2]: *** [../bin/pjsua2-test-powerpc-e300c3-linux-gnu]Error 1

make[2]: Leaving directory`/home/mpc8306/pjsip/pjproject-2.5.5-powerpc/pjsip/build'

make[1]: ***[pjsua2-test-powerpc-e300c3-linux-gnu] Error 2

make[1]: Leaving directory`/home/mpc8306/pjsip/pjproject-2.5.5-powerpc/pjsip/build'

解决:./configure时没有指定 CXX=powerpc-e300c3-linux-gnu-g++

 

问题2

/home/mpc8306/pjsip/pjsip_powerpc/include/pj/config.h:1195:4:error: #error "PJ_IS_LITTLE_ENDIAN is not defined!"

/home/mpc8306/pjsip/pjsip_powerpc/include/pj/config.h:1199:4:error: #error "PJ_IS_BIG_ENDIAN is not defined!"

/home/mpc8306/pjsip/pjsip_powerpc/include/pj/config.h:263:6:error: #error Endianness must be declared for this processor

解决:在pj/下添加config.h,并添加

#define PJ_IS_BIG_ENDIAN 1

#define PJ_IS_LITTLE_ENDIAN 0

注意:powerpc是大端模式

 

问题3

/opt/freescale/usr/local/gcc-4.1.78-eglibc-2.5.78-1/powerpc-e300c3-linux-gnu/lib/gcc/powerpc-e300c3-linux-gnu/4.1.2/../../../../powerpc-e300c3-linux-gnu/bin/ld:cannot find -luuid

collect2: ld returned 1 exit status

make: *** [pjsip_demo] Error 1

 

解决:

makefile中去掉-luuid

Mingw编译pjsip

1, 安装mingw

下载http://sourceforge.net/projects/mingw/files/

2, mingw中安装:msys-basemingw32-gccmingw32-gcc-g++mingw32-libz

mingwbin目录(如C:\MinGW\bin)添加到系统环境变量path

3, 安装sdl2
sdl网站https://www.libsdl.org/download-2.0.php下载Development Libraries:SDL2-devel-2.0.3-mingw.tar.gz
将子目录i686-w64-mingw32解压到D:\video\目录下,并将附件中的SDL_platform.h覆盖include/SDL2下的原文件
D:\video\i686-w64-mingw32\bin添加到系统环境变量path

4,  安装ffmpeg1.2
zeranoe ffmpeghttps://ffmpeg.zeranoe.com/blog/?p=178)下载ffmpegwindows版本:FFmpeg 1.2 Win32 SharedFFmpeg 1.2 Win32 Dev解压到D:\video\目录下
将附件中pkgconfig中的.pc文件复制到D:\video\ffmpeg-1.2-win32-dev\lib\pkgconfig,修改.pc文件

prefix=/video/ffmpeg-1.2-win32-dev/

将D:\video\ffmpeg-1.2-win32-shared\bin添加到系统环境变量path

5, 安装pkg-config
GTK+ for Windows下载GLib DLLpkg-config.exe,解压libglib-2.0-0.dllpkg-config.exeC:\MinGW\bin,将libintl-8.dll复制另命名intl.dll

6,  创建msys目录下的fstab文件(C:\MinGW\msys\1.0\etc),添加内容:如d:/pjproject-2.3 /pjsipd:/video /video

7,  解压pjsip2.3.0,在pjsip目录下(如D:\pjproject-2.3\pjlib\include\pj)

创建config_site.h,添加

#define PJMEDIA_HAS_VIDEO 1

8,启动msys.bat

cd /pjsip

exportPKG_CONFIG_PATH=/video/ffmpeg-1.2-win32-dev/lib/pkgconfig

./configureCFLAGS="-I/video/i686-w64-mingw32/include/SDL2"LDFLAGS="-L/video/i686-w64-mingw32/lib"

make dep

make

 

1configure过程中出现错误,查看config.Log,原因是没有链接到pthread库,打开MinGW Installer

注2:编译可执行程序时出错(没有链接到库)

a.    WIN32下链接ole32, Linux下链接libuuid

b.   -lws2_32

c.    –lwinmm

 

 

运行pjsua

官网文档:

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

 

1、  运行pjsua

 

cd pjsip-apps/bin

./pjsua-i686-pc-linux-gnu--null-audio

 

注:(这里一定要加上null-audio启动选项(Use NULL audio device),否则放音时会提示由于找不到默认声卡而出错)

 

2、  pjsua注册到服务器:

 

>>> +a  添加用户

 

Your SIP URL: (empty to cancel):sip:1000@192.168.1.90:5060

 

URL of the registrar: (empty to cancel):sip:192.168.1.89:5060

 

Auth Realm: (empty to cancel): 192.168.1.90

 

Auth Username: (empty to cancel): 1000

 

Auth Password: (empty to cancel): 1234

 

遇到问题

问题1:没有插入麦克风设备

pjsua_call.c  Making call with acc #1 to sip:192.168.1.88

pjsua_aud.c .Set sound device: capture=-1, playback=-2

pjsua_aud.c ..Error retrieving default audio device parameters: Unable to finddefault audio device (PJMEDIA_EAUD_NODEFDEV) [status=420006]

解决:

./pjsua-i686-pc-linux-gnu --null-audio

Mpc8306开发板运行pjsua程序退出卡死(pjsua_destroy()

解决:移植问题,powerpc是大端模式 (同上)

0 0
原创粉丝点击