winlin

support reload dvr

@@ -851,6 +851,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root) @@ -851,6 +851,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
851 } 851 }
852 srs_trace("vhost %s reload hls success.", vhost.c_str()); 852 srs_trace("vhost %s reload hls success.", vhost.c_str());
853 } 853 }
  854 + // dvr, only one per vhost
  855 + if (!srs_directive_equals(new_vhost->get("dvr"), old_vhost->get("dvr"))) {
  856 + for (it = subscribes.begin(); it != subscribes.end(); ++it) {
  857 + ISrsReloadHandler* subscribe = *it;
  858 + if ((ret = subscribe->on_reload_vhost_dvr(vhost)) != ERROR_SUCCESS) {
  859 + srs_error("vhost %s notify subscribes dvr failed. ret=%d", vhost.c_str(), ret);
  860 + return ret;
  861 + }
  862 + }
  863 + srs_trace("vhost %s reload hls success.", vhost.c_str());
  864 + }
854 // http, only one per vhost. 865 // http, only one per vhost.
855 if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) { 866 if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {
856 for (it = subscribes.begin(); it != subscribes.end(); ++it) { 867 for (it = subscribes.begin(); it != subscribes.end(); ++it) {
@@ -364,6 +364,10 @@ int SrsDvr::on_meta_data(SrsOnMetaDataPacket* metadata) @@ -364,6 +364,10 @@ int SrsDvr::on_meta_data(SrsOnMetaDataPacket* metadata)
364 { 364 {
365 int ret = ERROR_SUCCESS; 365 int ret = ERROR_SUCCESS;
366 366
  367 + if (!dvr_enabled) {
  368 + return ret;
  369 + }
  370 +
367 int size = 0; 371 int size = 0;
368 char* payload = NULL; 372 char* payload = NULL;
369 if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) { 373 if ((ret = metadata->encode(size, payload)) != ERROR_SUCCESS) {
@@ -382,6 +386,12 @@ int SrsDvr::on_audio(SrsSharedPtrMessage* audio) @@ -382,6 +386,12 @@ int SrsDvr::on_audio(SrsSharedPtrMessage* audio)
382 { 386 {
383 int ret = ERROR_SUCCESS; 387 int ret = ERROR_SUCCESS;
384 388
  389 + SrsAutoFree(SrsSharedPtrMessage, audio, false);
  390 +
  391 + if (!dvr_enabled) {
  392 + return ret;
  393 + }
  394 +
385 int32_t timestamp = audio->header.timestamp; 395 int32_t timestamp = audio->header.timestamp;
386 char* payload = (char*)audio->payload; 396 char* payload = (char*)audio->payload;
387 int size = (int)audio->size; 397 int size = (int)audio->size;
@@ -396,6 +406,12 @@ int SrsDvr::on_video(SrsSharedPtrMessage* video) @@ -396,6 +406,12 @@ int SrsDvr::on_video(SrsSharedPtrMessage* video)
396 { 406 {
397 int ret = ERROR_SUCCESS; 407 int ret = ERROR_SUCCESS;
398 408
  409 + SrsAutoFree(SrsSharedPtrMessage, video, false);
  410 +
  411 + if (!dvr_enabled) {
  412 + return ret;
  413 + }
  414 +
399 int32_t timestamp = video->header.timestamp; 415 int32_t timestamp = video->header.timestamp;
400 char* payload = (char*)video->payload; 416 char* payload = (char*)video->payload;
401 int size = (int)video->size; 417 int size = (int)video->size;
@@ -130,6 +130,11 @@ int ISrsReloadHandler::on_reload_vhost_hls(string /*vhost*/) @@ -130,6 +130,11 @@ int ISrsReloadHandler::on_reload_vhost_hls(string /*vhost*/)
130 return ERROR_SUCCESS; 130 return ERROR_SUCCESS;
131 } 131 }
132 132
  133 +int ISrsReloadHandler::on_reload_vhost_dvr(string /*vhost*/)
  134 +{
  135 + return ERROR_SUCCESS;
  136 +}
  137 +
133 int ISrsReloadHandler::on_reload_vhost_transcode(string /*vhost*/) 138 int ISrsReloadHandler::on_reload_vhost_transcode(string /*vhost*/)
134 { 139 {
135 return ERROR_SUCCESS; 140 return ERROR_SUCCESS;
@@ -60,6 +60,7 @@ public: @@ -60,6 +60,7 @@ public:
60 virtual int on_reload_vhost_queue_length(std::string vhost); 60 virtual int on_reload_vhost_queue_length(std::string vhost);
61 virtual int on_reload_vhost_forward(std::string vhost); 61 virtual int on_reload_vhost_forward(std::string vhost);
62 virtual int on_reload_vhost_hls(std::string vhost); 62 virtual int on_reload_vhost_hls(std::string vhost);
  63 + virtual int on_reload_vhost_dvr(std::string vhost);
63 virtual int on_reload_vhost_transcode(std::string vhost); 64 virtual int on_reload_vhost_transcode(std::string vhost);
64 virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id); 65 virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);
65 virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id); 66 virtual int on_reload_ingest_added(std::string vhost, std::string ingest_id);
@@ -605,6 +605,26 @@ int SrsSource::on_reload_vhost_hls(string vhost) @@ -605,6 +605,26 @@ int SrsSource::on_reload_vhost_hls(string vhost)
605 return ret; 605 return ret;
606 } 606 }
607 607
  608 +int SrsSource::on_reload_vhost_dvr(string vhost)
  609 +{
  610 + int ret = ERROR_SUCCESS;
  611 +
  612 + if (req->vhost != vhost) {
  613 + return ret;
  614 + }
  615 +
  616 +#ifdef SRS_AUTO_DVR
  617 + dvr->on_unpublish();
  618 + if ((ret = dvr->on_publish(req)) != ERROR_SUCCESS) {
  619 + srs_error("dvr publish failed. ret=%d", ret);
  620 + return ret;
  621 + }
  622 + srs_trace("vhost %s dvr reload success", vhost.c_str());
  623 +#endif
  624 +
  625 + return ret;
  626 +}
  627 +
608 int SrsSource::on_reload_vhost_transcode(string vhost) 628 int SrsSource::on_reload_vhost_transcode(string vhost)
609 { 629 {
610 int ret = ERROR_SUCCESS; 630 int ret = ERROR_SUCCESS;
@@ -278,6 +278,7 @@ public: @@ -278,6 +278,7 @@ public:
278 virtual int on_reload_vhost_queue_length(std::string vhost); 278 virtual int on_reload_vhost_queue_length(std::string vhost);
279 virtual int on_reload_vhost_forward(std::string vhost); 279 virtual int on_reload_vhost_forward(std::string vhost);
280 virtual int on_reload_vhost_hls(std::string vhost); 280 virtual int on_reload_vhost_hls(std::string vhost);
  281 + virtual int on_reload_vhost_dvr(std::string vhost);
281 virtual int on_reload_vhost_transcode(std::string vhost); 282 virtual int on_reload_vhost_transcode(std::string vhost);
282 public: 283 public:
283 // for the SrsForwarder to callback to request the sequence headers. 284 // for the SrsForwarder to callback to request the sequence headers.