当前位置: 首页 > news >正文

网站建设如何制作教程免费加客源软件

网站建设如何制作教程,免费加客源软件,网站页面,wordpress 首次 弹窗搭建CG28181 服务端,也即 SIP Server,这正是我们要实现的。实现CG28181服务端可以借助于现有的开源库 PJSIP,具体的实现步骤如下: 1、启动GB28181服务端,接收客户端消息请求 bool Init(std::string concat, int logL…

搭建CG28181 服务端,也即 SIP Server,这正是我们要实现的。实现CG28181服务端可以借助于现有的开源库 PJSIP,具体的实现步骤如下:

1、启动GB28181服务端,接收客户端消息请求

bool Init(std::string concat, int logLevel)
{this->concat = concat;pj_log_set_level(logLevel);auto status = pj_init();status = pjlib_util_init();pj_caching_pool_init(&cachingPool, &pj_pool_factory_default_policy, 0);status = pjsip_endpt_create(&cachingPool.factory, nullptr, &endPoint);status = pjsip_tsx_layer_init_module(endPoint);status = pjsip_ua_init_module(endPoint, nullptr);pool = pj_pool_create(&cachingPool.factory, "proxyapp", 4000, 4000, nullptr);auto pjStr =StrToPjstr(GetAddr());pj_sockaddr_in pjAddr;pjAddr.sin_family = pj_AF_INET();pj_inet_aton(&pjStr, &pjAddr.sin_addr);auto port = GetPort();pjAddr.sin_port = pj_htons(static_cast<pj_uint16_t>(GetPort()));status = pjsip_udp_transport_start(endPoint, &pjAddr, nullptr, 1, nullptr);if (status != PJ_SUCCESS) return status;auto realm = StrToPjstr(GetLocalDomain());return pjsip_auth_srv_init(pool, &authentication, &realm, lookup, 0) == PJ_SUCCESS ? true : false;
}

以上是PJSip初始化的代码,需要将服务将要监听的端口传给PJSIP,这样服务就在监听的端口接收SIP 消息了。

2、应答注册消息

        摄像机端发送来Register消息后,如果服务端不应答,摄像机端会一直发送直到收到服务端应答为止。如果服务器端重新运行,需要手动再次开启设备。

服务端应答注册消息代码如下:

bool OnReceive(pjsip_rx_data* rdata) override
{if(rdata->msg_info.cseq->method.id == PJSIP_REGISTER_METHOD){auto expires = static_cast<pjsip_expires_hdr*>(pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, nullptr));auto authHdr = static_cast<pjsip_authorization_hdr*>(pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_AUTHORIZATION, nullptr));if(expires && expires->ivalue > 0 ){if(authHdr){ cout <<"receive register info"<<endl;response(rdata, PJSIP_SC_OK, DateHead);QureryDeviceInfo(rdata);}else{response(rdata, PJSIP_SC_UNAUTHORIZED, AuthenHead);}return true;  }}return false;
}

 OnReceive 是服务端接收注册消息以后的响应方法,也就是说要将OnReceive作为入参传给PJSIP,完成此项功能在初始化<br>PJSIP Moudle时。至于PJSIP moudle,细节的话,可以查看PJSIP文档,代码如下:

bool  Init(std::string concat, int loglevel)
{bool ret = false;if(!mainModule){ret = context.Init(concat,loglevel);if(!ret) return ret;static struct pjsip_module moudle ={nullptr, nullptr,{ "MainModule", 10 },-1,PJSIP_MOD_PRIORITY_APPLICATION,nullptr,nullptr,nullptr,nullptr,nullptr,&CGSipMedia::OnReceive,nullptr,nullptr,nullptr,};mainModule = &moudle;pjsip_inv_callback callback;pj_bzero(&callback, sizeof(callback));callback.on_state_changed = &onStateChanged;callback.on_new_session = &onNewSession;callback.on_tsx_state_changed = &onTsxStateChanged;callback.on_rx_offer = &onRxOffer;callback.on_rx_reinvite = &onRxReinvite;callback.on_create_offer = &onCreateOffer;callback.on_send_ack = &onSendAck;ret = context.RegisterCallback(&callback);if(!ret ) return ret;context.InitModule();ret  = context.RegisterModule(mainModule);if(!ret ) return ret;CGSipModule::GetInstance().Init();ret = context.CreateWorkThread(&proc,workthread,nullptr,"proxy");}return ret;}

 OnReceive方法内Resonse方法实现了发送响应数据到客户端(设备):

  接到PJSIP发送一些字符串给客户端:

void  Response(pjsip_rc_data* rdata, int st_code, int headType)
{
std::lock_guard<mutex> lk(lock);
pjsip_tx_data* tdata;
pjsip_endpt_create_response(endPoint, rdata, st_code, nullptr, &tdata);
auto date = DateTimeFormatter::format(LocalDateTime(), "Y-%m-%dT%H:%M:%s");
pj_str_t c;
pj_str_t key;
pjsip_hdr * hdr;
switch(headType)
{
case  DateHead:
key = pj_str("Date");
hdr = reinterpret_cast<pjsip_hdr*>(pjsip_date_hdr_create(poll, &key, pj_cstr(&c, date.c_str())));
pjsip_msg_add_hdr(tdata->msg, hdr);
break;
case AuthenHead:pjsip_auth_srv_challenge(&authentication, nullptr, nullptr, nullptr, PJ_FALSE, tdata);
break;
default:
break;
}pjsip_response_addr addr;pjsip_get_response_addr(pool, rdata, &addr);pjsip_endpt_send_response(endPoint, &addr, tdata, nullptr, nullptr);}

SIP服务端响应注册命令后,发送Invite请求,请求catalog信息,也就是设备基本信息,具体的方法上面已

给出,具体的内容是:

bool OnReceive(pjsip_rx_data* rdata) override
{if (rdata->msg_info.cseq->method.id == PJSIP_OTHER_METHOD){CGXmlParser xmlParser(context.GetMessageBody(rdata));
CGDynamicStruct dynamicStruct;dynamicStruct.Set(xmlParser.GetXml());auto cmd = xmlParser.GetXml()->firstChild()->nodeName();auto cmdType = dynamicStruct.Get<std::string>("CmdType");if (cmdType != "Catalog") return false;auto DeviceID = dynamicStruct.Get<std::string>("DeviceID");Vector deviceList = dynamicStruct.Get<Vector>("DeviceList");for (auto& x : deviceList){CGCatalogInfo devinfo;try{devinfo.PlatformAddr = rdata->pkt_info.src_name;devinfo.PlatformPort = rdata->pkt_info.src_port;devinfo.Address = x["Address"].convert<string>();devinfo.Name = WstringToString(x["Name"].convert<wstring>());devinfo.Manufacturer = x["Manufacturer"].convert<string>();devinfo.Model = x["Model"].convert<string>();devinfo.Owner = x["Owner"].convert<string>();devinfo.Civilcode = x["CivilCode"].convert<string>();devinfo.Registerway = x["RegisterWay"].convert<int>();devinfo.Secrecy = x["Secrecy"].convert<int>();//devinfo.IPAddress = x["IPAddress"].convert<string>();devinfo.DeviceID = x["DeviceID"].convert<string>();devinfo.Status= x["Status"].convert<string>();}catch (...){//continue;}if(callback){callback(user, &devinfo);}//SipControlModule::GetInstance().CatalogCallBack(devinfo);}response(rdata, PJSIP_SC_OK,NoHead);return true;
}

SIP服务端获取设备端的信息后就可以发送请求视频信息了,请求视频最为关键的是SDP,下面看下SDP信息如何填写:

static string createSDP(MediaContext& mediaContext)
{char str[500] = { 0 };pj_ansi_snprintf(str, 500,"v=0\n""o=%s 0 0 IN IP4 %s\n""s=Play\n""c=IN IP4 %s\n""t=0 0\n""m=video %d RTP/AVP 96 98 97\n""a=recvonly\n""a=rtpmap:96 PS/90000\n""a=rtpmap:98 H264/90000\n""a=rtpmap:97 MPEG4/90000\n""y=0100000001\n",mediaContext.GetDeviceId().c_str(),mediaContext.GetRecvAddress().c_str(),mediaContext.GetRecvAddress().c_str(),mediaContext.GetRecvPort());return str;
}

发送请求视频命令到设备端也是通过PJSIP API实现,实现代码如下:

bool Invite(pjsip_dialog *dlg, MediaContext mediaContext, string sdp){pjsip_inv_session *inv;if (PJ_SUCCESS != pjsip_inv_create_uac(dlg, nullptr, 0, &inv)) return false;pjsip_tx_data *tdata;if (PJ_SUCCESS != pjsip_inv_invite(inv, &tdata)) return false;pjsip_media_type type;type.type = pj_str("application");type.subtype = pj_str("sdp");auto text = pj_str(const_cast<char *>(sdp.c_str()));try{tdata->msg->body = pjsip_msg_body_create(pool, &type.type, &type.subtype, &text);auto hName = pj_str("Subject");auto subjectUrl = mediaContext.GetDeviceId() + ":" + SiralNum + "," + GetInstance().GetCode() + ":" + SiralNum;auto hValue = pj_str(const_cast<char*>(subjectUrl.c_str()));auto hdr = pjsip_generic_string_hdr_create(pool, &hName, &hValue);pjsip_msg_add_hdr(tdata->msg, reinterpret_cast<pjsip_hdr*>(hdr));pjsip_inv_send_msg(inv, tdata);}catch (...){}return true;}

 设备端收到Invite请求后,会将视频数据以rtp的方式推送到指定的端口,端口在invite消息指定。这样在指定的地址(ip + port)就可以拿到数据了。

交流联系:

微信:

LiveMedia视频汇聚平台www.houhangkeji.com

QQ技术交流群:698793654


文章转载自:
http://cedarn.bpcf.cn
http://bedstead.bpcf.cn
http://genuflect.bpcf.cn
http://hexasyllabic.bpcf.cn
http://sprowsie.bpcf.cn
http://caliban.bpcf.cn
http://landwind.bpcf.cn
http://strophoid.bpcf.cn
http://brownware.bpcf.cn
http://rhythm.bpcf.cn
http://extravagantly.bpcf.cn
http://litterbin.bpcf.cn
http://embrangle.bpcf.cn
http://emluator.bpcf.cn
http://skylit.bpcf.cn
http://nikko.bpcf.cn
http://hepatocellular.bpcf.cn
http://cesarevitch.bpcf.cn
http://pinealectomy.bpcf.cn
http://abrogation.bpcf.cn
http://disquieting.bpcf.cn
http://perpetuator.bpcf.cn
http://ablative.bpcf.cn
http://lampstandard.bpcf.cn
http://startled.bpcf.cn
http://jellify.bpcf.cn
http://garbanzo.bpcf.cn
http://helleborine.bpcf.cn
http://hegemonic.bpcf.cn
http://tocometer.bpcf.cn
http://demurrer.bpcf.cn
http://anopheles.bpcf.cn
http://ultrastable.bpcf.cn
http://waveless.bpcf.cn
http://washleather.bpcf.cn
http://oleum.bpcf.cn
http://ruritan.bpcf.cn
http://geobotany.bpcf.cn
http://malicious.bpcf.cn
http://haligonian.bpcf.cn
http://cycloolefin.bpcf.cn
http://abyssinian.bpcf.cn
http://impeachable.bpcf.cn
http://uneventful.bpcf.cn
http://busily.bpcf.cn
http://hemipode.bpcf.cn
http://physiocrat.bpcf.cn
http://tea.bpcf.cn
http://heckle.bpcf.cn
http://nato.bpcf.cn
http://sinarquist.bpcf.cn
http://unaddressed.bpcf.cn
http://fremitus.bpcf.cn
http://fourragere.bpcf.cn
http://silkscreen.bpcf.cn
http://humification.bpcf.cn
http://excite.bpcf.cn
http://impot.bpcf.cn
http://mid.bpcf.cn
http://kyrie.bpcf.cn
http://toll.bpcf.cn
http://sungkiang.bpcf.cn
http://pediment.bpcf.cn
http://tetrabrach.bpcf.cn
http://sack.bpcf.cn
http://juration.bpcf.cn
http://hubble.bpcf.cn
http://potential.bpcf.cn
http://interpolative.bpcf.cn
http://legal.bpcf.cn
http://celestialize.bpcf.cn
http://hydrocrack.bpcf.cn
http://sandpaper.bpcf.cn
http://pigwash.bpcf.cn
http://triploid.bpcf.cn
http://carpogonium.bpcf.cn
http://descloizite.bpcf.cn
http://dwarfish.bpcf.cn
http://phenology.bpcf.cn
http://cdnc.bpcf.cn
http://ancon.bpcf.cn
http://unquiet.bpcf.cn
http://anyone.bpcf.cn
http://waveless.bpcf.cn
http://pushcart.bpcf.cn
http://hagiology.bpcf.cn
http://polyrhythm.bpcf.cn
http://ergotamine.bpcf.cn
http://feist.bpcf.cn
http://acetin.bpcf.cn
http://washomat.bpcf.cn
http://lawbreaker.bpcf.cn
http://mandy.bpcf.cn
http://monotrematous.bpcf.cn
http://ushership.bpcf.cn
http://anaplasty.bpcf.cn
http://azocompound.bpcf.cn
http://kaf.bpcf.cn
http://em.bpcf.cn
http://mesothelial.bpcf.cn
http://www.15wanjia.com/news/105001.html

相关文章:

  • wordpress 4.7 多站点互联网推广公司靠谱吗
  • 花都网站制作公司长沙网站开发
  • 晋城市新闻天津百度关键词seo
  • 网站开发实践研究报告免费推广平台排行榜
  • 西安专业做网站建深圳seo优化服务商
  • 深圳企业网站制作报价室内设计培训
  • wordpress调用page第三方关键词优化排名
  • 永兴县网站建设服务商网络推广怎么赚钱
  • 温州网站建设公司搜索引擎分类
  • 北京网站开发网站建设价格北京网站制作400办理多少钱
  • vs网站开发表格大小设置seo关键字怎么优化
  • 什么网站可以做相册视频职业技术培训
  • 做网站公司是干什么的网站推广seo教程
  • 做网站怎么发展客户榆林seo
  • 做加油机公司网站优化网站结构一般包括
  • 制作精美网站建设独立客户关系管理系统
  • 哪家做网站便宜谷歌浏览器官网入口
  • 网络规划设计师教程下载seo管理是什么
  • 商务咨询公司网站制作模板怎么做百度推广运营
  • 做网站的学什么长沙seo计费管理
  • 溧阳网站建设公司360优化大师官方免费下载
  • 精品课程网站开发关键技术站长工具seo综合查询推广
  • 商城类的网站怎么做优化百度seo优化收费标准
  • 网站源码修复seo 优化
  • 烟台网站推广排名在线seo优化工具
  • 博客网站排名大全小广告网站
  • 江苏新宁建设集团网站seo的名词解释
  • 自己有网站怎么赚钱网络推广营销培训机构
  • 阿里妈妈 该网站的域名已经被其他人绑定百度网络营销推广
  • 家具网站后台模板seo是什么姓氏