Project

General

Profile

Sip audio session » History » Version 21

Adrian Georgescu, 08/25/2009 04:39 PM

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 21 Adrian Georgescu
adigeo@ag-blink:~$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
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 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
                        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 1 Adrian Georgescu
                        session as soon as it starts ringing).
39
  --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
                        the interval is not, it defaults to 0 (hangup the
42
                        session as soon as it connects).
43
  -b, --batch           Run the program in batch mode: reading input from the
44
                        console is disabled and the option --auto-answer is
45
                        implied. This is particularly useful when running this
46
                        script in a non-interactive environment.
47
  -D, --daemonize       Enable running this program as a deamon. This option
48 20 Adrian Georgescu
                        implies --disable-sound, --auto-answer and --batch.
49 1 Adrian Georgescu
}}}
50
51
52
=== Example for incoming session ===
53
54
{{{
55 21 Adrian Georgescu
adigeo@ag-blink:~$sip_audio_session 
56 1 Adrian Georgescu
Using account 31208005169@ag-projects.com
57 21 Adrian Georgescu
Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt"
58
Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt"
59
Available audio input devices: None, system_default, Built-in Input, Built-in Microphone
60
Available audio output devices: None, system_default, Built-in Output
61 19 Adrian Georgescu
Using audio input device: Built-in Microphone
62
Using audio output device: Built-in Output
63
Using audio alert device: Built-in Output
64
65 1 Adrian Georgescu
Available control keys:
66
  s: toggle SIP trace on the console
67
  j: toggle PJSIP trace on the console
68
  n: toggle notifications trace on the console
69
  p: toggle printing RTP statistics on the console
70 19 Adrian Georgescu
  h: hang-up the active session
71
  r: toggle audio recording
72 21 Adrian Georgescu
  m: mute the microphone
73
  i: change audio input device
74
  o: change audio output device
75
  a: change audio alert device
76 1 Adrian Georgescu
  <>: adjust echo cancellation
77
  SPACE: hold/unhold
78
  Ctrl-d: quit the program
79
  ?: display this help message
80
81 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).
82 1 Adrian Georgescu
Other registered contacts:
83 21 Adrian Georgescu
  sip:31208005169@192.168.1.123:5060 (expires in 274 seconds)
84
  sip:kwbfxyvl@192.168.1.124:59116 (expires in 522 seconds)
85
  sip:ilmegvkp@192.168.1.124:59003 (expires in 339 seconds)
86
  sip:31208005169@192.168.1.1;uniq=5B2860C44383A3D6705629A7E1FB8 (expires in 1162 seconds)
87 19 Adrian Georgescu
Detected NAT type: Port Restricted
88 21 Adrian Georgescu
Incoming audio session from 'sip:adi@umts.ro', do you want to accept? (y/n)
89
Audio session established using "speex" codec at 16000Hz
90
Audio RTP endpoints 192.168.1.124:50378 <-> 85.17.186.6:58868
91 19 Adrian Georgescu
RTP audio stream is encrypted
92 21 Adrian Georgescu
Remote SIP User Agent is "Blink-0.9.0"
93
Remote party has put the audio session on hold
94
Audio session is put on hold
95 8 Adrian Georgescu
Audio session ended by remote party
96 21 Adrian Georgescu
Session duration was 6 seconds
97
2009-08-25 16:37:44 Registration ended.
98 1 Adrian Georgescu
}}}
99
100
=== Example for outgoing session ===
101 11 Adrian Georgescu
102
{{{
103 21 Adrian Georgescu
adigeo@ag-blink:~$sip -a umts ag@ag-projects.com
104
Using account adi@umts.ro
105
Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt"
106
Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt"
107
Available audio input devices: None, system_default, Built-in Input, Built-in Microphone
108
Available audio output devices: None, system_default, Built-in Output
109 1 Adrian Georgescu
Using audio input device: Built-in Microphone
110 11 Adrian Georgescu
Using audio output device: Built-in Output
111 1 Adrian Georgescu
Using audio alert device: Built-in Output
112 11 Adrian Georgescu
113 12 Adrian Georgescu
Available control keys:
114 11 Adrian Georgescu
  s: toggle SIP trace on the console
115 12 Adrian Georgescu
  j: toggle PJSIP trace on the console
116 11 Adrian Georgescu
  n: toggle notifications trace on the console
117
  p: toggle printing RTP statistics on the console
118 12 Adrian Georgescu
  h: hang-up the active session
119
  r: toggle audio recording
120 21 Adrian Georgescu
  m: mute the microphone
121
  i: change audio input device
122
  o: change audio output device
123
  a: change audio alert device
124 15 Adrian Georgescu
  <>: adjust echo cancellation
125 14 Adrian Georgescu
  SPACE: hold/unhold
126 16 Adrian Georgescu
  Ctrl-d: quit the program
127 14 Adrian Georgescu
  ?: display this help message
128
129 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...
130
Audio session established using "speex" codec at 16000Hz
131
Audio RTP endpoints 192.168.1.124:50054 <-> 85.17.186.6:58866
132 18 Adrian Georgescu
RTP audio stream is encrypted
133 21 Adrian Georgescu
Audio session is put on hold
134
Remote party has put the audio session on hold
135
Detected NAT type: Port Restricted
136 18 Adrian Georgescu
Ending audio session...
137
Audio session ended by local party
138 21 Adrian Georgescu
Session duration was 7 seconds
139 18 Adrian Georgescu
}}}
140 1 Adrian Georgescu
141
=== Alarm system ===
142
143
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:
144 21 Adrian Georgescu
145 1 Adrian Georgescu
  {{{
146
sip_audio_session --auto-hangup user@domain
147
  }}}
148
149
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.
150
151
To receive calls and answer them automatically you can also use sip_audio_session script as follows:
152
153
  {{{
154
sip_audio_session --daemonize
155
  }}}
156
157
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.