1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-24 06:54:22 +00:00

Merge branch 'develop' into min

This commit is contained in:
winlin 2020-02-09 18:33:10 +08:00
commit cd48bf8aed
18 changed files with 188 additions and 81 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();
@ -902,6 +906,8 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsSource* s, SrsRequest* r)
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);
@ -972,6 +978,7 @@ 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");
@ -982,40 +989,26 @@ srs_error_t SrsHttpStreamServer::on_reload_vhost_http_remux_updated(string vhost
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 += "-";
@ -410,6 +410,12 @@ srs_error_t SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective*
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) {
@ -198,9 +198,6 @@ srs_error_t SrsProcess::start()
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) {
@ -213,15 +210,21 @@ srs_error_t SrsProcess::start()
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

@ -1,13 +1,22 @@
#include "srt_data.hpp" #include "srt_data.hpp"
#include <string.h> #include <string.h>
SRT_DATA_MSG::SRT_DATA_MSG(unsigned int len, const std::string& path):_len(len) SRT_DATA_MSG::SRT_DATA_MSG(const std::string& path, unsigned int msg_type):_msg_type(msg_type)
,_len(0)
,_data_p(nullptr)
,_key_path(path) {
}
SRT_DATA_MSG::SRT_DATA_MSG(unsigned int len, const std::string& path, unsigned int msg_type):_msg_type(msg_type)
,_len(len)
,_key_path(path) { ,_key_path(path) {
_data_p = new unsigned char[len]; _data_p = new unsigned char[len];
memset(_data_p, 0, len); memset(_data_p, 0, len);
} }
SRT_DATA_MSG::SRT_DATA_MSG(unsigned char* data_p, unsigned int len, const std::string& path):_len(len) SRT_DATA_MSG::SRT_DATA_MSG(unsigned char* data_p, unsigned int len, const std::string& path, unsigned int msg_type):_msg_type(msg_type)
,_len(len)
,_key_path(path) ,_key_path(path)
{ {
_data_p = new unsigned char[len]; _data_p = new unsigned char[len];
@ -15,7 +24,13 @@ SRT_DATA_MSG::SRT_DATA_MSG(unsigned char* data_p, unsigned int len, const std::s
} }
SRT_DATA_MSG::~SRT_DATA_MSG() { SRT_DATA_MSG::~SRT_DATA_MSG() {
delete _data_p; if (_data_p && (_len > 0)) {
delete _data_p;
}
}
unsigned int SRT_DATA_MSG::msg_type() {
return _msg_type;
} }
std::string SRT_DATA_MSG::get_path() { std::string SRT_DATA_MSG::get_path() {

View file

@ -3,17 +3,23 @@
#include <string> #include <string>
#include <memory> #include <memory>
#define SRT_MSG_DATA_TYPE 0x01
#define SRT_MSG_CLOSE_TYPE 0x02
class SRT_DATA_MSG { class SRT_DATA_MSG {
public: public:
SRT_DATA_MSG(unsigned int len, const std::string& path); SRT_DATA_MSG(const std::string& path, unsigned int msg_type=SRT_MSG_DATA_TYPE);
SRT_DATA_MSG(unsigned char* data_p, unsigned int len, const std::string& path); SRT_DATA_MSG(unsigned int len, const std::string& path, unsigned int msg_type=SRT_MSG_DATA_TYPE);
SRT_DATA_MSG(unsigned char* data_p, unsigned int len, const std::string& path, unsigned int msg_type=SRT_MSG_DATA_TYPE);
~SRT_DATA_MSG(); ~SRT_DATA_MSG();
unsigned int msg_type();
unsigned int data_len(); unsigned int data_len();
unsigned char* get_data(); unsigned char* get_data();
std::string get_path(); std::string get_path();
private: private:
unsigned int _msg_type;
unsigned int _len; unsigned int _len;
unsigned char* _data_p; unsigned char* _data_p;
std::string _key_path; std::string _key_path;

View file

@ -17,8 +17,8 @@
static bool MONITOR_STATICS_ENABLE = false; static bool MONITOR_STATICS_ENABLE = false;
static long long MONITOR_TIMEOUT = 5000; static long long MONITOR_TIMEOUT = 5000;
const unsigned int DEF_DATA_SIZE = 188*7; const unsigned int DEF_DATA_SIZE = 188*7;
const long long CHECK_ALIVE_INTERVAL = 10*1000; const long long CHECK_ALIVE_INTERVAL = 5*1000;
const long long CHECK_ALIVE_TIMEOUT = 15*1000; const long long CHECK_ALIVE_TIMEOUT = 5*1000;
long long srt_now_ms = 0; long long srt_now_ms = 0;
@ -236,6 +236,10 @@ void srt_handle::onwork()
add_newconn(msg.conn_ptr, msg.events); add_newconn(msg.conn_ptr, msg.events);
} }
if (_conn_map.empty()) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
continue;
}
check_alive(); check_alive();
ret = srt_epoll_wait(_handle_pollid, read_fds, &rfd_num, write_fds, &wfd_num, ret = srt_epoll_wait(_handle_pollid, read_fds, &rfd_num, write_fds, &wfd_num,
@ -243,7 +247,6 @@ void srt_handle::onwork()
if (ret < 0) { if (ret < 0) {
srs_info("srt handle epoll is timeout, ret=%d, srt_now_ms=%ld", srs_info("srt handle epoll is timeout, ret=%d, srt_now_ms=%ld",
ret, srt_now_ms); ret, srt_now_ms);
std::this_thread::sleep_for(std::chrono::milliseconds(30));
continue; continue;
} }
@ -376,6 +379,7 @@ void srt_handle::close_push_conn(SRTSOCKET srtsocket) {
_push_conn_map.erase(push_iter); _push_conn_map.erase(push_iter);
} }
_conn_map.erase(iter); _conn_map.erase(iter);
srt2rtmp::get_instance()->insert_ctrl_message(SRT_MSG_CLOSE_TYPE, conn_ptr->get_subpath());
conn_ptr->close(); conn_ptr->close();
} }

View file

@ -61,6 +61,14 @@ void srt2rtmp::insert_data_message(unsigned char* data_p, unsigned int len, cons
return; return;
} }
void srt2rtmp::insert_ctrl_message(unsigned int msg_type, const std::string& key_path) {
std::unique_lock<std::mutex> locker(_mutex);
SRT_DATA_MSG_PTR msg_ptr = std::make_shared<SRT_DATA_MSG>(key_path, msg_type);
_msg_queue.push(msg_ptr);
//_notify_cond.notify_one();
return;
}
SRT_DATA_MSG_PTR srt2rtmp::get_data_message() { SRT_DATA_MSG_PTR srt2rtmp::get_data_message() {
std::unique_lock<std::mutex> locker(_mutex); std::unique_lock<std::mutex> locker(_mutex);
SRT_DATA_MSG_PTR msg_ptr; SRT_DATA_MSG_PTR msg_ptr;
@ -79,8 +87,8 @@ SRT_DATA_MSG_PTR srt2rtmp::get_data_message() {
} }
void srt2rtmp::check_rtmp_alive() { void srt2rtmp::check_rtmp_alive() {
const int64_t CHECK_INTERVAL = 15*1000; const int64_t CHECK_INTERVAL = 5*1000;
const int64_t ALIVE_TIMEOUT_MAX = 20*1000; const int64_t ALIVE_TIMEOUT_MAX = 5*1000;
if (_lastcheck_ts == 0) { if (_lastcheck_ts == 0) {
_lastcheck_ts = now_ms(); _lastcheck_ts = now_ms();
@ -108,6 +116,22 @@ void srt2rtmp::check_rtmp_alive() {
return; return;
} }
void srt2rtmp::handle_close_rtmpsession(const std::string& key_path) {
RTMP_CLIENT_PTR rtmp_ptr;
auto iter = _rtmp_client_map.find(key_path);
if (iter == _rtmp_client_map.end()) {
srs_error("fail to close rtmp session fail, can't find session by key_path:%s",
key_path.c_str());
return;
}
rtmp_ptr = iter->second;
_rtmp_client_map.erase(iter);
srs_trace("close rtmp session which key_path is %s", key_path.c_str());
rtmp_ptr->close();
return;
}
//the cycle is running in srs coroutine //the cycle is running in srs coroutine
srs_error_t srt2rtmp::cycle() { srs_error_t srt2rtmp::cycle() {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -119,7 +143,25 @@ srs_error_t srt2rtmp::cycle() {
if (!msg_ptr) { if (!msg_ptr) {
srs_usleep((30 * SRS_UTIME_MILLISECONDS)); srs_usleep((30 * SRS_UTIME_MILLISECONDS));
} else { } else {
handle_ts_data(msg_ptr); switch (msg_ptr->msg_type()) {
case SRT_MSG_DATA_TYPE:
{
handle_ts_data(msg_ptr);
break;
}
case SRT_MSG_CLOSE_TYPE:
{
handle_close_rtmpsession(msg_ptr->get_path());
break;
}
default:
{
srs_error("srt to rtmp get wrong message type(%u), path:%s",
msg_ptr->msg_type(), msg_ptr->get_path().c_str());
assert(0);
}
}
} }
check_rtmp_alive(); check_rtmp_alive();
if ((err = _trd_ptr->pull()) != srs_success) { if ((err = _trd_ptr->pull()) != srs_success) {

View file

@ -85,11 +85,13 @@ public:
void release(); void release();
void insert_data_message(unsigned char* data_p, unsigned int len, const std::string& key_path); void insert_data_message(unsigned char* data_p, unsigned int len, const std::string& key_path);
void insert_ctrl_message(unsigned int msg_type, const std::string& key_path);
private: private:
SRT_DATA_MSG_PTR get_data_message(); SRT_DATA_MSG_PTR get_data_message();
virtual srs_error_t cycle(); virtual srs_error_t cycle();
void handle_ts_data(SRT_DATA_MSG_PTR data_ptr); void handle_ts_data(SRT_DATA_MSG_PTR data_ptr);
void handle_close_rtmpsession(const std::string& key_path);
void check_rtmp_alive(); void check_rtmp_alive();
private: private:

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