Skip to content

Commit

Permalink
For #1592, support ff_log_level and default to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 5, 2020
1 parent 2fa1517 commit c50c518
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 11 deletions.
7 changes: 6 additions & 1 deletion trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ pid ./objs/srs.pid;
# performance about 10%.
# default: 60000
chunk_size 60000;
# the logs dir.
# the log dir for FFMPEG.
# if enabled ffmpeg, each transcoding stream will create a log file.
# /dev/null to disable the log.
# default: ./objs
ff_log_dir ./objs;
# the log level for FFMPEG.
# info warning error fatal panic quiet
# trace debug verbose
# default: warning
ff_log_level warning;
# the log tank, console or file.
# if console, print log to console.
# if file, write log to file. requires srs_log_file if log to file.
Expand Down
13 changes: 13 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_server" && n != "stream_caster"
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
&& n != "ff_log_level"
) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
}
Expand Down Expand Up @@ -5782,6 +5783,18 @@ string SrsConfig::get_ff_log_dir()
return conf->arg0();
}

string SrsConfig::get_ff_log_level()
{
static string DEFAULT = "warning";

SrsConfDirective* conf = root->get("ff_log_level");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return conf->arg0();
}

SrsConfDirective* SrsConfig::get_dash(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ class SrsConfig
// The ffmpeg log dir.
// @remark, /dev/null to disable it.
virtual std::string get_ff_log_dir();
// The ffmpeg log level.
virtual std::string get_ff_log_level();
// The MPEG-DASH section.
private:
virtual SrsConfDirective* get_dash(std::string vhost);
Expand Down
11 changes: 7 additions & 4 deletions trunk/src/app/srs_app_ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ SrsFFMPEG::~SrsFFMPEG()
srs_freep(process);
}

void SrsFFMPEG::set_iparams(string iparams)
void SrsFFMPEG::append_iparam(string iparam)
{
_iparams = iparams;
iparams.push_back(iparam);
}

void SrsFFMPEG::set_oformat(string format)
Expand Down Expand Up @@ -230,8 +230,11 @@ srs_error_t SrsFFMPEG::start()
params.push_back(ffmpeg);

// input params
if (!_iparams.empty()) {
params.push_back(_iparams);
for (int i = 0; i < iparams.size(); i++) {
string iparam = iparams.at(i);
if (!iparam.empty()) {
params.push_back(iparam);
}
}

// build the perfile
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_ffmpeg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SrsFFMPEG
std::string log_file;
private:
std::string ffmpeg;
std::string _iparams;
std::vector<std::string> iparams;
std::vector<std::string> perfile;
std::string iformat;
std::string input;
Expand All @@ -70,7 +70,7 @@ class SrsFFMPEG
SrsFFMPEG(std::string ffmpeg_bin);
virtual ~SrsFFMPEG();
public:
virtual void set_iparams(std::string iparams);
virtual void append_iparam(std::string iparam);
virtual void set_oformat(std::string format);
virtual std::string output();
public:
Expand Down
12 changes: 9 additions & 3 deletions trunk/src/app/srs_app_ingest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,13 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
log_file += stream;
log_file += ".log";
}


std::string log_level = _srs_config->get_ff_log_level();
if (!log_level.empty()) {
ffmpeg->append_iparam("-loglevel");
ffmpeg->append_iparam(log_level);
}

// input
std::string input_type = _srs_config->get_ingest_input_type(ingest);
if (input_type.empty()) {
Expand All @@ -423,7 +429,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
}

// for file, set re.
ffmpeg->set_iparams("-re");
ffmpeg->append_iparam("-re");

if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg");
Expand All @@ -435,7 +441,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
}

// for stream, no re.
ffmpeg->set_iparams("");
ffmpeg->append_iparam("");

if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg");
Expand Down
8 changes: 7 additions & 1 deletion trunk/src/utest/srs_utest_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_dirs ./objs;"));
}

if (true) {
MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_levels info;"));
}
}

VOID TEST(ConfigMainTest, CheckConf_srs_log_level)
Expand Down Expand Up @@ -3503,11 +3508,12 @@ VOID TEST(ConfigMainTest, CheckVhostConfig5)

if (true) {
MockSrsConfig conf;
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_tank xxx;srs_log_level xxx2;srs_log_file xxx3;ff_log_dir xxx4;"));
HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srs_log_tank xxx;srs_log_level xxx2;srs_log_file xxx3;ff_log_dir xxx4; ff_log_level xxx5;"));
EXPECT_TRUE(conf.get_log_tank_file());
EXPECT_STREQ("xxx2", conf.get_log_level().c_str());
EXPECT_STREQ("xxx3", conf.get_log_file().c_str());
EXPECT_STREQ("xxx4", conf.get_ff_log_dir().c_str());
EXPECT_STREQ("xxx5", conf.get_ff_log_level().c_str());
EXPECT_TRUE(conf.get_ff_log_enabled());
}

Expand Down

0 comments on commit c50c518

Please sign in to comment.