diff --git a/trunk/conf/compatible.conf b/trunk/conf/compatible.conf index e9a1d677af..e59c27ee6a 100644 --- a/trunk/conf/compatible.conf +++ b/trunk/conf/compatible.conf @@ -21,15 +21,25 @@ http_stream { dir ./objs/nginx/html; } vhost __defaultVhost__ { - # for SRS2. - refer github.com github.io; - refer_publish github.com github.io; - refer_play github.com github.io; - # for SRS1. http { enabled on; mount [vhost]/hls; dir ./objs/nginx/html/hls; } + + # for SRS2. + refer github.com github.io; + refer_publish github.com github.io; + refer_play github.com github.io; + + # for SRS2 + publish_1stpkt_timeout 20000; + publish_normal_timeout 7000; + + # for SRS2 + mr { + enabled off; + latency 350; + } } diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 183aef1ab8..33b2dce662 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -334,40 +334,6 @@ vhost security.srs.com { } } -# the MR(merged-read) setting for publisher. -# the MW(merged-write) settings for player. -vhost mrw.srs.com { - # whether enable min delay mode for vhost. - # for min latence mode: - # 1. disable the mr for vhost. - # 2. use timeout for cond wait for consumer queue. - # @see https://github.com/simple-rtmp-server/srs/issues/257 - # default: off - min_latency off; - # about MR, read https://github.com/simple-rtmp-server/srs/issues/241 - mr { - # whether enable the MR(merged-read) - # default: off - enabled on; - # the latency in ms for MR(merged-read), - # the performance+ when latency+, and memory+, - # memory(buffer) = latency * kbps / 8 - # for example, latency=500ms, kbps=3000kbps, each publish connection will consume - # memory = 500 * 3000 / 8 = 187500B = 183KB - # when there are 2500 publisher, the total memory of SRS atleast: - # 183KB * 2500 = 446MB - # the value recomment is [300, 2000] - # default: 350 - latency 350; - } - # set the MW(merged-write) latency in ms. - # SRS always set mw on, so we just set the latency value. - # the latency of stream >= mw_latency + mr_latency - # the value recomment is [300, 1800] - # default: 350 - mw_latency 350; -} - # vhost for edge, edge and origin is the same vhost vhost same.edge.srs.com { # the mode of vhost, local or remote. @@ -966,6 +932,58 @@ vhost debug.srs.com { debug_srs_upnode on; } +# the publish specified configs +vhost publish.srs.com { + # the config for FMLE/Flash publisher, which push RTMP to SRS. + publish { + # about MR, read https://github.com/simple-rtmp-server/srs/issues/241 + # when enabled the mr, SRS will read as large as possible. + # default: off + mr off; + # the latency in ms for MR(merged-read), + # the performance+ when latency+, and memory+, + # memory(buffer) = latency * kbps / 8 + # for example, latency=500ms, kbps=3000kbps, each publish connection will consume + # memory = 500 * 3000 / 8 = 187500B = 183KB + # when there are 2500 publisher, the total memory of SRS atleast: + # 183KB * 2500 = 446MB + # the value recomment is [300, 2000] + # default: 350 + mr_latency 350; + + # the 1st packet timeout in ms for encoder. + # default: 20000 + firstpkt_timeout 20000; + # the normal packet timeout in ms for encoder. + # default: 5000 + normal_timeout 7000; + } +} + +# the MR(merged-read) setting for publisher. +# the MW(merged-write) settings for player. +vhost mrw.srs.com { + # whether enable min delay mode for vhost. + # for min latence mode: + # 1. disable the publish.mr for vhost. + # 2. use timeout for cond wait for consumer queue. + # @see https://github.com/simple-rtmp-server/srs/issues/257 + # default: off + min_latency off; + # set the MW(merged-write) latency in ms. + # SRS always set mw on, so we just set the latency value. + # the latency of stream >= mw_latency + mr_latency + # the value recomment is [300, 1800] + # default: 350 + mw_latency 350; + + # @see publish.srs.com + publish { + mr off; + mr_latenct 350; + } +} + # the vhost for min delay, donot cache any stream. vhost min.delay.com { # @see vhost mrw.srs.com for detail. @@ -1019,12 +1037,12 @@ vhost stream.control.com { # while the sequence header is not changed yet. # default: off reduce_sequence_header on; - # the 1st packet timeout in ms for encoder. - # default: 20000 - publish_1stpkt_timeout 20000; - # the normal packet timeout in ms for encoder. - # default: 5000 - publish_normal_timeout 7000; + + # @see publish.srs.com + publish { + firstpkt_timeout 20000; + normal_timeout 7000; + } } # the vhost which forward publish streams. diff --git a/trunk/conf/full.one.vhost.conf b/trunk/conf/full.one.vhost.conf index eb7f375899..f108560795 100644 --- a/trunk/conf/full.one.vhost.conf +++ b/trunk/conf/full.one.vhost.conf @@ -66,17 +66,20 @@ vhost vhost.srs.com { atc_auto on; min_latency on; - mr { - enabled off; - } mw_latency 100; gop_cache off; queue_length 10; tcp_nodelay on; send_min_interval 10.0; reduce_sequence_header on; - publish_1stpkt_timeout 20000; - publish_normal_timeout 7000; + + publish { + mr off; + mr_latency 350; + + firstpkt_timeout 20000; + normal_timeout 7000; + } refer { enabled off; diff --git a/trunk/conf/realtime.conf b/trunk/conf/realtime.conf index a87f293f4f..ac11885a55 100644 --- a/trunk/conf/realtime.conf +++ b/trunk/conf/realtime.conf @@ -8,9 +8,9 @@ vhost __defaultVhost__ { gop_cache off; queue_length 10; min_latency on; - mr { - enabled off; - } mw_latency 100; tcp_nodelay on; + publish { + mr off; + } } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 209349efbf..d628ce19f6 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -816,16 +816,16 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) srs_trace("vhost %s reload exec success.", vhost.c_str()); } - // mr, only one per vhost - if (!srs_directive_equals(new_vhost->get("mr"), old_vhost->get("mr"))) { + // publish, only one per vhost + if (!srs_directive_equals(new_vhost->get("publish"), old_vhost->get("publish"))) { for (it = subscribes.begin(); it != subscribes.end(); ++it) { ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_vhost_mr(vhost)) != ERROR_SUCCESS) { - srs_error("vhost %s notify subscribes mr failed. ret=%d", vhost.c_str(), ret); + if ((ret = subscribe->on_reload_vhost_publish(vhost)) != ERROR_SUCCESS) { + srs_error("vhost %s notify subscribes publish failed. ret=%d", vhost.c_str(), ret); return ret; } } - srs_trace("vhost %s reload mr success.", vhost.c_str()); + srs_trace("vhost %s reload publish success.", vhost.c_str()); } // chunk_size, only one per vhost. @@ -876,30 +876,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) srs_trace("vhost %s reload tcp_nodelay success.", vhost.c_str()); } - // publish_1stpkt_timeout, only one per vhost - if (!srs_directive_equals(new_vhost->get("publish_1stpkt_timeout"), old_vhost->get("publish_1stpkt_timeout"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_vhost_p1stpt(vhost)) != ERROR_SUCCESS) { - srs_error("vhost %s notify subscribes p1stpt failed. ret=%d", vhost.c_str(), ret); - return ret; - } - } - srs_trace("vhost %s reload p1stpt success.", vhost.c_str()); - } - - // publish_normal_timeout, only one per vhost - if (!srs_directive_equals(new_vhost->get("publish_normal_timeout"), old_vhost->get("publish_normal_timeout"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_vhost_pnt(vhost)) != ERROR_SUCCESS) { - srs_error("vhost %s notify subscribes pnt failed. ret=%d", vhost.c_str(), ret); - return ret; - } - } - srs_trace("vhost %s reload pnt success.", vhost.c_str()); - } - // min_latency, only one per vhost if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) { for (it = subscribes.begin(); it != subscribes.end(); ++it) { @@ -1798,20 +1774,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) if ((dir = vhost->get("min_latency")) != NULL) { obj->set("min_latency", dir->dumps_arg0_to_boolean()); } - if ((dir = vhost->get("mr")) != NULL) { - SrsAmf0Object* mr = SrsAmf0Any::object(); - obj->set("mr", mr); - - for (int i = 0; i < (int)dir->directives.size(); i++) { - SrsConfDirective* sdir = dir->directives.at(i); - - if (sdir->name == "enabled") { - mr->set("enabled", sdir->dumps_arg0_to_boolean()); - } else if (sdir->name == "latency") { - mr->set("latency", sdir->dumps_arg0_to_number()); - } - } - } if ((dir = vhost->get("mw_latency")) != NULL) { obj->set("mw_latency", dir->dumps_arg0_to_number()); } @@ -1834,11 +1796,25 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj) if ((dir = vhost->get("reduce_sequence_header")) != NULL) { obj->set("reduce_sequence_header", dir->dumps_arg0_to_boolean()); } - if ((dir = vhost->get("publish_1stpkt_timeout")) != NULL) { - obj->set("publish_1stpkt_timeout", dir->dumps_arg0_to_number()); - } - if ((dir = vhost->get("publish_normal_timeout")) != NULL) { - obj->set("publish_normal_timeout", dir->dumps_arg0_to_number()); + + // publish + if ((dir = vhost->get("publish")) != NULL) { + SrsAmf0Object* publish = SrsAmf0Any::object(); + obj->set("publish", publish); + + for (int i = 0; i < (int)dir->directives.size(); i++) { + SrsConfDirective* sdir = dir->directives.at(i); + + if (sdir->name == "mr") { + publish->set("mr", sdir->dumps_arg0_to_boolean()); + } else if (sdir->name == "mr_latency") { + publish->set("mr_latency", sdir->dumps_arg0_to_number()); + } else if (sdir->name == "firstpkt_timeout") { + publish->set("firstpkt_timeout", sdir->dumps_arg0_to_number()); + } else if (sdir->name == "normal_timeout") { + publish->set("normal_timeout", sdir->dumps_arg0_to_number()); + } + } } // refer @@ -2702,9 +2678,8 @@ int SrsConfig::check_config() && n != "time_jitter" && n != "mix_correct" && n != "atc" && n != "atc_auto" && n != "debug_srs_upnode" - && n != "mr" && n != "mw_latency" && n != "min_latency" + && n != "publish" && n != "mw_latency" && n != "min_latency" && n != "tcp_nodelay" && n != "send_min_interval" && n != "reduce_sequence_header" - && n != "publish_1stpkt_timeout" && n != "publish_normal_timeout" && n != "security" && n != "http_remux" && n != "http_static" && n != "hds" && n != "exec" ) { @@ -2742,12 +2717,12 @@ int SrsConfig::check_config() return ret; } } - } else if (n == "mr") { + } else if (n == "publish") { for (int j = 0; j < (int)conf->directives.size(); j++) { string m = conf->at(j)->name.c_str(); - if (m != "enabled" && m != "latency") { + if (m != "mr" && m != "mr_latency" && m != "firstpkt_timeout" && m != "normal_timeout") { ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("unsupported vhost mr directive %s, ret=%d", m.c_str(), ret); + srs_error("unsupported vhost publish directive %s, ret=%d", m.c_str(), ret); return ret; } } @@ -3463,12 +3438,12 @@ bool SrsConfig::get_mr_enabled(string vhost) return SRS_PERF_MR_ENABLED; } - conf = conf->get("mr"); + conf = conf->get("publish"); if (!conf) { return SRS_PERF_MR_ENABLED; } - conf = conf->get("enabled"); + conf = conf->get("mr"); if (!conf || conf->arg0().empty()) { return SRS_PERF_MR_ENABLED; } @@ -3483,12 +3458,12 @@ int SrsConfig::get_mr_sleep_ms(string vhost) return SRS_PERF_MR_SLEEP; } - conf = conf->get("mr"); + conf = conf->get("publish"); if (!conf) { return SRS_PERF_MR_SLEEP; } - conf = conf->get("latency"); + conf = conf->get("mr_latency"); if (!conf || conf->arg0().empty()) { return SRS_PERF_MR_SLEEP; } @@ -3587,7 +3562,12 @@ int SrsConfig::get_publish_1stpkt_timeout(string vhost) return DEFAULT; } - conf = conf->get("publish_1stpkt_timeout"); + conf = conf->get("publish"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("firstpkt_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } @@ -3607,7 +3587,12 @@ int SrsConfig::get_publish_normal_timeout(string vhost) return DEFAULT; } - conf = conf->get("publish_normal_timeout"); + conf = conf->get("publish"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("normal_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } @@ -5677,7 +5662,7 @@ int srs_config_transform_vhost(SrsConfDirective* root) { int ret = ERROR_SUCCESS; - for (int i = 0; i < root->directives.size(); i++) { + for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* dir = root->directives.at(i); // SRS2.0, rename global http_stream to http_server. @@ -5694,6 +5679,7 @@ int srs_config_transform_vhost(SrsConfDirective* root) continue; } + // for each directive of vhost. std::vector::iterator it; for (it = dir->directives.begin(); it != dir->directives.end();) { SrsConfDirective* conf = *it; @@ -5736,6 +5722,66 @@ int srs_config_transform_vhost(SrsConfDirective* root) continue; } + // SRS3.0, change the mr style + // SRS2: + // vhost { mr { enabled; latency; } } + // SRS3+: + // vhost { publish { mr; mr_latency; } } + if (conf->name == "mr") { + it = dir->directives.erase(it); + + SrsConfDirective* publish = dir->get_or_create("publish"); + + SrsConfDirective* enabled = conf->get("enabled"); + if (enabled) { + SrsConfDirective* mr = publish->get_or_create("mr"); + mr->args = enabled->args; + } + + SrsConfDirective* latency = conf->get("latency"); + if (latency) { + SrsConfDirective* mr_latency = publish->get_or_create("mr_latency"); + mr_latency->args = latency->args; + } + + srs_freep(conf); + continue; + } + + // SRS3.0, change the publish_1stpkt_timeout + // SRS2: + // vhost { publish_1stpkt_timeout; } + // SRS3+: + // vhost { publish { firstpkt_timeout; } } + if (conf->name == "publish_1stpkt_timeout") { + it = dir->directives.erase(it); + + SrsConfDirective* publish = dir->get_or_create("publish"); + + SrsConfDirective* firstpkt_timeout = publish->get_or_create("firstpkt_timeout"); + firstpkt_timeout->args = conf->args; + + srs_freep(conf); + continue; + } + + // SRS3.0, change the publish_normal_timeout + // SRS2: + // vhost { publish_normal_timeout; } + // SRS3+: + // vhost { publish { normal_timeout; } } + if (conf->name == "publish_normal_timeout") { + it = dir->directives.erase(it); + + SrsConfDirective* publish = dir->get_or_create("publish"); + + SrsConfDirective* normal_timeout = publish->get_or_create("normal_timeout"); + normal_timeout->args = conf->args; + + srs_freep(conf); + continue; + } + ++it; } } diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 56dc7fd2bf..1c863da03b 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -424,7 +424,7 @@ void SrsPublishRecvThread::on_read(ssize_t nread) } #endif -int SrsPublishRecvThread::on_reload_vhost_mr(string vhost) +int SrsPublishRecvThread::on_reload_vhost_publish(string vhost) { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 345bf78373..f777d4eb44 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -206,7 +206,7 @@ class SrsPublishRecvThread : virtual public ISrsMessageHandler #endif // interface ISrsReloadHandler public: - virtual int on_reload_vhost_mr(std::string vhost); + virtual int on_reload_vhost_publish(std::string vhost); virtual int on_reload_vhost_realtime(std::string vhost); private: virtual void set_socket_buffer(int sleep_ms); diff --git a/trunk/src/app/srs_app_reload.cpp b/trunk/src/app/srs_app_reload.cpp index 551ca50414..66dd0be97a 100644 --- a/trunk/src/app/srs_app_reload.cpp +++ b/trunk/src/app/srs_app_reload.cpp @@ -170,7 +170,7 @@ int ISrsReloadHandler::on_reload_vhost_dvr(string /*vhost*/) return ERROR_SUCCESS; } -int ISrsReloadHandler::on_reload_vhost_mr(string /*vhost*/) +int ISrsReloadHandler::on_reload_vhost_publish(string /*vhost*/) { return ERROR_SUCCESS; } @@ -195,16 +195,6 @@ int ISrsReloadHandler::on_reload_vhost_realtime(string /*vhost*/) return ERROR_SUCCESS; } -int ISrsReloadHandler::on_reload_vhost_p1stpt(string /*vhost*/) -{ - return ERROR_SUCCESS; -} - -int ISrsReloadHandler::on_reload_vhost_pnt(string /*vhost*/) -{ - return ERROR_SUCCESS; -} - int ISrsReloadHandler::on_reload_vhost_chunk_size(string /*vhost*/) { return ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_reload.hpp b/trunk/src/app/srs_app_reload.hpp index c8a9442c52..e7dfdc9ad3 100644 --- a/trunk/src/app/srs_app_reload.hpp +++ b/trunk/src/app/srs_app_reload.hpp @@ -73,13 +73,11 @@ class ISrsReloadHandler virtual int on_reload_vhost_hls(std::string vhost); virtual int on_reload_vhost_hds(std::string vhost); virtual int on_reload_vhost_dvr(std::string vhost); - virtual int on_reload_vhost_mr(std::string vhost); + virtual int on_reload_vhost_publish(std::string vhost); virtual int on_reload_vhost_mw(std::string vhost); virtual int on_reload_vhost_smi(std::string vhost); virtual int on_reload_vhost_tcp_nodelay(std::string vhost); virtual int on_reload_vhost_realtime(std::string vhost); - virtual int on_reload_vhost_p1stpt(std::string vhost); - virtual int on_reload_vhost_pnt(std::string vhost); virtual int on_reload_vhost_chunk_size(std::string vhost); virtual int on_reload_vhost_transcode(std::string vhost); virtual int on_reload_vhost_exec(std::string vhost); diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 739be55fba..ecf027893e 100755 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -294,7 +294,7 @@ int SrsRtmpConn::on_reload_vhost_realtime(string vhost) return ret; } -int SrsRtmpConn::on_reload_vhost_p1stpt(string vhost) +int SrsRtmpConn::on_reload_vhost_publish(string vhost) { int ret = ERROR_SUCCESS; @@ -308,20 +308,9 @@ int SrsRtmpConn::on_reload_vhost_p1stpt(string vhost) publish_1stpkt_timeout = p1stpt; } - return ret; -} - -int SrsRtmpConn::on_reload_vhost_pnt(string vhost) -{ - int ret = ERROR_SUCCESS; - - if (req->vhost != vhost) { - return ret; - } - int pnt = _srs_config->get_publish_normal_timeout(req->vhost); if (pnt != publish_normal_timeout) { - srs_trace("p1stpt changed %d=>%d", publish_normal_timeout, pnt); + srs_trace("pnt changed %d=>%d", publish_normal_timeout, pnt); publish_normal_timeout = pnt; } diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index c7bbd6577c..f44b742484 100755 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -107,8 +107,7 @@ class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandl virtual int on_reload_vhost_smi(std::string vhost); virtual int on_reload_vhost_tcp_nodelay(std::string vhost); virtual int on_reload_vhost_realtime(std::string vhost); - virtual int on_reload_vhost_p1stpt(std::string vhost); - virtual int on_reload_vhost_pnt(std::string vhost); + virtual int on_reload_vhost_publish(std::string vhost); // interface IKbpsDelta public: virtual void resample();