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

For #307, refine RTC latency from 600ms to 200ms. 4.0.20

This commit is contained in:
winlin 2020-04-04 15:36:35 +08:00
parent 5144794044
commit 573449f1b0
7 changed files with 51 additions and 17 deletions

View file

@ -5126,9 +5126,12 @@ srs_utime_t SrsConfig::get_mr_sleep(string vhost)
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
}
srs_utime_t SrsConfig::get_mw_sleep(string vhost)
srs_utime_t SrsConfig::get_mw_sleep(string vhost, bool is_rtc)
{
static srs_utime_t DEFAULT = SRS_PERF_MW_SLEEP;
static srs_utime_t SYS_DEFAULT = SRS_PERF_MW_SLEEP;
static srs_utime_t RTC_DEFAULT = 0;
srs_utime_t DEFAULT = is_rtc? RTC_DEFAULT : SYS_DEFAULT;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
@ -5148,19 +5151,28 @@ srs_utime_t SrsConfig::get_mw_sleep(string vhost)
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
}
bool SrsConfig::get_realtime_enabled(string vhost)
bool SrsConfig::get_realtime_enabled(string vhost, bool is_rtc)
{
static bool SYS_DEFAULT = SRS_PERF_MIN_LATENCY_ENABLED;
static bool RTC_DEFAULT = true;
bool DEFAULT = is_rtc? RTC_DEFAULT : SYS_DEFAULT;
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return SRS_PERF_MIN_LATENCY_ENABLED;
return DEFAULT;
}
conf = conf->get("min_latency");
if (!conf || conf->arg0().empty()) {
return SRS_PERF_MIN_LATENCY_ENABLED;
return DEFAULT;
}
if (is_rtc) {
return SRS_CONF_PERFER_TRUE(conf->arg0());
} else {
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
return SRS_CONF_PERFER_FALSE(conf->arg0());
}
bool SrsConfig::get_tcp_nodelay(string vhost)

View file

@ -605,14 +605,14 @@ public:
// @param vhost, the vhost to get the mr sleep time.
// TODO: FIXME: add utest for mr config.
virtual srs_utime_t get_mr_sleep(std::string vhost);
// Get the mw sleep time in srs_utime_t for vhost.
// Get the mw_latency, mw sleep time in srs_utime_t for vhost.
// @param vhost, the vhost to get the mw sleep time.
// TODO: FIXME: add utest for mw config.
virtual srs_utime_t get_mw_sleep(std::string vhost);
virtual srs_utime_t get_mw_sleep(std::string vhost, bool is_rtc = false);
// Whether min latency mode enabled.
// @param vhost, the vhost to get the min_latency.
// TODO: FIXME: add utest for min_latency.
virtual bool get_realtime_enabled(std::string vhost);
virtual bool get_realtime_enabled(std::string vhost, bool is_rtc = false);
// Whether enable tcp nodelay for all clients of vhost.
virtual bool get_tcp_nodelay(std::string vhost);
// The minimal send interval in srs_utime_t.

View file

@ -507,21 +507,31 @@ srs_error_t SrsRtcSenderThread::cycle()
rtc_session->request.get_stream_url().c_str(), ::getpid(), source->source_id());
SrsConsumer* consumer = NULL;
SrsAutoFree(SrsConsumer, consumer);
if ((err = source->create_consumer(NULL, consumer)) != srs_success) {
return srs_error_wrap(err, "rtc create consumer, source url=%s", rtc_session->request.get_stream_url().c_str());
}
SrsAutoFree(SrsConsumer, consumer);
// TODO: FIXME: Support reload.
SrsRequest* req = &rtc_session->request;
bool realtime = _srs_config->get_realtime_enabled(req->vhost, true);
srs_utime_t mw_sleep = _srs_config->get_mw_sleep(req->vhost, true);
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
while (true) {
if ((err = trd->pull()) != srs_success) {
return srs_error_wrap(err, "rtc sender thread");
}
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
#ifdef SRS_PERF_QUEUE_COND_WAIT
consumer->wait(0, SRS_PERF_MW_SLEEP);
if (realtime) {
// for realtime, min required msgs is 0, send when got one+ msgs.
consumer->wait(0, mw_sleep);
} else {
// for no-realtime, got some msgs then send.
consumer->wait(SRS_PERF_MW_MIN_MSGS_FOR_RTC, mw_sleep);
}
#endif
int msg_count = 0;

View file

@ -124,6 +124,7 @@
#define SRS_PERF_QUEUE_COND_WAIT
#ifdef SRS_PERF_QUEUE_COND_WAIT
#define SRS_PERF_MW_MIN_MSGS 8
#define SRS_PERF_MW_MIN_MSGS_FOR_RTC 0
#endif
/**
* the default value of vhost for

View file

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION4_HPP
#define SRS_CORE_VERSION4_HPP
#define SRS_VERSION4_REVISION 19
#define SRS_VERSION4_REVISION 20
#endif