diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 06de1fe87..fbcaa5f13 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -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. diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index bd805b8ab..761a1a42b 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -449,8 +449,10 @@ private: // The address list, client may use multiple addresses. std::map 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: diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index 92affba4c..9e8dd1bbf 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -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(_srs_rtc_manager->at(i)); - if (!session || !session->is_stun_timeout() || session->disposing_) { + if (!session || !session->is_alive() || session->disposing_) { continue; }