mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
fix after RTMP is closed, empty PPS and SPS. sip client sockaddr set
This commit is contained in:
parent
ac8acc0b22
commit
5e4fdfd1d4
4 changed files with 37 additions and 32 deletions
|
@ -261,8 +261,9 @@ srs_error_t SrsGb28181PsRtpProcessor::on_udp_packet(const sockaddr* from, const
|
|||
}
|
||||
|
||||
if (pprint->can_print()) {
|
||||
srs_trace("<- " SRS_CONSTS_LOG_STREAM_CASTER " gb28181: client_id %s, ps rtp packet %dB, age=%d, vt=%d/%u, sts=%u/%u/%#x, paylod=%dB",
|
||||
channel_id.c_str(), nb_buf, pprint->age(), pkt.version, pkt.payload_type, pkt.sequence_number, pkt.timestamp, pkt.ssrc,
|
||||
srs_trace("<- " SRS_CONSTS_LOG_STREAM_CASTER " gb28181: client_id %s, peer(ip=%s, port=%d) ps rtp packet %dB, age=%d, vt=%d/%u, sts=%u/%u/%#x, paylod=%dB",
|
||||
channel_id.c_str(), address_string, peer_port, nb_buf, pprint->age(), pkt.version,
|
||||
pkt.payload_type, pkt.sequence_number, pkt.timestamp, pkt.ssrc,
|
||||
pkt.payload->length()
|
||||
);
|
||||
}
|
||||
|
@ -615,14 +616,15 @@ SrsGb28181RtmpMuxer::SrsGb28181RtmpMuxer(SrsGb28181Manger* c, std::string id, bo
|
|||
ps_demixer = new SrsPsStreamDemixer(this, id, a, k);
|
||||
wait_ps_queue = srs_cond_new();
|
||||
|
||||
h264_sps_changed = false;
|
||||
h264_pps_changed = false;
|
||||
h264_sps_pps_sent = false;
|
||||
|
||||
stream_idle_timeout = -1;
|
||||
recv_stream_time = 0;
|
||||
|
||||
_rtmp_url = "";
|
||||
|
||||
h264_sps = "";
|
||||
h264_pps = "";
|
||||
aac_specific_config = "";
|
||||
|
||||
}
|
||||
|
||||
SrsGb28181RtmpMuxer::~SrsGb28181RtmpMuxer()
|
||||
|
@ -761,7 +763,8 @@ srs_error_t SrsGb28181RtmpMuxer::do_cycle()
|
|||
//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_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("");
|
||||
}
|
||||
|
@ -887,7 +890,6 @@ srs_error_t SrsGb28181RtmpMuxer::on_rtp_video(SrsSimpleStream *stream, int64_t f
|
|||
if (h264_sps == sps) {
|
||||
continue;
|
||||
}
|
||||
h264_sps_changed = true;
|
||||
h264_sps = sps;
|
||||
|
||||
if ((err = write_h264_sps_pps(dts, pts)) != srs_success) {
|
||||
|
@ -906,7 +908,6 @@ srs_error_t SrsGb28181RtmpMuxer::on_rtp_video(SrsSimpleStream *stream, int64_t f
|
|||
if (h264_pps == pps) {
|
||||
continue;
|
||||
}
|
||||
h264_pps_changed = true;
|
||||
h264_pps = pps;
|
||||
|
||||
if ((err = write_h264_sps_pps(dts, pts)) != srs_success) {
|
||||
|
@ -1020,10 +1021,6 @@ srs_error_t SrsGb28181RtmpMuxer::write_h264_sps_pps(uint32_t dts, uint32_t pts)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (!h264_sps_changed || !h264_pps_changed) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// h264 raw to h264 packet.
|
||||
std::string sh;
|
||||
if ((err = avc->mux_sequence_header(h264_sps, h264_pps, dts, pts, sh)) != srs_success) {
|
||||
|
@ -1045,10 +1042,6 @@ srs_error_t SrsGb28181RtmpMuxer::write_h264_sps_pps(uint32_t dts, uint32_t pts)
|
|||
return srs_error_wrap(err, "write packet");
|
||||
}
|
||||
|
||||
// reset sps and pps.
|
||||
h264_sps_changed = false;
|
||||
h264_pps_changed = false;
|
||||
h264_sps_pps_sent = true;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -1157,6 +1150,12 @@ srs_error_t SrsGb28181RtmpMuxer::connect()
|
|||
void SrsGb28181RtmpMuxer::close()
|
||||
{
|
||||
srs_freep(sdk);
|
||||
|
||||
// cleared and sequence header will be sent again next time.
|
||||
// RTMP close may stop through API(rtmp_close)
|
||||
h264_sps = "";
|
||||
h264_pps = "";
|
||||
aac_specific_config = "";
|
||||
}
|
||||
|
||||
void SrsGb28181RtmpMuxer::rtmp_close(){
|
||||
|
|
|
@ -234,9 +234,6 @@ private:
|
|||
SrsRawH264Stream* avc;
|
||||
std::string h264_sps;
|
||||
std::string h264_pps;
|
||||
bool h264_sps_changed;
|
||||
bool h264_pps_changed;
|
||||
bool h264_sps_pps_sent;
|
||||
|
||||
SrsRawAacStream* aac;
|
||||
std::string aac_specific_config;
|
||||
|
|
|
@ -65,7 +65,6 @@ SrsGb28181SipSession::SrsGb28181SipSession(SrsGb28181SipService *c, SrsSipReques
|
|||
_peer_ip = "";
|
||||
_peer_port = 0;
|
||||
|
||||
_from = NULL;
|
||||
_fromlen = 0;
|
||||
}
|
||||
|
||||
|
@ -123,10 +122,10 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (config->print_sip_message)
|
||||
if (config->print_sip_message || true)
|
||||
{
|
||||
srs_trace("gb28181: request peer_ip=%s, peer_port=%d nbbuf=%d", peer_ip.c_str(), peer_port, nb_buf);
|
||||
srs_trace("gb28181: request recv message=%s", buf);
|
||||
//srs_trace("gb28181: request recv message=%s", buf);
|
||||
}
|
||||
|
||||
if (nb_buf < 10) {
|
||||
|
@ -175,7 +174,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
sip_session->set_register_status(SrsGb28181SipSessionRegisterOk);
|
||||
sip_session->set_register_time(srs_get_system_time());
|
||||
sip_session->set_reg_expires(req->expires);
|
||||
sip_session->set_sockaddr(from);
|
||||
sip_session->set_sockaddr((sockaddr)*from);
|
||||
sip_session->set_sockaddr_len(fromlen);
|
||||
sip_session->set_peer_ip(peer_ip);
|
||||
sip_session->set_peer_port(peer_port);
|
||||
|
@ -192,7 +191,7 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
sip_session->set_register_time(srs_get_system_time());
|
||||
sip_session->set_alive_status(SrsGb28181SipSessionAliveOk);
|
||||
sip_session->set_alive_time(srs_get_system_time());
|
||||
sip_session->set_sockaddr(from);
|
||||
sip_session->set_sockaddr((sockaddr)*from);
|
||||
sip_session->set_sockaddr_len(fromlen);
|
||||
sip_session->set_peer_port(peer_port);
|
||||
sip_session->set_peer_ip(peer_ip);
|
||||
|
@ -238,10 +237,12 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
srs_trace("gb28181: request client id=%s", req->sip_auth_id.c_str());
|
||||
|
||||
if (!sip_session){
|
||||
send_bye(req);
|
||||
srs_trace("gb28181: %s client not registered", req->sip_auth_id.c_str());
|
||||
return err;
|
||||
}
|
||||
|
||||
sip_session->set_sockaddr((sockaddr)*from);
|
||||
sip_session->set_sockaddr_len(fromlen);
|
||||
|
||||
if (sip_session->register_status() == SrsGb28181SipSessionUnkonw ||
|
||||
sip_session->alive_status() == SrsGb28181SipSessionUnkonw) {
|
||||
|
@ -273,6 +274,9 @@ srs_error_t SrsGb28181SipService::on_udp_sip(string peer_ip, int peer_port,
|
|||
srs_trace("gb28181: %s client not registered", req->sip_auth_id.c_str());
|
||||
return err;
|
||||
}
|
||||
|
||||
sip_session->set_sockaddr((sockaddr)*from);
|
||||
sip_session->set_sockaddr_len(fromlen);
|
||||
|
||||
sip_session->set_invite_status(SrsGb28181SipSessionBye);
|
||||
sip_session->set_invite_time(0);
|
||||
|
@ -356,7 +360,9 @@ int SrsGb28181SipService::send_invite(SrsSipRequest *req, string ip, int port,
|
|||
std::stringstream ss;
|
||||
sip->req_invite(ss, req, ip, port, ssrc);
|
||||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
sockaddr addr = sip_session->sockaddr_from();
|
||||
|
||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28181_SIP_INVITE_FAILED;
|
||||
}
|
||||
|
@ -391,7 +397,8 @@ int SrsGb28181SipService::send_bye(SrsSipRequest *req)
|
|||
std::stringstream ss;
|
||||
sip->req_bye(ss, req);
|
||||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
sockaddr addr = sip_session->sockaddr_from();
|
||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28181_SIP_BYE_FAILED;
|
||||
}
|
||||
|
@ -415,7 +422,8 @@ int SrsGb28181SipService::send_sip_raw_data(SrsSipRequest *req, std::string dat
|
|||
std::stringstream ss;
|
||||
ss << data;
|
||||
|
||||
if (send_message(sip_session->sockaddr_from(), sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
sockaddr addr = sip_session->sockaddr_from();
|
||||
if (send_message(&addr, sip_session->sockaddr_fromlen(), ss) <= 0)
|
||||
{
|
||||
return ERROR_GB28181_SIP_BYE_FAILED;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
std::string _peer_ip;
|
||||
int _peer_port;
|
||||
|
||||
sockaddr *_from;
|
||||
sockaddr _from;
|
||||
int _fromlen;
|
||||
SrsSipRequest *req;
|
||||
|
||||
|
@ -84,10 +84,11 @@ public:
|
|||
void set_reg_expires(int e) { _reg_expires = e;}
|
||||
void set_peer_ip(std::string i) { _peer_ip = i;}
|
||||
void set_peer_port(int o) { _peer_port = o;}
|
||||
void set_sockaddr(sockaddr *f) { _from = f;}
|
||||
void set_sockaddr(sockaddr f) { _from = f;}
|
||||
void set_sockaddr_len(int l) { _fromlen = l;}
|
||||
void set_request(SrsSipRequest *r) { req->copy(r);}
|
||||
|
||||
|
||||
SrsGb28181SipSessionStatusType register_status() { return _register_status;}
|
||||
SrsGb28181SipSessionStatusType alive_status() { return _alive_status;}
|
||||
SrsGb28181SipSessionStatusType invite_status() { return _invite_status;}
|
||||
|
@ -98,7 +99,7 @@ public:
|
|||
int reg_expires() { return _reg_expires;}
|
||||
std::string peer_ip() { return _peer_ip;}
|
||||
int peer_port() { return _peer_port;}
|
||||
sockaddr* sockaddr_from() { return _from;}
|
||||
sockaddr sockaddr_from() { return _from;}
|
||||
int sockaddr_fromlen() { return _fromlen;}
|
||||
SrsSipRequest request() { return *req;}
|
||||
|
||||
|
|
Loading…
Reference in a new issue