From 010b7a7595f49a960b8a62e885423fb427d731d7 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 14 Dec 2013 21:19:47 +0800 Subject: [PATCH] refine config. --- trunk/conf/srs.conf | 80 ++--- trunk/src/core/srs_core_client.cpp | 15 +- trunk/src/core/srs_core_config.cpp | 375 ++++++++++++++---------- trunk/src/core/srs_core_config.hpp | 108 +++---- trunk/src/core/srs_core_hls.cpp | 24 +- trunk/src/core/srs_core_pithy_print.cpp | 35 +-- 6 files changed, 327 insertions(+), 310 deletions(-) diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index a76f811e7..793c84134 100755 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -4,7 +4,7 @@ listen 1935; # some client does not support chunk size change, # however, most clients supports it and it can improve # performance about 10%. -# if not specified, set to 4096. +# default: 4096 chunk_size 65000; # the logs dir. # if enabled ffmpeg, each stracoding stream will create a log file. @@ -21,11 +21,13 @@ max_connections 2000; vhost __defaultVhost__ { enabled on; gop_cache on; - hls on; - hls_path ./objs/nginx/html; - hls_fragment 5; - hls_window 30; forward 127.0.0.1:19350; + hls { + hls on; + hls_path ./objs/nginx/html; + hls_fragment 5; + hls_window 30; + } transcode { enabled on; ffmpeg ./objs/ffmpeg/bin/ffmpeg; @@ -81,11 +83,13 @@ vhost __defaultVhost__ { vhost dev { enabled on; gop_cache on; - hls off; - hls_path ./objs/nginx/html; - hls_fragment 5; - hls_window 30; forward 127.0.0.1:19350; + hls { + hls off; + hls_path ./objs/nginx/html; + hls_fragment 5; + hls_window 30; + } http_hooks { enabled off; on_connect http://127.0.0.1:8085/api/v1/clients; @@ -626,36 +630,40 @@ vhost removed.vhost.com { enabled off; } # the vhost with hls specified. -vhost no-hls.vhost.com { - # whether the hls is enabled. - # if off, donot write hls(ts and m3u8) when publish. - # default: on - hls on; - # the hls output path. - # the app dir is auto created under the hls_path. - # for example, for rtmp stream: - # rtmp://127.0.0.1/live/livestream - # http://127.0.0.1/live/livestream.m3u8 - # where hls_path is /hls, srs will create the following files: - # /hls/live the app dir for all streams. - # /hls/live/livestream.m3u8 the HLS m3u8 file. - # /hls/live/livestream-1.ts the HLS media/ts file. - # in a word, the hls_path is for vhost. - # default: ./objs/nginx/html - hls_path /data/nginx/html; - # the hls fragment in seconds, the duration of a piece of ts. - # default: 10 - hls_fragment 10; - # the hls window in seconds, the number of ts in m3u8. - # default: 60 - hls_window 60; +vhost with-hls.vhost.com { + hls { + # whether the hls is enabled. + # if off, donot write hls(ts and m3u8) when publish. + # default: off + hls on; + # the hls output path. + # the app dir is auto created under the hls_path. + # for example, for rtmp stream: + # rtmp://127.0.0.1/live/livestream + # http://127.0.0.1/live/livestream.m3u8 + # where hls_path is /hls, srs will create the following files: + # /hls/live the app dir for all streams. + # /hls/live/livestream.m3u8 the HLS m3u8 file. + # /hls/live/livestream-1.ts the HLS media/ts file. + # in a word, the hls_path is for vhost. + # default: ./objs/nginx/html + hls_path /data/nginx/html; + # the hls fragment in seconds, the duration of a piece of ts. + # default: 10 + hls_fragment 10; + # the hls window in seconds, the number of ts in m3u8. + # default: 60 + hls_window 60; + } } # the vhost with hls disabled. vhost no-hls.vhost.com { - # whether the hls is enabled. - # if off, donot write hls(ts and m3u8) when publish. - # default: on - hls off; + hls { + # whether the hls is enabled. + # if off, donot write hls(ts and m3u8) when publish. + # default: off + hls off; + } } # the vhost for min delay, donot cache any stream. vhost min.delay.com { diff --git a/trunk/src/core/srs_core_client.cpp b/trunk/src/core/srs_core_client.cpp index 1b84b3287..766a2900d 100644 --- a/trunk/src/core/srs_core_client.cpp +++ b/trunk/src/core/srs_core_client.cpp @@ -150,11 +150,7 @@ int SrsClient::service_cycle() req->strip(); srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str()); - int chunk_size = 4096; - SrsConfDirective* conf = config->get_chunk_size(); - if (conf && !conf->arg0().empty()) { - chunk_size = ::atoi(conf->arg0().c_str()); - } + int chunk_size = config->get_chunk_size(); if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); return ret; @@ -175,14 +171,9 @@ int SrsClient::service_cycle() return ret; } - bool enabled_cache = true; - conf = config->get_gop_cache(req->vhost); - if (conf && conf->arg0() == "off") { - enabled_cache = false; - } - source->set_cache(enabled_cache); - + bool enabled_cache = config->get_gop_cache(req->vhost); srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); + source->set_cache(enabled_cache); switch (type) { case SrsClientPlay: { diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp index d799dddb3..cd910b21b 100644 --- a/trunk/src/core/srs_core_config.cpp +++ b/trunk/src/core/srs_core_config.cpp @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +using namespace std; #include #include @@ -152,7 +153,7 @@ SrsConfDirective::~SrsConfDirective() directives.clear(); } -std::string SrsConfDirective::arg0() +string SrsConfDirective::arg0() { if (args.size() > 0) { return args.at(0); @@ -161,7 +162,7 @@ std::string SrsConfDirective::arg0() return ""; } -std::string SrsConfDirective::arg1() +string SrsConfDirective::arg1() { if (args.size() > 1) { return args.at(1); @@ -170,7 +171,7 @@ std::string SrsConfDirective::arg1() return ""; } -std::string SrsConfDirective::arg2() +string SrsConfDirective::arg2() { if (args.size() > 2) { return args.at(2); @@ -184,7 +185,7 @@ SrsConfDirective* SrsConfDirective::at(int index) return directives.at(index); } -SrsConfDirective* SrsConfDirective::get(std::string _name) +SrsConfDirective* SrsConfDirective::get(string _name) { std::vector::iterator it; for (it = directives.begin(); it != directives.end(); ++it) { @@ -216,7 +217,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type) int ret = ERROR_SUCCESS; while (true) { - std::vector args; + std::vector args; ret = read_token(buffer, args); /** @@ -271,7 +272,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type) } // see: ngx_conf_read_token -int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector& args) +int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector& args) { int ret = ERROR_SUCCESS; @@ -395,7 +396,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector memcpy(word, pstart, len); word[len - 1] = 0; - std::string word_str = word; + string word_str = word; if (!word_str.empty()) { args.push_back(word_str); } @@ -537,7 +538,102 @@ int SrsConfig::parse_options(int argc, char** argv) return parse_file(config_file.c_str()); } -SrsConfDirective* SrsConfig::get_vhost(std::string vhost) +int SrsConfig::parse_file(const char* filename) +{ + int ret = ERROR_SUCCESS; + + config_file = filename; + + if (config_file.empty()) { + return ERROR_SYSTEM_CONFIG_INVALID; + } + + if ((ret = root->parse(config_file.c_str())) != ERROR_SUCCESS) { + return ret; + } + + SrsConfDirective* conf = NULL; + if ((conf = get_listen()) == NULL || conf->args.size() == 0) { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("line %d: conf error, " + "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret); + return ret; + } + + // TODO: check the hls. + // TODO: check forward. + // TODO: check ffmpeg. + // TODO: check http. + + return ret; +} + +int SrsConfig::parse_argv(int& i, char** argv) +{ + int ret = ERROR_SUCCESS; + + char* p = argv[i]; + + if (*p++ != '-') { + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("invalid options(index=%d, value=%s), " + "must starts with -, see help: %s -h, ret=%d", i, argv[i], argv[0], ret); + return ret; + } + + while (*p) { + switch (*p++) { + case '?': + case 'h': + show_help = true; + break; + case 'v': + case 'V': + show_version = true; + break; + case 'c': + if (*p) { + config_file = p; + return ret; + } + if (argv[++i]) { + config_file = argv[i]; + return ret; + } + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("option \"-c\" requires parameter, ret=%d", ret); + return ret; + default: + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("invalid option: \"%c\", see help: %s -h, ret=%d", *(p - 1), argv[0], ret); + return ret; + } + } + + return ret; +} + +void SrsConfig::print_help(char** argv) +{ + printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION + " Copyright (c) 2013 winlin\n" + "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n" + "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n" + "Usage: %s [-h?vV] [-c ]\n" + "\n" + "Options:\n" + " -?-h : show help\n" + " -v-V : show version and exit\n" + " -c filename : set configuration file\n" + "\n" + RTMP_SIG_SRS_WEB"\n" + RTMP_SIG_SRS_URL"\n" + "Email: "RTMP_SIG_SRS_EMAIL"\n" + "\n", + argv[0]); +} + +SrsConfDirective* SrsConfig::get_vhost(string vhost) { srs_assert(root); @@ -560,7 +656,7 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost) return NULL; } -SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -581,7 +677,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost) return conf->get("on_connect"); } -SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -602,7 +698,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost) return conf->get("on_close"); } -SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -623,7 +719,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost) return conf->get("on_publish"); } -SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -644,7 +740,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost) return conf->get("on_unpublish"); } -SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -665,7 +761,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost) return conf->get("on_play"); } -SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost) +SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -686,7 +782,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost) return conf->get("on_stop"); } -bool SrsConfig::get_vhost_enabled(std::string vhost) +bool SrsConfig::get_vhost_enabled(string vhost) { SrsConfDirective* vhost_conf = get_vhost(vhost); @@ -706,7 +802,7 @@ bool SrsConfig::get_vhost_enabled(std::string vhost) return true; } -SrsConfDirective* SrsConfig::get_transcode(std::string vhost, std::string scope) +SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope) { SrsConfDirective* conf = get_vhost(vhost); @@ -740,7 +836,7 @@ bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode) return true; } -std::string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) +string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) { if (!transcode) { return ""; @@ -785,7 +881,7 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine) return true; } -std::string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) +string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) { if (!engine) { return ""; @@ -869,7 +965,7 @@ int SrsConfig::get_engine_vthreads(SrsConfDirective* engine) return ::atoi(conf->arg0().c_str()); } -std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) +string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) { if (!engine) { return ""; @@ -883,7 +979,7 @@ std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) return conf->arg0(); } -std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) +string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) { if (!engine) { return ""; @@ -897,7 +993,7 @@ std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) return conf->arg0(); } -void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector& vparams) +void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector& vparams) { if (!engine) { return; @@ -919,7 +1015,7 @@ void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector& vfilter) +void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector& vfilter) { if (!engine) { return; @@ -941,7 +1037,7 @@ void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vectorarg0().c_str()); } -void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector& aparams) +void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector& aparams) { if (!engine) { return; @@ -1019,7 +1115,7 @@ void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vectorarg0(); } -std::string SrsConfig::get_log_dir() +string SrsConfig::get_log_dir() { srs_assert(root); @@ -1057,18 +1153,22 @@ int SrsConfig::get_max_connections() return ::atoi(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) +bool SrsConfig::get_gop_cache(string vhost) { SrsConfDirective* conf = get_vhost(vhost); if (!conf) { - return NULL; + return true; } - return conf->get("gop_cache"); + if (conf && conf->arg0() == "off") { + return false; + } + + return true; } -SrsConfDirective* SrsConfig::get_forward(std::string vhost) +SrsConfDirective* SrsConfig::get_forward(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -1079,7 +1179,7 @@ SrsConfDirective* SrsConfig::get_forward(std::string vhost) return conf->get("forward"); } -SrsConfDirective* SrsConfig::get_hls(std::string vhost) +SrsConfDirective* SrsConfig::get_hls(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -1090,12 +1190,12 @@ SrsConfDirective* SrsConfig::get_hls(std::string vhost) return conf->get("hls"); } -bool SrsConfig::get_hls_enabled(std::string vhost) +bool SrsConfig::get_hls_enabled(string vhost) { SrsConfDirective* hls = get_hls(vhost); if (!hls) { - return true; + return false; } if (hls->arg0() == "off") { @@ -1105,40 +1205,58 @@ bool SrsConfig::get_hls_enabled(std::string vhost) return true; } -SrsConfDirective* SrsConfig::get_hls_path(std::string vhost) +string SrsConfig::get_hls_path(string vhost) { - SrsConfDirective* conf = get_vhost(vhost); - - if (!conf) { - return NULL; + SrsConfDirective* hls = get_hls(vhost); + + if (!hls) { + return SRS_CONF_DEFAULT_HLS_PATH; } - return conf->get("hls_path"); + SrsConfDirective* conf = hls->get("hls_path"); + + if (!conf) { + return SRS_CONF_DEFAULT_HLS_PATH; + } + + return conf->arg0(); } -SrsConfDirective* SrsConfig::get_hls_fragment(std::string vhost) +double SrsConfig::get_hls_fragment(string vhost) { - SrsConfDirective* conf = get_vhost(vhost); - - if (!conf) { - return NULL; + SrsConfDirective* hls = get_hls(vhost); + + if (!hls) { + return SRS_CONF_DEFAULT_HLS_FRAGMENT; } - return conf->get("hls_fragment"); + SrsConfDirective* conf = hls->get("hls_fragment"); + + if (!conf) { + return SRS_CONF_DEFAULT_HLS_FRAGMENT; + } + + return ::atof(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_hls_window(std::string vhost) +double SrsConfig::get_hls_window(string vhost) { - SrsConfDirective* conf = get_vhost(vhost); - - if (!conf) { - return NULL; + SrsConfDirective* hls = get_hls(vhost); + + if (!hls) { + return SRS_CONF_DEFAULT_HLS_WINDOW; } - return conf->get("hls_window"); + SrsConfDirective* conf = hls->get("hls_window"); + + if (!conf) { + return SRS_CONF_DEFAULT_HLS_WINDOW; + } + + return ::atof(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_refer(std::string vhost) +SrsConfDirective* SrsConfig::get_refer(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -1149,7 +1267,7 @@ SrsConfDirective* SrsConfig::get_refer(std::string vhost) return conf->get("refer"); } -SrsConfDirective* SrsConfig::get_refer_play(std::string vhost) +SrsConfDirective* SrsConfig::get_refer_play(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -1160,7 +1278,7 @@ SrsConfDirective* SrsConfig::get_refer_play(std::string vhost) return conf->get("refer_play"); } -SrsConfDirective* SrsConfig::get_refer_publish(std::string vhost) +SrsConfDirective* SrsConfig::get_refer_publish(string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -1176,156 +1294,89 @@ SrsConfDirective* SrsConfig::get_listen() return root->get("listen"); } -SrsConfDirective* SrsConfig::get_chunk_size() +int SrsConfig::get_chunk_size() { - return root->get("chunk_size"); + SrsConfDirective* conf = root->get("chunk_size"); + if (!conf) { + return SRS_CONF_DEFAULT_CHUNK_SIZE; + } + + return ::atoi(conf->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_pithy_print_publish() +int SrsConfig::get_pithy_print_publish() { SrsConfDirective* pithy = root->get("pithy_print"); if (!pithy) { - return NULL; + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; } - return pithy->get("publish"); -} - -SrsConfDirective* SrsConfig::get_pithy_print_forwarder() -{ - SrsConfDirective* pithy = root->get("pithy_print"); + pithy = pithy->get("publish"); if (!pithy) { - return NULL; + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS; } - return pithy->get("forwarder"); + return ::atoi(pithy->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_pithy_print_hls() +int SrsConfig::get_pithy_print_forwarder() { SrsConfDirective* pithy = root->get("pithy_print"); if (!pithy) { - return NULL; + return SRS_STAGE_FORWARDER_INTERVAL_MS; } - return pithy->get("hls"); -} - -SrsConfDirective* SrsConfig::get_pithy_print_encoder() -{ - SrsConfDirective* pithy = root->get("encoder"); + pithy = pithy->get("forwarder"); if (!pithy) { - return NULL; + return SRS_STAGE_FORWARDER_INTERVAL_MS; } - return pithy->get("forwarder"); + return ::atoi(pithy->arg0().c_str()); } -SrsConfDirective* SrsConfig::get_pithy_print_play() +int SrsConfig::get_pithy_print_hls() { SrsConfDirective* pithy = root->get("pithy_print"); if (!pithy) { - return NULL; + return SRS_STAGE_HLS_INTERVAL_MS; + } + + pithy = pithy->get("hls"); + if (!pithy) { + return SRS_STAGE_HLS_INTERVAL_MS; } - return pithy->get("play"); + return ::atoi(pithy->arg0().c_str()); } -int SrsConfig::parse_file(const char* filename) +int SrsConfig::get_pithy_print_encoder() { - int ret = ERROR_SUCCESS; - - config_file = filename; - - if (config_file.empty()) { - return ERROR_SYSTEM_CONFIG_INVALID; - } - - if ((ret = root->parse(config_file.c_str())) != ERROR_SUCCESS) { - return ret; + SrsConfDirective* pithy = root->get("encoder"); + if (!pithy) { + return SRS_STAGE_ENCODER_INTERVAL_MS; } - SrsConfDirective* conf = NULL; - if ((conf = get_listen()) == NULL || conf->args.size() == 0) { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("line %d: conf error, " - "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret); - return ret; + pithy = pithy->get("forwarder"); + if (!pithy) { + return SRS_STAGE_ENCODER_INTERVAL_MS; } - // TODO: check the hls. - // TODO: check other config. - // TODO: check hls. - // TODO: check ssl. - // TODO: check ffmpeg. - // TODO: check http. - - return ret; + return ::atoi(pithy->arg0().c_str()); } -int SrsConfig::parse_argv(int& i, char** argv) +int SrsConfig::get_pithy_print_play() { - int ret = ERROR_SUCCESS; - - char* p = argv[i]; - - if (*p++ != '-') { - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("invalid options(index=%d, value=%s), " - "must starts with -, see help: %s -h, ret=%d", i, argv[i], argv[0], ret); - return ret; + SrsConfDirective* pithy = root->get("pithy_print"); + if (!pithy) { + return SRS_STAGE_PLAY_USER_INTERVAL_MS; } - while (*p) { - switch (*p++) { - case '?': - case 'h': - show_help = true; - break; - case 'v': - case 'V': - show_version = true; - break; - case 'c': - if (*p) { - config_file = p; - return ret; - } - if (argv[++i]) { - config_file = argv[i]; - return ret; - } - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("option \"-c\" requires parameter, ret=%d", ret); - return ret; - default: - ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("invalid option: \"%c\", see help: %s -h, ret=%d", *(p - 1), argv[0], ret); - return ret; - } + pithy = pithy->get("play"); + if (!pithy) { + return SRS_STAGE_PLAY_USER_INTERVAL_MS; } - return ret; -} - -void SrsConfig::print_help(char** argv) -{ - printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION - " Copyright (c) 2013 winlin\n" - "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n" - "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n" - "Usage: %s [-h?vV] [-c ]\n" - "\n" - "Options:\n" - " -?-h : show help\n" - " -v-V : show version and exit\n" - " -c filename : set configuration file\n" - "\n" - RTMP_SIG_SRS_WEB"\n" - RTMP_SIG_SRS_URL"\n" - "Email: "RTMP_SIG_SRS_EMAIL"\n" - "\n", - argv[0]); + return ::atoi(pithy->arg0().c_str()); } bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) diff --git a/trunk/src/core/srs_core_config.hpp b/trunk/src/core/srs_core_config.hpp index 50d7c1766..f5acb48c6 100644 --- a/trunk/src/core/srs_core_config.hpp +++ b/trunk/src/core/srs_core_config.hpp @@ -49,6 +49,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // in ms, for HLS aac flush the audio #define SRS_CONF_DEFAULT_AAC_DELAY 300 +#define SRS_CONF_DEFAULT_CHUNK_SIZE 4096 + +#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300 +#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100 +#define SRS_STAGE_FORWARDER_INTERVAL_MS 2000 +#define SRS_STAGE_ENCODER_INTERVAL_MS 2000 +#define SRS_STAGE_HLS_INTERVAL_MS 2000 + class SrsFileBuffer; class SrsConfDirective @@ -98,59 +106,61 @@ public: virtual void unsubscribe(SrsReloadHandler* handler); public: virtual int parse_options(int argc, char** argv); -public: - virtual SrsConfDirective* get_vhost(std::string vhost); - virtual bool get_vhost_enabled(std::string vhost); - virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); - virtual SrsConfDirective* get_vhost_on_close(std::string vhost); - virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); - virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); - virtual SrsConfDirective* get_vhost_on_play(std::string vhost); - virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); - virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); - virtual bool get_transcode_enabled(SrsConfDirective* transcode); - virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); - virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector& engines); - virtual bool get_engine_enabled(SrsConfDirective* engine); - virtual std::string get_engine_vcodec(SrsConfDirective* engine); - virtual int get_engine_vbitrate(SrsConfDirective* engine); - virtual double get_engine_vfps(SrsConfDirective* engine); - virtual int get_engine_vwidth(SrsConfDirective* engine); - virtual int get_engine_vheight(SrsConfDirective* engine); - virtual int get_engine_vthreads(SrsConfDirective* engine); - virtual std::string get_engine_vprofile(SrsConfDirective* engine); - virtual std::string get_engine_vpreset(SrsConfDirective* engine); - virtual void get_engine_vparams(SrsConfDirective* engine, std::vector& vparams); - virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector& vfilter); - virtual std::string get_engine_acodec(SrsConfDirective* engine); - virtual int get_engine_abitrate(SrsConfDirective* engine); - virtual int get_engine_asample_rate(SrsConfDirective* engine); - virtual int get_engine_achannels(SrsConfDirective* engine); - virtual void get_engine_aparams(SrsConfDirective* engine, std::vector& aparams); - virtual std::string get_engine_output(SrsConfDirective* engine); - virtual std::string get_log_dir(); - virtual int get_max_connections(); - virtual SrsConfDirective* get_gop_cache(std::string vhost); - virtual SrsConfDirective* get_forward(std::string vhost); - virtual SrsConfDirective* get_hls(std::string vhost); - virtual bool get_hls_enabled(std::string vhost); - virtual SrsConfDirective* get_hls_path(std::string vhost); - virtual SrsConfDirective* get_hls_fragment(std::string vhost); - virtual SrsConfDirective* get_hls_window(std::string vhost); - virtual SrsConfDirective* get_refer(std::string vhost); - virtual SrsConfDirective* get_refer_play(std::string vhost); - virtual SrsConfDirective* get_refer_publish(std::string vhost); - virtual SrsConfDirective* get_listen(); - virtual SrsConfDirective* get_chunk_size(); - virtual SrsConfDirective* get_pithy_print_publish(); - virtual SrsConfDirective* get_pithy_print_forwarder(); - virtual SrsConfDirective* get_pithy_print_encoder(); - virtual SrsConfDirective* get_pithy_print_hls(); - virtual SrsConfDirective* get_pithy_print_play(); private: virtual int parse_file(const char* filename); virtual int parse_argv(int& i, char** argv); virtual void print_help(char** argv); +public: + virtual SrsConfDirective* get_vhost(std::string vhost); + virtual bool get_vhost_enabled(std::string vhost); + virtual SrsConfDirective* get_vhost_on_connect(std::string vhost); + virtual SrsConfDirective* get_vhost_on_close(std::string vhost); + virtual SrsConfDirective* get_vhost_on_publish(std::string vhost); + virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost); + virtual SrsConfDirective* get_vhost_on_play(std::string vhost); + virtual SrsConfDirective* get_vhost_on_stop(std::string vhost); + virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope); + virtual bool get_transcode_enabled(SrsConfDirective* transcode); + virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode); + virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector& engines); + virtual bool get_engine_enabled(SrsConfDirective* engine); + virtual std::string get_engine_vcodec(SrsConfDirective* engine); + virtual int get_engine_vbitrate(SrsConfDirective* engine); + virtual double get_engine_vfps(SrsConfDirective* engine); + virtual int get_engine_vwidth(SrsConfDirective* engine); + virtual int get_engine_vheight(SrsConfDirective* engine); + virtual int get_engine_vthreads(SrsConfDirective* engine); + virtual std::string get_engine_vprofile(SrsConfDirective* engine); + virtual std::string get_engine_vpreset(SrsConfDirective* engine); + virtual void get_engine_vparams(SrsConfDirective* engine, std::vector& vparams); + virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector& vfilter); + virtual std::string get_engine_acodec(SrsConfDirective* engine); + virtual int get_engine_abitrate(SrsConfDirective* engine); + virtual int get_engine_asample_rate(SrsConfDirective* engine); + virtual int get_engine_achannels(SrsConfDirective* engine); + virtual void get_engine_aparams(SrsConfDirective* engine, std::vector& aparams); + virtual std::string get_engine_output(SrsConfDirective* engine); + virtual std::string get_log_dir(); + virtual int get_max_connections(); + virtual bool get_gop_cache(std::string vhost); + virtual SrsConfDirective* get_forward(std::string vhost); +private: + virtual SrsConfDirective* get_hls(std::string vhost); +public: + virtual bool get_hls_enabled(std::string vhost); + virtual std::string get_hls_path(std::string vhost); + virtual double get_hls_fragment(std::string vhost); + virtual double get_hls_window(std::string vhost); + virtual SrsConfDirective* get_refer(std::string vhost); + virtual SrsConfDirective* get_refer_play(std::string vhost); + virtual SrsConfDirective* get_refer_publish(std::string vhost); + virtual SrsConfDirective* get_listen(); + virtual int get_chunk_size(); + virtual int get_pithy_print_publish(); + virtual int get_pithy_print_forwarder(); + virtual int get_pithy_print_encoder(); + virtual int get_pithy_print_hls(); + virtual int get_pithy_print_play(); }; /** diff --git a/trunk/src/core/srs_core_hls.cpp b/trunk/src/core/srs_core_hls.cpp index 37848f6e3..ff5b8ffbf 100644 --- a/trunk/src/core/srs_core_hls.cpp +++ b/trunk/src/core/srs_core_hls.cpp @@ -1157,29 +1157,11 @@ int SrsHls::on_publish(SrsRequest* req) hls_enabled = true; // TODO: subscribe the reload event. - int hls_fragment = 0; - int hls_window = 0; - - SrsConfDirective* conf = NULL; - if ((conf = config->get_hls_fragment(vhost)) != NULL && !conf->arg0().empty()) { - hls_fragment = ::atoi(conf->arg0().c_str()); - } - if (hls_fragment <= 0) { - hls_fragment = SRS_CONF_DEFAULT_HLS_FRAGMENT; - } - - if ((conf = config->get_hls_window(vhost)) != NULL && !conf->arg0().empty()) { - hls_window = ::atoi(conf->arg0().c_str()); - } - if (hls_window <= 0) { - hls_window = SRS_CONF_DEFAULT_HLS_WINDOW; - } + int hls_fragment = config->get_hls_fragment(vhost); + int hls_window = config->get_hls_window(vhost); // get the hls path config - std::string hls_path = SRS_CONF_DEFAULT_HLS_PATH; - if ((conf = config->get_hls_path(vhost)) != NULL) { - hls_path = conf->arg0(); - } + std::string hls_path = config->get_hls_path(vhost); // open muxer if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { diff --git a/trunk/src/core/srs_core_pithy_print.cpp b/trunk/src/core/srs_core_pithy_print.cpp index 3323a10bb..4e3431ba6 100644 --- a/trunk/src/core/srs_core_pithy_print.cpp +++ b/trunk/src/core/srs_core_pithy_print.cpp @@ -32,11 +32,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #define SRS_STAGE_DEFAULT_INTERVAL_MS 1200 -#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300 -#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100 -#define SRS_STAGE_FORWARDER_INTERVAL_MS 2000 -#define SRS_STAGE_ENCODER_INTERVAL_MS 2000 -#define SRS_STAGE_HLS_INTERVAL_MS 2000 struct SrsStageInfo : public SrsReloadHandler { @@ -61,43 +56,23 @@ struct SrsStageInfo : public SrsReloadHandler { switch (stage_id) { case SRS_STAGE_PLAY_USER: { - pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS; - SrsConfDirective* conf = config->get_pithy_print_play(); - if (conf && !conf->arg0().empty()) { - pithy_print_time_ms = ::atoi(conf->arg0().c_str()); - } + pithy_print_time_ms = config->get_pithy_print_play(); break; } case SRS_STAGE_PUBLISH_USER: { - pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS; - SrsConfDirective* conf = config->get_pithy_print_publish(); - if (conf && !conf->arg0().empty()) { - pithy_print_time_ms = ::atoi(conf->arg0().c_str()); - } + pithy_print_time_ms = config->get_pithy_print_publish(); break; } case SRS_STAGE_FORWARDER: { - pithy_print_time_ms = SRS_STAGE_FORWARDER_INTERVAL_MS; - SrsConfDirective* conf = config->get_pithy_print_forwarder(); - if (conf && !conf->arg0().empty()) { - pithy_print_time_ms = ::atoi(conf->arg0().c_str()); - } + pithy_print_time_ms = config->get_pithy_print_forwarder(); break; } case SRS_STAGE_ENCODER: { - pithy_print_time_ms = SRS_STAGE_ENCODER_INTERVAL_MS; - SrsConfDirective* conf = config->get_pithy_print_encoder(); - if (conf && !conf->arg0().empty()) { - pithy_print_time_ms = ::atoi(conf->arg0().c_str()); - } + pithy_print_time_ms = config->get_pithy_print_encoder(); break; } case SRS_STAGE_HLS: { - pithy_print_time_ms = SRS_STAGE_HLS_INTERVAL_MS; - SrsConfDirective* conf = config->get_pithy_print_hls(); - if (conf && !conf->arg0().empty()) { - pithy_print_time_ms = ::atoi(conf->arg0().c_str()); - } + pithy_print_time_ms = config->get_pithy_print_hls(); break; } default: {