mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
for #319, when reload the listen, restart all ingesters.
This commit is contained in:
parent
310b5a14cb
commit
342483bf04
2 changed files with 37 additions and 2 deletions
|
@ -106,6 +106,8 @@ SrsIngester::SrsIngester()
|
|||
{
|
||||
_srs_config->subscribe(this);
|
||||
|
||||
expired = false;
|
||||
|
||||
pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US);
|
||||
pprint = SrsPithyPrint::create_ingester();
|
||||
}
|
||||
|
@ -222,9 +224,8 @@ int SrsIngester::parse_engines(SrsConfDirective* vhost, SrsConfDirective* ingest
|
|||
return ret;
|
||||
}
|
||||
|
||||
void SrsIngester::dispose()
|
||||
void SrsIngester::fast_stop()
|
||||
{
|
||||
// first, use fast stop to notice all FFMPEG to quit gracefully.
|
||||
std::vector<SrsIngesterFFMPEG*>::iterator it;
|
||||
for (it = ingesters.begin(); it != ingesters.end(); ++it) {
|
||||
SrsIngesterFFMPEG* ingester = *it;
|
||||
|
@ -234,6 +235,12 @@ void SrsIngester::dispose()
|
|||
if (!ingesters.empty()) {
|
||||
srs_trace("fast stop all ingesters ok.");
|
||||
}
|
||||
}
|
||||
|
||||
void SrsIngester::dispose()
|
||||
{
|
||||
// first, use fast stop to notice all FFMPEG to quit gracefully.
|
||||
fast_stop();
|
||||
|
||||
// then, use stop to wait FFMPEG quit one by one and send SIGKILL if needed.
|
||||
stop();
|
||||
|
@ -249,6 +256,21 @@ int SrsIngester::cycle()
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// when expired, restart all ingesters.
|
||||
if (expired) {
|
||||
expired = false;
|
||||
|
||||
// stop current ingesters.
|
||||
fast_stop();
|
||||
clear_engines();
|
||||
|
||||
// re-prase the ingesters.
|
||||
if ((ret = parse()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// cycle exists ingesters.
|
||||
std::vector<SrsIngesterFFMPEG*>::iterator it;
|
||||
for (it = ingesters.begin(); it != ingesters.end(); ++it) {
|
||||
SrsIngesterFFMPEG* ingester = *it;
|
||||
|
@ -551,5 +573,11 @@ int SrsIngester::on_reload_ingest_updated(string vhost, string ingest_id)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsIngester::on_reload_listen()
|
||||
{
|
||||
expired = true;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -81,6 +81,10 @@ private:
|
|||
private:
|
||||
SrsReusableThread* pthread;
|
||||
SrsPithyPrint* pprint;
|
||||
// whether the ingesters are expired,
|
||||
// for example, the listen port changed,
|
||||
// all ingesters must be restart.
|
||||
bool expired;
|
||||
public:
|
||||
SrsIngester();
|
||||
virtual ~SrsIngester();
|
||||
|
@ -89,6 +93,8 @@ public:
|
|||
public:
|
||||
virtual int start();
|
||||
virtual void stop();
|
||||
private:
|
||||
virtual void fast_stop();
|
||||
// interface ISrsReusableThreadHandler.
|
||||
public:
|
||||
virtual int cycle();
|
||||
|
@ -107,6 +113,7 @@ public:
|
|||
virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);
|
||||
virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id);
|
||||
virtual int on_reload_ingest_updated(std::string vhost, std::string ingest_id);
|
||||
virtual int on_reload_listen();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue