From 97442c56b64d2502e55be8ab2142a90cf835071c Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 31 Mar 2015 17:03:14 +0800 Subject: [PATCH] enhance hls in floor mode. --- trunk/research/api-server/server.py | 4 ++-- trunk/src/app/srs_app_hls.cpp | 15 ++++++++++++--- trunk/src/app/srs_app_hls.hpp | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/trunk/research/api-server/server.py b/trunk/research/api-server/server.py index e8fbd0418..085490655 100755 --- a/trunk/research/api-server/server.py +++ b/trunk/research/api-server/server.py @@ -253,7 +253,7 @@ class RESTDvrs(object): return json.dumps(dvrs) ''' - for SRS hook: on_dvr, on_dvr_reap_segment + for SRS hook: on_dvr, on_dvr: when srs reap a dvr file, call the hook, the request in the POST data string is a object encode by json: @@ -346,7 +346,7 @@ class RESTHls(object): return json.dumps(hls) ''' - for SRS hook: on_dvr, on_dvr_reap_segment + for SRS hook: on, on_dvr_reap_segment on_dvr: when srs reap a dvr file, call the hook, the request in the POST data string is a object encode by json: diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index be838dd8f..a0f0a9dcd 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -177,6 +177,7 @@ SrsHlsMuxer::SrsHlsMuxer() hls_aof_ratio = 1.0; hls_fragment_deviation = 0; previous_floor_ts = 0; + accept_floor_ts = 0; hls_ts_floor = false; target_duration = 0; _sequence_no = 0; @@ -244,6 +245,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, hls_aof_ratio = aof_ratio; hls_ts_floor = ts_floor; previous_floor_ts = 0; + accept_floor_ts = 0; hls_window = window; // for the first time, we set to -N% of fragment, // that is, the first piece always smaller. @@ -331,18 +333,25 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) std::string ts_file = hls_ts_file; ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream); if (hls_ts_floor) { + // accept the floor ts for the first piece. + int64_t floor_ts = (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); + if (!accept_floor_ts) { + accept_floor_ts = floor_ts - 1; + } else { + accept_floor_ts++; + } + // we always ensure the piece is increase one by one. std::stringstream ts_floor; - ts_floor << (int64_t)(previous_floor_ts + 1); + ts_floor << accept_floor_ts; ts_file = srs_string_replace(ts_file, "[timestamp]", ts_floor.str()); // dup/jmp detect for ts in floor mode. - int64_t floor_ts = (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); if (previous_floor_ts && previous_floor_ts != floor_ts - 1) { srs_warn("hls: dup or jmp for floor ts, previous=%"PRId64", current=%"PRId64", ts=%s, deviation=%.2f", previous_floor_ts, floor_ts, ts_file.c_str(), hls_fragment_deviation); } - previous_floor_ts++; + previous_floor_ts = floor_ts; } ts_file = srs_path_build_timestamp(ts_file); if (true) { diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 05f8ce3ee..3fcaa3da9 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -182,6 +182,7 @@ private: double hls_fragment_deviation; // the previous reap floor timestamp, // used to detect the dup or jmp or ts. + int64_t accept_floor_ts; int64_t previous_floor_ts; private: int _sequence_no;