winlin

refine config.

@@ -4,7 +4,7 @@ listen 1935; @@ -4,7 +4,7 @@ listen 1935;
4 # some client does not support chunk size change, 4 # some client does not support chunk size change,
5 # however, most clients supports it and it can improve 5 # however, most clients supports it and it can improve
6 # performance about 10%. 6 # performance about 10%.
7 -# if not specified, set to 4096. 7 +# default: 4096
8 chunk_size 65000; 8 chunk_size 65000;
9 # the logs dir. 9 # the logs dir.
10 # if enabled ffmpeg, each stracoding stream will create a log file. 10 # if enabled ffmpeg, each stracoding stream will create a log file.
@@ -21,11 +21,13 @@ max_connections 2000; @@ -21,11 +21,13 @@ max_connections 2000;
21 vhost __defaultVhost__ { 21 vhost __defaultVhost__ {
22 enabled on; 22 enabled on;
23 gop_cache on; 23 gop_cache on;
24 - hls on;  
25 - hls_path ./objs/nginx/html;  
26 - hls_fragment 5;  
27 - hls_window 30;  
28 forward 127.0.0.1:19350; 24 forward 127.0.0.1:19350;
  25 + hls {
  26 + hls on;
  27 + hls_path ./objs/nginx/html;
  28 + hls_fragment 5;
  29 + hls_window 30;
  30 + }
29 transcode { 31 transcode {
30 enabled on; 32 enabled on;
31 ffmpeg ./objs/ffmpeg/bin/ffmpeg; 33 ffmpeg ./objs/ffmpeg/bin/ffmpeg;
@@ -81,11 +83,13 @@ vhost __defaultVhost__ { @@ -81,11 +83,13 @@ vhost __defaultVhost__ {
81 vhost dev { 83 vhost dev {
82 enabled on; 84 enabled on;
83 gop_cache on; 85 gop_cache on;
84 - hls off;  
85 - hls_path ./objs/nginx/html;  
86 - hls_fragment 5;  
87 - hls_window 30;  
88 forward 127.0.0.1:19350; 86 forward 127.0.0.1:19350;
  87 + hls {
  88 + hls off;
  89 + hls_path ./objs/nginx/html;
  90 + hls_fragment 5;
  91 + hls_window 30;
  92 + }
89 http_hooks { 93 http_hooks {
90 enabled off; 94 enabled off;
91 on_connect http://127.0.0.1:8085/api/v1/clients; 95 on_connect http://127.0.0.1:8085/api/v1/clients;
@@ -626,36 +630,40 @@ vhost removed.vhost.com { @@ -626,36 +630,40 @@ vhost removed.vhost.com {
626 enabled off; 630 enabled off;
627 } 631 }
628 # the vhost with hls specified. 632 # the vhost with hls specified.
629 -vhost no-hls.vhost.com {  
630 - # whether the hls is enabled.  
631 - # if off, donot write hls(ts and m3u8) when publish.  
632 - # default: on  
633 - hls on;  
634 - # the hls output path.  
635 - # the app dir is auto created under the hls_path.  
636 - # for example, for rtmp stream:  
637 - # rtmp://127.0.0.1/live/livestream  
638 - # http://127.0.0.1/live/livestream.m3u8  
639 - # where hls_path is /hls, srs will create the following files:  
640 - # /hls/live the app dir for all streams.  
641 - # /hls/live/livestream.m3u8 the HLS m3u8 file.  
642 - # /hls/live/livestream-1.ts the HLS media/ts file.  
643 - # in a word, the hls_path is for vhost.  
644 - # default: ./objs/nginx/html  
645 - hls_path /data/nginx/html;  
646 - # the hls fragment in seconds, the duration of a piece of ts.  
647 - # default: 10  
648 - hls_fragment 10;  
649 - # the hls window in seconds, the number of ts in m3u8.  
650 - # default: 60  
651 - hls_window 60; 633 +vhost with-hls.vhost.com {
  634 + hls {
  635 + # whether the hls is enabled.
  636 + # if off, donot write hls(ts and m3u8) when publish.
  637 + # default: off
  638 + hls on;
  639 + # the hls output path.
  640 + # the app dir is auto created under the hls_path.
  641 + # for example, for rtmp stream:
  642 + # rtmp://127.0.0.1/live/livestream
  643 + # http://127.0.0.1/live/livestream.m3u8
  644 + # where hls_path is /hls, srs will create the following files:
  645 + # /hls/live the app dir for all streams.
  646 + # /hls/live/livestream.m3u8 the HLS m3u8 file.
  647 + # /hls/live/livestream-1.ts the HLS media/ts file.
  648 + # in a word, the hls_path is for vhost.
  649 + # default: ./objs/nginx/html
  650 + hls_path /data/nginx/html;
  651 + # the hls fragment in seconds, the duration of a piece of ts.
  652 + # default: 10
  653 + hls_fragment 10;
  654 + # the hls window in seconds, the number of ts in m3u8.
  655 + # default: 60
  656 + hls_window 60;
  657 + }
652 } 658 }
653 # the vhost with hls disabled. 659 # the vhost with hls disabled.
654 vhost no-hls.vhost.com { 660 vhost no-hls.vhost.com {
655 - # whether the hls is enabled.  
656 - # if off, donot write hls(ts and m3u8) when publish.  
657 - # default: on  
658 - hls off; 661 + hls {
  662 + # whether the hls is enabled.
  663 + # if off, donot write hls(ts and m3u8) when publish.
  664 + # default: off
  665 + hls off;
  666 + }
659 } 667 }
660 # the vhost for min delay, donot cache any stream. 668 # the vhost for min delay, donot cache any stream.
661 vhost min.delay.com { 669 vhost min.delay.com {
@@ -150,11 +150,7 @@ int SrsClient::service_cycle() @@ -150,11 +150,7 @@ int SrsClient::service_cycle()
150 req->strip(); 150 req->strip();
151 srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str()); 151 srs_trace("identify client success. type=%d, stream_name=%s", type, req->stream.c_str());
152 152
153 - int chunk_size = 4096;  
154 - SrsConfDirective* conf = config->get_chunk_size();  
155 - if (conf && !conf->arg0().empty()) {  
156 - chunk_size = ::atoi(conf->arg0().c_str());  
157 - } 153 + int chunk_size = config->get_chunk_size();
158 if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) { 154 if ((ret = rtmp->set_chunk_size(chunk_size)) != ERROR_SUCCESS) {
159 srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret); 155 srs_error("set chunk_size=%d failed. ret=%d", chunk_size, ret);
160 return ret; 156 return ret;
@@ -175,14 +171,9 @@ int SrsClient::service_cycle() @@ -175,14 +171,9 @@ int SrsClient::service_cycle()
175 return ret; 171 return ret;
176 } 172 }
177 173
178 - bool enabled_cache = true;  
179 - conf = config->get_gop_cache(req->vhost);  
180 - if (conf && conf->arg0() == "off") {  
181 - enabled_cache = false;  
182 - }  
183 - source->set_cache(enabled_cache);  
184 - 174 + bool enabled_cache = config->get_gop_cache(req->vhost);
185 srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache); 175 srs_info("source found, url=%s, enabled_cache=%d", req->get_stream_url().c_str(), enabled_cache);
  176 + source->set_cache(enabled_cache);
186 177
187 switch (type) { 178 switch (type) {
188 case SrsClientPlay: { 179 case SrsClientPlay: {
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 35
36 #include <vector> 36 #include <vector>
37 #include <algorithm> 37 #include <algorithm>
  38 +using namespace std;
38 39
39 #include <srs_core_error.hpp> 40 #include <srs_core_error.hpp>
40 #include <srs_core_log.hpp> 41 #include <srs_core_log.hpp>
@@ -152,7 +153,7 @@ SrsConfDirective::~SrsConfDirective() @@ -152,7 +153,7 @@ SrsConfDirective::~SrsConfDirective()
152 directives.clear(); 153 directives.clear();
153 } 154 }
154 155
155 -std::string SrsConfDirective::arg0() 156 +string SrsConfDirective::arg0()
156 { 157 {
157 if (args.size() > 0) { 158 if (args.size() > 0) {
158 return args.at(0); 159 return args.at(0);
@@ -161,7 +162,7 @@ std::string SrsConfDirective::arg0() @@ -161,7 +162,7 @@ std::string SrsConfDirective::arg0()
161 return ""; 162 return "";
162 } 163 }
163 164
164 -std::string SrsConfDirective::arg1() 165 +string SrsConfDirective::arg1()
165 { 166 {
166 if (args.size() > 1) { 167 if (args.size() > 1) {
167 return args.at(1); 168 return args.at(1);
@@ -170,7 +171,7 @@ std::string SrsConfDirective::arg1() @@ -170,7 +171,7 @@ std::string SrsConfDirective::arg1()
170 return ""; 171 return "";
171 } 172 }
172 173
173 -std::string SrsConfDirective::arg2() 174 +string SrsConfDirective::arg2()
174 { 175 {
175 if (args.size() > 2) { 176 if (args.size() > 2) {
176 return args.at(2); 177 return args.at(2);
@@ -184,7 +185,7 @@ SrsConfDirective* SrsConfDirective::at(int index) @@ -184,7 +185,7 @@ SrsConfDirective* SrsConfDirective::at(int index)
184 return directives.at(index); 185 return directives.at(index);
185 } 186 }
186 187
187 -SrsConfDirective* SrsConfDirective::get(std::string _name) 188 +SrsConfDirective* SrsConfDirective::get(string _name)
188 { 189 {
189 std::vector<SrsConfDirective*>::iterator it; 190 std::vector<SrsConfDirective*>::iterator it;
190 for (it = directives.begin(); it != directives.end(); ++it) { 191 for (it = directives.begin(); it != directives.end(); ++it) {
@@ -216,7 +217,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type) @@ -216,7 +217,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type)
216 int ret = ERROR_SUCCESS; 217 int ret = ERROR_SUCCESS;
217 218
218 while (true) { 219 while (true) {
219 - std::vector<std::string> args; 220 + std::vector<string> args;
220 ret = read_token(buffer, args); 221 ret = read_token(buffer, args);
221 222
222 /** 223 /**
@@ -271,7 +272,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type) @@ -271,7 +272,7 @@ int SrsConfDirective::parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type)
271 } 272 }
272 273
273 // see: ngx_conf_read_token 274 // see: ngx_conf_read_token
274 -int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>& args) 275 +int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<string>& args)
275 { 276 {
276 int ret = ERROR_SUCCESS; 277 int ret = ERROR_SUCCESS;
277 278
@@ -395,7 +396,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string> @@ -395,7 +396,7 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string>
395 memcpy(word, pstart, len); 396 memcpy(word, pstart, len);
396 word[len - 1] = 0; 397 word[len - 1] = 0;
397 398
398 - std::string word_str = word; 399 + string word_str = word;
399 if (!word_str.empty()) { 400 if (!word_str.empty()) {
400 args.push_back(word_str); 401 args.push_back(word_str);
401 } 402 }
@@ -537,7 +538,102 @@ int SrsConfig::parse_options(int argc, char** argv) @@ -537,7 +538,102 @@ int SrsConfig::parse_options(int argc, char** argv)
537 return parse_file(config_file.c_str()); 538 return parse_file(config_file.c_str());
538 } 539 }
539 540
540 -SrsConfDirective* SrsConfig::get_vhost(std::string vhost) 541 +int SrsConfig::parse_file(const char* filename)
  542 +{
  543 + int ret = ERROR_SUCCESS;
  544 +
  545 + config_file = filename;
  546 +
  547 + if (config_file.empty()) {
  548 + return ERROR_SYSTEM_CONFIG_INVALID;
  549 + }
  550 +
  551 + if ((ret = root->parse(config_file.c_str())) != ERROR_SUCCESS) {
  552 + return ret;
  553 + }
  554 +
  555 + SrsConfDirective* conf = NULL;
  556 + if ((conf = get_listen()) == NULL || conf->args.size() == 0) {
  557 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  558 + srs_error("line %d: conf error, "
  559 + "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);
  560 + return ret;
  561 + }
  562 +
  563 + // TODO: check the hls.
  564 + // TODO: check forward.
  565 + // TODO: check ffmpeg.
  566 + // TODO: check http.
  567 +
  568 + return ret;
  569 +}
  570 +
  571 +int SrsConfig::parse_argv(int& i, char** argv)
  572 +{
  573 + int ret = ERROR_SUCCESS;
  574 +
  575 + char* p = argv[i];
  576 +
  577 + if (*p++ != '-') {
  578 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  579 + srs_error("invalid options(index=%d, value=%s), "
  580 + "must starts with -, see help: %s -h, ret=%d", i, argv[i], argv[0], ret);
  581 + return ret;
  582 + }
  583 +
  584 + while (*p) {
  585 + switch (*p++) {
  586 + case '?':
  587 + case 'h':
  588 + show_help = true;
  589 + break;
  590 + case 'v':
  591 + case 'V':
  592 + show_version = true;
  593 + break;
  594 + case 'c':
  595 + if (*p) {
  596 + config_file = p;
  597 + return ret;
  598 + }
  599 + if (argv[++i]) {
  600 + config_file = argv[i];
  601 + return ret;
  602 + }
  603 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  604 + srs_error("option \"-c\" requires parameter, ret=%d", ret);
  605 + return ret;
  606 + default:
  607 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  608 + srs_error("invalid option: \"%c\", see help: %s -h, ret=%d", *(p - 1), argv[0], ret);
  609 + return ret;
  610 + }
  611 + }
  612 +
  613 + return ret;
  614 +}
  615 +
  616 +void SrsConfig::print_help(char** argv)
  617 +{
  618 + printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION
  619 + " Copyright (c) 2013 winlin\n"
  620 + "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n"
  621 + "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n"
  622 + "Usage: %s [-h?vV] [-c <filename>]\n"
  623 + "\n"
  624 + "Options:\n"
  625 + " -?-h : show help\n"
  626 + " -v-V : show version and exit\n"
  627 + " -c filename : set configuration file\n"
  628 + "\n"
  629 + RTMP_SIG_SRS_WEB"\n"
  630 + RTMP_SIG_SRS_URL"\n"
  631 + "Email: "RTMP_SIG_SRS_EMAIL"\n"
  632 + "\n",
  633 + argv[0]);
  634 +}
  635 +
  636 +SrsConfDirective* SrsConfig::get_vhost(string vhost)
541 { 637 {
542 srs_assert(root); 638 srs_assert(root);
543 639
@@ -560,7 +656,7 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost) @@ -560,7 +656,7 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
560 return NULL; 656 return NULL;
561 } 657 }
562 658
563 -SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost) 659 +SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
564 { 660 {
565 SrsConfDirective* conf = get_vhost(vhost); 661 SrsConfDirective* conf = get_vhost(vhost);
566 662
@@ -581,7 +677,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost) @@ -581,7 +677,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_connect(std::string vhost)
581 return conf->get("on_connect"); 677 return conf->get("on_connect");
582 } 678 }
583 679
584 -SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost) 680 +SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost)
585 { 681 {
586 SrsConfDirective* conf = get_vhost(vhost); 682 SrsConfDirective* conf = get_vhost(vhost);
587 683
@@ -602,7 +698,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost) @@ -602,7 +698,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_close(std::string vhost)
602 return conf->get("on_close"); 698 return conf->get("on_close");
603 } 699 }
604 700
605 -SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost) 701 +SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost)
606 { 702 {
607 SrsConfDirective* conf = get_vhost(vhost); 703 SrsConfDirective* conf = get_vhost(vhost);
608 704
@@ -623,7 +719,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost) @@ -623,7 +719,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_publish(std::string vhost)
623 return conf->get("on_publish"); 719 return conf->get("on_publish");
624 } 720 }
625 721
626 -SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost) 722 +SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost)
627 { 723 {
628 SrsConfDirective* conf = get_vhost(vhost); 724 SrsConfDirective* conf = get_vhost(vhost);
629 725
@@ -644,7 +740,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost) @@ -644,7 +740,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_unpublish(std::string vhost)
644 return conf->get("on_unpublish"); 740 return conf->get("on_unpublish");
645 } 741 }
646 742
647 -SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost) 743 +SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost)
648 { 744 {
649 SrsConfDirective* conf = get_vhost(vhost); 745 SrsConfDirective* conf = get_vhost(vhost);
650 746
@@ -665,7 +761,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost) @@ -665,7 +761,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_play(std::string vhost)
665 return conf->get("on_play"); 761 return conf->get("on_play");
666 } 762 }
667 763
668 -SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost) 764 +SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
669 { 765 {
670 SrsConfDirective* conf = get_vhost(vhost); 766 SrsConfDirective* conf = get_vhost(vhost);
671 767
@@ -686,7 +782,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost) @@ -686,7 +782,7 @@ SrsConfDirective* SrsConfig::get_vhost_on_stop(std::string vhost)
686 return conf->get("on_stop"); 782 return conf->get("on_stop");
687 } 783 }
688 784
689 -bool SrsConfig::get_vhost_enabled(std::string vhost) 785 +bool SrsConfig::get_vhost_enabled(string vhost)
690 { 786 {
691 SrsConfDirective* vhost_conf = get_vhost(vhost); 787 SrsConfDirective* vhost_conf = get_vhost(vhost);
692 788
@@ -706,7 +802,7 @@ bool SrsConfig::get_vhost_enabled(std::string vhost) @@ -706,7 +802,7 @@ bool SrsConfig::get_vhost_enabled(std::string vhost)
706 return true; 802 return true;
707 } 803 }
708 804
709 -SrsConfDirective* SrsConfig::get_transcode(std::string vhost, std::string scope) 805 +SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope)
710 { 806 {
711 SrsConfDirective* conf = get_vhost(vhost); 807 SrsConfDirective* conf = get_vhost(vhost);
712 808
@@ -740,7 +836,7 @@ bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode) @@ -740,7 +836,7 @@ bool SrsConfig::get_transcode_enabled(SrsConfDirective* transcode)
740 return true; 836 return true;
741 } 837 }
742 838
743 -std::string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode) 839 +string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* transcode)
744 { 840 {
745 if (!transcode) { 841 if (!transcode) {
746 return ""; 842 return "";
@@ -785,7 +881,7 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine) @@ -785,7 +881,7 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
785 return true; 881 return true;
786 } 882 }
787 883
788 -std::string SrsConfig::get_engine_vcodec(SrsConfDirective* engine) 884 +string SrsConfig::get_engine_vcodec(SrsConfDirective* engine)
789 { 885 {
790 if (!engine) { 886 if (!engine) {
791 return ""; 887 return "";
@@ -869,7 +965,7 @@ int SrsConfig::get_engine_vthreads(SrsConfDirective* engine) @@ -869,7 +965,7 @@ int SrsConfig::get_engine_vthreads(SrsConfDirective* engine)
869 return ::atoi(conf->arg0().c_str()); 965 return ::atoi(conf->arg0().c_str());
870 } 966 }
871 967
872 -std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) 968 +string SrsConfig::get_engine_vprofile(SrsConfDirective* engine)
873 { 969 {
874 if (!engine) { 970 if (!engine) {
875 return ""; 971 return "";
@@ -883,7 +979,7 @@ std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine) @@ -883,7 +979,7 @@ std::string SrsConfig::get_engine_vprofile(SrsConfDirective* engine)
883 return conf->arg0(); 979 return conf->arg0();
884 } 980 }
885 981
886 -std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) 982 +string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
887 { 983 {
888 if (!engine) { 984 if (!engine) {
889 return ""; 985 return "";
@@ -897,7 +993,7 @@ std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine) @@ -897,7 +993,7 @@ std::string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
897 return conf->arg0(); 993 return conf->arg0();
898 } 994 }
899 995
900 -void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams) 996 +void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<string>& vparams)
901 { 997 {
902 if (!engine) { 998 if (!engine) {
903 return; 999 return;
@@ -919,7 +1015,7 @@ void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::st @@ -919,7 +1015,7 @@ void SrsConfig::get_engine_vparams(SrsConfDirective* engine, std::vector<std::st
919 } 1015 }
920 } 1016 }
921 1017
922 -void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter) 1018 +void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<string>& vfilter)
923 { 1019 {
924 if (!engine) { 1020 if (!engine) {
925 return; 1021 return;
@@ -941,7 +1037,7 @@ void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::st @@ -941,7 +1037,7 @@ void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, std::vector<std::st
941 } 1037 }
942 } 1038 }
943 1039
944 -std::string SrsConfig::get_engine_acodec(SrsConfDirective* engine) 1040 +string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
945 { 1041 {
946 if (!engine) { 1042 if (!engine) {
947 return ""; 1043 return "";
@@ -997,7 +1093,7 @@ int SrsConfig::get_engine_achannels(SrsConfDirective* engine) @@ -997,7 +1093,7 @@ int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
997 return ::atoi(conf->arg0().c_str()); 1093 return ::atoi(conf->arg0().c_str());
998 } 1094 }
999 1095
1000 -void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams) 1096 +void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<string>& aparams)
1001 { 1097 {
1002 if (!engine) { 1098 if (!engine) {
1003 return; 1099 return;
@@ -1019,7 +1115,7 @@ void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::st @@ -1019,7 +1115,7 @@ void SrsConfig::get_engine_aparams(SrsConfDirective* engine, std::vector<std::st
1019 } 1115 }
1020 } 1116 }
1021 1117
1022 -std::string SrsConfig::get_engine_output(SrsConfDirective* engine) 1118 +string SrsConfig::get_engine_output(SrsConfDirective* engine)
1023 { 1119 {
1024 if (!engine) { 1120 if (!engine) {
1025 return ""; 1121 return "";
@@ -1033,7 +1129,7 @@ std::string SrsConfig::get_engine_output(SrsConfDirective* engine) @@ -1033,7 +1129,7 @@ std::string SrsConfig::get_engine_output(SrsConfDirective* engine)
1033 return conf->arg0(); 1129 return conf->arg0();
1034 } 1130 }
1035 1131
1036 -std::string SrsConfig::get_log_dir() 1132 +string SrsConfig::get_log_dir()
1037 { 1133 {
1038 srs_assert(root); 1134 srs_assert(root);
1039 1135
@@ -1057,18 +1153,22 @@ int SrsConfig::get_max_connections() @@ -1057,18 +1153,22 @@ int SrsConfig::get_max_connections()
1057 return ::atoi(conf->arg0().c_str()); 1153 return ::atoi(conf->arg0().c_str());
1058 } 1154 }
1059 1155
1060 -SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) 1156 +bool SrsConfig::get_gop_cache(string vhost)
1061 { 1157 {
1062 SrsConfDirective* conf = get_vhost(vhost); 1158 SrsConfDirective* conf = get_vhost(vhost);
1063 1159
1064 if (!conf) { 1160 if (!conf) {
1065 - return NULL; 1161 + return true;
1066 } 1162 }
1067 1163
1068 - return conf->get("gop_cache"); 1164 + if (conf && conf->arg0() == "off") {
  1165 + return false;
  1166 + }
  1167 +
  1168 + return true;
1069 } 1169 }
1070 1170
1071 -SrsConfDirective* SrsConfig::get_forward(std::string vhost) 1171 +SrsConfDirective* SrsConfig::get_forward(string vhost)
1072 { 1172 {
1073 SrsConfDirective* conf = get_vhost(vhost); 1173 SrsConfDirective* conf = get_vhost(vhost);
1074 1174
@@ -1079,7 +1179,7 @@ SrsConfDirective* SrsConfig::get_forward(std::string vhost) @@ -1079,7 +1179,7 @@ SrsConfDirective* SrsConfig::get_forward(std::string vhost)
1079 return conf->get("forward"); 1179 return conf->get("forward");
1080 } 1180 }
1081 1181
1082 -SrsConfDirective* SrsConfig::get_hls(std::string vhost) 1182 +SrsConfDirective* SrsConfig::get_hls(string vhost)
1083 { 1183 {
1084 SrsConfDirective* conf = get_vhost(vhost); 1184 SrsConfDirective* conf = get_vhost(vhost);
1085 1185
@@ -1090,12 +1190,12 @@ SrsConfDirective* SrsConfig::get_hls(std::string vhost) @@ -1090,12 +1190,12 @@ SrsConfDirective* SrsConfig::get_hls(std::string vhost)
1090 return conf->get("hls"); 1190 return conf->get("hls");
1091 } 1191 }
1092 1192
1093 -bool SrsConfig::get_hls_enabled(std::string vhost) 1193 +bool SrsConfig::get_hls_enabled(string vhost)
1094 { 1194 {
1095 SrsConfDirective* hls = get_hls(vhost); 1195 SrsConfDirective* hls = get_hls(vhost);
1096 1196
1097 if (!hls) { 1197 if (!hls) {
1098 - return true; 1198 + return false;
1099 } 1199 }
1100 1200
1101 if (hls->arg0() == "off") { 1201 if (hls->arg0() == "off") {
@@ -1105,40 +1205,58 @@ bool SrsConfig::get_hls_enabled(std::string vhost) @@ -1105,40 +1205,58 @@ bool SrsConfig::get_hls_enabled(std::string vhost)
1105 return true; 1205 return true;
1106 } 1206 }
1107 1207
1108 -SrsConfDirective* SrsConfig::get_hls_path(std::string vhost) 1208 +string SrsConfig::get_hls_path(string vhost)
1109 { 1209 {
1110 - SrsConfDirective* conf = get_vhost(vhost);  
1111 -  
1112 - if (!conf) {  
1113 - return NULL; 1210 + SrsConfDirective* hls = get_hls(vhost);
  1211 +
  1212 + if (!hls) {
  1213 + return SRS_CONF_DEFAULT_HLS_PATH;
1114 } 1214 }
1115 1215
1116 - return conf->get("hls_path"); 1216 + SrsConfDirective* conf = hls->get("hls_path");
  1217 +
  1218 + if (!conf) {
  1219 + return SRS_CONF_DEFAULT_HLS_PATH;
  1220 + }
  1221 +
  1222 + return conf->arg0();
1117 } 1223 }
1118 1224
1119 -SrsConfDirective* SrsConfig::get_hls_fragment(std::string vhost) 1225 +double SrsConfig::get_hls_fragment(string vhost)
1120 { 1226 {
1121 - SrsConfDirective* conf = get_vhost(vhost);  
1122 -  
1123 - if (!conf) {  
1124 - return NULL; 1227 + SrsConfDirective* hls = get_hls(vhost);
  1228 +
  1229 + if (!hls) {
  1230 + return SRS_CONF_DEFAULT_HLS_FRAGMENT;
1125 } 1231 }
1126 1232
1127 - return conf->get("hls_fragment"); 1233 + SrsConfDirective* conf = hls->get("hls_fragment");
  1234 +
  1235 + if (!conf) {
  1236 + return SRS_CONF_DEFAULT_HLS_FRAGMENT;
  1237 + }
  1238 +
  1239 + return ::atof(conf->arg0().c_str());
1128 } 1240 }
1129 1241
1130 -SrsConfDirective* SrsConfig::get_hls_window(std::string vhost) 1242 +double SrsConfig::get_hls_window(string vhost)
1131 { 1243 {
1132 - SrsConfDirective* conf = get_vhost(vhost);  
1133 -  
1134 - if (!conf) {  
1135 - return NULL; 1244 + SrsConfDirective* hls = get_hls(vhost);
  1245 +
  1246 + if (!hls) {
  1247 + return SRS_CONF_DEFAULT_HLS_WINDOW;
1136 } 1248 }
1137 1249
1138 - return conf->get("hls_window"); 1250 + SrsConfDirective* conf = hls->get("hls_window");
  1251 +
  1252 + if (!conf) {
  1253 + return SRS_CONF_DEFAULT_HLS_WINDOW;
  1254 + }
  1255 +
  1256 + return ::atof(conf->arg0().c_str());
1139 } 1257 }
1140 1258
1141 -SrsConfDirective* SrsConfig::get_refer(std::string vhost) 1259 +SrsConfDirective* SrsConfig::get_refer(string vhost)
1142 { 1260 {
1143 SrsConfDirective* conf = get_vhost(vhost); 1261 SrsConfDirective* conf = get_vhost(vhost);
1144 1262
@@ -1149,7 +1267,7 @@ SrsConfDirective* SrsConfig::get_refer(std::string vhost) @@ -1149,7 +1267,7 @@ SrsConfDirective* SrsConfig::get_refer(std::string vhost)
1149 return conf->get("refer"); 1267 return conf->get("refer");
1150 } 1268 }
1151 1269
1152 -SrsConfDirective* SrsConfig::get_refer_play(std::string vhost) 1270 +SrsConfDirective* SrsConfig::get_refer_play(string vhost)
1153 { 1271 {
1154 SrsConfDirective* conf = get_vhost(vhost); 1272 SrsConfDirective* conf = get_vhost(vhost);
1155 1273
@@ -1160,7 +1278,7 @@ SrsConfDirective* SrsConfig::get_refer_play(std::string vhost) @@ -1160,7 +1278,7 @@ SrsConfDirective* SrsConfig::get_refer_play(std::string vhost)
1160 return conf->get("refer_play"); 1278 return conf->get("refer_play");
1161 } 1279 }
1162 1280
1163 -SrsConfDirective* SrsConfig::get_refer_publish(std::string vhost) 1281 +SrsConfDirective* SrsConfig::get_refer_publish(string vhost)
1164 { 1282 {
1165 SrsConfDirective* conf = get_vhost(vhost); 1283 SrsConfDirective* conf = get_vhost(vhost);
1166 1284
@@ -1176,156 +1294,89 @@ SrsConfDirective* SrsConfig::get_listen() @@ -1176,156 +1294,89 @@ SrsConfDirective* SrsConfig::get_listen()
1176 return root->get("listen"); 1294 return root->get("listen");
1177 } 1295 }
1178 1296
1179 -SrsConfDirective* SrsConfig::get_chunk_size() 1297 +int SrsConfig::get_chunk_size()
1180 { 1298 {
1181 - return root->get("chunk_size"); 1299 + SrsConfDirective* conf = root->get("chunk_size");
  1300 + if (!conf) {
  1301 + return SRS_CONF_DEFAULT_CHUNK_SIZE;
  1302 + }
  1303 +
  1304 + return ::atoi(conf->arg0().c_str());
1182 } 1305 }
1183 1306
1184 -SrsConfDirective* SrsConfig::get_pithy_print_publish() 1307 +int SrsConfig::get_pithy_print_publish()
1185 { 1308 {
1186 SrsConfDirective* pithy = root->get("pithy_print"); 1309 SrsConfDirective* pithy = root->get("pithy_print");
1187 if (!pithy) { 1310 if (!pithy) {
1188 - return NULL; 1311 + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
1189 } 1312 }
1190 1313
1191 - return pithy->get("publish");  
1192 -}  
1193 -  
1194 -SrsConfDirective* SrsConfig::get_pithy_print_forwarder()  
1195 -{  
1196 - SrsConfDirective* pithy = root->get("pithy_print"); 1314 + pithy = pithy->get("publish");
1197 if (!pithy) { 1315 if (!pithy) {
1198 - return NULL; 1316 + return SRS_STAGE_PUBLISH_USER_INTERVAL_MS;
1199 } 1317 }
1200 1318
1201 - return pithy->get("forwarder"); 1319 + return ::atoi(pithy->arg0().c_str());
1202 } 1320 }
1203 1321
1204 -SrsConfDirective* SrsConfig::get_pithy_print_hls() 1322 +int SrsConfig::get_pithy_print_forwarder()
1205 { 1323 {
1206 SrsConfDirective* pithy = root->get("pithy_print"); 1324 SrsConfDirective* pithy = root->get("pithy_print");
1207 if (!pithy) { 1325 if (!pithy) {
1208 - return NULL; 1326 + return SRS_STAGE_FORWARDER_INTERVAL_MS;
1209 } 1327 }
1210 1328
1211 - return pithy->get("hls");  
1212 -}  
1213 -  
1214 -SrsConfDirective* SrsConfig::get_pithy_print_encoder()  
1215 -{  
1216 - SrsConfDirective* pithy = root->get("encoder"); 1329 + pithy = pithy->get("forwarder");
1217 if (!pithy) { 1330 if (!pithy) {
1218 - return NULL; 1331 + return SRS_STAGE_FORWARDER_INTERVAL_MS;
1219 } 1332 }
1220 1333
1221 - return pithy->get("forwarder"); 1334 + return ::atoi(pithy->arg0().c_str());
1222 } 1335 }
1223 1336
1224 -SrsConfDirective* SrsConfig::get_pithy_print_play() 1337 +int SrsConfig::get_pithy_print_hls()
1225 { 1338 {
1226 SrsConfDirective* pithy = root->get("pithy_print"); 1339 SrsConfDirective* pithy = root->get("pithy_print");
1227 if (!pithy) { 1340 if (!pithy) {
1228 - return NULL; 1341 + return SRS_STAGE_HLS_INTERVAL_MS;
  1342 + }
  1343 +
  1344 + pithy = pithy->get("hls");
  1345 + if (!pithy) {
  1346 + return SRS_STAGE_HLS_INTERVAL_MS;
1229 } 1347 }
1230 1348
1231 - return pithy->get("play"); 1349 + return ::atoi(pithy->arg0().c_str());
1232 } 1350 }
1233 1351
1234 -int SrsConfig::parse_file(const char* filename) 1352 +int SrsConfig::get_pithy_print_encoder()
1235 { 1353 {
1236 - int ret = ERROR_SUCCESS;  
1237 -  
1238 - config_file = filename;  
1239 -  
1240 - if (config_file.empty()) {  
1241 - return ERROR_SYSTEM_CONFIG_INVALID;  
1242 - }  
1243 -  
1244 - if ((ret = root->parse(config_file.c_str())) != ERROR_SUCCESS) {  
1245 - return ret; 1354 + SrsConfDirective* pithy = root->get("encoder");
  1355 + if (!pithy) {
  1356 + return SRS_STAGE_ENCODER_INTERVAL_MS;
1246 } 1357 }
1247 1358
1248 - SrsConfDirective* conf = NULL;  
1249 - if ((conf = get_listen()) == NULL || conf->args.size() == 0) {  
1250 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1251 - srs_error("line %d: conf error, "  
1252 - "directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);  
1253 - return ret; 1359 + pithy = pithy->get("forwarder");
  1360 + if (!pithy) {
  1361 + return SRS_STAGE_ENCODER_INTERVAL_MS;
1254 } 1362 }
1255 1363
1256 - // TODO: check the hls.  
1257 - // TODO: check other config.  
1258 - // TODO: check hls.  
1259 - // TODO: check ssl.  
1260 - // TODO: check ffmpeg.  
1261 - // TODO: check http.  
1262 -  
1263 - return ret; 1364 + return ::atoi(pithy->arg0().c_str());
1264 } 1365 }
1265 1366
1266 -int SrsConfig::parse_argv(int& i, char** argv) 1367 +int SrsConfig::get_pithy_print_play()
1267 { 1368 {
1268 - int ret = ERROR_SUCCESS;  
1269 -  
1270 - char* p = argv[i];  
1271 -  
1272 - if (*p++ != '-') {  
1273 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1274 - srs_error("invalid options(index=%d, value=%s), "  
1275 - "must starts with -, see help: %s -h, ret=%d", i, argv[i], argv[0], ret);  
1276 - return ret; 1369 + SrsConfDirective* pithy = root->get("pithy_print");
  1370 + if (!pithy) {
  1371 + return SRS_STAGE_PLAY_USER_INTERVAL_MS;
1277 } 1372 }
1278 1373
1279 - while (*p) {  
1280 - switch (*p++) {  
1281 - case '?':  
1282 - case 'h':  
1283 - show_help = true;  
1284 - break;  
1285 - case 'v':  
1286 - case 'V':  
1287 - show_version = true;  
1288 - break;  
1289 - case 'c':  
1290 - if (*p) {  
1291 - config_file = p;  
1292 - return ret;  
1293 - }  
1294 - if (argv[++i]) {  
1295 - config_file = argv[i];  
1296 - return ret;  
1297 - }  
1298 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1299 - srs_error("option \"-c\" requires parameter, ret=%d", ret);  
1300 - return ret;  
1301 - default:  
1302 - ret = ERROR_SYSTEM_CONFIG_INVALID;  
1303 - srs_error("invalid option: \"%c\", see help: %s -h, ret=%d", *(p - 1), argv[0], ret);  
1304 - return ret;  
1305 - } 1374 + pithy = pithy->get("play");
  1375 + if (!pithy) {
  1376 + return SRS_STAGE_PLAY_USER_INTERVAL_MS;
1306 } 1377 }
1307 1378
1308 - return ret;  
1309 -}  
1310 -  
1311 -void SrsConfig::print_help(char** argv)  
1312 -{  
1313 - printf(RTMP_SIG_SRS_NAME" "RTMP_SIG_SRS_VERSION  
1314 - " Copyright (c) 2013 winlin\n"  
1315 - "Contributors: "RTMP_SIG_SRS_CONTRIBUTOR"\n"  
1316 - "Build: "SRS_BUILD_DATE" Configuration: "SRS_CONFIGURE"\n"  
1317 - "Usage: %s [-h?vV] [-c <filename>]\n"  
1318 - "\n"  
1319 - "Options:\n"  
1320 - " -?-h : show help\n"  
1321 - " -v-V : show version and exit\n"  
1322 - " -c filename : set configuration file\n"  
1323 - "\n"  
1324 - RTMP_SIG_SRS_WEB"\n"  
1325 - RTMP_SIG_SRS_URL"\n"  
1326 - "Email: "RTMP_SIG_SRS_EMAIL"\n"  
1327 - "\n",  
1328 - argv[0]); 1379 + return ::atoi(pithy->arg0().c_str());
1329 } 1380 }
1330 1381
1331 bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b) 1382 bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b)
@@ -49,6 +49,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -49,6 +49,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 // in ms, for HLS aac flush the audio 49 // in ms, for HLS aac flush the audio
50 #define SRS_CONF_DEFAULT_AAC_DELAY 300 50 #define SRS_CONF_DEFAULT_AAC_DELAY 300
51 51
  52 +#define SRS_CONF_DEFAULT_CHUNK_SIZE 4096
  53 +
  54 +#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300
  55 +#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100
  56 +#define SRS_STAGE_FORWARDER_INTERVAL_MS 2000
  57 +#define SRS_STAGE_ENCODER_INTERVAL_MS 2000
  58 +#define SRS_STAGE_HLS_INTERVAL_MS 2000
  59 +
52 class SrsFileBuffer; 60 class SrsFileBuffer;
53 61
54 class SrsConfDirective 62 class SrsConfDirective
@@ -98,59 +106,61 @@ public: @@ -98,59 +106,61 @@ public:
98 virtual void unsubscribe(SrsReloadHandler* handler); 106 virtual void unsubscribe(SrsReloadHandler* handler);
99 public: 107 public:
100 virtual int parse_options(int argc, char** argv); 108 virtual int parse_options(int argc, char** argv);
101 -public:  
102 - virtual SrsConfDirective* get_vhost(std::string vhost);  
103 - virtual bool get_vhost_enabled(std::string vhost);  
104 - virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);  
105 - virtual SrsConfDirective* get_vhost_on_close(std::string vhost);  
106 - virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);  
107 - virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);  
108 - virtual SrsConfDirective* get_vhost_on_play(std::string vhost);  
109 - virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);  
110 - virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);  
111 - virtual bool get_transcode_enabled(SrsConfDirective* transcode);  
112 - virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);  
113 - virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines);  
114 - virtual bool get_engine_enabled(SrsConfDirective* engine);  
115 - virtual std::string get_engine_vcodec(SrsConfDirective* engine);  
116 - virtual int get_engine_vbitrate(SrsConfDirective* engine);  
117 - virtual double get_engine_vfps(SrsConfDirective* engine);  
118 - virtual int get_engine_vwidth(SrsConfDirective* engine);  
119 - virtual int get_engine_vheight(SrsConfDirective* engine);  
120 - virtual int get_engine_vthreads(SrsConfDirective* engine);  
121 - virtual std::string get_engine_vprofile(SrsConfDirective* engine);  
122 - virtual std::string get_engine_vpreset(SrsConfDirective* engine);  
123 - virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);  
124 - virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);  
125 - virtual std::string get_engine_acodec(SrsConfDirective* engine);  
126 - virtual int get_engine_abitrate(SrsConfDirective* engine);  
127 - virtual int get_engine_asample_rate(SrsConfDirective* engine);  
128 - virtual int get_engine_achannels(SrsConfDirective* engine);  
129 - virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);  
130 - virtual std::string get_engine_output(SrsConfDirective* engine);  
131 - virtual std::string get_log_dir();  
132 - virtual int get_max_connections();  
133 - virtual SrsConfDirective* get_gop_cache(std::string vhost);  
134 - virtual SrsConfDirective* get_forward(std::string vhost);  
135 - virtual SrsConfDirective* get_hls(std::string vhost);  
136 - virtual bool get_hls_enabled(std::string vhost);  
137 - virtual SrsConfDirective* get_hls_path(std::string vhost);  
138 - virtual SrsConfDirective* get_hls_fragment(std::string vhost);  
139 - virtual SrsConfDirective* get_hls_window(std::string vhost);  
140 - virtual SrsConfDirective* get_refer(std::string vhost);  
141 - virtual SrsConfDirective* get_refer_play(std::string vhost);  
142 - virtual SrsConfDirective* get_refer_publish(std::string vhost);  
143 - virtual SrsConfDirective* get_listen();  
144 - virtual SrsConfDirective* get_chunk_size();  
145 - virtual SrsConfDirective* get_pithy_print_publish();  
146 - virtual SrsConfDirective* get_pithy_print_forwarder();  
147 - virtual SrsConfDirective* get_pithy_print_encoder();  
148 - virtual SrsConfDirective* get_pithy_print_hls();  
149 - virtual SrsConfDirective* get_pithy_print_play();  
150 private: 109 private:
151 virtual int parse_file(const char* filename); 110 virtual int parse_file(const char* filename);
152 virtual int parse_argv(int& i, char** argv); 111 virtual int parse_argv(int& i, char** argv);
153 virtual void print_help(char** argv); 112 virtual void print_help(char** argv);
  113 +public:
  114 + virtual SrsConfDirective* get_vhost(std::string vhost);
  115 + virtual bool get_vhost_enabled(std::string vhost);
  116 + virtual SrsConfDirective* get_vhost_on_connect(std::string vhost);
  117 + virtual SrsConfDirective* get_vhost_on_close(std::string vhost);
  118 + virtual SrsConfDirective* get_vhost_on_publish(std::string vhost);
  119 + virtual SrsConfDirective* get_vhost_on_unpublish(std::string vhost);
  120 + virtual SrsConfDirective* get_vhost_on_play(std::string vhost);
  121 + virtual SrsConfDirective* get_vhost_on_stop(std::string vhost);
  122 + virtual SrsConfDirective* get_transcode(std::string vhost, std::string scope);
  123 + virtual bool get_transcode_enabled(SrsConfDirective* transcode);
  124 + virtual std::string get_transcode_ffmpeg(SrsConfDirective* transcode);
  125 + virtual void get_transcode_engines(SrsConfDirective* transcode, std::vector<SrsConfDirective*>& engines);
  126 + virtual bool get_engine_enabled(SrsConfDirective* engine);
  127 + virtual std::string get_engine_vcodec(SrsConfDirective* engine);
  128 + virtual int get_engine_vbitrate(SrsConfDirective* engine);
  129 + virtual double get_engine_vfps(SrsConfDirective* engine);
  130 + virtual int get_engine_vwidth(SrsConfDirective* engine);
  131 + virtual int get_engine_vheight(SrsConfDirective* engine);
  132 + virtual int get_engine_vthreads(SrsConfDirective* engine);
  133 + virtual std::string get_engine_vprofile(SrsConfDirective* engine);
  134 + virtual std::string get_engine_vpreset(SrsConfDirective* engine);
  135 + virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);
  136 + virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);
  137 + virtual std::string get_engine_acodec(SrsConfDirective* engine);
  138 + virtual int get_engine_abitrate(SrsConfDirective* engine);
  139 + virtual int get_engine_asample_rate(SrsConfDirective* engine);
  140 + virtual int get_engine_achannels(SrsConfDirective* engine);
  141 + virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
  142 + virtual std::string get_engine_output(SrsConfDirective* engine);
  143 + virtual std::string get_log_dir();
  144 + virtual int get_max_connections();
  145 + virtual bool get_gop_cache(std::string vhost);
  146 + virtual SrsConfDirective* get_forward(std::string vhost);
  147 +private:
  148 + virtual SrsConfDirective* get_hls(std::string vhost);
  149 +public:
  150 + virtual bool get_hls_enabled(std::string vhost);
  151 + virtual std::string get_hls_path(std::string vhost);
  152 + virtual double get_hls_fragment(std::string vhost);
  153 + virtual double get_hls_window(std::string vhost);
  154 + virtual SrsConfDirective* get_refer(std::string vhost);
  155 + virtual SrsConfDirective* get_refer_play(std::string vhost);
  156 + virtual SrsConfDirective* get_refer_publish(std::string vhost);
  157 + virtual SrsConfDirective* get_listen();
  158 + virtual int get_chunk_size();
  159 + virtual int get_pithy_print_publish();
  160 + virtual int get_pithy_print_forwarder();
  161 + virtual int get_pithy_print_encoder();
  162 + virtual int get_pithy_print_hls();
  163 + virtual int get_pithy_print_play();
154 }; 164 };
155 165
156 /** 166 /**
@@ -1157,29 +1157,11 @@ int SrsHls::on_publish(SrsRequest* req) @@ -1157,29 +1157,11 @@ int SrsHls::on_publish(SrsRequest* req)
1157 hls_enabled = true; 1157 hls_enabled = true;
1158 1158
1159 // TODO: subscribe the reload event. 1159 // TODO: subscribe the reload event.
1160 - int hls_fragment = 0;  
1161 - int hls_window = 0;  
1162 -  
1163 - SrsConfDirective* conf = NULL;  
1164 - if ((conf = config->get_hls_fragment(vhost)) != NULL && !conf->arg0().empty()) {  
1165 - hls_fragment = ::atoi(conf->arg0().c_str());  
1166 - }  
1167 - if (hls_fragment <= 0) {  
1168 - hls_fragment = SRS_CONF_DEFAULT_HLS_FRAGMENT;  
1169 - }  
1170 -  
1171 - if ((conf = config->get_hls_window(vhost)) != NULL && !conf->arg0().empty()) {  
1172 - hls_window = ::atoi(conf->arg0().c_str());  
1173 - }  
1174 - if (hls_window <= 0) {  
1175 - hls_window = SRS_CONF_DEFAULT_HLS_WINDOW;  
1176 - } 1160 + int hls_fragment = config->get_hls_fragment(vhost);
  1161 + int hls_window = config->get_hls_window(vhost);
1177 1162
1178 // get the hls path config 1163 // get the hls path config
1179 - std::string hls_path = SRS_CONF_DEFAULT_HLS_PATH;  
1180 - if ((conf = config->get_hls_path(vhost)) != NULL) {  
1181 - hls_path = conf->arg0();  
1182 - } 1164 + std::string hls_path = config->get_hls_path(vhost);
1183 1165
1184 // open muxer 1166 // open muxer
1185 if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) { 1167 if ((ret = muxer->update_config(app, stream, hls_path, hls_fragment, hls_window)) != ERROR_SUCCESS) {
@@ -32,11 +32,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -32,11 +32,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include <srs_core_error.hpp> 32 #include <srs_core_error.hpp>
33 33
34 #define SRS_STAGE_DEFAULT_INTERVAL_MS 1200 34 #define SRS_STAGE_DEFAULT_INTERVAL_MS 1200
35 -#define SRS_STAGE_PLAY_USER_INTERVAL_MS 1300  
36 -#define SRS_STAGE_PUBLISH_USER_INTERVAL_MS 1100  
37 -#define SRS_STAGE_FORWARDER_INTERVAL_MS 2000  
38 -#define SRS_STAGE_ENCODER_INTERVAL_MS 2000  
39 -#define SRS_STAGE_HLS_INTERVAL_MS 2000  
40 35
41 struct SrsStageInfo : public SrsReloadHandler 36 struct SrsStageInfo : public SrsReloadHandler
42 { 37 {
@@ -61,43 +56,23 @@ struct SrsStageInfo : public SrsReloadHandler @@ -61,43 +56,23 @@ struct SrsStageInfo : public SrsReloadHandler
61 { 56 {
62 switch (stage_id) { 57 switch (stage_id) {
63 case SRS_STAGE_PLAY_USER: { 58 case SRS_STAGE_PLAY_USER: {
64 - pithy_print_time_ms = SRS_STAGE_PLAY_USER_INTERVAL_MS;  
65 - SrsConfDirective* conf = config->get_pithy_print_play();  
66 - if (conf && !conf->arg0().empty()) {  
67 - pithy_print_time_ms = ::atoi(conf->arg0().c_str());  
68 - } 59 + pithy_print_time_ms = config->get_pithy_print_play();
69 break; 60 break;
70 } 61 }
71 case SRS_STAGE_PUBLISH_USER: { 62 case SRS_STAGE_PUBLISH_USER: {
72 - pithy_print_time_ms = SRS_STAGE_PUBLISH_USER_INTERVAL_MS;  
73 - SrsConfDirective* conf = config->get_pithy_print_publish();  
74 - if (conf && !conf->arg0().empty()) {  
75 - pithy_print_time_ms = ::atoi(conf->arg0().c_str());  
76 - } 63 + pithy_print_time_ms = config->get_pithy_print_publish();
77 break; 64 break;
78 } 65 }
79 case SRS_STAGE_FORWARDER: { 66 case SRS_STAGE_FORWARDER: {
80 - pithy_print_time_ms = SRS_STAGE_FORWARDER_INTERVAL_MS;  
81 - SrsConfDirective* conf = config->get_pithy_print_forwarder();  
82 - if (conf && !conf->arg0().empty()) {  
83 - pithy_print_time_ms = ::atoi(conf->arg0().c_str());  
84 - } 67 + pithy_print_time_ms = config->get_pithy_print_forwarder();
85 break; 68 break;
86 } 69 }
87 case SRS_STAGE_ENCODER: { 70 case SRS_STAGE_ENCODER: {
88 - pithy_print_time_ms = SRS_STAGE_ENCODER_INTERVAL_MS;  
89 - SrsConfDirective* conf = config->get_pithy_print_encoder();  
90 - if (conf && !conf->arg0().empty()) {  
91 - pithy_print_time_ms = ::atoi(conf->arg0().c_str());  
92 - } 71 + pithy_print_time_ms = config->get_pithy_print_encoder();
93 break; 72 break;
94 } 73 }
95 case SRS_STAGE_HLS: { 74 case SRS_STAGE_HLS: {
96 - pithy_print_time_ms = SRS_STAGE_HLS_INTERVAL_MS;  
97 - SrsConfDirective* conf = config->get_pithy_print_hls();  
98 - if (conf && !conf->arg0().empty()) {  
99 - pithy_print_time_ms = ::atoi(conf->arg0().c_str());  
100 - } 75 + pithy_print_time_ms = config->get_pithy_print_hls();
101 break; 76 break;
102 } 77 }
103 default: { 78 default: {