1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

fix cascade SIP bye failed

This commit is contained in:
kyxlx550 2020-04-19 00:18:30 +08:00
parent fb23739113
commit 167711400a
3 changed files with 86 additions and 13 deletions

View file

@ -472,7 +472,8 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
return err;
}
srs_assert(sip_session);
sip_session->set_request(req);
send_status(req, from, fromlen);
sip_session->set_register_status(SrsGb28181SipSessionRegisterOk);
sip_session->set_register_time(srs_get_system_time());
@ -481,6 +482,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
sip_session->set_sockaddr_len(fromlen);
sip_session->set_peer_ip(peer_ip);
sip_session->set_peer_port(peer_port);
}else if (req->is_message()) {
SrsGb28181SipSession* sip_session = fetch(session_id);
if (!sip_session || sip_session->register_status() == SrsGb28181SipSessionUnkonw){
@ -535,8 +537,15 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
device->req_inivate.copy(req);
device->invite_time = srs_get_system_time();
}
}else if (req->status == "100") {
//send_ack(req, from, fromlen);
SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
if (device){
device->req_inivate.copy(req);
device->invite_status = SrsGb28181SipSessionTrying;
device->invite_time = srs_get_system_time();
}
}else{
send_ack(req, from, fromlen);
SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
if (device){
device->req_inivate.copy(req);
@ -569,7 +578,13 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
srs_trace("gb28181: BYE %s client status=%s", req->sip_auth_id.c_str(), req->status.c_str());
if (req->status == "200") {
srs_trace("gb28181: BYE response %s client status=%s", req->sip_auth_id.c_str(), req->status.c_str());
SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
if (device){
device->invite_status = SrsGb28181SipSessionBye;
device->invite_time = srs_get_system_time();
}
}else {
//TODO:fixme
SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
if (device){
device->invite_status = SrsGb28181SipSessionBye;
@ -661,6 +676,10 @@ srs_error_t SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, i
req->serial = config->sip_serial;
req->chid = chid;
SrsSipRequest register_req = sip_session->request();
req->to_realm = register_req.to_realm;
req->from_realm = config->sip_realm;
std::stringstream ss;
sip->req_invite(ss, req, ip, port, ssrc);
@ -711,7 +730,11 @@ srs_error_t SrsGb28181SipService::send_bye(SrsSipRequest *req, std::string chid)
req->realm = config->sip_realm;
req->serial = config->sip_serial;
req->chid = chid;
SrsSipRequest register_req = sip_session->request();
req->to_realm = register_req.to_realm;
req->from_realm = config->sip_realm;
//get protocol stack
std::stringstream ss;
sip->req_bye(ss, req);

View file

@ -158,6 +158,9 @@ SrsSipRequest::SrsSipRequest()
peer_port = 0;
chid = "";
from_realm = "";
to_realm = "";
}
SrsSipRequest::~SrsSipRequest()
@ -247,6 +250,9 @@ void SrsSipRequest::copy(SrsSipRequest* src)
xml_body_map = src->xml_body_map;
device_list_map = src->device_list_map;
from_realm = src->from_realm;
to_realm = src->to_realm;
}
SrsSipStack::SrsSipStack()
@ -490,6 +496,11 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
if (srs_string_contains(content, "tag")) {
req->from_tag = srs_sip_get_param(content.c_str(), "tag");
}
std::vector<std::string> vec = srs_string_split(req->from, "@");
if (vec.size() > 1){
req->from_realm = vec.at(1);
}
}
else if (!strcasecmp(phead, "to:")) {
content = srs_string_replace(content, "sip:", "");
@ -497,6 +508,11 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
if (srs_string_contains(content, "tag")) {
req->to_tag = srs_sip_get_param(content.c_str(), "tag");
}
std::vector<std::string> vec = srs_string_split(req->to, "@");
if (vec.size() > 1){
req->to_realm = vec.at(1);
}
}
else if (!strcasecmp(phead, "via:")) {
req->via = content;
@ -579,7 +595,12 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
//map key:devicd_id value:status
for(int i=0 ; i<vec_device_id.size(); i++){
req->device_list_map[vec_device_id.at(i)] = vec_device_status.at(i);
std::string status = "";
if (vec_device_id.size() > i) {
status = vec_device_status.at(i);
}
req->device_list_map[vec_device_id.at(i)] = status;
}
}else{
//TODO: fixme
@ -651,7 +672,7 @@ std::string SrsSipStack::get_sip_via(SrsSipRequest const *req)
std::vector<std::string> vec_ip_port = srs_string_split(ip_port, ":");
std::string ip = vec_ip_port.empty() ? "" : vec_ip_port.at(0);
std::string port = vec_ip_port.size() > 0 ? vec_ip_port.at(1) : "";
std::string port = vec_ip_port.size() > 1 ? vec_ip_port.at(1) : "";
std::string branch, rport, received;
if (req->branch.empty()){
@ -660,6 +681,14 @@ std::string SrsSipStack::get_sip_via(SrsSipRequest const *req)
branch = ";branch=" + req->branch;
}
if (!req->peer_ip.empty()){
ip = req->peer_ip;
std::stringstream ss;
ss << req->peer_port;
port = ss.str();
}
received = ";received=" + ip;
rport = ";rport=" + port;
@ -850,7 +879,7 @@ void SrsSipStack::req_invite(stringstream& ss, SrsSipRequest *req, string ip, in
std::stringstream sdp;
sdp << "v=0" << SRS_RTSP_CRLF
<< "o=" << req->chid << " 0 0 IN IP4 " << ip << SRS_RTSP_CRLF
<< "o=" << req->serial << " 0 0 IN IP4 " << ip << SRS_RTSP_CRLF
<< "s=Play" << SRS_RTSP_CRLF
<< "c=IN IP4 " << ip << SRS_RTSP_CRLF
<< "t=0 0" << SRS_RTSP_CRLF
@ -871,14 +900,23 @@ void SrsSipStack::req_invite(stringstream& ss, SrsSipRequest *req, string ip, in
int rand = srs_sip_random(1000, 9999);
std::stringstream from, to, uri, branch, from_tag, call_id;
//"INVITE sip:34020000001320000001@3402000000 SIP/2.0\r\n
uri << "sip:" << req->chid << "@" << req->realm;
uri << "sip:" << req->chid << "@" << req->realm;
//From: <sip:34020000002000000001@%s:%s>;tag=500485%d\r\n
from << req->serial << "@" << req->host << ":" << req->host_port;
from << req->serial << "@" << req->realm;
to << req->chid << "@" << req->realm;
call_id << "2020" << rand ;
req->from = from.str();
req->to = to.str();
req->to = to.str();
if (!req->to_realm.empty()){
req->to = req->chid + "@" + req->to_realm;
}
if (!req->from_realm.empty()){
req->from = req->serial + "@" + req->from_realm;
}
req->uri = uri.str();
req->call_id = call_id.str();
@ -948,8 +986,8 @@ void SrsSipStack::req_ack(std::stringstream& ss, SrsSipRequest *req){
ss << "ACK " << "sip:" << req->chid << "@" << req->realm << " "<< SRS_SIP_VERSION << SRS_RTSP_CRLF
<< "Via: " << SRS_SIP_VERSION << "/UDP " << req->host << ":" << req->host_port << ";rport;branch=" << req->branch << SRS_RTSP_CRLF
<< "From: <sip:" << req->serial << "@" << req->host + ":" << req->host_port << ">;tag=" << req->from_tag << SRS_RTSP_CRLF
<< "To: <sip:"<< req->chid << "@" << req->realm << ">\r\n"
<< "From: " << get_sip_from(req) << SRS_RTSP_CRLF
<< "To: "<< get_sip_to(req) << SRS_RTSP_CRLF
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
<< "CSeq: " << req->seq << " ACK"<< SRS_RTSP_CRLF
<< "Max-Forwards: 70" << SRS_RTSP_CRLF
@ -989,7 +1027,16 @@ void SrsSipStack::req_bye(std::stringstream& ss, SrsSipRequest *req)
to << req->chid << "@" << req->realm;
req->from = from.str();
req->to = to.str();
req->to = to.str();
if (!req->to_realm.empty()){
req->to = req->chid + "@" + req->to_realm;
}
if (!req->from_realm.empty()){
req->from = req->serial + "@" + req->from_realm;
}
req->uri = uri.str();
int seq = srs_sip_random(22, 99);

View file

@ -106,6 +106,9 @@ public:
int host_port;
SrsSipCmdType cmdtype;
std::string from_realm;
std::string to_realm;
public:
SrsRtspSdp* sdp;
SrsRtspTransport* transport;