winlin

support reload the gop_cache

@@ -63,6 +63,8 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) @@ -63,6 +63,8 @@ SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
63 63
64 SrsClient::~SrsClient() 64 SrsClient::~SrsClient()
65 { 65 {
  66 + config->unsubscribe(this);
  67 +
66 srs_freepa(ip); 68 srs_freepa(ip);
67 srs_freep(req); 69 srs_freep(req);
68 srs_freep(res); 70 srs_freep(res);
@@ -71,8 +73,6 @@ SrsClient::~SrsClient() @@ -71,8 +73,6 @@ SrsClient::~SrsClient()
71 #ifdef SRS_HTTP 73 #ifdef SRS_HTTP
72 srs_freep(http_hooks); 74 srs_freep(http_hooks);
73 #endif 75 #endif
74 -  
75 - config->unsubscribe(this);  
76 } 76 }
77 77
78 // TODO: return detail message when error for client. 78 // TODO: return detail message when error for client.
@@ -537,6 +537,7 @@ int SrsConfig::reload() @@ -537,6 +537,7 @@ int SrsConfig::reload()
537 // merge config: vhost modified. 537 // merge config: vhost modified.
538 srs_trace("vhost %s modified, reload its detail.", vhost.c_str()); 538 srs_trace("vhost %s modified, reload its detail.", vhost.c_str());
539 if (get_vhost_enabled(new_vhost) && get_vhost_enabled(old_vhost)) { 539 if (get_vhost_enabled(new_vhost) && get_vhost_enabled(old_vhost)) {
  540 + // gop_cache
540 if (!srs_directive_equals(new_vhost->get("gop_cache"), old_vhost->get("gop_cache"))) { 541 if (!srs_directive_equals(new_vhost->get("gop_cache"), old_vhost->get("gop_cache"))) {
541 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 542 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
542 ISrsReloadHandler* subscribe = *it; 543 ISrsReloadHandler* subscribe = *it;
@@ -547,6 +548,17 @@ int SrsConfig::reload() @@ -547,6 +548,17 @@ int SrsConfig::reload()
547 } 548 }
548 srs_trace("vhost %s reload gop_cache success.", vhost.c_str()); 549 srs_trace("vhost %s reload gop_cache success.", vhost.c_str());
549 } 550 }
  551 + // forward
  552 + if (!srs_directive_equals(new_vhost->get("forward"), old_vhost->get("forward"))) {
  553 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  554 + ISrsReloadHandler* subscribe = *it;
  555 + if ((ret = subscribe->on_reload_forward(vhost)) != ERROR_SUCCESS) {
  556 + srs_error("vhost %s notify subscribes forward failed. ret=%d", vhost.c_str(), ret);
  557 + return ret;
  558 + }
  559 + }
  560 + srs_trace("vhost %s reload forward success.", vhost.c_str());
  561 + }
550 // TODO: suppor reload hls/forward/ffmpeg/http 562 // TODO: suppor reload hls/forward/ffmpeg/http
551 continue; 563 continue;
552 } 564 }
@@ -55,3 +55,8 @@ int ISrsReloadHandler::on_reload_gop_cache(string /*vhost*/) @@ -55,3 +55,8 @@ int ISrsReloadHandler::on_reload_gop_cache(string /*vhost*/)
55 return ERROR_SUCCESS; 55 return ERROR_SUCCESS;
56 } 56 }
57 57
  58 +int ISrsReloadHandler::on_reload_forward(string /*vhost*/)
  59 +{
  60 + return ERROR_SUCCESS;
  61 +}
  62 +
@@ -44,6 +44,7 @@ public: @@ -44,6 +44,7 @@ public:
44 virtual int on_reload_pithy_print(); 44 virtual int on_reload_pithy_print();
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 }; 48 };
48 49
49 #endif 50 #endif
@@ -374,10 +374,14 @@ SrsSource::SrsSource(string _stream_url, string _vhost) @@ -374,10 +374,14 @@ SrsSource::SrsSource(string _stream_url, string _vhost)
374 _can_publish = true; 374 _can_publish = true;
375 375
376 gop_cache = new SrsGopCache(); 376 gop_cache = new SrsGopCache();
  377 +
  378 + config->subscribe(this);
377 } 379 }
378 380
379 SrsSource::~SrsSource() 381 SrsSource::~SrsSource()
380 { 382 {
  383 + config->unsubscribe(this);
  384 +
381 if (true) { 385 if (true) {
382 std::vector<SrsConsumer*>::iterator it; 386 std::vector<SrsConsumer*>::iterator it;
383 for (it = consumers.begin(); it != consumers.end(); ++it) { 387 for (it = consumers.begin(); it != consumers.end(); ++it) {