Sip audio session

Version 26 (Adrian Georgescu, 03/10/2010 09:42 am)

1 24 Adrian Georgescu
== sip-audio-session ==
2 2 Adrian Georgescu
[[TOC(SipTesting*, sip_*, xcap*,depth=2)]]
3 1 Adrian Georgescu
4 1 Adrian Georgescu
=== Description ===
5 1 Adrian Georgescu
6 25 Adrian Georgescu
7 1 Adrian Georgescu
This script can be used for interactive audio session or for scripting alarms. The script returns appropriate shell response codes for failed or successful sessions. The script can be setup to auto answer and auto hangup after predefined number of seconds, detects SIP negative response codes, missing ACK and the lack of RTP media after a session has been established.
8 1 Adrian Georgescu
9 25 Adrian Georgescu
> This script is available in ''sipclients'' package that must be installed separately from SIP SIMPLe client SDK package.
10 1 Adrian Georgescu
11 1 Adrian Georgescu
{{{
12 24 Adrian Georgescu
adigeo@ag-blink:~$sip-audio-session -h
13 24 Adrian Georgescu
Usage: sip-audio-session [options] [user@domain]
14 1 Adrian Georgescu
15 17 Adrian Georgescu
This script can sit idle waiting for an incoming audio session, or initiate an
16 17 Adrian Georgescu
outgoing audio session to a SIP address. The program will close the session
17 17 Adrian Georgescu
and quit when Ctrl+D is pressed.
18 1 Adrian Georgescu
19 1 Adrian Georgescu
Options:
20 1 Adrian Georgescu
  -h, --help            show this help message and exit
21 5 Adrian Georgescu
  -a NAME, --account=NAME
22 5 Adrian Georgescu
                        The account name to use for any outgoing traffic. If
23 5 Adrian Georgescu
                        not supplied, the default account will be used.
24 19 Adrian Georgescu
  -c FILE, --config-file=FILE
25 1 Adrian Georgescu
                        The path to a configuration file to use. This
26 5 Adrian Georgescu
                        overrides the default location of the configuration
27 5 Adrian Georgescu
                        file.
28 17 Adrian Georgescu
  -s, --trace-sip       Dump the raw contents of incoming and outgoing SIP
29 17 Adrian Georgescu
                        messages.
30 17 Adrian Georgescu
  -j, --trace-pjsip     Print PJSIP logging output.
31 17 Adrian Georgescu
  -n, --trace-notifications
32 17 Adrian Georgescu
                        Print all notifications (disabled by default).
33 5 Adrian Georgescu
  -S, --disable-sound   Disables initializing the sound card.
34 17 Adrian Georgescu
  --auto-answer         Interval after which to answer an incoming session
35 1 Adrian Georgescu
                        (disabled by default). If the option is specified but
36 17 Adrian Georgescu
                        the interval is not, it defaults to 0 (accept the
37 1 Adrian Georgescu
                        session as soon as it starts ringing).
38 1 Adrian Georgescu
  --auto-hangup         Interval after which to hang up an established session
39 19 Adrian Georgescu
                        (disabled by default). If the option is specified but
40 19 Adrian Georgescu
                        the interval is not, it defaults to 0 (hangup the
41 19 Adrian Georgescu
                        session as soon as it connects).
42 19 Adrian Georgescu
  -b, --batch           Run the program in batch mode: reading input from the
43 19 Adrian Georgescu
                        console is disabled and the option --auto-answer is
44 19 Adrian Georgescu
                        implied. This is particularly useful when running this
45 19 Adrian Georgescu
                        script in a non-interactive environment.
46 19 Adrian Georgescu
  -D, --daemonize       Enable running this program as a deamon. This option
47 20 Adrian Georgescu
                        implies --disable-sound, --auto-answer and --batch.
48 1 Adrian Georgescu
}}}
49 1 Adrian Georgescu
50 1 Adrian Georgescu
51 1 Adrian Georgescu
=== Example for incoming session ===
52 1 Adrian Georgescu
53 1 Adrian Georgescu
{{{
54 24 Adrian Georgescu
adigeo@ag-blink:~$sip-audio-session 
55 1 Adrian Georgescu
Using account 31208005169@ag-projects.com
56 21 Adrian Georgescu
Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt"
57 21 Adrian Georgescu
Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt"
58 21 Adrian Georgescu
Available audio input devices: None, system_default, Built-in Input, Built-in Microphone
59 21 Adrian Georgescu
Available audio output devices: None, system_default, Built-in Output
60 19 Adrian Georgescu
Using audio input device: Built-in Microphone
61 19 Adrian Georgescu
Using audio output device: Built-in Output
62 19 Adrian Georgescu
Using audio alert device: Built-in Output
63 19 Adrian Georgescu
64 1 Adrian Georgescu
Available control keys:
65 1 Adrian Georgescu
  s: toggle SIP trace on the console
66 1 Adrian Georgescu
  j: toggle PJSIP trace on the console
67 1 Adrian Georgescu
  n: toggle notifications trace on the console
68 1 Adrian Georgescu
  p: toggle printing RTP statistics on the console
69 19 Adrian Georgescu
  h: hang-up the active session
70 19 Adrian Georgescu
  r: toggle audio recording
71 21 Adrian Georgescu
  m: mute the microphone
72 21 Adrian Georgescu
  i: change audio input device
73 21 Adrian Georgescu
  o: change audio output device
74 21 Adrian Georgescu
  a: change audio alert device
75 1 Adrian Georgescu
  <>: adjust echo cancellation
76 1 Adrian Georgescu
  SPACE: hold/unhold
77 1 Adrian Georgescu
  Ctrl-d: quit the program
78 1 Adrian Georgescu
  ?: display this help message
79 1 Adrian Georgescu
80 21 Adrian Georgescu
2009-08-25 16:37:12 Registered contact "sip:hxsyungk@192.168.1.124:59164" for sip:31208005169@ag-projects.com at 81.23.228.150:5060;transport=udp (expires in 600 seconds).
81 1 Adrian Georgescu
Other registered contacts:
82 21 Adrian Georgescu
  sip:31208005169@192.168.1.123:5060 (expires in 274 seconds)
83 21 Adrian Georgescu
  sip:kwbfxyvl@192.168.1.124:59116 (expires in 522 seconds)
84 21 Adrian Georgescu
  sip:ilmegvkp@192.168.1.124:59003 (expires in 339 seconds)
85 21 Adrian Georgescu
  sip:31208005169@192.168.1.1;uniq=5B2860C44383A3D6705629A7E1FB8 (expires in 1162 seconds)
86 19 Adrian Georgescu
Detected NAT type: Port Restricted
87 21 Adrian Georgescu
Incoming audio session from 'sip:adi@umts.ro', do you want to accept? (y/n)
88 21 Adrian Georgescu
Audio session established using "speex" codec at 16000Hz
89 21 Adrian Georgescu
Audio RTP endpoints 192.168.1.124:50378 <-> 85.17.186.6:58868
90 19 Adrian Georgescu
RTP audio stream is encrypted
91 21 Adrian Georgescu
Remote SIP User Agent is "Blink-0.9.0"
92 21 Adrian Georgescu
Remote party has put the audio session on hold
93 21 Adrian Georgescu
Audio session is put on hold
94 8 Adrian Georgescu
Audio session ended by remote party
95 21 Adrian Georgescu
Session duration was 6 seconds
96 21 Adrian Georgescu
2009-08-25 16:37:44 Registration ended.
97 1 Adrian Georgescu
}}}
98 1 Adrian Georgescu
99 1 Adrian Georgescu
=== Example for outgoing session ===
100 11 Adrian Georgescu
101 11 Adrian Georgescu
{{{
102 24 Adrian Georgescu
adigeo@ag-blink:~$sip-audio-session -a umts ag@ag-projects.com
103 21 Adrian Georgescu
Using account adi@umts.ro
104 21 Adrian Georgescu
Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt"
105 21 Adrian Georgescu
Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt"
106 21 Adrian Georgescu
Available audio input devices: None, system_default, Built-in Input, Built-in Microphone
107 21 Adrian Georgescu
Available audio output devices: None, system_default, Built-in Output
108 1 Adrian Georgescu
Using audio input device: Built-in Microphone
109 11 Adrian Georgescu
Using audio output device: Built-in Output
110 1 Adrian Georgescu
Using audio alert device: Built-in Output
111 11 Adrian Georgescu
112 12 Adrian Georgescu
Available control keys:
113 11 Adrian Georgescu
  s: toggle SIP trace on the console
114 12 Adrian Georgescu
  j: toggle PJSIP trace on the console
115 11 Adrian Georgescu
  n: toggle notifications trace on the console
116 11 Adrian Georgescu
  p: toggle printing RTP statistics on the console
117 12 Adrian Georgescu
  h: hang-up the active session
118 12 Adrian Georgescu
  r: toggle audio recording
119 21 Adrian Georgescu
  m: mute the microphone
120 21 Adrian Georgescu
  i: change audio input device
121 21 Adrian Georgescu
  o: change audio output device
122 21 Adrian Georgescu
  a: change audio alert device
123 15 Adrian Georgescu
  <>: adjust echo cancellation
124 14 Adrian Georgescu
  SPACE: hold/unhold
125 16 Adrian Georgescu
  Ctrl-d: quit the program
126 14 Adrian Georgescu
  ?: display this help message
127 14 Adrian Georgescu
128 21 Adrian Georgescu
Initiating SIP audio session from 'sip:adi@umts.ro' to 'sip:ag@ag-projects.com' via sip:85.17.186.7:5060;transport=udp...
129 21 Adrian Georgescu
Audio session established using "speex" codec at 16000Hz
130 26 Adrian Georgescu
ICE negotiation succeeded in 1s:412
131 26 Adrian Georgescu
Audio RTP endpoints 192.168.1.124:50852 (ICE type host) <-> 192.168.1.124:50871 (ICE type host)
132 18 Adrian Georgescu
RTP audio stream is encrypted
133 21 Adrian Georgescu
Audio session is put on hold
134 21 Adrian Georgescu
Remote party has put the audio session on hold
135 21 Adrian Georgescu
Detected NAT type: Port Restricted
136 18 Adrian Georgescu
Ending audio session...
137 23 Adrian Georgescu
Audio session ended by local party
138 23 Adrian Georgescu
Session duration was 7 seconds
139 23 Adrian Georgescu
}}}
140 1 Adrian Georgescu
141 1 Adrian Georgescu
=== Alarm system ===
142 1 Adrian Georgescu
143 25 Adrian Georgescu
sip-audio-session script can be used for end-to-end testing of a SIP service including the RTP media path. The following failures can be detected:
144 1 Adrian Georgescu
145 22 Adrian Georgescu
 * Timeout
146 22 Adrian Georgescu
 * Negative response code
147 22 Adrian Georgescu
 * Lack of RTP media after the SIP session has been established
148 22 Adrian Georgescu
 * Missing ACK
149 22 Adrian Georgescu
150 22 Adrian Georgescu
151 22 Adrian Georgescu
To setup the alarm system start periodically a caller script from a monitoring software using the following arguments:
152 22 Adrian Georgescu
153 1 Adrian Georgescu
  {{{
154 24 Adrian Georgescu
sip-audio-session --auto-hangup user@domain
155 1 Adrian Georgescu
  }}}
156 1 Adrian Georgescu
157 22 Adrian Georgescu
Where the user@domain has been configured as the SIP account of the listener, can be an answering machine on the PSTN network. The caller script hangs up after each call. The shell return code can be used to determine if the session setup has failed.
158 1 Adrian Georgescu
159 1 Adrian Georgescu
To receive calls and answer them automatically you can also use sip_audio_session script as follows:
160 1 Adrian Georgescu
161 1 Adrian Georgescu
  {{{
162 24 Adrian Georgescu
sip-audio-session --daemonize
163 1 Adrian Georgescu
  }}}
164 1 Adrian Georgescu
165 1 Adrian Georgescu
You must run the script as user root. The --daemonize option puts the client in the background and the logging goes to /var/log/syslog. The program saves its pid file to /var/run/sip_audio_session.pid.