From 394e070b2ef2fbcc8eeba817bbdcc036ba995582 Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 28 May 2015 14:59:12 +0800 Subject: [PATCH] support dolphin --- trunk/src/app/srs_app_config.cpp | 46 ++++++++++++++++++++++++++++++-- trunk/src/app/srs_app_config.hpp | 14 ++++++++++ trunk/src/app/srs_app_server.cpp | 5 ++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 356b85bab..23e8c92a2 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -364,6 +364,8 @@ int SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector& args, SrsConfig::SrsConfig() { + dolphin = false; + show_help = false; show_version = false; test_conf = false; @@ -378,6 +380,25 @@ SrsConfig::~SrsConfig() srs_freep(root); } +bool SrsConfig::is_dolphin() +{ + return dolphin; +} + +void SrsConfig::set_config_directive(SrsConfDirective* parent, string dir, string value) +{ + SrsConfDirective* d = parent->get(dir); + + if (!d) { + d = new SrsConfDirective(); + d->name = dir; + parent->directives.push_back(d); + } + + d->args.clear(); + d->args.push_back(value); +} + void SrsConfig::subscribe(ISrsReloadHandler* handler) { std::vector::iterator it; @@ -1260,6 +1281,19 @@ int SrsConfig::parse_argv(int& i, char** argv) show_help = false; test_conf = true; break; + case 'p': + dolphin = true; + if (*p) { + dolphin_port = p; + continue; + } + if (argv[++i]) { + dolphin_port = argv[i]; + continue; + } + ret = ERROR_SYSTEM_CONFIG_INVALID; + srs_error("option \"-p\" requires params, ret=%d", ret); + return ret; case 'v': case 'V': show_help = false; @@ -1269,11 +1303,11 @@ int SrsConfig::parse_argv(int& i, char** argv) show_help = false; if (*p) { config_file = p; - return ret; + continue; } if (argv[++i]) { config_file = argv[i]; - return ret; + continue; } ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("option \"-c\" requires parameter, ret=%d", ret); @@ -1844,6 +1878,14 @@ int SrsConfig::parse_buffer(SrsConfigBuffer* buffer) if ((ret = root->parse(buffer)) != ERROR_SUCCESS) { return ret; } + + // mock by dolphin mode. + // for the dolphin will start srs with specified params. + if (dolphin) { + set_config_directive(root, "listen", dolphin_port); + set_config_directive(root, "daemon", "off"); + set_config_directive(root, "srs_log_tank", "console"); + } return ret; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 6e2a1b353..fd822c68f 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -266,6 +266,12 @@ class SrsConfig { // user command private: + /** + * whether srs is run in dolphin mode. + * @see https://github.com/simple-rtmp-server/srs-dolphin + */ + bool dolphin; + std::string dolphin_port; /** * whether show help and exit. */ @@ -309,6 +315,14 @@ private: public: SrsConfig(); virtual ~SrsConfig(); +// dolphin +public: + /** + * whether srs is in dolphin mode. + */ + virtual bool is_dolphin(); +private: + virtual void set_config_directive(SrsConfDirective* parent, std::string dir, std::string value); // reload public: /** diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index a954a8a1f..7c092949a 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -639,6 +639,11 @@ int SrsServer::acquire_pid_file() { int ret = ERROR_SUCCESS; + // when srs in dolphin mode, no need the pid file. + if (_srs_config->is_dolphin()) { + return ret; + } + std::string pid_file = _srs_config->get_pid_file(); // -rw-r--r--