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 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, 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, 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. * 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 #1206]: https://github.com/ossrs/srs/issues/1206
[bug #939]: https://github.com/ossrs/srs/issues/939 [bug #939]: https://github.com/ossrs/srs/issues/939
[bug #1186]: https://github.com/ossrs/srs/issues/1186 [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 [bug #xxxxxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxxxxx
[exo #828]: https://github.com/google/ExoPlayer/pull/828 [exo #828]: https://github.com/google/ExoPlayer/pull/828

View file

@ -19,11 +19,16 @@ pid ./objs/srs.pid;
# performance about 10%. # performance about 10%.
# default: 60000 # default: 60000
chunk_size 60000; chunk_size 60000;
# the logs dir. # the log dir for FFMPEG.
# if enabled ffmpeg, each transcoding stream will create a log file. # if enabled ffmpeg, each transcoding stream will create a log file.
# /dev/null to disable the log. # /dev/null to disable the log.
# default: ./objs # default: ./objs
ff_log_dir ./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. # the log tank, console or file.
# if console, print log to console. # if console, print log to console.
# if file, write log to file. requires srs_log_file if log to file. # 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_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_server" && n != "stream_caster" && n != "srt_server" && n != "http_server" && n != "stream_caster" && n != "srt_server"
&& n != "utc_time" && n != "work_dir" && n != "asprocess" && 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()); 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(); 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; return log != SRS_CONSTS_NULL_FILE;
} }
string SrsConfig::get_ffmpeg_log_dir() string SrsConfig::get_ff_log_dir()
{ {
static string DEFAULT = "./objs"; static string DEFAULT = "./objs";
@ -5793,6 +5794,18 @@ string SrsConfig::get_ffmpeg_log_dir()
return conf->arg0(); 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* SrsConfig::get_dash(string vhost)
{ {
SrsConfDirective* conf = get_vhost(vhost); SrsConfDirective* conf = get_vhost(vhost);

View file

@ -786,10 +786,12 @@ public:
// Get the log file path. // Get the log file path.
virtual std::string get_log_file(); virtual std::string get_log_file();
// Whether ffmpeg log enabled // Whether ffmpeg log enabled
virtual bool get_ffmpeg_log_enabled(); virtual bool get_ff_log_enabled();
// The ffmpeg log dir. // The ffmpeg log dir.
// @remark, /dev/null to disable it. // @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. // The MPEG-DASH section.
private: private:
virtual SrsConfDirective* get_dash(std::string vhost); 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 std::string log_file = SRS_CONSTS_NULL_FILE; // disabled
// write ffmpeg info to log file. // write ffmpeg info to log file.
if (_srs_config->get_ffmpeg_log_enabled()) { if (_srs_config->get_ff_log_enabled()) {
log_file = _srs_config->get_ffmpeg_log_dir(); log_file = _srs_config->get_ff_log_dir();
log_file += "/"; log_file += "/";
log_file += "ffmpeg-encoder"; log_file += "ffmpeg-encoder";
log_file += "-"; log_file += "-";

View file

@ -82,9 +82,9 @@ SrsFFMPEG::~SrsFFMPEG()
srs_freep(process); 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) void SrsFFMPEG::set_oformat(string format)
@ -230,8 +230,11 @@ srs_error_t SrsFFMPEG::start()
params.push_back(ffmpeg); params.push_back(ffmpeg);
// input params // input params
if (!_iparams.empty()) { for (int i = 0; i < iparams.size(); i++) {
params.push_back(_iparams); string iparam = iparams.at(i);
if (!iparam.empty()) {
params.push_back(iparam);
}
} }
// build the perfile // build the perfile

View file

@ -45,7 +45,7 @@ private:
std::string log_file; std::string log_file;
private: private:
std::string ffmpeg; std::string ffmpeg;
std::string _iparams; std::vector<std::string> iparams;
std::vector<std::string> perfile; std::vector<std::string> perfile;
std::string iformat; std::string iformat;
std::string input; std::string input;
@ -70,7 +70,7 @@ public:
SrsFFMPEG(std::string ffmpeg_bin); SrsFFMPEG(std::string ffmpeg_bin);
virtual ~SrsFFMPEG(); virtual ~SrsFFMPEG();
public: public:
virtual void set_iparams(std::string iparams); virtual void append_iparam(std::string iparam);
virtual void set_oformat(std::string format); virtual void set_oformat(std::string format);
virtual std::string output(); virtual std::string output();
public: public:

View file

@ -809,6 +809,11 @@ SrsLiveEntry::SrsLiveEntry(std::string m)
_is_aac = (ext == ".aac"); _is_aac = (ext == ".aac");
} }
SrsLiveEntry::~SrsLiveEntry()
{
srs_freep(req);
}
bool SrsLiveEntry::is_flv() bool SrsLiveEntry::is_flv()
{ {
return _is_flv; return _is_flv;
@ -846,7 +851,6 @@ SrsHttpStreamServer::~SrsHttpStreamServer()
std::map<std::string, SrsLiveEntry*>::iterator it; std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = tflvs.begin(); it != tflvs.end(); ++it) { for (it = tflvs.begin(); it != tflvs.end(); ++it) {
SrsLiveEntry* entry = it->second; SrsLiveEntry* entry = it->second;
srs_freep(entry->req);
srs_freep(entry); srs_freep(entry);
} }
tflvs.clear(); tflvs.clear();
@ -901,7 +905,9 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/"); mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
entry = new SrsLiveEntry(mount); entry = new SrsLiveEntry(mount);
entry->source = s;
entry->req = r->copy()->as_http();
entry->cache = new SrsBufferCache(s, r); entry->cache = new SrsBufferCache(s, r);
entry->stream = new SrsLiveStream(s, r, entry->cache); entry->stream = new SrsLiveStream(s, r, entry->cache);
@ -971,7 +977,8 @@ srs_error_t SrsHttpStreamServer::on_reload_vhost_added(string vhost)
srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost) srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
// Create new vhost.
if (tflvs.find(vhost) == tflvs.end()) { if (tflvs.find(vhost) == tflvs.end()) {
if ((err = initialize_flv_entry(vhost)) != srs_success) { if ((err = initialize_flv_entry(vhost)) != srs_success) {
return srs_error_wrap(err, "init flv entry"); return srs_error_wrap(err, "init flv entry");
@ -981,41 +988,27 @@ srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost
// and do mount automatically on playing http flv if this stream is a new http_remux stream. // and do mount automatically on playing http flv if this stream is a new http_remux stream.
return err; return err;
} }
SrsLiveEntry* tmpl = tflvs[vhost]; // Update all streams for exists vhost.
SrsRequest* req = tmpl->req; // TODO: FIMXE: If url changed, needs more things to deal with.
SrsSource* source = tmpl->source; std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = sflvs.begin(); it != sflvs.end(); ++it) {
if (source && req) { SrsLiveEntry* entry = it->second;
// cleanup the exists http remux. if (!entry || !entry->req || !entry->source) {
http_unmount(source, req); continue;
} }
if (!_srs_config->get_vhost_http_remux_enabled(vhost)) { SrsRequest* req = entry->req;
return err; if (!req || req->vhost != vhost) {
} continue;
}
string old_tmpl_mount = tmpl->mount;
string new_tmpl_mount = _srs_config->get_vhost_http_remux_mount(vhost); SrsSource* source = entry->source;
if (_srs_config->get_vhost_http_remux_enabled(vhost)) {
/** http_mount(source, req);
* TODO: not support to reload different mount url for the time being. } else {
* if the mount is change, need more logical thing to deal with. http_unmount(source, req);
* 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()); srs_trace("vhost %s http_remux reload success", vhost.c_str());

View file

@ -207,7 +207,9 @@ private:
bool _is_aac; bool _is_aac;
bool _is_mp3; bool _is_mp3;
public: public:
// We will free the request.
SrsRequest* req; SrsRequest* req;
// Shared source.
SrsSource* source; SrsSource* source;
public: public:
// For template, the mount contains variables. // For template, the mount contains variables.
@ -218,6 +220,7 @@ public:
SrsBufferCache* cache; SrsBufferCache* cache;
SrsLiveEntry(std::string m); SrsLiveEntry(std::string m);
virtual ~SrsLiveEntry();
bool is_flv(); bool is_flv();
bool is_ts(); 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 std::string log_file = SRS_CONSTS_NULL_FILE; // disabled
// write ffmpeg info to log file. // write ffmpeg info to log file.
if (_srs_config->get_ffmpeg_log_enabled()) { if (_srs_config->get_ff_log_enabled()) {
log_file = _srs_config->get_ffmpeg_log_dir(); log_file = _srs_config->get_ff_log_dir();
log_file += "/"; log_file += "/";
log_file += "ffmpeg-ingest"; log_file += "ffmpeg-ingest";
log_file += "-"; log_file += "-";
@ -409,7 +409,13 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
log_file += stream; log_file += stream;
log_file += ".log"; 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 // input
std::string input_type = _srs_config->get_ingest_input_type(ingest); std::string input_type = _srs_config->get_ingest_input_type(ingest);
if (input_type.empty()) { if (input_type.empty()) {
@ -423,7 +429,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
} }
// for file, set re. // for file, set re.
ffmpeg->set_iparams("-re"); ffmpeg->append_iparam("-re");
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg"); return srs_error_wrap(err, "init ffmpeg");
@ -435,7 +441,7 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
} }
// for stream, no re. // for stream, no re.
ffmpeg->set_iparams(""); ffmpeg->append_iparam("");
if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) { if ((err = ffmpeg->initialize(input_url, output, log_file)) != srs_success) {
return srs_error_wrap(err, "init ffmpeg"); 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. // redirect the fd to file.
int fd = -1; 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; mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
if ((fd = ::open(from_file.c_str(), flags, mode)) < 0) { if ((fd = ::open(from_file.c_str(), flags, mode)) < 0) {
@ -197,10 +197,7 @@ srs_error_t SrsProcess::start()
// ignore the SIGINT and SIGTERM // ignore the SIGINT and SIGTERM
signal(SIGINT, SIG_IGN); signal(SIGINT, SIG_IGN);
signal(SIGTERM, SIG_IGN); signal(SIGTERM, SIG_IGN);
// for the stdin,
// should never close it or ffmpeg will error.
// for the stdout, ignore when not specified. // for the stdout, ignore when not specified.
// redirect stdout to file if possible. // redirect stdout to file if possible.
if ((err = srs_redirect_output(stdout_file, STDOUT_FILENO)) != srs_success) { if ((err = srs_redirect_output(stdout_file, STDOUT_FILENO)) != srs_success) {
@ -212,16 +209,22 @@ srs_error_t SrsProcess::start()
if ((err = srs_redirect_output(stderr_file, STDERR_FILENO)) != srs_success) { if ((err = srs_redirect_output(stderr_file, STDERR_FILENO)) != srs_success) {
return srs_error_wrap(err, "redirect output"); 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. // should never close the fd 3+, for it myabe used.
// for fd should close at exec, use fnctl to set it. // for fd should close at exec, use fnctl to set it.
// log basic info to stderr. // log basic info to stderr.
if (true) { if (true) {
fprintf(stderr, "\n"); fprintf(stdout, "\n");
fprintf(stderr, "process ppid=%d, cid=%d, pid=%d\n", ppid, cid, getpid()); fprintf(stdout, "process ppid=%d, cid=%d, pid=%d, in=%d, out=%d, err=%d\n",
fprintf(stderr, "process binary=%s, cli: %s\n", bin.c_str(), cli.c_str()); ppid, cid, getpid(), STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO);
fprintf(stderr, "process actual cli: %s\n", actual_cli.c_str()); 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. // memory leak in child process, it's ok.

View file

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

View file

@ -888,6 +888,11 @@ VOID TEST(ConfigMainTest, CheckConf_ff_log_dir)
MockSrsConfig conf; MockSrsConfig conf;
HELPER_ASSERT_FAILED(conf.parse(_MIN_OK_CONF "ff_log_dirs ./objs;")); 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) VOID TEST(ConfigMainTest, CheckConf_srs_log_level)
@ -3503,12 +3508,13 @@ VOID TEST(ConfigMainTest, CheckVhostConfig5)
if (true) { if (true) {
MockSrsConfig conf; 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_TRUE(conf.get_log_tank_file());
EXPECT_STREQ("xxx2", conf.get_log_level().c_str()); EXPECT_STREQ("xxx2", conf.get_log_level().c_str());
EXPECT_STREQ("xxx3", conf.get_log_file().c_str()); EXPECT_STREQ("xxx3", conf.get_log_file().c_str());
EXPECT_STREQ("xxx4", conf.get_ffmpeg_log_dir().c_str()); EXPECT_STREQ("xxx4", conf.get_ff_log_dir().c_str());
EXPECT_TRUE(conf.get_ffmpeg_log_enabled()); EXPECT_STREQ("xxx5", conf.get_ff_log_level().c_str());
EXPECT_TRUE(conf.get_ff_log_enabled());
} }
if (true) { if (true) {