From 7f081b417868f5215df4405a4b354256ec702e2b Mon Sep 17 00:00:00 2001 From: "jinxue.cgh" Date: Wed, 23 Dec 2020 15:13:21 +0800 Subject: [PATCH] RTC: Refine TWCC from 200ms to 50ms --- trunk/src/app/srs_app_log.hpp | 1 + trunk/src/app/srs_app_rtc_conn.cpp | 18 +++++++++++++++++- trunk/src/app/srs_app_rtc_conn.hpp | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_log.hpp b/trunk/src/app/srs_app_log.hpp index 5ae58059a..e6b82c4eb 100644 --- a/trunk/src/app/srs_app_log.hpp +++ b/trunk/src/app/srs_app_log.hpp @@ -38,6 +38,7 @@ #define TAG_DTLS_ALERT "DTLS_ALERT" #define TAG_DTLS_HANG "DTLS_HANG" #define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB" +#define TAG_LARGE_TIMER "LARGE_TIMER" // Use memory/disk cache and donot flush when write log. // it's ok to use it without config, which will log to console, and default trace level. diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 36724d557..dc9b46fa6 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -59,6 +59,7 @@ using namespace std; #include #define SRS_TICKID_RTCP 0 +#define SRS_TICKID_TWCC 2 ISrsRtcTransport::ISrsRtcTransport() { @@ -908,7 +909,7 @@ srs_error_t SrsRtcPlayStream::do_request_keyframe(uint32_t ssrc, SrsContextId ci SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid) { - timer_ = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS); + timer_ = new SrsHourGlass(this, 10 * SRS_UTIME_MILLISECONDS); cid_ = cid; is_started = false; @@ -927,6 +928,7 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon twcc_fb_count_ = 0; pli_worker_ = new SrsRtcPLIWorker(this); + last_time_send_twcc_ = 0; } SrsRtcPublishStream::~SrsRtcPublishStream() @@ -1000,6 +1002,10 @@ srs_error_t SrsRtcPublishStream::start() return err; } + if ((err = timer_->tick(SRS_TICKID_TWCC, 50 * SRS_UTIME_MILLISECONDS)) != srs_success) { + return srs_error_wrap(err, "twcc tick"); + } + if ((err = timer_->tick(SRS_TICKID_RTCP, 200 * SRS_UTIME_MILLISECONDS)) != srs_success) { return srs_error_wrap(err, "rtcp tick"); } @@ -1297,6 +1303,14 @@ srs_error_t SrsRtcPublishStream::send_periodic_twcc() { srs_error_t err = srs_success; + if (last_time_send_twcc_) { + srs_utime_t duration = srs_duration(last_time_send_twcc_, srs_get_system_time()); + if (duration > 80 * SRS_UTIME_MILLISECONDS) { + srs_warn2(TAG_LARGE_TIMER, "send_twcc interval exceeded %dms > 100ms", srsu2msi(duration)); + } + } + last_time_send_twcc_ = srs_get_system_time(); + if (!rtcp_twcc_.need_feedback()) { return err; } @@ -1457,7 +1471,9 @@ srs_error_t SrsRtcPublishStream::notify(int type, srs_utime_t interval, srs_utim srs_warn("XR err %s", srs_error_desc(err).c_str()); srs_freep(err); } + } + if (type == SRS_TICKID_TWCC) { // We should not depends on the received packet, // instead we should send feedback every Nms. if ((err = send_periodic_twcc()) != srs_success) { diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index 65509b7d0..e04c9671e 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -341,6 +341,7 @@ private: SrsRtcpTWCC rtcp_twcc_; SrsRtpExtensionTypes extension_types_; bool is_started; + srs_utime_t last_time_send_twcc_; public: SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid); virtual ~SrsRtcPublishStream();