1How-To initiate, modify or terminHaotlwei-bTceoaXloilsnsii.pt(2i3a)te, modify or terminate calls.(3)
2
3
4
6 How-To initiate, modify or terminate calls. - eXosip2 offers a flexible
7 API to help you controling calls.
8
9 Initiate a call
10 To start an outgoing call, you typically need a few headers which will
11 be used by eXosip2 to build a default SIP INVITE request. The code
12 below is used to start a call:
13
14 osip_message_t *invite;
15 int i;
16
17 i = eXosip_call_build_initial_invite (&invite, '<sip:to@antisip.com>',
18 '<sip:from@antisip.com>',
19 NULL, // optionnal route header
20 'This is a call for a conversation');
21 if (i != 0)
22 {
23 return -1;
24 }
25
26 osip_message_set_supported (invite, '100rel');
27
28 {
29 char tmp[4096];
30 char localip[128];
31
32 eXosip_guess_localip (AF_INET, localip, 128);
33 snprintf (tmp, 4096,
34 'v=0\r\n'
35 'o=josua 0 0 IN IP4 %s\r\n'
36 's=conversation\r\n'
37 'c=IN IP4 %s\r\n'
38 't=0 0\r\n'
39 'm=audio %s RTP/AVP 0 8 101\r\n'
40 'a=rtpmap:0 PCMU/8000\r\n'
41 'a=rtpmap:8 PCMA/8000\r\n'
42 'a=rtpmap:101 telephone-event/8000\r\n'
43 'a=fmtp:101 0-11\r\n', localip, localip, port);
44 osip_message_set_body (invite, tmp, strlen (tmp));
45 osip_message_set_content_type (invite, 'application/sdp');
46 }
47
48 eXosip_lock ();
49 i = eXosip_call_send_initial_invite (invite);
50 if (i > 0)
51 {
52 eXosip_call_set_reference (i, reference);
53 }
54 eXosip_unlock ();
55 return i;
56
57 The above code is using eXosip_call_build_initial_invite to build a
58 default SIP INVITE request for a new call. You have to insert a SDP
59 body announcing your audio parameter for the RTP stream.
60
61 The above code also show the flexibility of the eXosip2 API which allow
62 you to insert additionnal headers such as 'Supported: 100rel'
63 (announcing support for a SIP extension). Thus you can enterely control
64 the creation of SIP requests.
65
66 The returned element of eXosip_call_send_initial_invite is the call
67 identifier that you can use to send a CANCEL. In future events other
68 than 100 Trying, you'll also get the dialog identifier that will also
69 be needed to control established calls.
70
71 eXosip_call_set_reference is also a mean to attach one of your own
72 context to a call so that you'll get your pointer back in eXosip_event.
73
74 Answer a call
75 The code below is another example that teach you how to answer an
76 incoming call.
77
78 You'll usually need to send a '180 Ringing' SIP answer when receiving a
79 SIP INVITE:
80
81 eXosip_lock ();
82 eXosip_call_send_answer (ca->tid, 180, NULL);
83 eXosip_unlock ();
84
85 Note: The above code also shows that the stack is sometimes able to
86 build and send a default SIP messages with only one API call
87
88 Then, when the user wants to answer the call, you'll need to send a 200
89 ok and insert a SDP body in your SIP answer:
90
91 osip_message_t *answer = NULL;
92
93 eXosip_lock ();
94 i = eXosip_call_build_answer (ca->tid, 200, &answer);
95 if (i != 0)
96 {
97 eXosip_call_send_answer (ca->tid, 400, NULL);
98 }
99 else
100 {
101 i = sdp_complete_200ok (ca->did, answer);
102 if (i != 0)
103 {
104 osip_message_free (answer);
105 eXosip_call_send_answer (ca->tid, 415, NULL);
106 }
107 else
108 eXosip_call_send_answer (ca->tid, 200, answer);
109 }
110 eXosip_unlock ();
111
112 Note: In the above code, you can note that to send a response to a
113 request, you have to use the transaction identifier (and not a call
114 identifier or a dialog identifier!)
115
116 Note2: For sending a 200ok, you'll usually need to insert a SDP body in
117 the answer and before this, to negotiate the parameters and codecs that
118 you want to support. In the test tool, provided by eXosip2 (josua
119 application), you'll find a very basic implementation of the SDP
120 negotiation.
121
122 Sending other request
123 The call control API allows you to send and receive REFER, UPDATE,
124 INFO, OPTIONS, NOTIFY and INVITEs whitin calls. A few limitations still
125 exist for answering other requests within calls, but it should be
126 already possible to send any kind of request.
127
128 Here you have a code sample to send an INFO requests used to send an
129 out of band dtmf within the signalling layer.
130
131 osip_message_t *info;
132 char dtmf_body[1000];
133 int i;
134
135 eXosip_lock ();
136 i = eXosip_call_build_info (ca->did, &info);
137 if (i == 0)
138 {
139 snprintf (dtmf_body, 999, 'Signal=%c\r\nDuration=250\r\n', c);
140 osip_message_set_content_type (info, 'application/dtmf-relay');
141 osip_message_set_body (info, dtmf_body, strlen (dtmf_body));
142 i = eXosip_call_send_request (ca->did, info);
143 }
144 eXosip_unlock ();
145
146Version 3.0.1 Ho3w0-TAougin2i0t0i7ate, modify or terminate calls.(3)