From b9c21b1e8fc3a2783a1bbdd7a9d8aee11aa6c96c Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 31 Mar 2015 15:54:05 +0800 Subject: [PATCH] enhanced hls, warning when ts dup or jmp. --- trunk/src/app/srs_app_hls.cpp | 12 +++++++++++- trunk/src/app/srs_app_hls.hpp | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index d9bc9dad6..6f3a76c71 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -176,6 +176,7 @@ SrsHlsMuxer::SrsHlsMuxer() hls_fragment = hls_window = 0; hls_aof_ratio = 1.0; hls_fragment_deviation = 0; + previous_floor_ts = 0; hls_ts_floor = false; target_duration = 0; _sequence_no = 0; @@ -242,6 +243,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, hls_fragment = fragment; hls_aof_ratio = aof_ratio; hls_ts_floor = ts_floor; + previous_floor_ts = 0; hls_window = window; // for the first time, we set to -N% of fragment, // that is, the first piece always smaller. @@ -329,9 +331,17 @@ 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) { + int64_t floor_ts = (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); std::stringstream ts_floor; - ts_floor << (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); + ts_floor << floor_ts; ts_file = srs_string_replace(ts_file, "[timestamp]", ts_floor.str()); + + // dup/jmp detect for ts in floor mode. + 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 = 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 7cef249ce..05f8ce3ee 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -180,6 +180,9 @@ private: // the deviation in seconds to adjust the fragment to be more // bigger or smaller. double hls_fragment_deviation; + // the previous reap floor timestamp, + // used to detect the dup or jmp or ts. + int64_t previous_floor_ts; private: int _sequence_no; int target_duration;