winlin

fix bug of reload ffmpeg, support multiple transcode, change to 0.9.57

@@ -612,22 +612,10 @@ int SrsConfig::reload() @@ -612,22 +612,10 @@ int SrsConfig::reload()
612 } 612 }
613 srs_trace("vhost %s reload hls success.", vhost.c_str()); 613 srs_trace("vhost %s reload hls success.", vhost.c_str());
614 } 614 }
615 - // TODO: FIXME: there might be many transcoders per vhost.  
616 - // transcode, only one per vhost  
617 - if (!srs_directive_equals(new_vhost->get("transcode"), old_vhost->get("transcode"))) {  
618 - for (it = subscribes.begin(); it != subscribes.end(); ++it) {  
619 - ISrsReloadHandler* subscribe = *it;  
620 - if ((ret = subscribe->on_reload_transcode(vhost)) != ERROR_SUCCESS) {  
621 - srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret);  
622 - return ret;  
623 - }  
624 - }  
625 - srs_trace("vhost %s reload transcode success.", vhost.c_str());  
626 - }  
627 // transcode, many per vhost. 615 // transcode, many per vhost.
628 - /*if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) { 616 + if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) {
629 return ret; 617 return ret;
630 - }*/ 618 + }
631 // ingest, many per vhost. 619 // ingest, many per vhost.
632 if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) { 620 if ((ret = reload_ingest(new_vhost, old_vhost)) != ERROR_SUCCESS) {
633 return ret; 621 return ret;
@@ -698,6 +686,90 @@ int SrsConfig::parse_options(int argc, char** argv) @@ -698,6 +686,90 @@ int SrsConfig::parse_options(int argc, char** argv)
698 return parse_file(config_file.c_str()); 686 return parse_file(config_file.c_str());
699 } 687 }
700 688
  689 +int SrsConfig::reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
  690 +{
  691 + int ret = ERROR_SUCCESS;
  692 +
  693 + std::vector<SrsConfDirective*> old_transcoders;
  694 + for (int i = 0; i < (int)old_vhost->directives.size(); i++) {
  695 + SrsConfDirective* conf = old_vhost->at(i);
  696 + if (conf->name == "transcode") {
  697 + old_transcoders.push_back(conf);
  698 + }
  699 + }
  700 +
  701 + std::vector<SrsConfDirective*> new_transcoders;
  702 + for (int i = 0; i < (int)new_vhost->directives.size(); i++) {
  703 + SrsConfDirective* conf = new_vhost->at(i);
  704 + if (conf->name == "transcode") {
  705 + new_transcoders.push_back(conf);
  706 + }
  707 + }
  708 +
  709 + std::vector<ISrsReloadHandler*>::iterator it;
  710 +
  711 + std::string vhost = new_vhost->arg0();
  712 +
  713 + // to be simple:
  714 + // whatever, once tiny changed of transcode,
  715 + // restart all ffmpeg of vhost.
  716 + bool changed = false;
  717 +
  718 + // discovery the removed ffmpeg.
  719 + for (int i = 0; !changed && i < (int)old_transcoders.size(); i++) {
  720 + SrsConfDirective* old_transcoder = old_transcoders.at(i);
  721 + std::string transcoder_id = old_transcoder->arg0();
  722 +
  723 + // if transcoder exists in new vhost, not removed, ignore.
  724 + if (new_vhost->get("transcode", transcoder_id)) {
  725 + continue;
  726 + }
  727 +
  728 + changed = true;
  729 + }
  730 +
  731 + // discovery the added ffmpeg.
  732 + for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
  733 + SrsConfDirective* new_transcoder = new_transcoders.at(i);
  734 + std::string transcoder_id = new_transcoder->arg0();
  735 +
  736 + // if transcoder exists in old vhost, not added, ignore.
  737 + if (old_vhost->get("transcode", transcoder_id)) {
  738 + continue;
  739 + }
  740 +
  741 + changed = true;
  742 + }
  743 +
  744 + // for updated transcoders, restart them.
  745 + for (int i = 0; !changed && i < (int)new_transcoders.size(); i++) {
  746 + SrsConfDirective* new_transcoder = new_transcoders.at(i);
  747 + std::string transcoder_id = new_transcoder->arg0();
  748 + SrsConfDirective* old_transcoder = old_vhost->get("transcode", transcoder_id);
  749 + srs_assert(old_transcoder);
  750 +
  751 + if (srs_directive_equals(new_transcoder, old_transcoder)) {
  752 + continue;
  753 + }
  754 +
  755 + changed = true;
  756 + }
  757 +
  758 + // transcode, many per vhost
  759 + if (changed) {
  760 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  761 + ISrsReloadHandler* subscribe = *it;
  762 + if ((ret = subscribe->on_reload_transcode(vhost)) != ERROR_SUCCESS) {
  763 + srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret);
  764 + return ret;
  765 + }
  766 + }
  767 + srs_trace("vhost %s reload transcode success.", vhost.c_str());
  768 + }
  769 +
  770 + return ret;
  771 +}
  772 +
701 int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost) 773 int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost)
702 { 774 {
703 int ret = ERROR_SUCCESS; 775 int ret = ERROR_SUCCESS;
@@ -789,7 +861,7 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_ @@ -789,7 +861,7 @@ int SrsConfig::reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_
789 srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str()); 861 srs_trace("vhost %s reload ingest=%s updated success.", vhost.c_str(), ingest_id.c_str());
790 } 862 }
791 863
792 - srs_warn("invalid reload ingest vhost=%s", vhost.c_str()); 864 + srs_trace("ingest not changed for vhost=%s", vhost.c_str());
793 865
794 return ret; 866 return ret;
795 } 867 }
@@ -126,6 +126,7 @@ public: @@ -126,6 +126,7 @@ public:
126 virtual int parse_options(int argc, char** argv); 126 virtual int parse_options(int argc, char** argv);
127 private: 127 private:
128 virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost); 128 virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
  129 + virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
129 virtual int parse_file(const char* filename); 130 virtual int parse_file(const char* filename);
130 virtual int parse_argv(int& i, char** argv); 131 virtual int parse_argv(int& i, char** argv);
131 virtual void print_help(char** argv); 132 virtual void print_help(char** argv);
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "56" 34 +#define VERSION_REVISION "57"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"