From 2c569f568c3da9ecaf44cd29efb6e9912487f0cd Mon Sep 17 00:00:00 2001 From: ChenHaibo Date: Wed, 15 Jun 2022 17:38:37 +0800 Subject: [PATCH] HLS: Support config hls_ctx to disable HLS streaming. --- trunk/conf/full.conf | 8 ++++++++ trunk/src/app/srs_app_config.cpp | 19 ++++++++++++++++++- trunk/src/app/srs_app_config.hpp | 2 ++ trunk/src/app/srs_app_http_static.cpp | 4 ++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index efbd38991..c42726e60 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -1499,6 +1499,14 @@ vhost hls.srs.com { # the key root URL, use this can support https. # @remark It's optional. 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. ########################################### diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 4603f220c..ba388b57d 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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_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_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()); } @@ -6388,6 +6388,23 @@ bool SrsConfig::get_vhost_hls_dts_directly(string vhost) 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) { static bool DEFAULT = true; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 36a14a57c..fce3e5dc5 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -956,6 +956,8 @@ public: virtual int get_vhost_hls_nb_notify(std::string vhost); // Whether turn the FLV timestamp to TS DTS. 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 private: // Get the hds directive of vhost. diff --git a/trunk/src/app/srs_app_http_static.cpp b/trunk/src/app/srs_app_http_static.cpp index 0b1a19d4f..563bcc47a 100644 --- a/trunk/src/app/srs_app_http_static.cpp +++ b/trunk/src/app/srs_app_http_static.cpp @@ -202,6 +202,10 @@ srs_error_t SrsVodStream::serve_m3u8_ctx(ISrsHttpResponseWriter * w, ISrsHttpMes } 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); if (!ctx.empty() && ctx_is_exist(ctx)) {