Sip audio session » History » Revision 21
Revision 20 (Adrian Georgescu, 08/19/2009 02:08 PM) → Revision 21/28 (Adrian Georgescu, 08/25/2009 04:39 PM)
== sip_audio_session == [[TOC(SipTesting*, sip_*, xcap*,depth=2)]] === Description === 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. [[Image(http://www.tech-invite.com/img/cf3665/cf3665-32.gif)]] Source code: [source:scripts/sip_audio_session.py scripts/sip_audio_session.py] {{{ adigeo@ag-blink:~$sip_audio_session adigeo@ag-imac3:~$sip_audio_session -h Usage: sip_audio_session [options] [user@domain] This script can sit idle waiting for an incoming audio session, or initiate an outgoing audio session to a SIP address. The program will close the session and quit when Ctrl+D is pressed. Options: -h, --help show this help message and exit -a NAME, --account=NAME The account name to use for any outgoing traffic. If not supplied, the default account will be used. -c FILE, --config-file=FILE The path to a configuration file to use. This overrides the default location of the configuration file. -s, --trace-sip Dump the raw contents of incoming and outgoing SIP messages. -j, --trace-pjsip Print PJSIP logging output. -n, --trace-notifications Print all notifications (disabled by default). -S, --disable-sound Disables initializing the sound card. --auto-answer Interval after which to answer an incoming session (disabled by default). If the option is specified but the interval is not, it defaults to 0 (accept the session as soon as it starts ringing). --auto-hangup Interval after which to hang up an established session (disabled by default). If the option is specified but the interval is not, it defaults to 0 (hangup the session as soon as it connects). -b, --batch Run the program in batch mode: reading input from the console is disabled and the option --auto-answer is implied. This is particularly useful when running this script in a non-interactive environment. -D, --daemonize Enable running this program as a deamon. This option implies --disable-sound, --auto-answer and --batch. }}} === Example for incoming session === {{{ adigeo@ag-blink:~$sip_audio_session adigeo@ag-imac3:~$sip_audio_session Using account 31208005169@ag-projects.com Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt" "/Users/adigeo/.sipclient/logs/sip_trace.txt" Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt" "/Users/adigeo/.sipclient/logs/pjsip_trace.txt" Available audio input devices: None, system_default, Built-in Input, Built-in Microphone Microphone, Logitech Wireless Headset Available audio output devices: None, system_default, Built-in Output Output, Logitech Wireless Headset Using audio input device: Built-in Microphone Using audio output device: Built-in Output Using audio alert device: Built-in Output Available control keys: s: toggle SIP trace on the console j: toggle PJSIP trace on the console n: toggle notifications trace on the console p: toggle printing RTP statistics on the console h: hang-up the active session r: toggle audio recording m: mute the microphone i: change audio input device o: change audio output device a: change audio alert device <>: adjust echo cancellation SPACE: hold/unhold Ctrl-d: quit the program ?: display this help message 2009-08-25 16:37:12 2009-07-23 13:40:02 Registered contact "sip:hxsyungk@192.168.1.124:59164" "sip:oedtbzgw@192.168.1.6:50361" for sip:31208005169@ag-projects.com at 81.23.228.150:5060;transport=udp 81.23.228.129:5060;transport=udp (expires in 600 seconds). Other registered contacts: sip:31208005169@192.168.1.123:5060 sip:froghdmq@192.168.1.6:50334 (expires in 274 547 seconds) sip:kwbfxyvl@192.168.1.124:59116 sip:31208005169@192.168.1.123:5060 (expires in 522 234 seconds) sip:ilmegvkp@192.168.1.124:59003 sip:zegoxqlw@192.168.1.6:50298 (expires in 339 468 seconds) sip:31208005169@192.168.1.1;uniq=5B2860C44383A3D6705629A7E1FB8 (expires in 1162 813 seconds) Detected NAT type: Port Restricted Incoming audio session from 'sip:adi@umts.ro', 'sip:31208005169@ag-projects.com', do you want to accept? (y/n) Audio session established using "speex" codec at 16000Hz 32000Hz Audio RTP endpoints 192.168.1.124:50378 80.101.96.20:50406 <-> 85.17.186.6:58868 81.23.228.150:52916 RTP audio stream is encrypted Remote SIP User Agent is "Blink-0.9.0" "sipsimple 0.9.1" Remote party has put the audio session on hold Audio session is put on hold Audio session ended by remote party Session Call duration was 6 4 seconds 2009-08-25 16:37:44 Registration ended. }}} === Example for outgoing session === {{{ adigeo@ag-blink:~$sip -a umts adigeo@ag-imac3:~$sip_audio_session ag@ag-projects.com Using account adi@umts.ro 31208005169@ag-projects.com Logging SIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/sip_trace.txt" "/Users/adigeo/.sipclient/logs/sip_trace.txt" Logging PJSIP trace to file "/Users/adigeo/Library/Application Support/Blink/logs/pjsip_trace.txt" "/Users/adigeo/.sipclient/logs/pjsip_trace.txt" Available audio input devices: None, system_default, Built-in Input, Built-in Microphone Microphone, Logitech Wireless Headset Available audio output devices: None, system_default, Built-in Output Output, Logitech Wireless Headset Using audio input device: Built-in Microphone Using audio output device: Built-in Output Using audio alert device: Built-in Output Available control keys: s: toggle SIP trace on the console j: toggle PJSIP trace on the console n: toggle notifications trace on the console p: toggle printing RTP statistics on the console h: hang-up the active session r: toggle audio recording m: mute the microphone i: change audio input device o: change audio output device a: change audio alert device <>: adjust echo cancellation SPACE: hold/unhold Ctrl-d: quit the program ?: display this help message Initiating SIP audio session from 'sip:adi@umts.ro' 'sip:31208005169@ag-projects.com' to 'sip:ag@ag-projects.com' via sip:85.17.186.7:5060;transport=udp... sip:81.23.228.150:5060;transport=udp... Audio session established using "speex" codec at 16000Hz 32000Hz Audio RTP endpoints 192.168.1.124:50054 80.101.96.20:50400 <-> 85.17.186.6:58866 81.23.228.150:53734 RTP audio stream is encrypted Ending audio session... Audio session ended by local party Call duration was 5 seconds }}} === Example for bonjour mode === In bonjour mode no server is put used. This mode is useful for serverless ad-hoc LAN operation. > The actual bonjour protocol that uses multicast DNS to broadcast the contact SIP URIs is not implemented. [[Image(http://www.tech-invite.com/img/cf3665/cf3665-31.gif)]] '''Called party''' {{{ adigeo@ag-imac3:~$sip_audio_session -a bonjour@local Using account bonjour@local Listening on hold "sip:wjnrczhi@192.168.1.6:57624;transport=tls" Remote party has put Listening on "sip:wjnrczhi@192.168.1.6:57623;transport=tcp" Listening on "sip:wjnrczhi@192.168.1.6:61994" Available control keys: h: hang-up the active session r: toggle audio recording t: toggle SIP trace on the console j: toggle PJSIP trace on the console <> : adjust echo cancellation SPACE: hold/on-hold Ctrl-d: quit the program ?: display this help message Incoming audio session from "sip:imdyzosg@192.168.1.6", do you want to accept? (y/n) Session established, using "speex" codec at 32000Hz Audio RTP endpoints 192.168.1.6:50276 <-> 192.168.1.6:50100 RTP audio stream is encrypted Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553" Session ended by remote party. Session duration was 5 seconds }}} '''Calling party''' {{{ adigeo@ag-imac3:~$sip_audio_session -a bonjour@local "sip:wjnrczhi@192.168.1.6:57624;transport=tls" Using account bonjour@local Listening on hold "sip:imdyzosg@192.168.1.6:57626;transport=tls" Detected NAT type: Port Restricted Listening on "sip:imdyzosg@192.168.1.6:57625;transport=tcp" Listening on "sip:imdyzosg@192.168.1.6:62008" 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 ... Available control keys: h: hang-up the active session r: toggle audio recording t: toggle SIP trace on the console j: toggle PJSIP trace on the console <> : adjust echo cancellation SPACE: hold/on-hold Ctrl-d: quit the program ?: display this help message Ringing... Session established, using "speex" codec at 32000Hz Audio RTP endpoints 192.168.1.6:50100 <-> 192.168.1.6:50276 RTP audio stream is encrypted Remote SIP User Agent is "sip2sip-0.9.0-pjsip-1.0.2-trunk-r2553" Ending audio session... Audio session Session ended by local party party. Session duration was 7 5 seconds }}} === Alarm system === 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: {{{ sip_audio_session --auto-hangup user@domain }}} 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. To receive calls and answer them automatically you can also use sip_audio_session script as follows: {{{ sip_audio_session --daemonize }}} 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.