exosip「建议收藏」

exosip「建议收藏」exosip针对UA是对osip进行扩展,oSIP不提供不论什么高速产生请求消息和响应消息的方法,全部请求消息和响应消息的形成必须调用一组sipmessageapi来手动组装完毕,所以作者在osi

大家好,又见面了,我是你们的朋友全栈君。

exosip针对UA是对osip进行扩展,oSIP不提供不论什么高速产生请求消息和响应消息的方法,全部请求消息和响应消息的形成必须调用一组sip message api来手动组装完毕,所以作者在osip上基础上开发了exosip,用exosip开发软电话非常方便,仅需几个API就能够完毕.exosip中附带一个样例:josua,只是josua相对复杂了点,以下给出一个最简单的样例供大家參考,由于样例实在太简单所以没有给出凝视,用到exosip的API的參数请參看exosip源码,看懂这个样例再研究josua就非常easy了.我使用的是osip 2.0.9+exosip 0.77.

#include “assert.h”
#include <conio.h>
#include <iostream>
#include <osip2/osip_mt.h>
#include <eXosip/eXosip.h>
#include <eXosip/eXosip_cfg.h>

using namespace std;

class jcall;

class jcall {
public:
 int cid;
 int did;
 
 char reason_phrase[50];
 int  status_code;
 
 char textinfo[256];
 char req_uri[256];
 char local_uri[256];
 char remote_uri[256];
 char subject[256];
 
 char remote_sdp_audio_ip[50];
 int  remote_sdp_audio_port;
 int  payload;
 char payload_name[50];
 
 int state;
 
 jcall() {}
 
 int build(eXosip_event_t *je)
 {
  jcall *ca = this;
  
  ca->cid = je->cid;
  ca->did = je->did;
  
  if (ca->did<1 && ca->cid<1)
  {
   assert(0);
   return -1; /* not enough information for this event?? */
  }
  
  osip_strncpy(ca->textinfo,   je->textinfo, 255);
  osip_strncpy(ca->req_uri,    je->req_uri, 255);
  osip_strncpy(ca->local_uri,  je->local_uri, 255);
  osip_strncpy(ca->remote_uri, je->remote_uri, 255);
  osip_strncpy(ca->subject,    je->subject, 255);
  
  if (ca->remote_sdp_audio_ip[0]==’/0′)
  {
   osip_strncpy(ca->remote_sdp_audio_ip, je->remote_sdp_audio_ip, 49);
   ca->remote_sdp_audio_port = je->remote_sdp_audio_port;
   ca->payload = je->payload;
   osip_strncpy(ca->payload_name, je->payload_name, 49);
   
  }
  
  if (je->reason_phrase[0]!=’/0′)
  {
   osip_strncpy(ca->reason_phrase, je->reason_phrase, 49);
   ca->status_code = je->status_code;
  }
  
  ca->state = je->type;
  return 0;
 }
 
};

jcall call;

void __exit( int r )
{
 char line[256];
 gets( line );
 exit( r );
}

void josua_printf(char* buf)
{
 printf( “/n” );
}

int josua_event_get()
{
 int counter =0;
 /* use events to print some info */
 eXosip_event_t *je;
 for (;;)
 {
  char buf[100];
  je = eXosip_event_wait(0,50);
  if (je==NULL)
   break;
  counter++;
  if (je->type==EXOSIP_CALL_NEW)
  {
   printf( “<- (%i %i) INVITE from: %s”,
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   call.build(je);
  }
  else if (je->type==EXOSIP_CALL_ANSWERED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_PROCEEDING)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_RINGING)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_REDIRECTED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_REQUESTFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_SERVERFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_GLOBALFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_CLOSED)
  {
   printf( “<- (%i %i) BYE from: %s”,
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_HOLD)
  {
   printf( “<- (%i %i) INVITE (On Hold) from: %s”,
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_CALL_OFFHOLD)
  {
   printf( “<- (%i %i) INVITE (Off Hold) from: %s”,
    je->cid, je->did, je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_REGISTRATION_SUCCESS)
  {
   printf( “<- (%i) [%i %s] %s for REGISTER %s”,
    je->rid,
    je->status_code,
    je->reason_phrase,
    je->remote_uri,
    je->req_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_REGISTRATION_FAILURE)
  {
   printf( “<- (%i) [%i %s] %s for REGISTER %s”,
    je->rid,
    je->status_code,
    je->reason_phrase,
    je->remote_uri,
    je->req_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_NEW)
  {
   printf( “<- (%i %i) OPTIONS from: %s”,
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_OPTIONS_ANSWERED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_PROCEEDING)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_OPTIONS_REDIRECTED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_REQUESTFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_SERVERFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_OPTIONS_GLOBALFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_NEW)
  {
   printf( “<- (%i %i) INFO from: %s”,
    je->cid, je->did,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_ANSWERED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_PROCEEDING)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_REDIRECTED)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_REQUESTFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_SERVERFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_INFO_GLOBALFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s”,
    je->cid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  
  else if (je->type==EXOSIP_SUBSCRIPTION_ANSWERED)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
   printf( “<- (%i %i) online=%i [status: %i reason:%i]”,
    je->sid, je->did,
    je->online_status,
    je->ss_status,
    je->ss_reason);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_PROCEEDING)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_REDIRECTED)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_REQUESTFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_SERVERFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_GLOBALFAILURE)
  {
   printf( “<- (%i %i) [%i %s] %s for SUBSCRIBE”,
    je->sid, je->did,
    je->status_code,
    je->reason_phrase,
    je->remote_uri);
   josua_printf(buf);
  }
  else if (je->type==EXOSIP_SUBSCRIPTION_NOTIFY)
  {
   printf( “<- (%i %i) NOTIFY from: %s”,
    je->sid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   printf( “<- (%i %i) online=%i [status: %i reason:%i]”,
    je->sid, je->did,
    je->online_status,
    je->ss_status,
    je->ss_reason);
   josua_printf(buf);
   
  }
  else if (je->type==EXOSIP_IN_SUBSCRIPTION_NEW)
  {
   printf( “<- (%i %i) SUBSCRIBE from: %s”,
    je->nid, je->did,
    je->remote_uri);
   josua_printf(buf);
   
   /* search for the user to see if he has been
   previously accepted or not! */
   
   eXosip_notify(je->did, EXOSIP_SUBCRSTATE_PENDING, EXOSIP_NOTIFY_AWAY);
  }
  else if (je->textinfo[0]!=’/0′)
  {
   printf( “(%i %i %i %i) %s”, je->cid, je->sid, je->nid, je->did, je->textinfo);
   josua_printf(buf);
  }
  
  
  eXosip_event_free(je);
    }
 if (counter>0)
  return 0;
 return -1;
}

int main(int argc, char* argv[])
{
 int i;
 memset( &call, 0, sizeof(call) );
 
 cout << “Usage:”<< endl;
 cout << “a – answering call”<< endl;
 cout << “h – hangup”<< endl;
 cout << “r – ringing”<< endl;
 cout << “c – call”<< endl;
 cout << “q – quit”<< endl;
 
 FILE* logfile = fopen( “logfile.txt”, “w”);
 // osip_trace_initialize( (_trace_level)0, logfile );
 // osip_trace_initialize( (_trace_level)8, stdout );
 i = eXosip_init(stdin, stdout, 5060);
 if (i!=0)
    {
  fprintf (stderr, “test: could not initialize eXosip/n”);
  __exit(0);
  
    }
 
 
 eXosip_sdp_negotiation_remove_audio_payloads();
 eXosip_sdp_negotiation_add_codec(osip_strdup(“0”),
  NULL,
  osip_strdup(“RTP/AVP”),
  NULL, NULL, NULL,
  NULL,NULL,
  osip_strdup(“0 PCMU/8000”));
 
 eXosip_sdp_negotiation_add_codec(osip_strdup(“8”),
  NULL,
  osip_strdup(“RTP/AVP”),
  NULL, NULL, NULL,
  NULL,NULL,
  osip_strdup(“8 PCMA/8000”));
   
 /* register callbacks? */
 eXosip_set_mode(EVENT_MODE);
 
 osip_message_t *invite;
 i = eXosip_build_initial_invite(&invite,
  “sip:192.168.197.5:5060”,       //被叫对IP
  “sip:192.168.197.254:5060”,     //自己IP
  NULL,
  “oSIP phone”);
 if (i!=0)
 {
  fprintf (stderr, “eXosip_build_initial_invite failed/n”);
  __exit(0);
 }
 
 
 cout << “oSIP>”;
 bool run = true;
 while( run )
 {
  josua_event_get();
  
  if ( _kbhit() )
  {
   switch ( _getch() )
   {
   case ‘a’:
    cout << “answer”<< endl;
    eXosip_lock();
    eXosip_answer_call(call.did, 200, 0);
    eXosip_unlock();
    break;
    
   case ‘h’:
    cout << “hangup”<< endl;
    eXosip_lock();
    eXosip_terminate_call( call.cid, call.did );
    eXosip_unlock();
    break;
    
   case ‘r’:
    cout << “ringing”<< endl;
    eXosip_lock();
    eXosip_answer_call(call.did, 180, 0);
    eXosip_unlock();
    break;
    
   case ‘c’:
    cout << “call”<< endl;
    eXosip_lock();
    eXosip_initiate_call(invite, NULL, NULL, “10500”);
    eXosip_unlock();
    break;
    
   case ‘q’:
    cout << “quit”<< endl;
    run = false;
    break;
    
   default :
    cout << “/noSIP>”;
   }
  }
 }
 
 
 return 0;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/154497.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 使用一个运放滤三次谐波 二阶有源带通滤波器的电路设计及波形效果

    使用一个运放滤三次谐波 二阶有源带通滤波器的电路设计及波形效果本文主要讲无限增益多路反馈有源带通滤波器的实现,工程实作,非理论知识,关于其他方法简略提,不做细究

  • polkit启动失败_zabbix4.4 启动失败分析

    polkit启动失败_zabbix4.4 启动失败分析zabbix是基于WEB界面提供分布式系统监视以及网络监视功能的企业级开源解决方案,能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。做为开源用户的支持者,我们大部分环境用的软件包含监控软件、数据库、继承应用、操作系统等都是用开源的,例如centos、PG、zabbix、openshift等,但是开源的在成熟度上是不错,但是安装软件有时比…

  • BN层理解_理解六层次总结

    BN层理解_理解六层次总结bn层计算的均值和方差是channel的输入数据是nchw,求得的均值和方差均是长度为c的向量mini-batch指的是一个batch的所有样本对应通道组合成一个minibatch,1个nchw的数据有c个mini-batch一个mini-batch在一起进行求均值和方差HW的归一化,求出NC个均值与方差,然后N个均值与方差求出一个均值与方差的Vector,size为C,即相同通道的一个mini_batch的样本求出一个mean和variance每次迭代时采用的是滑动平均方式更新,.

    2022年10月14日
  • SynchronousQueue同步队列

    SynchronousQueue同步队列SynchronousQueue简介Java6的并发编程包中的SynchronousQueue是一个没有数据缓冲的BlockingQueue,生产者线程对其的插入操作put必须等待消费者的移除操作take,反过来也一样。不像ArrayBlockingQueue或LinkedListBlockingQueue,SynchronousQueue内部并没有数据缓存空间,你不能调用peek()方…

  • MySQL字段存储的内容是不区分大小写的,你知道吗?

    做一个积极的人编码、改bug、提升自己我有一个乐园,面向编程,春暖花开!分享一下大神老师的人工智能教程。零基础!通俗易懂!风趣幽默(偶尔开开车,讲讲黄段子)!大家可以看看是否对自己有帮助,如果你对人工智能感兴趣,希望你也加入到我们人工智能的队伍中来,点击这里查看【人工智能教程】。接下来进入正文。文章目录00 简单回顾01 一个例子02 解决方案03 总结04 参考资料00 简单回…

  • Fiddler抓取视频数据「建议收藏」

    准备工作:(1)、手机(安卓、ios都可以)/安卓模拟器,今天主要以安卓模拟器为主,操作过程一致。(2)、抓包工具:Fiddel下载地址:(https://www.telerik.com/download/fiddler)(3)、编程工具:pycharm(4)、安卓模拟器上安装抖音(逍遥安装模拟器)一、fiddler配置在tools中的options中,按照图中勾选后点击Actio…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号