winlin

Merge pull request #330 from wenjiegit/develop

HDS support reload,for #328
... ... @@ -826,6 +826,19 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
}
srs_trace("vhost %s reload hls success.", vhost.c_str());
}
// hds reload
if (!srs_directive_equals(new_vhost->get("hds"), old_vhost->get("hds"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
ISrsReloadHandler* subscribe = *it;
if ((ret = subscribe->on_reload_vhost_hds(vhost)) != ERROR_SUCCESS) {
srs_error("vhost %s notify subscribes hds failed. ret=%d", vhost.c_str(), ret);
return ret;
}
}
srs_trace("vhost %s reload hds success.", vhost.c_str());
}
// dvr, only one per vhost
if (!srs_directive_equals(new_vhost->get("dvr"), old_vhost->get("dvr"))) {
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
... ...
... ... @@ -267,6 +267,7 @@ SrsHds::SrsHds(SrsSource *s)
, video_sh(NULL)
, audio_sh(NULL)
, hds_req(NULL)
, hds_enabled(false)
{
}
... ... @@ -278,9 +279,18 @@ SrsHds::~SrsHds()
int SrsHds::on_publish(SrsRequest *req)
{
// TODO: FIXME: check whether disabled.
// TODO: FIXME: support reload.
int ret = ERROR_SUCCESS;
if (hds_enabled) {
return ret;
}
std::string vhost = req->vhost;
if (!_srs_config->get_hds_enabled(vhost)) {
hds_enabled = false;
return ret;
}
hds_enabled = true;
hds_req = req->copy();
return flush_mainfest();
... ... @@ -290,6 +300,12 @@ int SrsHds::on_unpublish()
{
int ret = ERROR_SUCCESS;
if (!hds_enabled) {
return ret;
}
hds_enabled = false;
srs_freep(video_sh);
srs_freep(audio_sh);
srs_freep(hds_req);
... ... @@ -313,6 +329,10 @@ int SrsHds::on_video(SrsSharedPtrMessage* msg)
{
int ret = ERROR_SUCCESS;
if (!hds_enabled) {
return ret;
}
if (SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) {
srs_freep(video_sh);
video_sh = msg->copy();
... ... @@ -361,6 +381,10 @@ int SrsHds::on_audio(SrsSharedPtrMessage* msg)
{
int ret = ERROR_SUCCESS;
if (!hds_enabled) {
return ret;
}
if (SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) {
srs_freep(audio_sh);
audio_sh = msg->copy();
... ...
... ... @@ -61,6 +61,7 @@ private:
SrsSharedPtrMessage *audio_sh;
SrsRequest *hds_req;
bool hds_enabled;
};
#endif
... ...
... ... @@ -140,6 +140,11 @@ int ISrsReloadHandler::on_reload_vhost_hls(string /*vhost*/)
return ERROR_SUCCESS;
}
int ISrsReloadHandler::on_reload_vhost_hds(string /*vhost*/)
{
return ERROR_SUCCESS;
}
int ISrsReloadHandler::on_reload_vhost_dvr(string /*vhost*/)
{
return ERROR_SUCCESS;
... ...
... ... @@ -65,6 +65,7 @@ public:
virtual int on_reload_vhost_time_jitter(std::string vhost);
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_hds(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_mr(std::string vhost);
virtual int on_reload_vhost_mw(std::string vhost);
... ...
... ... @@ -1013,6 +1013,26 @@ int SrsSource::on_reload_vhost_hls(string vhost)
return ret;
}
int SrsSource::on_reload_vhost_hds(string vhost)
{
int ret = ERROR_SUCCESS;
if (_req->vhost != vhost) {
return ret;
}
#ifdef SRS_AUTO_HDS
hds->on_unpublish();
if ((ret = hds->on_publish(_req)) != ERROR_SUCCESS) {
srs_error("hds publish failed. ret=%d", ret);
return ret;
}
srs_trace("vhost %s hds reload success", vhost.c_str());
#endif
return ret;
}
int SrsSource::on_reload_vhost_dvr(string vhost)
{
int ret = ERROR_SUCCESS;
... ...
... ... @@ -476,6 +476,7 @@ public:
virtual int on_reload_vhost_time_jitter(std::string vhost);
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_hds(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_transcode(std::string vhost);
// for the tools callback
... ...
... ... @@ -266,6 +266,12 @@ int MockReloadHandler::on_reload_vhost_hls(string /*vhost*/)
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_hds(string /*vhost*/)
{
vhost_hls_reloaded = true;
return ERROR_SUCCESS;
}
int MockReloadHandler::on_reload_vhost_dvr(string /*vhost*/)
{
vhost_dvr_reloaded = true;
... ...
... ... @@ -91,6 +91,7 @@ public:
virtual int on_reload_vhost_time_jitter(std::string vhost);
virtual int on_reload_vhost_forward(std::string vhost);
virtual int on_reload_vhost_hls(std::string vhost);
virtual int on_reload_vhost_hds(std::string vhost);
virtual int on_reload_vhost_dvr(std::string vhost);
virtual int on_reload_vhost_transcode(std::string vhost);
virtual int on_reload_ingest_removed(std::string vhost, std::string ingest_id);
... ...