diff --git a/bin/libcares.so b/bin/libcares.so new file mode 100755 index 0000000..44f6e1e --- /dev/null +++ b/bin/libcares.so diff --git a/bin/libcares.so.2 b/bin/libcares.so.2 new file mode 100755 index 0000000..44f6e1e --- /dev/null +++ b/bin/libcares.so.2 diff --git a/bin/libcares.so.2.5.1 b/bin/libcares.so.2.5.1 new file mode 100755 index 0000000..44f6e1e --- /dev/null +++ b/bin/libcares.so.2.5.1 diff --git a/src/decoder/gb28181/sip/SipServer.cpp b/src/decoder/gb28181/sip/SipServer.cpp index d316ae9..835f08f 100644 --- a/src/decoder/gb28181/sip/SipServer.cpp +++ b/src/decoder/gb28181/sip/SipServer.cpp @@ -318,6 +318,14 @@ void SipServer::response_register_401unauthorized(eXosip_event_t *evtp) { } +void printDevice(std::vector vec_device) { + LOG_INFO("-----start print----"); + for (size_t i = 0; i < vec_device.size(); i++) { + LOG_INFO("{} {}", vec_device[i].id, vec_device[i].parentid); + } + LOG_INFO("-----end print----"); +} + void SipServer::response_message(eXosip_event_t *evtp) { osip_body_t* body = nullptr; @@ -329,19 +337,18 @@ void SipServer::response_message(eXosip_event_t *evtp) { parse_xml(body->body, "", false, "", false, DeviceID); } -// Client *client = getClientByDevice(DeviceID); -// if(client){ -// LOG_INFO("response_message:{} 已注册",DeviceID); -// }else{ -// LOG_ERROR("response_message:{} 未注册",DeviceID); -// } - LOG_INFO("CmdType={},DeviceID={}", CmdType, DeviceID); + // LOG_INFO("CmdType={},DeviceID={}", CmdType, DeviceID); if(!strcmp(CmdType, "Catalog")) { this->response_message_answer(evtp,200); // 需要根据对方的Catelog请求,做一些相应的应答请求 CCatalogParser catPaser; - m_vec_device = catPaser.Decode_Catlog(body->body); + std::vector vec_device = catPaser.Decode_Catlog(body->body); + printDevice(vec_device); + for (size_t i = 0; i < vec_device.size(); i++) { + DeviceInfo info = vec_device[i]; + m_device_map[info.id] = info; + } } else if(!strcmp(CmdType, "Keepalive")){ this->response_message_answer(evtp,200); @@ -351,6 +358,20 @@ void SipServer::response_message(eXosip_event_t *evtp) { } +Client* SipServer::get_parent_by_id(string id) { + auto it_info = m_device_map.find(id); + if (it_info == m_device_map.end()) { + return nullptr; + } + string parent_id = it_info->second.parentid; + auto it_client = mClientMap.find(parent_id); + if (it_client == mClientMap.end()) { + return nullptr; + } + + return mClientMap[parent_id]; +} + void SipServer::response_invite_ack(eXosip_event_t *evtp){ osip_message_t* msg = nullptr; @@ -377,8 +398,10 @@ int SipServer::RequestInvite_UDP(const char* dst_channel, int rtpPort) { return -1; } - auto it = mClientMap.begin(); - Client* client = it->second; + Client* client = get_parent_by_id(dst_channel); + if (client == nullptr) { + return -1; + } LOG_INFO("INVITE UDP"); @@ -391,31 +414,15 @@ int SipServer::RequestInvite_UDP(const char* dst_channel, int rtpPort) { sprintf(from, "sip:%s@%s:%d", mInfo.getSipId().c_str(), mInfo.getIp().c_str(), mInfo.getPort()); sprintf(to, "sip:%s@%s:%d", dst_channel, client->getIp().c_str(), client->getPort()); - // snprintf(sdp, 2048, - // "v=0\r\n" - // "o=%s 0 0 IN IP4 %s\r\n" - // "s=Play\r\n" - // "c=IN IP4 %s\r\n" - // "t=0 0\r\n" - // "m=video %d RTP/AVP 96 98 97\r\n" - // "a=recvonly\r\n" - // "a=rtpmap:96 PS/90000\r\n" - // "a=rtpmap:98 H264/90000\r\n" - // "a=rtpmap:97 MPEG4/90000\r\n" - // "a=setup:passive\r\n" - // "a=connection:new\r\n" - // "y=0100000001\r\n" - // "f=\r\n", mInfo.getSipId().c_str(), mInfo.getIp().c_str(), mInfo.getIp().c_str(), rtpPort); - - snprintf(sdp, 2048, + snprintf(sdp, 2048, "v=0\r\n" "o=%s 0 0 IN IP4 %s\r\n" "s=Play\r\n" "c=IN IP4 %s\r\n" "t=0 0\r\n" - "m=video %d RTP/AVP 98 97\r\n" + "m=video %d RTP/AVP 96 98 97\r\n" "a=recvonly\r\n" - // "a=rtpmap:96 PS/90000\r\n" + "a=rtpmap:96 PS/90000\r\n" "a=rtpmap:98 H264/90000\r\n" "a=rtpmap:97 MPEG4/90000\r\n" "a=setup:passive\r\n" @@ -450,8 +457,10 @@ int SipServer::RequestInvite_TCP_a(const char* dst_channel, int rtpPort) { return -1; } - auto it = mClientMap.begin(); - Client* client = it->second; + Client* client = get_parent_by_id(dst_channel); + if (client == nullptr) { + return -1; + } LOG_INFO("INVITE TCP active"); @@ -558,15 +567,7 @@ int SipServer::clearClientMap(){ return 0; } -Client * SipServer::GetClientByDevice(string device) { - auto it = mClientMap.find(device); - if(it == mClientMap.end()){ - return nullptr; - } - return it->second; -} - -void SipServer::DeleteClientByDevice(string device) { +void SipServer::deleteClientByDevice(string device) { auto it = mClientMap.find(device); if (it == mClientMap.end()) { return ; @@ -576,14 +577,6 @@ void SipServer::DeleteClientByDevice(string device) { mClientMap.erase(it); } -std::map SipServer::GetClientMap() { - return mClientMap; -} - -std::vector< DeviceInfo > SipServer::GetDeviceList() { - return m_vec_device; -} - 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) { const char* satrt = strstr( data, s_mark ); diff --git a/src/decoder/gb28181/sip/SipServer.h b/src/decoder/gb28181/sip/SipServer.h index a0c6a8c..72996d0 100644 --- a/src/decoder/gb28181/sip/SipServer.h +++ b/src/decoder/gb28181/sip/SipServer.h @@ -130,13 +130,6 @@ public: bool Init(ServerInfo info); - Client* GetClientByDevice(string device); - void DeleteClientByDevice(string device); - - std::vector< DeviceInfo > GetDeviceList(); - - std::map GetClientMap(); - int RequestInvite_UDP(const char* dst_channel, int rtpPort); int RequestInvite_TCP_a(const char* dst_channel, int rtpPort); @@ -163,6 +156,9 @@ private: void dump_response(eXosip_event_t *evtp); int clearClientMap(); + void deleteClientByDevice(string device); + + Client* get_parent_by_id(string id); private: bool mQuit{ false }; @@ -170,8 +166,7 @@ private: ServerInfo mInfo; std::map mClientMap;// - - std::vector< DeviceInfo > m_vec_device; + std::map m_device_map; thread* m_event_loop_thread; };