1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

HLS: Support config hls_ctx to disable HLS streaming.

This commit is contained in:
ChenHaibo 2022-06-15 17:38:37 +08:00 committed by winlin
parent 6dc86b8a2e
commit 2c569f568c
4 changed files with 32 additions and 1 deletions

View file

@ -1499,6 +1499,14 @@ vhost hls.srs.com {
# the key root URL, use this can support https. # the key root URL, use this can support https.
# @remark It's optional. # @remark It's optional.
hls_key_url https://localhost:8080; hls_key_url https://localhost:8080;
# Whether enable hls_ctx.
# hls_ctx used to keep track of subsequent m3u8 requests.
# if on, hls client info can be collected in stat module,
# if on, on_play/on_stop can be called in http hook module.
# otherwise not;
# When request stopped, http hook or stat with special time effected, that is 2*hls_window,
# Default: off
hls_ctx on;
# Special control controls. # Special control controls.
########################################### ###########################################

View file

@ -2701,7 +2701,7 @@ srs_error_t SrsConfig::check_normal_config()
&& m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec"
&& m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify"
&& m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_keys" && m != "hls_fragments_per_key" && m != "hls_key_file" && m != "hls_wait_keyframe" && m != "hls_dispose" && m != "hls_keys" && m != "hls_fragments_per_key" && m != "hls_key_file"
&& m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly") { && m != "hls_key_file_path" && m != "hls_key_url" && m != "hls_dts_directly" && m != "hls_ctx") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.hls.%s of %s", m.c_str(), vhost->arg0().c_str()); return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.hls.%s of %s", m.c_str(), vhost->arg0().c_str());
} }
@ -6388,6 +6388,23 @@ bool SrsConfig::get_vhost_hls_dts_directly(string vhost)
return SRS_CONF_PERFER_TRUE(conf->arg0()); return SRS_CONF_PERFER_TRUE(conf->arg0());
} }
bool SrsConfig::get_hls_ctx_enabled(std::string vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = get_hls(vhost);
if (!conf) {
return DEFAULT;
}
conf = conf->get("hls_ctx");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}
bool SrsConfig::get_hls_cleanup(string vhost) bool SrsConfig::get_hls_cleanup(string vhost)
{ {
static bool DEFAULT = true; static bool DEFAULT = true;

View file

@ -956,6 +956,8 @@ public:
virtual int get_vhost_hls_nb_notify(std::string vhost); virtual int get_vhost_hls_nb_notify(std::string vhost);
// Whether turn the FLV timestamp to TS DTS. // Whether turn the FLV timestamp to TS DTS.
virtual bool get_vhost_hls_dts_directly(std::string vhost); virtual bool get_vhost_hls_dts_directly(std::string vhost);
// Whether enable hls_ctx
virtual bool get_hls_ctx_enabled(std::string vhost);
// hds section // hds section
private: private:
// Get the hds directive of vhost. // Get the hds directive of vhost.

View file

@ -202,6 +202,10 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes
} }
SrsAutoFree(SrsRequest, req); SrsAutoFree(SrsRequest, req);
if (!_srs_config->get_hls_ctx_enabled(req->vhost)) {
return SrsHttpFileServer::serve_m3u8_ctx(w, r, fullpath);
}
string ctx = hr->query_get(SRS_CONTEXT_IN_HLS); string ctx = hr->query_get(SRS_CONTEXT_IN_HLS);
if (!ctx.empty() && ctx_is_exist(ctx)) { if (!ctx.empty() && ctx_is_exist(ctx)) {