mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support config the hls_nb_notify.
This commit is contained in:
parent
0a7cea063c
commit
5d37e47783
6 changed files with 39 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue