PJSIP Linux版をビルドする

PJSIP

PJSIPのLinux版をCentOS 5.4環境でビルドし、動作確認を行います。

PJSIP Linux版のダウンロード

PJSIP - Open Source SIP Stack
http://www.pjsip.org/download.htm
 pjproject-1.0.3.tar.bz2

準備

・pjproject-1.0.3.tar.bz2 を解凍し /home/pjsipディレクトリに作成します。
# cd /home
# mkdir pjsip
# tar jxvf <pjproject-1.0.3.tar.bz2> -C /home/pjsip

・pjlib/include/pj 配下に空ファイルconfig_site.hを作成します。
# cd /home/pjsip/pjproject-1.0.3/pjlib/include/pj
# vi config_site.h

ビルド

ビルドします。

# cd /home/pjsip/pjproject-1.0.3
# ./configure
# make dep
# make

ビルド結果

ビルド中にエラーがなければ、
/home/pjsip/pjproject-1.0.3/pjsip-apps/binにpjsua-i686-pc-linux-gnuが作成されます。

# cd /home/pjsip/pjproject-1.0.3/pjsip-apps/bin

# ls -l
合計 1324
-rwxr-xr-x 1 root root 1347557 11月  6 22:20 pjsua-i686-pc-linux-gnu
drwxr-xr-x 2 1000 1000    4096 11月  6 22:20 samples
#

動作確認

・/home/pjsip/pjproject-1.0.3/pjsip-apps/bin/pjsua-i686-pc-linux-gnu を実行します。
・SIPサーバにREGISTされることを確認します。

<動作確認環境>
SIPサーバ 3CX PhoneSystem sip:192.168.1.202
IP Soft Phone sip:9001@192.168.1.202
PJSIP sip:6002@192.168.1.166

<起動操作例>
# /home/pjsip/pjproject-1.0.3/pjsip-apps/bin/
# ./pjsua-i686-pc-linux-gnu --id=sip:6002@192.168.1.166 --registrar=sip:asrterisk@192.168.1.202 --realm=* --username=6002 --password=6002 --local-port=5061

--id=ローカルのSIP URL
--registrar=SIPサーバのIP URL
--realm=* (不明な場合)
--username=ユーザ名
--password=パスワード

<電話をかける>
・「m」+ Enter キーを押します。
・相手先SIPアドレスを入力してEnterキーを押します。
(例)sip:9001@192.168.1.202+ Enter

<電話を受ける>
・「a」 + Enterキーを押します。
・コードをきかれるので「200 」+ Enterキーを押します。

<通話終了>
・「h」 + Enterキーを押します。

マニュアル

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

--helpコマンド実行例

# ./pjsua-i686-pc-linux-gnu --help
 23:10:40.725 os_core_unix.c  pjlib 1.0.3 for POSIX initialized
 23:10:40.728 sip_endpoint.c  Creating endpoint instance...
 23:10:40.729          pjlib  select() I/O Queue created (0x9daf128)
 23:10:40.729 sip_endpoint.c  Module "mod-msg-print" registered
 23:10:40.729 sip_transport.  Transport manager created.
Usage:
  pjsua [options] [SIP URL to call]

General options:
  --config-file=file  Read the config/arguments from file.
  --help              Display this help screen
  --version           Display version info

Logging options:
  --log-file=fname    Log to filename (default stderr)
  --log-level=N       Set log max level to N (0(none) to 6(trace)) (default=5)
  --app-log-level=N   Set log max level for stdout display (default=4)
  --color             Use colorful logging (default yes on Win32)
  --no-color          Disable colorful logging
  --light-bg          Use dark colors for light background (default is dark bg)

SIP Account options:
  --use-ims           Enable 3GPP/IMS related settings on this account
  --use-srtp=N        Use SRTP?  0:disabled, 1:optional, 2:mandatory (def:0)
  --srtp-secure=N     SRTP require secure SIP? 0:no, 1:tls, 1:sips (def:1)
  --registrar=url     Set the URL of registrar server
  --id=url            Set the URL of local ID (used in From header)
  --contact=url       Optionally override the Contact information
  --contact-params=S  Append the specified parameters S in Contact URI
  --proxy=url         Optional URL of proxy server to visit
                      May be specified multiple times
  --reg-timeout=SEC   Optional registration interval (default 55)
  --realm=string      Set realm
  --username=string   Set authentication username
  --password=string   Set authentication password
  --publish           Send presence PUBLISH for this account
  --use-100rel        Require reliable provisional response (100rel)
  --auto-update-nat=N Where N is 0 or 1 to enable/disable SIP traversal behind
                      symmetric NAT (default 1)
  --next-cred         Add another credentials

SIP Account Control:
  --next-account      Add more account

Transport Options:
  --local-port=port   Set TCP/UDP port. This implicitly enables both 
                      TCP and UDP transports on the specified port, unless
                      if TCP or UDP is disabled.
  --ip-addr=IP        Use the specifed address as SIP and RTP addresses.
                      (Hint: the IP may be the public IP of the NAT/router)
  --no-tcp            Disable TCP transport.
  --no-udp            Disable UDP transport.
  --nameserver=NS     Add the specified nameserver to enable SRV resolution
                      This option can be specified multiple times.
  --outbound=url      Set the URL of global outbound proxy server
                      May be specified multiple times
  --stun-srv=name     Set STUN server host or domain

TLS Options:
  --use-tls           Enable TLS transport (default=no)
  --tls-ca-file       Specify TLS CA file (default=none)
  --tls-cert-file     Specify TLS certificate file (default=none)
  --tls-privkey-file  Specify TLS private key file (default=none)
  --tls-password      Specify TLS password to private key file (default=none)
  --tls-verify-server Verify server's certificate (default=no)
  --tls-verify-client Verify client's certificate (default=no)
  --tls-neg-timeout   Specify TLS negotiation timeout (default=no)
  --tls-srv-name      Specify TLS server name for multi-hosting server (optional)

Media Options:
  --add-codec=name    Manually add codec (default is to enable all)
  --dis-codec=name    Disable codec (can be specified multiple times)
  --clock-rate=N      Override conference bridge clock rate
  --snd-clock-rate=N  Override sound device clock rate
  --stereo            Audio device and conference bridge opened in stereo mode
  --null-audio        Use NULL audio device
  --play-file=file    Register WAV file in conference bridge.
                      This can be specified multiple times.
  --play-tone=FORMAT  Register tone to the conference bridge.
                      FORMAT is 'F1,F2,ON,OFF', where F1,F2 are
                      frequencies, and ON,OFF=on/off duration in msec.
                      This can be specified multiple times.
  --auto-play         Automatically play the file (to incoming calls only)
  --auto-loop         Automatically loop incoming RTP to outgoing RTP
  --auto-conf         Automatically put calls in conference with others
  --rec-file=file     Open file recorder (extension can be .wav or .mp3
  --auto-rec          Automatically record conversation
  --quality=N         Specify media quality (0-10, default=6)
  --ptime=MSEC        Override codec ptime to MSEC (default=specific)
  --no-vad            Disable VAD/silence detector (default=vad enabled)
  --ec-tail=MSEC      Set echo canceller tail length (default=256)
  --ec-opt=OPT        Select echo canceller algorithm (0=default, 
                        1=speex, 2=suppressor)
  --ilbc-mode=MODE    Set iLBC codec mode (20 or 30, default is 30)
  --capture-dev=id    Audio capture device ID (default=-1)
  --playback-dev=id   Audio playback device ID (default=-1)
  --capture-lat=N     Audio capture latency, in ms (default=100)
  --playback-lat=N    Audio playback latency, in ms (default=100)
  --snd-auto-close=N  Auto close audio device when it is idle for N seconds.
                      Specify N=-1 (default) to disable this feature.
                      Specify N=0 for instant close when unused.
  --no-tones          Disable audible tones
  --jb-max-size       Specify jitter buffer maximum size, in frames (default=-1)

Media Transport Options:
  --use-ice           Enable ICE (default:no)
  --ice-no-host       Disable ICE host candidates (default: no)
  --ice-no-rtcp       Disable RTCP component in ICE (default: no)
  --rtp-port=N        Base port to try for RTP (default=4000)
  --rx-drop-pct=PCT   Drop PCT percent of RX RTP (for pkt lost sim, default: 0)
  --tx-drop-pct=PCT   Drop PCT percent of TX RTP (for pkt lost sim, default: 0)
  --use-turn          Enable TURN relay with ICE (default:no)
  --turn-srv          Domain or host name of TURN server ("NAME:PORT" format)
  --turn-tcp          Use TCP connection to TURN server (default no)
  --turn-user         TURN username
  --turn-passwd       TURN password

Buddy List (can be more than one):
  --add-buddy url     Add the specified URL to the buddy list.

User Agent options:
  --auto-answer=code  Automatically answer incoming calls with code (e.g. 200)
  --max-calls=N       Maximum number of concurrent calls (default:4, max:255)
  --thread-cnt=N      Number of worker threads (default:1)
  --duration=SEC      Set maximum call duration (default:no limit)
  --norefersub        Suppress event subscription when transfering calls
  --use-compact-form  Minimize SIP message size
  --no-force-lr       Allow strict-route to be used (i.e. do not force lr)
  --accept-redirect=N Specify how to handle call redirect (3xx) response.
                      0: reject, 1: follow automatically (default), 2: ask

When URL is specified, pjsua will immediately initiate call to that URL

# 


起動時表示例

# ./pjsua-i686-pc-linux-gnu --id=sip:6002@192.168.1.166
 --registrar=sip:asrterisk@192.168.1.202 --realm=*
 --username=6002 --password=6002 --local-port=5061
 23:03:16.855 os_core_unix.c  pjlib 1.0.3 for POSIX initialized
 23:03:16.878 sip_endpoint.c  Creating endpoint instance...
 23:03:16.886          pjlib  select() I/O Queue created (0x9394128)
 23:03:16.886 sip_endpoint.c  Module "mod-msg-print" registered
 23:03:16.886 sip_transport.  Transport manager created.
 23:03:16.887 sip_endpoint.c  Module "mod-pjsua-log" registered
 23:03:16.887 sip_endpoint.c  Module "mod-tsx-layer" registered
 23:03:16.887 sip_endpoint.c  Module "mod-stateful-util" registered
 23:03:16.887 sip_endpoint.c  Module "mod-ua" registered
 23:03:16.889 sip_endpoint.c  Module "mod-100rel" registered
 23:03:16.889 sip_endpoint.c  Module "mod-pjsua" registered
 23:03:16.889 sip_endpoint.c  Module "mod-invite" registered
 23:03:16.992      pasound.c  PortAudio sound library initialized, status=0
 23:03:16.992      pasound.c  PortAudio host api count=1
 23:03:16.992      pasound.c  Sound device count=1
 23:03:16.993          pjlib  select() I/O Queue created (0x939af74)
 23:03:16.993 sip_endpoint.c  Module "mod-evsub" registered
 23:03:17.004 sip_endpoint.c  Module "mod-presence" registered
 23:03:17.007 sip_endpoint.c  Module "mod-refer" registered
 23:03:17.007 sip_endpoint.c  Module "mod-pjsua-pres" registered
 23:03:17.007 sip_endpoint.c  Module "mod-pjsua-im" registered
 23:03:17.007 sip_endpoint.c  Module "mod-pjsua-options" registered
 23:03:17.007   pjsua_core.c  1 SIP worker threads created
 23:03:17.007   pjsua_core.c  pjsua version 1.0.3 for i686-pc-linux-gnu initialized
 23:03:17.008 sip_endpoint.c  Module "mod-default-handler" registered
 23:03:17.009   pjsua_core.c  SIP UDP socket reachable at 192.168.1.166:5061
 23:03:17.009   udp0x93aac28  SIP UDP transport started, published address is 192.168.1.166:5061
 23:03:17.009    pjsua_acc.c  Account  added with id 0
 23:03:17.033    tcplis:5061  SIP TCP listener ready for incoming connections at 192.168.1.166:5061
 23:03:17.045    pjsua_acc.c  Account  added with id 1
 23:03:17.045    pjsua_acc.c  Account sip:6002@192.168.1.166 added with id 2
 23:03:17.046   pjsua_core.c  TX 452 bytes Request msg REGISTER/cseq=38445
 (tdta0x93ad688) to UDP 192.168.1.202:5060:
REGISTER sip:asrterisk@192.168.1.202 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.166:5061;rport;branch=z9hG4bKPjdb12e21e-3f20-4940-a0f4-12e60e025588
Max-Forwards: 70
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
To: 
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38445 REGISTER
User-Agent: PJSUA v1.0.3/i686-pc-linux-gnu
Contact: 
Expires: 300
Content-Length:  0


--end msg--
 23:03:17.046    pjsua_acc.c  Registration sent
 23:03:17.062  pjsua_media.c  RTP socket reachable at 192.168.1.166:4000
 23:03:17.074  pjsua_media.c  RTCP socket reachable at 192.168.1.166:4001
 23:03:17.075  pjsua_media.c  RTP socket reachable at 192.168.1.166:4002
 23:03:17.075  pjsua_media.c  RTCP socket reachable at 192.168.1.166:4003
 23:03:17.075  pjsua_media.c  RTP socket reachable at 192.168.1.166:4004
 23:03:17.075  pjsua_media.c  RTCP socket reachable at 192.168.1.166:4005
 23:03:17.075  pjsua_media.c  RTP socket reachable at 192.168.1.166:4006
 23:03:17.075  pjsua_media.c  RTCP socket reachable at 192.168.1.166:4007
>
Account list:
  [ 0] : does not register
       Online status: Online
  [ 1] : does not register
       Online status: Online
 *[ 2] sip:6002@192.168.1.166: 100/In Progress (expires=0)
       Online status: Online
Buddy list:
 -none-

+=============================================================================+
|       Call Commands:         |   Buddy, IM & Presence:  |     Account:      |
|                              |                          |                   |
|  m  Make new call            | +b  Add new buddy       .| +a  Add new accnt |
|  M  Make multiple calls      | -b  Delete buddy         | -a  Delete accnt. |
|  a  Answer call              |  i  Send IM              | !a  Modify accnt. |
|  h  Hangup call  (ha=all)    |  s  Subscribe presence   | rr  (Re-)register |
|  H  Hold call                |  u  Unsubscribe presence | ru  Unregister    |
|  v  re-inVite (release hold) |  t  ToGgle Online status |  >  Cycle next ac.|
|  U  send UPDATE              |  T  Set online status    |  <  Cycle prev ac.|
| ],[ Select next/prev call    +--------------------------+-------------------+
|  x  Xfer call                |      Media Commands:     |  Status & Config: |
|  X  Xfer with Replaces       |                          |                   |
|  #  Send RFC 2833 DTMF       | cl  List ports           |  d  Dump status   |
|  *  Send DTMF with INFO      | cc  Connect port         | dd  Dump detailed |
| dq  Dump curr. call quality  | cd  Disconnect port      | dc  Dump config   |
|                              |  V  Adjust audio Volume  |  f  Save config   |
|  S  Send arbitrary REQUEST   | Cp  Codec priorities     |  f  Save config   |
+------------------------------+--------------------------+-------------------+
|  q  QUIT       sleep MS     echo [0|1|txt]        n: detect NAT type        |
+=============================================================================+
You have 0 active call
>  23:03:17.171   pjsua_core.c  RX 496 bytes Response msg 407/REGISTER/cseq=38445
 (rdata0x93ab09c) from UDP 192.168.1.202:5060:
SIP/2.0 407 Proxy Authentication Required
Via: SIP/2.0/UDP 192.168.1.166:5061;rport=5061;branch=z9hG4bKPjdb12e21e-3f20-4940-a0f4-12e60e025588
Proxy-Authenticate: Digest nonce="12901989789:82b1cd4537531ae0776bb0d91f0f04ab",
algorithm=MD5,realm="3CXPhoneSystem"
To: ;tag=7416bb6d
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38445 REGISTER
User-Agent: 3CXPhoneSystem
Content-Length: 0


--end msg--
 23:03:17.171   pjsua_core.c  TX 670 bytes Request msg REGISTER/cseq=38446
 (tdta0x93ad688) to UDP 192.168.1.202:5060:
REGISTER sip:asrterisk@192.168.1.202 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.166:5061;rport;branch=z9hG4bKPj82f43fa9-a877-49ce-9f1f-2e136e648f19
Max-Forwards: 70
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
To: 
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38446 REGISTER
User-Agent: PJSUA v1.0.3/i686-pc-linux-gnu
Contact: 
Expires: 300
Proxy-Authorization: Digest username="6002",
 realm="3CXPhoneSystem", nonce="12901989789:82b1cd4537531ae0776bb0d91f0f04ab",
 uri="sip:asrterisk@192.168.1.202",
 response="d9d17757595114d9e026470de3f2517b",
 algorithm=MD5
Content-Length:  0


--end msg--
 23:03:17.672   pjsua_core.c  TX 670 bytes Request msg REGISTER/cseq=38446
 (tdta0x93ad688) to UDP 192.168.1.202:5060:
REGISTER sip:asrterisk@192.168.1.202 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.166:5061;rport;branch=z9hG4bKPj82f43fa9-a877-49ce-9f1f-2e136e648f19
Max-Forwards: 70
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
To: 
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38446 REGISTER
User-Agent: PJSUA v1.0.3/i686-pc-linux-gnu
Contact: 
Expires: 300
Proxy-Authorization: Digest username="6002", realm="3CXPhoneSystem",
 nonce="12901989789:82b1cd4537531ae0776bb0d91f0f04ab",
 uri="sip:asrterisk@192.168.1.202",
 response="d9d17757595114d9e026470de3f2517b", algorithm=MD5
Content-Length:  0


--end msg--
 23:03:17.677   pjsua_core.c  RX 403 bytes Response msg 200/REGISTER/cseq=38446
 (rdata0x93ab09c) from UDP 192.168.1.202:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.166:5061;rport=5061;branch=z9hG4bKPj82f43fa9-a877-49ce-9f1f-2e136e648f19
Contact: ;expires=300
To: ;tag=d7368f03
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38446 REGISTER
User-Agent: 3CXPhoneSystem
Content-Length: 0


--end msg--
 23:03:17.677    pjsua_acc.c  sip:6002@192.168.1.166:
 registration success, status=200 (OK), will re-register in 300 seconds
 23:03:17.677    pjsua_acc.c  Keep-alive timer started for acc 2,
 destination:192.168.1.202:5060, interval:15s
 23:03:17.678   pjsua_core.c  RX 403 bytes Response msg 200/REGISTER/cseq=38446
 (rdata0x93ab09c) from UDP 192.168.1.202:5060:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.166:5061;rport=5061;branch=z9hG4bKPj82f43fa9-a877-49ce-9f1f-2e136e648f19
Contact: ;expires=300
To: ;tag=d7368f03
From: ;tag=99a79b82-0fd7-4b99-93c2-b405a4459a75
Call-ID: 85ace62f-3243-4f1c-9062-2664d8aa7b68
CSeq: 38446 REGISTER
User-Agent: 3CXPhoneSystem
Content-Length: 0


--end msg--

2009.09.10