Project

General

Profile

SipDeveloperGuide » History » Version 155

Adrian Georgescu, 06/16/2011 02:52 PM

1 155 Adrian Georgescu
[[TOC(SipIntegrationGuide*, depth=3)]]
2 1 Adrian Georgescu
3 155 Adrian Georgescu
= SIP SIMPLE SDK Integration Guide =
4 147 Adrian Georgescu
5 155 Adrian Georgescu
SIP SIMPLE client SDK is a Software Development Kit with a Python API useful for development of real-time communications end-points based on SIP and related protocols with multimedia like Audio, Instant Messaging, File Transfers, Desktop Sharing and Presence. Other media types can be easily added by using an extensible high-level API. The library has cross platform capabilities on Linux OS, Mac OSX and Microsoft Windows. The library works with no or minimal changes on any platform that supports Python and provides direct access to the input and audio devices using one of the supported backends.
6 73 Adrian Georgescu
7 155 Adrian Georgescu
== Current Status ==
8 1 Adrian Georgescu
9 155 Adrian Georgescu
SIP SIMPLE client SDK is reliable for production use and is used today in finished products that are downloaded daily more than 300 times. The products work on Linux, Mac and Windows desktop OS and Linux Servers.
10 127 Adrian Georgescu
11 155 Adrian Georgescu
== Installation Instructions ==
12 1 Adrian Georgescu
13 155 Adrian Georgescu
SIP SIMPLE client SDK is ready packaged for latest Ubuntu Linux distributions (Lucid, Maverick and Natty), Debian Linux distributions (Stable and Unstable) and can be manually installed on MacOSX 10.5, 10.6 and Microsoft Windows XP, Vista and 7 by following the documentation provided with the source code. To install the SDK on Debian or Ubuntu, configure your deb repository as described [http://www.ag-projects.com/projects-products-96/683-software-repositories here], then:
14 1 Adrian Georgescu
15 155 Adrian Georgescu
{{{
16
sudo apt-get update
17
sudo apt-get install python-sipsimple
18
}}}
19 1 Adrian Georgescu
20 155 Adrian Georgescu
Complete building instructions from source for the SDK and its dependencies are available [http://sipsimpleclient.com/wiki/SipInstallation here] 
21 1 Adrian Georgescu
22 155 Adrian Georgescu
== API Documentation ==
23 1 Adrian Georgescu
24 155 Adrian Georgescu
 * Online documentation is available at http://sipsimpleclient.com/wiki/SipMiddlewareApi
25
 * Printable documentation in PDF format is available at http://download.ag-projects.com/SipClient/SIPSIMPLE-Manual.pdf
26 1 Adrian Georgescu
27 155 Adrian Georgescu
== Usage Instructions ==
28 1 Adrian Georgescu
29 155 Adrian Georgescu
Using SIP Simple SDK library is no different than using any other Python library, by installing it in the system manually from the source code with 'sudo python setup.py install' command or from a ready made package when available for the target OS then import its modules into the program and use it.
30 1 Adrian Georgescu
31 155 Adrian Georgescu
To setup a simple audio call and hangup one has to write as little as 10 lines of code. A complete wide-band conferencing application has been written in only 300 lines of code.
32 1 Adrian Georgescu
33 155 Adrian Georgescu
The complexity goes up as one may need to interact with the end-user for more actions like creating conferences interacting with telephony applications, adding chat or presence messages, this complexity is dictated by the GUI design, the library provides easy to understand high-level functions and the develeper does not need to understand SIP or other related protocols used inside the kit to achive it goal.
34 1 Adrian Georgescu
35 155 Adrian Georgescu
=== Deployment Scenarios ===
36 1 Adrian Georgescu
37 155 Adrian Georgescu
The SDK can be used to build real-time communications end-points that operates in the following scenarios:
38 1 Adrian Georgescu
39 155 Adrian Georgescu
 * On a LAN by using Bonjour discovery mechanism or on the public Internet by using the Server of a SIP Service provider, next hop lookup is based on DNS as described in RFC 3263
40
 * In a P2P overlay network like a DHT that provides routing and lookup service. For this, the SIP end-point must publish its Address of Records (AoR) address:port:protocol where it listens for incoming requests into the overlay and must implement a lookup function to obtain the peer end-points addresses from the overlay so that it can establish outbound sessions with them. For NAT traversal there must be a set of super-nodes that provide media relay functions based on ICE methodology 
41 1 Adrian Georgescu
42 155 Adrian Georgescu
== Sample Code ==
43
44
=== Hello World Program ===
45
46
This is the hello world example that establish a wideband audio call. After installing the SDK, paste this code into a console and run it using Python.
47
48
{{{
49
#/usr/bin/python
50
51
from application.notification import NotificationCenter
52
53
from sipsimple.account import AccountManager
54
from sipsimple.application import SIPApplication
55
from sipsimple.core import SIPURI, ToHeader
56
from sipsimple.lookup import DNSLookup, DNSLookupError
57
from sipsimple.storage import FileStorage
58
from sipsimple.session import Session
59
from sipsimple.streams import AudioStream
60
from sipsimple.threading.green import run_in_green_thread
61
62
from threading import Event
63
64
class SimpleCallApplication(SIPApplication):
65
66
    def __init__(self):
67
        SIPApplication.__init__(self)
68
        self.ended = Event()
69
        self.callee = None
70
        self.session = None
71
        notification_center = NotificationCenter()
72
        notification_center.add_observer(self)
73
74
    def call(self, callee):
75
        self.callee = callee
76
        self.start(FileStorage('config'))
77
78
    @run_in_green_thread
79
    def _NH_SIPApplicationDidStart(self, notification):
80
        self.callee = ToHeader(SIPURI.parse(self.callee))
81
        try:
82
            routes = DNSLookup().lookup_sip_proxy(self.callee.uri, ['udp']).wait()
83
        except DNSLookupError, e:
84
            print 'DNS lookup failed: %s' % str(e)
85
        else:
86
            account = AccountManager().default_account
87
            self.session = Session(account)
88
            self.session.connect(self.callee, routes, [AudioStream(account)])
89
90
    def _NH_SIPSessionGotRingIndication(self, notification):
91
        print 'Ringing!'
92
93
    def _NH_SIPSessionDidStart(self, notification):
94
        audio_stream = notification.data.streams[0]
95
        print 'Audio session established using "%s" codec at %sHz' % (audio_stream.codec, audio_stream.sample_rate)
96
97
    def _NH_SIPSessionDidFail(self, notification):
98
        print 'Failed to connect'
99
        self.stop()
100
101
    def _NH_SIPSessionDidEnd(self, notification):
102
        print 'Session ended'
103
        self.stop()
104
105
    def _NH_SIPApplicationDidEnd(self, notification):
106
        self.ended.set()
107
108
# place an audio call to the specified SIP URI in user@domain format
109
target_uri="sip:3333@sip2sip.info"
110
application = SimpleCallApplication()
111
application.call(target_uri)
112
print "Placing call to %s, press Enter to quit the program" % target_uri
113
raw_input()
114
application.session.end()
115
application.ended.wait()
116
}}}
117
118
=== Full Demo Programs ===
119
120
Full sample programs are available in 'sipclients' package available in the [http://www.ag-projects.com/projects-products-96/683-software-repositories same repository] as python-sipsimple. These programs operate in a Linux or MacOSX  terminal and implement most of the functions provided by the the SDK.
121
122
{{{
123
sudo apt-get install sipclients
124
}}}
125
126
 * sip-register - REGISTER a SIP end-point with a SIP Registrar or detect Bonjour neighbors
127
 * sip_audio_session - Setup a single SIP audio session using RTP/sRTP media
128
 * sip_session - Complete client supporting multiple sessions with Audio (RTP/sRTP), IM and File Transfer (MSRP)
129
 * sip_message - Send and receive short messages in paging mode using SIP MESSAGE method
130
 * sip_publish_presence- PUBLISH presence to a Presence Agent
131
 * sip_subscribe_winfo - SUBSCRIBE to the watcher list for given SIP address on the Presence Agent
132
 * sip_subscribe_presence - SUBSCRIBE to Presence Event for a given SIP address
133
 * sip_subscribe_rls - SUBSCRIBE for Presence Event to a list managed by a Resource List Server
134
 * sip_subscribe_xcap_diff - SUBSCRIBE for xcap-diff Event to monitor changes to XCAP documents
135
 * sip_subscribe_mwi - SUBSCRIBE for Message Waiting Indicator
136
137
For a description of the sample programs see http://sipsimpleclient.com/wiki/SipTesting
138
139
=== Finished Products ===
140
141
The SDK is used in several products since end of 2009. These are end-products that use the SDK and provide excellent examples for how the SDK was used to achieve the goals.
142
143
 1. Multiparty Conference Application with Wideband Audio, IM and File Transfer: http://sylkserver.com
144
 1. SIP client implementation for MacOS X available in the Mac App Store: http://itunes.apple.com/us/app/blink-pro/id404360415?mt=12&ls=1 
145
 1. SIP Client for Linux: Blink for Ubuntu, and Debian, use same repositories from AG Projects and do 'sudo apt-get install blink' 
146
 1. SIP client for MS Windows: https://blink.sipthor.net/download.phtml?download&os=nt
147
148
== Non-Python environments ==
149
150
As the programming choice was Python this SDK will appeal to people that want to develop applications in Python. If one want to use the library into another environment it must check if is feasible or not as embedding a programming language into another is not a string forward process if at all possible.
151
152
=== Cocoa Objective C ===
153
154
MacOS platform is using Objective C for native development. But it also provide a bridge between Python and Objective C. This makes it possible to write pure Python programs that run into the native OS without much changes.
155
156
http://pyobjc.sourceforge.net/
157
158
The SDK was fully used without any problems to build Blink for MacOSX by using this bridge.
159
160
=== Qt Framework ===
161
162
Qt Framework from Nokia (formerly Trolltech) is using C for native development. But it also has Python bindings. This makes it possible to write pure Python programs that integrate with Qt framework.
163
164
http://qt.nokia.com/
165
166
The SDK was fully used without any problems to build Blink for Windows and Linux by using Qt Framework and its Python bindings.
167
168
=== Web Browser Plugin ===
169
170
Today, web browsers do not give direct access to the input and output audio devices to their plugins, which is required  by a real-time audio application. Browsers do not support direct embedding of Python code either. If one looks for example at how Google Talk plugin in the browser works, it actually installs a regular server daemon into the system that performs similar functions to IP SIMPLE Client SDK and the web browser interacts with it by using a proprietary API running on the same host between the daemon and the browser plugin. The core software that does the media, signaling, integration with the audio device does not run in the browser itself, the browser is only used only as a GUI. 
171
172
There is a recent initiative to form a work group in both W3C and IETF to address this important issue of accessing and processing audio data within the browser itself as today this is not possible. This requires cooperation from the browser manufacturers, third-party developers cannot do this on their own without cooperation from the web browser makers (like Adobe has obtained for its Flash product).  This initiative is called RTCweb http://rtc-web.alvestrand.com. 
173
174
Google published a first specification and code drop just last month in May 2011 and IETF and W3Chad a few initial conference calls to setup the future agenda but no more at this stage. SIP SIMPLE Client SDK cannot run in the browser today as browsers won't support Python nor direct access to audio devices both required by the SDK to operate. However one could build a program that stay behind the browser in the same way by using SIP Simple client SDK.
175
176
=== C Language  ===
177
178
Embedding C code into Python program is easy and feasible we do this in our Python library as well for some low level parts where we speed was needed. The other way around is not, as passing complex data structure from a high level language like Python to a low level one like C is quite a problem.  How to possibly integrate Python into C is described here:
179
180
http://docs.python.org/extending/embedding.html
181
182
Is unlikely that the SDK can be used in such way because of data translation or multi-threading issues that could be impossible to solve, in any case nobody has ever tried.
183
184
=== Java Language  ===
185
186
There is a bridge between Python and Java.
187
188
http://www.jython.org/
189
190
It is unknown if is feasible to use the SDK under this environment, as nobody has reported trying it yet.
191
192
=== Translating into other languages  ===
193
194
There are currently 47,000 lines of code in SIP SIMPLE Client SDK.
195
196
The state machine for a multimedia real-time application is an order of magnitude more complex than protocols like BitTorent. 
197
198
 * SIP signaling has 10 states with 16 possible transitions between them, a diagram is [http://sipsimpleclient.com/raw-attachment/wiki/SipCoreApiDocumentation/sipsimple-core-invite-state-machine.png here]
199
 * The RTP media used for audio and video has 6 to 10 states depending on the type of media
200
 * ICE NAT traversal has many states interrelated with both signaling and the media plane
201
 * IM chat functionality has multiple states
202
 * Presence Subscribe/Notify mechanism has multiple states
203
204
There are multiple-threads and the design is non-blocking by using asynchronous reactor and a notification system.  SIP Simple SDK generates today 135 Notification on state changes, each of them carrying complex data structures. 
205
206
When all combined together the final application is quite complex and achieving the same in a low level programming language like C for example would be a major undertaking. Expressing this complexity into a low level language like C requires many years of work with a large team of well qualified people.