Sip audio session

Version 20 (Adrian Georgescu, 08/19/2009 02:08 pm)

1 1 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 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.
7 6 Adrian Georgescu
8 10 Adrian Georgescu
[[Image(http://www.tech-invite.com/img/cf3665/cf3665-32.gif)]]
9 1 Adrian Georgescu
10 1 Adrian Georgescu
Source code: [source:scripts/sip_audio_session.py scripts/sip_audio_session.py]
11 1 Adrian Georgescu
12 1 Adrian Georgescu
{{{
13 19 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session -h
14 17 Adrian Georgescu
Usage: sip_audio_session [options] [user@domain]
15 1 Adrian Georgescu
16 17 Adrian Georgescu
This script can sit idle waiting for an incoming audio session, or initiate an
17 17 Adrian Georgescu
outgoing audio session to a SIP address. The program will close the session
18 17 Adrian Georgescu
and quit when Ctrl+D is pressed.
19 1 Adrian Georgescu
20 1 Adrian Georgescu
Options:
21 1 Adrian Georgescu
  -h, --help            show this help message and exit
22 5 Adrian Georgescu
  -a NAME, --account=NAME
23 5 Adrian Georgescu
                        The account name to use for any outgoing traffic. If
24 5 Adrian Georgescu
                        not supplied, the default account will be used.
25 19 Adrian Georgescu
  -c FILE, --config-file=FILE
26 1 Adrian Georgescu
                        The path to a configuration file to use. This
27 5 Adrian Georgescu
                        overrides the default location of the configuration
28 5 Adrian Georgescu
                        file.
29 17 Adrian Georgescu
  -s, --trace-sip       Dump the raw contents of incoming and outgoing SIP
30 17 Adrian Georgescu
                        messages.
31 17 Adrian Georgescu
  -j, --trace-pjsip     Print PJSIP logging output.
32 17 Adrian Georgescu
  -n, --trace-notifications
33 17 Adrian Georgescu
                        Print all notifications (disabled by default).
34 5 Adrian Georgescu
  -S, --disable-sound   Disables initializing the sound card.
35 17 Adrian Georgescu
  --auto-answer         Interval after which to answer an incoming session
36 1 Adrian Georgescu
                        (disabled by default). If the option is specified but
37 17 Adrian Georgescu
                        the interval is not, it defaults to 0 (accept the
38 1 Adrian Georgescu
                        session as soon as it starts ringing).
39 1 Adrian Georgescu
  --auto-hangup         Interval after which to hang up an established session
40 19 Adrian Georgescu
                        (disabled by default). If the option is specified but
41 19 Adrian Georgescu
                        the interval is not, it defaults to 0 (hangup the
42 19 Adrian Georgescu
                        session as soon as it connects).
43 19 Adrian Georgescu
  -b, --batch           Run the program in batch mode: reading input from the
44 19 Adrian Georgescu
                        console is disabled and the option --auto-answer is
45 19 Adrian Georgescu
                        implied. This is particularly useful when running this
46 19 Adrian Georgescu
                        script in a non-interactive environment.
47 19 Adrian Georgescu
  -D, --daemonize       Enable running this program as a deamon. This option
48 19 Adrian Georgescu
                        implies --disable-sound, --auto-answer and --batch.
49 20 Adrian Georgescu
50 1 Adrian Georgescu
}}}
51 1 Adrian Georgescu
52 1 Adrian Georgescu
53 1 Adrian Georgescu
=== Example for incoming session ===
54 1 Adrian Georgescu
55 1 Adrian Georgescu
{{{
56 19 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session 
57 1 Adrian Georgescu
Using account 31208005169@ag-projects.com
58 19 Adrian Georgescu
Logging SIP trace to file "/Users/adigeo/.sipclient/logs/sip_trace.txt"
59 19 Adrian Georgescu
Logging PJSIP trace to file "/Users/adigeo/.sipclient/logs/pjsip_trace.txt"
60 19 Adrian Georgescu
Available audio input devices: Built-in Input, Built-in Microphone, Logitech Wireless Headset
61 19 Adrian Georgescu
Available audio output devices: Built-in Output, Logitech Wireless Headset
62 19 Adrian Georgescu
Using audio input device: Built-in Microphone
63 19 Adrian Georgescu
Using audio output device: Built-in Output
64 19 Adrian Georgescu
Using audio alert device: Built-in Output
65 19 Adrian Georgescu
66 1 Adrian Georgescu
Available control keys:
67 19 Adrian Georgescu
  s: toggle SIP trace on the console
68 19 Adrian Georgescu
  j: toggle PJSIP trace on the console
69 19 Adrian Georgescu
  n: toggle notifications trace on the console
70 19 Adrian Georgescu
  p: toggle printing RTP statistics on the console
71 1 Adrian Georgescu
  h: hang-up the active session
72 1 Adrian Georgescu
  r: toggle audio recording
73 19 Adrian Georgescu
  <>: adjust echo cancellation
74 19 Adrian Georgescu
  SPACE: hold/unhold
75 1 Adrian Georgescu
  Ctrl-d: quit the program
76 1 Adrian Georgescu
  ?: display this help message
77 1 Adrian Georgescu
78 19 Adrian Georgescu
2009-07-23 13:40:02 Registered contact "sip:oedtbzgw@192.168.1.6:50361" for sip:31208005169@ag-projects.com at 81.23.228.129:5060;transport=udp (expires in 600 seconds).
79 19 Adrian Georgescu
Other registered contacts:
80 19 Adrian Georgescu
  sip:froghdmq@192.168.1.6:50334 (expires in 547 seconds)
81 19 Adrian Georgescu
  sip:31208005169@192.168.1.123:5060 (expires in 234 seconds)
82 19 Adrian Georgescu
  sip:zegoxqlw@192.168.1.6:50298 (expires in 468 seconds)
83 19 Adrian Georgescu
  sip:31208005169@192.168.1.1;uniq=5B2860C44383A3D6705629A7E1FB8 (expires in 813 seconds)
84 19 Adrian Georgescu
Detected NAT type: Port Restricted
85 19 Adrian Georgescu
Incoming audio session from 'sip:31208005169@ag-projects.com', do you want to accept? (y/n)
86 19 Adrian Georgescu
Audio session established using "speex" codec at 32000Hz
87 19 Adrian Georgescu
Audio RTP endpoints 80.101.96.20:50406 <-> 81.23.228.150:52916
88 19 Adrian Georgescu
RTP audio stream is encrypted
89 19 Adrian Georgescu
Remote SIP User Agent is "sipsimple 0.9.1"
90 19 Adrian Georgescu
Audio session ended by remote party
91 19 Adrian Georgescu
Call duration was 4 seconds
92 8 Adrian Georgescu
}}}
93 8 Adrian Georgescu
94 1 Adrian Georgescu
=== Example for outgoing session ===
95 1 Adrian Georgescu
96 1 Adrian Georgescu
{{{
97 1 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session ag@ag-projects.com
98 7 Adrian Georgescu
Using account 31208005169@ag-projects.com
99 19 Adrian Georgescu
Logging SIP trace to file "/Users/adigeo/.sipclient/logs/sip_trace.txt"
100 19 Adrian Georgescu
Logging PJSIP trace to file "/Users/adigeo/.sipclient/logs/pjsip_trace.txt"
101 19 Adrian Georgescu
Available audio input devices: Built-in Input, Built-in Microphone, Logitech Wireless Headset
102 19 Adrian Georgescu
Available audio output devices: Built-in Output, Logitech Wireless Headset
103 19 Adrian Georgescu
Using audio input device: Built-in Microphone
104 19 Adrian Georgescu
Using audio output device: Built-in Output
105 19 Adrian Georgescu
Using audio alert device: Built-in Output
106 19 Adrian Georgescu
107 7 Adrian Georgescu
Available control keys:
108 19 Adrian Georgescu
  s: toggle SIP trace on the console
109 19 Adrian Georgescu
  j: toggle PJSIP trace on the console
110 19 Adrian Georgescu
  n: toggle notifications trace on the console
111 19 Adrian Georgescu
  p: toggle printing RTP statistics on the console
112 1 Adrian Georgescu
  h: hang-up the active session
113 11 Adrian Georgescu
  r: toggle audio recording
114 19 Adrian Georgescu
  <>: adjust echo cancellation
115 19 Adrian Georgescu
  SPACE: hold/unhold
116 11 Adrian Georgescu
  Ctrl-d: quit the program
117 11 Adrian Georgescu
  ?: display this help message
118 19 Adrian Georgescu
119 19 Adrian Georgescu
Initiating SIP audio session from 'sip:31208005169@ag-projects.com' to 'sip:ag@ag-projects.com' via sip:81.23.228.150:5060;transport=udp...
120 19 Adrian Georgescu
Audio session established using "speex" codec at 32000Hz
121 19 Adrian Georgescu
Audio RTP endpoints 80.101.96.20:50400 <-> 81.23.228.150:53734
122 19 Adrian Georgescu
RTP audio stream is encrypted
123 19 Adrian Georgescu
Ending audio session...
124 19 Adrian Georgescu
Audio session ended by local party
125 19 Adrian Georgescu
Call duration was 5 seconds
126 12 Adrian Georgescu
}}}
127 11 Adrian Georgescu
128 12 Adrian Georgescu
129 12 Adrian Georgescu
=== Example for bonjour mode ===
130 12 Adrian Georgescu
131 11 Adrian Georgescu
In bonjour mode no server is used. This mode is useful for serverless ad-hoc LAN operation. 
132 11 Adrian Georgescu
133 11 Adrian Georgescu
> The actual bonjour protocol that uses multicast DNS to broadcast the contact SIP URIs is not implemented.
134 1 Adrian Georgescu
135 1 Adrian Georgescu
[[Image(http://www.tech-invite.com/img/cf3665/cf3665-31.gif)]]
136 11 Adrian Georgescu
137 11 Adrian Georgescu
'''Called party'''
138 11 Adrian Georgescu
139 11 Adrian Georgescu
{{{
140 12 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session -a bonjour@local
141 1 Adrian Georgescu
Using account bonjour@local
142 12 Adrian Georgescu
Listening on "sip:wjnrczhi@192.168.1.6:57624;transport=tls"
143 1 Adrian Georgescu
Listening on "sip:wjnrczhi@192.168.1.6:57623;transport=tcp"
144 1 Adrian Georgescu
Listening on "sip:wjnrczhi@192.168.1.6:61994"
145 12 Adrian Georgescu
Available control keys:
146 11 Adrian Georgescu
  h: hang-up the active session
147 11 Adrian Georgescu
  r: toggle audio recording
148 11 Adrian Georgescu
  t: toggle SIP trace on the console
149 12 Adrian Georgescu
  j: toggle PJSIP trace on the console
150 12 Adrian Georgescu
  <> : adjust echo cancellation
151 11 Adrian Georgescu
  SPACE: hold/on-hold
152 12 Adrian Georgescu
  Ctrl-d: quit the program
153 1 Adrian Georgescu
  ?: display this help message
154 12 Adrian Georgescu
Incoming audio session from "sip:imdyzosg@192.168.1.6", do you want to accept? (y/n)
155 12 Adrian Georgescu
Session established, using "speex" codec at 32000Hz
156 12 Adrian Georgescu
Audio RTP endpoints 192.168.1.6:50276 <-> 192.168.1.6:50100
157 12 Adrian Georgescu
RTP audio stream is encrypted
158 11 Adrian Georgescu
Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553"
159 11 Adrian Georgescu
Session ended by remote party.
160 11 Adrian Georgescu
Session duration was 5 seconds
161 11 Adrian Georgescu
}}}
162 11 Adrian Georgescu
163 11 Adrian Georgescu
'''Calling party'''
164 11 Adrian Georgescu
165 11 Adrian Georgescu
{{{
166 11 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session -a bonjour@local "sip:wjnrczhi@192.168.1.6:57624;transport=tls"
167 12 Adrian Georgescu
Using account bonjour@local
168 11 Adrian Georgescu
Listening on "sip:imdyzosg@192.168.1.6:57626;transport=tls"
169 12 Adrian Georgescu
Listening on "sip:imdyzosg@192.168.1.6:57625;transport=tcp"
170 11 Adrian Georgescu
Listening on "sip:imdyzosg@192.168.1.6:62008"
171 11 Adrian Georgescu
Initiating SIP session from sip:imdyzosg@192.168.1.6 to sip:wjnrczhi@192.168.1.6:57624;transport=tls via tls:192.168.1.6:57624 ...
172 12 Adrian Georgescu
Available control keys:
173 12 Adrian Georgescu
  h: hang-up the active session
174 1 Adrian Georgescu
  r: toggle audio recording
175 1 Adrian Georgescu
  t: toggle SIP trace on the console
176 14 Adrian Georgescu
  j: toggle PJSIP trace on the console
177 14 Adrian Georgescu
  <> : adjust echo cancellation
178 15 Adrian Georgescu
  SPACE: hold/on-hold
179 14 Adrian Georgescu
  Ctrl-d: quit the program
180 16 Adrian Georgescu
  ?: display this help message
181 14 Adrian Georgescu
Ringing...
182 14 Adrian Georgescu
Session established, using "speex" codec at 32000Hz
183 14 Adrian Georgescu
Audio RTP endpoints 192.168.1.6:50100 <-> 192.168.1.6:50276
184 14 Adrian Georgescu
RTP audio stream is encrypted
185 16 Adrian Georgescu
Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553"
186 18 Adrian Georgescu
Ending session...
187 18 Adrian Georgescu
Session ended by local party.
188 18 Adrian Georgescu
Session duration was 5 seconds
189 18 Adrian Georgescu
}}}
190 18 Adrian Georgescu
191 18 Adrian Georgescu
192 18 Adrian Georgescu
=== Alarm system ===
193 18 Adrian Georgescu
194 1 Adrian Georgescu
sip_audio_session script can be used for end-to-end testing of a SIP service. To setup the alarm system start periodically a caller script from a monitoring software using the following arguments:
195 1 Adrian Georgescu
  {{{
196 1 Adrian Georgescu
sip_audio_session --auto-hangup user@domain
197 1 Adrian Georgescu
  }}}
198 1 Adrian Georgescu
199 1 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. The failure can be caused by timeout, a negative response code or lack of RTP media after the SIP session has been established.
200 1 Adrian Georgescu
201 1 Adrian Georgescu
To receive calls and answer them automatically you can also use sip_audio_session script as follows:
202 1 Adrian Georgescu
203 1 Adrian Georgescu
  {{{
204 1 Adrian Georgescu
sip_audio_session --daemonize
205 1 Adrian Georgescu
  }}}
206 1 Adrian Georgescu
207 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.