基于exosip 编写呼叫流程实例

1、已经编译生成号exosip相关库,

2、复制如下代码生成UAC,该实例使用的是windows控制台程序,对于sdp的解析部分需修改一下

代码如下:

#include <eXosip2/eXosip.h>
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>

int main(int argc, char *argv[])
{

	struct eXosip_t *context_eXosip;

	eXosip_event_t *je;
	osip_message_t *reg = NULL;
	osip_message_t *invite = NULL;
	osip_message_t *ack = NULL;
	osip_message_t *info = NULL;
	osip_message_t *message = NULL;

	int call_id, dialog_id;
	int i, flag;
	int flag1 = 1;

	char *identity = "sip:140@192.168.0.115";   //UAC1,端口是15060
	char *registar = "sip:133@192.168.0.115:15061"; //UAS,端口是15061
	char *source_call = "sip:140@192.168.0.115";
	char *dest_call = "sip:814@192.168.0.103:15061";
	//identify和register这一组地址是和source和destination地址相同的
	//在这个例子中,uac和uas通信,则source就是自己的地址,而目的地址就是uac1的地址
	char command;
	char tmp[4096];

	printf("r   向服务器注册\n\n");
	printf("c   取消注册\n\n");
	printf("i   发起呼叫请求\n\n");
	printf("h   挂断\n\n");
	printf("q   推出程序\n\n");
	printf("s   执行方法INFO\n\n");
	printf("m   执行方法MESSAGE\n\n");

	//初始化
	struct eXosip_t *excontext;
	excontext = eXosip_malloc();
	i = eXosip_init(excontext);

	if (i != 0)
	{
		printf("Couldn't initialize eXosip!\n");
		osip_free(excontext);
		return -1;
	}
	else
	{
		printf("eXosip_init successfully!\n");
	}

	//绑定uac自己的端口15060,并进行端口监听
	i = eXosip_listen_addr(excontext, IPPROTO_UDP, NULL, 15060, AF_INET, 0);
	if (i != 0)
	{
		eXosip_quit(excontext);
		fprintf(stderr, "Couldn't initialize transport layer!\n");
		osip_free(excontext);
		return -1;
	}
	flag = 1;

	while (flag)
	{
		//输入命令
		printf("Please input the command:\n");
		scanf_s("%c", &command);
		getchar();

		switch (command)
		{
		case 'r':
			printf("This modal is not completed!\n");
			break;
		case 'i'://INVITE,发起呼叫请求
			i = eXosip_call_build_initial_invite(excontext, &invite, dest_call, source_call, NULL, "This is a call for conversation");
			if (i != 0)
			{
				printf("Initial INVITE failed!\n");
				break;
			}
			//符合SDP格式,其中属性a是自定义格式,也就是说可以存放自己的信息,
			//但是只能有两列,比如帐户信息
			//但是经过测试,格式vot必不可少,原因未知,估计是协议栈在传输时需要检查的
			_snprintf_s(tmp, 4096,
				"v=0\r\n"
				"o=anonymous 0 0 IN IP4 0.0.0.0\r\n"
				"t=0 0\r\n"
				"m=audio 62100 RTP/AVP 114 0 8 101\r\n"
				"a=rtpmap:114 AMR/8000\r\n"
				"a=fmtp:114 octet-align=1;mode-set=7,0\r\n"
				"a=rtpmap:0 PCMU/8000\r\n"
				"a=rtpmap:8 PCMA/8000\r\n"
				"m=video 62102 RTP/AVP 102 99\r\n"
				"a=rtpmap:102 H264/90000\r\n"
				"a=rtpmap:99 MP4V-ES/90000\r\n"
				);

			osip_message_set_body(invite, tmp, strlen(tmp));
			osip_message_set_content_type(invite, "application/sdp");

			eXos
  • 4
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值