2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-12-30 02:10:35 +00:00
|
|
|
* Copyright (c) 2013-2020 Winlin
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
#include <srs_app_config.hpp>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
// file operations.
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <srs_kernel_error.hpp>
|
|
|
|
#include <srs_kernel_log.hpp>
|
2015-09-22 01:11:07 +00:00
|
|
|
#include <srs_protocol_utility.hpp>
|
2014-11-11 09:19:56 +00:00
|
|
|
#include <srs_core_autofree.hpp>
|
|
|
|
#include <srs_app_source.hpp>
|
|
|
|
#include <srs_kernel_file.hpp>
|
|
|
|
#include <srs_app_utility.hpp>
|
2014-12-04 13:35:13 +00:00
|
|
|
#include <srs_core_performance.hpp>
|
2015-09-22 01:05:21 +00:00
|
|
|
#include <srs_protocol_amf0.hpp>
|
2015-08-27 15:55:59 +00:00
|
|
|
#include <srs_app_statistic.hpp>
|
2015-09-17 05:36:02 +00:00
|
|
|
#include <srs_protocol_json.hpp>
|
|
|
|
#include <srs_app_http_hooks.hpp>
|
|
|
|
#include <srs_kernel_utility.hpp>
|
|
|
|
#include <srs_rtmp_stack.hpp>
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
using namespace _srs_internal;
|
|
|
|
|
2016-12-08 09:26:04 +00:00
|
|
|
// @global the version to identify the core.
|
2017-05-06 06:05:22 +00:00
|
|
|
const char* _srs_version = "XCORE-" RTMP_SIG_SRS_SERVER;
|
2016-01-05 08:49:27 +00:00
|
|
|
|
2015-11-11 02:37:50 +00:00
|
|
|
#define SRS_WIKI_URL_LOG "https://github.com/ossrs/srs/wiki/v1_CN_SrsLog"
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
// when user config an invalid value, macros to perfer true or false.
|
|
|
|
#define SRS_CONF_PERFER_FALSE(conf_arg) conf_arg == "on"
|
|
|
|
#define SRS_CONF_PERFER_TRUE(conf_arg) conf_arg != "off"
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
// default config file.
|
2015-07-06 03:11:59 +00:00
|
|
|
#define SRS_CONF_DEFAULT_COFNIG_FILE "conf/srs.conf"
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// '\n'
|
2015-07-06 03:11:59 +00:00
|
|
|
#define SRS_LF (char)SRS_CONSTS_LF
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
// '\r'
|
2015-07-06 03:11:59 +00:00
|
|
|
#define SRS_CR (char)SRS_CONSTS_CR
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-31 04:06:22 +00:00
|
|
|
/**
|
|
|
|
* dumps the ingest/transcode-engine in @param dir to amf0 object @param engine.
|
|
|
|
* @param dir the transcode or ingest config directive.
|
|
|
|
* @param engine the amf0 object to dumps to.
|
|
|
|
*/
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine);
|
2015-08-30 15:08:27 +00:00
|
|
|
|
2015-08-31 04:06:22 +00:00
|
|
|
/**
|
|
|
|
* whether the ch is common space.
|
|
|
|
*/
|
2014-11-11 09:19:56 +00:00
|
|
|
bool is_common_space(char ch)
|
|
|
|
{
|
2015-03-21 02:25:03 +00:00
|
|
|
return (ch == ' ' || ch == '\t' || ch == SRS_CR || ch == SRS_LF);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
namespace _srs_internal
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfigBuffer::SrsConfigBuffer()
|
|
|
|
{
|
|
|
|
line = 1;
|
|
|
|
|
|
|
|
pos = last = start = NULL;
|
|
|
|
end = start;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfigBuffer::~SrsConfigBuffer()
|
|
|
|
{
|
2015-11-02 03:05:39 +00:00
|
|
|
srs_freepa(start);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2020-01-01 05:41:19 +00:00
|
|
|
|
|
|
|
// LCOV_EXCL_START
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfigBuffer::fullfill(const char* filename)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsFileReader reader;
|
|
|
|
|
|
|
|
// open file reader.
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = reader.open(filename)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "open file=%s", filename);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// read all.
|
|
|
|
int filesize = (int)reader.filesize();
|
|
|
|
|
|
|
|
// create buffer
|
2015-11-02 03:05:39 +00:00
|
|
|
srs_freepa(start);
|
2015-09-17 05:36:02 +00:00
|
|
|
pos = last = start = new char[filesize];
|
|
|
|
end = start + filesize;
|
|
|
|
|
|
|
|
// read total content from file.
|
|
|
|
ssize_t nread = 0;
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = reader.read(start, filesize, &nread)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "read %d only %d bytes", filesize, nread);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2020-01-01 05:41:19 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
bool SrsConfigBuffer::empty()
|
|
|
|
{
|
|
|
|
return pos >= end;
|
|
|
|
}
|
|
|
|
};
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_directive_equals_self(SrsConfDirective* a, SrsConfDirective* b)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
// both NULL, equal.
|
|
|
|
if (!a && !b) {
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
if (!a || !b) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->name != b->name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->args.size() != b->args.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)a->args.size(); i++) {
|
|
|
|
if (a->args.at(i) != b->args.at(i)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->directives.size() != b->directives.size()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
// both NULL, equal.
|
|
|
|
if (!a && !b) {
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!srs_directive_equals_self(a, b)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)a->directives.size(); i++) {
|
|
|
|
SrsConfDirective* a0 = a->at(i);
|
|
|
|
SrsConfDirective* b0 = b->at(i);
|
|
|
|
|
|
|
|
if (!srs_directive_equals(a0, b0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_directive_equals(SrsConfDirective* a, SrsConfDirective* b, string except)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
// both NULL, equal.
|
|
|
|
if (!a && !b) {
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!srs_directive_equals_self(a, b)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)a->directives.size(); i++) {
|
|
|
|
SrsConfDirective* a0 = a->at(i);
|
|
|
|
SrsConfDirective* b0 = b->at(i);
|
|
|
|
|
|
|
|
// donot compare the except child directive.
|
|
|
|
if (a0->name == except) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!srs_directive_equals(a0, b0, except)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 06:12:36 +00:00
|
|
|
void set_config_directive(SrsConfDirective* parent, string dir, string value)
|
|
|
|
{
|
|
|
|
SrsConfDirective* d = parent->get_or_create(dir);
|
|
|
|
d->name = dir;
|
|
|
|
d->args.clear();
|
|
|
|
d->args.push_back(value);
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_hls_is_on_error_ignore(string strategy)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return strategy == "ignore";
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_hls_is_on_error_continue(string strategy)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return strategy == "continue";
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_ingest_is_file(string type)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return type == "file";
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_ingest_is_stream(string type)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return type == "stream";
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_dvr_is_plan_segment(string plan)
|
2015-08-29 10:40:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return plan == "segment";
|
2015-08-29 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_dvr_is_plan_session(string plan)
|
2015-08-29 10:40:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return plan == "session";
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_stream_caster_is_udp(string caster)
|
2015-09-15 04:15:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return caster == "mpegts_over_udp";
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_stream_caster_is_rtsp(string caster)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return caster == "rtsp";
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_stream_caster_is_flv(string caster)
|
2015-01-24 06:52:52 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return caster == "flv";
|
2015-01-24 06:52:52 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool srs_config_apply_filter(SrsConfDirective* dvr_apply, SrsRequest* req)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
|
|
|
|
|
|
|
if (!dvr_apply || dvr_apply->args.empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string>& args = dvr_apply->args;
|
|
|
|
if (args.size() == 1 && dvr_apply->arg0() == "all") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
string id = req->app + "/" + req->stream;
|
|
|
|
if (::find(args.begin(), args.end(), id) != args.end()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 14:17:15 +00:00
|
|
|
string srs_config_bool2switch(string sbool)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
|
|
|
return sbool == "true"? "on":"off";
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
|
2015-08-26 13:49:05 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-26 13:49:05 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* dir = root->directives.at(i);
|
|
|
|
|
|
|
|
// SRS2.0, rename global http_stream to http_server.
|
|
|
|
// SRS1:
|
|
|
|
// http_stream {}
|
|
|
|
// SRS2+:
|
|
|
|
// http_server {}
|
|
|
|
if (dir->name == "http_stream") {
|
|
|
|
dir->name = "http_server";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dir->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for each directive of vhost.
|
|
|
|
std::vector<SrsConfDirective*>::iterator it;
|
|
|
|
for (it = dir->directives.begin(); it != dir->directives.end();) {
|
|
|
|
SrsConfDirective* conf = *it;
|
|
|
|
string n = conf->name;
|
|
|
|
|
|
|
|
// SRS2.0, rename vhost http to http_static
|
|
|
|
// SRS1:
|
|
|
|
// vhost { http {} }
|
|
|
|
// SRS2+:
|
|
|
|
// vhost { http_static {} }
|
|
|
|
if (n == "http") {
|
|
|
|
conf->name = "http_static";
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.http => vhost.http_static for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
++it;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-05 01:08:56 +00:00
|
|
|
// SRS3.0, ignore hstrs, always on.
|
|
|
|
// SRS1/2:
|
|
|
|
// vhost { http_remux { hstrs; } }
|
|
|
|
if (n == "http_remux") {
|
|
|
|
SrsConfDirective* hstrs = conf->get("hstrs");
|
|
|
|
conf->remove(hstrs);
|
|
|
|
srs_freep(hstrs);
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
// SRS3.0, change the refer style
|
|
|
|
// SRS1/2:
|
|
|
|
// vhost { refer; refer_play; refer_publish; }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { refer { enabled; all; play; publish; } }
|
|
|
|
if ((n == "refer" && conf->directives.empty()) || n == "refer_play" || n == "refer_publish") {
|
|
|
|
// remove the old one first, for name duplicated.
|
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* refer = dir->get_or_create("refer");
|
|
|
|
refer->get_or_create("enabled", "on");
|
|
|
|
if (n == "refer") {
|
|
|
|
SrsConfDirective* all = refer->get_or_create("all");
|
|
|
|
all->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.refer to vhost.refer.all for %s", dir->name.c_str());
|
2017-01-11 01:45:22 +00:00
|
|
|
} else if (n == "refer_play") {
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* play = refer->get_or_create("play");
|
|
|
|
play->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.refer_play to vhost.refer.play for %s", dir->name.c_str());
|
2017-01-11 01:45:22 +00:00
|
|
|
} else if (n == "refer_publish") {
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* publish = refer->get_or_create("publish");
|
|
|
|
publish->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.refer_publish to vhost.refer.publish for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove the old directive.
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the mr style
|
|
|
|
// SRS2:
|
|
|
|
// vhost { mr { enabled; latency; } }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { publish { mr; mr_latency; } }
|
|
|
|
if (n == "mr") {
|
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* publish = dir->get_or_create("publish");
|
|
|
|
|
|
|
|
SrsConfDirective* enabled = conf->get("enabled");
|
|
|
|
if (enabled) {
|
|
|
|
SrsConfDirective* mr = publish->get_or_create("mr");
|
|
|
|
mr->args = enabled->args;
|
2020-01-01 05:41:19 +00:00
|
|
|
srs_warn("transform: vhost.mr.enabled to vhost.publish.mr for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* latency = conf->get("latency");
|
|
|
|
if (latency) {
|
|
|
|
SrsConfDirective* mr_latency = publish->get_or_create("mr_latency");
|
|
|
|
mr_latency->args = latency->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.mr.latency to vhost.publish.mr_latency for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the publish_1stpkt_timeout
|
|
|
|
// SRS2:
|
|
|
|
// vhost { publish_1stpkt_timeout; }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { publish { firstpkt_timeout; } }
|
|
|
|
if (n == "publish_1stpkt_timeout") {
|
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* publish = dir->get_or_create("publish");
|
|
|
|
|
|
|
|
SrsConfDirective* firstpkt_timeout = publish->get_or_create("firstpkt_timeout");
|
|
|
|
firstpkt_timeout->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.publish_1stpkt_timeout to vhost.publish.firstpkt_timeout for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the publish_normal_timeout
|
|
|
|
// SRS2:
|
|
|
|
// vhost { publish_normal_timeout; }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { publish { normal_timeout; } }
|
|
|
|
if (n == "publish_normal_timeout") {
|
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* publish = dir->get_or_create("publish");
|
|
|
|
|
|
|
|
SrsConfDirective* normal_timeout = publish->get_or_create("normal_timeout");
|
|
|
|
normal_timeout->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.publish_normal_timeout to vhost.publish.normal_timeout for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the folowing like a shadow:
|
|
|
|
// time_jitter, mix_correct, atc, atc_auto, mw_latency, gop_cache, queue_length
|
|
|
|
// SRS1/2:
|
|
|
|
// vhost { shadow; }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { play { shadow; } }
|
|
|
|
if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto"
|
|
|
|
|| n == "mw_latency" || n == "gop_cache" || n == "queue_length" || n == "send_min_interval"
|
2017-06-11 06:03:19 +00:00
|
|
|
|| n == "reduce_sequence_header") {
|
2015-09-17 05:36:02 +00:00
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* play = dir->get_or_create("play");
|
|
|
|
SrsConfDirective* shadow = play->get_or_create(conf->name);
|
|
|
|
shadow->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.%s to vhost.play.%s of %s", n.c_str(), n.c_str(), dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the forward.
|
|
|
|
// SRS1/2:
|
2017-06-11 06:03:19 +00:00
|
|
|
// vhost { forward target; }
|
2015-09-17 05:36:02 +00:00
|
|
|
// SRS3+:
|
2017-06-11 06:03:19 +00:00
|
|
|
// vhost { forward { enabled; destination target; } }
|
|
|
|
if (n == "forward" && conf->directives.empty() && !conf->args.empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
conf->get_or_create("enabled")->set_arg0("on");
|
|
|
|
|
|
|
|
SrsConfDirective* destination = conf->get_or_create("destination");
|
|
|
|
destination->args = conf->args;
|
|
|
|
conf->args.clear();
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.forward to vhost.forward.destination for %s", dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
++it;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// SRS3.0, change the folowing like a shadow:
|
|
|
|
// mode, origin, token_traverse, vhost, debug_srs_upnode
|
|
|
|
// SRS1/2:
|
|
|
|
// vhost { shadow; }
|
|
|
|
// SRS3+:
|
|
|
|
// vhost { cluster { shadow; } }
|
|
|
|
if (n == "mode" || n == "origin" || n == "token_traverse" || n == "vhost" || n == "debug_srs_upnode") {
|
|
|
|
it = dir->directives.erase(it);
|
|
|
|
|
|
|
|
SrsConfDirective* cluster = dir->get_or_create("cluster");
|
|
|
|
SrsConfDirective* shadow = cluster->get_or_create(conf->name);
|
|
|
|
shadow->args = conf->args;
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("transform: vhost.%s to vhost.cluster.%s of %s", n.c_str(), n.c_str(), dir->name.c_str());
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
srs_freep(conf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 05:41:19 +00:00
|
|
|
// LCOV_EXCL_START
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t srs_config_dumps_engine(SrsConfDirective* dir, SrsJsonObject* engine)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = NULL;
|
|
|
|
|
|
|
|
engine->set("id", dir->dumps_arg0_to_str());
|
2015-09-19 04:27:31 +00:00
|
|
|
engine->set("enabled", SrsJsonAny::boolean(_srs_config->get_engine_enabled(dir)));
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
if ((conf = dir->get("iformat")) != NULL) {
|
|
|
|
engine->set("iformat", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vfilter")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* vfilter = SrsJsonAny::object();
|
2015-09-17 05:36:02 +00:00
|
|
|
engine->set("vfilter", vfilter);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = conf->directives.at(i);
|
|
|
|
vfilter->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vcodec")) != NULL) {
|
|
|
|
engine->set("vcodec", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vbitrate")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("vbitrate", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vfps")) != NULL) {
|
|
|
|
engine->set("vfps", conf->dumps_arg0_to_number());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vwidth")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("vwidth", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vheight")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("vheight", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vthreads")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("vthreads", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vprofile")) != NULL) {
|
|
|
|
engine->set("vprofile", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vpreset")) != NULL) {
|
|
|
|
engine->set("vpreset", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("vparams")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* vparams = SrsJsonAny::object();
|
2015-09-17 05:36:02 +00:00
|
|
|
engine->set("vparams", vparams);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = conf->directives.at(i);
|
|
|
|
vparams->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("acodec")) != NULL) {
|
|
|
|
engine->set("acodec", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("abitrate")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("abitrate", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("asample_rate")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("asample_rate", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("achannels")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
engine->set("achannels", conf->dumps_arg0_to_integer());
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("aparams")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* aparams = SrsJsonAny::object();
|
2015-09-17 05:36:02 +00:00
|
|
|
engine->set("aparams", aparams);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = conf->directives.at(i);
|
|
|
|
aparams->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("oformat")) != NULL) {
|
|
|
|
engine->set("oformat", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf = dir->get("output")) != NULL) {
|
|
|
|
engine->set("output", conf->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2020-01-01 05:41:19 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective::SrsConfDirective()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective::~SrsConfDirective()
|
|
|
|
{
|
|
|
|
std::vector<SrsConfDirective*>::iterator it;
|
|
|
|
for (it = directives.begin(); it != directives.end(); ++it) {
|
|
|
|
SrsConfDirective* directive = *it;
|
|
|
|
srs_freep(directive);
|
|
|
|
}
|
|
|
|
directives.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::copy()
|
2015-12-15 06:27:49 +00:00
|
|
|
{
|
|
|
|
return copy("");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::copy(string except)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* cp = new SrsConfDirective();
|
|
|
|
|
|
|
|
cp->conf_line = conf_line;
|
|
|
|
cp->name = name;
|
|
|
|
cp->args = args;
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)directives.size(); i++) {
|
|
|
|
SrsConfDirective* directive = directives.at(i);
|
2015-12-15 06:27:49 +00:00
|
|
|
if (!except.empty() && directive->name == except) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cp->directives.push_back(directive->copy(except));
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfDirective::arg0()
|
|
|
|
{
|
|
|
|
if (args.size() > 0) {
|
|
|
|
return args.at(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfDirective::arg1()
|
|
|
|
{
|
|
|
|
if (args.size() > 1) {
|
|
|
|
return args.at(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfDirective::arg2()
|
|
|
|
{
|
|
|
|
if (args.size() > 2) {
|
|
|
|
return args.at(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-09-17 06:03:25 +00:00
|
|
|
string SrsConfDirective::arg3()
|
|
|
|
{
|
|
|
|
if (args.size() > 3) {
|
|
|
|
return args.at(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfDirective::at(int index)
|
|
|
|
{
|
|
|
|
srs_assert(index < (int)directives.size());
|
|
|
|
return directives.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::get(string _name)
|
|
|
|
{
|
|
|
|
std::vector<SrsConfDirective*>::iterator it;
|
|
|
|
for (it = directives.begin(); it != directives.end(); ++it) {
|
|
|
|
SrsConfDirective* directive = *it;
|
|
|
|
if (directive->name == _name) {
|
|
|
|
return directive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::get(string _name, string _arg0)
|
|
|
|
{
|
|
|
|
std::vector<SrsConfDirective*>::iterator it;
|
|
|
|
for (it = directives.begin(); it != directives.end(); ++it) {
|
|
|
|
SrsConfDirective* directive = *it;
|
|
|
|
if (directive->name == _name && directive->arg0() == _arg0) {
|
|
|
|
return directive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::get_or_create(string n)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get(n);
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
conf = new SrsConfDirective();
|
|
|
|
conf->name = n;
|
|
|
|
directives.push_back(conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfDirective::get_or_create(string n, string a0)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get(n, a0);
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
conf = new SrsConfDirective();
|
|
|
|
conf->name = n;
|
2020-02-04 11:07:54 +00:00
|
|
|
conf->args.push_back(a0);
|
2015-09-17 05:36:02 +00:00
|
|
|
directives.push_back(conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
2020-02-04 11:07:54 +00:00
|
|
|
SrsConfDirective* SrsConfDirective::get_or_create(string n, string a0, string a1)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get(n, a0);
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
conf = new SrsConfDirective();
|
|
|
|
conf->name = n;
|
|
|
|
conf->args.push_back(a0);
|
|
|
|
conf->args.push_back(a1);
|
|
|
|
directives.push_back(conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfDirective::set_arg0(string a0)
|
|
|
|
{
|
|
|
|
if (arg0() == a0) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update a0.
|
|
|
|
if (!args.empty()) {
|
|
|
|
args.erase(args.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
args.insert(args.begin(), a0);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SrsConfDirective::remove(SrsConfDirective* v)
|
|
|
|
{
|
|
|
|
std::vector<SrsConfDirective*>::iterator it;
|
|
|
|
if ((it = ::find(directives.begin(), directives.end(), v)) != directives.end()) {
|
|
|
|
directives.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfDirective::is_vhost()
|
|
|
|
{
|
|
|
|
return name == "vhost";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfDirective::is_stream_caster()
|
|
|
|
{
|
|
|
|
return name == "stream_caster";
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfDirective::parse(SrsConfigBuffer* buffer)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
|
|
|
return parse_conf(buffer, parse_file);
|
|
|
|
}
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t SrsConfDirective::persistence(SrsFileWriter* writer, int level)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
static char SPACE = SRS_CONSTS_SP;
|
2015-08-26 13:49:05 +00:00
|
|
|
static char SEMICOLON = SRS_CONSTS_SE;
|
|
|
|
static char LF = SRS_CONSTS_LF;
|
|
|
|
static char LB = SRS_CONSTS_LB;
|
|
|
|
static char RB = SRS_CONSTS_RB;
|
|
|
|
static const char* INDENT = " ";
|
|
|
|
|
|
|
|
// for level0 directive, only contains sub directives.
|
|
|
|
if (level > 0) {
|
|
|
|
// indent by (level - 1) * 4 space.
|
|
|
|
for (int i = 0; i < level - 1; i++) {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write indent");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// directive name.
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)name.c_str(), (int)name.length(), NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write name");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
2018-01-01 11:39:57 +00:00
|
|
|
if (!args.empty() && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write name space");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// directive args.
|
|
|
|
for (int i = 0; i < (int)args.size(); i++) {
|
|
|
|
std::string& arg = args.at(i);
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)arg.c_str(), (int)arg.length(), NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write arg");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
2018-01-01 11:39:57 +00:00
|
|
|
if (i < (int)args.size() - 1 && (err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write arg space");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// native directive, without sub directives.
|
|
|
|
if (directives.empty()) {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&SEMICOLON, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write arg semicolon");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// persistence all sub directives.
|
|
|
|
if (level > 0) {
|
|
|
|
if (!directives.empty()) {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&SPACE, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir space");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&LB, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir left-brace");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir linefeed");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)directives.size(); i++) {
|
|
|
|
SrsConfDirective* dir = directives.at(i);
|
2017-06-11 01:54:09 +00:00
|
|
|
if ((err = dir->persistence(writer, level + 1)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "sub-dir %s", dir->name.c_str());
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level > 0 && !directives.empty()) {
|
|
|
|
// indent by (level - 1) * 4 space.
|
|
|
|
for (int i = 0; i < level - 1; i++) {
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)INDENT, 4, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir indent");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&RB, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir right-brace");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = writer->write((char*)&LF, 1, NULL)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "write sub-dir linefeed");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
return err;
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 06:12:36 +00:00
|
|
|
// LCOV_EXCL_START
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* SrsConfDirective::dumps_args()
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* arr = SrsJsonAny::array();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int i = 0; i < (int)args.size(); i++) {
|
|
|
|
string arg = args.at(i);
|
2015-09-19 04:27:31 +00:00
|
|
|
arr->append(SrsJsonAny::str(arg.c_str()));
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonAny* SrsConfDirective::dumps_arg0_to_str()
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
return SrsJsonAny::str(arg0().c_str());
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
SrsJsonAny* SrsConfDirective::dumps_arg0_to_integer()
|
|
|
|
{
|
2019-12-17 12:52:10 +00:00
|
|
|
return SrsJsonAny::integer(::atoll(arg0().c_str()));
|
2015-09-19 06:40:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonAny* SrsConfDirective::dumps_arg0_to_number()
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
return SrsJsonAny::number(::atof(arg0().c_str()));
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonAny* SrsConfDirective::dumps_arg0_to_boolean()
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2015-09-19 04:27:31 +00:00
|
|
|
return SrsJsonAny::boolean(arg0() == "on");
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
2020-01-01 06:12:36 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2015-08-27 14:46:56 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// see: ngx_conf_parse
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfDirective::parse_conf(SrsConfigBuffer* buffer, SrsDirectiveType type)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
std::vector<string> args;
|
|
|
|
int line_start = 0;
|
2017-06-11 06:03:19 +00:00
|
|
|
err = read_token(buffer, args, line_start);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* ret maybe:
|
|
|
|
* ERROR_SYSTEM_CONFIG_INVALID error.
|
|
|
|
* ERROR_SYSTEM_CONFIG_DIRECTIVE directive terminated by ';' found
|
|
|
|
* ERROR_SYSTEM_CONFIG_BLOCK_START token terminated by '{' found
|
|
|
|
* ERROR_SYSTEM_CONFIG_BLOCK_END the '}' found
|
|
|
|
* ERROR_SYSTEM_CONFIG_EOF the config file is done
|
|
|
|
*/
|
2017-06-11 06:03:19 +00:00
|
|
|
if (srs_error_code(err) == ERROR_SYSTEM_CONFIG_INVALID) {
|
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
if (srs_error_code(err) == ERROR_SYSTEM_CONFIG_BLOCK_END) {
|
2014-11-11 09:19:56 +00:00
|
|
|
if (type != parse_block) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_wrap(err, "line %d: unexpected \"}\"", buffer->line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
|
|
|
|
srs_freep(err);
|
|
|
|
return srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
if (srs_error_code(err) == ERROR_SYSTEM_CONFIG_EOF) {
|
2014-11-11 09:19:56 +00:00
|
|
|
if (type == parse_block) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_wrap(err, "line %d: unexpected end of file, expecting \"}\"", conf_line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
|
|
|
|
srs_freep(err);
|
|
|
|
return srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: empty directive", conf_line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// build directive tree.
|
|
|
|
SrsConfDirective* directive = new SrsConfDirective();
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
directive->conf_line = line_start;
|
|
|
|
directive->name = args[0];
|
|
|
|
args.erase(args.begin());
|
|
|
|
directive->args.swap(args);
|
|
|
|
|
|
|
|
directives.push_back(directive);
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if (srs_error_code(err) == ERROR_SYSTEM_CONFIG_BLOCK_START) {
|
|
|
|
srs_freep(err);
|
|
|
|
if ((err = directive->parse_conf(buffer, parse_block)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "parse dir");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_freep(err);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see: ngx_conf_read_token
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfDirective::read_token(SrsConfigBuffer* buffer, vector<string>& args, int& line_start)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
char* pstart = buffer->pos;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
bool sharp_comment = false;
|
|
|
|
|
|
|
|
bool d_quoted = false;
|
|
|
|
bool s_quoted = false;
|
|
|
|
|
|
|
|
bool need_space = false;
|
|
|
|
bool last_space = true;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (buffer->empty()) {
|
|
|
|
if (!args.empty() || !last_space) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID,
|
|
|
|
"line %d: unexpected end of file, expecting ; or \"}\"",
|
|
|
|
buffer->line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
srs_trace("config parse complete");
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_EOF, "EOF");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char ch = *buffer->pos++;
|
|
|
|
|
2015-03-21 02:25:03 +00:00
|
|
|
if (ch == SRS_LF) {
|
2014-11-11 09:19:56 +00:00
|
|
|
buffer->line++;
|
|
|
|
sharp_comment = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sharp_comment) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_space) {
|
|
|
|
if (is_common_space(ch)) {
|
|
|
|
last_space = true;
|
|
|
|
need_space = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ch == ';') {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_DIRECTIVE, "dir");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
if (ch == '{') {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_BLOCK_START, "block");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: unexpected '%c'", buffer->line, ch);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// last charecter is space.
|
|
|
|
if (last_space) {
|
|
|
|
if (is_common_space(ch)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pstart = buffer->pos - 1;
|
|
|
|
switch (ch) {
|
|
|
|
case ';':
|
|
|
|
if (args.size() == 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: unexpected ';'", buffer->line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_DIRECTIVE, "dir");
|
2014-11-11 09:19:56 +00:00
|
|
|
case '{':
|
|
|
|
if (args.size() == 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: unexpected '{'", buffer->line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_BLOCK_START, "block");
|
2014-11-11 09:19:56 +00:00
|
|
|
case '}':
|
|
|
|
if (args.size() != 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "line %d: unexpected '}'", buffer->line);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_BLOCK_END, "block");
|
2014-11-11 09:19:56 +00:00
|
|
|
case '#':
|
|
|
|
sharp_comment = 1;
|
|
|
|
continue;
|
|
|
|
case '"':
|
|
|
|
pstart++;
|
|
|
|
d_quoted = true;
|
|
|
|
last_space = 0;
|
|
|
|
continue;
|
|
|
|
case '\'':
|
|
|
|
pstart++;
|
|
|
|
s_quoted = true;
|
|
|
|
last_space = 0;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
last_space = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2015-09-17 03:37:35 +00:00
|
|
|
// last charecter is not space
|
2014-11-11 09:19:56 +00:00
|
|
|
if (line_start == 0) {
|
|
|
|
line_start = buffer->line;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
if (d_quoted) {
|
|
|
|
if (ch == '"') {
|
|
|
|
d_quoted = false;
|
|
|
|
need_space = true;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
} else if (s_quoted) {
|
|
|
|
if (ch == '\'') {
|
|
|
|
s_quoted = false;
|
|
|
|
need_space = true;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
} else if (is_common_space(ch) || ch == ';' || ch == '{') {
|
|
|
|
last_space = true;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
2015-03-14 05:09:34 +00:00
|
|
|
int len = (int)(buffer->pos - pstart);
|
2014-11-11 09:19:56 +00:00
|
|
|
char* aword = new char[len];
|
|
|
|
memcpy(aword, pstart, len);
|
|
|
|
aword[len - 1] = 0;
|
|
|
|
|
|
|
|
string word_str = aword;
|
|
|
|
if (!word_str.empty()) {
|
|
|
|
args.push_back(word_str);
|
|
|
|
}
|
2015-11-02 03:05:39 +00:00
|
|
|
srs_freepa(aword);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (ch == ';') {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_DIRECTIVE, "dir");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
if (ch == '{') {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_BLOCK_START, "block");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfig::SrsConfig()
|
|
|
|
{
|
2015-05-28 06:59:12 +00:00
|
|
|
dolphin = false;
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
show_help = false;
|
|
|
|
show_version = false;
|
|
|
|
test_conf = false;
|
|
|
|
|
|
|
|
root = new SrsConfDirective();
|
|
|
|
root->conf_line = 0;
|
|
|
|
root->name = "root";
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfig::~SrsConfig()
|
|
|
|
{
|
|
|
|
srs_freep(root);
|
|
|
|
}
|
|
|
|
|
2015-05-28 06:59:12 +00:00
|
|
|
bool SrsConfig::is_dolphin()
|
|
|
|
{
|
|
|
|
return dolphin;
|
|
|
|
}
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
void SrsConfig::subscribe(ISrsReloadHandler* handler)
|
|
|
|
{
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
it = std::find(subscribes.begin(), subscribes.end(), handler);
|
|
|
|
if (it != subscribes.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribes.push_back(handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SrsConfig::unsubscribe(ISrsReloadHandler* handler)
|
|
|
|
{
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
it = std::find(subscribes.begin(), subscribes.end(), handler);
|
|
|
|
if (it == subscribes.end()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
subscribes.erase(it);
|
|
|
|
}
|
|
|
|
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_START
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t SrsConfig::reload()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfig conf;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = conf.parse_file(config_file.c_str())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "parse file");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
srs_info("config reloader parse file success.");
|
2015-08-29 10:40:18 +00:00
|
|
|
|
|
|
|
// transform config to compatible with previous style of config.
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = srs_config_transform_vhost(conf.root)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "transform config");
|
2015-08-29 10:40:18 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = conf.check_config()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "check config");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
if ((err = reload_conf(&conf)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload config");
|
2017-06-11 01:54:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
// merge config.
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
2015-08-30 00:30:04 +00:00
|
|
|
// following directly support reload.
|
|
|
|
// origin, token_traverse, vhost, debug_srs_upnode
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// state graph
|
|
|
|
// old_vhost new_vhost
|
|
|
|
// DISABLED => ENABLED
|
|
|
|
// ENABLED => DISABLED
|
|
|
|
// ENABLED => ENABLED (modified)
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// collect all vhost names
|
|
|
|
std::vector<std::string> vhosts;
|
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* vhost = root->at(i);
|
|
|
|
if (vhost->name != "vhost") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
vhosts.push_back(vhost->arg0());
|
|
|
|
}
|
|
|
|
for (int i = 0; i < (int)old_root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* vhost = old_root->at(i);
|
|
|
|
if (vhost->name != "vhost") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (root->get("vhost", vhost->arg0())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
vhosts.push_back(vhost->arg0());
|
|
|
|
}
|
|
|
|
|
|
|
|
// process each vhost
|
|
|
|
for (int i = 0; i < (int)vhosts.size(); i++) {
|
|
|
|
std::string vhost = vhosts.at(i);
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* old_vhost = old_root->get("vhost", vhost);
|
|
|
|
SrsConfDirective* new_vhost = root->get("vhost", vhost);
|
|
|
|
|
|
|
|
// DISABLED => ENABLED
|
|
|
|
if (!get_vhost_enabled(old_vhost) && get_vhost_enabled(new_vhost)) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_added(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload vhost added");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ENABLED => DISABLED
|
|
|
|
if (get_vhost_enabled(old_vhost) && !get_vhost_enabled(new_vhost)) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_removed(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload vhost removed");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-30 00:30:04 +00:00
|
|
|
// cluster.mode, never supports reload.
|
2014-11-11 09:19:56 +00:00
|
|
|
// first, for the origin and edge role change is too complex.
|
|
|
|
// second, the vhosts in origin device group normally are all origin,
|
|
|
|
// they never change to edge sometimes.
|
|
|
|
// third, the origin or upnode device can always be restart,
|
|
|
|
// edge will retry and the users connected to edge are ok.
|
|
|
|
// it's ok to add or remove edge/origin vhost.
|
|
|
|
if (get_vhost_is_edge(old_vhost) != get_vhost_is_edge(new_vhost)) {
|
2017-09-22 08:14:30 +00:00
|
|
|
return srs_error_new(ERROR_RTMP_EDGE_RELOAD, "vhost mode changed");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-14 10:36:44 +00:00
|
|
|
|
|
|
|
// the auto reload configs:
|
|
|
|
// publish.parse_sps
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// ENABLED => ENABLED (modified)
|
|
|
|
if (get_vhost_enabled(new_vhost) && get_vhost_enabled(old_vhost)) {
|
|
|
|
srs_trace("vhost %s maybe modified, reload its detail.", vhost.c_str());
|
2015-08-29 22:49:20 +00:00
|
|
|
// chunk_size, only one per vhost.
|
|
|
|
if (!srs_directive_equals(new_vhost->get("chunk_size"), old_vhost->get("chunk_size"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_chunk_size(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes chunk_size failed", vhost.c_str());
|
2015-08-29 22:49:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload chunk_size success.", vhost.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// tcp_nodelay, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("tcp_nodelay"), old_vhost->get("tcp_nodelay"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_tcp_nodelay(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes tcp_nodelay failed", vhost.c_str());
|
2015-08-29 22:49:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload tcp_nodelay success.", vhost.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// min_latency, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("min_latency"), old_vhost->get("min_latency"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_realtime(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes min_latency failed", vhost.c_str());
|
2015-08-29 22:49:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload min_latency success.", vhost.c_str());
|
|
|
|
}
|
|
|
|
|
2015-08-29 15:18:25 +00:00
|
|
|
// play, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("play"), old_vhost->get("play"))) {
|
2014-11-11 09:19:56 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_play(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes play failed", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 15:18:25 +00:00
|
|
|
srs_trace("vhost %s reload play success.", vhost.c_str());
|
2015-04-15 09:12:22 +00:00
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// forward, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("forward"), old_vhost->get("forward"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_forward(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes forward failed", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload forward success.", vhost.c_str());
|
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2017-02-11 13:14:28 +00:00
|
|
|
// To reload DASH.
|
|
|
|
if (!srs_directive_equals(new_vhost->get("dash"), old_vhost->get("dash"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_dash(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "Reload vhost %s dash failed", vhost.c_str());
|
2017-02-11 13:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("Reload vhost %s dash ok.", vhost.c_str());
|
|
|
|
}
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// hls, only one per vhost
|
2014-12-20 03:45:59 +00:00
|
|
|
// @remark, the hls_on_error directly support reload.
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_hls(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes hls failed", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload hls success.", vhost.c_str());
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-03-12 14:38:11 +00:00
|
|
|
// hds reload
|
|
|
|
if (!srs_directive_equals(new_vhost->get("hds"), old_vhost->get("hds"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_hds(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes hds failed", vhost.c_str());
|
2015-03-12 14:38:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload hds success.", vhost.c_str());
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-15 07:58:57 +00:00
|
|
|
// dvr, only one per vhost, except the dvr_apply
|
|
|
|
if (!srs_directive_equals(new_vhost->get("dvr"), old_vhost->get("dvr"), "dvr_apply")) {
|
2014-11-11 09:19:56 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_dvr(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes dvr failed", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
srs_trace("vhost %s reload dvr success.", vhost.c_str());
|
|
|
|
}
|
2015-09-15 07:58:57 +00:00
|
|
|
// dvr_apply, the dynamic dvr filter.
|
|
|
|
if (true) {
|
|
|
|
// we must reload the dvr_apply, for it's apply to specified stream,
|
|
|
|
// and we donot want one stream reload take effect on another one.
|
2015-11-11 02:45:45 +00:00
|
|
|
// @see https://github.com/ossrs/srs/issues/459#issuecomment-140296597
|
2015-09-15 07:58:57 +00:00
|
|
|
SrsConfDirective* nda = new_vhost->get("dvr")? new_vhost->get("dvr")->get("dvr_apply") : NULL;
|
|
|
|
SrsConfDirective* oda = old_vhost->get("dvr")? old_vhost->get("dvr")->get("dvr_apply") : NULL;
|
2017-09-22 08:14:30 +00:00
|
|
|
if (!srs_directive_equals(nda, oda) && (err = do_reload_vhost_dvr_apply(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload dvr_apply");
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
|
|
|
// exec, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("exec"), old_vhost->get("exec"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_exec(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes exec failed", vhost.c_str());
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload exec success.", vhost.c_str());
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-08-29 14:41:50 +00:00
|
|
|
// publish, only one per vhost
|
|
|
|
if (!srs_directive_equals(new_vhost->get("publish"), old_vhost->get("publish"))) {
|
2014-12-04 10:21:04 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_publish(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes publish failed", vhost.c_str());
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 14:41:50 +00:00
|
|
|
srs_trace("vhost %s reload publish success.", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-01-22 01:34:33 +00:00
|
|
|
// http_static, only one per vhost.
|
|
|
|
if (!srs_directive_equals(new_vhost->get("http_static"), old_vhost->get("http_static"))) {
|
2015-01-18 10:00:40 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_http_updated()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes http_static failed", vhost.c_str());
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 01:34:33 +00:00
|
|
|
srs_trace("vhost %s reload http_static success.", vhost.c_str());
|
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-01-22 01:34:33 +00:00
|
|
|
// http_remux, only one per vhost.
|
|
|
|
if (!srs_directive_equals(new_vhost->get("http_remux"), old_vhost->get("http_remux"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_http_remux_updated(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes http_remux failed", vhost.c_str());
|
2015-01-22 01:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload http_remux success.", vhost.c_str());
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// transcode, many per vhost.
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = reload_transcode(new_vhost, old_vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload transcode");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// ingest, many per vhost.
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = reload_ingest(new_vhost, old_vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload ingest");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
srs_trace("ignore reload vhost, enabled old: %d, new: %d",
|
2017-03-25 09:21:39 +00:00
|
|
|
get_vhost_enabled(old_vhost), get_vhost_enabled(new_vhost));
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t SrsConfig::reload_conf(SrsConfig* conf)
|
2015-08-03 06:11:21 +00:00
|
|
|
{
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-03 06:11:21 +00:00
|
|
|
|
|
|
|
SrsConfDirective* old_root = root;
|
|
|
|
SrsAutoFree(SrsConfDirective, old_root);
|
|
|
|
|
|
|
|
root = conf->root;
|
|
|
|
conf->root = NULL;
|
|
|
|
|
|
|
|
// merge config.
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// never support reload:
|
|
|
|
// daemon
|
|
|
|
//
|
|
|
|
// always support reload without additional code:
|
|
|
|
// chunk_size, ff_log_dir,
|
2015-08-30 00:30:04 +00:00
|
|
|
// bandcheck, http_hooks, heartbeat,
|
2015-08-03 06:11:21 +00:00
|
|
|
// security
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// merge config: listen
|
|
|
|
if (!srs_directive_equals(root->get("listen"), old_root->get("listen"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_listen()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "listen");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: pid
|
|
|
|
if (!srs_directive_equals(root->get("pid"), old_root->get("pid"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_pid()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "pid");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: srs_log_tank
|
|
|
|
if (!srs_directive_equals(root->get("srs_log_tank"), old_root->get("srs_log_tank"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_tank()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "log tank");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: srs_log_level
|
|
|
|
if (!srs_directive_equals(root->get("srs_log_level"), old_root->get("srs_log_level"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_level()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "log level");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: srs_log_file
|
|
|
|
if (!srs_directive_equals(root->get("srs_log_file"), old_root->get("srs_log_file"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_file()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "log file");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 15:32:02 +00:00
|
|
|
// merge config: max_connections
|
|
|
|
if (!srs_directive_equals(root->get("max_connections"), old_root->get("max_connections"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_max_connections()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "max connections");;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: utc_time
|
|
|
|
if (!srs_directive_equals(root->get("utc_time"), old_root->get("utc_time"))) {
|
2017-07-29 12:02:38 +00:00
|
|
|
if ((err = do_reload_utc_time()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "utc time");;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// merge config: pithy_print_ms
|
|
|
|
if (!srs_directive_equals(root->get("pithy_print_ms"), old_root->get("pithy_print_ms"))) {
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_pithy_print_ms()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "pithy print ms");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: http_api
|
2017-07-29 13:39:57 +00:00
|
|
|
if ((err = reload_http_api(old_root)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// merge config: http_stream
|
2017-07-29 13:39:57 +00:00
|
|
|
if ((err = reload_http_stream(old_root)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http steram");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// TODO: FIXME: support reload stream_caster.
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// merge config: vhost
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = reload_vhost(old_root)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost");;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsConfig::reload_http_api(SrsConfDirective* old_root)
|
2015-08-03 06:11:21 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-03 06:11:21 +00:00
|
|
|
|
|
|
|
// merge config.
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
// state graph
|
|
|
|
// old_http_api new_http_api
|
|
|
|
// DISABLED => ENABLED
|
|
|
|
// ENABLED => DISABLED
|
|
|
|
// ENABLED => ENABLED (modified)
|
|
|
|
|
|
|
|
SrsConfDirective* new_http_api = root->get("http_api");
|
|
|
|
SrsConfDirective* old_http_api = old_root->get("http_api");
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// DISABLED => ENABLED
|
|
|
|
if (!get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_api_enabled()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api off=>on");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload off=>on http_api success.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// ENABLED => DISABLED
|
|
|
|
if (get_http_api_enabled(old_http_api) && !get_http_api_enabled(new_http_api)) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_api_disabled()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api on=>off");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http_api on=>off success.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ENABLED => ENABLED (modified)
|
|
|
|
if (get_http_api_enabled(old_http_api) && get_http_api_enabled(new_http_api)
|
|
|
|
&& !srs_directive_equals(old_http_api, new_http_api)
|
2017-03-25 09:21:39 +00:00
|
|
|
) {
|
2015-08-03 06:11:21 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_api_enabled()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api enabled");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http api enabled success.");
|
2015-08-03 06:11:21 +00:00
|
|
|
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!srs_directive_equals(old_http_api->get("crossdomain"), new_http_api->get("crossdomain"))) {
|
2015-08-28 04:38:09 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-07-29 13:39:57 +00:00
|
|
|
if ((err = subscribe->on_reload_http_api_crossdomain()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api crossdomain");
|
2015-08-28 04:38:09 +00:00
|
|
|
}
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http api crossdomain success.");
|
2015-08-28 04:28:18 +00:00
|
|
|
|
|
|
|
if (!srs_directive_equals(old_http_api->get("raw_api"), new_http_api->get("raw_api"))) {
|
2015-08-28 04:38:09 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_api_raw_api()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http api raw_api");
|
2015-08-28 04:38:09 +00:00
|
|
|
}
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http api raw_api success.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http_api success, nothing changed.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t SrsConfig::reload_http_stream(SrsConfDirective* old_root)
|
2015-08-03 06:11:21 +00:00
|
|
|
{
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-03 06:11:21 +00:00
|
|
|
|
|
|
|
// merge config.
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
// state graph
|
|
|
|
// old_http_stream new_http_stream
|
|
|
|
// DISABLED => ENABLED
|
|
|
|
// ENABLED => DISABLED
|
|
|
|
// ENABLED => ENABLED (modified)
|
|
|
|
|
2015-08-29 10:40:18 +00:00
|
|
|
SrsConfDirective* new_http_stream = root->get("http_server");
|
|
|
|
SrsConfDirective* old_http_stream = old_root->get("http_server");
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// DISABLED => ENABLED
|
|
|
|
if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_stream_enabled()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http stream off=>on");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http stream off=>on success.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
// ENABLED => DISABLED
|
|
|
|
if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_stream_disabled()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http stream on=>off");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http stream on=>off success.");
|
|
|
|
return err;
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ENABLED => ENABLED (modified)
|
|
|
|
if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
|
|
|
|
&& !srs_directive_equals(old_http_stream, new_http_stream)
|
2017-03-25 09:21:39 +00:00
|
|
|
) {
|
2015-08-03 06:11:21 +00:00
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_http_stream_updated()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http stream enabled");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http stream enabled success.");
|
2015-08-03 06:11:21 +00:00
|
|
|
|
2016-12-15 08:22:04 +00:00
|
|
|
if (!srs_directive_equals(old_http_stream->get("crossdomain"), new_http_stream->get("crossdomain"))) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-07-29 13:39:57 +00:00
|
|
|
if ((err = subscribe->on_reload_http_stream_crossdomain()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "http stream crossdomain");
|
2016-12-15 08:22:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http stream crossdomain success.");
|
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("reload http stream success, nothing changed.");
|
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
std::vector<SrsConfDirective*> old_transcoders;
|
|
|
|
for (int i = 0; i < (int)old_vhost->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = old_vhost->at(i);
|
|
|
|
if (conf->name == "transcode") {
|
|
|
|
old_transcoders.push_back(conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SrsConfDirective*> new_transcoders;
|
|
|
|
for (int i = 0; i < (int)new_vhost->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = new_vhost->at(i);
|
|
|
|
if (conf->name == "transcode") {
|
|
|
|
new_transcoders.push_back(conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
std::string vhost = new_vhost->arg0();
|
|
|
|
|
|
|
|
// to be simple:
|
2017-03-25 09:21:39 +00:00
|
|
|
// whatever, once tiny changed of transcode,
|
2014-11-11 09:19:56 +00:00
|
|
|
// restart all ffmpeg of vhost.
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
// discovery the removed ffmpeg.
|
|
|
|
for (int i = 0; !changed && i < (int)old_transcoders.size(); i++) {
|
|
|
|
SrsConfDirective* old_transcoder = old_transcoders.at(i);
|
|
|
|
std::string transcoder_id = old_transcoder->arg0();
|
|
|
|
|
|
|
|
// if transcoder exists in new vhost, not removed, ignore.
|
|
|
|
if (new_vhost->get("transcode", transcoder_id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// discovery the added ffmpeg.
|
|
|
|
for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
|
|
|
|
SrsConfDirective* new_transcoder = new_transcoders.at(i);
|
|
|
|
std::string transcoder_id = new_transcoder->arg0();
|
|
|
|
|
|
|
|
// if transcoder exists in old vhost, not added, ignore.
|
|
|
|
if (old_vhost->get("transcode", transcoder_id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for updated transcoders, restart them.
|
|
|
|
for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
|
|
|
|
SrsConfDirective* new_transcoder = new_transcoders.at(i);
|
|
|
|
std::string transcoder_id = new_transcoder->arg0();
|
|
|
|
SrsConfDirective* old_transcoder = old_vhost->get("transcode", transcoder_id);
|
|
|
|
srs_assert(old_transcoder);
|
|
|
|
|
|
|
|
if (srs_directive_equals(new_transcoder, old_transcoder)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// transcode, many per vhost
|
|
|
|
if (changed) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_transcode(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes transcode failed", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload transcode success.", vhost.c_str());
|
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
std::vector<SrsConfDirective*> old_ingesters;
|
|
|
|
for (int i = 0; i < (int)old_vhost->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = old_vhost->at(i);
|
|
|
|
if (conf->name == "ingest") {
|
|
|
|
old_ingesters.push_back(conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SrsConfDirective*> new_ingesters;
|
|
|
|
for (int i = 0; i < (int)new_vhost->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = new_vhost->at(i);
|
|
|
|
if (conf->name == "ingest") {
|
|
|
|
new_ingesters.push_back(conf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
|
|
|
|
std::string vhost = new_vhost->arg0();
|
|
|
|
|
|
|
|
// for removed ingesters, stop them.
|
|
|
|
for (int i = 0; i < (int)old_ingesters.size(); i++) {
|
|
|
|
SrsConfDirective* old_ingester = old_ingesters.at(i);
|
|
|
|
std::string ingest_id = old_ingester->arg0();
|
|
|
|
SrsConfDirective* new_ingester = new_vhost->get("ingest", ingest_id);
|
|
|
|
|
|
|
|
// ENABLED => DISABLED
|
|
|
|
if (get_ingest_enabled(old_ingester) && !get_ingest_enabled(new_ingester)) {
|
|
|
|
// notice handler ingester removed.
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_ingest_removed(vhost, ingest_id)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes ingest=%s removed failed", vhost.c_str(), ingest_id.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload ingest=%s removed success.", vhost.c_str(), ingest_id.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for added ingesters, start them.
|
|
|
|
for (int i = 0; i < (int)new_ingesters.size(); i++) {
|
|
|
|
SrsConfDirective* new_ingester = new_ingesters.at(i);
|
|
|
|
std::string ingest_id = new_ingester->arg0();
|
|
|
|
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
|
|
|
|
|
|
|
|
// DISABLED => ENABLED
|
|
|
|
if (!get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_ingest_added(vhost, ingest_id)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes ingest=%s added failed", vhost.c_str(), ingest_id.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload ingest=%s added success.", vhost.c_str(), ingest_id.c_str());
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// for updated ingesters, restart them.
|
|
|
|
for (int i = 0; i < (int)new_ingesters.size(); i++) {
|
|
|
|
SrsConfDirective* new_ingester = new_ingesters.at(i);
|
|
|
|
std::string ingest_id = new_ingester->arg0();
|
|
|
|
SrsConfDirective* old_ingester = old_vhost->get("ingest", ingest_id);
|
|
|
|
|
|
|
|
// ENABLED => ENABLED
|
|
|
|
if (get_ingest_enabled(old_ingester) && get_ingest_enabled(new_ingester)) {
|
|
|
|
if (srs_directive_equals(new_ingester, old_ingester)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
// notice handler ingester removed.
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_ingest_updated(vhost, ingest_id)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes ingest=%s updated failed", vhost.c_str(), ingest_id.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str());
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
srs_trace("ingest nothing changed for vhost=%s", vhost.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// see: ngx_get_options
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_START
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::parse_options(int argc, char** argv)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
// argv
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
_argv.append(argv[i]);
|
|
|
|
|
|
|
|
if (i < argc - 1) {
|
|
|
|
_argv.append(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// config
|
|
|
|
show_help = true;
|
|
|
|
for (int i = 1; i < argc; i++) {
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = parse_argv(i, argv)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "parse argv");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_help) {
|
|
|
|
print_help(argv);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_version) {
|
|
|
|
fprintf(stderr, "%s\n", RTMP_SIG_SRS_VERSION);
|
|
|
|
exit(0);
|
|
|
|
}
|
2016-01-04 09:28:18 +00:00
|
|
|
if (show_signature) {
|
|
|
|
fprintf(stderr, "%s\n", RTMP_SIG_SRS_SERVER);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// first hello message.
|
2016-01-05 08:58:21 +00:00
|
|
|
srs_trace(_srs_version);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (config_file.empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no config, read help: %s -h", argv[0]);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
err = parse_file(config_file.c_str());
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (test_conf) {
|
|
|
|
// the parse_file never check the config,
|
|
|
|
// we check it when user requires check config file.
|
2017-06-11 06:03:19 +00:00
|
|
|
if (err == srs_success && (err = srs_config_transform_vhost(root)) == srs_success) {
|
|
|
|
if (err == srs_success && (err = check_config()) == srs_success) {
|
|
|
|
srs_trace("config file is ok");
|
|
|
|
exit(0);
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error("invalid config, %s", srs_error_desc(err).c_str());
|
|
|
|
int ret = srs_error_code(err);
|
|
|
|
srs_freep(err);
|
|
|
|
exit(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// transform config to compatible with previous style of config.
|
|
|
|
if ((err = srs_config_transform_vhost(root)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "transform");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check log name and level
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (true) {
|
|
|
|
std::string log_filename = this->get_log_file();
|
|
|
|
if (get_log_tank_file() && log_filename.empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "no log file");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
if (get_log_tank_file()) {
|
|
|
|
srs_trace("write log to file %s", log_filename.c_str());
|
|
|
|
srs_trace("you can: tailf %s", log_filename.c_str());
|
|
|
|
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
|
|
|
|
} else {
|
|
|
|
srs_trace("write log to console");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::initialize_cwd()
|
2016-01-08 05:58:19 +00:00
|
|
|
{
|
|
|
|
// cwd
|
|
|
|
char cwd[256];
|
|
|
|
getcwd(cwd, sizeof(cwd));
|
|
|
|
_cwd = cwd;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_success;
|
2016-01-08 05:58:19 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t SrsConfig::persistence()
|
2015-08-26 13:11:28 +00:00
|
|
|
{
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-26 13:49:05 +00:00
|
|
|
|
|
|
|
// write to a tmp file, then mv to the config.
|
|
|
|
std::string path = config_file + ".tmp";
|
|
|
|
|
|
|
|
// open the tmp file for persistence
|
|
|
|
SrsFileWriter fw;
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = fw.open(path)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "open file");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 06:27:49 +00:00
|
|
|
// do persistence to writer.
|
2017-06-11 01:54:09 +00:00
|
|
|
if ((err = do_persistence(&fw)) != srs_success) {
|
2015-08-26 13:49:05 +00:00
|
|
|
::unlink(path.c_str());
|
2017-06-11 01:54:09 +00:00
|
|
|
return srs_error_wrap(err, "persistence");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// rename the config file.
|
|
|
|
if (::rename(path.c_str(), config_file.c_str()) < 0) {
|
|
|
|
::unlink(path.c_str());
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_PERSISTENCE, "rename %s=>%s", path.c_str(), config_file.c_str());
|
2015-12-15 06:27:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
return err;
|
2015-12-15 06:27:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t SrsConfig::do_persistence(SrsFileWriter* fw)
|
2015-12-15 06:27:49 +00:00
|
|
|
{
|
2017-06-11 01:54:09 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-12-15 06:27:49 +00:00
|
|
|
|
|
|
|
// persistence root directive to writer.
|
2017-06-11 01:54:09 +00:00
|
|
|
if ((err = root->persistence(fw, 0)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "root persistence");
|
2015-08-26 13:49:05 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 01:54:09 +00:00
|
|
|
return err;
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::minimal_to_json(SrsJsonObject* obj)
|
2015-09-01 05:33:49 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-01 05:33:49 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* dir = root->directives.at(i);
|
|
|
|
if (dir->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir->name == "listen") {
|
|
|
|
obj->set(dir->name, dir->dumps_args());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-01 05:33:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::global_to_json(SrsJsonObject* obj)
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-27 14:46:56 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* dir = root->directives.at(i);
|
|
|
|
if (dir->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir->name == "listen") {
|
|
|
|
obj->set(dir->name, dir->dumps_args());
|
|
|
|
} else if (dir->name == "pid") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_str());
|
|
|
|
} else if (dir->name == "chunk_size") {
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (dir->name == "ff_log_dir") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_str());
|
|
|
|
} else if (dir->name == "srs_log_tank") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_str());
|
|
|
|
} else if (dir->name == "srs_log_level") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_str());
|
|
|
|
} else if (dir->name == "srs_log_file") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_str());
|
|
|
|
} else if (dir->name == "max_connections") {
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (dir->name == "daemon") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_boolean());
|
|
|
|
} else if (dir->name == "utc_time") {
|
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_boolean());
|
|
|
|
} else if (dir->name == "pithy_print_ms") {
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set(dir->name, dir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (dir->name == "heartbeat") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name == "enabled") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "interval") {
|
2015-09-19 06:40:32 +00:00
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (sdir->name == "url") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "device_id") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "summaries") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->set(dir->name, sobj);
|
|
|
|
} else if (dir->name == "stats") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name == "network") {
|
2015-09-19 06:40:32 +00:00
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (sdir->name == "disk") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_args());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->set(dir->name, sobj);
|
|
|
|
} else if (dir->name == "http_api") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name == "enabled") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "listen") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "crossdomain") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "raw_api") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* ssobj = SrsJsonAny::object();
|
2015-08-30 14:23:47 +00:00
|
|
|
sobj->set(sdir->name, ssobj);
|
|
|
|
|
|
|
|
for (int j = 0; j < (int)sdir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* ssdir = sdir->directives.at(j);
|
|
|
|
if (ssdir->name == "enabled") {
|
|
|
|
ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (ssdir->name == "allow_reload") {
|
|
|
|
ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (ssdir->name == "allow_query") {
|
|
|
|
ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
|
2015-08-30 15:08:27 +00:00
|
|
|
} else if (ssdir->name == "allow_update") {
|
|
|
|
ssobj->set(ssdir->name, ssdir->dumps_arg0_to_boolean());
|
2015-08-30 14:23:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->set(dir->name, sobj);
|
|
|
|
} else if (dir->name == "http_server") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name == "enabled") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "listen") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "dir") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->set(dir->name, sobj);
|
|
|
|
} else if (dir->name == "stream_caster") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name == "enabled") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "caster") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "output") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "listen") {
|
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "rtp_port_min") {
|
2015-09-19 06:40:32 +00:00
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
} else if (sdir->name == "rtp_port_max") {
|
2015-09-19 06:40:32 +00:00
|
|
|
sobj->set(sdir->name, sdir->dumps_arg0_to_integer());
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
obj->set(dir->name, sobj);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobjs = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
int nb_vhosts = 0;
|
|
|
|
|
2015-08-27 15:55:59 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
2015-08-27 14:46:56 +00:00
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* dir = root->directives.at(i);
|
|
|
|
if (!dir->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nb_vhosts++;
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-27 14:46:56 +00:00
|
|
|
sobjs->set(dir->arg0(), sobj);
|
|
|
|
|
2015-08-27 15:55:59 +00:00
|
|
|
SrsStatisticVhost* svhost = stat->find_vhost(dir->arg0());
|
2015-09-19 06:40:32 +00:00
|
|
|
sobj->set("id", SrsJsonAny::integer(svhost? (double)svhost->id : 0));
|
2015-08-30 04:16:26 +00:00
|
|
|
sobj->set("name", dir->dumps_arg0_to_str());
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("enabled", SrsJsonAny::boolean(get_vhost_enabled(dir->arg0())));
|
2015-08-27 15:55:59 +00:00
|
|
|
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_dvr_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("dvr", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_vhost_http_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("http_static", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_vhost_http_remux_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("http_remux", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_hls_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("hls", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_hds_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("hds", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_vhost_http_hooks(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("http_hooks", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_exec_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("exec", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_bw_check_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("bandcheck", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (!get_vhost_is_edge(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("origin", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_forward_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("forward", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_security_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("security", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_refer_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("refer", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_mr_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("mr", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_realtime_enabled(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("min_latency", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_gop_cache(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("gop_cache", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_tcp_nodelay(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("tcp_nodelay", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_mix_correct(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("mix_correct", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_time_jitter(dir->arg0()) != SrsRtmpJitterAlgorithmOFF) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("time_jitter", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-09-12 14:22:33 +00:00
|
|
|
if (get_atc(dir->arg0())) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("atc", SrsJsonAny::boolean(true));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
|
|
|
|
bool has_transcode = false;
|
|
|
|
for (int j = 0; !has_transcode && j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name != "transcode") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_transcode_enabled(sdir)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int k = 0; !has_transcode && k < (int)sdir->directives.size(); k++) {
|
|
|
|
SrsConfDirective* ssdir = sdir->directives.at(k);
|
|
|
|
if (ssdir->name != "engine") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_engine_enabled(ssdir)) {
|
|
|
|
has_transcode = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-30 04:16:26 +00:00
|
|
|
if (has_transcode) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("transcode", SrsJsonAny::boolean(has_transcode));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
|
|
|
|
bool has_ingest = false;
|
|
|
|
for (int j = 0; !has_ingest && j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
if (sdir->name != "ingest") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_ingest_enabled(sdir)) {
|
|
|
|
has_ingest = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-08-30 04:16:26 +00:00
|
|
|
if (has_ingest) {
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("ingest", SrsJsonAny::boolean(has_ingest));
|
2015-08-30 04:16:26 +00:00
|
|
|
}
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("nb_vhosts", SrsJsonAny::integer(nb_vhosts));
|
2015-08-27 14:46:56 +00:00
|
|
|
obj->set("vhosts", sobjs);
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-27 14:46:56 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj)
|
2015-08-27 14:46:56 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-27 14:46:56 +00:00
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
SrsConfDirective* dir = NULL;
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
// always present in vhost.
|
2015-08-29 08:12:30 +00:00
|
|
|
SrsStatistic* stat = SrsStatistic::instance();
|
|
|
|
|
|
|
|
SrsStatisticVhost* svhost = stat->find_vhost(vhost->arg0());
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("id", SrsJsonAny::integer(svhost? (double)svhost->id : 0));
|
2015-08-29 08:12:30 +00:00
|
|
|
|
|
|
|
obj->set("name", vhost->dumps_arg0_to_str());
|
2015-09-19 04:27:31 +00:00
|
|
|
obj->set("enabled", SrsJsonAny::boolean(get_vhost_enabled(vhost)));
|
2015-08-29 08:12:30 +00:00
|
|
|
|
2015-08-29 22:49:20 +00:00
|
|
|
// vhost scope configs.
|
|
|
|
if ((dir = vhost->get("chunk_size")) != NULL) {
|
2015-09-19 06:40:32 +00:00
|
|
|
obj->set("chunk_size", dir->dumps_arg0_to_integer());
|
2015-08-29 22:49:20 +00:00
|
|
|
}
|
|
|
|
if ((dir = vhost->get("min_latency")) != NULL) {
|
|
|
|
obj->set("min_latency", dir->dumps_arg0_to_boolean());
|
|
|
|
}
|
|
|
|
if ((dir = vhost->get("tcp_nodelay")) != NULL) {
|
|
|
|
obj->set("tcp_nodelay", dir->dumps_arg0_to_boolean());
|
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
|
2015-08-30 00:30:04 +00:00
|
|
|
// cluster.
|
|
|
|
if ((dir = vhost->get("cluster")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* cluster = SrsJsonAny::object();
|
2015-08-30 00:30:04 +00:00
|
|
|
obj->set("cluster", cluster);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
|
|
|
if (sdir->name == "mode") {
|
|
|
|
cluster->set("mode", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "origin") {
|
|
|
|
cluster->set("origin", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "token_traverse") {
|
|
|
|
cluster->set("token_traverse", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "vhost") {
|
|
|
|
cluster->set("vhost", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "debug_srs_upnode") {
|
|
|
|
cluster->set("debug_srs_upnode", sdir->dumps_arg0_to_boolean());
|
|
|
|
}
|
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// forward
|
|
|
|
if ((dir = vhost->get("forward")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* forward = SrsJsonAny::object();
|
2015-08-29 23:59:25 +00:00
|
|
|
obj->set("forward", forward);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
forward->set("enabled", SrsJsonAny::boolean(get_forward_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 23:59:25 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "destination") {
|
2015-08-29 23:59:25 +00:00
|
|
|
forward->set("destination", sdir->dumps_args());
|
|
|
|
}
|
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 15:18:25 +00:00
|
|
|
// play
|
|
|
|
if ((dir = vhost->get("play")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* play = SrsJsonAny::object();
|
2015-08-29 15:18:25 +00:00
|
|
|
obj->set("play", play);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
|
|
|
if (sdir->name == "time_jitter") {
|
|
|
|
play->set("time_jitter", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "mix_correct") {
|
|
|
|
play->set("mix_correct", sdir->dumps_arg0_to_boolean());
|
2015-08-29 15:36:03 +00:00
|
|
|
} else if (sdir->name == "atc") {
|
|
|
|
play->set("atc", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "atc_auto") {
|
|
|
|
play->set("atc_auto", sdir->dumps_arg0_to_boolean());
|
2015-08-29 23:05:57 +00:00
|
|
|
} else if (sdir->name == "mw_latency") {
|
2015-09-19 06:40:32 +00:00
|
|
|
play->set("mw_latency", sdir->dumps_arg0_to_integer());
|
2015-08-29 23:26:55 +00:00
|
|
|
} else if (sdir->name == "gop_cache") {
|
|
|
|
play->set("gop_cache", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "queue_length") {
|
2015-09-19 06:40:32 +00:00
|
|
|
play->set("queue_length", sdir->dumps_arg0_to_integer());
|
2015-08-29 23:36:06 +00:00
|
|
|
} else if (sdir->name == "reduce_sequence_header") {
|
|
|
|
play->set("reduce_sequence_header", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "send_min_interval") {
|
2015-09-19 06:40:32 +00:00
|
|
|
play->set("send_min_interval", sdir->dumps_arg0_to_integer());
|
2015-08-29 15:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 14:41:50 +00:00
|
|
|
// publish
|
|
|
|
if ((dir = vhost->get("publish")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* publish = SrsJsonAny::object();
|
2015-08-29 14:41:50 +00:00
|
|
|
obj->set("publish", publish);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
|
|
|
if (sdir->name == "mr") {
|
|
|
|
publish->set("mr", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "mr_latency") {
|
2015-09-19 06:40:32 +00:00
|
|
|
publish->set("mr_latency", sdir->dumps_arg0_to_integer());
|
2015-08-29 14:41:50 +00:00
|
|
|
} else if (sdir->name == "firstpkt_timeout") {
|
2015-09-19 06:40:32 +00:00
|
|
|
publish->set("firstpkt_timeout", sdir->dumps_arg0_to_integer());
|
2015-08-29 14:41:50 +00:00
|
|
|
} else if (sdir->name == "normal_timeout") {
|
2015-09-19 06:40:32 +00:00
|
|
|
publish->set("normal_timeout", sdir->dumps_arg0_to_integer());
|
2015-08-29 14:41:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// refer
|
|
|
|
if ((dir = vhost->get("refer")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* refer = SrsJsonAny::object();
|
2015-08-29 10:40:18 +00:00
|
|
|
obj->set("refer", refer);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
refer->set("enabled", SrsJsonAny::boolean(get_refer_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 10:40:18 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "all") {
|
2015-08-29 10:40:18 +00:00
|
|
|
refer->set("all", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "publish") {
|
|
|
|
refer->set("publish", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "play") {
|
|
|
|
refer->set("play", sdir->dumps_args());
|
|
|
|
}
|
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// bandcheck
|
|
|
|
if ((dir = vhost->get("bandcheck")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* bandcheck = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("bandcheck", bandcheck);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
bandcheck->set("enabled", SrsJsonAny::boolean(get_bw_check_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "key") {
|
2015-08-29 08:12:30 +00:00
|
|
|
bandcheck->set("key", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "interval") {
|
2015-09-19 06:40:32 +00:00
|
|
|
bandcheck->set("interval", sdir->dumps_arg0_to_integer());
|
2015-08-29 08:12:30 +00:00
|
|
|
} else if (sdir->name == "limit_kbps") {
|
2015-09-19 06:40:32 +00:00
|
|
|
bandcheck->set("limit_kbps", sdir->dumps_arg0_to_integer());
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
// security
|
|
|
|
if ((dir = vhost->get("security")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* security = SrsJsonAny::object();
|
2015-08-28 15:51:23 +00:00
|
|
|
obj->set("security", security);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
security->set("enabled", SrsJsonAny::boolean(get_security_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* allows = SrsJsonAny::array();
|
2015-08-28 15:51:23 +00:00
|
|
|
security->set("allows", allows);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* denies = SrsJsonAny::array();
|
2015-08-30 02:17:39 +00:00
|
|
|
security->set("denies", denies);
|
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "allow") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* allow = SrsJsonAny::object();
|
|
|
|
allow->set("action", SrsJsonAny::str(sdir->name.c_str()));
|
|
|
|
allow->set("method", SrsJsonAny::str(sdir->arg0().c_str()));
|
|
|
|
allow->set("entry", SrsJsonAny::str(sdir->arg1().c_str()));
|
2015-08-28 15:51:23 +00:00
|
|
|
allows->append(allow);
|
2015-08-30 02:17:39 +00:00
|
|
|
} else if (sdir->name == "deny") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* deny = SrsJsonAny::object();
|
|
|
|
deny->set("action", SrsJsonAny::str(sdir->name.c_str()));
|
|
|
|
deny->set("method", SrsJsonAny::str(sdir->arg0().c_str()));
|
|
|
|
deny->set("entry", SrsJsonAny::str(sdir->arg1().c_str()));
|
2015-08-30 02:17:39 +00:00
|
|
|
denies->append(deny);
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
// http_static
|
|
|
|
if ((dir = vhost->get("http_static")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* http_static = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("http_static", http_static);
|
2015-08-28 15:51:23 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
http_static->set("enabled", SrsJsonAny::boolean(get_vhost_http_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "mount") {
|
2015-08-29 08:12:30 +00:00
|
|
|
http_static->set("mount", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "dir") {
|
|
|
|
http_static->set("dir", sdir->dumps_arg0_to_str());
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
// http_remux
|
|
|
|
if ((dir = vhost->get("http_remux")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* http_remux = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("http_remux", http_remux);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
http_remux->set("enabled", SrsJsonAny::boolean(get_vhost_http_remux_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "fast_cache") {
|
2015-09-19 06:40:32 +00:00
|
|
|
http_remux->set("fast_cache", sdir->dumps_arg0_to_integer());
|
2015-08-29 08:12:30 +00:00
|
|
|
} else if (sdir->name == "mount") {
|
|
|
|
http_remux->set("mount", sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
2015-08-29 08:12:30 +00:00
|
|
|
|
|
|
|
// http_hooks
|
|
|
|
if ((dir = vhost->get("http_hooks")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* http_hooks = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("http_hooks", http_hooks);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
http_hooks->set("enabled", SrsJsonAny::boolean(get_vhost_http_hooks_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "on_connect") {
|
2015-08-29 08:12:30 +00:00
|
|
|
http_hooks->set("on_connect", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_close") {
|
|
|
|
http_hooks->set("on_close", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_publish") {
|
|
|
|
http_hooks->set("on_publish", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_unpublish") {
|
|
|
|
http_hooks->set("on_unpublish", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_play") {
|
|
|
|
http_hooks->set("on_play", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_stop") {
|
|
|
|
http_hooks->set("on_stop", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_dvr") {
|
|
|
|
http_hooks->set("on_dvr", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_hls") {
|
|
|
|
http_hooks->set("on_hls", sdir->dumps_args());
|
|
|
|
} else if (sdir->name == "on_hls_notify") {
|
|
|
|
http_hooks->set("on_hls_notify", sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hls
|
|
|
|
if ((dir = vhost->get("hls")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* hls = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("hls", hls);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
hls->set("enabled", SrsJsonAny::boolean(get_hls_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "hls_fragment") {
|
2015-08-29 08:12:30 +00:00
|
|
|
hls->set("hls_fragment", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_td_ratio") {
|
|
|
|
hls->set("hls_td_ratio", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_aof_ratio") {
|
|
|
|
hls->set("hls_aof_ratio", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_window") {
|
|
|
|
hls->set("hls_window", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_on_error") {
|
|
|
|
hls->set("hls_on_error", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_storage") {
|
|
|
|
hls->set("hls_storage", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_path") {
|
|
|
|
hls->set("hls_path", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_m3u8_file") {
|
|
|
|
hls->set("hls_m3u8_file", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_ts_file") {
|
|
|
|
hls->set("hls_ts_file", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_ts_floor") {
|
|
|
|
hls->set("hls_ts_floor", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "hls_entry_prefix") {
|
|
|
|
hls->set("hls_entry_prefix", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_mount") {
|
|
|
|
hls->set("hls_mount", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_acodec") {
|
|
|
|
hls->set("hls_acodec", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_vcodec") {
|
|
|
|
hls->set("hls_vcodec", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_cleanup") {
|
|
|
|
hls->set("hls_cleanup", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "hls_dispose") {
|
|
|
|
hls->set("hls_dispose", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_nb_notify") {
|
2015-09-19 06:40:32 +00:00
|
|
|
hls->set("hls_nb_notify", sdir->dumps_arg0_to_integer());
|
2019-12-05 12:47:23 +00:00
|
|
|
} else if (sdir->name == "hls_dts_directly") {
|
|
|
|
hls->set("hls_dts_directly", sdir->dumps_arg0_to_boolean());
|
2015-08-29 08:12:30 +00:00
|
|
|
} else if (sdir->name == "hls_wait_keyframe") {
|
|
|
|
hls->set("hls_wait_keyframe", sdir->dumps_arg0_to_boolean());
|
2018-03-25 04:05:52 +00:00
|
|
|
} else if (sdir->name == "hls_keys") {
|
|
|
|
hls->set("hls_keys", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "hls_fragments_per_key") {
|
|
|
|
hls->set("hls_fragments_per_key", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hls_key_file") {
|
|
|
|
hls->set("hls_key_file", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_key_file_path") {
|
|
|
|
hls->set("hls_key_file_path", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "hls_key_url") {
|
|
|
|
hls->set("hls_key_url", sdir->dumps_arg0_to_str());
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hds
|
|
|
|
if ((dir = vhost->get("hds")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* hds = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("hds", hds);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
hds->set("enabled", SrsJsonAny::boolean(get_hds_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "hds_fragment") {
|
2015-08-29 08:12:30 +00:00
|
|
|
hds->set("hds_fragment", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hds_window") {
|
|
|
|
hds->set("hds_window", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "hds_path") {
|
|
|
|
hds->set("hds_path", sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// dvr
|
|
|
|
if ((dir = vhost->get("dvr")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* dvr = SrsJsonAny::object();
|
2015-08-28 15:51:23 +00:00
|
|
|
obj->set("dvr", dvr);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
dvr->set("enabled", SrsJsonAny::boolean(get_dvr_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "dvr_plan") {
|
2015-08-28 15:51:23 +00:00
|
|
|
dvr->set("dvr_plan", sdir->dumps_arg0_to_str());
|
2015-09-15 07:58:57 +00:00
|
|
|
} else if (sdir->name == "dvr_apply") {
|
|
|
|
dvr->set("dvr_apply", sdir->dumps_args());
|
2015-08-28 15:51:23 +00:00
|
|
|
} else if (sdir->name == "dvr_path") {
|
|
|
|
dvr->set("dvr_path", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "dvr_duration") {
|
|
|
|
dvr->set("dvr_duration", sdir->dumps_arg0_to_number());
|
|
|
|
} else if (sdir->name == "dvr_wait_keyframe") {
|
|
|
|
dvr->set("dvr_wait_keyframe", sdir->dumps_arg0_to_boolean());
|
|
|
|
} else if (sdir->name == "time_jitter") {
|
|
|
|
dvr->set("time_jitter", sdir->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
// exec
|
|
|
|
if ((dir = vhost->get("exec")) != NULL) {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* ng_exec = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
obj->set("exec", ng_exec);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
ng_exec->set("enabled", SrsJsonAny::boolean(get_exec_enabled(vhost->name)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "publish") {
|
2015-08-29 08:12:30 +00:00
|
|
|
ng_exec->set("publish", sdir->dumps_args());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:51:23 +00:00
|
|
|
// ingest
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* ingests = NULL;
|
2015-08-28 15:51:23 +00:00
|
|
|
for (int i = 0; i < (int)vhost->directives.size(); i++) {
|
|
|
|
dir = vhost->directives.at(i);
|
|
|
|
if (dir->name != "ingest") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ingests) {
|
2015-09-19 04:27:31 +00:00
|
|
|
ingests = SrsJsonAny::array();
|
2015-08-28 15:51:23 +00:00
|
|
|
obj->set("ingests", ingests);
|
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* ingest = SrsJsonAny::object();
|
2015-08-28 15:51:23 +00:00
|
|
|
ingest->set("id", dir->dumps_arg0_to_str());
|
2015-09-19 04:27:31 +00:00
|
|
|
ingest->set("enabled", SrsJsonAny::boolean(get_ingest_enabled(dir)));
|
2015-08-28 15:51:23 +00:00
|
|
|
ingests->append(ingest);
|
|
|
|
|
|
|
|
for (int j = 0; j < (int)dir->directives.size(); j++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(j);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "input") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* input = SrsJsonAny::object();
|
2015-08-28 15:51:23 +00:00
|
|
|
ingest->set("input", input);
|
|
|
|
|
|
|
|
SrsConfDirective* type = sdir->get("type");
|
|
|
|
if (type) {
|
|
|
|
input->set("type", type->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* url = sdir->get("url");
|
|
|
|
if (url) {
|
|
|
|
input->set("url", url->dumps_arg0_to_str());
|
|
|
|
}
|
|
|
|
} else if (sdir->name == "ffmpeg") {
|
|
|
|
ingest->set("ffmpeg", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "engine") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* engine = SrsJsonAny::object();
|
2015-08-28 15:51:23 +00:00
|
|
|
ingest->set("engine", engine);
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "dump engine");
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-29 08:12:30 +00:00
|
|
|
// transcode
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* transcodes = NULL;
|
2015-08-30 06:52:12 +00:00
|
|
|
for (int i = 0; i < (int)vhost->directives.size(); i++) {
|
|
|
|
dir = vhost->directives.at(i);
|
|
|
|
if (dir->name != "transcode") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!transcodes) {
|
2015-09-19 04:27:31 +00:00
|
|
|
transcodes = SrsJsonAny::array();
|
2015-08-30 06:52:12 +00:00
|
|
|
obj->set("transcodes", transcodes);
|
|
|
|
}
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* transcode = SrsJsonAny::object();
|
2015-08-30 06:52:12 +00:00
|
|
|
transcodes->append(transcode);
|
2015-08-28 15:51:23 +00:00
|
|
|
|
2015-08-30 06:52:12 +00:00
|
|
|
transcode->set("apply", dir->dumps_arg0_to_str());
|
2015-09-19 04:27:31 +00:00
|
|
|
transcode->set("enabled", SrsJsonAny::boolean(get_transcode_enabled(dir)));
|
2015-08-30 02:17:39 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonArray* engines = SrsJsonAny::array();
|
2015-08-30 06:52:12 +00:00
|
|
|
transcode->set("engines", engines);
|
2015-08-28 15:51:23 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
|
|
|
SrsConfDirective* sdir = dir->directives.at(i);
|
|
|
|
|
2015-08-30 02:17:39 +00:00
|
|
|
if (sdir->name == "ffmpeg") {
|
2015-08-29 08:12:30 +00:00
|
|
|
transcode->set("ffmpeg", sdir->dumps_arg0_to_str());
|
|
|
|
} else if (sdir->name == "engine") {
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* engine = SrsJsonAny::object();
|
2015-08-29 08:12:30 +00:00
|
|
|
engines->append(engine);
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
if ((err = srs_config_dumps_engine(sdir, engine)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "dump engine");
|
2015-08-29 08:12:30 +00:00
|
|
|
}
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-26 13:11:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_to_json(SrsJsonObject* obj)
|
2015-08-28 04:28:18 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-28 04:28:18 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* sobj = SrsJsonAny::object();
|
2015-08-28 04:28:18 +00:00
|
|
|
obj->set("http_api", sobj);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
sobj->set("enabled", SrsJsonAny::boolean(get_http_api_enabled()));
|
|
|
|
sobj->set("listen", SrsJsonAny::str(get_http_api_listen().c_str()));
|
|
|
|
sobj->set("crossdomain", SrsJsonAny::boolean(get_http_api_crossdomain()));
|
2015-08-28 05:17:46 +00:00
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
SrsJsonObject* ssobj = SrsJsonAny::object();
|
2015-08-28 05:17:46 +00:00
|
|
|
sobj->set("raw_api", ssobj);
|
|
|
|
|
2015-09-19 04:27:31 +00:00
|
|
|
ssobj->set("enabled", SrsJsonAny::boolean(get_raw_api()));
|
|
|
|
ssobj->set("allow_reload", SrsJsonAny::boolean(get_raw_api_allow_reload()));
|
|
|
|
ssobj->set("allow_query", SrsJsonAny::boolean(get_raw_api_allow_query()));
|
|
|
|
ssobj->set("allow_update", SrsJsonAny::boolean(get_raw_api_allow_update()));
|
2015-08-28 15:51:23 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-28 15:51:23 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_listen(const vector<string>& eps, bool& applied)
|
2015-08-30 15:18:14 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-30 15:18:14 +00:00
|
|
|
|
2015-08-31 04:06:22 +00:00
|
|
|
applied = false;
|
|
|
|
|
2015-08-31 15:34:03 +00:00
|
|
|
SrsConfDirective* conf = root->get("listen");
|
2015-08-31 04:06:22 +00:00
|
|
|
|
2017-07-29 13:39:57 +00:00
|
|
|
// nothing changed, ignore.
|
2015-08-31 15:34:03 +00:00
|
|
|
if (srs_vector_actual_equals(conf->args, eps)) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-31 04:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// changed, apply and reload.
|
2015-08-31 15:34:03 +00:00
|
|
|
conf->args = eps;
|
2015-08-30 15:18:14 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_listen()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload listen");
|
2015-08-31 04:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
2015-08-31 15:34:03 +00:00
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_pid(string pid, bool& applied)
|
2015-08-31 15:34:03 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-31 15:34:03 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("pid");
|
|
|
|
|
|
|
|
if (conf->arg0() == pid) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(pid);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_pid()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload pid");
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-08-31 04:06:22 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied)
|
2015-09-01 13:27:04 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-01 13:27:04 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("chunk_size");
|
|
|
|
|
|
|
|
if (conf->arg0() == chunk_size) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-01 13:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(chunk_size);
|
|
|
|
|
|
|
|
// directly supported reload for chunk_size change.
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-01 13:27:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_ff_log_dir(string ff_log_dir, bool& applied)
|
2015-09-09 13:46:29 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 13:46:29 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("ff_log_dir");
|
|
|
|
|
|
|
|
if (conf->arg0() == ff_log_dir) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 13:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(ff_log_dir);
|
|
|
|
|
|
|
|
// directly supported reload for ff_log_dir change.
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 13:46:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_srs_log_tank(string srs_log_tank, bool& applied)
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("srs_log_tank");
|
|
|
|
|
|
|
|
if (conf->arg0() == srs_log_tank) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(srs_log_tank);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_tank()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload log tank");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_srs_log_level(string srs_log_level, bool& applied)
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("srs_log_level");
|
|
|
|
|
|
|
|
if (conf->arg0() == srs_log_level) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(srs_log_level);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_level()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload log level");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_srs_log_file(string srs_log_file, bool& applied)
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("srs_log_file");
|
|
|
|
|
|
|
|
if (conf->arg0() == srs_log_file) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(srs_log_file);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_srs_log_file()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload log file");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_max_connections(string max_connections, bool& applied)
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("max_connections");
|
|
|
|
|
|
|
|
if (conf->arg0() == max_connections) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(max_connections);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_max_connections()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload max connection");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_utc_time(string utc_time, bool& applied)
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("utc_time");
|
|
|
|
|
|
|
|
if (conf->arg0() == utc_time) {
|
2017-07-29 12:02:38 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(utc_time);
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
if ((err = do_reload_utc_time()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "reload");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_set_pithy_print_ms(string pithy_print_ms, bool& applied)
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("pithy_print_ms");
|
|
|
|
|
|
|
|
if (conf->arg0() == pithy_print_ms) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf->args.clear();
|
|
|
|
conf->args.push_back(pithy_print_ms);
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_pithy_print_ms()) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload pithy print");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_create_vhost(string vhost, bool& applied)
|
2015-09-12 13:55:53 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-12 13:55:53 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get_or_create("vhost", vhost);
|
|
|
|
conf->get_or_create("enabled")->set_arg0("on");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_added(vhost)) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload vhost");
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_update_vhost(string vhost, string name, bool& applied)
|
2015-09-15 04:15:18 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 04:15:18 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
// the vhost must be disabled, so we donot need to reload.
|
|
|
|
SrsConfDirective* conf = root->get_or_create("vhost", vhost);
|
|
|
|
conf->set_arg0(name);
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_delete_vhost(string vhost, bool& applied)
|
2015-09-15 04:15:18 +00:00
|
|
|
{
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 04:15:18 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
// the vhost must be disabled, so we donot need to reload.
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
srs_assert(conf);
|
|
|
|
|
|
|
|
// remove the directive.
|
|
|
|
root->remove(conf);
|
|
|
|
srs_freep(conf);
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 04:15:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_disable_vhost(string vhost, bool& applied)
|
2015-09-15 04:51:14 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 04:51:14 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
conf->get_or_create("enabled")->set_arg0("off");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_removed(vhost)) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload vhost removed");
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_enable_vhost(string vhost, bool& applied)
|
2015-09-15 04:51:14 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 04:51:14 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
conf->get_or_create("enabled")->set_arg0("on");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_added(vhost)) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload vhost added");
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_enable_dvr(string vhost, string stream, bool& applied)
|
2015-09-15 15:00:00 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 15:00:00 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
conf = conf->get_or_create("dvr")->get_or_create("dvr_apply");
|
|
|
|
|
|
|
|
if (conf->args.size() == 1 && (conf->arg0() == "all" || conf->arg0() == "none")) {
|
|
|
|
conf->args.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (::find(conf->args.begin(), conf->args.end(), stream) == conf->args.end()) {
|
|
|
|
conf->args.push_back(stream);
|
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload vhost dvr");
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
srs_error_t SrsConfig::raw_disable_dvr(string vhost, string stream, bool& applied)
|
2015-09-15 15:00:00 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 15:00:00 +00:00
|
|
|
|
|
|
|
applied = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("vhost", vhost);
|
|
|
|
conf = conf->get_or_create("dvr")->get_or_create("dvr_apply");
|
|
|
|
|
|
|
|
std::vector<string>::iterator it;
|
|
|
|
|
|
|
|
if ((it = ::find(conf->args.begin(), conf->args.end(), stream)) != conf->args.end()) {
|
|
|
|
conf->args.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->args.empty()) {
|
|
|
|
conf->args.push_back("none");
|
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = do_reload_vhost_dvr_apply(vhost)) != srs_success) {
|
2018-01-01 11:39:57 +00:00
|
|
|
return srs_error_wrap(err, "reload vhost dvr");
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
applied = true;
|
|
|
|
|
2018-01-01 11:39:57 +00:00
|
|
|
return err;
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2015-09-15 15:00:00 +00:00
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_listen()
|
2015-08-31 04:06:22 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-31 04:06:22 +00:00
|
|
|
|
2015-08-30 15:42:21 +00:00
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_listen()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload listen failed");
|
2015-08-30 15:42:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload listen success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-08-30 15:18:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_pid()
|
2015-08-31 15:34:03 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-08-31 15:34:03 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_pid()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload pid failed");
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload pid success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-08-31 15:34:03 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_srs_log_tank()
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_log_tank()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload srs_log_tank failed");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload srs_log_tank success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_srs_log_level()
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_log_level()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload srs_log_level failed");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload srs_log_level success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_srs_log_file()
|
2015-09-09 14:44:34 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 14:44:34 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_log_file()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload srs_log_file failed");
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload srs_log_file success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-09 14:44:34 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_max_connections()
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_max_conns()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes reload max_connections failed");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload max_connections success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_utc_time()
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-07-29 12:02:38 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-07-29 12:02:38 +00:00
|
|
|
if ((err = subscribe->on_reload_utc_time()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "utc_time");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload utc_time success.");
|
|
|
|
|
2017-07-29 12:02:38 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_pithy_print_ms()
|
2015-09-09 15:32:02 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-09 15:32:02 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_pithy_print()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes pithy_print_ms failed");
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload pithy_print_ms success.");
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_vhost_added(string vhost)
|
2015-09-12 13:55:53 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-12 13:55:53 +00:00
|
|
|
|
|
|
|
srs_trace("vhost %s added, reload it.", vhost.c_str());
|
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_added(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes added vhost %s failed", vhost.c_str());
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
srs_trace("reload new vhost %s success.", vhost.c_str());
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-12 13:55:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_vhost_removed(string vhost)
|
2015-09-15 04:51:14 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 04:51:14 +00:00
|
|
|
|
|
|
|
srs_trace("vhost %s removed, reload it.", vhost.c_str());
|
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_removed(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "notify subscribes removed vhost %s failed", vhost.c_str());
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("reload removed vhost %s success.", vhost.c_str());
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-15 04:51:14 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t SrsConfig::do_reload_vhost_dvr_apply(string vhost)
|
2015-09-15 15:00:00 +00:00
|
|
|
{
|
2017-09-22 08:14:30 +00:00
|
|
|
srs_error_t err = srs_success;
|
2015-09-15 15:00:00 +00:00
|
|
|
|
|
|
|
vector<ISrsReloadHandler*>::iterator it;
|
|
|
|
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
|
|
|
ISrsReloadHandler* subscribe = *it;
|
2017-09-22 08:14:30 +00:00
|
|
|
if ((err = subscribe->on_reload_vhost_dvr_apply(vhost)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "vhost %s notify subscribes dvr_apply failed", vhost.c_str());
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_trace("vhost %s reload dvr_apply success.", vhost.c_str());
|
|
|
|
|
2017-09-22 08:14:30 +00:00
|
|
|
return err;
|
2015-09-15 15:00:00 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
string SrsConfig::config()
|
|
|
|
{
|
|
|
|
return config_file;
|
|
|
|
}
|
|
|
|
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_START
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::parse_argv(int& i, char** argv)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
char* p = argv[i];
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (*p++ != '-') {
|
|
|
|
show_help = true;
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*p) {
|
|
|
|
switch (*p++) {
|
|
|
|
case '?':
|
|
|
|
case 'h':
|
|
|
|
show_help = true;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
show_help = false;
|
|
|
|
test_conf = true;
|
|
|
|
break;
|
2015-05-28 06:59:12 +00:00
|
|
|
case 'p':
|
|
|
|
dolphin = true;
|
|
|
|
if (*p) {
|
2015-05-28 13:02:43 +00:00
|
|
|
dolphin_rtmp_port = p;
|
2015-05-28 06:59:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (argv[++i]) {
|
2015-05-28 13:02:43 +00:00
|
|
|
dolphin_rtmp_port = argv[i];
|
2015-05-28 06:59:12 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "-p requires params");
|
2015-05-28 13:02:43 +00:00
|
|
|
case 'x':
|
|
|
|
dolphin = true;
|
|
|
|
if (*p) {
|
|
|
|
dolphin_http_port = p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (argv[++i]) {
|
|
|
|
dolphin_http_port = argv[i];
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "-x requires params");
|
2014-11-11 09:19:56 +00:00
|
|
|
case 'v':
|
|
|
|
case 'V':
|
|
|
|
show_help = false;
|
|
|
|
show_version = true;
|
|
|
|
break;
|
2016-01-04 09:28:18 +00:00
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
show_help = false;
|
|
|
|
show_signature = true;
|
|
|
|
break;
|
2014-11-11 09:19:56 +00:00
|
|
|
case 'c':
|
|
|
|
show_help = false;
|
|
|
|
if (*p) {
|
|
|
|
config_file = p;
|
2015-05-28 06:59:12 +00:00
|
|
|
continue;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
if (argv[++i]) {
|
|
|
|
config_file = argv[i];
|
2015-05-28 06:59:12 +00:00
|
|
|
continue;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "-c requires params");
|
2014-11-11 09:19:56 +00:00
|
|
|
default:
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "invalid option: \"%c\", read help: %s -h",
|
|
|
|
*(p - 1), argv[0]);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SrsConfig::print_help(char** argv)
|
|
|
|
{
|
|
|
|
printf(
|
2019-04-30 00:53:51 +00:00
|
|
|
RTMP_SIG_SRS_SERVER ", " RTMP_SIG_SRS_URL ", licensed under " RTMP_SIG_SRS_LICENSE
|
|
|
|
", built at " SRS_AUTO_BUILD_DATE ", configured by " SRS_AUTO_USER_CONFIGURE
|
|
|
|
", which means " SRS_AUTO_CONFIGURE "\n""\n"
|
2019-04-30 01:15:06 +00:00
|
|
|
"Usage: %s <-h?vVgG>|<[-t] -c filename>\n"
|
2017-03-25 09:21:39 +00:00
|
|
|
"Options:\n"
|
2019-04-30 01:15:06 +00:00
|
|
|
" -?, -h : Show this help and exit 0.\n"
|
|
|
|
" -v, -V : Show version and exit 0.\n"
|
|
|
|
" -g, -G : Show server signature and exit 0.\n"
|
|
|
|
" -t : Test configuration file, exit with error code(0 for success).\n"
|
|
|
|
" -c filename : Use config file to start server.\n"
|
2017-03-25 09:21:39 +00:00
|
|
|
"For example:\n"
|
|
|
|
" %s -v\n"
|
2017-05-06 06:05:22 +00:00
|
|
|
" %s -t -c " SRS_CONF_DEFAULT_COFNIG_FILE "\n"
|
|
|
|
" %s -c " SRS_CONF_DEFAULT_COFNIG_FILE "\n",
|
2017-03-25 09:21:39 +00:00
|
|
|
argv[0], argv[0], argv[0], argv[0]);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::parse_file(const char* filename)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
config_file = filename;
|
|
|
|
|
|
|
|
if (config_file.empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "empty config");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfigBuffer buffer;
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = buffer.fullfill(config_file.c_str())) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "buffer fullfil");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = parse_buffer(&buffer)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "parse buffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::check_config()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = check_normal_config()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "check normal");
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = check_number_connections()) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "check connections");
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::check_normal_config()
|
2017-03-26 06:25:08 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-03-26 06:25:08 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
srs_trace("srs checking config...");
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check empty
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (root->directives.size() == 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "conf is empty");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-03 06:11:21 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check root directives.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = root->at(i);
|
|
|
|
std::string n = conf->name;
|
2017-03-25 09:21:39 +00:00
|
|
|
if (n != "listen" && n != "pid" && n != "chunk_size" && n != "ff_log_dir"
|
2015-08-03 06:11:21 +00:00
|
|
|
&& n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
|
|
|
|
&& n != "max_connections" && n != "daemon" && n != "heartbeat"
|
|
|
|
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
|
2019-10-03 04:45:38 +00:00
|
|
|
&& n != "http_server" && n != "stream_caster"
|
2016-09-23 07:00:50 +00:00
|
|
|
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
|
2020-02-18 11:59:47 +00:00
|
|
|
&& n != "ff_log_level" && n != "grace_final_wait"
|
2017-03-25 09:21:39 +00:00
|
|
|
) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
2015-08-29 10:40:18 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
2015-08-03 06:11:21 +00:00
|
|
|
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
2015-08-28 04:28:18 +00:00
|
|
|
SrsConfDirective* obj = conf->at(i);
|
|
|
|
string n = obj->name;
|
2015-08-27 10:11:50 +00:00
|
|
|
if (n != "enabled" && n != "listen" && n != "crossdomain" && n != "raw_api") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal http_api.%s", n.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2015-08-28 04:28:18 +00:00
|
|
|
|
|
|
|
if (n == "raw_api") {
|
|
|
|
for (int j = 0; j < (int)obj->directives.size(); j++) {
|
|
|
|
string m = obj->at(j)->name;
|
2015-08-30 15:08:27 +00:00
|
|
|
if (m != "enabled" && m != "allow_reload" && m != "allow_query" && m != "allow_update") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal http_api.raw_api.%s", m.c_str());
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
2015-08-29 10:40:18 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_server");
|
2015-08-03 06:11:21 +00:00
|
|
|
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
|
|
|
string n = conf->at(i)->name;
|
2016-12-15 08:22:04 +00:00
|
|
|
if (n != "enabled" && n != "listen" && n != "dir" && n != "crossdomain") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal http_stream.%s", n.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
|
|
|
string n = conf->at(i)->name;
|
|
|
|
if (n != "enabled" && n != "interval" && n != "url"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& n != "device_id" && n != "summaries") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal heartbeat.%s", n.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
SrsConfDirective* conf = get_stats();
|
|
|
|
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
|
|
|
string n = conf->at(i)->name;
|
|
|
|
if (n != "network" && n != "disk") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal stats.%s", n.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check listen for rtmp.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (true) {
|
|
|
|
vector<string> listens = get_listens();
|
|
|
|
if (listens.size() <= 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "listen requires params");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < (int)listens.size(); i++) {
|
|
|
|
string port = listens[i];
|
|
|
|
if (port.empty() || ::atoi(port.c_str()) <= 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "listen.port=%d is invalid", port.c_str());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check heartbeat
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (get_heartbeat_interval() <= 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "invalid heartbeat.interval=%" PRId64,
|
|
|
|
get_heartbeat_interval());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-08-03 06:11:21 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check stats
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (get_stats_network() < 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "invalid stats.network=%d", get_stats_network());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
if (true) {
|
2017-10-14 03:29:33 +00:00
|
|
|
vector<std::string> ips = srs_get_local_ips();
|
2015-08-03 06:11:21 +00:00
|
|
|
int index = get_stats_network();
|
|
|
|
if (index >= (int)ips.size()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "invalid stats.network=%d of %d",
|
|
|
|
index, (int)ips.size());
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
srs_warn("stats network use index=%d, ip=%s", index, ips.at(index).c_str());
|
|
|
|
}
|
|
|
|
if (true) {
|
|
|
|
SrsConfDirective* conf = get_stats_disk_device();
|
|
|
|
if (conf == NULL || (int)conf->args.size() <= 0) {
|
|
|
|
srs_warn("stats disk not configed, disk iops disabled.");
|
|
|
|
} else {
|
|
|
|
string disks;
|
|
|
|
for (int i = 0; i < (int)conf->args.size(); i++) {
|
|
|
|
disks += conf->args.at(i);
|
|
|
|
disks += " ";
|
|
|
|
}
|
|
|
|
srs_warn("stats disk list: %s", disks.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check http api
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (get_http_api_listen().empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "http_api.listen requires params");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check http stream
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (get_http_stream_listen().empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "http_stream.listen requires params");
|
2015-08-03 06:11:21 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2015-08-03 06:11:21 +00:00
|
|
|
// check log name and level
|
2014-11-11 09:19:56 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2015-08-03 06:11:21 +00:00
|
|
|
if (true) {
|
|
|
|
std::string log_filename = this->get_log_file();
|
|
|
|
if (get_log_tank_file() && log_filename.empty()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "log file is empty");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-03 06:11:21 +00:00
|
|
|
if (get_log_tank_file()) {
|
|
|
|
srs_trace("write log to file %s", log_filename.c_str());
|
|
|
|
srs_trace("you can: tailf %s", log_filename.c_str());
|
|
|
|
srs_trace("@see: %s", SRS_WIKI_URL_LOG);
|
|
|
|
} else {
|
|
|
|
srs_trace("write log to console");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-03 06:11:21 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check features
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
vector<SrsConfDirective*> stream_casters = get_stream_casters();
|
2015-01-24 06:52:52 +00:00
|
|
|
for (int n = 0; n < (int)stream_casters.size(); n++) {
|
|
|
|
SrsConfDirective* stream_caster = stream_casters[n];
|
|
|
|
for (int i = 0; stream_caster && i < (int)stream_caster->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = stream_caster->at(i);
|
|
|
|
string n = conf->name;
|
|
|
|
if (n != "enabled" && n != "caster" && n != "output"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& n != "listen" && n != "rtp_port_min" && n != "rtp_port_max") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal stream_caster.%s", n.c_str());
|
2015-01-24 06:52:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check vhosts.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2015-08-03 06:11:21 +00:00
|
|
|
vector<SrsConfDirective*> vhosts;
|
|
|
|
get_vhosts(vhosts);
|
2014-11-11 09:19:56 +00:00
|
|
|
for (int n = 0; n < (int)vhosts.size(); n++) {
|
|
|
|
SrsConfDirective* vhost = vhosts[n];
|
|
|
|
for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = vhost->at(i);
|
|
|
|
string n = conf->name;
|
2015-08-29 22:49:20 +00:00
|
|
|
if (n != "enabled" && n != "chunk_size" && n != "min_latency" && n != "tcp_nodelay"
|
2015-01-22 01:34:33 +00:00
|
|
|
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
|
2015-08-29 10:40:18 +00:00
|
|
|
&& n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
|
2015-08-30 00:30:04 +00:00
|
|
|
&& n != "play" && n != "publish" && n != "cluster"
|
2017-02-11 13:14:28 +00:00
|
|
|
&& n != "security" && n != "http_remux" && n != "dash"
|
2015-08-29 10:40:18 +00:00
|
|
|
&& n != "http_static" && n != "hds" && n != "exec"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& n != "in_ack_size" && n != "out_ack_size") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.%s", n.c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
// for each sub directives of vhost.
|
|
|
|
if (n == "dvr") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-09-15 07:58:57 +00:00
|
|
|
if (m != "enabled" && m != "dvr_apply" && m != "dvr_path" && m != "dvr_plan"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& m != "dvr_duration" && m != "dvr_wait_keyframe" && m != "time_jitter") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.dvr.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 10:40:18 +00:00
|
|
|
} else if (n == "refer") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-08-29 10:40:18 +00:00
|
|
|
if (m != "enabled" && m != "all" && m != "publish" && m != "play") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.refer.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-08-29 10:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-25 14:29:00 +00:00
|
|
|
} else if (n == "exec") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-08-25 14:29:00 +00:00
|
|
|
if (m != "enabled" && m != "publish") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.exec.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 15:18:25 +00:00
|
|
|
} else if (n == "play") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-08-29 23:36:06 +00:00
|
|
|
if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto" && m != "mw_latency"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& m != "gop_cache" && m != "queue_length" && m != "send_min_interval" && m != "reduce_sequence_header") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.play.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-08-29 15:18:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-30 00:30:04 +00:00
|
|
|
} else if (n == "cluster") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2018-02-16 02:31:19 +00:00
|
|
|
if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode" && m != "coworkers"
|
|
|
|
&& m != "origin_cluster") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.cluster.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-08-30 00:30:04 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 14:41:50 +00:00
|
|
|
} else if (n == "publish") {
|
2014-12-04 10:21:04 +00:00
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-09-14 10:42:31 +00:00
|
|
|
if (m != "mr" && m != "mr_latency" && m != "firstpkt_timeout" && m != "normal_timeout" && m != "parse_sps") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.publish.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
} else if (n == "ingest") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-08-25 14:29:00 +00:00
|
|
|
if (m != "enabled" && m != "input" && m != "ffmpeg" && m != "engine") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.ingest.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 10:40:18 +00:00
|
|
|
} else if (n == "http_static") {
|
2014-11-11 09:19:56 +00:00
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2014-11-11 09:19:56 +00:00
|
|
|
if (m != "enabled" && m != "mount" && m != "dir") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.http_static.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-22 01:34:33 +00:00
|
|
|
} else if (n == "http_remux") {
|
2015-01-18 10:00:40 +00:00
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2017-01-05 01:08:56 +00:00
|
|
|
if (m != "enabled" && m != "mount" && m != "fast_cache") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.http_remux.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-11 13:14:28 +00:00
|
|
|
} else if (n == "dash") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
|
|
|
string m = conf->at(j)->name;
|
2017-02-26 12:40:33 +00:00
|
|
|
if (m != "enabled" && m != "dash_fragment" && m != "dash_update_period" && m != "dash_timeshift" && m != "dash_path"
|
|
|
|
&& m != "dash_mpd_file") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.dash.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2017-02-11 13:14:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
} else if (n == "hls") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-03-12 16:22:55 +00:00
|
|
|
if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
|
2015-03-19 09:24:27 +00:00
|
|
|
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
|
2015-05-30 02:48:02 +00:00
|
|
|
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
|
2018-03-25 04:05:52 +00:00
|
|
|
&& m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_keys" && m != "hls_fragments_per_key" && m != "hls_key_file"
|
2019-12-05 12:47:23 +00:00
|
|
|
&& m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.hls.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2016-12-15 06:54:09 +00:00
|
|
|
|
|
|
|
// TODO: FIXME: remove it in future.
|
|
|
|
if (m == "hls_storage" || m == "hls_mount") {
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_warn("HLS RAM is removed in SRS3+, read https://github.com/ossrs/srs/issues/513.");
|
2016-12-15 06:54:09 +00:00
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
} else if (n == "http_hooks") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2014-11-11 09:19:56 +00:00
|
|
|
if (m != "enabled" && m != "on_connect" && m != "on_close" && m != "on_publish"
|
|
|
|
&& m != "on_unpublish" && m != "on_play" && m != "on_stop"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& m != "on_dvr" && m != "on_hls" && m != "on_hls_notify") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.http_hooks.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (n == "forward") {
|
2015-08-29 23:59:25 +00:00
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2015-08-29 23:59:25 +00:00
|
|
|
if (m != "enabled" && m != "destination") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.forward.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-29 23:59:25 +00:00
|
|
|
}
|
2015-01-02 08:02:13 +00:00
|
|
|
} else if (n == "security") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
|
|
|
SrsConfDirective* security = conf->at(j);
|
|
|
|
string m = security->name.c_str();
|
|
|
|
if (m != "enabled" && m != "deny" && m != "allow") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.security.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
} else if (n == "transcode") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
|
|
|
SrsConfDirective* trans = conf->at(j);
|
|
|
|
string m = trans->name.c_str();
|
|
|
|
if (m != "enabled" && m != "ffmpeg" && m != "engine") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.transcode.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
if (m == "engine") {
|
|
|
|
for (int k = 0; k < (int)trans->directives.size(); k++) {
|
|
|
|
string e = trans->at(k)->name;
|
|
|
|
if (e != "enabled" && e != "vfilter" && e != "vcodec"
|
|
|
|
&& e != "vbitrate" && e != "vfps" && e != "vwidth" && e != "vheight"
|
|
|
|
&& e != "vthreads" && e != "vprofile" && e != "vpreset" && e != "vparams"
|
|
|
|
&& e != "acodec" && e != "abitrate" && e != "asample_rate" && e != "achannels"
|
2017-01-06 02:39:37 +00:00
|
|
|
&& e != "aparams" && e != "output" && e != "perfile"
|
2017-06-11 06:03:19 +00:00
|
|
|
&& e != "iformat" && e != "oformat") {
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.transcode.engine.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (n == "bandcheck") {
|
|
|
|
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
2017-02-11 13:14:28 +00:00
|
|
|
string m = conf->at(j)->name;
|
2014-11-11 09:19:56 +00:00
|
|
|
if (m != "enabled" && m != "key" && m != "interval" && m != "limit_kbps") {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.bandcheck.%s of %s", m.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check ingest id unique.
|
|
|
|
for (int i = 0; i < (int)vhosts.size(); i++) {
|
|
|
|
SrsConfDirective* vhost = vhosts[i];
|
|
|
|
std::vector<std::string> ids;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
for (int j = 0; j < (int)vhost->directives.size(); j++) {
|
|
|
|
SrsConfDirective* conf = vhost->at(j);
|
|
|
|
if (conf->name != "ingest") {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
std::string id = conf->arg0();
|
|
|
|
for (int k = 0; k < (int)ids.size(); k++) {
|
|
|
|
if (id == ids.at(k)) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "ingest id=%s exists for %s",
|
|
|
|
id.c_str(), vhost->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ids.push_back(id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check chunk size
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2017-03-25 09:21:39 +00:00
|
|
|
if (get_global_chunk_size() < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
|
2017-06-11 06:03:19 +00:00
|
|
|
|| get_global_chunk_size() > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE) {
|
|
|
|
srs_warn("chunk_size=%s should be in [%d, %d]", get_global_chunk_size(),
|
|
|
|
SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, SRS_CONSTS_RTMP_MAX_CHUNK_SIZE);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < (int)vhosts.size(); i++) {
|
|
|
|
SrsConfDirective* vhost = vhosts[i];
|
2017-03-25 09:21:39 +00:00
|
|
|
if (get_chunk_size(vhost->arg0()) < SRS_CONSTS_RTMP_MIN_CHUNK_SIZE
|
2017-06-11 06:03:19 +00:00
|
|
|
|| get_chunk_size(vhost->arg0()) > SRS_CONSTS_RTMP_MAX_CHUNK_SIZE) {
|
|
|
|
srs_warn("chunk_size=%s of %s should be in [%d, %d]", get_global_chunk_size(), vhost->arg0().c_str(),
|
|
|
|
SRS_CONSTS_RTMP_MIN_CHUNK_SIZE, SRS_CONSTS_RTMP_MAX_CHUNK_SIZE);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2016-09-23 07:00:50 +00:00
|
|
|
// asprocess conflict with daemon
|
2019-05-06 23:46:20 +00:00
|
|
|
if (get_asprocess() && get_daemon()) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "daemon conflicts with asprocess");
|
2016-09-23 07:00:50 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2015-02-17 08:28:28 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_START
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::check_number_connections()
|
2017-03-26 06:25:08 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2017-03-26 06:25:08 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// check max connections
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
if (get_max_connections() <= 0) {
|
2017-06-11 06:03:19 +00:00
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "max_connections=%d is invalid", get_max_connections());
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check max connections of system limits
|
|
|
|
if (true) {
|
|
|
|
int nb_consumed_fds = (int)get_listens().size();
|
|
|
|
if (!get_http_api_listen().empty()) {
|
|
|
|
nb_consumed_fds++;
|
|
|
|
}
|
|
|
|
if (!get_http_stream_listen().empty()) {
|
|
|
|
nb_consumed_fds++;
|
|
|
|
}
|
|
|
|
if (get_log_tank_file()) {
|
|
|
|
nb_consumed_fds++;
|
|
|
|
}
|
|
|
|
// 0, 1, 2 for stdin, stdout and stderr.
|
|
|
|
nb_consumed_fds += 3;
|
|
|
|
|
|
|
|
int nb_connections = get_max_connections();
|
|
|
|
int nb_total = nb_connections + nb_consumed_fds;
|
|
|
|
|
|
|
|
int max_open_files = (int)sysconf(_SC_OPEN_MAX);
|
|
|
|
int nb_canbe = max_open_files - nb_consumed_fds - 1;
|
|
|
|
|
|
|
|
// for each play connections, we open a pipe(2fds) to convert SrsConsumver to io,
|
|
|
|
// refine performance, @see: https://github.com/ossrs/srs/issues/194
|
|
|
|
if (nb_total >= max_open_files) {
|
|
|
|
srs_error("invalid max_connections=%d, required=%d, system limit to %d, "
|
2017-06-11 06:03:19 +00:00
|
|
|
"total=%d(max_connections=%d, nb_consumed_fds=%d). "
|
2017-03-26 06:25:08 +00:00
|
|
|
"you can change max_connections from %d to %d, or "
|
|
|
|
"you can login as root and set the limit: ulimit -HSn %d",
|
|
|
|
nb_connections, nb_total + 100, max_open_files,
|
|
|
|
nb_total, nb_connections, nb_consumed_fds,
|
2017-06-11 06:03:19 +00:00
|
|
|
nb_connections, nb_canbe, nb_total + 100);
|
|
|
|
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "%d exceed max open files=%d",
|
|
|
|
nb_total, max_open_files);
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2017-03-26 06:25:08 +00:00
|
|
|
}
|
2020-01-01 06:21:24 +00:00
|
|
|
// LCOV_EXCL_STOP
|
2017-03-26 06:25:08 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
|
2015-02-17 08:28:28 +00:00
|
|
|
{
|
2017-06-11 06:03:19 +00:00
|
|
|
srs_error_t err = srs_success;
|
2019-04-08 00:31:58 +00:00
|
|
|
|
2020-01-01 09:14:59 +00:00
|
|
|
// We use a new root to parse buffer, to allow parse multiple times.
|
2019-04-08 00:31:58 +00:00
|
|
|
srs_freep(root);
|
|
|
|
root = new SrsConfDirective();
|
|
|
|
|
|
|
|
// Parse root tree from buffer.
|
2017-06-11 06:03:19 +00:00
|
|
|
if ((err = root->parse(buffer)) != srs_success) {
|
|
|
|
return srs_error_wrap(err, "root parse");
|
2015-02-17 08:28:28 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
// mock by dolphin mode.
|
|
|
|
// for the dolphin will start srs with specified params.
|
|
|
|
if (dolphin) {
|
|
|
|
// for RTMP.
|
|
|
|
set_config_directive(root, "listen", dolphin_rtmp_port);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
// for HTTP
|
|
|
|
set_config_directive(root, "http_server", "");
|
|
|
|
SrsConfDirective* http_server = root->get("http_server");
|
|
|
|
set_config_directive(http_server, "enabled", "on");
|
|
|
|
set_config_directive(http_server, "listen", dolphin_http_port);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
// others.
|
|
|
|
set_config_directive(root, "daemon", "off");
|
|
|
|
set_config_directive(root, "srs_log_tank", "console");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2017-06-11 06:03:19 +00:00
|
|
|
return err;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::cwd()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return _cwd;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::argv()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return _argv;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 23:46:20 +00:00
|
|
|
bool SrsConfig::get_daemon()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("daemon");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return true;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_root()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
return root;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_max_connections()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 1000;
|
2015-08-30 00:30:04 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("max_connections");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> SrsConfig::get_listens()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
std::vector<string> ports;
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("listen");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return ports;
|
2015-08-29 15:36:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->args.size(); i++) {
|
|
|
|
ports.push_back(conf->args.at(i));
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ports;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_pid_file()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/srs.pid";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("pid");
|
2015-08-29 15:36:03 +00:00
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:55:54 +00:00
|
|
|
srs_utime_t SrsConfig::get_pithy_print()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-09 00:55:54 +00:00
|
|
|
static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS;
|
2015-08-29 15:18:25 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("pithy_print_ms");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:55:54 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_utc_time()
|
2015-04-15 09:12:22 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-04-15 09:12:22 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("utc_time");
|
2015-04-15 09:12:22 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-15 09:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2016-01-08 05:58:19 +00:00
|
|
|
string SrsConfig::get_work_dir() {
|
2016-12-08 09:26:04 +00:00
|
|
|
static string DEFAULT = "./";
|
2016-09-23 06:53:58 +00:00
|
|
|
|
2016-01-08 05:58:19 +00:00
|
|
|
SrsConfDirective* conf = root->get("work_dir");
|
|
|
|
if( !conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2016-01-08 05:58:19 +00:00
|
|
|
return conf->arg0();
|
2016-09-23 06:53:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 07:00:50 +00:00
|
|
|
bool SrsConfig::get_asprocess()
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("asprocess");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2016-01-08 05:58:19 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 11:59:47 +00:00
|
|
|
srs_utime_t SrsConfig::get_grace_final_wait()
|
|
|
|
{
|
|
|
|
static srs_utime_t DEFAULT = 3200 * SRS_UTIME_MILLISECONDS;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("grace_final_wait");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (srs_utime_t)(::atol(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> SrsConfig::get_stream_casters()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
srs_assert(root);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
std::vector<SrsConfDirective*> stream_casters;
|
2015-08-29 23:26:55 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = root->at(i);
|
|
|
|
|
|
|
|
if (!conf->is_stream_caster()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream_casters.push_back(conf);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return stream_casters;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_stream_caster_enabled(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 10:40:18 +00:00
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_stream_caster_engine(SrsConfDirective* conf)
|
2015-08-29 10:40:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("caster");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_stream_caster_output(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("output");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_stream_caster_listen(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("listen");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_stream_caster_rtp_port_min(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
conf = conf->get("rtp_port_min");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_stream_caster_rtp_port_max(SrsConfDirective* conf)
|
2015-09-14 10:36:44 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2015-09-14 10:36:44 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("rtp_port_max");
|
2015-09-14 10:36:44 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2015-09-14 10:36:44 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
|
2014-12-04 10:21:04 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
srs_assert(root);
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = root->at(i);
|
|
|
|
|
|
|
|
if (!conf->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conf->arg0() == vhost) {
|
|
|
|
return conf;
|
|
|
|
}
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
if (try_default_vhost && vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
|
|
|
return get_vhost(SRS_CONSTS_RTMP_DEFAULT_VHOST);
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
2015-04-07 09:42:41 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
void SrsConfig::get_vhosts(vector<SrsConfDirective*>& vhosts)
|
2014-12-04 10:21:04 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
srs_assert(root);
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)root->directives.size(); i++) {
|
|
|
|
SrsConfDirective* conf = root->at(i);
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!conf->is_vhost()) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vhosts.push_back(conf);
|
|
|
|
}
|
2014-12-04 13:35:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_enabled(string vhost)
|
2014-12-04 13:35:13 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
return get_vhost_enabled(conf);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_vhost_enabled(SrsConfDirective* conf)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = true;
|
|
|
|
|
|
|
|
// false for NULL vhost.
|
2014-12-04 13:35:13 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return false;
|
2014-12-04 13:35:13 +00:00
|
|
|
}
|
2015-08-29 23:05:57 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
// perfer true for exists one.
|
|
|
|
conf = conf->get("enabled");
|
2014-12-04 13:35:13 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2014-12-04 10:21:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_gop_cache(string vhost)
|
2014-12-12 13:51:06 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_GOP_CACHE;
|
2014-12-12 13:51:06 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_GOP_CACHE;
|
2014-12-12 13:51:06 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
conf = conf->get("gop_cache");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return SRS_PERF_GOP_CACHE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2014-12-12 13:51:06 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_debug_srs_upnode(string vhost)
|
2015-08-12 05:22:09 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2015-08-12 05:22:09 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("cluster");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-08-12 05:22:09 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("debug_srs_upnode");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2015-08-12 05:22:09 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_atc(string vhost)
|
2015-08-14 03:13:40 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-08-14 03:13:40 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-08-29 23:36:06 +00:00
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-08-29 23:36:06 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("atc");
|
2015-08-14 03:13:40 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-08-14 03:13:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_atc_auto(string vhost)
|
2015-08-14 06:35:41 +00:00
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-08-29 23:36:06 +00:00
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-08-29 23:36:06 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("atc_auto");
|
2015-08-14 06:35:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_time_jitter(string vhost)
|
2015-08-19 08:16:05 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "full";
|
2015-08-19 08:16:05 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(DEFAULT);
|
2015-08-19 08:16:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(DEFAULT);
|
2015-08-29 14:41:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("time_jitter");
|
2015-08-19 08:16:05 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(DEFAULT);
|
2015-08-19 08:16:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(conf->arg0());
|
2015-08-19 08:16:05 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_mix_correct(string vhost)
|
2015-08-19 08:16:05 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-08-19 08:16:05 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-08-29 14:41:50 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mix_correct");
|
2015-08-19 08:16:05 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-08-19 08:16:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:55:19 +00:00
|
|
|
srs_utime_t SrsConfig::get_queue_length(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-15 23:55:19 +00:00
|
|
|
static srs_utime_t DEFAULT = SRS_PERF_PLAY_QUEUE;
|
2015-12-29 10:33:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-12-29 10:33:02 +00:00
|
|
|
return DEFAULT;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2015-12-29 10:33:02 +00:00
|
|
|
return DEFAULT;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("queue_length");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-12-29 10:33:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:55:19 +00:00
|
|
|
return srs_utime_t(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_refer_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 23:59:25 +00:00
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 23:59:25 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("refer");
|
2015-08-29 23:59:25 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_refer_all(string vhost)
|
2015-08-29 23:59:25 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static SrsConfDirective* DEFAULT = NULL;
|
|
|
|
|
2015-08-29 23:59:25 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-08-29 23:59:25 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("refer");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("all");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_refer_play(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static SrsConfDirective* DEFAULT = NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("refer");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("play");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_refer_publish(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static SrsConfDirective* DEFAULT = NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("refer");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("publish");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-06 06:57:54 +00:00
|
|
|
int SrsConfig::get_in_ack_size(string vhost)
|
|
|
|
{
|
|
|
|
static int DEFAULT = 0;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("in_ack_size");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrsConfig::get_out_ack_size(string vhost)
|
|
|
|
{
|
|
|
|
static int DEFAULT = 2500000;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("out_ack_size");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_chunk_size(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
if (vhost.empty()) {
|
|
|
|
return get_global_chunk_size();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
// vhost does not specify the chunk size,
|
|
|
|
// use the global instead.
|
|
|
|
return get_global_chunk_size();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("chunk_size");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
// vhost does not specify the chunk size,
|
|
|
|
// use the global instead.
|
|
|
|
return get_global_chunk_size();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_parse_sps(string vhost)
|
2015-01-03 07:33:23 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
|
2015-03-31 09:42:12 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-01-03 07:33:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("publish");
|
2015-03-31 09:42:12 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-03-31 09:42:12 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("parse_sps");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-04-10 04:01:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2015-04-10 04:01:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_mr_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_MR_ENABLED;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("publish");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_MR_ENABLED;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mr");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_MR_ENABLED;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-04-07 09:42:41 +00:00
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 01:20:44 +00:00
|
|
|
srs_utime_t SrsConfig::get_mr_sleep(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2020-01-01 09:14:59 +00:00
|
|
|
static srs_utime_t DEFAULT = SRS_PERF_MR_SLEEP;
|
2019-04-09 01:20:44 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2019-04-09 01:20:44 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("publish");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2019-04-09 01:20:44 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mr_latency");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2019-04-09 01:20:44 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2019-04-09 01:20:44 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 01:39:16 +00:00
|
|
|
srs_utime_t SrsConfig::get_mw_sleep(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2020-01-01 09:14:59 +00:00
|
|
|
static srs_utime_t DEFAULT = SRS_PERF_MW_SLEEP;
|
2019-04-09 01:39:16 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2019-04-09 01:39:16 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("play");
|
2017-02-05 01:15:46 +00:00
|
|
|
if (!conf) {
|
2019-04-09 01:39:16 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mw_latency");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2019-04-09 01:39:16 +00:00
|
|
|
return DEFAULT;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2019-04-09 01:39:16 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_realtime_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_PERF_MIN_LATENCY_ENABLED;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("min_latency");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return SRS_PERF_MIN_LATENCY_ENABLED;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_tcp_nodelay(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-07-23 06:20:46 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-07-23 06:20:46 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-30 00:30:04 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("tcp_nodelay");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-07-23 06:20:46 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 23:59:27 +00:00
|
|
|
srs_utime_t SrsConfig::get_send_min_interval(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-15 23:59:27 +00:00
|
|
|
static srs_utime_t DEFAULT = 0;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("play");
|
2015-10-28 04:55:16 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-08-30 00:30:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("send_min_interval");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:59:27 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_reduce_sequence_header(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("play");
|
2015-10-28 04:55:16 +00:00
|
|
|
if (!conf) {
|
2015-08-30 00:30:04 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("reduce_sequence_header");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:53:09 +00:00
|
|
|
srs_utime_t SrsConfig::get_publish_1stpkt_timeout(string vhost)
|
2015-04-03 02:56:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
// when no msg recevied for publisher, use larger timeout.
|
2019-04-09 23:53:09 +00:00
|
|
|
static srs_utime_t DEFAULT = 20 * SRS_UTIME_SECONDS;
|
2015-04-03 02:56:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-04-03 02:56:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-03 02:56:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("publish");
|
|
|
|
if (!conf) {
|
2015-08-30 00:30:04 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("firstpkt_timeout");
|
2015-04-03 02:56:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-03 02:56:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:53:09 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2015-04-03 02:56:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:58:39 +00:00
|
|
|
srs_utime_t SrsConfig::get_publish_normal_timeout(string vhost)
|
2015-01-02 08:02:13 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
// the timeout for publish recv.
|
|
|
|
// we must use more smaller timeout, for the recv never know the status
|
|
|
|
// of underlayer socket.
|
2019-04-09 23:58:39 +00:00
|
|
|
static srs_utime_t DEFAULT = 5 * SRS_UTIME_SECONDS;
|
2015-01-02 08:02:13 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-01-02 08:02:13 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("publish");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("normal_timeout");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 23:58:39 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS);
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_global_chunk_size()
|
2015-01-02 08:02:13 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("chunk_size");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return SRS_CONSTS_RTMP_SRS_CHUNK_SIZE;
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2015-01-02 08:02:13 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_forward_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("forward");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_forwards(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2015-08-29 11:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("forward");
|
|
|
|
if (!conf) {
|
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("destination");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("http_hooks");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_http_hooks_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_connect(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2015-08-29 11:46:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_connect");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_close(string vhost)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_close");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_publish(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_publish");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_unpublish(string vhost)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_unpublish");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_play(string vhost)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_play");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_stop(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_stop");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_dvr(string vhost)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_dvr");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_hls(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_hls");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost_http_hooks(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("on_hls_notify");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_bw_check_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("bandcheck");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-07-21 04:07:26 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_bw_check_key(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("bandcheck");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("key");
|
2015-07-21 04:07:26 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 00:46:22 +00:00
|
|
|
srs_utime_t SrsConfig::get_bw_check_interval(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-08 00:46:22 +00:00
|
|
|
static int64_t DEFAULT = 30 * SRS_UTIME_SECONDS;
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("bandcheck");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("interval");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2019-04-08 00:46:22 +00:00
|
|
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_bw_check_limit_kbps(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 1000;
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("bandcheck");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("limit_kbps");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_is_edge(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
return get_vhost_is_edge(conf);
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = vhost;
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("cluster");
|
2015-12-04 07:22:13 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mode");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return "remote" == conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("cluster");
|
2015-12-04 07:22:13 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("origin");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("cluster");
|
2015-12-04 07:22:13 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("token_traverse");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_vhost_edge_transform_vhost(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "[vhost]";
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("cluster");
|
2015-12-04 07:22:13 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vhost");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:31:19 +00:00
|
|
|
bool SrsConfig::get_vhost_origin_cluster(string vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("cluster");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("origin_cluster");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2018-02-14 13:52:40 +00:00
|
|
|
vector<string> SrsConfig::get_vhost_coworkers(string vhost)
|
|
|
|
{
|
|
|
|
vector<string> coworkers;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return coworkers;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("cluster");
|
|
|
|
if (!conf) {
|
|
|
|
return coworkers;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("coworkers");
|
2018-02-16 08:39:07 +00:00
|
|
|
for (int i = 0; i < (int)conf->args.size(); i++) {
|
|
|
|
coworkers.push_back(conf->args.at(i));
|
2018-02-14 13:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return coworkers;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_security_enabled(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-07-21 04:07:26 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-07-21 04:07:26 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* security = conf->get("security");
|
|
|
|
if (!security) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = security->get("enabled");
|
2015-07-21 04:07:26 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_security_rules(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("security");
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_transcode(string vhost, string scope)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("transcode");
|
|
|
|
if (!conf || conf->arg0() != scope) {
|
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_transcode_enabled(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_transcode_ffmpeg(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static string DEFAULT = "";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("ffmpeg");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> SrsConfig::get_transcode_engines(SrsConfDirective* conf)
|
2015-08-25 14:29:00 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> engines;
|
|
|
|
|
2015-08-25 14:29:00 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return engines;
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* engine = conf->directives[i];
|
|
|
|
|
|
|
|
if (engine->name == "engine") {
|
|
|
|
engines.push_back(engine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return engines;
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_engine_enabled(SrsConfDirective* conf)
|
2015-08-25 14:29:00 +00:00
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2017-01-06 02:39:37 +00:00
|
|
|
string srs_prefix_underscores_ifno(string name)
|
|
|
|
{
|
|
|
|
if (srs_string_starts_with(name, "-")) {
|
|
|
|
return name;
|
|
|
|
} else {
|
|
|
|
return "-" + name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string> SrsConfig::get_engine_perfile(SrsConfDirective* conf)
|
|
|
|
{
|
|
|
|
vector<string> perfile;
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
return perfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("perfile");
|
|
|
|
if (!conf) {
|
|
|
|
return perfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* option = conf->directives[i];
|
|
|
|
if (!option) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
perfile.push_back(srs_prefix_underscores_ifno(option->name));
|
2020-01-01 13:01:14 +00:00
|
|
|
if (!option->arg0().empty()) {
|
|
|
|
perfile.push_back(option->arg0());
|
|
|
|
}
|
2017-01-06 02:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return perfile;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_iformat(SrsConfDirective* conf)
|
2015-08-25 14:29:00 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "flv";
|
2015-08-25 14:29:00 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("iformat");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-08-25 14:29:00 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> vfilter;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return vfilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("vfilter");
|
|
|
|
if (!conf) {
|
|
|
|
return vfilter;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* filter = conf->directives[i];
|
|
|
|
if (!filter) {
|
|
|
|
continue;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2017-01-06 02:39:37 +00:00
|
|
|
vfilter.push_back(srs_prefix_underscores_ifno(filter->name));
|
2020-01-01 13:01:14 +00:00
|
|
|
if (!filter->arg0().empty()) {
|
|
|
|
vfilter.push_back(filter->arg0());
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return vfilter;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_vcodec(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vcodec");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_vbitrate(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vbitrate");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
double SrsConfig::get_engine_vfps(SrsConfDirective* conf)
|
|
|
|
{
|
|
|
|
static double DEFAULT = 0;
|
|
|
|
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("vfps");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atof(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_vwidth(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vwidth");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_vheight(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vheight");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_vthreads(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 1;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vthreads");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_vprofile(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vprofile");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_vpreset(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vpreset");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> SrsConfig::get_engine_vparams(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> vparams;
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return vparams;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("vparams");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return vparams;
|
2015-08-29 11:46:56 +00:00
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* filter = conf->directives[i];
|
|
|
|
if (!filter) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-06 02:39:37 +00:00
|
|
|
vparams.push_back(srs_prefix_underscores_ifno(filter->name));
|
2020-01-01 13:01:14 +00:00
|
|
|
if (!filter->arg0().empty()) {
|
|
|
|
vparams.push_back(filter->arg0());
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return vparams;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_acodec(SrsConfDirective* conf)
|
2015-03-12 16:22:55 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static string DEFAULT = "";
|
2015-03-12 16:22:55 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-03-12 16:22:55 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("acodec");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-12 16:22:55 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2015-03-16 23:57:58 +00:00
|
|
|
return conf->arg0();
|
2015-03-12 16:22:55 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_abitrate(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("abitrate");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-03-30 04:44:04 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_asample_rate(SrsConfDirective* conf)
|
2015-03-30 04:44:04 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2015-03-30 04:44:04 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("asample_rate");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_engine_achannels(SrsConfDirective* conf)
|
2015-03-30 04:44:04 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 0;
|
2015-03-30 04:44:04 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("achannels");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-03-30 04:44:04 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* conf)
|
2015-03-31 07:39:47 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<string> aparams;
|
2015-03-31 07:39:47 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return aparams;
|
2015-03-31 07:39:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("aparams");
|
|
|
|
if (!conf) {
|
|
|
|
return aparams;
|
2015-03-31 07:39:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* filter = conf->directives[i];
|
|
|
|
if (!filter) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-06 02:39:37 +00:00
|
|
|
aparams.push_back(srs_prefix_underscores_ifno(filter->name));
|
2020-01-01 13:01:14 +00:00
|
|
|
if (!filter->arg0().empty()) {
|
|
|
|
aparams.push_back(filter->arg0());
|
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return aparams;
|
2015-03-31 07:39:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_oformat(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "flv";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("oformat");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_engine_output(SrsConfDirective* conf)
|
2015-02-12 05:34:59 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-02-12 05:34:59 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-02-12 05:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("output");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-02-12 05:34:59 +00:00
|
|
|
}
|
2015-03-19 09:24:27 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-03-19 09:24:27 +00:00
|
|
|
}
|
2015-02-12 05:34:59 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_exec(string vhost)
|
2015-03-19 09:24:27 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-03-19 09:24:27 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("exec");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_exec_enabled(string vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_exec(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-03-19 09:24:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-03-19 09:24:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-02-12 05:34:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> SrsConfig::get_exec_publishs(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> eps;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_exec(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return eps;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* ep = conf->at(i);
|
|
|
|
if (ep->name == "publish") {
|
|
|
|
eps.push_back(ep);
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return eps;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
vector<SrsConfDirective*> SrsConfig::get_ingesters(string vhost)
|
2014-12-20 03:45:59 +00:00
|
|
|
{
|
2015-09-19 05:31:57 +00:00
|
|
|
vector<SrsConfDirective*> integers;
|
2014-12-20 03:45:59 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
2015-09-19 05:31:57 +00:00
|
|
|
return integers;
|
2014-12-20 03:45:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
for (int i = 0; i < (int)conf->directives.size(); i++) {
|
|
|
|
SrsConfDirective* ingester = conf->directives[i];
|
|
|
|
|
|
|
|
if (ingester->name == "ingest") {
|
2015-09-19 05:31:57 +00:00
|
|
|
integers.push_back(ingester);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2014-12-20 03:45:59 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2015-09-19 05:31:57 +00:00
|
|
|
return integers;
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
2014-12-20 03:45:59 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_ingest_by_id(string vhost, string ingest_id)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->get("ingest", ingest_id);
|
2014-12-20 03:45:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_ingest_enabled(SrsConfDirective* conf)
|
2015-02-03 08:01:07 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-02-03 08:01:07 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-02-03 08:01:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-02-03 08:01:07 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-02-03 08:01:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_ingest_ffmpeg(SrsConfDirective* conf)
|
2015-02-03 08:01:07 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-02-03 08:01:07 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-02-03 08:01:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("ffmpeg");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-02-03 08:01:07 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-02-03 08:01:07 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_ingest_input_type(SrsConfDirective* conf)
|
2015-02-15 09:43:35 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "file";
|
2015-02-15 09:43:35 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-02-15 09:43:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("input");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("type");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-02-15 09:43:35 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-02-15 09:43:35 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_ingest_input_url(SrsConfDirective* conf)
|
2015-02-15 10:11:24 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-02-15 10:11:24 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-02-15 10:11:24 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("input");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("url");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-02-15 10:11:24 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-02-15 10:11:24 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_log_tank_file()
|
2015-04-10 07:00:07 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2015-04-10 07:00:07 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("srs_log_tank");
|
2015-04-10 07:00:07 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-10 07:00:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0() != "console";
|
2015-04-10 07:00:07 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_log_level()
|
2015-04-02 03:52:03 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "trace";
|
2015-04-02 03:52:03 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("srs_log_level");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-02 03:52:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-04-02 03:52:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_log_file()
|
2015-05-30 02:48:02 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/srs.log";
|
2015-05-30 02:48:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("srs_log_file");
|
2015-05-30 02:48:02 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-05-30 02:48:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 04:15:44 +00:00
|
|
|
bool SrsConfig::get_ff_log_enabled()
|
2015-04-13 02:32:32 +00:00
|
|
|
{
|
2020-02-05 04:15:44 +00:00
|
|
|
string log = get_ff_log_dir();
|
2015-09-17 05:36:02 +00:00
|
|
|
return log != SRS_CONSTS_NULL_FILE;
|
|
|
|
}
|
|
|
|
|
2020-02-05 04:15:44 +00:00
|
|
|
string SrsConfig::get_ff_log_dir()
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
|
|
|
static string DEFAULT = "./objs";
|
2015-04-13 02:32:32 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("ff_log_dir");
|
2015-04-13 02:32:32 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-04-13 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-04-13 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-05 04:32:15 +00:00
|
|
|
string SrsConfig::get_ff_log_level()
|
|
|
|
{
|
2020-02-05 05:04:00 +00:00
|
|
|
static string DEFAULT = "info";
|
2020-02-05 04:32:15 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("ff_log_level");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2017-02-11 13:14:28 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_dash(string vhost)
|
2015-03-11 05:34:58 +00:00
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2017-02-11 13:14:28 +00:00
|
|
|
return conf? conf->get("dash") : NULL;
|
|
|
|
}
|
2015-03-11 05:34:58 +00:00
|
|
|
|
2017-02-11 13:14:28 +00:00
|
|
|
bool SrsConfig::get_dash_enabled(string vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
2015-03-11 05:34:58 +00:00
|
|
|
if (!conf) {
|
2017-02-11 13:14:28 +00:00
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2017-02-11 13:14:28 +00:00
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2019-04-08 01:02:39 +00:00
|
|
|
srs_utime_t SrsConfig::get_dash_fragment(string vhost)
|
2017-02-26 12:40:33 +00:00
|
|
|
{
|
2019-12-29 10:21:45 +00:00
|
|
|
static int DEFAULT = 30 * SRS_UTIME_SECONDS;
|
2017-02-26 12:40:33 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dash_fragment");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-04-08 01:02:39 +00:00
|
|
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2017-02-26 12:40:33 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:10:06 +00:00
|
|
|
srs_utime_t SrsConfig::get_dash_update_period(string vhost)
|
2017-02-26 12:40:33 +00:00
|
|
|
{
|
2019-12-29 10:21:45 +00:00
|
|
|
static srs_utime_t DEFAULT = 150 * SRS_UTIME_SECONDS;
|
2017-02-26 12:40:33 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dash_update_period");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-04-08 01:10:06 +00:00
|
|
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2017-02-26 12:40:33 +00:00
|
|
|
}
|
|
|
|
|
2019-04-08 01:20:02 +00:00
|
|
|
srs_utime_t SrsConfig::get_dash_timeshift(string vhost)
|
2017-02-26 12:40:33 +00:00
|
|
|
{
|
2019-12-29 10:21:45 +00:00
|
|
|
static srs_utime_t DEFAULT = 300 * SRS_UTIME_SECONDS;
|
2017-02-26 12:40:33 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dash_timeshift");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-04-08 01:20:02 +00:00
|
|
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2017-02-26 12:40:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_dash_path(string vhost)
|
|
|
|
{
|
|
|
|
static string DEFAULT = "./objs/nginx/html";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dash_path");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_dash_mpd_file(string vhost)
|
|
|
|
{
|
|
|
|
static string DEFAULT = "[app]/[stream].mpd";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dash(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dash_mpd_file");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2017-02-11 13:14:28 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_hls(string vhost)
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
return conf? conf->get("hls") : NULL;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_hls_enabled(string vhost)
|
2015-03-11 05:34:58 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-04-07 09:42:41 +00:00
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_entry_prefix(string vhost)
|
2015-03-11 05:34:58 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "";
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-03-11 05:34:58 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_entry_prefix");
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-03-11 05:34:58 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_path(string vhost)
|
2015-03-11 05:34:58 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/nginx/html";
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-03-11 05:34:58 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_path");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_m3u8_file(string vhost)
|
2015-03-11 05:34:58 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "[app]/[stream].m3u8";
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-03-11 05:34:58 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_m3u8_file");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-03-11 05:34:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_ts_file(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "[app]/[stream]-[seq].ts";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_ts_file");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_hls_ts_floor(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_ts_floor");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:14:12 +00:00
|
|
|
srs_utime_t SrsConfig::get_hls_fragment(string vhost)
|
2015-09-15 07:58:57 +00:00
|
|
|
{
|
2019-04-16 00:14:12 +00:00
|
|
|
static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-09-15 07:58:57 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_fragment");
|
2015-09-15 07:58:57 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2019-04-16 00:14:12 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
double SrsConfig::get_hls_td_ratio(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static double DEFAULT = 1.5;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_td_ratio");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atof(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
double SrsConfig::get_hls_aof_ratio(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static double DEFAULT = 2.0;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_aof_ratio");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atof(conf->arg0().c_str());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:20:32 +00:00
|
|
|
srs_utime_t SrsConfig::get_hls_window(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-16 00:20:32 +00:00
|
|
|
static srs_utime_t DEFAULT = (60 * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_window");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:20:32 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_on_error(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-12-15 08:06:40 +00:00
|
|
|
// try to ignore the error.
|
|
|
|
static string DEFAULT = "continue";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_on_error");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_acodec(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "aac";
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_acodec");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-09-17 05:36:02 +00:00
|
|
|
|
2015-03-23 15:13:57 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hls_vcodec(string vhost)
|
2015-02-21 13:17:59 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "h264";
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-02-21 13:17:59 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2015-02-21 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_vcodec");
|
2015-02-21 13:17:59 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2015-02-21 13:17:59 +00:00
|
|
|
}
|
2015-04-07 09:42:41 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-02-21 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_vhost_hls_nb_notify(string vhost)
|
2015-08-28 04:28:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static int DEFAULT = 64;
|
2015-08-28 04:28:18 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_nb_notify");
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return ::atoi(conf->arg0().c_str());
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2019-12-05 12:47:23 +00:00
|
|
|
bool SrsConfig::get_vhost_hls_dts_directly(string vhost)
|
|
|
|
{
|
2019-12-12 08:51:34 +00:00
|
|
|
static bool DEFAULT = true;
|
2019-12-05 12:47:23 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_dts_directly");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-12-12 08:51:34 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2019-12-05 12:47:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_hls_cleanup(string vhost)
|
2015-08-27 10:11:50 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2015-08-27 10:11:50 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_cleanup");
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2015-08-28 04:28:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 01:07:03 +00:00
|
|
|
srs_utime_t SrsConfig::get_hls_dispose(string vhost)
|
2015-08-28 04:28:18 +00:00
|
|
|
{
|
2019-04-10 01:07:03 +00:00
|
|
|
static srs_utime_t DEFAULT = 0;
|
2015-08-28 04:28:18 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-28 04:28:18 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_dispose");
|
2015-08-27 10:11:50 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:07:03 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2015-08-27 10:11:50 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_hls_wait_keyframe(string vhost)
|
2015-08-30 15:08:27 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2015-08-30 15:08:27 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
2015-08-30 15:08:27 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hls_wait_keyframe");
|
2015-08-30 15:08:27 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2018-03-25 04:05:52 +00:00
|
|
|
bool SrsConfig::get_hls_keys(string vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_keys");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrsConfig::get_hls_fragments_per_key(string vhost)
|
|
|
|
{
|
2018-08-25 13:59:56 +00:00
|
|
|
static int DEFAULT = 5;
|
2018-03-25 04:05:52 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_fragments_per_key");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_hls_key_file(string vhost)
|
|
|
|
{
|
2018-05-15 03:20:52 +00:00
|
|
|
static string DEFAULT = "[app]/[stream]-[seq].key";
|
2018-03-25 04:05:52 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_key_file");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_hls_key_file_path(std::string vhost)
|
|
|
|
{
|
|
|
|
//put the key in ts path defaultly.
|
|
|
|
static string DEFAULT = get_hls_path(vhost);
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_key_file_path");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_hls_key_url(std::string vhost)
|
|
|
|
{
|
|
|
|
//put the key in ts path defaultly.
|
|
|
|
static string DEFAULT = get_hls_path(vhost);
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_hls(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("hls_key_url");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective *SrsConfig::get_hds(const string &vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!conf) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("hds");
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_hds_enabled(const string &vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 10:40:18 +00:00
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hds(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
conf = conf->get("enabled");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_hds_path(const string &vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/nginx/html";
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hds(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hds_path");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 15:13:57 +00:00
|
|
|
return conf->arg0();
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:24:11 +00:00
|
|
|
srs_utime_t SrsConfig::get_hds_fragment(const string &vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-16 00:24:11 +00:00
|
|
|
static srs_utime_t DEFAULT = (10 * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hds(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hds_fragment");
|
2015-08-29 10:40:18 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:24:11 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:24:11 +00:00
|
|
|
srs_utime_t SrsConfig::get_hds_window(const string &vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2019-04-16 00:24:11 +00:00
|
|
|
static srs_utime_t DEFAULT = (60 * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_hds(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("hds_window");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:24:11 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_dvr(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 10:40:18 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->get("dvr");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_dvr_enabled(string vhost)
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 10:40:18 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* SrsConfig::get_dvr_apply(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("dvr_apply");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return NULL;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf;
|
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_dvr_path(string vhost)
|
2015-01-18 10:00:40 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/nginx/html/[app]/[stream].[timestamp].flv";
|
2015-01-18 10:00:40 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2015-01-18 10:00:40 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("dvr_path");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_dvr_plan(string vhost)
|
2015-01-19 05:17:46 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "session";
|
2015-01-19 05:17:46 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2015-01-19 05:17:46 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-19 05:17:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("dvr_plan");
|
2015-08-29 11:46:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-01-19 05:17:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
2015-01-19 05:17:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 00:32:46 +00:00
|
|
|
srs_utime_t SrsConfig::get_dvr_duration(string vhost)
|
2015-01-18 10:00:40 +00:00
|
|
|
{
|
2019-04-10 00:32:46 +00:00
|
|
|
static srs_utime_t DEFAULT = 30 * SRS_UTIME_SECONDS;
|
2015-01-18 10:00:40 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2015-01-18 10:00:40 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("dvr_duration");
|
2015-01-18 10:00:40 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 00:32:46 +00:00
|
|
|
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2015-01-18 10:00:40 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_dvr_wait_keyframe(string vhost)
|
2015-03-14 01:52:47 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2015-03-14 01:52:47 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2015-03-14 01:52:47 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-14 01:52:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("dvr_wait_keyframe");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2015-03-14 01:52:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-29 11:46:56 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2015-03-14 01:52:47 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
int SrsConfig::get_dvr_time_jitter(string vhost)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "full";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_dvr(vhost);
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(DEFAULT);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("time_jitter");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(DEFAULT);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return _srs_time_jitter_string2int(conf->arg0());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_http_api_enabled()
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
|
|
|
return get_http_api_enabled(conf);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf)
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2015-08-29 11:46:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_http_api_listen()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "1985";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
2014-11-11 09:19:56 +00:00
|
|
|
|
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("listen");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
2017-03-25 09:21:39 +00:00
|
|
|
|
2014-11-11 09:19:56 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_http_api_crossdomain()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = true;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("crossdomain");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_raw_api()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-08-29 11:46:56 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("raw_api");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("enabled");
|
2015-04-07 09:42:41 +00:00
|
|
|
if (!conf || conf->arg0().empty()) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 09:42:41 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_raw_api_allow_reload()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-08-29 11:46:56 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("raw_api");
|
2014-11-11 09:19:56 +00:00
|
|
|
if (!conf) {
|
2015-09-17 05:36:02 +00:00
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("allow_reload");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_raw_api_allow_query()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("raw_api");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("allow_query");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_raw_api_allow_update()
|
2014-11-11 09:19:56 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2014-11-11 09:19:56 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_api");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("raw_api");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("allow_update");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_http_stream_enabled()
|
2015-09-15 07:58:57 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = root->get("http_server");
|
|
|
|
return get_http_stream_enabled(conf);
|
2014-11-11 09:19:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf)
|
2015-09-15 07:58:57 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-09-15 07:58:57 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-07-10 05:50:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_http_stream_listen()
|
2015-07-10 05:50:35 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "8080";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("http_server");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("listen");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2015-07-10 05:50:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_http_stream_dir()
|
2015-07-10 05:50:35 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "./objs/nginx/html";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("http_server");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dir");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2015-07-10 05:50:35 +00:00
|
|
|
}
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2016-12-15 08:22:04 +00:00
|
|
|
bool SrsConfig::get_http_stream_crossdomain()
|
|
|
|
{
|
|
|
|
static bool DEFAULT = true;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = root->get("http_server");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("crossdomain");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_http_enabled(string vhost)
|
2015-09-15 07:58:57 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2015-09-15 07:58:57 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
2015-09-15 07:58:57 +00:00
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("http_static");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-09-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
2015-09-09 15:32:02 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
string SrsConfig::get_vhost_http_mount(string vhost)
|
2015-08-29 10:40:18 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static string DEFAULT = "[vhost]/";
|
2015-08-29 10:40:18 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("http_static");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("mount");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_vhost_http_dir(string vhost)
|
|
|
|
{
|
|
|
|
static string DEFAULT = "./objs/nginx/html";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-29 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("http_static");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("dir");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf->arg0();
|
2015-08-29 10:40:18 +00:00
|
|
|
}
|
2015-08-30 15:08:27 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
bool SrsConfig::get_vhost_http_remux_enabled(string vhost)
|
2015-08-30 15:08:27 +00:00
|
|
|
{
|
2015-09-17 05:36:02 +00:00
|
|
|
static bool DEFAULT = false;
|
2020-01-15 13:26:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2020-01-15 13:26:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("http_remux");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
2020-01-15 13:26:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
2020-01-15 13:26:02 +00:00
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2019-04-16 00:50:48 +00:00
|
|
|
srs_utime_t SrsConfig::get_vhost_http_remux_fast_cache(string vhost)
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
2019-04-16 00:50:48 +00:00
|
|
|
static srs_utime_t DEFAULT = 0;
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("http_remux");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("fast_cache");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 00:50:48 +00:00
|
|
|
return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_vhost_http_remux_mount(string vhost)
|
|
|
|
{
|
|
|
|
static string DEFAULT = "[vhost]/[app]/[stream].flv";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_vhost(vhost);
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("http_remux");
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("mount");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_heartbeart()
|
|
|
|
{
|
|
|
|
return root->get("heartbeat");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_heartbeat_enabled()
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("enabled");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
2019-04-09 00:47:18 +00:00
|
|
|
srs_utime_t SrsConfig::get_heartbeat_interval()
|
2015-09-17 05:36:02 +00:00
|
|
|
{
|
2019-04-09 00:47:18 +00:00
|
|
|
static srs_utime_t DEFAULT = (srs_utime_t)(9.9 * SRS_UTIME_SECONDS);
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("interval");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:47:18 +00:00
|
|
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
2015-09-17 05:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_heartbeat_url()
|
|
|
|
{
|
2017-05-06 06:05:22 +00:00
|
|
|
static string DEFAULT = "http://" SRS_CONSTS_LOCALHOST ":8085/api/v1/servers";
|
2015-09-17 05:36:02 +00:00
|
|
|
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("url");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
string SrsConfig::get_heartbeat_device_id()
|
|
|
|
{
|
|
|
|
static string DEFAULT = "";
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
conf = conf->get("device_id");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|
|
|
|
|
2015-09-17 05:36:02 +00:00
|
|
|
return conf->arg0();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SrsConfig::get_heartbeat_summaries()
|
|
|
|
{
|
|
|
|
static bool DEFAULT = false;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_heartbeart();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("summaries");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_stats()
|
|
|
|
{
|
|
|
|
return root->get("stats");
|
|
|
|
}
|
|
|
|
|
|
|
|
int SrsConfig::get_stats_network()
|
|
|
|
{
|
|
|
|
static int DEFAULT = 0;
|
|
|
|
|
|
|
|
SrsConfDirective* conf = get_stats();
|
|
|
|
if (!conf) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("network");
|
|
|
|
if (!conf || conf->arg0().empty()) {
|
|
|
|
return DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::atoi(conf->arg0().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SrsConfDirective* SrsConfig::get_stats_disk_device()
|
|
|
|
{
|
|
|
|
SrsConfDirective* conf = get_stats();
|
|
|
|
if (!conf) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = conf->get("disk");
|
|
|
|
if (!conf || conf->args.size() == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return conf;
|
2015-08-30 15:08:27 +00:00
|
|
|
}
|