博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
libeXosip2(1-2) -- How-To initiate, modify or terminate calls.
阅读量:5086 次
发布时间:2019-06-13

本文共 4974 字,大约阅读时间需要 16 分钟。

How-To initiate, modify or terminate calls.

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 = (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];

(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");

}

(ctx);

cid = (ctx, invite);

if (cid > 0)

{

(ctx, i, reference);

}

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

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:

(ctx);

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

(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;

(ctx);

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

if (i != 0)

{

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

}

else

{

i = sdp_complete_200ok (evt->, answer);

if (i != 0)

{

osip_message_free (answer);

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

}

else

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

}

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

(ctx);

(ctx, cid, did);

(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;

(ctx);

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

}

(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;

(ctx);

i = (ctx, evt->, "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 = (ctx, evt->, message);

}

(ctx);


转载于:https://www.cnblogs.com/elisha-blogs/p/3945483.html

你可能感兴趣的文章
Aizu - 1378 Secret of Chocolate Poles (DP)
查看>>
csv HTTP简单表服务器
查看>>
OO设计的接口分隔原则
查看>>
数据库连接字符串大全 (转载)
查看>>
java类加载和对象初始化
查看>>
对于负载均衡的理解
查看>>
django简介
查看>>
window.event在IE和Firefox的异同
查看>>
常见的js算法面试题收集,es6实现
查看>>
IO流写出到本地 D盘demoIO.txt 文本中
查看>>
Windows10 下Apache服务器搭建
查看>>
HDU 5458 Stability
查看>>
左手坐标系和右手坐标系
查看>>
solr后台操作Documents之增删改查
查看>>
http://yusi123.com/
查看>>
文件文本的操作
查看>>
Ubuntu linux下gcc版本切换
查看>>
记一次Web服务的性能调优
查看>>
jQuery.form.js使用
查看>>
(转)linux sort,uniq,cut,wc命令详解
查看>>