RTC: Set to alive when got any packet

pull/1969/head
winlin 4 years ago
parent 8bf677e3c8
commit 7c682a99c9

@ -1912,8 +1912,6 @@ srs_error_t SrsRtcConnection::on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r)
return err;
}
last_stun_time = srs_get_system_time();
// We are running in the ice-lite(server) mode. If client have multi network interface,
// we only choose one candidate pair which is determined by client.
update_sendonly_socket(skt);
@ -2203,11 +2201,16 @@ srs_error_t SrsRtcConnection::start_publish(std::string stream_uri)
return err;
}
bool SrsRtcConnection::is_stun_timeout()
bool SrsRtcConnection::is_alive()
{
return last_stun_time + session_timeout < srs_get_system_time();
}
void SrsRtcConnection::alive()
{
last_stun_time = srs_get_system_time();
}
void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
{
// TODO: FIXME: Refine performance.

@ -449,8 +449,10 @@ private:
// The address list, client may use multiple addresses.
std::map<std::string, SrsUdpMuxSocket*> peer_addresses_;
private:
// TODO: FIXME: Rename it.
// The timeout of session, keep alive by STUN ping pong.
srs_utime_t session_timeout;
// TODO: FIXME: Rename it.
srs_utime_t last_stun_time;
private:
// For each RTC session, we use a specified cid for debugging logs.
@ -521,7 +523,8 @@ public:
srs_error_t on_dtls_alert(std::string type, std::string desc);
srs_error_t start_play(std::string stream_uri);
srs_error_t start_publish(std::string stream_uri);
bool is_stun_timeout();
bool is_alive();
void alive();
void update_sendonly_socket(SrsUdpMuxSocket* skt);
// interface ISrsHourGlass
public:

@ -312,6 +312,11 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
}
}
// When got any packet, the session is alive now.
if (session) {
session->alive();
}
// Notify hijack to handle the UDP packet.
if (hijacker) {
bool consumed = false;
@ -586,7 +591,7 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
// Check all sessions and dispose the dead sessions.
for (int i = 0; i < (int)_srs_rtc_manager->size(); i++) {
SrsRtcConnection* session = dynamic_cast<SrsRtcConnection*>(_srs_rtc_manager->at(i));
if (!session || !session->is_stun_timeout() || session->disposing_) {
if (!session || !session->is_alive() || session->disposing_) {
continue;
}

Loading…
Cancel
Save