From 1fd83d9314a420857c441d82b392e25e1ef8b916 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 17 Sep 2015 13:36:02 +0800 Subject: [PATCH] refine the order. --- trunk/src/app/srs_app_config.cpp | 1041 +++++++++++----------- trunk/src/app/srs_app_config.hpp | 175 ++-- trunk/src/app/srs_app_conn.cpp | 36 +- trunk/src/app/srs_app_conn.hpp | 22 + trunk/src/app/srs_app_edge.cpp | 17 +- trunk/src/app/srs_app_edge.hpp | 4 + trunk/src/app/srs_app_hls.cpp | 34 +- trunk/src/app/srs_app_http_client.cpp | 6 + trunk/src/app/srs_app_http_conn.cpp | 54 +- trunk/src/app/srs_app_http_conn.hpp | 6 + trunk/src/app/srs_app_http_hooks.cpp | 4 +- trunk/src/app/srs_app_http_stream.cpp | 12 +- trunk/src/app/srs_app_rtmp_conn.cpp | 24 +- trunk/src/app/srs_app_rtmp_conn.hpp | 5 + trunk/src/app/srs_app_source.cpp | 5 + trunk/src/app/srs_app_source.hpp | 2 + trunk/src/app/srs_app_statistic.hpp | 1 + trunk/src/app/srs_app_thread.cpp | 5 + trunk/src/app/srs_app_thread.hpp | 6 + trunk/src/app/srs_app_utility.cpp | 14 + trunk/src/app/srs_app_utility.hpp | 3 + trunk/src/kernel/srs_kernel_consts.hpp | 1 + trunk/src/kernel/srs_kernel_ts.cpp | 14 +- trunk/src/kernel/srs_kernel_ts.hpp | 8 + trunk/src/main/srs_main_server.cpp | 10 +- trunk/src/protocol/srs_protocol_json.cpp | 30 + trunk/src/protocol/srs_protocol_json.hpp | 2 + trunk/src/protocol/srs_rtmp_utility.cpp | 11 +- trunk/src/utest/srs_utest_reload.cpp | 182 ++-- trunk/src/utest/srs_utest_reload.hpp | 2 +- 30 files changed, 985 insertions(+), 751 deletions(-) mode change 100755 => 100644 trunk/src/app/srs_app_rtmp_conn.cpp mode change 100755 => 100644 trunk/src/app/srs_app_rtmp_conn.hpp mode change 100755 => 100644 trunk/src/app/srs_app_source.cpp mode change 100755 => 100644 trunk/src/app/srs_app_source.hpp diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 31b5d0390..082995164 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -46,9 +46,12 @@ using namespace std; #include #include #include -#include #include #include +#include +#include +#include +#include using namespace _srs_internal; @@ -112,6 +115,504 @@ bool is_common_space(char ch) return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF); } +namespace _srs_internal +{ + SrsConfigBuffer::SrsConfigBuffer() + { + line = 1; + + pos = last = start = NULL; + end = start; + } + + SrsConfigBuffer::~SrsConfigBuffer() + { + srs_freep(start); + } + + int SrsConfigBuffer::fullfill(const char* filename) + { + int ret = ERROR_SUCCESS; + + SrsFileReader reader; + + // open file reader. + if ((ret = reader.open(filename)) != ERROR_SUCCESS) { + srs_error("open conf file error. ret=%d", ret); + return ret; + } + + // read all. + int filesize = (int)reader.filesize(); + + // create buffer + srs_freep(start); + pos = last = start = new char[filesize]; + end = start + filesize; + + // read total content from file. + ssize_t nread = 0; + if ((ret = reader.read(start, filesize, &nread)) != ERROR_SUCCESS) { + srs_error("read file read error. expect %d, actual %d bytes, ret=%d", + filesize, nread, ret); + return ret; + } + + return ret; + } + + bool SrsConfigBuffer::empty() + { + return pos >= end; + } +}; + +bool srs_directive_equals_self(SrsConfDirective* a, SrsConfDirective* b) +{ + // both NULL, equal. + if (!a && !b) { + return true; + } + + if (!a || !b) { + return false; + } + + if (a->name != b->name) { + return false; + } + + if (a->args.size() != b->args.size()) { + return false; + } + + for (int i = 0; i < (int)a->args.size(); i++) { + if (a->args.at(i) != b->args.at(i)) { + return false; + } + } + + if (a->directives.size() != b->directives.size()) { + return false; + } + + return true; +} + +bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) +{ + // both NULL, equal. + if (!a && !b) { + return true; + } + + if (!srs_directive_equals_self(a, b)) { + return false; + } + + for (int i = 0; i < (int)a->directives.size(); i++) { + SrsConfDirective* a0 = a->at(i); + SrsConfDirective* b0 = b->at(i); + + if (!srs_directive_equals(a0, b0)) { + return false; + } + } + + return true; +} + +bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, string except) +{ + // both NULL, equal. + if (!a && !b) { + return true; + } + + if (!srs_directive_equals_self(a, b)) { + return false; + } + + for (int i = 0; i < (int)a->directives.size(); i++) { + SrsConfDirective* a0 = a->at(i); + SrsConfDirective* b0 = b->at(i); + + // donot compare the except child directive. + if (a0->name == except) { + continue; + } + + if (!srs_directive_equals(a0, b0, except)) { + return false; + } + } + + return true; +} + +bool srs_config_hls_is_on_error_ignore(string strategy) +{ + return strategy == "ignore"; +} + +bool srs_config_hls_is_on_error_continue(string strategy) +{ + return strategy == "continue"; +} + +bool srs_config_ingest_is_file(string type) +{ + return type == "file"; +} + +bool srs_config_ingest_is_stream(string type) +{ + return type == "stream"; +} + +bool srs_config_dvr_is_plan_segment(string plan) +{ + return plan == "segment"; +} + +bool srs_config_dvr_is_plan_session(string plan) +{ + return plan == "session"; +} + +bool srs_config_dvr_is_plan_append(string plan) +{ + return plan == "append"; +} + +bool srs_stream_caster_is_udp(string caster) +{ + return caster == "mpegts_over_udp"; +} + +bool srs_stream_caster_is_rtsp(string caster) +{ + return caster == "rtsp"; +} + +bool srs_stream_caster_is_flv(string caster) +{ + return caster == "flv"; +} + +bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req) +{ + static bool DEFAULT = true; + + if (!dvr_apply || dvr_apply->args.empty()) { + return DEFAULT; + } + + vector& args = dvr_apply->args; + if (args.size() == 1 && dvr_apply->arg0() == "all") { + return true; + } + + string id = req->app + "/" + req->stream; + if (::find(args.begin(), args.end(), id) != args.end()) { + return true; + } + + return false; +} + +string srs_config_bool2switch(const string& sbool) +{ + return sbool == "true"? "on":"off"; +} + +int srs_config_transform_vhost(SrsConfDirective* root) +{ + int ret = ERROR_SUCCESS; + + 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. + // SRS1: + // http_stream {} + // SRS2+: + // http_server {} + if (dir->name == "http_stream") { + dir->name = "http_server"; + continue; + } + + if (!dir->is_vhost()) { + continue; + } + + // for each directive of vhost. + std::vector::iterator it; + for (it = dir->directives.begin(); it != dir->directives.end();) { + SrsConfDirective* conf = *it; + string n = conf->name; + + // SRS2.0, rename vhost http to http_static + // SRS1: + // vhost { http {} } + // SRS2+: + // vhost { http_static {} } + if (n == "http") { + conf->name = "http_static"; + ++it; + continue; + } + + // SRS3.0, change the refer style + // SRS1/2: + // vhost { refer; refer_play; refer_publish; } + // SRS3+: + // vhost { refer { enabled; all; play; publish; } } + if ((n == "refer" && conf->directives.empty()) || n == "refer_play" || n == "refer_publish") { + // remove the old one first, for name duplicated. + it = dir->directives.erase(it); + + SrsConfDirective* refer = dir->get_or_create("refer"); + refer->get_or_create("enabled", "on"); + if (n == "refer") { + SrsConfDirective* all = refer->get_or_create("all"); + all->args = conf->args; + } else if (n == "play") { + SrsConfDirective* play = refer->get_or_create("play"); + play->args = conf->args; + } else if (n == "publish") { + SrsConfDirective* publish = refer->get_or_create("publish"); + publish->args = conf->args; + } + + // remove the old directive. + srs_freep(conf); + continue; + } + + // SRS3.0, change the mr style + // SRS2: + // vhost { mr { enabled; latency; } } + // SRS3+: + // vhost { publish { mr; mr_latency; } } + if (n == "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 (n == "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 (n == "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; + } + + // SRS3.0, change the folowing like a shadow: + // time_jitter, mix_correct, atc, atc_auto, mw_latency, gop_cache, queue_length + // SRS1/2: + // vhost { shadow; } + // SRS3+: + // vhost { play { shadow; } } + if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto" + || n == "mw_latency" || n == "gop_cache" || n == "queue_length" || n == "send_min_interval" + || n == "reduce_sequence_header" + ) { + it = dir->directives.erase(it); + + SrsConfDirective* play = dir->get_or_create("play"); + SrsConfDirective* shadow = play->get_or_create(conf->name); + shadow->args = conf->args; + + srs_freep(conf); + continue; + } + + // SRS3.0, change the forward. + // SRS1/2: + // vhost { forward; } + // SRS3+: + // vhost { forward { enabled; destination; } } + if (n == "forward" && conf->directives.empty()) { + conf->get_or_create("enabled")->set_arg0("on"); + + SrsConfDirective* destination = conf->get_or_create("destination"); + destination->args = conf->args; + conf->args.clear(); + + ++it; + continue; + } + + // SRS3.0, change the folowing like a shadow: + // mode, origin, token_traverse, vhost, debug_srs_upnode + // SRS1/2: + // vhost { shadow; } + // SRS3+: + // vhost { cluster { shadow; } } + if (n == "mode" || n == "origin" || n == "token_traverse" || n == "vhost" || n == "debug_srs_upnode") { + it = dir->directives.erase(it); + + SrsConfDirective* cluster = dir->get_or_create("cluster"); + SrsConfDirective* shadow = cluster->get_or_create(conf->name); + shadow->args = conf->args; + + srs_freep(conf); + continue; + } + + ++it; + } + } + + return ret; +} + +int srs_config_dumps_engine(SrsConfDirective* dir, SrsAmf0Object* engine) +{ + int ret = ERROR_SUCCESS; + + SrsConfDirective* conf = NULL; + + engine->set("id", dir->dumps_arg0_to_str()); + engine->set("enabled", SrsAmf0Any::boolean(_srs_config->get_engine_enabled(dir))); + + if ((conf = dir->get("iformat")) != NULL) { + engine->set("iformat", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("vfilter")) != NULL) { + SrsAmf0Object* vfilter = SrsAmf0Any::object(); + engine->set("vfilter", vfilter); + + for (int i = 0; i < (int)conf->directives.size(); i++) { + SrsConfDirective* sdir = conf->directives.at(i); + vfilter->set(sdir->name, sdir->dumps_arg0_to_str()); + } + } + + if ((conf = dir->get("vcodec")) != NULL) { + engine->set("vcodec", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("vbitrate")) != NULL) { + engine->set("vbitrate", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("vfps")) != NULL) { + engine->set("vfps", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("vwidth")) != NULL) { + engine->set("vwidth", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("vheight")) != NULL) { + engine->set("vheight", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("vthreads")) != NULL) { + engine->set("vthreads", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("vprofile")) != NULL) { + engine->set("vprofile", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("vpreset")) != NULL) { + engine->set("vpreset", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("vparams")) != NULL) { + SrsAmf0Object* vparams = SrsAmf0Any::object(); + engine->set("vparams", vparams); + + for (int i = 0; i < (int)conf->directives.size(); i++) { + SrsConfDirective* sdir = conf->directives.at(i); + vparams->set(sdir->name, sdir->dumps_arg0_to_str()); + } + } + + if ((conf = dir->get("acodec")) != NULL) { + engine->set("acodec", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("abitrate")) != NULL) { + engine->set("abitrate", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("asample_rate")) != NULL) { + engine->set("asample_rate", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("achannels")) != NULL) { + engine->set("achannels", conf->dumps_arg0_to_number()); + } + + if ((conf = dir->get("aparams")) != NULL) { + SrsAmf0Object* aparams = SrsAmf0Any::object(); + engine->set("aparams", aparams); + + for (int i = 0; i < (int)conf->directives.size(); i++) { + SrsConfDirective* sdir = conf->directives.at(i); + aparams->set(sdir->name, sdir->dumps_arg0_to_str()); + } + } + + if ((conf = dir->get("oformat")) != NULL) { + engine->set("oformat", conf->dumps_arg0_to_str()); + } + + if ((conf = dir->get("output")) != NULL) { + engine->set("output", conf->dumps_arg0_to_str()); + } + + return ret; +} + SrsConfDirective::SrsConfDirective() { } @@ -126,6 +627,22 @@ SrsConfDirective::~SrsConfDirective() directives.clear(); } +SrsConfDirective* SrsConfDirective::copy() +{ + SrsConfDirective* cp = new SrsConfDirective(); + + cp->conf_line = conf_line; + cp->name = name; + cp->args = args; + + for (int i = 0; i < (int)directives.size(); i++) { + SrsConfDirective* directive = directives.at(i); + cp->directives.push_back(directive->copy()); + } + + return cp; +} + string SrsConfDirective::arg0() { if (args.size() > 0) { @@ -429,22 +946,6 @@ int SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveType type) return ret; } -SrsConfDirective* SrsConfDirective::copy() -{ - SrsConfDirective* cp = new SrsConfDirective(); - - cp->conf_line = conf_line; - cp->name = name; - cp->args = args; - - for (int i = 0; i < (int)directives.size(); i++) { - SrsConfDirective* directive = directives.at(i); - cp->directives.push_back(directive->copy()); - } - - return cp; -} - // see: ngx_conf_read_token int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector& args, int& line_start) { @@ -932,7 +1433,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) srs_trace("ignore reload vhost, enabled old: %d, new: %d", get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost)); } - + return ret; } @@ -3114,7 +3615,7 @@ int SrsConfig::check_config() get_heartbeat_interval(), ret); return ret; } - + //////////////////////////////////////////////////////////////////////// // check stats //////////////////////////////////////////////////////////////////////// @@ -3168,6 +3669,7 @@ int SrsConfig::check_config() get_http_stream_listen().c_str(), ret); return ret; } + //////////////////////////////////////////////////////////////////////// // check log name and level //////////////////////////////////////////////////////////////////////// @@ -3217,6 +3719,9 @@ int SrsConfig::check_config() } } + //////////////////////////////////////////////////////////////////////// + // check vhosts. + //////////////////////////////////////////////////////////////////////// vector vhosts; get_vhosts(vhosts); for (int n = 0; n < (int)vhosts.size(); n++) { @@ -6241,501 +6746,3 @@ SrsConfDirective* SrsConfig::get_stats_disk_device() return conf; } -namespace _srs_internal -{ - SrsConfigBuffer::SrsConfigBuffer() - { - line = 1; - - pos = last = start = NULL; - end = start; - } - - SrsConfigBuffer::~SrsConfigBuffer() - { - srs_freep(start); - } - - int SrsConfigBuffer::fullfill(const char* filename) - { - int ret = ERROR_SUCCESS; - - SrsFileReader reader; - - // open file reader. - if ((ret = reader.open(filename)) != ERROR_SUCCESS) { - srs_error("open conf file error. ret=%d", ret); - return ret; - } - - // read all. - int filesize = (int)reader.filesize(); - - // create buffer - srs_freep(start); - pos = last = start = new char[filesize]; - end = start + filesize; - - // read total content from file. - ssize_t nread = 0; - if ((ret = reader.read(start, filesize, &nread)) != ERROR_SUCCESS) { - srs_error("read file read error. expect %d, actual %d bytes, ret=%d", - filesize, nread, ret); - return ret; - } - - return ret; - } - - bool SrsConfigBuffer::empty() - { - return pos >= end; - } -}; - -bool srs_directive_equals_self(SrsConfDirective* a, SrsConfDirective* b) -{ - // both NULL, equal. - if (!a && !b) { - return true; - } - - if (!a || !b) { - return false; - } - - if (a->name != b->name) { - return false; - } - - if (a->args.size() != b->args.size()) { - return false; - } - - for (int i = 0; i < (int)a->args.size(); i++) { - if (a->args.at(i) != b->args.at(i)) { - return false; - } - } - - if (a->directives.size() != b->directives.size()) { - return false; - } - - return true; -} - -bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) -{ - // both NULL, equal. - if (!a && !b) { - return true; - } - - if (!srs_directive_equals_self(a, b)) { - return false; - } - - for (int i = 0; i < (int)a->directives.size(); i++) { - SrsConfDirective* a0 = a->at(i); - SrsConfDirective* b0 = b->at(i); - - if (!srs_directive_equals(a0, b0)) { - return false; - } - } - - return true; -} - -bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, string except) -{ - // both NULL, equal. - if (!a && !b) { - return true; - } - - if (!srs_directive_equals_self(a, b)) { - return false; - } - - for (int i = 0; i < (int)a->directives.size(); i++) { - SrsConfDirective* a0 = a->at(i); - SrsConfDirective* b0 = b->at(i); - - // donot compare the except child directive. - if (a0->name == except) { - continue; - } - - if (!srs_directive_equals(a0, b0, except)) { - return false; - } - } - - return true; -} - -bool srs_config_hls_is_on_error_ignore(string strategy) -{ - return strategy == "ignore"; -} - -bool srs_config_hls_is_on_error_continue(string strategy) -{ - return strategy == "continue"; -} - -bool srs_config_ingest_is_file(string type) -{ - return type == "file"; -} - -bool srs_config_ingest_is_stream(string type) -{ - return type == "stream"; -} - -bool srs_config_dvr_is_plan_segment(string plan) -{ - return plan == "segment"; -} - -bool srs_config_dvr_is_plan_session(string plan) -{ - return plan == "session"; -} - -bool srs_config_dvr_is_plan_append(string plan) -{ - return plan == "append"; -} - -bool srs_stream_caster_is_udp(string caster) -{ - return caster == "mpegts_over_udp"; -} - -bool srs_stream_caster_is_rtsp(string caster) -{ - return caster == "rtsp"; -} - -bool srs_stream_caster_is_flv(string caster) -{ - return caster == "flv"; -} - -bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req) -{ - static bool DEFAULT = true; - - if (!dvr_apply || dvr_apply->args.empty()) { - return DEFAULT; - } - - vector& args = dvr_apply->args; - if (args.size() == 1 && dvr_apply->arg0() == "all") { - return true; - } - - string id = req->app + "/" + req->stream; - if (::find(args.begin(), args.end(), id) != args.end()) { - return true; - } - - return false; -} - -string srs_config_bool2switch(const string& sbool) -{ - return sbool == "true"? "on":"off"; -} - -int srs_config_transform_vhost(SrsConfDirective* root) -{ - int ret = ERROR_SUCCESS; - - 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. - // SRS1: - // http_stream {} - // SRS2+: - // http_server {} - if (dir->name == "http_stream") { - dir->name = "http_server"; - continue; - } - - if (!dir->is_vhost()) { - continue; - } - - // for each directive of vhost. - std::vector::iterator it; - for (it = dir->directives.begin(); it != dir->directives.end();) { - SrsConfDirective* conf = *it; - string n = conf->name; - - // SRS2.0, rename vhost http to http_static - // SRS1: - // vhost { http {} } - // SRS2+: - // vhost { http_static {} } - if (n == "http") { - conf->name = "http_static"; - ++it; - continue; - } - - // SRS3.0, change the refer style - // SRS1/2: - // vhost { refer; refer_play; refer_publish; } - // SRS3+: - // vhost { refer { enabled; all; play; publish; } } - if ((n == "refer" && conf->directives.empty()) || n == "refer_play" || n == "refer_publish") { - // remove the old one first, for name duplicated. - it = dir->directives.erase(it); - - SrsConfDirective* refer = dir->get_or_create("refer"); - refer->get_or_create("enabled", "on"); - if (n == "refer") { - SrsConfDirective* all = refer->get_or_create("all"); - all->args = conf->args; - } else if (n == "play") { - SrsConfDirective* play = refer->get_or_create("play"); - play->args = conf->args; - } else if (n == "publish") { - SrsConfDirective* publish = refer->get_or_create("publish"); - publish->args = conf->args; - } - - // remove the old directive. - srs_freep(conf); - continue; - } - - // SRS3.0, change the mr style - // SRS2: - // vhost { mr { enabled; latency; } } - // SRS3+: - // vhost { publish { mr; mr_latency; } } - if (n == "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 (n == "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 (n == "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; - } - - // SRS3.0, change the folowing like a shadow: - // time_jitter, mix_correct, atc, atc_auto, mw_latency, gop_cache, queue_length - // SRS1/2: - // vhost { shadow; } - // SRS3+: - // vhost { play { shadow; } } - if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto" - || n == "mw_latency" || n == "gop_cache" || n == "queue_length" || n == "send_min_interval" - || n == "reduce_sequence_header" - ) { - it = dir->directives.erase(it); - - SrsConfDirective* play = dir->get_or_create("play"); - SrsConfDirective* shadow = play->get_or_create(conf->name); - shadow->args = conf->args; - - srs_freep(conf); - continue; - } - - // SRS3.0, change the forward. - // SRS1/2: - // vhost { forward; } - // SRS3+: - // vhost { forward { enabled; destination; } } - if (n == "forward" && conf->directives.empty()) { - conf->get_or_create("enabled")->set_arg0("on"); - - SrsConfDirective* destination = conf->get_or_create("destination"); - destination->args = conf->args; - conf->args.clear(); - - ++it; - continue; - } - - // SRS3.0, change the folowing like a shadow: - // mode, origin, token_traverse, vhost, debug_srs_upnode - // SRS1/2: - // vhost { shadow; } - // SRS3+: - // vhost { cluster { shadow; } } - if (n == "mode" || n == "origin" || n == "token_traverse" || n == "vhost" || n == "debug_srs_upnode") { - it = dir->directives.erase(it); - - SrsConfDirective* cluster = dir->get_or_create("cluster"); - SrsConfDirective* shadow = cluster->get_or_create(conf->name); - shadow->args = conf->args; - - srs_freep(conf); - continue; - } - - ++it; - } - } - - return ret; -} - -int srs_config_dumps_engine(SrsConfDirective* dir, SrsAmf0Object* engine) -{ - int ret = ERROR_SUCCESS; - - SrsConfDirective* conf = NULL; - - engine->set("id", dir->dumps_arg0_to_str()); - engine->set("enabled", SrsAmf0Any::boolean(_srs_config->get_engine_enabled(dir))); - - if ((conf = dir->get("iformat")) != NULL) { - engine->set("iformat", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("vfilter")) != NULL) { - SrsAmf0Object* vfilter = SrsAmf0Any::object(); - engine->set("vfilter", vfilter); - - for (int i = 0; i < (int)conf->directives.size(); i++) { - SrsConfDirective* sdir = conf->directives.at(i); - vfilter->set(sdir->name, sdir->dumps_arg0_to_str()); - } - } - - if ((conf = dir->get("vcodec")) != NULL) { - engine->set("vcodec", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("vbitrate")) != NULL) { - engine->set("vbitrate", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("vfps")) != NULL) { - engine->set("vfps", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("vwidth")) != NULL) { - engine->set("vwidth", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("vheight")) != NULL) { - engine->set("vheight", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("vthreads")) != NULL) { - engine->set("vthreads", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("vprofile")) != NULL) { - engine->set("vprofile", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("vpreset")) != NULL) { - engine->set("vpreset", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("vparams")) != NULL) { - SrsAmf0Object* vparams = SrsAmf0Any::object(); - engine->set("vparams", vparams); - - for (int i = 0; i < (int)conf->directives.size(); i++) { - SrsConfDirective* sdir = conf->directives.at(i); - vparams->set(sdir->name, sdir->dumps_arg0_to_str()); - } - } - - if ((conf = dir->get("acodec")) != NULL) { - engine->set("acodec", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("abitrate")) != NULL) { - engine->set("abitrate", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("asample_rate")) != NULL) { - engine->set("asample_rate", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("achannels")) != NULL) { - engine->set("achannels", conf->dumps_arg0_to_number()); - } - - if ((conf = dir->get("aparams")) != NULL) { - SrsAmf0Object* aparams = SrsAmf0Any::object(); - engine->set("aparams", aparams); - - for (int i = 0; i < (int)conf->directives.size(); i++) { - SrsConfDirective* sdir = conf->directives.at(i); - aparams->set(sdir->name, sdir->dumps_arg0_to_str()); - } - } - - if ((conf = dir->get("oformat")) != NULL) { - engine->set("oformat", conf->dumps_arg0_to_str()); - } - - if ((conf = dir->get("output")) != NULL) { - engine->set("output", conf->dumps_arg0_to_str()); - } - - return ret; -} - diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 0bbf01032..eba92904a 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -31,9 +31,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include #include #include +#include +#include class SrsRequest; class SrsFileWriter; @@ -41,10 +44,89 @@ class SrsAmf0Object; class SrsAmf0StrictArray; class SrsAmf0Any; +class SrsConfig; +class SrsRequest; +class SrsJsonArray; +class SrsConfDirective; + + namespace _srs_internal { - class SrsConfigBuffer; -} + /** + * the buffer of config content. + */ + class SrsConfigBuffer + { + protected: + // last available position. + char* last; + // end of buffer. + char* end; + // start of buffer. + char* start; + public: + // current consumed position. + char* pos; + // current parsed line. + int line; + public: + SrsConfigBuffer(); + virtual ~SrsConfigBuffer(); + public: + /** + * fullfill the buffer with content of file specified by filename. + */ + virtual int fullfill(const char* filename); + /** + * whether buffer is empty. + */ + virtual bool empty(); + }; +}; + +/** + * deep compare directive. + */ +extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); +extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, std::string except); + +/** + * helper utilities, used for compare the consts values. + */ +extern bool srs_config_hls_is_on_error_ignore(std::string strategy); +extern bool srs_config_hls_is_on_error_continue(std::string strategy); +extern bool srs_config_ingest_is_file(std::string type); +extern bool srs_config_ingest_is_stream(std::string type); +extern bool srs_config_dvr_is_plan_segment(std::string plan); +extern bool srs_config_dvr_is_plan_session(std::string plan); +extern bool srs_config_dvr_is_plan_append(std::string plan); +extern bool srs_stream_caster_is_udp(std::string caster); +extern bool srs_stream_caster_is_rtsp(std::string caster); +extern bool srs_stream_caster_is_flv(std::string caster); +// whether the dvr_apply active the stream specified by req. +extern bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req); + +/** + * convert bool in str to on/off + */ +extern std::string srs_config_bool2switch(const std::string& sbool); + +/** + * parse loaded vhost directives to compatible mode. + * for exmaple, SRS1/2 use the follow refer style: + * refer a.domain.com b.domain.com; + * while SRS3 use the following: + * refer { + * enabled on; + * all a.domain.com b.domain.com; + * } + * so we must transform the vhost directive anytime load the config. + * @param root the root directive to transform, in and out parameter. + */ +extern int srs_config_transform_vhost(SrsConfDirective* root); + +// global config +extern SrsConfig* _srs_config; /** * the config directive. @@ -103,6 +185,13 @@ public: public: SrsConfDirective(); virtual ~SrsConfDirective(); +public: + /** + * deep copy the directive, for SrsConfig to use it to support reload in upyun cluster, + * for when reload the upyun dynamic config, the root will be changed, + * so need to copy it to an old root directive, and use the copy result to do reload. + */ + virtual SrsConfDirective* copy(); // args public: /** @@ -189,10 +278,6 @@ private: * 3. if ret flag indicates there are child-directives, read_conf(directive, block) recursively. */ virtual int parse_conf(_srs_internal::SrsConfigBuffer* buffer, SrsDirectiveType type); - /** - * deep copy the directive. - */ - virtual SrsConfDirective* copy(); /** * read a token from buffer. * a token, is the directive args and a flag indicates whether has child-directives. @@ -1291,83 +1376,5 @@ public: virtual SrsConfDirective* get_stats_disk_device(); }; -namespace _srs_internal -{ - /** - * the buffer of config content. - */ - class SrsConfigBuffer - { - protected: - // last available position. - char* last; - // end of buffer. - char* end; - // start of buffer. - char* start; - public: - // current consumed position. - char* pos; - // current parsed line. - int line; - public: - SrsConfigBuffer(); - virtual ~SrsConfigBuffer(); - public: - /** - * fullfill the buffer with content of file specified by filename. - */ - virtual int fullfill(const char* filename); - /** - * whether buffer is empty. - */ - virtual bool empty(); - }; -}; - -/** -* deep compare directive. - */ -extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b); -extern bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, std::string except); - -/** - * helper utilities, used for compare the consts values. - */ -extern bool srs_config_hls_is_on_error_ignore(std::string strategy); -extern bool srs_config_hls_is_on_error_continue(std::string strategy); -extern bool srs_config_ingest_is_file(std::string type); -extern bool srs_config_ingest_is_stream(std::string type); -extern bool srs_config_dvr_is_plan_segment(std::string plan); -extern bool srs_config_dvr_is_plan_session(std::string plan); -extern bool srs_config_dvr_is_plan_append(std::string plan); -extern bool srs_stream_caster_is_udp(std::string caster); -extern bool srs_stream_caster_is_rtsp(std::string caster); -extern bool srs_stream_caster_is_flv(std::string caster); -// whether the dvr_apply active the stream specified by req. -extern bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req); - -/** - * convert bool in str to on/off - */ -extern std::string srs_config_bool2switch(const std::string& sbool); - -/** - * parse loaded vhost directives to compatible mode. - * for exmaple, SRS1/2 use the follow refer style: - * refer a.domain.com b.domain.com; - * while SRS3 use the following: - * refer { - * enabled on; - * all a.domain.com b.domain.com; - * } - * so we must transform the vhost directive anytime load the config. - * @param root the root directive to transform, in and out parameter. - */ -extern int srs_config_transform_vhost(SrsConfDirective* root); - -// global config -extern SrsConfig* _srs_config; - #endif diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index 3aa88fbdb..e49465291 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include IConnectionManager::IConnectionManager() { @@ -42,7 +43,12 @@ SrsConnection::SrsConnection(IConnectionManager* cm, st_netfd_t c) stfd = c; disposed = false; expired = false; - + create_time = srs_get_system_time_ms(); + + skt = new SrsStSocket(c); + kbps = new SrsKbps(); + kbps->set_io(skt, skt); + // the client thread should reap itself, // so we never use joinable. // TODO: FIXME: maybe other thread need to stop it. @@ -53,10 +59,32 @@ SrsConnection::SrsConnection(IConnectionManager* cm, st_netfd_t c) SrsConnection::~SrsConnection() { dispose(); - + + srs_freep(kbps); + srs_freep(skt); srs_freep(pthread); } +void SrsConnection::resample() +{ + kbps->resample(); +} + +int64_t SrsConnection::get_send_bytes_delta() +{ + return kbps->get_send_bytes_delta(); +} + +int64_t SrsConnection::get_recv_bytes_delta() +{ + return kbps->get_recv_bytes_delta(); +} + +void SrsConnection::cleanup() +{ + kbps->cleanup(); +} + void SrsConnection::dispose() { if (disposed) { @@ -86,7 +114,7 @@ int SrsConnection::cycle() ip = srs_get_peer_ip(st_netfd_fileno(stfd)); - ret = do_cycle(); + int oret = ret = do_cycle(); // if socket io error, set to closed. if (srs_is_client_gracefully_close(ret)) { @@ -100,7 +128,7 @@ int SrsConnection::cycle() // client close peer. if (ret == ERROR_SOCKET_CLOSED) { - srs_warn("client disconnect peer. ret=%d", ret); + srs_warn("client disconnect peer. oret=%d, ret=%d", oret, ret); } return ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index ae48421ba..c319269b0 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -93,9 +93,31 @@ protected: * when expired, the connection must never be served and quit ASAP. */ bool expired; + /** + * the underlayer socket. + */ + SrsStSocket* skt; + /** + * connection total kbps. + * not only the rtmp or http connection, all type of connection are + * need to statistic the kbps of io. + * the SrsStatistic will use it indirectly to statistic the bytes delta of current connection. + */ + SrsKbps* kbps; + /** + * the create time in milliseconds. + * for current connection to log self create time and calculate the living time. + */ + int64_t create_time; public: SrsConnection(IConnectionManager* cm, st_netfd_t c); virtual ~SrsConnection(); +// interface IKbpsDelta +public: + virtual void resample(); + virtual int64_t get_send_bytes_delta(); + virtual int64_t get_recv_bytes_delta(); + virtual void cleanup(); public: /** * to dipose the connection. diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index f60bc7e6b..59fdf4e76 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -70,6 +70,7 @@ SrsEdgeIngester::SrsEdgeIngester() origin_index = 0; stream_id = 0; stfd = NULL; + curr_origin_server = ""; pthread = new SrsReusableThread2("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US); } @@ -118,6 +119,11 @@ void SrsEdgeIngester::stop() _source->on_unpublish(); } +string SrsEdgeIngester::get_curr_origin() +{ + return curr_origin_server; +} + int SrsEdgeIngester::cycle() { int ret = ERROR_SUCCESS; @@ -205,7 +211,7 @@ int SrsEdgeIngester::ingest() return ret; } } - + return ret; } @@ -352,9 +358,9 @@ int SrsEdgeIngester::connect_server(string& ep_server, string& ep_port) } // select the origin. - std::string server = conf->args.at(origin_index % conf->args.size()); + std::string server = curr_origin_server = conf->args.at(origin_index % conf->args.size()); origin_index = (origin_index + 1) % conf->args.size(); - + std::string s_port = SRS_CONSTS_RTMP_DEFAULT_PORT; int port = ::atoi(SRS_CONSTS_RTMP_DEFAULT_PORT); size_t pos = server.find(":"); @@ -754,6 +760,11 @@ void SrsPlayEdge::on_all_client_stop() } } +string SrsPlayEdge::get_curr_origin() +{ + return ingester->get_curr_origin(); +} + int SrsPlayEdge::on_ingest_play() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp index 949c387f3..8efb70999 100644 --- a/trunk/src/app/srs_app_edge.hpp +++ b/trunk/src/app/srs_app_edge.hpp @@ -89,6 +89,8 @@ private: SrsKbps* kbps; SrsRtmpClient* client; int origin_index; + // current origin server of current source. + std::string curr_origin_server; public: SrsEdgeIngester(); virtual ~SrsEdgeIngester(); @@ -96,6 +98,7 @@ public: virtual int initialize(SrsSource* source, SrsPlayEdge* edge, SrsRequest* req); virtual int start(); virtual void stop(); + virtual std::string get_curr_origin(); // interface ISrsReusableThread2Handler public: virtual int cycle(); @@ -182,6 +185,7 @@ public: * when all client stopped play, disconnect to origin. */ virtual void on_all_client_stop(); + virtual std::string get_curr_origin(); public: /** * when ingester start to play stream. diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 1cc63f9d4..00b93023f 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -387,13 +387,13 @@ int SrsHlsMuxer::deviation() int SrsHlsMuxer::initialize(ISrsHlsHandler* h) { int ret = ERROR_SUCCESS; - + handler = h; if ((ret = async->start()) != ERROR_SUCCESS) { return ret; } - + return ret; } @@ -724,7 +724,7 @@ int SrsHlsMuxer::segment_close(string log_desc) // when too large, it maybe timestamp corrupt. if (current->duration * 1000 >= SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS && (int)current->duration <= max_td) { segments.push_back(current); - + // use async to call the http hooks, for it will cause thread switch. if ((ret = async->execute(new SrsDvrAsyncCallOnHls( _srs_context->get_id(), req, @@ -733,12 +733,12 @@ int SrsHlsMuxer::segment_close(string log_desc) { return ret; } - + // use async to call the http hooks, for it will cause thread switch. if ((ret = async->execute(new SrsDvrAsyncCallOnHlsNotify(_srs_context->get_id(), req, current->uri))) != ERROR_SUCCESS) { return ret; } - + srs_info("%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64, log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration, current->segment_start_dts); @@ -749,12 +749,12 @@ int SrsHlsMuxer::segment_close(string log_desc) srs_error("notify handler for update ts failed. ret=%d", ret); return ret; } - + // close the muxer of finished segment. srs_freep(current->muxer); std::string full_path = current->full_path; current = NULL; - + // rename from tmp to real path std::string tmp_file = full_path + ".tmp"; if (should_write_file && rename(tmp_file.c_str(), full_path.c_str()) < 0) { @@ -766,11 +766,11 @@ int SrsHlsMuxer::segment_close(string log_desc) } else { // reuse current segment index. _sequence_no--; - + srs_trace("%s drop ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64"", log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration, current->segment_start_dts); - + // rename from tmp to real path std::string tmp_file = current->full_path + ".tmp"; if (should_write_file) { @@ -778,13 +778,13 @@ int SrsHlsMuxer::segment_close(string log_desc) srs_warn("ignore unlink path failed, file=%s.", tmp_file.c_str()); } } - + srs_freep(current); } - + // the segments to remove std::vector segment_to_remove; - + // shrink the segments. double duration = 0; int remove_index = -1; @@ -802,7 +802,7 @@ int SrsHlsMuxer::segment_close(string log_desc) segments.erase(segments.begin()); segment_to_remove.push_back(segment); } - + // refresh the m3u8, donot contains the removed ts ret = refresh_m3u8(); @@ -815,24 +815,24 @@ int SrsHlsMuxer::segment_close(string log_desc) srs_warn("cleanup unlink path failed, file=%s.", segment->full_path.c_str()); } } - + if (should_write_cache) { if ((ret = handler->on_remove_ts(req, segment->uri)) != ERROR_SUCCESS) { srs_warn("remove the ts from ram hls failed. ret=%d", ret); return ret; } } - + srs_freep(segment); } segment_to_remove.clear(); - + // check ret of refresh m3u8 if (ret != ERROR_SUCCESS) { srs_error("refresh m3u8 failed. ret=%d", ret); return ret; } - + return ret; } diff --git a/trunk/src/app/srs_app_http_client.cpp b/trunk/src/app/srs_app_http_client.cpp index fda78cec5..08f4b2b0c 100644 --- a/trunk/src/app/srs_app_http_client.cpp +++ b/trunk/src/app/srs_app_http_client.cpp @@ -44,6 +44,7 @@ SrsHttpClient::SrsHttpClient() skt = NULL; parser = NULL; timeout_us = 0; + port = 0; } SrsHttpClient::~SrsHttpClient() @@ -56,6 +57,11 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us) { int ret = ERROR_SUCCESS; + // disconnect first when h:p changed. + if ((!host.empty() && host != h) || (port != 0 && port != p)) { + disconnect(); + } + srs_freep(parser); parser = new SrsHttpParser(); diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index bab2c2953..e06d046ee 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -55,6 +55,9 @@ using namespace std; #include #include #include +#include +#include +#include #endif @@ -1204,47 +1207,57 @@ int SrsHttpConn::do_cycle() srs_error("http initialize http parser failed. ret=%d", ret); return ret; } - - // underlayer socket - SrsStSocket skt(stfd); - + // set the recv timeout, for some clients never disconnect the connection. // @see https://github.com/simple-rtmp-server/srs/issues/398 - skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); - + skt->set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); + + SrsRequest* last_req = NULL; + SrsAutoFree(SrsRequest, last_req); + // process http messages. while (!disposed) { ISrsHttpMessage* req = NULL; - + // get a http message - if ((ret = parser->parse_message(&skt, this, &req)) != ERROR_SUCCESS) { - return ret; + if ((ret = parser->parse_message(skt, this, &req)) != ERROR_SUCCESS) { + break; } // if SUCCESS, always NOT-NULL. srs_assert(req); - + // always free it in this scope. SrsAutoFree(ISrsHttpMessage, req); - + + // get the last request, for report the info of request on connection disconnect. + delete last_req; + SrsHttpMessage* hreq = dynamic_cast(req); + last_req = hreq->to_request(hreq->host()); + // may should discard the body. if ((ret = on_got_http_message(req)) != ERROR_SUCCESS) { - return ret; + break; } - + // ok, handle http request. - SrsHttpResponseWriter writer(&skt); + SrsHttpResponseWriter writer(skt); if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { - return ret; + break; } - + // donot keep alive, disconnect it. // @see https://github.com/simple-rtmp-server/srs/issues/399 if (!req->is_keep_alive()) { break; } } - + + int disc_ret = ERROR_SUCCESS; + if ((disc_ret = on_disconnect(last_req)) != ERROR_SUCCESS) { + srs_warn("connection on disconnect peer failed, but ignore this error. disc_ret=%d, ret=%d", disc_ret, ret); + } + return ret; } @@ -1266,6 +1279,13 @@ int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) return ret; } +int SrsHttpConn::on_disconnect(SrsRequest* req) +{ + int ret = ERROR_SUCCESS; + // TODO: implements it.s + return ret; +} + SrsResponseOnlyHttpConn::SrsResponseOnlyHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m) : SrsHttpConn(cm, fd, m) { diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index 829a023e6..aee2a91c5 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -406,6 +406,12 @@ protected: virtual int on_got_http_message(ISrsHttpMessage* msg) = 0; private: virtual int process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); + /** + * when the connection disconnect, call this method. + * e.g. log msg of connection and report to other system. + * @param request: request which is converted by the last http message. + */ + virtual int on_disconnect(SrsRequest* req); }; /** diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index dd93be76f..d7a9029bd 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -474,13 +474,13 @@ int SrsHttpHooks::do_post(SrsHttpClient* hc, std::string url, std::string req, i srs_error("res code error, ret=%d", ret); return ret; } - + if ((res_code->to_integer()) != ERROR_SUCCESS) { ret = ERROR_RESPONSE_CODE; srs_error("res code error, ret=%d, code=%d", ret, code); return ret; } - + return ret; } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 651174869..c317c9769 100644 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -54,6 +54,7 @@ using namespace std; #include #include #include +#include #endif @@ -494,6 +495,13 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) SrsAutoFree(SrsPithyPrint, pprint); SrsMessageArray msgs(SRS_PERF_MW_MSGS); + + // update the statistic when source disconveried. + SrsStatistic* stat = SrsStatistic::instance(); + if ((ret = stat->on_client(_srs_context->get_id(), req, NULL, SrsRtmpConnPlay)) != ERROR_SUCCESS) { + srs_error("stat client failed. ret=%d", ret); + return ret; + } // the memory writer. SrsStreamWriter writer(w); @@ -1132,7 +1140,7 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) if (ext.empty()) { return ret; } - + // find the actually request vhost. SrsConfDirective* vhost = _srs_config->get_vhost(request->host()); if (!vhost || !_srs_config->get_vhost_enabled(vhost)) { @@ -1179,7 +1187,7 @@ int SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandler** ph) return ret; } } - + // convert to concreate class. SrsHttpMessage* hreq = dynamic_cast(request); srs_assert(hreq); diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp old mode 100755 new mode 100644 index 206b864ce..94e5a17a4 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -53,6 +53,8 @@ using namespace std; #include #include #include +#include +#include // when stream is busy, for example, streaming is already // publishing, when a new client to request to publish, @@ -89,13 +91,13 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c) kbps = new SrsKbps(); kbps->set_io(skt, skt); wakable = NULL; - + mw_sleep = SRS_PERF_MW_SLEEP; mw_enabled = false; realtime = SRS_PERF_MIN_LATENCY_ENABLED; send_min_interval = 0; tcp_nodelay = false; - + _srs_config->subscribe(this); } @@ -208,8 +210,11 @@ int SrsRtmpConn::do_cycle() } ret = service_cycle(); - - http_hooks_on_close(); + + int disc_ret = ERROR_SUCCESS; + if ((disc_ret = on_disconnect()) != ERROR_SUCCESS) { + srs_warn("connection on disconnect peer failed, but ignore this error. disc_ret=%d, ret=%d", disc_ret, ret); + } return ret; } @@ -1308,6 +1313,17 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) return ret; } +int SrsRtmpConn::on_disconnect() +{ + int ret = ERROR_SUCCESS; + + http_hooks_on_close(); + + // TODO: implements it. + + return ret; +} + int SrsRtmpConn::http_hooks_on_connect() { int ret = ERROR_SUCCESS; diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp old mode 100755 new mode 100644 index 926d03f4a..bf9b8e12d --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -134,6 +134,11 @@ private: virtual int check_edge_token_traverse_auth(); virtual int connect_server(int origin_index, st_netfd_t* pstsock); virtual int do_token_traverse_auth(SrsRtmpClient* client); + /** + * when the connection disconnect, call this method. + * e.g. log msg of connection and report to other system. + */ + virtual int on_disconnect(); private: virtual int http_hooks_on_connect(); virtual void http_hooks_on_close(); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp old mode 100755 new mode 100644 index 928e2a474..919bb1298 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -2292,3 +2292,8 @@ void SrsSource::destroy_forwarders() forwarders.clear(); } +string SrsSource::get_curr_origin() +{ + return play_edge->get_curr_origin(); +} + diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp old mode 100755 new mode 100644 index e72be3238..cdf8be132 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -592,6 +592,8 @@ public: private: virtual int create_forwarders(); virtual void destroy_forwarders(); +public: + virtual std::string get_curr_origin(); }; #endif diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 330894865..86b71065b 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include #include #include diff --git a/trunk/src/app/srs_app_thread.cpp b/trunk/src/app/srs_app_thread.cpp index 274c16f6b..e4f5da414 100644 --- a/trunk/src/app/srs_app_thread.cpp +++ b/trunk/src/app/srs_app_thread.cpp @@ -435,6 +435,11 @@ void SrsReusableThread::stop() pthread->stop(); } +bool SrsReusableThread::can_loop() +{ + return pthread->can_loop(); +} + int SrsReusableThread::cid() { return pthread->cid(); diff --git a/trunk/src/app/srs_app_thread.hpp b/trunk/src/app/srs_app_thread.hpp index 8eb65dc0d..d00d94aa5 100644 --- a/trunk/src/app/srs_app_thread.hpp +++ b/trunk/src/app/srs_app_thread.hpp @@ -340,6 +340,12 @@ public: * @remark user can stop multiple times, ignore if already stopped. */ virtual void stop(); + /** + * whether the thread should loop, + * used for handler->cycle() which has a loop method, + * to check this method, break if false. + */ + virtual bool can_loop(); public: /** * get the context id. @see: ISrsThreadContext.get_id(). diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 3365fb204..ca28e7859 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -1483,3 +1483,17 @@ void srs_api_dump_summaries(SrsAmf0Object* obj) sys->set("conn_srs", SrsAmf0Any::number(nrs->nb_conn_srs)); } +string srs_join_vector_string(vector& vs, string separator) +{ + string str = ""; + + for (int i = 0; i < (int)vs.size(); i++) { + str += vs.at(i); + if (i != (int)vs.size() - 1) { + str += separator; + } + } + + return str; +} + diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index bc8661e37..cfee7de38 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -684,5 +684,8 @@ extern bool srs_is_boolean(const std::string& str); // dump summaries for /api/v1/summaries. extern void srs_api_dump_summaries(SrsAmf0Object* obj); +// join string in vector with indicated separator +extern std::string srs_join_vector_string(std::vector& vs, std::string separator); + #endif diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index 0f7765d7e..a334f9a04 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -42,6 +42,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. /////////////////////////////////////////////////////////// // default vhost of rtmp #define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__" +#define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__" // default port of rtmp #define SRS_CONSTS_RTMP_DEFAULT_PORT "1935" diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index 433aaa201..fb560e675 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -198,6 +198,7 @@ ISrsTsHandler::~ISrsTsHandler() SrsTsContext::SrsTsContext() { pure_audio = false; + sync_byte = 0x47; // ts default sync byte. vcodec = SrsCodecVideoReserved; acodec = SrsCodecAudioReserved1; } @@ -368,6 +369,11 @@ int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo } } +void SrsTsContext::set_sync_byte(int8_t sb) +{ + sync_byte = sb; +} + int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as) { int ret = ERROR_SUCCESS; @@ -384,6 +390,8 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea SrsTsPacket* pkt = SrsTsPacket::create_pat(this, pmt_number, pmt_pid); SrsAutoFree(SrsTsPacket, pkt); + pkt->sync_byte = sync_byte; + char* buf = new char[SRS_TS_PACKET_SIZE]; SrsAutoFree(char, buf); @@ -409,6 +417,8 @@ int SrsTsContext::encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStrea SrsTsPacket* pkt = SrsTsPacket::create_pmt(this, pmt_number, pmt_pid, vpid, vs, apid, as); SrsAutoFree(SrsTsPacket, pkt); + pkt->sync_byte = sync_byte; + char* buf = new char[SRS_TS_PACKET_SIZE]; SrsAutoFree(char, buf); @@ -479,6 +489,8 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p } SrsAutoFree(SrsTsPacket, pkt); + pkt->sync_byte = sync_byte; + char* buf = new char[SRS_TS_PACKET_SIZE]; SrsAutoFree(char, buf); @@ -2704,7 +2716,7 @@ int SrsTSMuxer::open(string p) path = p; close(); - + // reset the context for a new ts start. context->reset(); diff --git a/trunk/src/kernel/srs_kernel_ts.hpp b/trunk/src/kernel/srs_kernel_ts.hpp index 772524f1d..914d93bdb 100644 --- a/trunk/src/kernel/srs_kernel_ts.hpp +++ b/trunk/src/kernel/srs_kernel_ts.hpp @@ -345,6 +345,7 @@ class SrsTsContext private: std::map pids; bool pure_audio; + int8_t sync_byte; // encoder private: // when any codec changed, write the PAT/PMT. @@ -394,6 +395,13 @@ public: * @param ac the audio codec, write the PAT/PMT table when changed. */ virtual int encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo vc, SrsCodecAudio ac); +// drm methods +public: + /** + * set sync byte of ts segment. + * replace the standard ts sync byte to bravo sync byte. + */ + virtual void set_sync_byte(int8_t sb); private: virtual int encode_pat_pmt(SrsFileWriter* writer, int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as); virtual int encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio); diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 73de98386..5193ce600 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -258,7 +258,7 @@ int main(int argc, char** argv) #ifdef SRS_AUTO_GPERF_MP #warning "gmp is not used for memory leak, please use gmc instead." #endif - + // never use srs log(srs_trace, srs_error, etc) before config parse the option, // which will load the log config and apply it. if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { @@ -274,7 +274,7 @@ int main(int argc, char** argv) if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { return ret; } - + srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION); srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT); srs_trace("primary/master: "RTMP_SIG_SRS_PRIMARY); @@ -288,11 +288,11 @@ int main(int argc, char** argv) srs_trace("arm tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); #endif srs_trace("conf: %s, limit: %d", _srs_config->config().c_str(), _srs_config->get_max_connections()); - + // features check_macro_features(); show_macro_features(); - + /** * we do nothing in the constructor of server, * and use initialize to create members, set hooks for instance the reload handler, @@ -357,7 +357,7 @@ int run_master() if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) { return ret; } - + if ((ret = _srs_server->initialize_signal()) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/protocol/srs_protocol_json.cpp b/trunk/src/protocol/srs_protocol_json.cpp index d6e1b1185..0a008d93a 100644 --- a/trunk/src/protocol/srs_protocol_json.cpp +++ b/trunk/src/protocol/srs_protocol_json.cpp @@ -487,6 +487,36 @@ SrsJsonAny* SrsJsonObject::ensure_property_boolean(string name) return prop; } +SrsJsonAny* SrsJsonObject::ensure_property_object(string name) +{ + SrsJsonAny* prop = get_property(name); + + if (!prop) { + return NULL; + } + + if (!prop->is_object()) { + return NULL; + } + + return prop; +} + +SrsJsonAny* SrsJsonObject::ensure_property_array(string name) +{ + SrsJsonAny* prop = get_property(name); + + if (!prop) { + return NULL; + } + + if (!prop->is_array()) { + return NULL; + } + + return prop; +} + SrsJsonArray::SrsJsonArray() { marker = SRS_JSON_Array; diff --git a/trunk/src/protocol/srs_protocol_json.hpp b/trunk/src/protocol/srs_protocol_json.hpp index 9be221a21..d56376834 100644 --- a/trunk/src/protocol/srs_protocol_json.hpp +++ b/trunk/src/protocol/srs_protocol_json.hpp @@ -151,6 +151,8 @@ public: virtual SrsJsonAny* ensure_property_string(std::string name); virtual SrsJsonAny* ensure_property_integer(std::string name); virtual SrsJsonAny* ensure_property_boolean(std::string name); + virtual SrsJsonAny* ensure_property_object(std::string name); + virtual SrsJsonAny* ensure_property_array(std::string name); }; class SrsJsonArray : public SrsJsonAny diff --git a/trunk/src/protocol/srs_rtmp_utility.cpp b/trunk/src/protocol/srs_rtmp_utility.cpp index 61338bd93..4258572d1 100644 --- a/trunk/src/protocol/srs_rtmp_utility.cpp +++ b/trunk/src/protocol/srs_rtmp_utility.cpp @@ -67,8 +67,13 @@ void srs_discovery_tc_url( host = host.substr(0, pos); srs_info("discovery host=%s, port=%s", host.c_str(), port.c_str()); } - - app = url; + + if (url.empty()) { + app = SRS_CONSTS_RTMP_DEFAULT_APP; + } else { + app = url; + } + vhost = host; srs_vhost_resolve(vhost, app, param); } @@ -230,7 +235,7 @@ std::string srs_generate_stream_url(std::string vhost, std::string app, std::str std::string url = ""; if (SRS_CONSTS_RTMP_DEFAULT_VHOST != vhost){ - url += vhost; + url += vhost; } url += "/"; url += app; diff --git a/trunk/src/utest/srs_utest_reload.cpp b/trunk/src/utest/srs_utest_reload.cpp index 2a5cdd367..ab912c81e 100644 --- a/trunk/src/utest/srs_utest_reload.cpp +++ b/trunk/src/utest/srs_utest_reload.cpp @@ -292,7 +292,7 @@ MockSrsReloadConfig::~MockSrsReloadConfig() { } -int MockSrsReloadConfig::reload(string buf) +int MockSrsReloadConfig::do_reload(string buf) { int ret = ERROR_SUCCESS; @@ -301,7 +301,7 @@ int MockSrsReloadConfig::reload(string buf) return ret; } - return reload_conf(&conf); + return MockSrsConfig::reload_conf(&conf); } #ifdef ENABLE_UTEST_RELOAD @@ -313,7 +313,7 @@ VOID TEST(ConfigReloadTest, ReloadEmpty) conf.subscribe(&handler); EXPECT_FALSE(ERROR_SUCCESS == conf.parse("")); - EXPECT_FALSE(ERROR_SUCCESS == conf.reload("")); + EXPECT_FALSE(ERROR_SUCCESS == conf.do_reload("")); EXPECT_TRUE(handler.all_false()); } @@ -324,35 +324,35 @@ VOID TEST(ConfigReloadTest, ReloadListen) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse("listen 1935;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1935;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1936;")); EXPECT_TRUE(handler.listen_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1936;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1936 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1936 1935;")); EXPECT_TRUE(handler.listen_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1935;")); EXPECT_TRUE(handler.listen_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1935 1935;")); EXPECT_TRUE(handler.listen_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload("listen 1935;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload("listen 1935;")); EXPECT_TRUE(handler.listen_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); @@ -365,16 +365,16 @@ VOID TEST(ConfigReloadTest, ReloadPid) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pid srs.pid;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs.pid;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pid srs.pid;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs1.pid;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pid srs1.pid;")); EXPECT_TRUE(handler.pid_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pid srs.pid;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pid srs.pid;")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -386,16 +386,16 @@ VOID TEST(ConfigReloadTest, ReloadLogTank) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_tank console;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank console;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_tank console;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank file;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_tank file;")); EXPECT_TRUE(handler.log_tank_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_tank console;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_tank console;")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -407,16 +407,16 @@ VOID TEST(ConfigReloadTest, ReloadLogLevel) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_level trace;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level trace;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_level trace;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level warn;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_level warn;")); EXPECT_TRUE(handler.log_level_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_level trace;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_level trace;")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -428,16 +428,16 @@ VOID TEST(ConfigReloadTest, ReloadLogFile) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"srs_log_file srs.log;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs.log;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_file srs.log;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs1.log;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_file srs1.log;")); EXPECT_TRUE(handler.log_file_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"srs_log_file srs.log;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"srs_log_file srs.log;")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -449,16 +449,16 @@ VOID TEST(ConfigReloadTest, ReloadPithyPrint) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"pithy_print_ms 1000;")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print_ms 1000;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pithy_print_ms 1000;")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print_ms 2000;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pithy_print_ms 2000;")); EXPECT_TRUE(handler.pithy_print_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"pithy_print_ms 1000;")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"pithy_print_ms 1000;")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -470,16 +470,16 @@ VOID TEST(ConfigReloadTest, ReloadHttpApiEnabled) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled off;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}")); EXPECT_TRUE(handler.http_api_enabled_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -491,16 +491,16 @@ VOID TEST(ConfigReloadTest, ReloadHttpApiDisabled) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_api {enabled on;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled off;}")); EXPECT_TRUE(handler.http_api_disabled_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_api {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_api {enabled on;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -512,16 +512,16 @@ VOID TEST(ConfigReloadTest, ReloadHttpStreamEnabled) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled off;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}")); EXPECT_TRUE(handler.http_stream_enabled_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -533,16 +533,16 @@ VOID TEST(ConfigReloadTest, ReloadHttpStreamDisabled) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled off;}")); EXPECT_TRUE(handler.http_stream_disabled_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -554,16 +554,16 @@ VOID TEST(ConfigReloadTest, ReloadHttpStreamUpdated) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8000;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8000;}")); EXPECT_TRUE(handler.http_stream_updated_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"http_stream {enabled on; listen 8080;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -575,16 +575,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostHttpUpdated) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls1;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls1;}}")); EXPECT_TRUE(handler.vhost_http_updated_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost http.srs.com {http {enabled on;mount /hls;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -596,16 +596,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostAdded) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{} vhost b{}")); EXPECT_TRUE(handler.vhost_added_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -617,16 +617,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostRemoved) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{enabled off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{enabled off;}")); EXPECT_TRUE(handler.vhost_removed_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -638,16 +638,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostRemoved2) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{} vhost b{}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{} vhost b{}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_TRUE(handler.vhost_removed_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{} vhost b{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{} vhost b{}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -659,16 +659,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostAtc) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{atc off;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{atc off;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{atc on;}")); EXPECT_TRUE(handler.vhost_atc_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{atc off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{atc off;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -680,16 +680,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostGopCache) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{gop_cache off;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{gop_cache off;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache on;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{gop_cache on;}")); EXPECT_TRUE(handler.vhost_gop_cache_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{gop_cache off;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{gop_cache off;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -701,16 +701,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostQueueLength) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{queue_length 10;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 10;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{queue_length 10;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 20;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{queue_length 20;}")); EXPECT_TRUE(handler.vhost_queue_length_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{queue_length 10;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{queue_length 10;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -722,16 +722,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostTimeJitter) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{time_jitter full;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter full;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{time_jitter full;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter zero;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{time_jitter zero;}")); EXPECT_TRUE(handler.vhost_time_jitter_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{time_jitter full;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{time_jitter full;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -743,16 +743,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostForward) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1937;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1937;}")); EXPECT_TRUE(handler.vhost_forward_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{forward 127.0.0.1:1936;}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -764,16 +764,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostHls) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{hls {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled off;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{hls {enabled off;}}")); EXPECT_TRUE(handler.vhost_hls_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{hls {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -785,16 +785,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostDvr) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{dvr {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled off;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{dvr {enabled off;}}")); EXPECT_TRUE(handler.vhost_dvr_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{dvr {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -806,16 +806,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostTranscode) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{transcode {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled off;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{transcode {enabled off;}}")); EXPECT_TRUE(handler.vhost_transcode_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{transcode {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -827,16 +827,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostIngestAdded) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); EXPECT_TRUE(handler.ingest_added_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -848,16 +848,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostIngestAdded2) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;} ingest b {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;} ingest b {enabled on;}}")); EXPECT_TRUE(handler.ingest_added_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest a {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -869,16 +869,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostIngestRemoved) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{}")); EXPECT_TRUE(handler.ingest_removed_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -890,16 +890,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostIngestRemoved2) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled off;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled off;}}")); EXPECT_TRUE(handler.ingest_removed_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } @@ -911,16 +911,16 @@ VOID TEST(ConfigReloadTest, ReloadVhostIngestUpdated) conf.subscribe(&handler); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}")); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}")); EXPECT_TRUE(handler.all_false()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg1;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg1;}}")); EXPECT_TRUE(handler.ingest_updated_reloaded); EXPECT_EQ(1, handler.count_true()); handler.reset(); - EXPECT_TRUE(ERROR_SUCCESS == conf.reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.do_reload(_MIN_OK_CONF"vhost a{ingest {enabled on;ffmpeg ffmpeg;}}")); EXPECT_EQ(1, handler.count_true()); handler.reset(); } diff --git a/trunk/src/utest/srs_utest_reload.hpp b/trunk/src/utest/srs_utest_reload.hpp index bc38a5a1d..0b7a1e2cb 100644 --- a/trunk/src/utest/srs_utest_reload.hpp +++ b/trunk/src/utest/srs_utest_reload.hpp @@ -102,7 +102,7 @@ public: MockSrsReloadConfig(); virtual ~MockSrsReloadConfig(); public: - virtual int reload(std::string buf); + virtual int do_reload(std::string buf); }; #endif