Skip to content

Commit

Permalink
Threads: Remove reload for streams
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 28, 2021
1 parent 96637f2 commit d24bd9b
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 419 deletions.
4 changes: 2 additions & 2 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ threads {
hybrids 1;
# Whether automatically generate stream config by hybrid.
# If off, user must create a number of streams, which is equal to the hybrids.
# Default: on
generate_streams on;
# Default: off
generate_streams off;
# CPU set for affinity, for example:
# 0 means CPU0
# 0-3 means CPU0, CPU1, CPU2
Expand Down
6 changes: 0 additions & 6 deletions trunk/src/app/srs_app_caster_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,6 @@ srs_error_t SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecod
return err;
}

srs_error_t SrsDynamicHttpConn::on_reload_http_stream_crossdomain()
{
bool v = _srs_config->get_http_stream_crossdomain();
return conn->set_crossdomain_enabled(v);
}

srs_error_t SrsDynamicHttpConn::on_start()
{
return srs_success;
Expand Down
4 changes: 0 additions & 4 deletions trunk/src/app/srs_app_caster_flv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ class SrsDynamicHttpConn : virtual public ISrsStartableConneciton, virtual publi
virtual srs_error_t proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o);
private:
virtual srs_error_t do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec);
// Extract APIs from SrsTcpConnection.
// Interface ISrsReloadHandler
public:
virtual srs_error_t on_reload_http_stream_crossdomain();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
Expand Down
121 changes: 7 additions & 114 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1612,27 +1612,13 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
// bandcheck, http_hooks, heartbeat,
// security

// merge config: listen
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
if ((err = do_reload_listen()) != srs_success) {
return srs_error_wrap(err, "listen");
}
}

// merge config: pid
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
if ((err = do_reload_pid()) != srs_success) {
return srs_error_wrap(err, "pid");;
}
}

// merge config: max_connections
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
if ((err = do_reload_max_connections()) != srs_success) {
return srs_error_wrap(err, "max connections");;
}
}

// merge config: pithy_print_ms
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
if ((err = do_reload_pithy_print_ms()) != srs_success) {
Expand All @@ -1644,15 +1630,10 @@ srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
if ((err = reload_http_api(old_root)) != srs_success) {
return srs_error_wrap(err, "http api");;
}

// merge config: http_stream
if ((err = reload_http_stream(old_root)) != srs_success) {
return srs_error_wrap(err, "http steram");;
}

// Merge config: rtc_server
if ((err = reload_rtc_server(old_root)) != srs_success) {
return srs_error_wrap(err, "http steram");;
// merge config: streams
if ((err = reload_streams(old_root)) != srs_success) {
return srs_error_wrap(err, "streams");;
}

// TODO: FIXME: support reload stream_caster.
Expand Down Expand Up @@ -1743,17 +1724,10 @@ srs_error_t SrsConfig::reload_http_api(SrsConfDirective* old_root)
return err;
}

srs_error_t SrsConfig::reload_http_stream(SrsConfDirective* old_root)
srs_error_t SrsConfig::reload_streams(SrsConfDirective* old_root)
{
srs_error_t err = srs_success;
// TODO: FIXME: We never support reload HTTP stream.
return err;
}

srs_error_t SrsConfig::reload_rtc_server(SrsConfDirective* old_root)
{
srs_error_t err = srs_success;
// TODO: FIXME: Do not support reloading RTC Server.
// TODO: FIXME: We never support reload streams.
return err;
}

Expand Down Expand Up @@ -2859,31 +2833,6 @@ srs_error_t SrsConfig::raw_to_json(SrsJsonObject* obj)
return err;
}

srs_error_t SrsConfig::raw_set_listen(const vector<string>& eps, bool& applied)
{
srs_error_t err = srs_success;

applied = false;

SrsConfDirective* conf = root->get("listen");

// nothing changed, ignore.
if (srs_vector_actual_equals(conf->args, eps)) {
return err;
}

// changed, apply and reload.
conf->args = eps;

if ((err = do_reload_listen()) != srs_success) {
return srs_error_wrap(err, "reload listen");
}

applied = true;

return err;
}

srs_error_t SrsConfig::raw_set_pid(string pid, bool& applied)
{
srs_error_t err = srs_success;
Expand Down Expand Up @@ -2952,30 +2901,6 @@ srs_error_t SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied)
return err;
}

srs_error_t SrsConfig::raw_set_max_connections(string max_connections, bool& applied)
{
srs_error_t err = srs_success;

applied = false;

SrsConfDirective* conf = root->get_or_create("max_connections");

if (conf->arg0() == max_connections) {
return err;
}

conf->args.clear();
conf->args.push_back(max_connections);

if ((err = do_reload_max_connections()) != srs_success) {
return srs_error_wrap(err, "reload max connection");
}

applied = true;

return err;
}

srs_error_t SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied)
{
srs_error_t err = srs_success;
Expand Down Expand Up @@ -3143,22 +3068,6 @@ srs_error_t SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applie
}
// LCOV_EXCL_STOP

srs_error_t SrsConfig::do_reload_listen()
{
srs_error_t err = srs_success;

vector<ISrsReloadHandler*>::iterator it;
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((err = subscribe->on_reload_listen()) != srs_success) {
return srs_error_wrap(err, "notify subscribes reload listen failed");
}
}
srs_trace("reload listen success.");

return err;
}

srs_error_t SrsConfig::do_reload_pid()
{
srs_error_t err = srs_success;
Expand All @@ -3175,22 +3084,6 @@ srs_error_t SrsConfig::do_reload_pid()
return err;
}

srs_error_t SrsConfig::do_reload_max_connections()
{
srs_error_t err = srs_success;

vector<ISrsReloadHandler*>::iterator it;
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((err = subscribe->on_reload_max_conns()) != srs_success) {
return srs_error_wrap(err, "notify subscribes reload max_connections failed");
}
}
srs_trace("reload max_connections success.");

return err;
}

srs_error_t SrsConfig::do_reload_pithy_print_ms()
{
srs_error_t err = srs_success;
Expand Down Expand Up @@ -4237,7 +4130,7 @@ int SrsConfig::get_threads_hybrids()

bool SrsConfig::get_threads_generate_stream()
{
static bool DEFAULT = true;
static bool DEFAULT = false;

SrsConfDirective* conf = root->get("threads");
if (!conf) {
Expand All @@ -4249,7 +4142,7 @@ bool SrsConfig::get_threads_generate_stream()
return DEFAULT;
}

return SRS_CONF_PERFER_TRUE(conf->arg0());
return SRS_CONF_PERFER_FALSE(conf->arg0());
}

bool SrsConfig::get_threads_cpu_affinity(std::string label, int* start, int* end)
Expand Down
13 changes: 2 additions & 11 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,8 @@ class SrsConfig
private:
// Reload the http_api section of config.
virtual srs_error_t reload_http_api(SrsConfDirective* old_root);
// Reload the http_stream section of config.
// TODO: FIXME: rename to http_server.
virtual srs_error_t reload_http_stream(SrsConfDirective* old_root);
// Reload the rtc_server section of config.
virtual srs_error_t reload_rtc_server(SrsConfDirective* old_root);
// Reload the streams for hybrids.
virtual srs_error_t reload_streams(SrsConfDirective* old_root);
// Reload the transcode section of vhost of config.
virtual srs_error_t reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
// Reload the ingest section of vhost of config.
Expand All @@ -355,16 +352,12 @@ class SrsConfig
virtual srs_error_t vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj);
// Dumps the http_api sections to json for raw api info.
virtual srs_error_t raw_to_json(SrsJsonObject* obj);
// RAW set the global listen.
virtual srs_error_t raw_set_listen(const std::vector<std::string>& eps, bool& applied);
// RAW set the global pid.
virtual srs_error_t raw_set_pid(std::string pid, bool& applied);
// RAW set the global chunk size.
virtual srs_error_t raw_set_chunk_size(std::string chunk_size, bool& applied);
// RAW set the global ffmpeg log dir.
virtual srs_error_t raw_set_ff_log_dir(std::string ff_log_dir, bool& applied);
// RAW set the global max connections of srs.
virtual srs_error_t raw_set_max_connections(std::string max_connections, bool& applied);
// RAW set the global pithy print interval in ms.
virtual srs_error_t raw_set_pithy_print_ms(std::string pithy_print_ms, bool& applied);
// RAW create the new vhost.
Expand All @@ -382,9 +375,7 @@ class SrsConfig
// RAW disable the dvr of stream of vhost.
virtual srs_error_t raw_disable_dvr(std::string vhost, std::string stream, bool& applied);
private:
virtual srs_error_t do_reload_listen();
virtual srs_error_t do_reload_pid();
virtual srs_error_t do_reload_max_connections();
virtual srs_error_t do_reload_pithy_print_ms();
virtual srs_error_t do_reload_vhost_added(std::string vhost);
virtual srs_error_t do_reload_vhost_removed(std::string vhost);
Expand Down
40 changes: 3 additions & 37 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,14 +993,12 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
// @data the extra data for scope.
// possible updates:
// @scope @value value-description
// listen 1935,1936 the port list.
// pid ./objs/srs.pid the pid file of srs.
// chunk_size 60000 the global RTMP chunk_size.
// ff_log_dir ./objs the dir for ffmpeg log.
// srs_log_tank file the tank to log, file or console.
// srs_log_level trace the level of log, verbose, info, trace, warn, error.
// srs_log_file ./objs/srs.log the log file when tank is file.
// max_connections 1000 the max connections of srs.
// utc_time false whether enable utc time.
// pithy_print_ms 10000 the pithy print interval in ms.
// vhost specified updates:
Expand All @@ -1021,38 +1019,17 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
if (scope.empty()) {
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
}
if (scope != "listen" && scope != "pid" && scope != "chunk_size"
if (scope != "pid" && scope != "chunk_size"
&& scope != "ff_log_dir" && scope != "srs_log_tank" && scope != "srs_log_level"
&& scope != "srs_log_file" && scope != "max_connections" && scope != "utc_time"
&& scope != "srs_log_file" && scope != "utc_time"
&& scope != "pithy_print_ms" && scope != "vhost" && scope != "dvr"
) {
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED);
}

bool applied = false;
string extra = "";
if (scope == "listen") {
vector<string> eps = srs_string_split(value, ",");

bool invalid = eps.empty();
for (int i = 0; i < (int)eps.size(); i++) {
string ep = eps.at(i);
int port = ::atoi(ep.c_str());
if (port <= 2 || port >= 65535) {
invalid = true;
break;
}
}
if (invalid) {
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
}

if ((err = _srs_config->raw_set_listen(eps, applied)) != srs_success) {
int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
} else if (scope == "pid") {
if (scope == "pid") {
if (value.empty() || !srs_string_starts_with(value, "./", "/tmp/", "/var/") || !srs_string_ends_with(value, ".pid")) {
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
}
Expand Down Expand Up @@ -1083,17 +1060,6 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
} else if (scope == "max_connections") {
int mcv = ::atoi(value.c_str());
if (mcv < 10 || mcv > 65535 || !srs_is_digit_number(value)) {
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_PARAMS);
}

if ((err = _srs_config->raw_set_max_connections(value, applied)) != srs_success) {
int code = srs_error_code(err);
srs_error_reset(err);
return srs_api_response_code(w, r, code);
}
} else if (scope == "pithy_print_ms") {
int ppmv = ::atoi(value.c_str());
if (ppmv < 100 || ppmv > 300000 || !srs_is_digit_number(value)) {
Expand Down
6 changes: 0 additions & 6 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,6 @@ srs_error_t SrsResponseOnlyHttpConn::pop_message(ISrsHttpMessage** preq)
return err;
}

srs_error_t SrsResponseOnlyHttpConn::on_reload_http_stream_crossdomain()
{
bool v = _srs_config->get_http_stream_crossdomain();
return conn->set_crossdomain_enabled(v);
}

srs_error_t SrsResponseOnlyHttpConn::on_start()
{
srs_error_t err = srs_success;
Expand Down
3 changes: 0 additions & 3 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ class SrsResponseOnlyHttpConn : virtual public ISrsStartableConneciton, virtual
// @see https://github.com/ossrs/srs/issues/636#issuecomment-298208427
// @remark Should only used in HTTP-FLV streaming connection.
virtual srs_error_t pop_message(ISrsHttpMessage** preq);
// Interface ISrsReloadHandler
public:
virtual srs_error_t on_reload_http_stream_crossdomain();
// Interface ISrsHttpConnOwner.
public:
virtual srs_error_t on_start();
Expand Down
25 changes: 0 additions & 25 deletions trunk/src/app/srs_app_reload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,6 @@ srs_error_t ISrsReloadHandler::on_reload_http_api_raw_api()
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_http_stream_enabled()
{
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_http_stream_disabled()
{
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_http_stream_updated()
{
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_http_stream_crossdomain()
{
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_rtc_server()
{
return srs_success;
}

srs_error_t ISrsReloadHandler::on_reload_vhost_http_updated()
{
return srs_success;
Expand Down
Loading

0 comments on commit d24bd9b

Please sign in to comment.