正在显示
6 个修改的文件
包含
39 行增加
和
6 行删除
| @@ -613,6 +613,11 @@ vhost with-hls.srs.com { | @@ -613,6 +613,11 @@ vhost with-hls.srs.com { | ||
| 613 | # whether cleanup the old ts files. | 613 | # whether cleanup the old ts files. |
| 614 | # default: on | 614 | # default: on |
| 615 | hls_cleanup on; | 615 | hls_cleanup on; |
| 616 | + # the max size to notify hls, | ||
| 617 | + # to read max bytes from ts of specified cdn network, | ||
| 618 | + # @remark only used when on_hls_notify is config. | ||
| 619 | + # default: 64 | ||
| 620 | + hls_nb_notify 64; | ||
| 616 | 621 | ||
| 617 | # on_hls, never config in here, should config in http_hooks. | 622 | # on_hls, never config in here, should config in http_hooks. |
| 618 | # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com | 623 | # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com |
| @@ -1487,7 +1487,7 @@ int SrsConfig::check_config() | @@ -1487,7 +1487,7 @@ int SrsConfig::check_config() | ||
| 1487 | string m = conf->at(j)->name.c_str(); | 1487 | string m = conf->at(j)->name.c_str(); |
| 1488 | if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" | 1488 | if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" |
| 1489 | && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" | 1489 | && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" |
| 1490 | - && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" | 1490 | + && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" && m != "hls_cleanup" && m != "hls_nb_notify" |
| 1491 | ) { | 1491 | ) { |
| 1492 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1492 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 1493 | srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); | 1493 | 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) | @@ -2440,6 +2440,22 @@ SrsConfDirective* SrsConfig::get_vhost_on_hls_notify(string vhost) | ||
| 2440 | return conf->get("on_hls_notify"); | 2440 | return conf->get("on_hls_notify"); |
| 2441 | } | 2441 | } |
| 2442 | 2442 | ||
| 2443 | +int SrsConfig::get_vhost_hls_nb_notify(string vhost) | ||
| 2444 | +{ | ||
| 2445 | + SrsConfDirective* conf = get_vhost_http_hooks(vhost); | ||
| 2446 | + | ||
| 2447 | + if (!conf) { | ||
| 2448 | + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY; | ||
| 2449 | + } | ||
| 2450 | + | ||
| 2451 | + conf = conf->get("hls_nb_notify"); | ||
| 2452 | + if (!conf || conf->arg0().empty()) { | ||
| 2453 | + return SRS_CONF_DEFAULT_HLS_NB_NOTIFY; | ||
| 2454 | + } | ||
| 2455 | + | ||
| 2456 | + return ::atoi(conf->arg0().c_str()); | ||
| 2457 | +} | ||
| 2458 | + | ||
| 2443 | bool SrsConfig::get_bw_check_enabled(string vhost) | 2459 | bool SrsConfig::get_bw_check_enabled(string vhost) |
| 2444 | { | 2460 | { |
| 2445 | SrsConfDirective* conf = get_vhost(vhost); | 2461 | SrsConfDirective* conf = get_vhost(vhost); |
| @@ -63,6 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -63,6 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 63 | #define SRS_CONF_DEFAULT_HLS_ACODEC "aac" | 63 | #define SRS_CONF_DEFAULT_HLS_ACODEC "aac" |
| 64 | #define SRS_CONF_DEFAULT_HLS_VCODEC "h264" | 64 | #define SRS_CONF_DEFAULT_HLS_VCODEC "h264" |
| 65 | #define SRS_CONF_DEFAULT_HLS_CLEANUP true | 65 | #define SRS_CONF_DEFAULT_HLS_CLEANUP true |
| 66 | +#define SRS_CONF_DEFAULT_HLS_NB_NOTIFY 64 | ||
| 66 | #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" | 67 | #define SRS_CONF_DEFAULT_DVR_PATH "./objs/nginx/html/[app]/[stream].[timestamp].flv" |
| 67 | #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" | 68 | #define SRS_CONF_DEFAULT_DVR_PLAN_SESSION "session" |
| 68 | #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" | 69 | #define SRS_CONF_DEFAULT_DVR_PLAN_SEGMENT "segment" |
| @@ -651,6 +652,11 @@ public: | @@ -651,6 +652,11 @@ public: | ||
| 651 | * @return the on_hls_notify callback directive, the args is the url to callback. | 652 | * @return the on_hls_notify callback directive, the args is the url to callback. |
| 652 | */ | 653 | */ |
| 653 | virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); | 654 | virtual SrsConfDirective* get_vhost_on_hls_notify(std::string vhost); |
| 655 | + /** | ||
| 656 | + * get the size of bytes to read from cdn network, for the on_hls_notify callback, | ||
| 657 | + * that is, to read max bytes of the bytes from the callback, or timeout or error. | ||
| 658 | + */ | ||
| 659 | + virtual int get_vhost_hls_nb_notify(std::string vhost); | ||
| 654 | // bwct(bandwidth check tool) section | 660 | // bwct(bandwidth check tool) section |
| 655 | public: | 661 | public: |
| 656 | /** | 662 | /** |
| @@ -240,9 +240,10 @@ int SrsDvrAsyncCallOnHlsNotify::call() | @@ -240,9 +240,10 @@ int SrsDvrAsyncCallOnHlsNotify::call() | ||
| 240 | return ret; | 240 | return ret; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| 243 | + int nb_notify = _srs_config->get_vhost_hls_nb_notify(req->vhost); | ||
| 243 | for (int i = 0; i < (int)on_hls->args.size(); i++) { | 244 | for (int i = 0; i < (int)on_hls->args.size(); i++) { |
| 244 | std::string url = on_hls->args.at(i); | 245 | std::string url = on_hls->args.at(i); |
| 245 | - if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url)) != ERROR_SUCCESS) { | 246 | + if ((ret = SrsHttpHooks::on_hls_notify(url, req, ts_url, nb_notify)) != ERROR_SUCCESS) { |
| 246 | srs_error("hook client on_hls_notify failed. url=%s, ts=%s, ret=%d", url.c_str(), ts_url.c_str(), ret); | 247 | srs_error("hook client on_hls_notify failed. url=%s, ts=%s, ret=%d", url.c_str(), ts_url.c_str(), ret); |
| 247 | return ret; | 248 | return ret; |
| 248 | } | 249 | } |
| @@ -329,7 +329,7 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl | @@ -329,7 +329,7 @@ int SrsHttpHooks::on_hls(string url, SrsRequest* req, string file, int sn, doubl | ||
| 329 | return ret; | 329 | return ret; |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | -int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url) | 332 | +int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify) |
| 333 | { | 333 | { |
| 334 | int ret = ERROR_SUCCESS; | 334 | int ret = ERROR_SUCCESS; |
| 335 | 335 | ||
| @@ -365,9 +365,13 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts | @@ -365,9 +365,13 @@ int SrsHttpHooks::on_hls_notify(std::string url, SrsRequest* req, std::string ts | ||
| 365 | 365 | ||
| 366 | int nb_read = 0; | 366 | int nb_read = 0; |
| 367 | ISrsHttpResponseReader* br = msg->body_reader(); | 367 | ISrsHttpResponseReader* br = msg->body_reader(); |
| 368 | - if (!br->eof()) { | 368 | + while (nb_read < nb_notify && !br->eof()) { |
| 369 | char buf[64]; // only read a little of bytes of ts. | 369 | char buf[64]; // only read a little of bytes of ts. |
| 370 | - ret = br->read(buf, 64, &nb_read); | 370 | + int nb_buf = 64; |
| 371 | + if ((ret = br->read(buf, nb_buf, &nb_buf)) != ERROR_SUCCESS) { | ||
| 372 | + break; | ||
| 373 | + } | ||
| 374 | + nb_read += nb_buf; | ||
| 371 | } | 375 | } |
| 372 | 376 | ||
| 373 | int spenttime = (int)(srs_update_system_time_ms() - starttime); | 377 | int spenttime = (int)(srs_update_system_time_ms() - starttime); |
| @@ -110,8 +110,9 @@ public: | @@ -110,8 +110,9 @@ public: | ||
| 110 | * @param url the api server url, to process the event. | 110 | * @param url the api server url, to process the event. |
| 111 | * ignore if empty. | 111 | * ignore if empty. |
| 112 | * @param ts_url the ts uri, used to replace the variable [ts_url] in url. | 112 | * @param ts_url the ts uri, used to replace the variable [ts_url] in url. |
| 113 | + * @param nb_notify the max bytes to read from notify server. | ||
| 113 | */ | 114 | */ |
| 114 | - static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url); | 115 | + static int on_hls_notify(std::string url, SrsRequest* req, std::string ts_url, int nb_notify); |
| 115 | private: | 116 | private: |
| 116 | static int do_post(std::string url, std::string req, int& code, std::string& res); | 117 | static int do_post(std::string url, std::string req, int& code, std::string& res); |
| 117 | }; | 118 | }; |
-
请 注册 或 登录 后发表评论