Commit 0af3b245b7aa28aa80125ee4588398636ecb9041

Authored by Hu Chunming
1 parent 5b86d771

添加多nvr和多摄像头管理

bin/libcares.so 0 → 100755
No preview for this file type
bin/libcares.so.2 0 → 100755
No preview for this file type
bin/libcares.so.2.5.1 0 → 100755
No preview for this file type
src/decoder/gb28181/sip/SipServer.cpp
... ... @@ -318,6 +318,14 @@ void SipServer::response_register_401unauthorized(eXosip_event_t *evtp) {
318 318  
319 319 }
320 320  
  321 +void printDevice(std::vector<DeviceInfo> vec_device) {
  322 + LOG_INFO("-----start print----");
  323 + for (size_t i = 0; i < vec_device.size(); i++) {
  324 + LOG_INFO("{} {}", vec_device[i].id, vec_device[i].parentid);
  325 + }
  326 + LOG_INFO("-----end print----");
  327 +}
  328 +
321 329 void SipServer::response_message(eXosip_event_t *evtp) {
322 330  
323 331 osip_body_t* body = nullptr;
... ... @@ -329,19 +337,18 @@ void SipServer::response_message(eXosip_event_t *evtp) {
329 337 parse_xml(body->body, "<DeviceID>", false, "</DeviceID>", false, DeviceID);
330 338 }
331 339  
332   -// Client *client = getClientByDevice(DeviceID);
333   -// if(client){
334   -// LOG_INFO("response_message:{} 已注册",DeviceID);
335   -// }else{
336   -// LOG_ERROR("response_message:{} 未注册",DeviceID);
337   -// }
338   - LOG_INFO("CmdType={},DeviceID={}", CmdType, DeviceID);
  340 + // LOG_INFO("CmdType={},DeviceID={}", CmdType, DeviceID);
339 341  
340 342 if(!strcmp(CmdType, "Catalog")) {
341 343 this->response_message_answer(evtp,200);
342 344 // 需要根据对方的Catelog请求,做一些相应的应答请求
343 345 CCatalogParser catPaser;
344   - m_vec_device = catPaser.Decode_Catlog(body->body);
  346 + std::vector<DeviceInfo> vec_device = catPaser.Decode_Catlog(body->body);
  347 + printDevice(vec_device);
  348 + for (size_t i = 0; i < vec_device.size(); i++) {
  349 + DeviceInfo info = vec_device[i];
  350 + m_device_map[info.id] = info;
  351 + }
345 352 }
346 353 else if(!strcmp(CmdType, "Keepalive")){
347 354 this->response_message_answer(evtp,200);
... ... @@ -351,6 +358,20 @@ void SipServer::response_message(eXosip_event_t *evtp) {
351 358  
352 359 }
353 360  
  361 +Client* SipServer::get_parent_by_id(string id) {
  362 + auto it_info = m_device_map.find(id);
  363 + if (it_info == m_device_map.end()) {
  364 + return nullptr;
  365 + }
  366 + string parent_id = it_info->second.parentid;
  367 + auto it_client = mClientMap.find(parent_id);
  368 + if (it_client == mClientMap.end()) {
  369 + return nullptr;
  370 + }
  371 +
  372 + return mClientMap[parent_id];
  373 +}
  374 +
354 375 void SipServer::response_invite_ack(eXosip_event_t *evtp){
355 376  
356 377 osip_message_t* msg = nullptr;
... ... @@ -377,8 +398,10 @@ int SipServer::RequestInvite_UDP(const char* dst_channel, int rtpPort) {
377 398 return -1;
378 399 }
379 400  
380   - auto it = mClientMap.begin();
381   - Client* client = it->second;
  401 + Client* client = get_parent_by_id(dst_channel);
  402 + if (client == nullptr) {
  403 + return -1;
  404 + }
382 405  
383 406 LOG_INFO("INVITE UDP");
384 407  
... ... @@ -391,31 +414,15 @@ int SipServer::RequestInvite_UDP(const char* dst_channel, int rtpPort) {
391 414  
392 415 sprintf(from, "sip:%s@%s:%d", mInfo.getSipId().c_str(), mInfo.getIp().c_str(), mInfo.getPort());
393 416 sprintf(to, "sip:%s@%s:%d", dst_channel, client->getIp().c_str(), client->getPort());
394   - // snprintf(sdp, 2048,
395   - // "v=0\r\n"
396   - // "o=%s 0 0 IN IP4 %s\r\n"
397   - // "s=Play\r\n"
398   - // "c=IN IP4 %s\r\n"
399   - // "t=0 0\r\n"
400   - // "m=video %d RTP/AVP 96 98 97\r\n"
401   - // "a=recvonly\r\n"
402   - // "a=rtpmap:96 PS/90000\r\n"
403   - // "a=rtpmap:98 H264/90000\r\n"
404   - // "a=rtpmap:97 MPEG4/90000\r\n"
405   - // "a=setup:passive\r\n"
406   - // "a=connection:new\r\n"
407   - // "y=0100000001\r\n"
408   - // "f=\r\n", mInfo.getSipId().c_str(), mInfo.getIp().c_str(), mInfo.getIp().c_str(), rtpPort);
409   -
410   - snprintf(sdp, 2048,
  417 + snprintf(sdp, 2048,
411 418 "v=0\r\n"
412 419 "o=%s 0 0 IN IP4 %s\r\n"
413 420 "s=Play\r\n"
414 421 "c=IN IP4 %s\r\n"
415 422 "t=0 0\r\n"
416   - "m=video %d RTP/AVP 98 97\r\n"
  423 + "m=video %d RTP/AVP 96 98 97\r\n"
417 424 "a=recvonly\r\n"
418   - // "a=rtpmap:96 PS/90000\r\n"
  425 + "a=rtpmap:96 PS/90000\r\n"
419 426 "a=rtpmap:98 H264/90000\r\n"
420 427 "a=rtpmap:97 MPEG4/90000\r\n"
421 428 "a=setup:passive\r\n"
... ... @@ -450,8 +457,10 @@ int SipServer::RequestInvite_TCP_a(const char* dst_channel, int rtpPort) {
450 457 return -1;
451 458 }
452 459  
453   - auto it = mClientMap.begin();
454   - Client* client = it->second;
  460 + Client* client = get_parent_by_id(dst_channel);
  461 + if (client == nullptr) {
  462 + return -1;
  463 + }
455 464  
456 465 LOG_INFO("INVITE TCP active");
457 466  
... ... @@ -558,15 +567,7 @@ int SipServer::clearClientMap(){
558 567 return 0;
559 568 }
560 569  
561   -Client * SipServer::GetClientByDevice(string device) {
562   - auto it = mClientMap.find(device);
563   - if(it == mClientMap.end()){
564   - return nullptr;
565   - }
566   - return it->second;
567   -}
568   -
569   -void SipServer::DeleteClientByDevice(string device) {
  570 +void SipServer::deleteClientByDevice(string device) {
570 571 auto it = mClientMap.find(device);
571 572 if (it == mClientMap.end()) {
572 573 return ;
... ... @@ -576,14 +577,6 @@ void SipServer::DeleteClientByDevice(string device) {
576 577 mClientMap.erase(it);
577 578 }
578 579  
579   -std::map<std::string, Client*> SipServer::GetClientMap() {
580   - return mClientMap;
581   -}
582   -
583   -std::vector< DeviceInfo > SipServer::GetDeviceList() {
584   - return m_vec_device;
585   -}
586   -
587 580 int SipServer::parse_xml(const char *data, const char *s_mark, bool with_s_make, const char *e_mark, bool with_e_make, char *dest) {
588 581 const char* satrt = strstr( data, s_mark );
589 582  
... ...
src/decoder/gb28181/sip/SipServer.h
... ... @@ -130,13 +130,6 @@ public:
130 130  
131 131 bool Init(ServerInfo info);
132 132  
133   - Client* GetClientByDevice(string device);
134   - void DeleteClientByDevice(string device);
135   -
136   - std::vector< DeviceInfo > GetDeviceList();
137   -
138   - std::map<std::string, Client*> GetClientMap();
139   -
140 133 int RequestInvite_UDP(const char* dst_channel, int rtpPort);
141 134  
142 135 int RequestInvite_TCP_a(const char* dst_channel, int rtpPort);
... ... @@ -163,6 +156,9 @@ private:
163 156 void dump_response(eXosip_event_t *evtp);
164 157  
165 158 int clearClientMap();
  159 + void deleteClientByDevice(string device);
  160 +
  161 + Client* get_parent_by_id(string id);
166 162  
167 163 private:
168 164 bool mQuit{ false };
... ... @@ -170,8 +166,7 @@ private:
170 166 ServerInfo mInfo;
171 167  
172 168 std::map<std::string, Client *> mClientMap;// <DeviceID,SipClient>
173   -
174   - std::vector< DeviceInfo > m_vec_device;
  169 + std::map<std::string, DeviceInfo> m_device_map;
175 170  
176 171 thread* m_event_loop_thread;
177 172 };
... ...