From 5d37e47783abcdd3d7aa6d2fb12fd9f059ee03bf Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 10 Apr 2015 14:44:18 +0800 Subject: [PATCH] support config the hls_nb_notify. --- trunk/conf/full.conf | 5 +++++ trunk/src/app/srs_app_config.cpp | 18 +++++++++++++++++- trunk/src/app/srs_app_config.hpp | 6 ++++++ trunk/src/app/srs_app_hls.cpp | 3 ++- trunk/src/app/srs_app_http_hooks.cpp | 10 +++++++--- trunk/src/app/srs_app_http_hooks.hpp | 3 ++- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 217a7f95c..7bcae649d 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -613,6 +613,11 @@ vhost with-hls.srs.com { # whether cleanup the old ts files. # default: on hls_cleanup on; + # the max size to notify hls, + # to read max bytes from ts of specified cdn network, + # @remark only used when on_hls_notify is config. + # default: 64 + hls_nb_notify 64; # on_hls, never config in here, should config in http_hooks. # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 5b9563fb8..7236bf162 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1487,7 +1487,7 @@ int SrsConfig::check_config() string m = conf->at(j)->name.c_str(); if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" && 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_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" ) { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); @@ -2440,6 +2440,22 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost) return conf->get("on_hls_notify"); } +int SrsConfig::get_vhost_hls_nb_notify(string vhost) +{ + SrsConfDirective* conf = get_vhost_http_hooks(vhost); + + if (!conf) { + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY; + } + + conf = conf->get("hls_nb_notify"); + if (!conf || conf->arg0().empty()) { + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY; + } + + return ::atoi(conf->arg0().c_str()); +} + bool SrsConfig::get_bw_check_enabled(string vhost) { SrsConfDirective* conf = get_vhost(vhost); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index d31889bba..02d81f917 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -63,6 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONF_DEFAULT_HLS_ACODEC "aac" #define SRS_CONF_DEFAULT_HLS_VCODEC "h264" #define SRS_CONF_DEFAULT_HLS_CLEANUP true +#define SRS_CONF_DEFAULT_HLS_NB_NOTIFY 64 #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" @@ -651,6 +652,11 @@ public: * @return the on_hls_notify callback directive, the args is the url to callback. */ virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); + /** + * get the size of bytes to read from cdn network, for the on_hls_notify callback, + * that is, to read max bytes of the bytes from the callback, or timeout or error. + */ + virtual int get_vhost_hls_nb_notify(std::string vhost); // bwct(bandwidth check tool) section public: /** diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index bbc62cd95..d63d5f408 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -240,9 +240,10 @@ int SrsDvrAsyncCallOnHlsNotify::call() return ret; } + int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost); for (int i = 0; i < (int)on_hls->args.size(); i++) { std::string url = on_hls->args.at(i); - if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url)) != ERROR_SUCCESS) { + if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url, nb_notify)) != ERROR_SUCCESS) { srs_error("hook client on_hls_notify failed. url=%s, ts=%s, ret=%d", url.c_str(), ts_url.c_str(), ret); return ret; } diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index c262ba07f..5e79e7c74 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -329,7 +329,7 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl return ret; } -int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url) +int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify) { int ret = ERROR_SUCCESS; @@ -365,9 +365,13 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts int nb_read = 0; ISrsHttpResponseReader* br = msg->body_reader(); - if (!br->eof()) { + while (nb_read < nb_notify && !br->eof()) { char buf[64]; // only read a little of bytes of ts. - ret = br->read(buf, 64, &nb_read); + int nb_buf = 64; + if ((ret = br->read(buf, nb_buf, &nb_buf)) != ERROR_SUCCESS) { + break; + } + nb_read += nb_buf; } int spenttime = (int)(srs_update_system_time_ms() - starttime); diff --git a/trunk/src/app/srs_app_http_hooks.hpp b/trunk/src/app/srs_app_http_hooks.hpp index 1a63bdce0..d63eca3af 100644 --- a/trunk/src/app/srs_app_http_hooks.hpp +++ b/trunk/src/app/srs_app_http_hooks.hpp @@ -110,8 +110,9 @@ public: * @param url the api server url, to process the event. * ignore if empty. * @param ts_url the ts uri, used to replace the variable [ts_url] in url. + * @param nb_notify the max bytes to read from notify server. */ - static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url); + static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify); private: static int do_post(std::string url, std::string req, int& code, std::string& res); };