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:
parent
5144794044
commit
573449f1b0
7 changed files with 51 additions and 17 deletions
|
@ -158,6 +158,7 @@ For previous versions, please read:
|
||||||
|
|
||||||
## V4 changes
|
## V4 changes
|
||||||
|
|
||||||
|
* v4.0, 2020-04-04, For [#307][bug #307], refine RTC latency from 600ms to 200ms. 4.0.20
|
||||||
* v4.0, 2020-04-03, For [#307][bug #307], build SRTP with openssl to improve performance. 4.0.19
|
* v4.0, 2020-04-03, For [#307][bug #307], build SRTP with openssl to improve performance. 4.0.19
|
||||||
* v4.0, 2020-03-31, For [#1500][bug #1500], support push stream by GB28181. 4.0.18
|
* v4.0, 2020-03-31, For [#1500][bug #1500], support push stream by GB28181. 4.0.18
|
||||||
* v4.0, 2020-03-31, Play stream by WebRTC on iOS/Android/PC browser. 4.0.17
|
* v4.0, 2020-03-31, Play stream by WebRTC on iOS/Android/PC browser. 4.0.17
|
||||||
|
|
|
@ -421,6 +421,14 @@ vhost rtc.vhost.srs.com {
|
||||||
# default: transcode
|
# default: transcode
|
||||||
aac transcode;
|
aac transcode;
|
||||||
}
|
}
|
||||||
|
# whether enable min delay mode for vhost.
|
||||||
|
# For RTC, we recommend to set to on.
|
||||||
|
min_latency on;
|
||||||
|
play {
|
||||||
|
# set the MW(merged-write) latency in ms.
|
||||||
|
# For RTC, we recommend lower value, such as 0.
|
||||||
|
mw_latency 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
|
@ -444,7 +452,8 @@ vhost scope.vhost.srs.com {
|
||||||
# 1. disable the publish.mr for vhost.
|
# 1. disable the publish.mr for vhost.
|
||||||
# 2. use timeout for cond wait for consumer queue.
|
# 2. use timeout for cond wait for consumer queue.
|
||||||
# @see https://github.com/ossrs/srs/issues/257
|
# @see https://github.com/ossrs/srs/issues/257
|
||||||
# default: off
|
# default: off (for RTMP/HTTP-FLV)
|
||||||
|
# default: on (for WebRTC)
|
||||||
min_latency off;
|
min_latency off;
|
||||||
|
|
||||||
# whether enable the TCP_NODELAY
|
# whether enable the TCP_NODELAY
|
||||||
|
@ -645,7 +654,8 @@ vhost play.srs.com {
|
||||||
# SRS always set mw on, so we just set the latency value.
|
# SRS always set mw on, so we just set the latency value.
|
||||||
# the latency of stream >= mw_latency + mr_latency
|
# the latency of stream >= mw_latency + mr_latency
|
||||||
# the value recomment is [300, 1800]
|
# the value recomment is [300, 1800]
|
||||||
# default: 350
|
# default: 350 (for RTMP/HTTP-FLV)
|
||||||
|
# default: 0 (for WebRTC)
|
||||||
mw_latency 350;
|
mw_latency 350;
|
||||||
|
|
||||||
# the minimal packets send interval in ms,
|
# the minimal packets send interval in ms,
|
||||||
|
|
|
@ -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);
|
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);
|
SrsConfDirective* conf = get_vhost(vhost);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
@ -5148,20 +5151,29 @@ srs_utime_t SrsConfig::get_mw_sleep(string vhost)
|
||||||
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
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);
|
SrsConfDirective* conf = get_vhost(vhost);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
return SRS_PERF_MIN_LATENCY_ENABLED;
|
return DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = conf->get("min_latency");
|
conf = conf->get("min_latency");
|
||||||
if (!conf || conf->arg0().empty()) {
|
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)
|
bool SrsConfig::get_tcp_nodelay(string vhost)
|
||||||
{
|
{
|
||||||
|
|
|
@ -605,14 +605,14 @@ public:
|
||||||
// @param vhost, the vhost to get the mr sleep time.
|
// @param vhost, the vhost to get the mr sleep time.
|
||||||
// TODO: FIXME: add utest for mr config.
|
// TODO: FIXME: add utest for mr config.
|
||||||
virtual srs_utime_t get_mr_sleep(std::string vhost);
|
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.
|
// @param vhost, the vhost to get the mw sleep time.
|
||||||
// TODO: FIXME: add utest for mw config.
|
// 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.
|
// Whether min latency mode enabled.
|
||||||
// @param vhost, the vhost to get the min_latency.
|
// @param vhost, the vhost to get the min_latency.
|
||||||
// TODO: FIXME: add utest for 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.
|
// Whether enable tcp nodelay for all clients of vhost.
|
||||||
virtual bool get_tcp_nodelay(std::string vhost);
|
virtual bool get_tcp_nodelay(std::string vhost);
|
||||||
// The minimal send interval in srs_utime_t.
|
// The minimal send interval in srs_utime_t.
|
||||||
|
|
|
@ -507,21 +507,31 @@ srs_error_t SrsRtcSenderThread::cycle()
|
||||||
rtc_session->request.get_stream_url().c_str(), ::getpid(), source->source_id());
|
rtc_session->request.get_stream_url().c_str(), ::getpid(), source->source_id());
|
||||||
|
|
||||||
SrsConsumer* consumer = NULL;
|
SrsConsumer* consumer = NULL;
|
||||||
|
SrsAutoFree(SrsConsumer, consumer);
|
||||||
if ((err = source->create_consumer(NULL, consumer)) != srs_success) {
|
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());
|
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) {
|
while (true) {
|
||||||
if ((err = trd->pull()) != srs_success) {
|
if ((err = trd->pull()) != srs_success) {
|
||||||
return srs_error_wrap(err, "rtc sender thread");
|
return srs_error_wrap(err, "rtc sender thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsMessageArray msgs(SRS_PERF_MW_MSGS);
|
|
||||||
|
|
||||||
#ifdef SRS_PERF_QUEUE_COND_WAIT
|
#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
|
#endif
|
||||||
|
|
||||||
int msg_count = 0;
|
int msg_count = 0;
|
||||||
|
|
|
@ -124,6 +124,7 @@
|
||||||
#define SRS_PERF_QUEUE_COND_WAIT
|
#define SRS_PERF_QUEUE_COND_WAIT
|
||||||
#ifdef SRS_PERF_QUEUE_COND_WAIT
|
#ifdef SRS_PERF_QUEUE_COND_WAIT
|
||||||
#define SRS_PERF_MW_MIN_MSGS 8
|
#define SRS_PERF_MW_MIN_MSGS 8
|
||||||
|
#define SRS_PERF_MW_MIN_MSGS_FOR_RTC 0
|
||||||
#endif
|
#endif
|
||||||
/**
|
/**
|
||||||
* the default value of vhost for
|
* the default value of vhost for
|
||||||
|
|
|
@ -24,6 +24,6 @@
|
||||||
#ifndef SRS_CORE_VERSION4_HPP
|
#ifndef SRS_CORE_VERSION4_HPP
|
||||||
#define SRS_CORE_VERSION4_HPP
|
#define SRS_CORE_VERSION4_HPP
|
||||||
|
|
||||||
#define SRS_VERSION4_REVISION 19
|
#define SRS_VERSION4_REVISION 20
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue