Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > d661425f055462744853e295597df6f5 > files > 58

libeXosip2-devel-3.1.0-3.fc12.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>libeXosip2: How-To initiate, modify or terminate calls.</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.9 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>How-To initiate, modify or terminate calls.<br>
<small>
[<a class="el" href="group__libeXosip2.html">The eXtented eXosip stack</a>]</small>
</h1><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
</table>
eXosip2 offers a flexible API to help you controling calls.<p>
<h2>Initiate a call</h2>
<p>
To start an outgoing call, you typically need a few headers which will be used by eXosip2 to build a default SIP INVITE request. The code below is used to start a call:<p>
<pre>
  osip_message_t *invite;
  int i;</pre><p>
<pre>  i = eXosip_call_build_initial_invite (&amp;invite, "&lt;sip:to@antisip.com&gt;",
                                        "&lt;sip:from@antisip.com&gt;",
                                        NULL, // optionnal route header
                                        "This is a call for a conversation");
  if (i != 0)
    {
      return -1;
    }</pre><p>
<pre>  osip_message_set_supported (invite, "100rel");</pre><p>
<pre>  {
    char tmp[4096];
    char localip[128];</pre><p>
<pre>    eXosip_guess_localip (AF_INET, localip, 128);
    snprintf (tmp, 4096,
              "v=0\r\n"
              "o=josua 0 0 IN IP4 %s\r\n"
              "s=conversation\r\n"
              "c=IN IP4 %s\r\n"
              "t=0 0\r\n"
              "m=audio %s RTP/AVP 0 8 101\r\n"
              "a=rtpmap:0 PCMU/8000\r\n"
              "a=rtpmap:8 PCMA/8000\r\n"
              "a=rtpmap:101 telephone-event/8000\r\n"
              "a=fmtp:101 0-11\r\n", localip, localip, port);
    osip_message_set_body (invite, tmp, strlen (tmp));
    osip_message_set_content_type (invite, "application/sdp");
  }</pre><p>
<pre>  eXosip_lock ();
  i = eXosip_call_send_initial_invite (invite);
  if (i &gt; 0)
    {
      eXosip_call_set_reference (i, reference);
    }
  eXosip_unlock ();
  return i;</pre><p>
<pre></pre><p>
The above code is using eXosip_call_build_initial_invite to build a default SIP INVITE request for a new call. You have to insert a SDP body announcing your audio parameter for the RTP stream.<p>
The above code also show the flexibility of the eXosip2 API which allow you to insert additionnal headers such as "Supported: 100rel" (announcing support for a SIP extension). Thus you can enterely control the creation of SIP requests.<p>
The returned element of eXosip_call_send_initial_invite is the call identifier that you can use to send a CANCEL. In future events other than 100 Trying, you'll also get the dialog identifier that will also be needed to control established calls.<p>
eXosip_call_set_reference is also a mean to attach one of your own context to a call so that you'll get your pointer back in <a class="el" href="structeXosip__event.html">eXosip_event</a>.<p>
<h2>Answer a call</h2>
<p>
The code below is another example that teach you how to answer an incoming call.<p>
You'll usually need to send a "180 Ringing" SIP answer when receiving a SIP INVITE:<p>
<pre>
  eXosip_lock ();
  eXosip_call_send_answer (ca-&gt;tid, 180, NULL);
  eXosip_unlock ();
</pre><p>
<b>Note</b>: The above code also shows that the stack is sometimes able to build and send a default SIP messages with only one API call<p>
Then, when the user wants to answer the call, you'll need to send a 200 ok and insert a SDP body in your SIP answer:<p>
<pre>
  osip_message_t *answer = NULL;</pre><p>
<pre>  eXosip_lock ();
  i = eXosip_call_build_answer (ca-&gt;tid, 200, &amp;answer);
  if (i != 0)
  {
     eXosip_call_send_answer (ca-&gt;tid, 400, NULL);
  }
  else
  {
     i = sdp_complete_200ok (ca-&gt;did, answer);
     if (i != 0)
     {
        osip_message_free (answer);
        eXosip_call_send_answer (ca-&gt;tid, 415, NULL);
     }
     else
        eXosip_call_send_answer (ca-&gt;tid, 200, answer);
  }
  eXosip_unlock ();
</pre><p>
<b>Note</b>: In the above code, you can note that to send a response to a request, you have to use the transaction identifier (and not a call identifier or a dialog identifier!)<p>
<b>Note2</b>: For sending a 200ok, you'll usually need to insert a SDP body in the answer and before this, to negotiate the parameters and codecs that you want to support. In the test tool, provided by eXosip2 (josua application), you'll find a very basic implementation of the SDP negotiation.<p>
<h2>Sending other request</h2>
<p>
The call control API allows you to send and receive REFER, UPDATE, INFO, OPTIONS, NOTIFY and INVITEs whitin calls. A few limitations still exist for answering other requests within calls, but it should be already possible to send any kind of request.<p>
Here you have a code sample to send an INFO requests used to send an out of band dtmf within the signalling layer.<p>
<pre>
  osip_message_t *info;
  char dtmf_body[1000];
  int i;</pre><p>
<pre>  eXosip_lock ();
  i = eXosip_call_build_info (ca-&gt;did, &amp;info);
  if (i == 0)
  {
     snprintf (dtmf_body, 999, "Signal=%c\r\nDuration=250\r\n", c);
     osip_message_set_content_type (info, "application/dtmf-relay");
     osip_message_set_body (info, dtmf_body, strlen (dtmf_body));
     i = eXosip_call_send_request (ca-&gt;did, info);
  }
  eXosip_unlock ();
</pre> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Jul 26 15:51:58 2009 for libeXosip2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>