1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge branch '3.0release' into develop

This commit is contained in:
winlin 2020-02-05 14:18:07 +08:00
commit bdc7973596
13 changed files with 108 additions and 70 deletions

View file

@ -159,6 +159,8 @@ For previous versions, please read:
## V3 changes
* v3.0, 2020-02-05, For [#665][bug #665], fix HTTP-FLV reloading bug. 3.0.116
* v3.0, 2020-02-05, For [#1592][bug #1592], fix terminal echo off by redirect process stdin. 3.0.115
* v3.0, 2020-02-04, For [#1186][bug #1186], refactor security check. 3.0.114
* v3.0, 2020-02-04, Fix [#939][bug #939], response right A/V flag in FLV header. 3.0.113
* v3.0, 2020-02-04, For [#939][bug #939], always enable fast FLV streaming.
@ -1664,6 +1666,8 @@ Winlin
[bug #1206]: https://github.com/ossrs/srs/issues/1206
[bug #939]: https://github.com/ossrs/srs/issues/939
[bug #1186]: https://github.com/ossrs/srs/issues/1186
[bug #1592]: https://github.com/ossrs/srs/issues/1592
[bug #665]: https://github.com/ossrs/srs/issues/665
[bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx
[exo #828]: https://github.com/google/ExoPlayer/pull/828

View file

@ -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: info
ff_log_level info;
# 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.

View file

@ -3488,6 +3488,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 != "srt_server"
&& 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());
}
@ -5775,13 +5776,13 @@ string SrsConfig::get_log_file()
return conf->arg0();
}
bool SrsConfig::get_ffmpeg_log_enabled()
bool SrsConfig::get_ff_log_enabled()
{
string log = get_ffmpeg_log_dir();
string log = get_ff_log_dir();
return log != SRS_CONSTS_NULL_FILE;
}
string SrsConfig::get_ffmpeg_log_dir()
string SrsConfig::get_ff_log_dir()
{
static string DEFAULT = "./objs";
@ -5793,6 +5794,18 @@ string SrsConfig::get_ffmpeg_log_dir()
return conf->arg0();
}
string SrsConfig::get_ff_log_level()
{
static string DEFAULT = "info";
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);

View file

@ -786,10 +786,12 @@ public:
// Get the log file path.
virtual std::string get_log_file();
// Whether ffmpeg log enabled
virtual bool get_ffmpeg_log_enabled();
virtual bool get_ff_log_enabled();
// The ffmpeg log dir.
// @remark, /dev/null to disable it.
virtual std::string get_ffmpeg_log_dir();
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);

View file

@ -285,8 +285,8 @@ srs_error_t SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, Sr
std::string log_file = SRS_CONSTS_NULL_FILE; // disabled
// write ffmpeg info to log file.
if (_srs_config->get_ffmpeg_log_enabled()) {
log_file = _srs_config->get_ffmpeg_log_dir();
if (_srs_config->get_ff_log_enabled()) {
log_file = _srs_config->get_ff_log_dir();
log_file += "/";
log_file += "ffmpeg-encoder";
log_file += "-";

View file

@ -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)
@ -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

View file

@ -45,7 +45,7 @@ private:
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;
@ -70,7 +70,7 @@ public:
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:

View file

@ -809,6 +809,11 @@ SrsLiveEntry::SrsLiveEntry(std::string m)
_is_aac = (ext == ".aac");
}
SrsLiveEntry::~SrsLiveEntry()
{
srs_freep(req);
}
bool SrsLiveEntry::is_flv()
{
return _is_flv;
@ -846,7 +851,6 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = tflvs.begin(); it != tflvs.end(); ++it) {
SrsLiveEntry* entry = it->second;
srs_freep(entry->req);
srs_freep(entry);
}
tflvs.clear();
@ -902,6 +906,8 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
entry = new SrsLiveEntry(mount);
entry->source = s;
entry->req = r->copy()->as_http();
entry->cache = new SrsBufferCache(s, r);
entry->stream = new SrsLiveStream(s, r, entry->cache);
@ -972,6 +978,7 @@ srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost
{
srs_error_t err = srs_success;
// Create new vhost.
if (tflvs.find(vhost) == tflvs.end()) {
if ((err = initialize_flv_entry(vhost)) != srs_success) {
return srs_error_wrap(err, "init flv entry");
@ -982,40 +989,26 @@ srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost
return err;
}
SrsLiveEntry* tmpl = tflvs[vhost];
SrsRequest* req = tmpl->req;
SrsSource* source = tmpl->source;
// Update all streams for exists vhost.
// TODO: FIMXE: If url changed, needs more things to deal with.
std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = sflvs.begin(); it != sflvs.end(); ++it) {
SrsLiveEntry* entry = it->second;
if (!entry || !entry->req || !entry->source) {
continue;
}
if (source && req) {
// cleanup the exists http remux.
SrsRequest* req = entry->req;
if (!req || req->vhost != vhost) {
continue;
}
SrsSource* source = entry->source;
if (_srs_config->get_vhost_http_remux_enabled(vhost)) {
http_mount(source, req);
} else {
http_unmount(source, req);
}
if (!_srs_config->get_vhost_http_remux_enabled(vhost)) {
return err;
}
string old_tmpl_mount = tmpl->mount;
string new_tmpl_mount = _srs_config->get_vhost_http_remux_mount(vhost);
/**
* TODO: not support to reload different mount url for the time being.
* if the mount is change, need more logical thing to deal with.
* such as erase stream from sflvs and free all related resource.
*/
srs_assert(old_tmpl_mount == new_tmpl_mount);
// do http mount directly with SrsRequest and SrsSource if stream is played already.
if (req) {
std::string sid = req->get_stream_url();
// remount stream.
if ((err = http_mount(source, req)) != srs_success) {
return srs_error_wrap(err, "vhost %s http_remux reload failed", vhost.c_str());
}
} else {
// for without SrsRequest and SrsSource if stream is not played yet, do http mount automatically
// when start play this http flv stream.
}
srs_trace("vhost %s http_remux reload success", vhost.c_str());

View file

@ -207,7 +207,9 @@ private:
bool _is_aac;
bool _is_mp3;
public:
// We will free the request.
SrsRequest* req;
// Shared source.
SrsSource* source;
public:
// For template, the mount contains variables.
@ -218,6 +220,7 @@ public:
SrsBufferCache* cache;
SrsLiveEntry(std::string m);
virtual ~SrsLiveEntry();
bool is_flv();
bool is_ts();

View file

@ -397,8 +397,8 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
std::string log_file = SRS_CONSTS_NULL_FILE; // disabled
// write ffmpeg info to log file.
if (_srs_config->get_ffmpeg_log_enabled()) {
log_file = _srs_config->get_ffmpeg_log_dir();
if (_srs_config->get_ff_log_enabled()) {
log_file = _srs_config->get_ff_log_dir();
log_file += "/";
log_file += "ffmpeg-ingest";
log_file += "-";
@ -410,6 +410,12 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
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()) {
@ -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");
@ -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");

View file

@ -152,7 +152,7 @@ srs_error_t srs_redirect_output(string from_file, int to_fd)
// redirect the fd to file.
int fd = -1;
int flags = O_CREAT|O_WRONLY|O_APPEND;
int flags = O_CREAT|O_RDWR|O_APPEND;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
if ((fd = ::open(from_file.c_str(), flags, mode)) < 0) {
@ -198,9 +198,6 @@ srs_error_t SrsProcess::start()
signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN);
// for the stdin,
// should never close it or ffmpeg will error.
// for the stdout, ignore when not specified.
// redirect stdout to file if possible.
if ((err = srs_redirect_output(stdout_file, STDOUT_FILENO)) != srs_success) {
@ -213,15 +210,21 @@ srs_error_t SrsProcess::start()
return srs_error_wrap(err, "redirect output");
}
// No stdin for process, @bug https://github.com/ossrs/srs/issues/1592
if ((err = srs_redirect_output("/dev/null", STDIN_FILENO)) != srs_success) {
return srs_error_wrap(err, "redirect input");
}
// should never close the fd 3+, for it myabe used.
// for fd should close at exec, use fnctl to set it.
// log basic info to stderr.
if (true) {
fprintf(stderr, "\n");
fprintf(stderr, "process ppid=%d, cid=%d, pid=%d\n", ppid, cid, getpid());
fprintf(stderr, "process binary=%s, cli: %s\n", bin.c_str(), cli.c_str());
fprintf(stderr, "process actual cli: %s\n", actual_cli.c_str());
fprintf(stdout, "\n");
fprintf(stdout, "process ppid=%d, cid=%d, pid=%d, in=%d, out=%d, err=%d\n",
ppid, cid, getpid(), STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);
fprintf(stdout, "process binary=%s, cli: %s\n", bin.c_str(), cli.c_str());
fprintf(stdout, "process actual cli: %s\n", actual_cli.c_str());
}
// memory leak in child process, it's ok.

View file

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP
#define SRS_VERSION3_REVISION 114
#define SRS_VERSION3_REVISION 116
#endif

View file

@ -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)
@ -3503,12 +3508,13 @@ 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_ffmpeg_log_dir().c_str());
EXPECT_TRUE(conf.get_ffmpeg_log_enabled());
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());
}
if (true) {