mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #209, server cycle to enable the hls to cleanup. do dispose
This commit is contained in:
parent
567d84e997
commit
d611bb6b45
8 changed files with 109 additions and 3 deletions
|
@ -618,9 +618,14 @@ vhost with-hls.srs.com {
|
|||
# h264, vn
|
||||
# default: h264
|
||||
hls_vcodec h264;
|
||||
# whether cleanup the old ts files.
|
||||
# whether cleanup the old expired ts files.
|
||||
# default: on
|
||||
hls_cleanup on;
|
||||
# the timeout in seconds to dispose the hls,
|
||||
# dispose is to remove all hls files, m3u8 and ts files.
|
||||
# when timeout or server terminate, dispose hls.
|
||||
# default: 300
|
||||
hls_dispose 300;
|
||||
# the max size to notify hls,
|
||||
# to read max bytes from ts of specified cdn network,
|
||||
# @remark only used when on_hls_notify is config.
|
||||
|
|
|
@ -1564,7 +1564,8 @@ int SrsConfig::check_config()
|
|||
string m = conf->at(j)->name.c_str();
|
||||
if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error"
|
||||
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
|
||||
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" && m != "hls_wait_keyframe"
|
||||
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
|
||||
&& m != "hls_wait_keyframe" && m != "hls_dispose"
|
||||
) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret);
|
||||
|
@ -3561,6 +3562,24 @@ bool SrsConfig::get_hls_cleanup(string vhost)
|
|||
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
||||
}
|
||||
|
||||
int SrsConfig::get_hls_dispose(string vhost)
|
||||
{
|
||||
SrsConfDirective* conf = get_hls(vhost);
|
||||
|
||||
int DEFAULT = 300;
|
||||
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("hls_dispose");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return ::atoi(conf->arg0().c_str());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_hls_wait_keyframe(string vhost)
|
||||
{
|
||||
SrsConfDirective* hls = get_hls(vhost);
|
||||
|
|
|
@ -984,6 +984,10 @@ public:
|
|||
* whether cleanup the old ts files.
|
||||
*/
|
||||
virtual bool get_hls_cleanup(std::string vhost);
|
||||
/**
|
||||
* the timeout to dispose the hls.
|
||||
*/
|
||||
virtual int get_hls_dispose(std::string vhost);
|
||||
/**
|
||||
* whether reap the ts when got keyframe.
|
||||
*/
|
||||
|
|
|
@ -1109,6 +1109,19 @@ SrsHls::~SrsHls()
|
|||
srs_freep(pprint);
|
||||
}
|
||||
|
||||
void SrsHls::dispose()
|
||||
{
|
||||
}
|
||||
|
||||
int SrsHls::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
srs_info("hls cycle for source %d", source->source_id());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsHls::initialize(SrsSource* s, ISrsHlsHandler* h)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
|
@ -402,6 +402,9 @@ private:
|
|||
public:
|
||||
SrsHls();
|
||||
virtual ~SrsHls();
|
||||
public:
|
||||
virtual void dispose();
|
||||
virtual int cycle();
|
||||
public:
|
||||
/**
|
||||
* initialize the hls by handler and source.
|
||||
|
|
|
@ -562,9 +562,12 @@ void SrsServer::dispose()
|
|||
|
||||
#ifdef SRS_AUTO_INGEST
|
||||
ingester->dispose();
|
||||
srs_trace("gracefully cleanup ingesters");
|
||||
srs_trace("gracefully dispose ingesters");
|
||||
#endif
|
||||
|
||||
SrsSource::dispose_all();
|
||||
srs_trace("gracefully dispose sources");
|
||||
|
||||
srs_trace("terminate server");
|
||||
}
|
||||
|
||||
|
@ -962,6 +965,11 @@ int SrsServer::do_cycle()
|
|||
srs_trace("reload config success.");
|
||||
}
|
||||
|
||||
// notice the stream sources to cycle.
|
||||
if ((ret = SrsSource::cycle_all()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// update the cache time
|
||||
if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) {
|
||||
srs_info("update current time cache.");
|
||||
|
|
|
@ -771,6 +771,32 @@ SrsSource* SrsSource::fetch(std::string vhost, std::string app, std::string stre
|
|||
return source;
|
||||
}
|
||||
|
||||
void SrsSource::dispose_all()
|
||||
{
|
||||
std::map<std::string, SrsSource*>::iterator it;
|
||||
for (it = pool.begin(); it != pool.end(); ++it) {
|
||||
SrsSource* source = it->second;
|
||||
source->dispose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int SrsSource::cycle_all()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// TODO: FIXME: support remove dead source for a long time.
|
||||
std::map<std::string, SrsSource*>::iterator it;
|
||||
for (it = pool.begin(); it != pool.end(); ++it) {
|
||||
SrsSource* source = it->second;
|
||||
if ((ret = source->cycle()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SrsSource::destroy()
|
||||
{
|
||||
std::map<std::string, SrsSource*>::iterator it;
|
||||
|
@ -909,6 +935,26 @@ SrsSource::~SrsSource()
|
|||
srs_freep(_req);
|
||||
}
|
||||
|
||||
void SrsSource::dispose()
|
||||
{
|
||||
#ifdef SRS_AUTO_HLS
|
||||
hls->dispose();
|
||||
#endif
|
||||
}
|
||||
|
||||
int SrsSource::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_AUTO_HLS
|
||||
if ((ret = hls->cycle()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
|
@ -410,6 +410,11 @@ public:
|
|||
* get the exists source by stream info(vhost, app, stream), NULL when not exists.
|
||||
*/
|
||||
static SrsSource* fetch(std::string vhost, std::string app, std::string stream);
|
||||
/**
|
||||
* dispose and cycle all sources.
|
||||
*/
|
||||
static void dispose_all();
|
||||
static int cycle_all();
|
||||
/**
|
||||
* when system exit, destroy the sources,
|
||||
* for gmc to analysis mem leaks.
|
||||
|
@ -486,6 +491,9 @@ private:
|
|||
public:
|
||||
SrsSource();
|
||||
virtual ~SrsSource();
|
||||
public:
|
||||
virtual void dispose();
|
||||
virtual int cycle();
|
||||
// initialize, get and setter.
|
||||
public:
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue