⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ht1-callcontrol.dox

📁 mediastreamer2是开源的网络传输媒体流的库
💻 DOX
字号:
/** * @ingroup libeXosip2 The eXtented eXosip stack * @defgroup howto1_initialize How-To initiate, modify or terminate calls.eXosip2 offers a flexible API to help you controling calls.<H2>Initiate a call</H2>To start an outgoing call, you typically need a few headers whichwill be used by eXosip2 to build a default SIP INVITE request. Thecode below is used to start a call:<PRE>  osip_message_t *invite;  int i;  i = eXosip_call_build_initial_invite (&invite, "<sip:to@antisip.com>",                                        "<sip:from@antisip.com>",                                        NULL, // optionnal route header                                        "This is a call for a conversation");  if (i != 0)    {      return -1;    }  osip_message_set_supported (invite, "100rel");  {    char tmp[4096];    char localip[128];    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");  }  eXosip_lock ();  i = eXosip_call_send_initial_invite (invite);  if (i > 0)    {      eXosip_call_set_reference (i, reference);    }  eXosip_unlock ();  return i;</PRE>The above code is using eXosip_call_build_initial_invite to builda default SIP INVITE request for a new call. You have to inserta SDP body announcing your audio parameter for the RTP stream.The above code also show the flexibility of the eXosip2 API whichallow you to insert additionnal headers such as "Supported: 100rel"(announcing support for a SIP extension). Thus you can enterelycontrol the creation of SIP requests.The returned element of eXosip_call_send_initial_invite is thecall identifier that you can use to send a CANCEL. In future eventsother than 100 Trying, you'll also get the dialog identifierthat will also be needed to control established calls.eXosip_call_set_reference is also a mean to attach one of yourown context to a call so that you'll get your pointer back ineXosip_event.<H2>Answer a call</H2>The code below is another example that teach you how to answeran incoming call.You'll usually need to send a "180 Ringing" SIP answer whenreceiving a SIP INVITE: <PRE>  eXosip_lock ();  eXosip_call_send_answer (ca->tid, 180, NULL);  eXosip_unlock ();</PRE><b>Note</b>: The above code also shows that the stack is sometimes able tobuild and send a default SIP messages with only one API callThen, when the user wants to answer the call, you'll need to send a200 ok and insert a SDP body in your SIP answer:<PRE>  osip_message_t *answer = NULL;  eXosip_lock ();  i = eXosip_call_build_answer (ca->tid, 200, &answer);  if (i != 0)  {     eXosip_call_send_answer (ca->tid, 400, NULL);  }  else  {     i = sdp_complete_200ok (ca->did, answer);     if (i != 0)     {        osip_message_free (answer);        eXosip_call_send_answer (ca->tid, 415, NULL);     }     else        eXosip_call_send_answer (ca->tid, 200, answer);  }  eXosip_unlock ();</PRE><b>Note</b>: In the above code, you can note that to send a responseto a request, you have to use the transaction identifier (and not acall identifier or a dialog identifier!)<b>Note2</b>: For sending a 200ok, you'll usually need to inserta SDP body in the answer and before this, to negotiate the parametersand codecs that you want to support. In the test tool, provided byeXosip2 (josua application), you'll find a very basic implementationof the SDP negotiation.<H2>Sending other request</H2>The call control API allows you to send and receive REFER, UPDATE, INFO,OPTIONS, NOTIFY and INVITEs whitin calls. A few limitations still existfor answering other requests within calls, but it should be already possibleto send any kind of request.Here you have a code sample to send an INFO requests used tosend an out of band dtmf within the signalling layer.<PRE>  osip_message_t *info;  char dtmf_body[1000];  int i;  eXosip_lock ();  i = eXosip_call_build_info (ca->did, &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->did, info);  }  eXosip_unlock ();</PRE>*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -