mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix 28281 to 28181, sip heart message, timeout channel peer ip and port reset
This commit is contained in:
parent
c5c0df6536
commit
ac8acc0b22
10 changed files with 136 additions and 81 deletions
|
@ -1,4 +1,4 @@
|
|||
# push gb28281 stream to SRS.
|
||||
# push gb28181 stream to SRS.
|
||||
|
||||
listen 1935;
|
||||
max_connections 1000;
|
||||
|
|
|
@ -236,7 +236,7 @@ srs_error_t SrsGb28181PsRtpProcessor::on_udp_packet(const sockaddr* from, const
|
|||
//TODO: check sequence number out of order
|
||||
//it may be out of order, or multiple streaming ssrc are the same
|
||||
// if (pre_sequence_number > pkt.sequence_number){
|
||||
// srs_info("gb28281: ps sequence_number out of order, ssrc=%#x, pre=%u, cur=%u, addr=%s,port=%s",
|
||||
// srs_info("gb28181: ps sequence_number out of order, ssrc=%#x, pre=%u, cur=%u, addr=%s,port=%s",
|
||||
// pkt.ssrc, pre_sequence_number, pkt.sequence_number, address_string, port_string);
|
||||
// //return err;
|
||||
// }
|
||||
|
@ -305,11 +305,11 @@ srs_error_t SrsGb28181PsRtpProcessor::on_udp_packet(const sockaddr* from, const
|
|||
muxer->get_channel_id().c_str(), pkt.ssrc, muxer->channel_peer_port(), peer_port);
|
||||
srs_freep(key->second);
|
||||
}else {
|
||||
//put it in queue, wait for conn to process, and then free
|
||||
//put it in queue, wait for consumer to process, and then free
|
||||
muxer->ps_packet_enqueue(key->second);
|
||||
}
|
||||
}else{
|
||||
//no connection process it, discarded
|
||||
//no consumer process it, discarded
|
||||
srs_freep(key->second);
|
||||
}
|
||||
cache_ps_rtp_packet.erase(pkt_key);
|
||||
|
@ -461,7 +461,7 @@ srs_error_t SrsPsStreamDemixer::on_ps_stream(char* ps_data, int ps_size, uint32_
|
|||
//in a frame of data, pts is obtained from the first PSE packet
|
||||
if (pse_index == 0 && pts_dts_flags > 0) {
|
||||
video_pts = parse_ps_timestamp((unsigned char*)next_ps_pack + 9);
|
||||
srs_info("gb28181: ps stream video ts=%u pkt_ts=%u", pts, timestamp);
|
||||
srs_info("gb28181: ps stream video ts=%u pkt_ts=%u", video_pts, timestamp);
|
||||
}
|
||||
pse_index +=1;
|
||||
|
||||
|
@ -704,6 +704,11 @@ std::string SrsGb28181RtmpMuxer::rtmp_url()
|
|||
return _rtmp_url;
|
||||
}
|
||||
|
||||
srs_utime_t SrsGb28181RtmpMuxer::get_recv_stream_time()
|
||||
{
|
||||
return recv_stream_time;
|
||||
}
|
||||
|
||||
|
||||
void SrsGb28181RtmpMuxer::destroy()
|
||||
{
|
||||
|
@ -750,6 +755,16 @@ srs_error_t SrsGb28181RtmpMuxer::do_cycle()
|
|||
|
||||
srs_utime_t now = srs_get_system_time();
|
||||
srs_utime_t duration = now - recv_stream_time;
|
||||
|
||||
//if no RTP data is received within 2 seconds,
|
||||
//the peer-port and peer-ip will be cleared and
|
||||
//other port data will be received again
|
||||
if (duration > (2 * SRS_UTIME_SECONDS) && channel->get_rtp_peer_port() != 0){
|
||||
srs_warn("gb28181: client id=%s ssrc=%#x, peer(ip=%s port=%d), no rtp data %d in seconds, clean it, wait other port!",
|
||||
channel_id.c_str(), channel->get_ssrc(), channel->get_rtp_peer_ip().c_str(), channel->get_rtp_peer_port(), duration/SRS_UTIME_SECONDS);
|
||||
channel->set_rtp_peer_port(0);
|
||||
channel->set_rtp_peer_ip("");
|
||||
}
|
||||
|
||||
SrsGb28181Config config = gb28181_manger->get_gb28181_config();
|
||||
if (duration > config.rtp_idle_timeout){
|
||||
|
@ -777,6 +792,8 @@ void SrsGb28181RtmpMuxer::stop()
|
|||
void SrsGb28181RtmpMuxer::ps_packet_enqueue(SrsPsRtpPacket *pkt)
|
||||
{
|
||||
srs_assert(pkt);
|
||||
|
||||
recv_stream_time = srs_update_system_time();
|
||||
|
||||
//prevent consumers from being unable to process data
|
||||
//and accumulating in the queue
|
||||
|
@ -1292,7 +1309,7 @@ srs_error_t SrsGb28181Manger::fetch_or_create_rtmpmuxer(std::string id, SrsGb28
|
|||
|
||||
muxer = new SrsGb28181RtmpMuxer(this, id, config->audio_enable, config->wait_keyframe);
|
||||
if ((err = muxer->serve()) != srs_success) {
|
||||
return srs_error_wrap(err, "gb28281: rtmp muxer serve %s", id.c_str());
|
||||
return srs_error_wrap(err, "gb28181: rtmp muxer serve %s", id.c_str());
|
||||
}
|
||||
rtmpmuxers[id] = muxer;
|
||||
*gb28181 = muxer;
|
||||
|
@ -1453,12 +1470,12 @@ uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channe
|
|||
channel->set_port_mode(RTP_PORT_MODE_FIXED);
|
||||
}
|
||||
|
||||
//create on rtmp muxer, gb28281 stream to rtmp
|
||||
//create on rtmp muxer, gb28181 stream to rtmp
|
||||
srs_error_t err = srs_success;
|
||||
if ((err = fetch_or_create_rtmpmuxer(id, &muxer)) != srs_success){
|
||||
srs_warn("gb28181: create rtmp muxer error, %s", srs_error_desc(err).c_str());
|
||||
srs_freep(err);
|
||||
return ERROR_GB28281_CREATER_RTMPMUXER_FAILED;
|
||||
return ERROR_GB28181_CREATER_RTMPMUXER_FAILED;
|
||||
}
|
||||
|
||||
//Start RTP listening port, receive gb28181 stream,
|
||||
|
@ -1477,7 +1494,7 @@ uint32_t SrsGb28181Manger::create_stream_channel(SrsGb28181StreamChannel *channe
|
|||
srs_warn("gb28181: start ps rtp listen error, %s", srs_error_desc(err).c_str());
|
||||
srs_freep(err);
|
||||
free_port(rtp_port, rtp_port + 1);
|
||||
return ERROR_GB28281_CREATER_RTMPMUXER_FAILED;
|
||||
return ERROR_GB28181_CREATER_RTMPMUXER_FAILED;
|
||||
}
|
||||
}
|
||||
else if(port_mode == RTP_PORT_MODE_FIXED) {
|
||||
|
|
|
@ -76,7 +76,7 @@ public:
|
|||
virtual srs_error_t decode(SrsBuffer* stream);
|
||||
};
|
||||
|
||||
//randomly assigned ports receive gb28281 device streams
|
||||
//randomly assigned ports receive gb28181 device streams
|
||||
class SrsPsRtpListener: public ISrsUdpHandler
|
||||
{
|
||||
private:
|
||||
|
@ -94,7 +94,7 @@ public:
|
|||
virtual srs_error_t on_udp_packet(const sockaddr* from, const int fromlen, char* buf, int nb_buf);
|
||||
};
|
||||
|
||||
//multiplexing service, single port receiving all gb28281 device streams
|
||||
//multiplexing service, single port receiving all gb28181 device streams
|
||||
class SrsGb28181RtpMuxService : public ISrsUdpHandler
|
||||
{
|
||||
private:
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
};
|
||||
|
||||
|
||||
//process gb28281 RTP package, generate a completed PS stream data,
|
||||
//process gb28181 RTP package, generate a completed PS stream data,
|
||||
//call the PS stream parser, parse the original video and audio
|
||||
class SrsGb28181PsRtpProcessor: public ISrsUdpHandler
|
||||
{
|
||||
|
@ -262,6 +262,7 @@ public:
|
|||
virtual void set_rtmp_url(std::string url);
|
||||
virtual std::string rtmp_url();
|
||||
virtual SrsGb28181StreamChannel get_channel();
|
||||
srs_utime_t get_recv_stream_time();
|
||||
|
||||
private:
|
||||
virtual srs_error_t do_cycle();
|
||||
|
@ -288,7 +289,7 @@ public:
|
|||
virtual void rtmp_close();
|
||||
};
|
||||
|
||||
//system parameter configuration of gb28281 module,
|
||||
//system parameter configuration of gb28181 module,
|
||||
//read file from configuration file to generate
|
||||
class SrsGb28181Config
|
||||
{
|
||||
|
|
|
@ -143,7 +143,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
{
|
||||
srs_trace("gb28181: %s method=%s, uri=%s, version=%s ",
|
||||
req->get_cmdtype_str().c_str(), req->method.c_str(), req->uri.c_str(), req->version.c_str());
|
||||
srs_trace("gb28281: request client id=%s", req->sip_auth_id.c_str());
|
||||
srs_trace("gb28181: request client id=%s", req->sip_auth_id.c_str());
|
||||
}
|
||||
|
||||
req->peer_ip = peer_ip;
|
||||
|
@ -163,7 +163,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
srs_trace("gb28181: request peer_ip=%s, peer_port=%d", peer_ip.c_str(), peer_port, nb_buf);
|
||||
srs_trace("gb28181: request %s method=%s, uri=%s, version=%s ",
|
||||
req->get_cmdtype_str().c_str(), req->method.c_str(), req->uri.c_str(), req->version.c_str());
|
||||
srs_trace("gb28281: request client id=%s", req->sip_auth_id.c_str());
|
||||
srs_trace("gb28181: request client id=%s", req->sip_auth_id.c_str());
|
||||
|
||||
SrsGb28181SipSession* sip_session = create_sip_session(req);
|
||||
if (!sip_session) {
|
||||
|
@ -235,7 +235,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
srs_trace("gb28181: request peer_ip=%s, peer_port=%d", peer_ip.c_str(), peer_port, nb_buf);
|
||||
srs_trace("gb28181: request %s method=%s, uri=%s, version=%s ",
|
||||
req->get_cmdtype_str().c_str(), req->method.c_str(), req->uri.c_str(), req->version.c_str());
|
||||
srs_trace("gb28281: request client id=%s", req->sip_auth_id.c_str());
|
||||
srs_trace("gb28181: request client id=%s", req->sip_auth_id.c_str());
|
||||
|
||||
if (!sip_session){
|
||||
send_bye(req);
|
||||
|
@ -264,7 +264,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
srs_trace("gb28181: request peer_ip=%s, peer_port=%d", peer_ip.c_str(), peer_port, nb_buf);
|
||||
srs_trace("gb28181: request %s method=%s, uri=%s, version=%s ",
|
||||
req->get_cmdtype_str().c_str(), req->method.c_str(), req->uri.c_str(), req->version.c_str());
|
||||
srs_trace("gb28281: request client id=%s", req->sip_auth_id.c_str());
|
||||
srs_trace("gb28181: request client id=%s", req->sip_auth_id.c_str());
|
||||
|
||||
SrsGb28181SipSession* sip_session = fetch(session_id);
|
||||
send_status(req, from, fromlen);
|
||||
|
@ -311,7 +311,7 @@ int SrsGb28181SipService::send_ack(SrsSipRequest *req, sockaddr *f, int l)
|
|||
req->realm = config->sip_realm;
|
||||
req->serial = config->sip_serial;
|
||||
|
||||
sip->resp_ack(ss, req);
|
||||
sip->req_ack(ss, req);
|
||||
return send_message(f, l, ss);
|
||||
}
|
||||
|
||||
|
@ -345,7 +345,7 @@ int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port,
|
|||
//you cannot invite again. you need to 'bye' and try again
|
||||
if (sip_session->invite_status() == SrsGb28181SipSessionTrying ||
|
||||
sip_session->invite_status() == SrsGb28181SipSessionInviteOk){
|
||||
return ERROR_GB28281_SIP_IS_INVITING;
|
||||
return ERROR_GB28181_SIP_IS_INVITING;
|
||||
}
|
||||
|
||||
req->host = config->host;
|
||||
|
@ -358,7 +358,7 @@ int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port,
|
|||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28281_SIP_INVITE_FAILED;
|
||||
return ERROR_GB28181_SIP_INVITE_FAILED;
|
||||
}
|
||||
|
||||
sip_session->set_invite_status(SrsGb28181SipSessionTrying);
|
||||
|
@ -393,7 +393,7 @@ int SrsGb28181SipService::send_bye(SrsSipRequest *req)
|
|||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28281_SIP_BYE_FAILED;
|
||||
return ERROR_GB28181_SIP_BYE_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
|
@ -417,7 +417,7 @@ int SrsGb28181SipService::send_sip_raw_data(SrsSipRequest *req, std::string dat
|
|||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28281_SIP_BYE_FAILED;
|
||||
return ERROR_GB28181_SIP_BYE_FAILED;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
|
|
|
@ -41,7 +41,7 @@ class SrsGb28181Config;
|
|||
class SrsSipStack;
|
||||
class SrsGb28181SipService;
|
||||
|
||||
enum SrsGb28281SipSessionStatusType{
|
||||
enum SrsGb28181SipSessionStatusType{
|
||||
SrsGb28181SipSessionUnkonw = 0,
|
||||
SrsGb28181SipSessionRegisterOk = 1,
|
||||
SrsGb28181SipSessionAliveOk = 2,
|
||||
|
@ -57,9 +57,9 @@ private:
|
|||
SrsGb28181SipService *caster;
|
||||
std::string session_id;
|
||||
private:
|
||||
SrsGb28281SipSessionStatusType _register_status;
|
||||
SrsGb28281SipSessionStatusType _alive_status;
|
||||
SrsGb28281SipSessionStatusType _invite_status;
|
||||
SrsGb28181SipSessionStatusType _register_status;
|
||||
SrsGb28181SipSessionStatusType _alive_status;
|
||||
SrsGb28181SipSessionStatusType _invite_status;
|
||||
srs_utime_t _register_time;
|
||||
srs_utime_t _alive_time;
|
||||
srs_utime_t _invite_time;
|
||||
|
@ -74,9 +74,9 @@ private:
|
|||
SrsSipRequest *req;
|
||||
|
||||
public:
|
||||
void set_register_status(SrsGb28281SipSessionStatusType s) { _register_status = s;}
|
||||
void set_alive_status(SrsGb28281SipSessionStatusType s) { _alive_status = s;}
|
||||
void set_invite_status(SrsGb28281SipSessionStatusType s) { _invite_status = s;}
|
||||
void set_register_status(SrsGb28181SipSessionStatusType s) { _register_status = s;}
|
||||
void set_alive_status(SrsGb28181SipSessionStatusType s) { _alive_status = s;}
|
||||
void set_invite_status(SrsGb28181SipSessionStatusType s) { _invite_status = s;}
|
||||
void set_register_time(srs_utime_t t) { _register_time = t;}
|
||||
void set_alive_time(srs_utime_t t) { _alive_time = t;}
|
||||
void set_invite_time(srs_utime_t t) { _invite_time = t;}
|
||||
|
@ -88,9 +88,9 @@ public:
|
|||
void set_sockaddr_len(int l) { _fromlen = l;}
|
||||
void set_request(SrsSipRequest *r) { req->copy(r);}
|
||||
|
||||
SrsGb28281SipSessionStatusType register_status() { return _register_status;}
|
||||
SrsGb28281SipSessionStatusType alive_status() { return _alive_status;}
|
||||
SrsGb28281SipSessionStatusType invite_status() { return _invite_status;}
|
||||
SrsGb28181SipSessionStatusType register_status() { return _register_status;}
|
||||
SrsGb28181SipSessionStatusType alive_status() { return _alive_status;}
|
||||
SrsGb28181SipSessionStatusType invite_status() { return _invite_status;}
|
||||
srs_utime_t register_time() { return _register_time;}
|
||||
srs_utime_t alive_time() { return _alive_time;}
|
||||
srs_utime_t invite_time() { return _invite_time;}
|
||||
|
|
|
@ -696,7 +696,7 @@ void SrsServer::destroy()
|
|||
srs_freep(conn_manager);
|
||||
|
||||
#ifdef SRS_AUTO_GB28181
|
||||
//free global gb28281 manager
|
||||
//free global gb28181 manager
|
||||
srs_freep(_srs_gb28181);
|
||||
#endif
|
||||
}
|
||||
|
@ -1349,7 +1349,7 @@ srs_error_t SrsServer::listen_http_stream()
|
|||
}
|
||||
|
||||
#ifdef SRS_AUTO_GB28181
|
||||
srs_error_t SrsServer::listen_gb28281_sip(SrsConfDirective* stream_caster)
|
||||
srs_error_t SrsServer::listen_gb28181_sip(SrsConfDirective* stream_caster)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -1400,7 +1400,7 @@ srs_error_t SrsServer::listen_stream_caster()
|
|||
listener = new SrsHttpFlvListener(this, SrsListenerFlv, stream_caster);
|
||||
} else if (srs_stream_caster_is_gb28181(caster)) {
|
||||
#ifdef SRS_AUTO_GB28181
|
||||
//init global gb28281 manger
|
||||
//init global gb28181 manger
|
||||
if (_srs_gb28181 == NULL){
|
||||
_srs_gb28181 = new SrsGb28181Manger(stream_caster);
|
||||
if ((err = _srs_gb28181->initialize()) != srs_success){
|
||||
|
@ -1410,12 +1410,12 @@ srs_error_t SrsServer::listen_stream_caster()
|
|||
|
||||
//sip listener
|
||||
if (_srs_config->get_stream_caster_gb28181_sip_enable(stream_caster)){
|
||||
if ((err = listen_gb28281_sip(stream_caster)) != srs_success){
|
||||
if ((err = listen_gb28181_sip(stream_caster)) != srs_success){
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
//gb28281 stream listener
|
||||
//gb28181 stream listener
|
||||
listener = new SrsGb28181Listener(this, SrsListenerGb28181RtpMux, stream_caster);
|
||||
#else
|
||||
srs_warn("gb28181 is disabled, please enable it by: ./configure --with-gb28181");
|
||||
|
|
|
@ -324,7 +324,7 @@ private:
|
|||
virtual srs_error_t listen_http_stream();
|
||||
virtual srs_error_t listen_stream_caster();
|
||||
#ifdef SRS_AUTO_GB28181
|
||||
virtual srs_error_t listen_gb28281_sip(SrsConfDirective* c);
|
||||
virtual srs_error_t listen_gb28181_sip(SrsConfDirective* c);
|
||||
#endif
|
||||
// Close the listeners for specified type,
|
||||
// Remove the listen object from manager.
|
||||
|
|
|
@ -359,10 +359,10 @@
|
|||
#define ERROR_GB28181_VALUE_EMPTY 6005
|
||||
#define ERROR_GB28181_ACTION_INVALID 6006
|
||||
#define ERROR_GB28181_SIP_NOT_RUN 6007
|
||||
#define ERROR_GB28281_SIP_INVITE_FAILED 6008
|
||||
#define ERROR_GB28281_SIP_BYE_FAILED 6009
|
||||
#define ERROR_GB28281_SIP_IS_INVITING 6010
|
||||
#define ERROR_GB28281_CREATER_RTMPMUXER_FAILED 6011
|
||||
#define ERROR_GB28181_SIP_INVITE_FAILED 6008
|
||||
#define ERROR_GB28181_SIP_BYE_FAILED 6009
|
||||
#define ERROR_GB28181_SIP_IS_INVITING 6010
|
||||
#define ERROR_GB28181_CREATER_RTMPMUXER_FAILED 6011
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// HTTP API error.
|
||||
|
|
|
@ -345,7 +345,7 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
|||
}
|
||||
}
|
||||
else if (!strcasecmp(phead, "via:")) {
|
||||
std::vector<std::string> vec_seq = srs_string_split(content, ";");
|
||||
//std::vector<std::string> vec_via = srs_string_split(content, ";");
|
||||
req->via = content;
|
||||
req->branch = srs_sip_get_param(content.c_str(), "branch");
|
||||
}
|
||||
|
@ -417,7 +417,52 @@ srs_error_t SrsSipStack::do_parse_request(SrsSipRequest* req, const char* recv_m
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsSipStack::resp_keepalive(std::stringstream& ss, SrsSipRequest *req){
|
||||
std::string SrsSipStack::get_sip_from(SrsSipRequest const *req)
|
||||
{
|
||||
std::string from_tag;
|
||||
if (req->from_tag.empty()){
|
||||
from_tag = "";
|
||||
}else {
|
||||
from_tag = ";tag=" + req->from_tag;
|
||||
}
|
||||
|
||||
return "<sip:" + req->from + ">" + from_tag;
|
||||
}
|
||||
|
||||
std::string SrsSipStack::get_sip_to(SrsSipRequest const *req)
|
||||
{
|
||||
std::string to_tag;
|
||||
if (req->to_tag.empty()){
|
||||
to_tag = "";
|
||||
}else {
|
||||
to_tag = ";tag=" + req->to_tag;
|
||||
}
|
||||
|
||||
return "<sip:" + req->to + ">" + to_tag;
|
||||
}
|
||||
|
||||
std::string SrsSipStack::get_sip_via(SrsSipRequest const *req)
|
||||
{
|
||||
std::string via = srs_string_replace(req->via, SRS_SIP_VERSION"/UDP ", "");
|
||||
std::vector<std::string> vec_via = srs_string_split(via, ";");
|
||||
std::string ip_port = vec_via.at(0);
|
||||
std::vector<std::string> vec_ip_port = srs_string_split(ip_port, ":");
|
||||
|
||||
std::string branch, rport, received;
|
||||
if (req->branch.empty()){
|
||||
branch = "";
|
||||
}else {
|
||||
branch = ";branch=" + req->branch;
|
||||
}
|
||||
|
||||
received = ";received=" + vec_ip_port.at(0);
|
||||
rport = ";rport=" + vec_ip_port.at(1);
|
||||
|
||||
return SRS_SIP_VERSION"/UDP " + ip_port + rport + received + branch;
|
||||
}
|
||||
|
||||
void SrsSipStack::resp_keepalive(std::stringstream& ss, SrsSipRequest *req)
|
||||
{
|
||||
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
|
||||
<< "Via: " << SRS_SIP_VERSION << "/UDP " << req->host << ":" << req->host_port << ";branch=" << req->branch << SRS_RTSP_CRLF
|
||||
<< "From: <sip:" << req->from.c_str() << ">;tag=" << req->from_tag << SRS_RTSP_CRLF
|
||||
|
@ -466,9 +511,9 @@ void SrsSipStack::resp_status(stringstream& ss, SrsSipRequest *req)
|
|||
}
|
||||
|
||||
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
|
||||
<< "Via: " << req->via << SRS_RTSP_CRLF
|
||||
<< "From: <sip:"<< req->from << ">" << SRS_RTSP_CRLF
|
||||
<< "To: <sip:"<< req->to << ">" << SRS_RTSP_CRLF
|
||||
<< "Via: " << get_sip_via(req) << SRS_RTSP_CRLF
|
||||
<< "From: "<< get_sip_from(req) << SRS_RTSP_CRLF
|
||||
<< "To: "<< get_sip_to(req) << SRS_RTSP_CRLF
|
||||
<< "CSeq: "<< req->seq << " " << req->method << SRS_RTSP_CRLF
|
||||
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
|
||||
<< "Contact: " << req->contact << SRS_RTSP_CRLF
|
||||
|
@ -511,9 +556,9 @@ void SrsSipStack::resp_status(stringstream& ss, SrsSipRequest *req)
|
|||
*/
|
||||
|
||||
ss << SRS_SIP_VERSION <<" 200 OK" << SRS_RTSP_CRLF
|
||||
<< "Via: " << req->via << SRS_RTSP_CRLF
|
||||
<< "From: <sip:"<< req->from << ">" << SRS_RTSP_CRLF
|
||||
<< "To: <sip:"<< req->to << ">" << SRS_RTSP_CRLF
|
||||
<< "Via: " << get_sip_via(req) << SRS_RTSP_CRLF
|
||||
<< "From: " << get_sip_from(req) << SRS_RTSP_CRLF
|
||||
<< "To: "<< get_sip_to(req) << SRS_RTSP_CRLF
|
||||
<< "CSeq: "<< req->seq << " " << req->method << SRS_RTSP_CRLF
|
||||
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
|
||||
<< "User-Agent: " << SRS_SIP_USER_AGENT << SRS_RTSP_CRLF
|
||||
|
@ -635,8 +680,8 @@ void SrsSipStack::req_invite(stringstream& ss, SrsSipRequest *req, string ip, in
|
|||
|
||||
ss << "INVITE " << req->uri << " " << 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->from << ">;tag=" << req->from_tag << SRS_RTSP_CRLF
|
||||
<< "To: <sip:" << req->to << ">" << SRS_RTSP_CRLF
|
||||
<< "From: " << get_sip_from(req) << SRS_RTSP_CRLF
|
||||
<< "To: " << get_sip_to(req) << SRS_RTSP_CRLF
|
||||
<< "Call-ID: 20000" << rand <<SRS_RTSP_CRLF
|
||||
<< "CSeq: 20 INVITE" << SRS_RTSP_CRLF
|
||||
<< "Content-Type: Application/SDP" << SRS_RTSP_CRLF
|
||||
|
@ -666,9 +711,9 @@ void SrsSipStack::req_401_unauthorized(std::stringstream& ss, SrsSipRequest *req
|
|||
|
||||
ss << SRS_SIP_VERSION <<" 401 Unauthorized" << SRS_RTSP_CRLF
|
||||
//<< "Via: " << req->via << SRS_RTSP_CRLF
|
||||
<< "Via: " << req->via << ";rport=" << req->peer_port << ";received=" << req->peer_ip << ";branch=" << req->branch << SRS_RTSP_CRLF
|
||||
<< "From: <sip:"<< req->from << ">" << SRS_RTSP_CRLF
|
||||
<< "To: <sip:"<< req->to << ">" << SRS_RTSP_CRLF
|
||||
<< "Via: " << get_sip_via(req) << SRS_RTSP_CRLF
|
||||
<< "From: " << get_sip_from(req) << SRS_RTSP_CRLF
|
||||
<< "To: " << get_sip_to(req) << SRS_RTSP_CRLF
|
||||
<< "CSeq: "<< req->seq << " " << req->method << SRS_RTSP_CRLF
|
||||
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
|
||||
<< "Contact: " << req->contact << SRS_RTSP_CRLF
|
||||
|
@ -678,7 +723,7 @@ void SrsSipStack::req_401_unauthorized(std::stringstream& ss, SrsSipRequest *req
|
|||
return;
|
||||
}
|
||||
|
||||
void SrsSipStack::resp_ack(std::stringstream& ss, SrsSipRequest *req){
|
||||
void SrsSipStack::req_ack(std::stringstream& ss, SrsSipRequest *req){
|
||||
/*
|
||||
//request: sip-agent <------ ACK ------- sip-server
|
||||
ACK sip:34020000001320000003@3402000000 SIP/2.0
|
||||
|
@ -738,31 +783,13 @@ void SrsSipStack::req_bye(std::stringstream& ss, SrsSipRequest *req)
|
|||
req->to = to.str();
|
||||
req->uri = uri.str();
|
||||
|
||||
string to_tag, from_tag, branch;
|
||||
|
||||
if (req->branch.empty()){
|
||||
branch = "";
|
||||
}else {
|
||||
branch = ";branch=" + req->branch;
|
||||
}
|
||||
|
||||
if (req->from_tag.empty()){
|
||||
from_tag = "";
|
||||
}else {
|
||||
from_tag = ";tag=" + req->from_tag;
|
||||
}
|
||||
|
||||
if (req->to_tag.empty()){
|
||||
to_tag = "";
|
||||
}else {
|
||||
to_tag = ";tag=" + req->to_tag;
|
||||
}
|
||||
|
||||
int seq = srs_sip_random(22, 99);
|
||||
ss << "BYE " << req->uri << " "<< SRS_SIP_VERSION << SRS_RTSP_CRLF
|
||||
<< "Via: "<< SRS_SIP_VERSION << "/UDP "<< req->host << ":" << req->host_port << ";rport" << branch << SRS_RTSP_CRLF
|
||||
<< "From: <sip:" << req->from << ">" << from_tag << SRS_RTSP_CRLF
|
||||
<< "To: <sip:" << req->to << ">" << to_tag << SRS_RTSP_CRLF
|
||||
//<< "Via: "<< SRS_SIP_VERSION << "/UDP "<< req->host << ":" << req->host_port << ";rport" << branch << SRS_RTSP_CRLF
|
||||
<< "Via: " << SRS_SIP_VERSION << "/UDP " << req->host << ":" << req->host_port << ";rport;branch=" << req->branch << SRS_RTSP_CRLF
|
||||
<< "From: " << get_sip_from(req) << SRS_RTSP_CRLF
|
||||
<< "To: " << get_sip_to(req) << SRS_RTSP_CRLF
|
||||
//bye callid is inivte callid
|
||||
<< "Call-ID: " << req->call_id << SRS_RTSP_CRLF
|
||||
<< "CSeq: "<< seq <<" BYE" << SRS_RTSP_CRLF
|
||||
<< "Max-Forwards: 70" << SRS_RTSP_CRLF
|
||||
|
|
|
@ -130,12 +130,22 @@ public:
|
|||
protected:
|
||||
virtual srs_error_t do_parse_request(SrsSipRequest* req, const char *recv_msg);
|
||||
|
||||
private:
|
||||
//response from
|
||||
virtual std::string get_sip_from(SrsSipRequest const *req);
|
||||
//response to
|
||||
virtual std::string get_sip_to(SrsSipRequest const *req);
|
||||
//response via
|
||||
virtual std::string get_sip_via(SrsSipRequest const *req);
|
||||
|
||||
public:
|
||||
//response: request sent by the sip-agent, wait for sip-server response
|
||||
virtual void resp_status(std::stringstream& ss, SrsSipRequest *req);
|
||||
virtual void resp_keepalive(std::stringstream& ss, SrsSipRequest *req);
|
||||
virtual void resp_ack(std::stringstream& ss, SrsSipRequest *req);
|
||||
|
||||
|
||||
//request: request sent by the sip-server, wait for sip-agent response
|
||||
virtual void req_invite(std::stringstream& ss, SrsSipRequest *req, std::string ip, int port, uint32_t ssrc);
|
||||
virtual void req_ack(std::stringstream& ss, SrsSipRequest *req);
|
||||
virtual void req_bye(std::stringstream& ss, SrsSipRequest *req);
|
||||
virtual void req_401_unauthorized(std::stringstream& ss, SrsSipRequest *req);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue