1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

GB28181: 无法对接平台问题及一些小bug (#2109)

* 1-新增srs_string_split2函数,该函数支持空串也能按照原有顺序进行切分并放入数组
2-SrsGb28181Device增加属性字段,并在收到catalog命令时能够更新该属性
3-修复sip包解包不严谨bug(body中有可能会有SRS_RTSP_CRLFCRLF那么导致header_body[1]就不一定是body了可能只是body的一部分)

* 1-修复停用rtp多路复用参数(invite_port_fixed)不起作用bug

* bugfix: 当srs发送invite时会指定一个ssrc作为流媒体序列号,但有些平台发流时并不使用这个作为ssrc,而是自己新生成一个。(修复该bug是在invite response时解析内容中的sdp,把对方生成的流媒体序列号ssrc读出来,并且更新srs的channel映射)

* Update push.gb28181.conf

恢复成原来的conf

* bugfix,在取得muxer时需要更新。之前写反了

* Merge branch 'develop' into 4.0release

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 修改sdp_map相同属性的连接符

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 修改sdp_map相同属性的连接符

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 解决冲突时,优先选择原有代码(还原选择develop的代码)

* 回退原来代码

* 删除parse_sdp存储至map相关代码

* 格式恢复

* 格式恢复

* 恢复格式

* srs_string_split() 函数的bugfix

Co-authored-by: xbpeng <xianbin.peng@sibat.cn>
This commit is contained in:
xbpeng121 2021-01-06 15:37:02 +08:00 committed by GitHub
parent 6cf93557e1
commit 47422b7819
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 62 deletions

View file

@ -306,35 +306,7 @@ srs_error_t SrsGb28181PsRtpProcessor::on_rtp_packet(const sockaddr* from, const
if(key != cache_ps_rtp_packet.end()) if(key != cache_ps_rtp_packet.end())
{ {
SrsGb28181RtmpMuxer* muxer = NULL; SrsGb28181RtmpMuxer* muxer = NULL;
//First, search according to the channel_id. Otherwise, search according to the SSRC. muxer = fetch_rtmpmuxer(channel_id,pkt.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);
}
if (muxer){ if (muxer){
//TODO: fixme: the same device uses the same SSRC to send with different local ports //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; 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){ if(true){
SrsGb28181RtmpMuxer* muxer = NULL; SrsGb28181RtmpMuxer* muxer = NULL;
@ -382,7 +354,13 @@ SrsGb28181RtmpMuxer* SrsGb28181PsRtpProcessor::create_rtmpmuxer(std::string chan
SrsGb28181StreamChannel channel; SrsGb28181StreamChannel channel;
channel.set_channel_id(tmp_id); 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); channel.set_ssrc(ssrc);
srs_error_t err2 = srs_success; 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){ if (muxer){
rtmpmuxer_enqueue_data(muxer, pkt->ssrc, peer_port, address_string, pkt); 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; SrsGb28181RtmpMuxer* muxer = NULL;
if (rtmpmuxers.find(id) == rtmpmuxers.end()) { 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; return;
} }
muxer = rtmpmuxers[id]; muxer = rtmpmuxers[id];
SrsGb28181StreamChannel mc = muxer->get_channel(); SrsGb28181StreamChannel mc = muxer->get_channel();
uint32_t old_ssrc = mc.get_ssrc(); uint32_t old_ssrc = mc.get_ssrc();
if (old_ssrc == 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"); return srs_error_wrap(err, "start rtp listen port is mux port");
} }
map<std::string, SrsGb28181RtmpMuxer*>::iterator key = rtmpmuxers.find(id); /* delete by xbpeng 20201222 should not check rtmpmuxers, becasue it always not find*/
if (key == rtmpmuxers.end()){ // map<std::string, SrsGb28181RtmpMuxer*>::iterator key = rtmpmuxers.find(id);
return srs_error_wrap(err, "start rtp listen port rtmp muxer is null"); // 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 (!config->rtp_mux_tcp_enable) {
if (rtp_pool.find(port) == rtp_pool.end()) 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 //channel not exist
SrsGb28181StreamChannel channel; SrsGb28181StreamChannel channel;
channel.set_channel_id(key); 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); err = create_stream_channel(&channel);
if (err != srs_success){ if (err != srs_success){
return err; return err;

View file

@ -108,6 +108,7 @@ class SrsGb28181Conn;
class SrsGb28181Caster; class SrsGb28181Caster;
//ps rtp header packet parse //ps rtp header packet parse
class SrsPsRtpPacket: public SrsRtpPacket class SrsPsRtpPacket: public SrsRtpPacket
{ {
public: public:
@ -160,7 +161,7 @@ private:
SrsPithyPrint* pprint; SrsPithyPrint* pprint;
SrsGb28181Config* config; SrsGb28181Config* config;
std::map<std::string, SrsPsRtpPacket*> cache_ps_rtp_packet; std::map<std::string, SrsPsRtpPacket*> cache_ps_rtp_packet;
std::map<std::string, SrsPsRtpPacket*> pre_packet; std::map<std::string, SrsPsRtpPacket*> pre_packet;
std::string channel_id; std::string channel_id;
bool auto_create_channel; bool auto_create_channel;
public: public:
@ -170,7 +171,7 @@ private:
bool can_send_ps_av_packet(); bool can_send_ps_av_packet();
void dispose(); void dispose();
void clear_pre_packet(); 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, srs_error_t rtmpmuxer_enqueue_data(SrsGb28181RtmpMuxer *muxer, uint32_t ssrc,
int peer_port, std::string address_string, SrsPsRtpPacket *pkt); int peer_port, std::string address_string, SrsPsRtpPacket *pkt);
// Interface ISrsUdpHandler // Interface ISrsUdpHandler

View file

@ -72,7 +72,7 @@ SrsGb28181Device::SrsGb28181Device()
invite_status = SrsGb28181SipSessionUnkonw; invite_status = SrsGb28181SipSessionUnkonw;
invite_time = 0; invite_time = 0;
device_status = ""; device_status = "";
} }
SrsGb28181Device::~SrsGb28181Device() SrsGb28181Device::~SrsGb28181Device()
@ -286,7 +286,7 @@ srs_error_t SrsGb28181SipSession::do_cycle()
invite_duration = 0; 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(), _session_id.c_str(), chid.c_str(), device->device_status.c_str(),
srs_get_sip_session_status_str(device->invite_status).c_str(), srs_get_sip_session_status_str(device->invite_status).c_str(),
(invite_duration / SRS_UTIME_SECONDS)); (invite_duration / SRS_UTIME_SECONDS));

View file

@ -480,30 +480,24 @@ int srs_string_count(string str, string flag)
return nn; return nn;
} }
vector<string> srs_string_split(string str, string flag)
{ vector<string> srs_string_split(string s, string seperator) {
vector<string> arr; vector<string> result;
if(seperator.empty()){
if (flag.empty()) { result.push_back(s);
arr.push_back(str); return result;
return arr;
} }
size_t pos; size_t posBegin = 0;
string s = str; size_t posSeperator = s.find(seperator);
while (posSeperator != string::npos) {
while ((pos = s.find(flag)) != string::npos) { result.push_back(s.substr(posBegin, posSeperator - posBegin));
if (pos != 0) { posBegin = posSeperator + seperator.length(); // next byte of seperator
arr.push_back(s.substr(0, pos)); posSeperator = s.find(seperator, posBegin);
}
s = s.substr(pos + flag.length());
} }
// push the last element
if (!s.empty()) { result.push_back(s.substr(posBegin));
arr.push_back(s); return result;
}
return arr;
} }
string srs_string_min_match(string str, vector<string> flags) string srs_string_min_match(string str, vector<string> flags)

View file

@ -103,7 +103,7 @@ extern int srs_string_count(std::string str, std::string flag);
// Find the min match in str for flags. // Find the min match in str for flags.
extern std::string srs_string_min_match(std::string str, std::vector<std::string> flags); extern std::string srs_string_min_match(std::string str, std::vector<std::string> flags);
// Split the string by flag to array. // Split the string by flag to array.
extern std::vector<std::string> srs_string_split(std::string str, std::string flag); extern std::vector<std::string> srs_string_split(std::string s, std::string seperator);
extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags); extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags);
// Compare the memory in bytes. // Compare the memory in bytes.