diff --git a/trunk/src/app/srs_app_gb28181.cpp b/trunk/src/app/srs_app_gb28181.cpp index a352ecd3a..89a9c620d 100644 --- a/trunk/src/app/srs_app_gb28181.cpp +++ b/trunk/src/app/srs_app_gb28181.cpp @@ -306,35 +306,7 @@ srs_error_t SrsGb28181PsRtpProcessor::on_rtp_packet(const sockaddr* from, const if(key != cache_ps_rtp_packet.end()) { SrsGb28181RtmpMuxer* muxer = NULL; - //First, search according to the channel_id. Otherwise, search according to the SSRC. - //Some channel_id are created by RTP pool, which are different ports. - //No channel_id are created by multiplexing ports, which are the same port - if (!channel_id.empty()){ - muxer = _srs_gb28181->fetch_rtmpmuxer(channel_id); - }else { - muxer = _srs_gb28181->fetch_rtmpmuxer_by_ssrc(pkt.ssrc); - } - - //auto crate channel - if (!muxer && config->auto_create_channel){ - //auto create channel generated id - std::stringstream ss, ss1; - ss << "chid" << pkt.ssrc; - std::string tmp_id = ss.str(); - - SrsGb28181StreamChannel channel; - channel.set_channel_id(tmp_id); - channel.set_port_mode(RTP_PORT_MODE_FIXED); - channel.set_ssrc(pkt.ssrc); - - srs_error_t err2 = srs_success; - if ((err2 = _srs_gb28181->create_stream_channel(&channel)) != srs_success){ - srs_warn("gb28181: RtpProcessor create stream channel error %s", srs_error_desc(err2).c_str()); - srs_error_reset(err2); - }; - - muxer = _srs_gb28181->fetch_rtmpmuxer(tmp_id); - } + muxer = fetch_rtmpmuxer(channel_id,pkt.ssrc); if (muxer){ //TODO: fixme: the same device uses the same SSRC to send with different local ports @@ -360,7 +332,7 @@ srs_error_t SrsGb28181PsRtpProcessor::on_rtp_packet(const sockaddr* from, const return err; } -SrsGb28181RtmpMuxer* SrsGb28181PsRtpProcessor::create_rtmpmuxer(std::string channel_id, uint32_t ssrc) +SrsGb28181RtmpMuxer* SrsGb28181PsRtpProcessor::fetch_rtmpmuxer(std::string channel_id, uint32_t ssrc) { if(true){ SrsGb28181RtmpMuxer* muxer = NULL; @@ -382,7 +354,13 @@ SrsGb28181RtmpMuxer* SrsGb28181PsRtpProcessor::create_rtmpmuxer(std::string chan SrsGb28181StreamChannel channel; channel.set_channel_id(tmp_id); - channel.set_port_mode(RTP_PORT_MODE_FIXED); + // channel.set_port_mode(RTP_PORT_MODE_FIXED); + if (!config->sip_invite_port_fixed) { + channel.set_port_mode(RTP_PORT_MODE_RANDOM); + }else + { + channel.set_port_mode(RTP_PORT_MODE_FIXED); + } channel.set_ssrc(ssrc); srs_error_t err2 = srs_success; @@ -471,7 +449,7 @@ srs_error_t SrsGb28181PsRtpProcessor::on_rtp_packet_jitter(const sockaddr* from, ); } - SrsGb28181RtmpMuxer *muxer = create_rtmpmuxer(channel_id, pkt->ssrc); + SrsGb28181RtmpMuxer *muxer = fetch_rtmpmuxer(channel_id, pkt->ssrc); if (muxer){ rtmpmuxer_enqueue_data(muxer, pkt->ssrc, peer_port, address_string, pkt); } @@ -2367,10 +2345,12 @@ void SrsGb28181Manger::update_rtmpmuxer_to_newssrc_by_id(std::string id, uint32_ SrsGb28181RtmpMuxer* muxer = NULL; if (rtmpmuxers.find(id) == rtmpmuxers.end()) { + srs_warn("gb28181: at update_rtmpmuxer_to_newssrc_by_id() client_id not found. client_id=%s",id.c_str()); return; } muxer = rtmpmuxers[id]; + SrsGb28181StreamChannel mc = muxer->get_channel(); uint32_t old_ssrc = mc.get_ssrc(); if (old_ssrc == ssrc) { @@ -2459,10 +2439,12 @@ srs_error_t SrsGb28181Manger::start_ps_rtp_listen(std::string id, int port) return srs_error_wrap(err, "start rtp listen port is mux port"); } - map::iterator key = rtmpmuxers.find(id); - if (key == rtmpmuxers.end()){ - return srs_error_wrap(err, "start rtp listen port rtmp muxer is null"); - } + /* delete by xbpeng 20201222 should not check rtmpmuxers, becasue it always not find*/ + // map::iterator key = rtmpmuxers.find(id); + // if (key == rtmpmuxers.end()){ + // srs_warn("start rtp listen port rtmp muxer is null. id=%s,port=%d", id.c_str(),port); + // return srs_error_wrap(err, "start rtp listen port rtmp muxer is null"); + // } if (!config->rtp_mux_tcp_enable) { if (rtp_pool.find(port) == rtp_pool.end()) @@ -2703,6 +2685,12 @@ srs_error_t SrsGb28181Manger::notify_sip_invite(std::string id, std::string ip, //channel not exist SrsGb28181StreamChannel channel; channel.set_channel_id(key); + if (!this->config->sip_invite_port_fixed) { + channel.set_port_mode(RTP_PORT_MODE_RANDOM); + }else + { + channel.set_port_mode(RTP_PORT_MODE_FIXED); + } err = create_stream_channel(&channel); if (err != srs_success){ return err; diff --git a/trunk/src/app/srs_app_gb28181.hpp b/trunk/src/app/srs_app_gb28181.hpp index 80a87a0f1..0a934a834 100644 --- a/trunk/src/app/srs_app_gb28181.hpp +++ b/trunk/src/app/srs_app_gb28181.hpp @@ -108,6 +108,7 @@ class SrsGb28181Conn; class SrsGb28181Caster; //ps rtp header packet parse + class SrsPsRtpPacket: public SrsRtpPacket { public: @@ -160,7 +161,7 @@ private: SrsPithyPrint* pprint; SrsGb28181Config* config; std::map cache_ps_rtp_packet; - std::map pre_packet; + std::map pre_packet; std::string channel_id; bool auto_create_channel; public: @@ -170,7 +171,7 @@ private: bool can_send_ps_av_packet(); void dispose(); void clear_pre_packet(); - SrsGb28181RtmpMuxer* create_rtmpmuxer(std::string channel_id, uint32_t ssrc); + SrsGb28181RtmpMuxer* fetch_rtmpmuxer(std::string channel_id, uint32_t ssrc); srs_error_t rtmpmuxer_enqueue_data(SrsGb28181RtmpMuxer *muxer, uint32_t ssrc, int peer_port, std::string address_string, SrsPsRtpPacket *pkt); // Interface ISrsUdpHandler diff --git a/trunk/src/app/srs_app_gb28181_sip.cpp b/trunk/src/app/srs_app_gb28181_sip.cpp index 6342cfd77..8e416fb11 100644 --- a/trunk/src/app/srs_app_gb28181_sip.cpp +++ b/trunk/src/app/srs_app_gb28181_sip.cpp @@ -72,7 +72,7 @@ SrsGb28181Device::SrsGb28181Device() invite_status = SrsGb28181SipSessionUnkonw; invite_time = 0; device_status = ""; - + } SrsGb28181Device::~SrsGb28181Device() @@ -286,7 +286,7 @@ srs_error_t SrsGb28181SipSession::do_cycle() invite_duration = 0; } - srs_trace("gb28181: sip session=%s device=%s status(%s, %s), duration(%u)", + srs_info("gb28181: sip session=%s device=%s status(%s, %s), duration(%u)", _session_id.c_str(), chid.c_str(), device->device_status.c_str(), srs_get_sip_session_status_str(device->invite_status).c_str(), (invite_duration / SRS_UTIME_SECONDS)); diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index d79a4964d..e461445a0 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -480,30 +480,24 @@ int srs_string_count(string str, string flag) return nn; } -vector srs_string_split(string str, string flag) -{ - vector arr; - - if (flag.empty()) { - arr.push_back(str); - return arr; + +vector srs_string_split(string s, string seperator) { + vector result; + if(seperator.empty()){ + result.push_back(s); + return result; } - size_t pos; - string s = str; - - while ((pos = s.find(flag)) != string::npos) { - if (pos != 0) { - arr.push_back(s.substr(0, pos)); - } - s = s.substr(pos + flag.length()); + size_t posBegin = 0; + size_t posSeperator = s.find(seperator); + while (posSeperator != string::npos) { + result.push_back(s.substr(posBegin, posSeperator - posBegin)); + posBegin = posSeperator + seperator.length(); // next byte of seperator + posSeperator = s.find(seperator, posBegin); } - - if (!s.empty()) { - arr.push_back(s); - } - - return arr; + // push the last element + result.push_back(s.substr(posBegin)); + return result; } string srs_string_min_match(string str, vector flags) diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 586878ca4..1f0f56491 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -103,7 +103,7 @@ extern int srs_string_count(std::string str, std::string flag); // Find the min match in str for flags. extern std::string srs_string_min_match(std::string str, std::vector flags); // Split the string by flag to array. -extern std::vector srs_string_split(std::string str, std::string flag); +extern std::vector srs_string_split(std::string s, std::string seperator); extern std::vector srs_string_split(std::string str, std::vector flags); // Compare the memory in bytes.