1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

RTC: Refine TWCC from 200ms to 50ms

This commit is contained in:
jinxue.cgh 2020-12-23 15:13:21 +08:00 committed by winlin
parent ec212b7413
commit 7f081b4178
3 changed files with 19 additions and 1 deletions

View file

@ -38,6 +38,7 @@
#define TAG_DTLS_ALERT "DTLS_ALERT" #define TAG_DTLS_ALERT "DTLS_ALERT"
#define TAG_DTLS_HANG "DTLS_HANG" #define TAG_DTLS_HANG "DTLS_HANG"
#define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB" #define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB"
#define TAG_LARGE_TIMER "LARGE_TIMER"
// Use memory/disk cache and donot flush when write log. // 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. // it's ok to use it without config, which will log to console, and default trace level.

View file

@ -59,6 +59,7 @@ using namespace std;
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#define SRS_TICKID_RTCP 0 #define SRS_TICKID_RTCP 0
#define SRS_TICKID_TWCC 2
ISrsRtcTransport::ISrsRtcTransport() 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) 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; cid_ = cid;
is_started = false; is_started = false;
@ -927,6 +928,7 @@ SrsRtcPublishStream::SrsRtcPublishStream(SrsRtcConnection* session, const SrsCon
twcc_fb_count_ = 0; twcc_fb_count_ = 0;
pli_worker_ = new SrsRtcPLIWorker(this); pli_worker_ = new SrsRtcPLIWorker(this);
last_time_send_twcc_ = 0;
} }
SrsRtcPublishStream::~SrsRtcPublishStream() SrsRtcPublishStream::~SrsRtcPublishStream()
@ -1000,6 +1002,10 @@ srs_error_t SrsRtcPublishStream::start()
return err; 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) { if ((err = timer_->tick(SRS_TICKID_RTCP, 200 * SRS_UTIME_MILLISECONDS)) != srs_success) {
return srs_error_wrap(err, "rtcp tick"); return srs_error_wrap(err, "rtcp tick");
} }
@ -1297,6 +1303,14 @@ srs_error_t SrsRtcPublishStream::send_periodic_twcc()
{ {
srs_error_t err = srs_success; 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()) { if (!rtcp_twcc_.need_feedback()) {
return err; 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_warn("XR err %s", srs_error_desc(err).c_str());
srs_freep(err); srs_freep(err);
} }
}
if (type == SRS_TICKID_TWCC) {
// We should not depends on the received packet, // We should not depends on the received packet,
// instead we should send feedback every Nms. // instead we should send feedback every Nms.
if ((err = send_periodic_twcc()) != srs_success) { if ((err = send_periodic_twcc()) != srs_success) {

View file

@ -341,6 +341,7 @@ private:
SrsRtcpTWCC rtcp_twcc_; SrsRtcpTWCC rtcp_twcc_;
SrsRtpExtensionTypes extension_types_; SrsRtpExtensionTypes extension_types_;
bool is_started; bool is_started;
srs_utime_t last_time_send_twcc_;
public: public:
SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid); SrsRtcPublishStream(SrsRtcConnection* session, const SrsContextId& cid);
virtual ~SrsRtcPublishStream(); virtual ~SrsRtcPublishStream();