winlin

support reload the hls/forwarder/transcoder

@@ -559,6 +559,28 @@ int SrsConfig::reload() @@ -559,6 +559,28 @@ int SrsConfig::reload()
559 } 559 }
560 srs_trace("vhost %s reload forward success.", vhost.c_str()); 560 srs_trace("vhost %s reload forward success.", vhost.c_str());
561 } 561 }
  562 + // hls
  563 + if (!srs_directive_equals(new_vhost->get("hls"), old_vhost->get("hls"))) {
  564 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  565 + ISrsReloadHandler* subscribe = *it;
  566 + if ((ret = subscribe->on_reload_hls(vhost)) != ERROR_SUCCESS) {
  567 + srs_error("vhost %s notify subscribes hls failed. ret=%d", vhost.c_str(), ret);
  568 + return ret;
  569 + }
  570 + }
  571 + srs_trace("vhost %s reload hls success.", vhost.c_str());
  572 + }
  573 + // transcode
  574 + if (!srs_directive_equals(new_vhost->get("transcode"), old_vhost->get("transcode"))) {
  575 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  576 + ISrsReloadHandler* subscribe = *it;
  577 + if ((ret = subscribe->on_reload_transcode(vhost)) != ERROR_SUCCESS) {
  578 + srs_error("vhost %s notify subscribes transcode failed. ret=%d", vhost.c_str(), ret);
  579 + return ret;
  580 + }
  581 + }
  582 + srs_trace("vhost %s reload transcode success.", vhost.c_str());
  583 + }
562 // TODO: suppor reload hls/forward/ffmpeg/http 584 // TODO: suppor reload hls/forward/ffmpeg/http
563 continue; 585 continue;
564 } 586 }
@@ -60,3 +60,13 @@ int ISrsReloadHandler::on_reload_forward(string /*vhost*/) @@ -60,3 +60,13 @@ int ISrsReloadHandler::on_reload_forward(string /*vhost*/)
60 return ERROR_SUCCESS; 60 return ERROR_SUCCESS;
61 } 61 }
62 62
  63 +int ISrsReloadHandler::on_reload_hls(string /*vhost*/)
  64 +{
  65 + return ERROR_SUCCESS;
  66 +}
  67 +
  68 +int ISrsReloadHandler::on_reload_transcode(string /*vhost*/)
  69 +{
  70 + return ERROR_SUCCESS;
  71 +}
  72 +
@@ -45,6 +45,8 @@ public: @@ -45,6 +45,8 @@ public:
45 virtual int on_reload_vhost_removed(std::string vhost); 45 virtual int on_reload_vhost_removed(std::string vhost);
46 virtual int on_reload_gop_cache(std::string vhost); 46 virtual int on_reload_gop_cache(std::string vhost);
47 virtual int on_reload_forward(std::string vhost); 47 virtual int on_reload_forward(std::string vhost);
  48 + virtual int on_reload_hls(std::string vhost);
  49 + virtual int on_reload_transcode(std::string vhost);
48 }; 50 };
49 51
50 #endif 52 #endif
@@ -455,6 +455,47 @@ int SrsSource::on_reload_forward(string vhost) @@ -455,6 +455,47 @@ int SrsSource::on_reload_forward(string vhost)
455 return ret; 455 return ret;
456 } 456 }
457 457
  458 +int SrsSource::on_reload_hls(string vhost)
  459 +{
  460 + int ret = ERROR_SUCCESS;
  461 +
  462 + if (req->vhost != vhost) {
  463 + return ret;
  464 + }
  465 +
  466 + // TODO: HLS should continue previous sequence and stream.
  467 +#ifdef SRS_HLS
  468 + hls->on_unpublish();
  469 + if ((ret = hls->on_publish(req)) != ERROR_SUCCESS) {
  470 + srs_error("hls publish failed. ret=%d", ret);
  471 + return ret;
  472 + }
  473 + srs_trace("vhost %s hls reload success", vhost.c_str());
  474 +#endif
  475 +
  476 + return ret;
  477 +}
  478 +
  479 +int SrsSource::on_reload_transcode(string vhost)
  480 +{
  481 + int ret = ERROR_SUCCESS;
  482 +
  483 + if (req->vhost != vhost) {
  484 + return ret;
  485 + }
  486 +
  487 +#ifdef SRS_FFMPEG
  488 + encoder->on_unpublish();
  489 + if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) {
  490 + srs_error("start encoder failed. ret=%d", ret);
  491 + return ret;
  492 + }
  493 + srs_trace("vhost %s transcode reload success", vhost.c_str());
  494 +#endif
  495 +
  496 + return ret;
  497 +}
  498 +
458 bool SrsSource::can_publish() 499 bool SrsSource::can_publish()
459 { 500 {
460 return _can_publish; 501 return _can_publish;
@@ -697,12 +738,14 @@ int SrsSource::on_publish(SrsRequest* _req) @@ -697,12 +738,14 @@ int SrsSource::on_publish(SrsRequest* _req)
697 738
698 #ifdef SRS_FFMPEG 739 #ifdef SRS_FFMPEG
699 if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) { 740 if ((ret = encoder->on_publish(req)) != ERROR_SUCCESS) {
  741 + srs_error("start encoder failed. ret=%d", ret);
700 return ret; 742 return ret;
701 } 743 }
702 #endif 744 #endif
703 745
704 #ifdef SRS_HLS 746 #ifdef SRS_HLS
705 if ((ret = hls->on_publish(req)) != ERROR_SUCCESS) { 747 if ((ret = hls->on_publish(req)) != ERROR_SUCCESS) {
  748 + srs_error("start hls failed. ret=%d", ret);
706 return ret; 749 return ret;
707 } 750 }
708 #endif 751 #endif
@@ -219,6 +219,8 @@ public: @@ -219,6 +219,8 @@ public:
219 public: 219 public:
220 virtual int on_reload_gop_cache(std::string vhost); 220 virtual int on_reload_gop_cache(std::string vhost);
221 virtual int on_reload_forward(std::string vhost); 221 virtual int on_reload_forward(std::string vhost);
  222 + virtual int on_reload_hls(std::string vhost);
  223 + virtual int on_reload_transcode(std::string vhost);
222 public: 224 public:
223 virtual bool can_publish(); 225 virtual bool can_publish();
224 virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata); 226 virtual int on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata);