From 6fe36afcfac56b1e7b5f7b833ae8d85ac4e1053d Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 14 Jul 2015 11:00:58 +0800 Subject: [PATCH] when hls timestamp jump, reset it. --- trunk/src/app/srs_app_hls.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 5a4920e03..526ff3b1e 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -53,6 +53,8 @@ using namespace std; // drop the segment when duration of ts too small. #define SRS_AUTO_HLS_SEGMENT_MIN_DURATION_MS 100 +// when hls timestamp jump, reset it. +#define SRS_AUTO_HLS_SEGMENT_TIMESTAMP_JUMP_MS 300 // fragment plus the deviation percent. #define SRS_HLS_FLOOR_REAP_PERCENT 0.3 @@ -161,6 +163,11 @@ void SrsHlsSegment::update_duration(int64_t current_frame_dts) // update the segment duration, which is nagetive, // just ignore it. if (current_frame_dts < segment_start_dts) { + // for atc and timestamp jump, reset the start dts. + if (current_frame_dts < segment_start_dts - SRS_AUTO_HLS_SEGMENT_TIMESTAMP_JUMP_MS * 90) { + srs_warn("hls timestamp jump %"PRId64"=>%"PRId64, segment_start_dts, current_frame_dts); + segment_start_dts = current_frame_dts; + } return; } @@ -830,8 +837,10 @@ int SrsHlsMuxer::refresh_m3u8() } // remove the temp file. - if (unlink(temp_m3u8.c_str()) < 0) { - srs_warn("ignore remove m3u8 failed, %s", temp_m3u8.c_str()); + if (srs_path_exists(temp_m3u8)) { + if (unlink(temp_m3u8.c_str()) < 0) { + srs_warn("ignore remove m3u8 failed, %s", temp_m3u8.c_str()); + } } return ret;