1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine config.

This commit is contained in:
winlin 2013-12-14 21:19:47 +08:00
parent 5b29d0ec42
commit 010b7a7595
6 changed files with 331 additions and 314 deletions

View file

@ -4,7 +4,7 @@ listen 1935;
# some client does not support chunk size change, # some client does not support chunk size change,
# however, most clients supports it and it can improve # however, most clients supports it and it can improve
# performance about 10%. # performance about 10%.
# if not specified, set to 4096. # default: 4096
chunk_size 65000; chunk_size 65000;
# the logs dir. # the logs dir.
# if enabled ffmpeg, each stracoding stream will create a log file. # if enabled ffmpeg, each stracoding stream will create a log file.
@ -21,11 +21,13 @@ max_connections 2000;
vhost __defaultVhost__ { vhost __defaultVhost__ {
enabled on; enabled on;
gop_cache on; gop_cache on;
hls on;
hls_path ./objs/nginx/html;
hls_fragment 5;
hls_window 30;
forward 127.0.0.1:19350; forward 127.0.0.1:19350;
hls {
hls on;
hls_path ./objs/nginx/html;
hls_fragment 5;
hls_window 30;
}
transcode { transcode {
enabled on; enabled on;
ffmpeg ./objs/ffmpeg/bin/ffmpeg; ffmpeg ./objs/ffmpeg/bin/ffmpeg;
@ -81,11 +83,13 @@ vhost __defaultVhost__ {
vhost dev { vhost dev {
enabled on; enabled on;
gop_cache on; gop_cache on;
hls off;
hls_path ./objs/nginx/html;
hls_fragment 5;
hls_window 30;
forward 127.0.0.1:19350; forward 127.0.0.1:19350;
hls {
hls off;
hls_path ./objs/nginx/html;
hls_fragment 5;
hls_window 30;
}
http_hooks { http_hooks {
enabled off; enabled off;
on_connect http://127.0.0.1:8085/api/v1/clients; on_connect http://127.0.0.1:8085/api/v1/clients;
@ -626,36 +630,40 @@ vhost removed.vhost.com {
enabled off; enabled off;
} }
# the vhost with hls specified. # the vhost with hls specified.
vhost no-hls.vhost.com { vhost with-hls.vhost.com {
# whether the hls is enabled. hls {
# if off, donot write hls(ts and m3u8) when publish. # whether the hls is enabled.
# default: on # if off, donot write hls(ts and m3u8) when publish.
hls on; # default: off
# the hls output path. hls on;
# the app dir is auto created under the hls_path. # the hls output path.
# for example, for rtmp stream: # the app dir is auto created under the hls_path.
# rtmp://127.0.0.1/live/livestream # for example, for rtmp stream:
# http://127.0.0.1/live/livestream.m3u8 # rtmp://127.0.0.1/live/livestream
# where hls_path is /hls, srs will create the following files: # http://127.0.0.1/live/livestream.m3u8
# /hls/live the app dir for all streams. # where hls_path is /hls, srs will create the following files:
# /hls/live/livestream.m3u8 the HLS m3u8 file. # /hls/live the app dir for all streams.
# /hls/live/livestream-1.ts the HLS media/ts file. # /hls/live/livestream.m3u8 the HLS m3u8 file.
# in a word, the hls_path is for vhost. # /hls/live/livestream-1.ts the HLS media/ts file.
# default: ./objs/nginx/html # in a word, the hls_path is for vhost.
hls_path /data/nginx/html; # default: ./objs/nginx/html
# the hls fragment in seconds, the duration of a piece of ts. hls_path /data/nginx/html;
# default: 10 # the hls fragment in seconds, the duration of a piece of ts.
hls_fragment 10; # default: 10
# the hls window in seconds, the number of ts in m3u8. hls_fragment 10;
# default: 60 # the hls window in seconds, the number of ts in m3u8.
hls_window 60; # default: 60
hls_window 60;
}
} }
# the vhost with hls disabled. # the vhost with hls disabled.
vhost no-hls.vhost.com { vhost no-hls.vhost.com {
# whether the hls is enabled. hls {
# if off, donot write hls(ts and m3u8) when publish. # whether the hls is enabled.
# default: on # if off, donot write hls(ts and m3u8) when publish.
hls off; # default: off
hls off;
}
} }
# the vhost for min delay, donot cache any stream. # the vhost for min delay, donot cache any stream.
vhost min.delay.com { vhost min.delay.com {

View file

@ -150,11 +150,7 @@ int SrsClient::service_cycle()
req->strip(); req->strip();
srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str()); srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str());
int chunk_size = 4096; int chunk_size = config->get_chunk_size();
SrsConfDirective* conf = config->get_chunk_size();
if (conf && !conf->arg0().empty()) {
chunk_size = ::atoi(conf->arg0().c_str());
}
if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
return ret; return ret;
@ -175,14 +171,9 @@ int SrsClient::service_cycle()
return ret; return ret;
} }
bool enabled_cache = true; bool enabled_cache = config->get_gop_cache(req->vhost);
conf = config->get_gop_cache(req->vhost);
if (conf && conf->arg0() == "off") {
enabled_cache = false;
}
source->set_cache(enabled_cache);
srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
source->set_cache(enabled_cache);
switch (type) { switch (type) {
case SrsClientPlay: { case SrsClientPlay: {

View file

@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
using namespace std;
#include <srs_core_error.hpp> #include <srs_core_error.hpp>
#include <srs_core_log.hpp> #include <srs_core_log.hpp>
@ -152,7 +153,7 @@ SrsConfDirective::~SrsConfDirective()
directives.clear(); directives.clear();
} }
std::string SrsConfDirective::arg0() string SrsConfDirective::arg0()
{ {
if (args.size() > 0) { if (args.size() > 0) {
return args.at(0); return args.at(0);
@ -161,7 +162,7 @@ std::string SrsConfDirective::arg0()
return ""; return "";
} }
std::string SrsConfDirective::arg1() string SrsConfDirective::arg1()
{ {
if (args.size() > 1) { if (args.size() > 1) {
return args.at(1); return args.at(1);
@ -170,7 +171,7 @@ std::string SrsConfDirective::arg1()
return ""; return "";
} }
std::string SrsConfDirective::arg2() string SrsConfDirective::arg2()
{ {
if (args.size() > 2) { if (args.size() > 2) {
return args.at(2); return args.at(2);
@ -184,7 +185,7 @@ SrsConfDirective* SrsConfDirective::at(int index)
return directives.at(index); return directives.at(index);
} }
SrsConfDirective* SrsConfDirective::get(std::string _name) SrsConfDirective* SrsConfDirective::get(string _name)
{ {
std::vector<SrsConfDirective*>::iterator it; std::vector<SrsConfDirective*>::iterator it;
for (it = directives.begin(); it != directives.end(); ++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; int ret = ERROR_SUCCESS;
while (true) { while (true) {
std::vector<std::string> args; std::vector<string> args;
ret = read_token(buffer, args); ret = read_token(buffer, args);
/** /**
@ -271,7 +272,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type)
} }
// see: ngx_conf_read_token // see: ngx_conf_read_token
int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>& args) int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& args)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -395,7 +396,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
memcpy(word, pstart, len); memcpy(word, pstart, len);
word[len - 1] = 0; word[len - 1] = 0;
std::string word_str = word; string word_str = word;
if (!word_str.empty()) { if (!word_str.empty()) {
args.push_back(word_str); args.push_back(word_str);
} }
@ -537,7 +538,102 @@ int SrsConfig::parse_options(int argc, char** argv)
return parse_file(config_file.c_str()); 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 <filename>]\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); srs_assert(root);
@ -560,7 +656,7 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
return NULL; return NULL;
} }
SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost) SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);
@ -581,7 +677,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost)
return conf->get("on_connect"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -602,7 +698,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost)
return conf->get("on_close"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -623,7 +719,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost)
return conf->get("on_publish"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -644,7 +740,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost)
return conf->get("on_unpublish"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -665,7 +761,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost)
return conf->get("on_play"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -686,7 +782,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost)
return conf->get("on_stop"); 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); SrsConfDirective* vhost_conf = get_vhost(vhost);
@ -706,7 +802,7 @@ bool SrsConfig::get_vhost_enabled(std::string vhost)
return true; 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); SrsConfDirective* conf = get_vhost(vhost);
@ -740,7 +836,7 @@ bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode)
return true; return true;
} }
std::string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode)
{ {
if (!transcode) { if (!transcode) {
return ""; return "";
@ -785,7 +881,7 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
return true; return true;
} }
std::string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) string SrsConfig::get_engine_vcodec(SrsConfDirective* engine)
{ {
if (!engine) { if (!engine) {
return ""; return "";
@ -869,7 +965,7 @@ int SrsConfig::get_engine_vthreads(SrsConfDirective* engine)
return ::atoi(conf->arg0().c_str()); return ::atoi(conf->arg0().c_str());
} }
std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) string SrsConfig::get_engine_vprofile(SrsConfDirective* engine)
{ {
if (!engine) { if (!engine) {
return ""; return "";
@ -883,7 +979,7 @@ std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine)
return conf->arg0(); return conf->arg0();
} }
std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
{ {
if (!engine) { if (!engine) {
return ""; return "";
@ -897,7 +993,7 @@ std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
return conf->arg0(); return conf->arg0();
} }
void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams) void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<string>& vparams)
{ {
if (!engine) { if (!engine) {
return; return;
@ -919,7 +1015,7 @@ void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::st
} }
} }
void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter) void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<string>& vfilter)
{ {
if (!engine) { if (!engine) {
return; return;
@ -941,7 +1037,7 @@ void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::st
} }
} }
std::string SrsConfig::get_engine_acodec(SrsConfDirective* engine) string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
{ {
if (!engine) { if (!engine) {
return ""; return "";
@ -997,7 +1093,7 @@ int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
return ::atoi(conf->arg0().c_str()); return ::atoi(conf->arg0().c_str());
} }
void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams) void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<string>& aparams)
{ {
if (!engine) { if (!engine) {
return; return;
@ -1019,7 +1115,7 @@ void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::st
} }
} }
std::string SrsConfig::get_engine_output(SrsConfDirective* engine) string SrsConfig::get_engine_output(SrsConfDirective* engine)
{ {
if (!engine) { if (!engine) {
return ""; return "";
@ -1033,7 +1129,7 @@ std::string SrsConfig::get_engine_output(SrsConfDirective* engine)
return conf->arg0(); return conf->arg0();
} }
std::string SrsConfig::get_log_dir() string SrsConfig::get_log_dir()
{ {
srs_assert(root); srs_assert(root);
@ -1057,18 +1153,22 @@ int SrsConfig::get_max_connections()
return ::atoi(conf->arg0().c_str()); 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); SrsConfDirective* conf = get_vhost(vhost);
if (!conf) { 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); SrsConfDirective* conf = get_vhost(vhost);
@ -1079,7 +1179,7 @@ SrsConfDirective* SrsConfig::get_forward(std::string vhost)
return conf->get("forward"); return conf->get("forward");
} }
SrsConfDirective* SrsConfig::get_hls(std::string vhost) SrsConfDirective* SrsConfig::get_hls(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);
@ -1090,12 +1190,12 @@ SrsConfDirective* SrsConfig::get_hls(std::string vhost)
return conf->get("hls"); return conf->get("hls");
} }
bool SrsConfig::get_hls_enabled(std::string vhost) bool SrsConfig::get_hls_enabled(string vhost)
{ {
SrsConfDirective* hls = get_hls(vhost); SrsConfDirective* hls = get_hls(vhost);
if (!hls) { if (!hls) {
return true; return false;
} }
if (hls->arg0() == "off") { if (hls->arg0() == "off") {
@ -1105,40 +1205,58 @@ bool SrsConfig::get_hls_enabled(std::string vhost)
return true; return true;
} }
SrsConfDirective* SrsConfig::get_hls_path(std::string vhost) string SrsConfig::get_hls_path(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* hls = get_hls(vhost);
if (!conf) { if (!hls) {
return NULL; 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); SrsConfDirective* hls = get_hls(vhost);
if (!conf) { if (!hls) {
return NULL; 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); SrsConfDirective* hls = get_hls(vhost);
if (!conf) { if (!hls) {
return NULL; 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); SrsConfDirective* conf = get_vhost(vhost);
@ -1149,7 +1267,7 @@ SrsConfDirective* SrsConfig::get_refer(std::string vhost)
return conf->get("refer"); return conf->get("refer");
} }
SrsConfDirective* SrsConfig::get_refer_play(std::string vhost) SrsConfDirective* SrsConfig::get_refer_play(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);
@ -1160,7 +1278,7 @@ SrsConfDirective* SrsConfig::get_refer_play(std::string vhost)
return conf->get("refer_play"); 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); SrsConfDirective* conf = get_vhost(vhost);
@ -1176,156 +1294,89 @@ SrsConfDirective* SrsConfig::get_listen()
return root->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"); SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) { if (!pithy) {
return NULL; return SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
} }
return pithy->get("publish"); pithy = pithy->get("publish");
if (!pithy) {
return SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
}
return ::atoi(pithy->arg0().c_str());
} }
SrsConfDirective* SrsConfig::get_pithy_print_forwarder() int SrsConfig::get_pithy_print_forwarder()
{ {
SrsConfDirective* pithy = root->get("pithy_print"); SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) { if (!pithy) {
return NULL; return SRS_STAGE_FORWARDER_INTERVAL_MS;
} }
return pithy->get("forwarder"); pithy = pithy->get("forwarder");
if (!pithy) {
return SRS_STAGE_FORWARDER_INTERVAL_MS;
}
return ::atoi(pithy->arg0().c_str());
} }
SrsConfDirective* SrsConfig::get_pithy_print_hls() int SrsConfig::get_pithy_print_hls()
{ {
SrsConfDirective* pithy = root->get("pithy_print"); SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) { if (!pithy) {
return NULL; return SRS_STAGE_HLS_INTERVAL_MS;
} }
return pithy->get("hls"); pithy = pithy->get("hls");
if (!pithy) {
return SRS_STAGE_HLS_INTERVAL_MS;
}
return ::atoi(pithy->arg0().c_str());
} }
SrsConfDirective* SrsConfig::get_pithy_print_encoder() int SrsConfig::get_pithy_print_encoder()
{ {
SrsConfDirective* pithy = root->get("encoder"); SrsConfDirective* pithy = root->get("encoder");
if (!pithy) { if (!pithy) {
return NULL; return SRS_STAGE_ENCODER_INTERVAL_MS;
} }
return pithy->get("forwarder"); pithy = pithy->get("forwarder");
if (!pithy) {
return SRS_STAGE_ENCODER_INTERVAL_MS;
}
return ::atoi(pithy->arg0().c_str());
} }
SrsConfDirective* SrsConfig::get_pithy_print_play() int SrsConfig::get_pithy_print_play()
{ {
SrsConfDirective* pithy = root->get("pithy_print"); SrsConfDirective* pithy = root->get("pithy_print");
if (!pithy) { if (!pithy) {
return NULL; return SRS_STAGE_PLAY_USER_INTERVAL_MS;
} }
return pithy->get("play"); pithy = pithy->get("play");
} if (!pithy) {
return SRS_STAGE_PLAY_USER_INTERVAL_MS;
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 ::atoi(pithy->arg0().c_str());
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 other config.
// TODO: check hls.
// TODO: check ssl.
// 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 <filename>]\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]);
} }
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b)

View file

@ -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 // in ms, for HLS aac flush the audio
#define SRS_CONF_DEFAULT_AAC_DELAY 300 #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 SrsFileBuffer;
class SrsConfDirective class SrsConfDirective
@ -98,59 +106,61 @@ public:
virtual void unsubscribe(SrsReloadHandler* handler); virtual void unsubscribe(SrsReloadHandler* handler);
public: public:
virtual int parse_options(int argc, char** argv); 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<SrsConfDirective*>& 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<std::string>& vparams);
virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& 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<std::string>& 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: private:
virtual int parse_file(const char* filename); virtual int parse_file(const char* filename);
virtual int parse_argv(int& i, char** argv); virtual int parse_argv(int& i, char** argv);
virtual void print_help(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<SrsConfDirective*>& 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<std::string>& vparams);
virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& 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<std::string>& 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();
}; };
/** /**

View file

@ -1157,29 +1157,11 @@ int SrsHls::on_publish(SrsRequest* req)
hls_enabled = true; hls_enabled = true;
// TODO: subscribe the reload event. // TODO: subscribe the reload event.
int hls_fragment = 0; int hls_fragment = config->get_hls_fragment(vhost);
int hls_window = 0; int hls_window = config->get_hls_window(vhost);
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;
}
// get the hls path config // get the hls path config
std::string hls_path = SRS_CONF_DEFAULT_HLS_PATH; std::string hls_path = config->get_hls_path(vhost);
if ((conf = config->get_hls_path(vhost)) != NULL) {
hls_path = conf->arg0();
}
// open muxer // open muxer
if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {

View file

@ -32,11 +32,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_error.hpp> #include <srs_core_error.hpp>
#define SRS_STAGE_DEFAULT_INTERVAL_MS 1200 #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 struct SrsStageInfo : public SrsReloadHandler
{ {
@ -61,43 +56,23 @@ struct SrsStageInfo : public SrsReloadHandler
{ {
switch (stage_id) { switch (stage_id) {
case SRS_STAGE_PLAY_USER: { case SRS_STAGE_PLAY_USER: {
pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS; pithy_print_time_ms = config->get_pithy_print_play();
SrsConfDirective* conf = config->get_pithy_print_play();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break; break;
} }
case SRS_STAGE_PUBLISH_USER: { case SRS_STAGE_PUBLISH_USER: {
pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS; pithy_print_time_ms = config->get_pithy_print_publish();
SrsConfDirective* conf = config->get_pithy_print_publish();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break; break;
} }
case SRS_STAGE_FORWARDER: { case SRS_STAGE_FORWARDER: {
pithy_print_time_ms = SRS_STAGE_FORWARDER_INTERVAL_MS; pithy_print_time_ms = config->get_pithy_print_forwarder();
SrsConfDirective* conf = config->get_pithy_print_forwarder();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break; break;
} }
case SRS_STAGE_ENCODER: { case SRS_STAGE_ENCODER: {
pithy_print_time_ms = SRS_STAGE_ENCODER_INTERVAL_MS; pithy_print_time_ms = config->get_pithy_print_encoder();
SrsConfDirective* conf = config->get_pithy_print_encoder();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break; break;
} }
case SRS_STAGE_HLS: { case SRS_STAGE_HLS: {
pithy_print_time_ms = SRS_STAGE_HLS_INTERVAL_MS; pithy_print_time_ms = config->get_pithy_print_hls();
SrsConfDirective* conf = config->get_pithy_print_hls();
if (conf && !conf->arg0().empty()) {
pithy_print_time_ms = ::atoi(conf->arg0().c_str());
}
break; break;
} }
default: { default: {