1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

For #307, support config RTC session timeout

This commit is contained in:
winlin 2020-04-08 13:30:28 +08:00
parent 8e0f83fdd2
commit e6e8605304
5 changed files with 36 additions and 4 deletions

View file

@ -434,6 +434,10 @@ vhost rtc.vhost.srs.com {
# discard Discard aac audio packet.
# default: transcode
aac transcode;
# The timeout in seconds for session timeout.
# Client will send ping(STUN binding request) to server, we use it as heartbeat.
# default: 30
stun_timeout 30;
}
# whether enable min delay mode for vhost.
# For RTC, we recommend to set to on.

View file

@ -4780,6 +4780,24 @@ bool SrsConfig::get_rtc_aac_discard(string vhost)
return conf->arg0() == "discard";
}
srs_utime_t SrsConfig::get_rtc_stun_timeout(string vhost)
{
static srs_utime_t DEFAULT = 30 * SRS_UTIME_SECONDS;
SrsConfDirective* conf = get_rtc(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("stun_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
}
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);

View file

@ -525,11 +525,13 @@ public:
virtual bool get_rtc_server_ecdsa();
virtual int get_rtc_server_sendmmsg();
virtual bool get_rtc_server_encrypt();
virtual bool get_rtc_server_encrypt();
SrsConfDirective* get_rtc(std::string vhost);
bool get_rtc_enabled(std::string vhost);
bool get_rtc_bframe_discard(std::string vhost);
bool get_rtc_aac_discard(std::string vhost);
srs_utime_t get_rtc_stun_timeout(std::string vhost);
// vhost specified section
public:

View file

@ -635,6 +635,9 @@ SrsRtcSession::SrsRtcSession(SrsRtcServer* rtc_svr, const SrsRequest& req, const
cid = context_id;
encrypt = true;
// TODO: FIXME: Support reload.
sessionStunTimeout = _srs_config->get_rtc_stun_timeout(req.vhost);
}
SrsRtcSession::~SrsRtcSession()
@ -951,7 +954,7 @@ block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
srs_error_t SrsRtcSession::on_connection_established(SrsUdpMuxSocket* udp_mux_skt)
{
srs_trace("rtc session=%s, connection established", id().c_str());
srs_trace("rtc session=%s, timeout=%dms connection established", id().c_str(), srsu2msi(sessionStunTimeout));
return start_play(udp_mux_skt);
}
@ -988,6 +991,11 @@ srs_error_t SrsRtcSession::start_play(SrsUdpMuxSocket* udp_mux_skt)
return err;
}
bool SrsRtcSession::is_stun_timeout()
{
return last_stun_time + sessionStunTimeout < srs_get_system_time();
}
srs_error_t SrsRtcSession::on_dtls(SrsUdpMuxSocket* udp_mux_skt)
{
return dtls_session->on_dtls(udp_mux_skt);

View file

@ -65,8 +65,6 @@ const uint8_t kSLI = 2;
const uint8_t kRPSI = 3;
const uint8_t kAFB = 15;
const srs_utime_t kSrsRtcSessionStunTimeoutUs = 10*1000*1000LL;
enum SrsRtcSessionStateType
{
// TODO: FIXME: Should prefixed by enum name.
@ -169,6 +167,8 @@ private:
// Sepcifies by HTTP API, query encrypt, optional.
// TODO: FIXME: Support reload.
bool encrypt;
// The timeout of session, keep alive by STUN ping pong.
srs_utime_t sessionStunTimeout;
public:
SrsRequest request;
SrsSource* source;
@ -202,7 +202,7 @@ public:
srs_error_t on_connection_established(SrsUdpMuxSocket* udp_mux_skt);
srs_error_t start_play(SrsUdpMuxSocket* udp_mux_skt);
public:
bool is_stun_timeout() { return last_stun_time + kSrsRtcSessionStunTimeoutUs < srs_get_system_time(); }
bool is_stun_timeout();
private:
srs_error_t check_source();
private: