正在显示
6 个修改的文件
包含
139 行增加
和
17 行删除
| @@ -566,6 +566,7 @@ Supported operating systems and hardware: | @@ -566,6 +566,7 @@ Supported operating systems and hardware: | ||
| 566 | 566 | ||
| 567 | ### SRS 2.0 history | 567 | ### SRS 2.0 history |
| 568 | 568 | ||
| 569 | +* v2.0, 2015-03-31, enhanced hls, support deviation for duration. 2.0.151. | ||
| 569 | * v2.0, 2015-03-30, for [#351](https://github.com/winlinvip/simple-rtmp-server/issues/351), support config the m3u8/ts path for hls. 2.0.149. | 570 | * v2.0, 2015-03-30, for [#351](https://github.com/winlinvip/simple-rtmp-server/issues/351), support config the m3u8/ts path for hls. 2.0.149. |
| 570 | * v2.0, 2015-03-17, for [#155](https://github.com/winlinvip/simple-rtmp-server/issues/155), osx(darwin) support demo with nginx and ffmpeg. 2.0.143. | 571 | * v2.0, 2015-03-17, for [#155](https://github.com/winlinvip/simple-rtmp-server/issues/155), osx(darwin) support demo with nginx and ffmpeg. 2.0.143. |
| 571 | * v2.0, 2015-03-15, start [2.0release branch](https://github.com/winlinvip/simple-rtmp-server/tree/2.0release), 80773 lines. | 572 | * v2.0, 2015-03-15, start [2.0release branch](https://github.com/winlinvip/simple-rtmp-server/tree/2.0release), 80773 lines. |
| @@ -560,6 +560,11 @@ vhost with-hls.srs.com { | @@ -560,6 +560,11 @@ vhost with-hls.srs.com { | ||
| 560 | # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS#hls-config | 560 | # @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS#hls-config |
| 561 | # default: [app]/[stream]-[seq].ts | 561 | # default: [app]/[stream]-[seq].ts |
| 562 | hls_ts_file [app]/[stream]-[seq].ts; | 562 | hls_ts_file [app]/[stream]-[seq].ts; |
| 563 | + # whether use floor for the hls_ts_file path generation. | ||
| 564 | + # if on, use floor(timestamp/hls_fragment) as the variable [timestamp], | ||
| 565 | + # and use enahanced algorithm to calc deviation for segment. | ||
| 566 | + # default: off | ||
| 567 | + hls_ts_floor off; | ||
| 563 | # the hls entry prefix, which is base url of ts url. | 568 | # the hls entry prefix, which is base url of ts url. |
| 564 | # if specified, the ts path in m3u8 will be like: | 569 | # if specified, the ts path in m3u8 will be like: |
| 565 | # http://your-server/live/livestream-0.ts | 570 | # http://your-server/live/livestream-0.ts |
| @@ -588,6 +593,11 @@ vhost with-hls.srs.com { | @@ -588,6 +593,11 @@ vhost with-hls.srs.com { | ||
| 588 | # h264, vn | 593 | # h264, vn |
| 589 | # default: h264 | 594 | # default: h264 |
| 590 | hls_vcodec h264; | 595 | hls_vcodec h264; |
| 596 | + | ||
| 597 | + # on_hls, never config in here, should config in http_hooks. | ||
| 598 | + # for the hls http callback, @see http_hooks.on_hls of vhost hooks.callback.srs.com | ||
| 599 | + # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_DeliveryHLS#http-callback | ||
| 600 | + # @read https://github.com/winlinvip/simple-rtmp-server/wiki/v2_EN_DeliveryHLS#http-callback | ||
| 591 | } | 601 | } |
| 592 | } | 602 | } |
| 593 | # the vhost with hls disabled. | 603 | # the vhost with hls disabled. |
| @@ -722,6 +732,20 @@ vhost hooks.callback.srs.com { | @@ -722,6 +732,20 @@ vhost hooks.callback.srs.com { | ||
| 722 | # an int value specifies the error code(0 corresponding to success): | 732 | # an int value specifies the error code(0 corresponding to success): |
| 723 | # 0 | 733 | # 0 |
| 724 | on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs; | 734 | on_dvr http://127.0.0.1:8085/api/v1/dvrs http://localhost:8085/api/v1/dvrs; |
| 735 | + # when srs reap a ts file of hls, call the hook, | ||
| 736 | + # the request in the POST data string is a object encode by json: | ||
| 737 | + # { | ||
| 738 | + # "action": "on_hls", | ||
| 739 | + # "client_id": 1985, | ||
| 740 | + # "ip": "192.168.1.10", "vhost": "video.test.com", "app": "live", | ||
| 741 | + # "stream": "livestream", | ||
| 742 | + # "cwd": "/usr/local/srs", | ||
| 743 | + # "file": "./objs/nginx/html/live/livestream.1420254068776-100.ts" | ||
| 744 | + # } | ||
| 745 | + # if valid, the hook must return HTTP code 200(Stauts OK) and response | ||
| 746 | + # an int value specifies the error code(0 corresponding to success): | ||
| 747 | + # 0 | ||
| 748 | + on_hls http://127.0.0.1:8085/api/v1/hls http://localhost:8085/api/v1/hls; | ||
| 725 | } | 749 | } |
| 726 | } | 750 | } |
| 727 | 751 |
| @@ -1482,7 +1482,7 @@ int SrsConfig::check_config() | @@ -1482,7 +1482,7 @@ int SrsConfig::check_config() | ||
| 1482 | string m = conf->at(j)->name.c_str(); | 1482 | string m = conf->at(j)->name.c_str(); |
| 1483 | if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" | 1483 | if (m != "enabled" && m != "hls_entry_prefix" && m != "hls_path" && m != "hls_fragment" && m != "hls_window" && m != "hls_on_error" |
| 1484 | && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" | 1484 | && m != "hls_storage" && m != "hls_mount" && m != "hls_td_ratio" && m != "hls_aof_ratio" && m != "hls_acodec" && m != "hls_vcodec" |
| 1485 | - && m != "hls_m3u8_file" && m != "hls_ts_file" | 1485 | + && m != "hls_m3u8_file" && m != "hls_ts_file" && m != "hls_ts_floor" |
| 1486 | ) { | 1486 | ) { |
| 1487 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1487 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
| 1488 | srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); | 1488 | srs_error("unsupported vhost hls directive %s, ret=%d", m.c_str(), ret); |
| @@ -3207,6 +3207,23 @@ string SrsConfig::get_hls_ts_file(string vhost) | @@ -3207,6 +3207,23 @@ string SrsConfig::get_hls_ts_file(string vhost) | ||
| 3207 | return conf->arg0(); | 3207 | return conf->arg0(); |
| 3208 | } | 3208 | } |
| 3209 | 3209 | ||
| 3210 | +bool SrsConfig::get_hls_ts_floor(string vhost) | ||
| 3211 | +{ | ||
| 3212 | + SrsConfDirective* hls = get_hls(vhost); | ||
| 3213 | + | ||
| 3214 | + if (!hls) { | ||
| 3215 | + return SRS_CONF_DEFAULT_HLS_TS_FLOOR; | ||
| 3216 | + } | ||
| 3217 | + | ||
| 3218 | + SrsConfDirective* conf = hls->get("hls_ts_floor"); | ||
| 3219 | + | ||
| 3220 | + if (!conf || conf->arg0() != "on") { | ||
| 3221 | + return SRS_CONF_DEFAULT_HLS_TS_FLOOR; | ||
| 3222 | + } | ||
| 3223 | + | ||
| 3224 | + return true; | ||
| 3225 | +} | ||
| 3226 | + | ||
| 3210 | double SrsConfig::get_hls_fragment(string vhost) | 3227 | double SrsConfig::get_hls_fragment(string vhost) |
| 3211 | { | 3228 | { |
| 3212 | SrsConfDirective* hls = get_hls(vhost); | 3229 | SrsConfDirective* hls = get_hls(vhost); |
| @@ -48,6 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -48,6 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 48 | #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" | 48 | #define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html" |
| 49 | #define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8" | 49 | #define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8" |
| 50 | #define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts" | 50 | #define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts" |
| 51 | +#define SRS_CONF_DEFAULT_HLS_TS_FLOOR "off" | ||
| 51 | #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 | 52 | #define SRS_CONF_DEFAULT_HLS_FRAGMENT 10 |
| 52 | #define SRS_CONF_DEFAULT_HLS_TD_RATIO 1.5 | 53 | #define SRS_CONF_DEFAULT_HLS_TD_RATIO 1.5 |
| 53 | #define SRS_CONF_DEFAULT_HLS_AOF_RATIO 2.0 | 54 | #define SRS_CONF_DEFAULT_HLS_AOF_RATIO 2.0 |
| @@ -885,6 +886,10 @@ public: | @@ -885,6 +886,10 @@ public: | ||
| 885 | */ | 886 | */ |
| 886 | virtual std::string get_hls_ts_file(std::string vhost); | 887 | virtual std::string get_hls_ts_file(std::string vhost); |
| 887 | /** | 888 | /** |
| 889 | + * whether enable the floor(timestamp/hls_fragment) for variable timestamp. | ||
| 890 | + */ | ||
| 891 | + virtual bool get_hls_ts_floor(std::string vhost); | ||
| 892 | + /** | ||
| 888 | * get the hls fragment time, in seconds. | 893 | * get the hls fragment time, in seconds. |
| 889 | */ | 894 | */ |
| 890 | virtual double get_hls_fragment(std::string vhost); | 895 | virtual double get_hls_fragment(std::string vhost); |
| @@ -58,6 +58,11 @@ using namespace std; | @@ -58,6 +58,11 @@ using namespace std; | ||
| 58 | // drop the segment when duration of ts too small. | 58 | // drop the segment when duration of ts too small. |
| 59 | #define SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS 100 | 59 | #define SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS 100 |
| 60 | 60 | ||
| 61 | +// startup piece, the first piece, fragment percent to reap. | ||
| 62 | +#define SRS_HLS_FLOOR_STARTUP_PERCENT 0.1 | ||
| 63 | +// fragment plus the deviation percent. | ||
| 64 | +#define SRS_HLS_FLOOR_REAP_PERCENT 0.2 | ||
| 65 | + | ||
| 61 | ISrsHlsHandler::ISrsHlsHandler() | 66 | ISrsHlsHandler::ISrsHlsHandler() |
| 62 | { | 67 | { |
| 63 | } | 68 | } |
| @@ -170,6 +175,9 @@ SrsHlsMuxer::SrsHlsMuxer() | @@ -170,6 +175,9 @@ SrsHlsMuxer::SrsHlsMuxer() | ||
| 170 | handler = NULL; | 175 | handler = NULL; |
| 171 | hls_fragment = hls_window = 0; | 176 | hls_fragment = hls_window = 0; |
| 172 | hls_aof_ratio = 1.0; | 177 | hls_aof_ratio = 1.0; |
| 178 | + hls_fragment_deviation = 0; | ||
| 179 | + previous_floor_ts = 0; | ||
| 180 | + hls_ts_floor = false; | ||
| 173 | target_duration = 0; | 181 | target_duration = 0; |
| 174 | _sequence_no = 0; | 182 | _sequence_no = 0; |
| 175 | current = NULL; | 183 | current = NULL; |
| @@ -205,8 +213,24 @@ int SrsHlsMuxer::sequence_no() | @@ -205,8 +213,24 @@ int SrsHlsMuxer::sequence_no() | ||
| 205 | return _sequence_no; | 213 | return _sequence_no; |
| 206 | } | 214 | } |
| 207 | 215 | ||
| 216 | +string SrsHlsMuxer::ts_url() | ||
| 217 | +{ | ||
| 218 | + return current? current->uri:""; | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +double SrsHlsMuxer::duration() | ||
| 222 | +{ | ||
| 223 | + return current? current->duration:0; | ||
| 224 | +} | ||
| 225 | + | ||
| 226 | +double SrsHlsMuxer::deviation() | ||
| 227 | +{ | ||
| 228 | + return hls_fragment_deviation; | ||
| 229 | +} | ||
| 230 | + | ||
| 208 | int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, | 231 | int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, |
| 209 | - string path, string m3u8_file, string ts_file, int fragment, int window, double aof_ratio | 232 | + string path, string m3u8_file, string ts_file, double fragment, double window, |
| 233 | + bool ts_floor, double aof_ratio | ||
| 210 | ) { | 234 | ) { |
| 211 | int ret = ERROR_SUCCESS; | 235 | int ret = ERROR_SUCCESS; |
| 212 | 236 | ||
| @@ -218,7 +242,12 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, | @@ -218,7 +242,12 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, | ||
| 218 | hls_ts_file = ts_file; | 242 | hls_ts_file = ts_file; |
| 219 | hls_fragment = fragment; | 243 | hls_fragment = fragment; |
| 220 | hls_aof_ratio = aof_ratio; | 244 | hls_aof_ratio = aof_ratio; |
| 245 | + hls_ts_floor = ts_floor; | ||
| 246 | + previous_floor_ts = 0; | ||
| 221 | hls_window = window; | 247 | hls_window = window; |
| 248 | + // for the first time, we set to -N% of fragment, | ||
| 249 | + // that is, the first piece always smaller. | ||
| 250 | + hls_fragment_deviation = -1 * (fragment * SRS_HLS_FLOOR_STARTUP_PERCENT); | ||
| 222 | 251 | ||
| 223 | // generate the m3u8 dir and path. | 252 | // generate the m3u8 dir and path. |
| 224 | m3u8 = path + "/" + m3u8_file; | 253 | m3u8 = path + "/" + m3u8_file; |
| @@ -301,6 +330,19 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | @@ -301,6 +330,19 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | ||
| 301 | // generate filename. | 330 | // generate filename. |
| 302 | std::string ts_file = hls_ts_file; | 331 | std::string ts_file = hls_ts_file; |
| 303 | ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream); | 332 | ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream); |
| 333 | + if (hls_ts_floor) { | ||
| 334 | + int64_t floor_ts = (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); | ||
| 335 | + std::stringstream ts_floor; | ||
| 336 | + ts_floor << floor_ts; | ||
| 337 | + ts_file = srs_string_replace(ts_file, "[timestamp]", ts_floor.str()); | ||
| 338 | + | ||
| 339 | + // dup/jmp detect for ts in floor mode. | ||
| 340 | + if (previous_floor_ts && previous_floor_ts != floor_ts - 1) { | ||
| 341 | + srs_warn("hls: dup or jmp for floor ts, previous=%"PRId64", current=%"PRId64", ts=%s, deviation=%.2f", | ||
| 342 | + previous_floor_ts, floor_ts, ts_file.c_str(), hls_fragment_deviation); | ||
| 343 | + } | ||
| 344 | + previous_floor_ts = floor_ts; | ||
| 345 | + } | ||
| 304 | ts_file = srs_path_build_timestamp(ts_file); | 346 | ts_file = srs_path_build_timestamp(ts_file); |
| 305 | if (true) { | 347 | if (true) { |
| 306 | std::stringstream ss; | 348 | std::stringstream ss; |
| @@ -308,6 +350,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | @@ -308,6 +350,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | ||
| 308 | ts_file = srs_string_replace(ts_file, "[seq]", ss.str()); | 350 | ts_file = srs_string_replace(ts_file, "[seq]", ss.str()); |
| 309 | } | 351 | } |
| 310 | current->full_path = hls_path + "/" + ts_file; | 352 | current->full_path = hls_path + "/" + ts_file; |
| 353 | + srs_info("hls: generate ts path %s, tmpl=%s, floor=%d", ts_file.c_str(), hls_ts_file.c_str(), hls_ts_floor); | ||
| 311 | 354 | ||
| 312 | // the ts url, relative or absolute url. | 355 | // the ts url, relative or absolute url. |
| 313 | std::string ts_url = current->full_path; | 356 | std::string ts_url = current->full_path; |
| @@ -336,7 +379,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | @@ -336,7 +379,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | ||
| 336 | srs_error("open hls muxer failed. ret=%d", ret); | 379 | srs_error("open hls muxer failed. ret=%d", ret); |
| 337 | return ret; | 380 | return ret; |
| 338 | } | 381 | } |
| 339 | - srs_info("open HLS muxer success. path=%s, tmp=%s", | 382 | + srs_info("open HLS muxer success. path=%s, tmp=%s", |
| 340 | current->full_path.c_str(), tmp_file.c_str()); | 383 | current->full_path.c_str(), tmp_file.c_str()); |
| 341 | 384 | ||
| 342 | // set the segment muxer audio codec. | 385 | // set the segment muxer audio codec. |
| @@ -363,14 +406,22 @@ int SrsHlsMuxer::on_sequence_header() | @@ -363,14 +406,22 @@ int SrsHlsMuxer::on_sequence_header() | ||
| 363 | bool SrsHlsMuxer::is_segment_overflow() | 406 | bool SrsHlsMuxer::is_segment_overflow() |
| 364 | { | 407 | { |
| 365 | srs_assert(current); | 408 | srs_assert(current); |
| 366 | - return current->duration >= hls_fragment; | 409 | + |
| 410 | + // use N% deviation, to smoother. | ||
| 411 | + double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * hls_fragment_deviation : 0.0; | ||
| 412 | + | ||
| 413 | + return current->duration >= hls_fragment + deviation; | ||
| 367 | } | 414 | } |
| 368 | 415 | ||
| 369 | bool SrsHlsMuxer::is_segment_absolutely_overflow() | 416 | bool SrsHlsMuxer::is_segment_absolutely_overflow() |
| 370 | { | 417 | { |
| 371 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/151#issuecomment-83553950 | 418 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/151#issuecomment-83553950 |
| 372 | srs_assert(current); | 419 | srs_assert(current); |
| 373 | - return current->duration >= hls_aof_ratio * hls_fragment; | 420 | + |
| 421 | + // use N% deviation, to smoother. | ||
| 422 | + double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * hls_fragment_deviation : 0.0; | ||
| 423 | + | ||
| 424 | + return current->duration >= hls_aof_ratio * (hls_fragment + deviation); | ||
| 374 | } | 425 | } |
| 375 | 426 | ||
| 376 | int SrsHlsMuxer::update_acodec(SrsCodecAudio ac) | 427 | int SrsHlsMuxer::update_acodec(SrsCodecAudio ac) |
| @@ -457,10 +508,15 @@ int SrsHlsMuxer::segment_close(string log_desc) | @@ -457,10 +508,15 @@ int SrsHlsMuxer::segment_close(string log_desc) | ||
| 457 | // valid, add to segments if segment duration is ok | 508 | // valid, add to segments if segment duration is ok |
| 458 | if (current->duration * 1000 >= SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS) { | 509 | if (current->duration * 1000 >= SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS) { |
| 459 | segments.push_back(current); | 510 | segments.push_back(current); |
| 511 | + | ||
| 512 | + // when reap ts, adjust the deviation. | ||
| 513 | + if (hls_ts_floor) { | ||
| 514 | + hls_fragment_deviation += (double)(hls_fragment - current->duration); | ||
| 515 | + } | ||
| 460 | 516 | ||
| 461 | - srs_info("%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64"", | 517 | + srs_info("%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64", deviation=%.2f", |
| 462 | log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration, | 518 | log_desc.c_str(), current->sequence_no, current->uri.c_str(), current->duration, |
| 463 | - current->segment_start_dts); | 519 | + current->segment_start_dts, hls_fragment_deviation); |
| 464 | 520 | ||
| 465 | // notify handler for update ts. | 521 | // notify handler for update ts. |
| 466 | srs_assert(current->writer); | 522 | srs_assert(current->writer); |
| @@ -505,7 +561,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | @@ -505,7 +561,7 @@ int SrsHlsMuxer::segment_close(string log_desc) | ||
| 505 | // shrink the segments. | 561 | // shrink the segments. |
| 506 | double duration = 0; | 562 | double duration = 0; |
| 507 | int remove_index = -1; | 563 | int remove_index = -1; |
| 508 | - for (int i = segments.size() - 1; i >= 0; i--) { | 564 | + for (int i = (int)segments.size() - 1; i >= 0; i--) { |
| 509 | SrsHlsSegment* segment = segments[i]; | 565 | SrsHlsSegment* segment = segments[i]; |
| 510 | duration += segment->duration; | 566 | duration += segment->duration; |
| 511 | 567 | ||
| @@ -662,8 +718,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | @@ -662,8 +718,8 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | ||
| 662 | std::string stream = req->stream; | 718 | std::string stream = req->stream; |
| 663 | std::string app = req->app; | 719 | std::string app = req->app; |
| 664 | 720 | ||
| 665 | - int hls_fragment = (int)_srs_config->get_hls_fragment(vhost); | ||
| 666 | - int hls_window = (int)_srs_config->get_hls_window(vhost); | 721 | + double hls_fragment = _srs_config->get_hls_fragment(vhost); |
| 722 | + double hls_window = _srs_config->get_hls_window(vhost); | ||
| 667 | 723 | ||
| 668 | // get the hls m3u8 ts list entry prefix config | 724 | // get the hls m3u8 ts list entry prefix config |
| 669 | std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost); | 725 | std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost); |
| @@ -673,12 +729,16 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | @@ -673,12 +729,16 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | ||
| 673 | std::string ts_file = _srs_config->get_hls_ts_file(vhost); | 729 | std::string ts_file = _srs_config->get_hls_ts_file(vhost); |
| 674 | // the audio overflow, for pure audio to reap segment. | 730 | // the audio overflow, for pure audio to reap segment. |
| 675 | double hls_aof_ratio = _srs_config->get_hls_aof_ratio(vhost); | 731 | double hls_aof_ratio = _srs_config->get_hls_aof_ratio(vhost); |
| 732 | + // whether use floor(timestamp/hls_fragment) for variable timestamp | ||
| 733 | + bool ts_floor = _srs_config->get_hls_ts_floor(vhost); | ||
| 676 | 734 | ||
| 677 | // TODO: FIXME: support load exists m3u8, to continue publish stream. | 735 | // TODO: FIXME: support load exists m3u8, to continue publish stream. |
| 678 | // for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase. | 736 | // for the HLS donot requires the EXT-X-MEDIA-SEQUENCE be monotonically increase. |
| 679 | 737 | ||
| 680 | // open muxer | 738 | // open muxer |
| 681 | - if ((ret = muxer->update_config(req, entry_prefix, path, m3u8_file, ts_file, hls_fragment, hls_window, hls_aof_ratio)) != ERROR_SUCCESS) { | 739 | + if ((ret = muxer->update_config(req, entry_prefix, |
| 740 | + path, m3u8_file, ts_file, hls_fragment, hls_window, ts_floor, hls_aof_ratio)) != ERROR_SUCCESS | ||
| 741 | + ) { | ||
| 682 | srs_error("m3u8 muxer update config failed. ret=%d", ret); | 742 | srs_error("m3u8 muxer update config failed. ret=%d", ret); |
| 683 | return ret; | 743 | return ret; |
| 684 | } | 744 | } |
| @@ -687,6 +747,9 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | @@ -687,6 +747,9 @@ int SrsHlsCache::on_publish(SrsHlsMuxer* muxer, SrsRequest* req, int64_t segment | ||
| 687 | srs_error("m3u8 muxer open segment failed. ret=%d", ret); | 747 | srs_error("m3u8 muxer open segment failed. ret=%d", ret); |
| 688 | return ret; | 748 | return ret; |
| 689 | } | 749 | } |
| 750 | + srs_trace("hls: win=%.2f, frag=%.2f, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d", | ||
| 751 | + hls_window, hls_fragment, entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), | ||
| 752 | + ts_file.c_str(), hls_aof_ratio, ts_floor); | ||
| 690 | 753 | ||
| 691 | return ret; | 754 | return ret; |
| 692 | } | 755 | } |
| @@ -1057,9 +1120,9 @@ void SrsHls::hls_show_mux_log() | @@ -1057,9 +1120,9 @@ void SrsHls::hls_show_mux_log() | ||
| 1057 | // the run time is not equals to stream time, | 1120 | // the run time is not equals to stream time, |
| 1058 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/81#issuecomment-48100994 | 1121 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/81#issuecomment-48100994 |
| 1059 | // it's ok. | 1122 | // it's ok. |
| 1060 | - srs_trace("-> "SRS_CONSTS_LOG_HLS | ||
| 1061 | - " time=%"PRId64", stream dts=%"PRId64"(%"PRId64"ms), sequence_no=%d", | ||
| 1062 | - pprint->age(), stream_dts, stream_dts / 90, muxer->sequence_no()); | 1123 | + srs_trace("-> "SRS_CONSTS_LOG_HLS" time=%"PRId64", stream dts=%"PRId64"(%"PRId64"ms), sequence_no=%d, ts=%s, duration=%.2f, deviation=%.2f", |
| 1124 | + pprint->age(), stream_dts, stream_dts / 90, muxer->sequence_no(), muxer->ts_url().c_str(), | ||
| 1125 | + muxer->duration(), muxer->deviation()); | ||
| 1063 | } | 1126 | } |
| 1064 | } | 1127 | } |
| 1065 | 1128 |
| @@ -172,8 +172,17 @@ private: | @@ -172,8 +172,17 @@ private: | ||
| 172 | std::string hls_ts_file; | 172 | std::string hls_ts_file; |
| 173 | std::string m3u8_dir; | 173 | std::string m3u8_dir; |
| 174 | double hls_aof_ratio; | 174 | double hls_aof_ratio; |
| 175 | - int hls_fragment; | ||
| 176 | - int hls_window; | 175 | + double hls_fragment; |
| 176 | + double hls_window; | ||
| 177 | +private: | ||
| 178 | + // whether use floor algorithm for timestamp. | ||
| 179 | + bool hls_ts_floor; | ||
| 180 | + // the deviation in seconds to adjust the fragment to be more | ||
| 181 | + // bigger or smaller. | ||
| 182 | + double hls_fragment_deviation; | ||
| 183 | + // the previous reap floor timestamp, | ||
| 184 | + // used to detect the dup or jmp or ts. | ||
| 185 | + int64_t previous_floor_ts; | ||
| 177 | private: | 186 | private: |
| 178 | int _sequence_no; | 187 | int _sequence_no; |
| 179 | int target_duration; | 188 | int target_duration; |
| @@ -203,6 +212,9 @@ public: | @@ -203,6 +212,9 @@ public: | ||
| 203 | virtual ~SrsHlsMuxer(); | 212 | virtual ~SrsHlsMuxer(); |
| 204 | public: | 213 | public: |
| 205 | virtual int sequence_no(); | 214 | virtual int sequence_no(); |
| 215 | + virtual std::string ts_url(); | ||
| 216 | + virtual double duration(); | ||
| 217 | + virtual double deviation(); | ||
| 206 | public: | 218 | public: |
| 207 | /** | 219 | /** |
| 208 | * initialize the hls muxer. | 220 | * initialize the hls muxer. |
| @@ -213,7 +225,7 @@ public: | @@ -213,7 +225,7 @@ public: | ||
| 213 | */ | 225 | */ |
| 214 | virtual int update_config(SrsRequest* r, std::string entry_prefix, | 226 | virtual int update_config(SrsRequest* r, std::string entry_prefix, |
| 215 | std::string path, std::string m3u8_file, std::string ts_file, | 227 | std::string path, std::string m3u8_file, std::string ts_file, |
| 216 | - int fragment, int window, double aof_ratio); | 228 | + double fragment, double window, bool ts_floor, double aof_ratio); |
| 217 | /** | 229 | /** |
| 218 | * open a new segment(a new ts file), | 230 | * open a new segment(a new ts file), |
| 219 | * @param segment_start_dts use to calc the segment duration, | 231 | * @param segment_start_dts use to calc the segment duration, |
-
请 注册 或 登录 后发表评论