From e5b8e0da01eee95eb06fa5b37459af274feded0f Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 10 Apr 2015 15:00:07 +0800 Subject: [PATCH] fix async call and hls_nb_notify bug. --- trunk/src/app/srs_app_async_call.cpp | 2 +- trunk/src/app/srs_app_config.cpp | 32 ++++++++++++++-------------- trunk/src/app/srs_app_config.hpp | 13 ++++++----- trunk/src/app/srs_app_http_hooks.cpp | 12 +++++++---- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/trunk/src/app/srs_app_async_call.cpp b/trunk/src/app/srs_app_async_call.cpp index 3bfac6391..471564343 100644 --- a/trunk/src/app/srs_app_async_call.cpp +++ b/trunk/src/app/srs_app_async_call.cpp @@ -87,7 +87,7 @@ int SrsDvrAsyncCallThread::cycle() for (it = copies.begin(); it != copies.end(); ++it) { ISrsDvrAsyncCall* call = *it; if ((ret = call->call()) != ERROR_SUCCESS) { - srs_warn("dvr: ignore callback %s, ret=%d", call->to_string().c_str(), ret); + srs_warn("ignore async callback %s, ret=%d", call->to_string().c_str(), ret); } srs_freep(call); } diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 7236bf162..527084b66 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2440,22 +2440,6 @@ 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); @@ -3434,6 +3418,22 @@ string SrsConfig::get_hls_vcodec(string vhost) return conf->arg0(); } +int SrsConfig::get_vhost_hls_nb_notify(string vhost) +{ + SrsConfDirective* conf = get_hls(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_hls_cleanup(string vhost) { SrsConfDirective* hls = get_hls(vhost); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 02d81f917..3c829ab72 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -652,11 +652,6 @@ 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: /** @@ -965,8 +960,12 @@ public: * whether cleanup the old ts files. */ virtual bool get_hls_cleanup(std::string vhost); - - // hds section + /** + * 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); +// hds section private: /** * get the hds directive of vhost. diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 5e79e7c74..3055da53f 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -42,6 +42,7 @@ using namespace std; #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) #define SRS_HTTP_HEADER_BUFFER 1024 +#define SRS_HTTP_READ_BUFFER 4096 #define SRS_HTTP_BODY_BUFFER 32 * 1024 // the timeout for hls notify, in us. @@ -363,15 +364,18 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts } SrsAutoFree(SrsHttpMessage, msg); + int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER); + char* buf = new char[nb_buf]; + SrsAutoFree(char, buf); + int nb_read = 0; ISrsHttpResponseReader* br = msg->body_reader(); while (nb_read < nb_notify && !br->eof()) { - char buf[64]; // only read a little of bytes of ts. - int nb_buf = 64; - if ((ret = br->read(buf, nb_buf, &nb_buf)) != ERROR_SUCCESS) { + int nb_bytes = 0; + if ((ret = br->read(buf, nb_buf, &nb_bytes)) != ERROR_SUCCESS) { break; } - nb_read += nb_buf; + nb_read += nb_bytes; } int spenttime = (int)(srs_update_system_time_ms() - starttime);