diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index b24fc3a25..d44751bd4 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -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::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::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 diff --git a/trunk/src/app/srs_app_ingest.hpp b/trunk/src/app/srs_app_ingest.hpp index 15137d035..e6f48f31d 100644 --- a/trunk/src/app/srs_app_ingest.hpp +++ b/trunk/src/app/srs_app_ingest.hpp @@ -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