How-To initiate, modify or terminate calls.

The eXtented eXosip stack

eXosip2 offers a flexible API to help you controling calls.

Initiate a call

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:

osip_message_t *invite;

int cid;

int i;

i = eXosip_call_build_initial_invite (ctx, &invite, "<sip:to@antisip.com>",

"<sip:from@antisip.com>",

NULL, // optional 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 (ctx, AF_INET, localip, 128);

snprintf (tmp, 4096,

"v=0\r\n"

"o=jack 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 (ctx);

cid = eXosip_call_send_initial_invite (ctx, invite);

if (cid > 0)

{

eXosip_call_set_reference (ctx, i, reference);

}

eXosip_unlock (ctx);

return i;

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.

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.

The returned element of eXosip_call_send_initial_invite is the cid (call identifier) that you can use to send a CANCEL. In future events other than 100 Trying, you'll also get the did (dialog identifier) that will also be needed to control established calls.

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 eXosip_event.

Answer a call

The code below is another example that teach you how to answer an incoming call.

You'll usually need to send a "180 Ringing" SIP answer when receiving a SIP INVITE:

eXosip_lock (ctx);

eXosip_call_send_answer (ctx, evt->tid, 180, NULL);

eXosip_unlock (ctx);

Note: The above code also shows that the stack is sometimes able to build and send a default SIP messages with only one API call

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:

osip_message_t *answer = NULL;

eXosip_lock (ctx);

i = eXosip_call_build_answer (ctx, evt->tid, 200, &answer);

if (i != 0)

{

eXosip_call_send_answer (ctx, evt->tid, 400, NULL);

}

else

{

i = sdp_complete_200ok (evt->did, answer);

if (i != 0)

{

osip_message_free (answer);

eXosip_call_send_answer (ctx, evt->tid, 415, NULL);

}

else

eXosip_call_send_answer (ctx, evt->tid, 200, answer);

}

eXosip_unlock (ctx);

Note: In the above code, you can note that to send a response to a request, you have to use the tid (transaction identifier) and not a cid (call identifier) or a did (dialog identifier).

Note2: 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. This is left to you! Once you have created the SDP, you add it in the answer using the following code:

osip_message_set_body (answer, tmp, strlen (tmp));

osip_message_set_content_type (answer, "application/sdp");

Terminate a Call

Simple API, no much to say about it! You can use it when you want: it will either send a CANCEL, a negative answer or a BYE depending on the call state.

eXosip_lock (ctx);

eXosip_call_terminate (ctx, cid, did);

eXosip_unlock (ctx);

Note: You can't stop a call where no 100 Trying has been received. In that case, you need to wait before sending a CANCEL or a BYE... This is per rfc3261.

Sending INFO, REFER, UPDATE, NOTIFY, OPTIONS request

The call control API allows you to send and receive REFER, UPDATE, INFO, OPTIONS, NOTIFY and INVITEs whitin calls.

Here you have a code sample to send an INFO requests used to send an out of band dtmf within the signalling layer. (not standard, but still used on some system!)

osip_message_t *info;

char dtmf_body[1000];

int i;

eXosip_lock (ctx);

i = eXosip_call_build_info (ctx, evt->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 (ctx, evt->did, info);

}

eXosip_unlock (ctx);

Sending any other request, with any header

You can in fact, send any kind of other request using eXosip2 API.

You will find many other API to build any kind of sip message. Using osip API, you can add any header or body in those message. eXosip2 will always prepare the minimal and technical stuff you need.

osip_message_t *message;

char body[1000];

int i;

eXosip_lock (ctx);

i = eXosip_call_build_request (ctx, evt->did, "PRIVATECOMMAND", &message);

if (i == 0)

{

snprintf (body, 999, "room=1;light=on\r\nroom=2;light=off\r\n");

osip_message_set_content_type (message, "application/antisip-domotic");

osip_message_set_body (message, body, strlen (body));

osip_message_set_header (invite, "P-MyCommand", "option=value");

i = eXosip_call_send_request (ctx, evt->did, message);

}

eXosip_unlock (ctx);


libeXosip2(1-2) -- How-To initiate, modify or terminate calls.的更多相关文章

  1. libeXosip2(1) -- Modules

    Modules Here is a list of all modules: [detail level 12] The eXtented eXosip stack LibeXosip2 Versio ...

  2. Simple GB28181 System

    I. Deployment  / Architecture Block Diagram II. Resources Used 1. freeswitch —— sip server and media ...

  3. RFC3261--sip

    本文转载自 http://www.ietf.org/rfc/rfc3261.txt 中文翻译可参考 http://wenku.baidu.com/view/3e59517b1711cc7931b716 ...

  4. SOA与C#

    What is SOA? SOA or Service oriented architecture is an architecture style for building business app ...

  5. Service Oriented Architecture and WCF 【转】

    http://www.codeproject.com/Articles/515253/Service-Oriented-Architecture-and-WCF Introduction This a ...

  6. XMPP and SIP

    过去一年多,一直关注这方面的技术和发展,这里有一个简单的介绍,我觉得比较简洁明了.我做了一点翻译,还有我的一些评估.       SIP vs XMPP (Jabber) SIP and XMPP a ...

  7. linux申请strace ,lstrace, ptrace, dtrace

    ltrace命令是用来跟踪进程调用库函数的情况. ltrace -hUsage: ltrace [option ...] [command [arg ...]]Trace library calls ...

  8. AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...

  9. Modify Branding of FreeCAD

    Modify Branding of FreeCAD eryar@163.com This article describes the Branding of FreeCAD. Branding me ...

随机推荐

  1. Oracle查询死锁&杀死会话

    select object_name,machine,s.sid,s.serial#  from v$locked_object l,dba_objects o ,v$session s where ...

  2. [HEOI 2013 day2] 钙铁锌硒维生素 (线性代数,二分图匹配)

    题目大意 给定两个n阶方阵,方阵B的行i能匹配方阵A的行j当且仅当在第一个方阵中用行向量i替换行向量j后,第一个方阵满秩,显然这是个二分图匹配问题,问是否存在完美匹配,如果存在,还要输出字典序最小的方 ...

  3. CFGYM 2013-2014 CT S01E03 D题 费用流模版题

    题意: n行, a房间的气球,b房间的气球 i行需要的气球,与a房的距离,b房的距离 求最小距离 #include <stdio.h> #include <string.h> ...

  4. 数学之路(3)-机器学习(3)-机器学习算法-PCA

    PCA 主成分分析(Principal components analysis,PCA),维基百科给出一个较容易理解的定义:“PCA是一个正交化线性变换,把数据变换到一个新的坐标系统中,使得这一数据的 ...

  5. js将日期格式的时候转换成时间搓

    自己写的一个方法 function split_time(time){//将当前时间转换成时间搓  例如2013-09-11 12:12:12   var arr=time.split(" ...

  6. debian 源

    把下面的源覆盖在/etc/apt/sources.list deb http://http.debian.net/debian wheezy main deb-src http://http.debi ...

  7. Spark 初级算子

    #常用Transformation(即转换,延迟加载) #通过并行化scala集合创建RDD val rdd1 = sc.parallelize(Array(1,2,3,4,5,6,7,8)) #查看 ...

  8. python - socket模块1

    1.使用生活中的接打电话,解释socket通信流程  2.根据上图,写出socket通信的伪代码 2.1.server端伪代码 #买手机   #买手机卡 #开机 #等待电话 #收消息 #发消息 #挂电 ...

  9. Qt串口通信

    1. Qt串口通信类QSerialPort 在Qt5的的更新中,新增了串口通信的相关接口类QSerialPort,这使得在开发者在使用Qt进行UI开发时,可以更加简单有效地实现串口通信的相关功能. 开 ...

  10. Thread 常搞混的几个概念sleep、wait、yield、interrupt (转)

    原文网址:http://blog.csdn.net/partner4java/article/details/7993420sleep:在指定的毫秒数内让当前正在执行的线程休眠(暂停执行),此操作受到 ...