Project

General

Profile

Sip audio session » History » Version 18

Adrian Georgescu, 04/16/2009 09:38 AM

1 1 Adrian Georgescu
== sip_audio_session ==
2 2 Adrian Georgescu
[[TOC(SipTesting*, sip_*, xcap*,depth=2)]]
3 1 Adrian Georgescu
4
=== Description ===
5
6
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
Source code: [source:scripts/sip_audio_session.py scripts/sip_audio_session.py]
11
12
{{{
13 5 Adrian Georgescu
adigeo@ag-oxygen:~$sip_audio_session --help
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
outgoing audio session to a SIP address. The program will close the session
18
and quit when Ctrl+D is pressed.
19 1 Adrian Georgescu
20
Options:
21
  -h, --help            show this help message and exit
22 5 Adrian Georgescu
  -a NAME, --account=NAME
23
                        The account name to use for any outgoing traffic. If
24
                        not supplied, the default account will be used.
25 17 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
                        file.
29 17 Adrian Georgescu
  -s, --trace-sip       Dump the raw contents of incoming and outgoing SIP
30
                        messages.
31
  -j, --trace-pjsip     Print PJSIP logging output.
32
  -n, --trace-notifications
33
                        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
                        session as soon as it starts ringing).
39
  --auto-hangup         Interval after which to hang up an established session
40
                        (applies only to outgoing sessions, disabled by
41
                        default). If the option is specified but the interval
42
                        is not, it defaults to 0 (hangup the session as soon
43
                        as it connects).
44
  -D, --daemonize       Enabled running this program as a deamon. Note that
45
                        this forces --disable-sound and --auto-answer.
46
47 1 Adrian Georgescu
}}}
48
49
50
=== Example for incoming session ===
51
52
{{{
53 7 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session
54
Using account 31208005169@ag-projects.com
55 1 Adrian Georgescu
Available control keys:
56
  h: hang-up the active session
57
  r: toggle audio recording
58
  t: toggle SIP trace on the console
59 7 Adrian Georgescu
  j: toggle PJSIP trace on the console
60 1 Adrian Georgescu
  <> : adjust echo cancellation
61
  SPACE: hold/on-hold
62
  Ctrl-d: quit the program
63
  ?: display this help message
64 7 Adrian Georgescu
Succesfully registered using contact "sip:cwntuzyl@192.168.1.6:61163"
65 1 Adrian Georgescu
Detected NAT type: Port Restricted
66 7 Adrian Georgescu
Incoming audio session from ""Adrian G." <sip:31208005169@ag-projects.com>", do you want to accept? (y/n)
67
Session established, using "PCMU" codec at 8000Hz
68
Audio RTP endpoints 192.168.1.6:50132 <-> 85.17.186.7:53358
69
Remote SIP User Agent is "CSCO/7"
70
Session ended by remote party.
71
Session duration was 3 seconds
72
73 1 Adrian Georgescu
}}}
74
75
=== Example for outgoing session ===
76
77
{{{
78 7 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session ag@ag-projects.com
79
Using account 31208005169@ag-projects.com
80 8 Adrian Georgescu
Initiating SIP session from "Adrian G." <sip:31208005169@ag-projects.com> to 
81
sip:ag@ag-projects.com via udp:81.23.228.150:5060 ...
82 1 Adrian Georgescu
Available control keys:
83
  h: hang-up the active session
84
  r: toggle audio recording
85
  t: toggle SIP trace on the console
86 7 Adrian Georgescu
  j: toggle PJSIP trace on the console
87 1 Adrian Georgescu
  <> : adjust echo cancellation
88
  SPACE: hold/on-hold
89
  Ctrl-d: quit the program
90
  ?: display this help message
91 7 Adrian Georgescu
Succesfully registered using contact "sip:ztomvpis@192.168.1.6:61215"
92 1 Adrian Georgescu
Ringing...
93
Session established, using "speex" codec at 32000Hz
94 7 Adrian Georgescu
Audio RTP endpoints 192.168.1.6:50374 <-> 81.23.228.129:52156
95
Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553"
96
Detected NAT type: Port Restricted
97
Ending session...
98
Session ended by local party.
99
Session duration was 12 seconds
100 1 Adrian Georgescu
}}}
101 11 Adrian Georgescu
102
103
=== Example for bonjour mode ===
104
105
In bonjour mode no server is used. This mode is useful for serverless ad-hoc LAN operation. 
106
107
> The actual bonjour protocol that uses multicast DNS to broadcast the contact SIP URIs is not implemented.
108
109
[[Image(http://www.tech-invite.com/img/cf3665/cf3665-31.gif)]]
110
111 12 Adrian Georgescu
'''Called party'''
112
113 1 Adrian Georgescu
{{{
114 12 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session -a bonjour@local
115 11 Adrian Georgescu
Using account bonjour@local
116 12 Adrian Georgescu
Listening on "sip:wjnrczhi@192.168.1.6:57624;transport=tls"
117
Listening on "sip:wjnrczhi@192.168.1.6:57623;transport=tcp"
118
Listening on "sip:wjnrczhi@192.168.1.6:61994"
119 11 Adrian Georgescu
Available control keys:
120
  h: hang-up the active session
121
  r: toggle audio recording
122 1 Adrian Georgescu
  t: toggle SIP trace on the console
123
  j: toggle PJSIP trace on the console
124 11 Adrian Georgescu
  <> : adjust echo cancellation
125
  SPACE: hold/on-hold
126
  Ctrl-d: quit the program
127
  ?: display this help message
128 12 Adrian Georgescu
Incoming audio session from "sip:imdyzosg@192.168.1.6", do you want to accept? (y/n)
129 1 Adrian Georgescu
Session established, using "speex" codec at 32000Hz
130 12 Adrian Georgescu
Audio RTP endpoints 192.168.1.6:50276 <-> 192.168.1.6:50100
131 1 Adrian Georgescu
RTP audio stream is encrypted
132
Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553"
133 12 Adrian Georgescu
Session ended by remote party.
134 11 Adrian Georgescu
Session duration was 5 seconds
135
}}}
136
137 12 Adrian Georgescu
'''Calling party'''
138
139 11 Adrian Georgescu
{{{
140 12 Adrian Georgescu
adigeo@ag-imac3:~$sip_audio_session -a bonjour@local "sip:wjnrczhi@192.168.1.6:57624;transport=tls"
141 1 Adrian Georgescu
Using account bonjour@local
142 12 Adrian Georgescu
Listening on "sip:imdyzosg@192.168.1.6:57626;transport=tls"
143
Listening on "sip:imdyzosg@192.168.1.6:57625;transport=tcp"
144
Listening on "sip:imdyzosg@192.168.1.6:62008"
145
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 ...
146 11 Adrian Georgescu
Available control keys:
147
  h: hang-up the active session
148
  r: toggle audio recording
149
  t: toggle SIP trace on the console
150
  j: toggle PJSIP trace on the console
151
  <> : adjust echo cancellation
152
  SPACE: hold/on-hold
153
  Ctrl-d: quit the program
154
  ?: display this help message
155 12 Adrian Georgescu
Ringing...
156 11 Adrian Georgescu
Session established, using "speex" codec at 32000Hz
157 12 Adrian Georgescu
Audio RTP endpoints 192.168.1.6:50100 <-> 192.168.1.6:50276
158 11 Adrian Georgescu
RTP audio stream is encrypted
159
Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553"
160 12 Adrian Georgescu
Ending session...
161
Session ended by local party.
162 1 Adrian Georgescu
Session duration was 5 seconds
163
}}}
164 14 Adrian Georgescu
165
166 15 Adrian Georgescu
=== Alarm system ===
167 14 Adrian Georgescu
168 16 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:
169 14 Adrian Georgescu
  {{{
170
sip_audio_session --auto-hangup user@domain
171
  }}}
172
173 16 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.
174 18 Adrian Georgescu
175
To receive calls and answer them automatically you can also use sip_audio_session script as follows:
176
177
  {{{
178
sip_audio_session --daemonize
179
  }}}
180
181
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.