winlin

refine config, add comments

... ... @@ -1835,7 +1835,7 @@ int SrsConfig::get_bw_check_limit_kbps(string vhost)
return ::atoi(conf->arg0().c_str());
}
bool SrsConfig::get_vhost_is_edge(std::string vhost)
bool SrsConfig::get_vhost_is_edge(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
return get_vhost_is_edge(conf);
... ... @@ -1868,7 +1868,7 @@ SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
return conf->get("origin");
}
bool SrsConfig::get_vhost_edge_token_traverse(std::string vhost)
bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ... @@ -1965,6 +1965,32 @@ bool SrsConfig::get_engine_enabled(SrsConfDirective* engine)
return true;
}
vector<string> SrsConfig::get_engine_vfilter(SrsConfDirective* engine)
{
vector<string> vfilter;
if (!engine) {
return vfilter;
}
SrsConfDirective* conf = engine->get("vfilter");
if (!conf) {
return vfilter;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* p = conf->directives[i];
if (!p) {
continue;
}
vfilter.push_back("-" + p->name);
vfilter.push_back(p->arg0());
}
return vfilter;
}
string SrsConfig::get_engine_vcodec(SrsConfDirective* engine)
{
if (!engine) {
... ... @@ -2077,15 +2103,17 @@ string SrsConfig::get_engine_vpreset(SrsConfDirective* engine)
return conf->arg0();
}
void SrsConfig::get_engine_vparams(SrsConfDirective* engine, vector<string>& vparams)
vector<string> SrsConfig::get_engine_vparams(SrsConfDirective* engine)
{
vector<string> vparams;
if (!engine) {
return;
return vparams;
}
SrsConfDirective* conf = engine->get("vparams");
if (!conf) {
return;
return vparams;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
... ... @@ -2097,28 +2125,8 @@ void SrsConfig::get_engine_vparams(SrsConfDirective* engine, vector<string>& vpa
vparams.push_back("-" + p->name);
vparams.push_back(p->arg0());
}
}
void SrsConfig::get_engine_vfilter(SrsConfDirective* engine, vector<string>& vfilter)
{
if (!engine) {
return;
}
SrsConfDirective* conf = engine->get("vfilter");
if (!conf) {
return;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* p = conf->directives[i];
if (!p) {
continue;
}
vfilter.push_back("-" + p->name);
vfilter.push_back(p->arg0());
}
return vparams;
}
string SrsConfig::get_engine_acodec(SrsConfDirective* engine)
... ... @@ -2177,15 +2185,17 @@ int SrsConfig::get_engine_achannels(SrsConfDirective* engine)
return ::atoi(conf->arg0().c_str());
}
void SrsConfig::get_engine_aparams(SrsConfDirective* engine, vector<string>& aparams)
vector<string> SrsConfig::get_engine_aparams(SrsConfDirective* engine)
{
vector<string> aparams;
if (!engine) {
return;
return aparams;
}
SrsConfDirective* conf = engine->get("aparams");
if (!conf) {
return;
return aparams;
}
for (int i = 0; i < (int)conf->directives.size(); i++) {
... ... @@ -2197,6 +2207,8 @@ void SrsConfig::get_engine_aparams(SrsConfDirective* engine, vector<string>& apa
aparams.push_back("-" + p->name);
aparams.push_back(p->arg0());
}
return aparams;
}
string SrsConfig::get_engine_output(SrsConfDirective* engine)
... ... @@ -2213,11 +2225,13 @@ string SrsConfig::get_engine_output(SrsConfDirective* engine)
return conf->arg0();
}
void SrsConfig::get_ingesters(std::string vhost, std::vector<SrsConfDirective*>& ingeters)
vector<SrsConfDirective*> SrsConfig::get_ingesters(string vhost)
{
vector<SrsConfDirective*> ingeters;
SrsConfDirective* vhost_conf = get_vhost(vhost);
if (!vhost_conf) {
return;
return ingeters;
}
for (int i = 0; i < (int)vhost_conf->directives.size(); i++) {
... ... @@ -2228,10 +2242,10 @@ void SrsConfig::get_ingesters(std::string vhost, std::vector<SrsConfDirective*>&
}
}
return;
return ingeters;
}
SrsConfDirective* SrsConfig::get_ingest_by_id(std::string vhost, std::string ingest_id)
SrsConfDirective* SrsConfig::get_ingest_by_id(string vhost, string ingest_id)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
... ...
... ... @@ -601,97 +601,112 @@ public:
*/
virtual std::vector<SrsConfDirective*> get_transcode_engines(SrsConfDirective* transcode);
/**
*
* whether the engine is enabled.
*/
virtual bool get_engine_enabled(SrsConfDirective* engine);
/**
*
* get the vfilter of engine,
* the video filter set before the vcodec of FFMPEG.
*/
virtual std::vector<std::string> get_engine_vfilter(SrsConfDirective* engine);
/**
* get the vcodec of engine,
* the codec of video, copy or libx264
*/
virtual std::string get_engine_vcodec(SrsConfDirective* engine);
/**
*
* get the vbitrate of engine,
* the bitrate in kbps of video, for example, 800kbps
*/
virtual int get_engine_vbitrate(SrsConfDirective* engine);
/**
*
* get the vfps of engine.
* the video fps, for example, 25fps
*/
virtual double get_engine_vfps(SrsConfDirective* engine);
/**
*
* get the vwidth of engine,
* the video width, for example, 1024
*/
virtual int get_engine_vwidth(SrsConfDirective* engine);
/**
*
* get the vheight of engine,
* the video height, for example, 576
*/
virtual int get_engine_vheight(SrsConfDirective* engine);
/**
*
* get the vthreads of engine,
* the video transcode libx264 threads, for instance, 8
*/
virtual int get_engine_vthreads(SrsConfDirective* engine);
/**
*
* get the vprofile of engine,
* the libx264 profile, can be high,main,baseline
*/
virtual std::string get_engine_vprofile(SrsConfDirective* engine);
/**
*
* get the vpreset of engine,
* the libx264 preset, can be ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo
*/
virtual std::string get_engine_vpreset(SrsConfDirective* engine);
/**
*
* get the additional video params.
*/
virtual void get_engine_vparams(SrsConfDirective* engine, std::vector<std::string>& vparams);
virtual std::vector<std::string> get_engine_vparams(SrsConfDirective* engine);
/**
*
*/
virtual void get_engine_vfilter(SrsConfDirective* engine, std::vector<std::string>& vfilter);
/**
*
* get the acodec of engine,
* the audio codec can be copy or libaacplus
*/
virtual std::string get_engine_acodec(SrsConfDirective* engine);
/**
*
* get the abitrate of engine,
* the audio bitrate in kbps, for instance, 64kbps.
*/
virtual int get_engine_abitrate(SrsConfDirective* engine);
/**
*
* get the asample_rate of engine,
* the audio sample_rate, for instance, 44100HZ
*/
virtual int get_engine_asample_rate(SrsConfDirective* engine);
/**
*
* get the achannels of engine,
* the audio channel, for instance, 1 for mono, 2 for stereo.
*/
virtual int get_engine_achannels(SrsConfDirective* engine);
/**
*
* get the aparams of engine,
* the audio additional params.
*/
virtual void get_engine_aparams(SrsConfDirective* engine, std::vector<std::string>& aparams);
virtual std::vector<std::string> get_engine_aparams(SrsConfDirective* engine);
/**
*
* get the output of engine, for example, rtmp://127.0.0.1/live/livestream,
* @remark, we will use some variable, for instance, [vhost] to substitude with vhost.
*/
virtual std::string get_engine_output(SrsConfDirective* engine);
// ingest section
public:
/**
*
* get the ingest directives of vhost.
*/
virtual void get_ingesters(std::string vhost, std::vector<SrsConfDirective*>& ingeters);
virtual std::vector<SrsConfDirective*> get_ingesters(std::string vhost);
/**
*
* get specified ingest.
*/
virtual SrsConfDirective* get_ingest_by_id(std::string vhost, std::string ingest_id);
/**
*
* whether ingest is enalbed.
*/
virtual bool get_ingest_enabled(SrsConfDirective* ingest);
/**
*
* get the ingest ffmpeg tool
*/
virtual std::string get_ingest_ffmpeg(SrsConfDirective* ingest);
/**
*
* get the ingest input type, file or stream.
*/
virtual std::string get_ingest_input_type(SrsConfDirective* ingest);
/**
*
* get the ingest input url.
*/
virtual std::string get_ingest_input_url(SrsConfDirective* ingest);
// log section
... ...
... ... @@ -96,21 +96,21 @@ int SrsFFMPEG::initialize_transcode(SrsConfDirective* engine)
{
int ret = ERROR_SUCCESS;
_srs_config->get_engine_vfilter(engine, vfilter);
vcodec = _srs_config->get_engine_vcodec(engine);
vbitrate = _srs_config->get_engine_vbitrate(engine);
vfps = _srs_config->get_engine_vfps(engine);
vwidth = _srs_config->get_engine_vwidth(engine);
vheight = _srs_config->get_engine_vheight(engine);
vthreads = _srs_config->get_engine_vthreads(engine);
vprofile = _srs_config->get_engine_vprofile(engine);
vpreset = _srs_config->get_engine_vpreset(engine);
_srs_config->get_engine_vparams(engine, vparams);
acodec = _srs_config->get_engine_acodec(engine);
abitrate = _srs_config->get_engine_abitrate(engine);
asample_rate = _srs_config->get_engine_asample_rate(engine);
achannels = _srs_config->get_engine_achannels(engine);
_srs_config->get_engine_aparams(engine, aparams);
vfilter = _srs_config->get_engine_vfilter(engine);
vcodec = _srs_config->get_engine_vcodec(engine);
vbitrate = _srs_config->get_engine_vbitrate(engine);
vfps = _srs_config->get_engine_vfps(engine);
vwidth = _srs_config->get_engine_vwidth(engine);
vheight = _srs_config->get_engine_vheight(engine);
vthreads = _srs_config->get_engine_vthreads(engine);
vprofile = _srs_config->get_engine_vprofile(engine);
vpreset = _srs_config->get_engine_vpreset(engine);
vparams = _srs_config->get_engine_vparams(engine);
acodec = _srs_config->get_engine_acodec(engine);
abitrate = _srs_config->get_engine_abitrate(engine);
asample_rate = _srs_config->get_engine_asample_rate(engine);
achannels = _srs_config->get_engine_achannels(engine);
aparams = _srs_config->get_engine_aparams(engine);
// ensure the size is even.
vwidth -= vwidth % 2;
... ...
... ... @@ -93,8 +93,7 @@ int SrsIngester::parse_ingesters(SrsConfDirective* vhost)
{
int ret = ERROR_SUCCESS;
std::vector<SrsConfDirective*> ingesters;
_srs_config->get_ingesters(vhost->arg0(), ingesters);
std::vector<SrsConfDirective*> ingesters = _srs_config->get_ingesters(vhost->arg0());
// create engine
for (int i = 0; i < (int)ingesters.size(); i++) {
... ...