Commit ffe810454e0fdda1be1367689e3ab76aadf77425

Authored by Hu Chunming
1 parent eddac644

优化目录xml解析;优化sipserver设置方式

src/ai_platform/MultiSourceProcess.cpp
@@ -228,19 +228,8 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){ @@ -228,19 +228,8 @@ int CMultiSourceProcess::InitAlgorthim(tsl_aiplatform_param vptParam){
228 pVpcUtil->init(m_devId); 228 pVpcUtil->init(m_devId);
229 229
230 // 初始化SIP服务器 230 // 初始化SIP服务器
231 - ServerInfo info(  
232 - "SY_Sip_Server",  
233 - "12345678",  
234 - "192.168.60.179",  
235 - 15060,  
236 - "34020000002000000002",  
237 - "3402000000",  
238 - "sy123456",  
239 - 1800,  
240 - 3600);  
241 -  
242 SipServer* pSipServer = SipServer::getInstance(); 231 SipServer* pSipServer = SipServer::getInstance();
243 - pSipServer->Init(info); 232 + pSipServer->Init(nullptr);
244 233
245 m_pAlgorthimThread = new thread([](void* arg) { 234 m_pAlgorthimThread = new thread([](void* arg) {
246 CMultiSourceProcess* process = (CMultiSourceProcess*)arg ; 235 CMultiSourceProcess* process = (CMultiSourceProcess*)arg ;
src/decoder/gb28181/sip/Message/CatalogParser.cpp
@@ -557,7 +557,7 @@ std::vector< DeviceInfo > CCatalogParser::Decode( const std::vector< tinyxml2::X @@ -557,7 +557,7 @@ std::vector< DeviceInfo > CCatalogParser::Decode( const std::vector< tinyxml2::X
557 return m_devices; 557 return m_devices;
558 } 558 }
559 559
560 -std::vector< DeviceInfo > CCatalogParser::Decode_Catlog(const char* body) 560 +std::vector< DeviceInfo > CCatalogParser::DecodeCatlog(const char* body)
561 { 561 {
562 std::vector< DeviceInfo > cat_list; 562 std::vector< DeviceInfo > cat_list;
563 if (body == NULL) 563 if (body == NULL)
@@ -604,14 +604,12 @@ std::vector&lt; DeviceInfo &gt; CCatalogParser::Decode_Catlog(const char* body) @@ -604,14 +604,12 @@ std::vector&lt; DeviceInfo &gt; CCatalogParser::Decode_Catlog(const char* body)
604 } 604 }
605 605
606 std::string sn = pSN->Value(); 606 std::string sn = pSN->Value();
607 - if (sn.empty())  
608 - { 607 + if (sn.empty()) {
609 return cat_list; 608 return cat_list;
610 } 609 }
611 610
612 std::string deviceid = pDeviceID->Value(); 611 std::string deviceid = pDeviceID->Value();
613 - if (deviceid.empty())  
614 - { 612 + if (deviceid.empty()) {
615 return cat_list; 613 return cat_list;
616 } 614 }
617 615
@@ -622,9 +620,95 @@ std::vector&lt; DeviceInfo &gt; CCatalogParser::Decode_Catlog(const char* body) @@ -622,9 +620,95 @@ std::vector&lt; DeviceInfo &gt; CCatalogParser::Decode_Catlog(const char* body)
622 cat_list = Decode(nodes); 620 cat_list = Decode(nodes);
623 if (cat_list.empty()) 621 if (cat_list.empty())
624 { 622 {
625 - LOG_ERROR("消息体解析错误!"); 623 + LOG_WARN("消息体未解析出设备!");
  624 + } else {
  625 + // 设置
  626 + for (size_t i = 0; i < cat_list.size(); i++) {
  627 + cat_list[i].parentid = deviceid;
  628 + }
626 } 629 }
627 } 630 }
628 631
629 return cat_list; 632 return cat_list;
  633 +}
  634 +
  635 +string CCatalogParser::getItemValue(tinyxml2::XMLNode *pItem) {
  636 +
  637 + tinyxml2::XMLNode *pValue = pItem->FirstChild();
  638 + if( pValue == NULL ) {
  639 + LOG_DEBUG( "参数值没有设置" );
  640 + return "";
  641 + }
  642 +
  643 + const char *value = pValue->Value();
  644 + if( value == NULL ) {
  645 + LOG_DEBUG( "参数值为空" );
  646 + return "";
  647 + }
  648 +
  649 + return value;
  650 +}
  651 +
  652 +ServerInfo CCatalogParser::DecodeServerConfig(const char* body)
  653 +{
  654 + ServerInfo info;
  655 + if (body == NULL) {
  656 + return info;
  657 + }
  658 +
  659 + tinyxml2::XMLDocument doc;
  660 + doc.Parse(body);
  661 + tinyxml2::XMLElement* pRoot = doc.RootElement();
  662 + if (pRoot == NULL) {
  663 + return info;
  664 + }
  665 +
  666 + for (tinyxml2::XMLNode* pNode = pRoot->FirstChild(); pNode != 0; pNode = pNode->NextSibling())
  667 + {
  668 + std::string type = pNode->Value();
  669 + if (CGBMessage::CompareNoCase( type, "Ua" ))
  670 + {
  671 + info.setUa(getItemValue(pNode));
  672 + }
  673 + else if (CGBMessage::CompareNoCase( type, "Nonce" ))
  674 + {
  675 + info.setNonce(getItemValue(pNode));
  676 + }
  677 + else if (CGBMessage::CompareNoCase( type, "Ip" ))
  678 + {
  679 + info.setIp(getItemValue(pNode));
  680 + }
  681 + else if (CGBMessage::CompareNoCase( type, "Port" ))
  682 + {
  683 + string str = getItemValue(pNode);
  684 + int i = atoi(str.c_str());
  685 + info.setPort(i);
  686 + }
  687 + else if (CGBMessage::CompareNoCase( type, "SipId" ))
  688 + {
  689 + info.setSipId(getItemValue(pNode));
  690 + }
  691 + else if (CGBMessage::CompareNoCase( type, "SipRealm" ))
  692 + {
  693 + info.setSipRealm(getItemValue(pNode));
  694 + }
  695 + else if (CGBMessage::CompareNoCase( type, "Password" ))
  696 + {
  697 + info.setSipPass(getItemValue(pNode));
  698 + }
  699 + else if (CGBMessage::CompareNoCase( type, "Timeout" ))
  700 + {
  701 + string str = getItemValue(pNode);
  702 + int i = atoi(str.c_str());
  703 + info.setTimeout(i);
  704 + }
  705 + else if (CGBMessage::CompareNoCase( type, "Expiry" ))
  706 + {
  707 + string str = getItemValue(pNode);
  708 + int i = atoi(str.c_str());
  709 + info.setExpiry(i);
  710 + }
  711 + }
  712 +
  713 + return info;
630 } 714 }
631 \ No newline at end of file 715 \ No newline at end of file
src/decoder/gb28181/sip/Message/CatalogParser.h
@@ -4,56 +4,8 @@ @@ -4,56 +4,8 @@
4 #include "GBMessage.h" 4 #include "GBMessage.h"
5 #include <vector> 5 #include <vector>
6 6
7 -enum EEventType  
8 -{  
9 - EVENT_ON = 0, // 上线  
10 - EVENT_OFF, // 离线  
11 - EVENT_VLOST, // 视频丢失  
12 - EVENT_DEFECT, // 故障  
13 - EVENT_ADD, // 增加  
14 - EVENT_DEL, // 删除  
15 - EVENT_UPDATE, // 更新  
16 -  
17 - EVENT_UNKNOW,  
18 -};  
19 -  
20 -struct DeviceInfo  
21 -{  
22 - EEventType event;  
23 - std::string id;  
24 - std::string name;  
25 - std::string manufacturer;  
26 - std::string model;  
27 - std::string owner;  
28 - std::string civil;  
29 - std::string block;  
30 - std::string address;  
31 - std::string safetyway;  
32 - std::string registerway;  
33 - std::string certnum;  
34 - std::string certifiable;  
35 - std::string errcode;  
36 - std::string secrecy;  
37 - std::string parental;  
38 - std::string parentid;  
39 - std::string endtime;  
40 - std::string ip;  
41 - std::string port;  
42 - std::string password;  
43 - std::string status;  
44 - std::string longitude;  
45 - std::string latitude;  
46 - std::string ptz;  
47 - std::string position;  
48 - std::string room;  
49 - std::string use;  
50 - std::string supplylight;  
51 - std::string direction;  
52 - std::string resolution;  
53 - std::string businessgroup;  
54 -}; 7 +#include "../sip_header.h"
55 8
56 -//////////////////////////////////////////////////////////////////////////  
57 class CCatalogParser : public CGBMessage 9 class CCatalogParser : public CGBMessage
58 { 10 {
59 public: 11 public:
@@ -64,7 +16,9 @@ public: @@ -64,7 +16,9 @@ public:
64 public: 16 public:
65 bool Encode( std::string &message ); 17 bool Encode( std::string &message );
66 18
67 - std::vector< DeviceInfo > Decode_Catlog(const char* body); 19 + std::vector<DeviceInfo> DecodeCatlog(const char* body);
  20 +
  21 + ServerInfo DecodeServerConfig(const char* body);
68 22
69 static std::string GetStrName(EEventType eType) 23 static std::string GetStrName(EEventType eType)
70 { 24 {
@@ -226,6 +180,7 @@ public: @@ -226,6 +180,7 @@ public:
226 180
227 private: 181 private:
228 std::vector< DeviceInfo > Decode(const std::vector< tinyxml2::XMLNode* >& nodes); 182 std::vector< DeviceInfo > Decode(const std::vector< tinyxml2::XMLNode* >& nodes);
  183 + string getItemValue(tinyxml2::XMLNode *pItem);
229 184
230 private: 185 private:
231 std::string m_sn; 186 std::string m_sn;
src/decoder/gb28181/sip/SipServer.cpp
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 18
19 #include <sstream> 19 #include <sstream>
20 #include <algorithm> 20 #include <algorithm>
  21 +#include <fstream>
21 22
22 using namespace std; 23 using namespace std;
23 24
@@ -92,8 +93,29 @@ SipServer::~SipServer() { @@ -92,8 +93,29 @@ SipServer::~SipServer() {
92 #endif // WIN32 93 #endif // WIN32
93 } 94 }
94 95
95 -bool SipServer::Init(ServerInfo info) {  
96 - mInfo = info; 96 +bool SipServer::Init(ServerInfo* pInfo) {
  97 +
  98 + if (pInfo == nullptr) {
  99 + std::ifstream cfgFile("./sip_server_cfg.xml");
  100 + if(cfgFile.is_open()) {
  101 + string strConfig;
  102 + string str;
  103 + int char_count = 0;
  104 + while(cfgFile >> str)
  105 + {
  106 + strConfig += str;
  107 + }
  108 + CCatalogParser catPaser;
  109 + mInfo = catPaser.DecodeServerConfig(strConfig.c_str());
  110 + } else {
  111 + LOG_ERROR("read sip server config file failed!");
  112 + return false;
  113 + }
  114 + cfgFile.close();
  115 + } else {
  116 + mInfo = *pInfo;
  117 + }
  118 +
97 LOG_INFO("{}:{}", mInfo.getIp(), mInfo.getPort()); 119 LOG_INFO("{}:{}", mInfo.getIp(), mInfo.getPort());
98 120
99 m_event_loop_thread = new std::thread(event_loop_thread, this); 121 m_event_loop_thread = new std::thread(event_loop_thread, this);
@@ -121,7 +143,7 @@ int SipServer::sip_event_handle(eXosip_event_t *evtp) { @@ -121,7 +143,7 @@ int SipServer::sip_event_handle(eXosip_event_t *evtp) {
121 this->dump_request(evtp); 143 this->dump_request(evtp);
122 this->dump_response(evtp); 144 this->dump_response(evtp);
123 145
124 - this->clearClientMap(); 146 + // this->clearClientMap();
125 break; 147 break;
126 case EXOSIP_MESSAGE_NEW://23 148 case EXOSIP_MESSAGE_NEW://23
127 // LOG_INFO("EXOSIP_MESSAGE_NEW type={}",evtp->type); 149 // LOG_INFO("EXOSIP_MESSAGE_NEW type={}",evtp->type);
@@ -204,6 +226,7 @@ void SipServer::event_loop() { @@ -204,6 +226,7 @@ void SipServer::event_loop() {
204 if(this->init_sip_server() !=0 ){ 226 if(this->init_sip_server() !=0 ){
205 return; 227 return;
206 } 228 }
  229 +
207 while(!mQuit) { 230 while(!mQuit) {
208 eXosip_event_t *evtp = eXosip_event_wait(mSipCtx, 0, 20); 231 eXosip_event_t *evtp = eXosip_event_wait(mSipCtx, 0, 20);
209 if (!evtp){ 232 if (!evtp){
@@ -383,7 +406,7 @@ void SipServer::response_message(eXosip_event_t *evtp) { @@ -383,7 +406,7 @@ void SipServer::response_message(eXosip_event_t *evtp) {
383 this->response_message_answer(evtp,200); 406 this->response_message_answer(evtp,200);
384 // 需要根据对方的Catelog请求,做一些相应的应答请求 407 // 需要根据对方的Catelog请求,做一些相应的应答请求
385 CCatalogParser catPaser; 408 CCatalogParser catPaser;
386 - std::vector<DeviceInfo> vec_device = catPaser.Decode_Catlog(body->body); 409 + std::vector<DeviceInfo> vec_device = catPaser.DecodeCatlog(body->body);
387 printDevice(vec_device); 410 printDevice(vec_device);
388 411
389 std::lock_guard<std::mutex> l(m_device_map_mtx); 412 std::lock_guard<std::mutex> l(m_device_map_mtx);
src/decoder/gb28181/sip/SipServer.h
1 -//  
2 -// Created bxc on 2022/11/25.  
3 -//  
4 -  
5 -#ifndef BXC_SIPSERVER_SIPSERVER_H  
6 -#define BXC_SIPSERVER_SIPSERVER_H 1 +#ifndef __SIPSERVER_H__
  2 +#define __SIPSERVER_H__
7 3
8 extern "C" { 4 extern "C" {
9 #include <osip2/osip_mt.h> 5 #include <osip2/osip_mt.h>
@@ -17,62 +13,10 @@ extern &quot;C&quot; { @@ -17,62 +13,10 @@ extern &quot;C&quot; {
17 #include <mutex> 13 #include <mutex>
18 14
19 #include "./Message/CatalogParser.h" 15 #include "./Message/CatalogParser.h"
  16 +#include "sip_header.h"
20 17
21 using namespace std; 18 using namespace std;
22 19
23 -class ServerInfo {  
24 -public:  
25 - ServerInfo() {}  
26 -  
27 - ServerInfo(string ua,string nonce, string ip, int port,  
28 - string sipId, string sipRealm, string sipPass, int sipTimeout, int sipExpiry):  
29 - mUa(ua),  
30 - mNonce(nonce),mIp(ip),mPort(port),mSipId(sipId),  
31 - mSipRealm(sipRealm),mSipPass(sipPass),mSipTimeout(sipTimeout),  
32 - mSipExpiry(sipExpiry){}  
33 -  
34 - ~ServerInfo() = default;  
35 -public:  
36 - string getUa() const{  
37 - return mUa;  
38 - }  
39 - string getNonce() const{  
40 - return mNonce;  
41 - }  
42 - string getIp() const{  
43 - return mIp;  
44 - }  
45 - int getPort() const {  
46 - return mPort;  
47 - }  
48 - string getSipId() const{  
49 - return mSipId;  
50 - }  
51 - string getSipRealm() const{  
52 - return mSipRealm;  
53 - }  
54 - string getSipPass() const{  
55 - return mSipPass;  
56 - }  
57 - int getTimeout() const {  
58 - return mSipTimeout;  
59 - }  
60 - int getExpiry() const {  
61 - return mSipExpiry;  
62 - }  
63 -  
64 -private:  
65 - string mUa;  
66 - string mNonce;//SIP服务随机数值  
67 - string mIp;//SIP服务IP  
68 - int mPort;//SIP服务端口  
69 - string mSipId; //SIP服务器ID  
70 - string mSipRealm;//SIP服务器域  
71 - string mSipPass;//SIP password  
72 - int mSipTimeout; //SIP timeout  
73 - int mSipExpiry;// SIP到期  
74 -};  
75 -  
76 class Client { 20 class Client {
77 public: 21 public:
78 Client(string ip, int port, string device) : 22 Client(string ip, int port, string device) :
@@ -135,7 +79,7 @@ public: @@ -135,7 +79,7 @@ public:
135 SipServer(); 79 SipServer();
136 ~SipServer(); 80 ~SipServer();
137 81
138 - bool Init(ServerInfo info); 82 + bool Init(ServerInfo* pInfo);
139 83
140 int RequestInvite_UDP(const char* dst_channel, int rtpPort); 84 int RequestInvite_UDP(const char* dst_channel, int rtpPort);
141 85
@@ -184,4 +128,4 @@ private: @@ -184,4 +128,4 @@ private:
184 }; 128 };
185 129
186 130
187 -#endif //BXC_SIPSERVER_SIPSERVER_H 131 +#endif //__SIPSERVER_H__
src/decoder/gb28181/sip/sip_header.h 0 → 100644
  1 +#ifndef __SIP_HEADER_H__
  2 +#define __SIP_HEADER_H__
  3 +
  4 +#include <string>
  5 +
  6 +using namespace std;
  7 +
  8 +enum EEventType
  9 +{
  10 + EVENT_ON = 0, // ����
  11 + EVENT_OFF, // ����
  12 + EVENT_VLOST, // ��Ƶ��ʧ
  13 + EVENT_DEFECT, // ����
  14 + EVENT_ADD, // ����
  15 + EVENT_DEL, // ɾ��
  16 + EVENT_UPDATE, // ����
  17 +
  18 + EVENT_UNKNOW,
  19 +};
  20 +
  21 +struct DeviceInfo
  22 +{
  23 + EEventType event;
  24 + std::string id;
  25 + std::string name;
  26 + std::string manufacturer;
  27 + std::string model;
  28 + std::string owner;
  29 + std::string civil;
  30 + std::string block;
  31 + std::string address;
  32 + std::string safetyway;
  33 + std::string registerway;
  34 + std::string certnum;
  35 + std::string certifiable;
  36 + std::string errcode;
  37 + std::string secrecy;
  38 + std::string parental;
  39 + std::string parentid;
  40 + std::string endtime;
  41 + std::string ip;
  42 + std::string port;
  43 + std::string password;
  44 + std::string status;
  45 + std::string longitude;
  46 + std::string latitude;
  47 + std::string ptz;
  48 + std::string position;
  49 + std::string room;
  50 + std::string use;
  51 + std::string supplylight;
  52 + std::string direction;
  53 + std::string resolution;
  54 + std::string businessgroup;
  55 +};
  56 +
  57 +class ServerInfo {
  58 +public:
  59 + ServerInfo() {}
  60 +
  61 + ServerInfo(string ua,string nonce, string ip, int port,
  62 + string sipId, string sipRealm, string sipPass, int sipTimeout, int sipExpiry):
  63 + mUa(ua),
  64 + mNonce(nonce),mIp(ip),mPort(port),mSipId(sipId),
  65 + mSipRealm(sipRealm),mSipPass(sipPass),mSipTimeout(sipTimeout),
  66 + mSipExpiry(sipExpiry){}
  67 +
  68 + ~ServerInfo() = default;
  69 +public:
  70 + string getUa() const{
  71 + return mUa;
  72 + }
  73 + void setUa(string ua) {
  74 + mUa = ua;
  75 + }
  76 + string getNonce() const{
  77 + return mNonce;
  78 + }
  79 + void setNonce(string nonce) {
  80 + mNonce = nonce;
  81 + }
  82 + string getIp() const{
  83 + return mIp;
  84 + }
  85 + void setIp(string s) {
  86 + mIp = s;
  87 + }
  88 + int getPort() const {
  89 + return mPort;
  90 + }
  91 + void setPort(int i) {
  92 + mPort = i;
  93 + }
  94 +
  95 + string getSipId() const{
  96 + return mSipId;
  97 + }
  98 + void setSipId(string s) {
  99 + mSipId = s;
  100 + }
  101 + string getSipRealm() const{
  102 + return mSipRealm;
  103 + }
  104 + void setSipRealm(string s) {
  105 + mSipRealm = s;
  106 + }
  107 + string getSipPass() const{
  108 + return mSipPass;
  109 + }
  110 + void setSipPass(string s) {
  111 + mSipPass = s;
  112 + }
  113 + int getTimeout() const {
  114 + return mSipTimeout;
  115 + }
  116 + void setTimeout(int i) {
  117 + mSipTimeout = i;
  118 + }
  119 + int getExpiry() const {
  120 + return mSipExpiry;
  121 + }
  122 + void setExpiry(int i) {
  123 + mSipExpiry = i;
  124 + }
  125 +
  126 +private:
  127 + string mUa;
  128 + string mNonce;//SIP服务随机数值
  129 + string mIp;//SIP服务IP
  130 + int mPort{0};//SIP服务端口
  131 + string mSipId; //SIP服务器ID
  132 + string mSipRealm;//SIP服务器域
  133 + string mSipPass;//SIP password
  134 + int mSipTimeout; //SIP timeout
  135 + int mSipExpiry;// SIP到期
  136 +};
  137 +
  138 +
  139 +#endif //__SIP_HEADER_H__
0 \ No newline at end of file 140 \ No newline at end of file