From e0a6fe63cc86fe4c8e13271f1463723e9c4da52d Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 10 Apr 2014 11:40:06 +0800 Subject: [PATCH] fix bug of reload ffmpeg, support multiple transcode, change to 0.9.57 --- trunk/src/app/srs_app_config.cpp | 102 ++++++++++++++++++++++++++----- trunk/src/app/srs_app_config.hpp | 1 + trunk/src/core/srs_core.hpp | 2 +- 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 9d3e1cb49..e9262abca 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -612,22 +612,10 @@ int SrsConfig::reload() } srs_trace("vhost %s reload hls success.", vhost.c_str()); } - // TODO: FIXME: there might be many transcoders per vhost. - // transcode, only one per vhost - if (!srs_directive_equals(new_vhost->get("transcode"), old_vhost->get("transcode"))) { - for (it = subscribes.begin(); it != subscribes.end(); ++it) { - ISrsReloadHandler* subscribe = *it; - if ((ret = subscribe->on_reload_transcode(vhost)) != ERROR_SUCCESS) { - srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret); - return ret; - } - } - srs_trace("vhost %s reload transcode success.", vhost.c_str()); - } // transcode, many per vhost. - /*if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { + if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { return ret; - }*/ + } // ingest, many per vhost. if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) { return ret; @@ -698,6 +686,90 @@ int SrsConfig::parse_options(int argc, char** argv) return parse_file(config_file.c_str()); } +int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) +{ + int ret = ERROR_SUCCESS; + + std::vector old_transcoders; + for (int i = 0; i < (int)old_vhost->directives.size(); i++) { + SrsConfDirective* conf = old_vhost->at(i); + if (conf->name == "transcode") { + old_transcoders.push_back(conf); + } + } + + std::vector new_transcoders; + for (int i = 0; i < (int)new_vhost->directives.size(); i++) { + SrsConfDirective* conf = new_vhost->at(i); + if (conf->name == "transcode") { + new_transcoders.push_back(conf); + } + } + + std::vector::iterator it; + + std::string vhost = new_vhost->arg0(); + + // to be simple: + // whatever, once tiny changed of transcode, + // restart all ffmpeg of vhost. + bool changed = false; + + // discovery the removed ffmpeg. + for (int i = 0; !changed && i < (int)old_transcoders.size(); i++) { + SrsConfDirective* old_transcoder = old_transcoders.at(i); + std::string transcoder_id = old_transcoder->arg0(); + + // if transcoder exists in new vhost, not removed, ignore. + if (new_vhost->get("transcode", transcoder_id)) { + continue; + } + + changed = true; + } + + // discovery the added ffmpeg. + for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) { + SrsConfDirective* new_transcoder = new_transcoders.at(i); + std::string transcoder_id = new_transcoder->arg0(); + + // if transcoder exists in old vhost, not added, ignore. + if (old_vhost->get("transcode", transcoder_id)) { + continue; + } + + changed = true; + } + + // for updated transcoders, restart them. + for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) { + SrsConfDirective* new_transcoder = new_transcoders.at(i); + std::string transcoder_id = new_transcoder->arg0(); + SrsConfDirective* old_transcoder = old_vhost->get("transcode", transcoder_id); + srs_assert(old_transcoder); + + if (srs_directive_equals(new_transcoder, old_transcoder)) { + continue; + } + + changed = true; + } + + // transcode, many per vhost + if (changed) { + for (it = subscribes.begin(); it != subscribes.end(); ++it) { + ISrsReloadHandler* subscribe = *it; + if ((ret = subscribe->on_reload_transcode(vhost)) != ERROR_SUCCESS) { + srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret); + return ret; + } + } + srs_trace("vhost %s reload transcode success.", vhost.c_str()); + } + + return ret; +} + int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) { int ret = ERROR_SUCCESS; @@ -789,7 +861,7 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_ srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str()); } - srs_warn("invalid reload ingest vhost=%s", vhost.c_str()); + srs_trace("ingest not changed for vhost=%s", vhost.c_str()); return ret; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index ae5af8287..98524101b 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -126,6 +126,7 @@ public: virtual int parse_options(int argc, char** argv); private: virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); + virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); virtual int parse_file(const char* filename); virtual int parse_argv(int& i, char** argv); virtual void print_help(char** argv); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index f50d2c2e7..ffc8c6b0f 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR "0" #define VERSION_MINOR "9" -#define VERSION_REVISION "56" +#define VERSION_REVISION "57" #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION // server info. #define RTMP_SIG_SRS_KEY "srs"