mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support hls mount to vhost and reload
This commit is contained in:
parent
041040b846
commit
d81b2cb140
3 changed files with 65 additions and 24 deletions
|
@ -956,6 +956,7 @@ vhost with-hls.srs.com {
|
|||
# [vhost], the vhost of stream.
|
||||
# [app], the app of stream.
|
||||
# [stream], the stream name of stream.
|
||||
# recommend: [vhost]/[app]/[stream].m3u8
|
||||
# default: [app]/[stream].m3u8
|
||||
hls_m3u8_file [app]/[stream].m3u8;
|
||||
# the hls ts file name.
|
||||
|
@ -974,6 +975,7 @@ vhost with-hls.srs.com {
|
|||
# [seq], the sequence number of ts.
|
||||
# @see https://github.com/ossrs/srs/wiki/v2_CN_DVR#custom-path
|
||||
# @see https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#hls-config
|
||||
# recommend: [vhost]/[app]/[stream]-[seq].ts
|
||||
# default: [app]/[stream]-[seq].ts
|
||||
hls_ts_file [app]/[stream]-[seq].ts;
|
||||
# whether use floor for the hls_ts_file path generation.
|
||||
|
|
|
@ -206,10 +206,12 @@ int SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
|
|||
SrsHttpStaticServer::SrsHttpStaticServer(SrsServer* svr)
|
||||
{
|
||||
server = svr;
|
||||
_srs_config->subscribe(this);
|
||||
}
|
||||
|
||||
SrsHttpStaticServer::~SrsHttpStaticServer()
|
||||
{
|
||||
_srs_config->unsubscribe(this);
|
||||
}
|
||||
|
||||
int SrsHttpStaticServer::initialize()
|
||||
|
@ -227,36 +229,17 @@ int SrsHttpStaticServer::initialize()
|
|||
continue;
|
||||
}
|
||||
|
||||
std::string vhost = conf->arg0();
|
||||
if (!_srs_config->get_vhost_http_enabled(vhost)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string mount = _srs_config->get_vhost_http_mount(vhost);
|
||||
std::string dir = _srs_config->get_vhost_http_dir(vhost);
|
||||
|
||||
// replace the vhost variable
|
||||
mount = srs_string_replace(mount, "[vhost]", vhost);
|
||||
|
||||
// remove the default vhost mount
|
||||
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
||||
|
||||
// the dir mount must always ends with "/"
|
||||
if (mount != "/" && !srs_string_ends_with(mount, "/")) {
|
||||
mount += "/";
|
||||
}
|
||||
|
||||
// mount the http of vhost.
|
||||
if ((ret = mux.handle(mount, new SrsVodStream(dir))) != ERROR_SUCCESS) {
|
||||
srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret);
|
||||
string pmount;
|
||||
string vhost = conf->arg0();
|
||||
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (mount == "/") {
|
||||
if (pmount == "/") {
|
||||
default_root_exists = true;
|
||||
std::string dir = _srs_config->get_vhost_http_dir(vhost);
|
||||
srs_warn("http: root mount to %s", dir.c_str());
|
||||
}
|
||||
srs_trace("http: vhost=%s mount to %s", vhost.c_str(), mount.c_str());
|
||||
}
|
||||
|
||||
if (!default_root_exists) {
|
||||
|
@ -272,6 +255,59 @@ int SrsHttpStaticServer::initialize()
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpStaticServer::mount_vhost(string vhost, string& pmount)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// when vhost disabled, ignore.
|
||||
if (!_srs_config->get_vhost_enabled(vhost)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// when vhost http_static disabled, ignore.
|
||||
if (!_srs_config->get_vhost_http_enabled(vhost)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string mount = _srs_config->get_vhost_http_mount(vhost);
|
||||
std::string dir = _srs_config->get_vhost_http_dir(vhost);
|
||||
|
||||
// replace the vhost variable
|
||||
mount = srs_string_replace(mount, "[vhost]", vhost);
|
||||
dir = srs_string_replace(dir, "[vhost]", vhost);
|
||||
|
||||
// remove the default vhost mount
|
||||
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
||||
|
||||
// the dir mount must always ends with "/"
|
||||
if (mount != "/" && !srs_string_ends_with(mount, "/")) {
|
||||
mount += "/";
|
||||
}
|
||||
|
||||
// mount the http of vhost.
|
||||
if ((ret = mux.handle(mount, new SrsVodStream(dir))) != ERROR_SUCCESS) {
|
||||
srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
srs_trace("http: vhost=%s mount to %s at %s", vhost.c_str(), mount.c_str(), dir.c_str());
|
||||
|
||||
pmount = mount;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpStaticServer::on_reload_vhost_added(string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
string pmount;
|
||||
if ((ret = mount_vhost(vhost, pmount)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpStaticServer::on_reload_vhost_http_updated()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
|
|
@ -65,8 +65,11 @@ public:
|
|||
virtual ~SrsHttpStaticServer();
|
||||
public:
|
||||
virtual int initialize();
|
||||
private:
|
||||
virtual int mount_vhost(std::string vhost, std::string& pmount);
|
||||
// interface ISrsReloadHandler.
|
||||
public:
|
||||
virtual int on_reload_vhost_added(std::string vhost);
|
||||
virtual int on_reload_vhost_http_updated();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue