Project

General

Profile

SipDeveloperGuide » History » Version 171

Adrian Georgescu, 06/20/2011 11:04 AM

1 156 Adrian Georgescu
[[TOC(SipDeveloperGuide*, depth=3)]]
2 1 Adrian Georgescu
3 155 Adrian Georgescu
= SIP SIMPLE SDK Integration Guide =
4 147 Adrian Georgescu
5 163 Adrian Georgescu
SIP SIMPLE client SDK is a Software Development Kit with a Python API designed for development of real-time communications end-points based on SIP and related protocols for multimedia like Audio, Instant Messaging, File Transfers, Desktop Sharing and Presence. Other media types can be added by using an extensible high-level API. The library has cross platform capabilities on Mac OSX, Microsoft Windows and Linux OS. 
6 73 Adrian Georgescu
7 155 Adrian Georgescu
== Current Status ==
8 1 Adrian Georgescu
9 162 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 OS, Windows desktop OS and Linux Servers.
10 127 Adrian Georgescu
11 155 Adrian Georgescu
== Installation Instructions ==
12 1 Adrian Georgescu
13 162 Adrian Georgescu
SIP SIMPLE client SDK is available as debian package for the 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.
14 1 Adrian Georgescu
15 162 Adrian Georgescu
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:
16
17 155 Adrian Georgescu
{{{
18 1 Adrian Georgescu
sudo apt-get update
19 155 Adrian Georgescu
sudo apt-get install python-sipsimple
20
}}}
21 1 Adrian Georgescu
22 162 Adrian Georgescu
Detailed building instructions from source for the SDK and its dependencies are available [http://sipsimpleclient.com/wiki/SipInstallation here] 
23 1 Adrian Georgescu
24 155 Adrian Georgescu
== API Documentation ==
25
26 1 Adrian Georgescu
 * Online documentation is available at http://sipsimpleclient.com/wiki/SipMiddlewareApi
27
 * Printable documentation in PDF format is available at http://download.ag-projects.com/SipClient/SIPSIMPLE-Manual.pdf
28
29 155 Adrian Georgescu
== Usage Instructions ==
30 1 Adrian Georgescu
31 163 Adrian Georgescu
The SDK works on any platform that supports Python and provides direct access to the input and audio devices using one of the supported backends.
32
33 171 Adrian Georgescu
Using SIP SIMPLE client SDK library is no different than using any other Python library, after installing it in the system, one must import its modules into the program and use it. There is a [http://sipsimpleclient.com/wiki/SipMiddlewareApi#SIPApplication high level API] that automates and integrates most of the tedious tasks like starting and stopping  all required sub-systems in the right order and performing most common applications like setting up an audio or a chat session so a developer can use the SDK by writing just a few lines of code without having to understand all the details or the used protocols.
34 1 Adrian Georgescu
35 169 Adrian Georgescu
To setup a simple audio call, print the connection state and hangup one has to write as little as 10 lines of code.
36
37
A complete audio+chat conferencing application has been written in 300 lines of code. On the other side of the scale developing a complete end-point like Skype is the most complex example of what the SDK may be used for. The complexity grows as one needs to interact with the end-user for more actions like creating conferences, interacting with telephony like applications, adding chat or handle presence updates. The complexity is dictated mainly by the external UI 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 achieve his goal.
38 1 Adrian Georgescu
39
=== Deployment Scenarios ===
40
41 155 Adrian Georgescu
The SDK can be used to build real-time communications end-points that operates in the following scenarios:
42 1 Adrian Georgescu
43 167 Adrian Georgescu
 * On a LAN using Bonjour discovery mechanism for address resolution
44
 * On the public Internet with any SIP Service provider using standard DNS for address resolution
45
 * Part of a P2P overlay network like a DHT that provides routing and lookup service. For this, the SIP end-point built with the SDK 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.
46 1 Adrian Georgescu
47 155 Adrian Georgescu
== Sample Code ==
48
49
=== Hello World Program ===
50
51 164 Adrian Georgescu
This is the hello world example that establishes a wideband audio session with a test number that plays a music tune. After installing the SDK, paste this code into a console and run it using Python.
52 155 Adrian Georgescu
53
{{{
54
#/usr/bin/python
55
56
from application.notification import NotificationCenter
57
58
from sipsimple.account import AccountManager
59
from sipsimple.application import SIPApplication
60
from sipsimple.core import SIPURI, ToHeader
61
from sipsimple.lookup import DNSLookup, DNSLookupError
62
from sipsimple.storage import FileStorage
63
from sipsimple.session import Session
64
from sipsimple.streams import AudioStream
65
from sipsimple.threading.green import run_in_green_thread
66
67
from threading import Event
68
69
class SimpleCallApplication(SIPApplication):
70
71
    def __init__(self):
72
        SIPApplication.__init__(self)
73
        self.ended = Event()
74
        self.callee = None
75
        self.session = None
76
        notification_center = NotificationCenter()
77
        notification_center.add_observer(self)
78
79
    def call(self, callee):
80
        self.callee = callee
81
        self.start(FileStorage('config'))
82
83
    @run_in_green_thread
84
    def _NH_SIPApplicationDidStart(self, notification):
85
        self.callee = ToHeader(SIPURI.parse(self.callee))
86
        try:
87
            routes = DNSLookup().lookup_sip_proxy(self.callee.uri, ['udp']).wait()
88
        except DNSLookupError, e:
89
            print 'DNS lookup failed: %s' % str(e)
90
        else:
91
            account = AccountManager().default_account
92
            self.session = Session(account)
93
            self.session.connect(self.callee, routes, [AudioStream(account)])
94
95
    def _NH_SIPSessionGotRingIndication(self, notification):
96
        print 'Ringing!'
97
98
    def _NH_SIPSessionDidStart(self, notification):
99
        audio_stream = notification.data.streams[0]
100
        print 'Audio session established using "%s" codec at %sHz' % (audio_stream.codec, audio_stream.sample_rate)
101
102
    def _NH_SIPSessionDidFail(self, notification):
103
        print 'Failed to connect'
104
        self.stop()
105
106
    def _NH_SIPSessionDidEnd(self, notification):
107
        print 'Session ended'
108
        self.stop()
109
110
    def _NH_SIPApplicationDidEnd(self, notification):
111
        self.ended.set()
112
113
# place an audio call to the specified SIP URI in user@domain format
114
target_uri="sip:3333@sip2sip.info"
115
application = SimpleCallApplication()
116 1 Adrian Georgescu
application.call(target_uri)
117 155 Adrian Georgescu
print "Placing call to %s, press Enter to quit the program" % target_uri
118
raw_input()
119 1 Adrian Georgescu
application.session.end()
120
application.ended.wait()
121
}}}
122
123
=== Full Demo Programs ===
124 155 Adrian Georgescu
125 162 Adrian Georgescu
Complete interactive 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.
126 1 Adrian Georgescu
127 155 Adrian Georgescu
{{{
128 1 Adrian Georgescu
sudo apt-get install sipclients
129 155 Adrian Georgescu
}}}
130
131 162 Adrian Georgescu
 * sip-register - REGISTER a SIP end-point or detect Bonjour neighbors
132 1 Adrian Georgescu
 * sip_audio_session - Setup a single SIP audio session using RTP/sRTP media
133 167 Adrian Georgescu
 * sip_session - Complete client with multiple sessions like Audio, IM and File Transfer
134 162 Adrian Georgescu
 * sip_message - Send and receive short messages using SIP MESSAGE method
135
 * sip_publish_presence- PUBLISH presence information for a given SIP address
136 1 Adrian Georgescu
 * sip_subscribe_winfo - SUBSCRIBE to the watcher list for given SIP address
137 162 Adrian Georgescu
 * sip_subscribe_presence - SUBSCRIBE to Presence Event for a given SIP address
138
 * sip_subscribe_rls - SUBSCRIBE for Presence Event to a list of SIP addresses
139
 * sip_subscribe_mwi - SUBSCRIBE for Voicemail Message Waiting Indicator
140 155 Adrian Georgescu
141
For a description of the sample programs see http://sipsimpleclient.com/wiki/SipTesting
142
143
=== Finished Products ===
144
145 162 Adrian Georgescu
The SDK is used in several products since end of 2009. These are end-products that use the SDK and provide exhaustive examples for how the SDK was used to achieve the goals.
146 155 Adrian Georgescu
147
 1. Multiparty Conference Application with Wideband Audio, IM and File Transfer: http://sylkserver.com
148
 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 
149
 1. SIP Client for Linux: Blink for Ubuntu, and Debian, use same repositories from AG Projects and do 'sudo apt-get install blink' 
150 162 Adrian Georgescu
 1. SIP client for Windows: https://blink.sipthor.net/download.phtml?download&os=nt
151 155 Adrian Georgescu
152
== Non-Python environments ==
153
154 162 Adrian Georgescu
As the programming choice was Python this SDK will appeal to people that want to develop applications in Python. 
155 155 Adrian Georgescu
156 162 Adrian Georgescu
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 straight forward process if at all possible.
157
158 155 Adrian Georgescu
=== Cocoa Objective C ===
159
160
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.
161
162
http://pyobjc.sourceforge.net/
163 1 Adrian Georgescu
164 155 Adrian Georgescu
The SDK was fully used without any problems to build Blink for MacOSX by using this bridge.
165
166
=== Qt Framework ===
167
168
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.
169
170
http://qt.nokia.com/
171
172 157 Adrian Georgescu
The SDK was fully used without any problems to build Blink for Windows and Linux by using Qt Framework and its Python bindings.
173 1 Adrian Georgescu
174 157 Adrian Georgescu
=== Web Browser Plugin ===
175
176 1 Adrian Georgescu
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. 
177 155 Adrian Georgescu
178
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:
179
180
http://rtc-web.alvestrand.com. 
181
182
Google published a first specification and code drop in May 2011 and IETF and W3C had a few initial conference calls to setup the future agenda but no more at this stage. 
183
184 162 Adrian Georgescu
SIP SIMPLE Client SDK cannot run in the browser today for the reasons highlighted above 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 stays behind the browser in the same way  as Google Talk daemon does.
185 155 Adrian Georgescu
186
=== C Language  ===
187
188 170 Adrian Georgescu
How to possibly integrate Python into C is described here:
189 155 Adrian Georgescu
190
http://docs.python.org/extending/embedding.html
191
192
=== Java Language  ===
193
194
There is a bridge between Python and Java.
195
196
http://www.jython.org/
197
198 1 Adrian Georgescu
=== Translating into other languages  ===
199 158 Adrian Georgescu
200 170 Adrian Georgescu
The state machine for a multimedia real-time application is orders of magnitude more complex than a non-real-time file transfer protocols like BitTorent.
201 158 Adrian Georgescu
202 155 Adrian Georgescu
 * 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]
203
 * RTP media used for audio and video has 6 to 10 states depending on the type of media
204
 * MSRP media used for chat functionality has multiple states
205
 * ICE NAT traversal has many states interrelated with both signaling and the media plane
206 1 Adrian Georgescu
 * Presence Publish/Subscribe/Notify mechanism has multiple states
207
208 168 Adrian Georgescu
One must describe the transitions of states, which may contain complex data and can be raised in different threads. There are multiple sockets in use using several transports. 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. While building the SDK in Python took about 3 years, expressing this complexity into a low level language like C requires many years of work with a large team of well qualified people.