winlin

enhanced hls, warning when ts dup or jmp.

@@ -176,6 +176,7 @@ SrsHlsMuxer::SrsHlsMuxer() @@ -176,6 +176,7 @@ SrsHlsMuxer::SrsHlsMuxer()
176 hls_fragment = hls_window = 0; 176 hls_fragment = hls_window = 0;
177 hls_aof_ratio = 1.0; 177 hls_aof_ratio = 1.0;
178 hls_fragment_deviation = 0; 178 hls_fragment_deviation = 0;
  179 + previous_floor_ts = 0;
179 hls_ts_floor = false; 180 hls_ts_floor = false;
180 target_duration = 0; 181 target_duration = 0;
181 _sequence_no = 0; 182 _sequence_no = 0;
@@ -242,6 +243,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, @@ -242,6 +243,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
242 hls_fragment = fragment; 243 hls_fragment = fragment;
243 hls_aof_ratio = aof_ratio; 244 hls_aof_ratio = aof_ratio;
244 hls_ts_floor = ts_floor; 245 hls_ts_floor = ts_floor;
  246 + previous_floor_ts = 0;
245 hls_window = window; 247 hls_window = window;
246 // for the first time, we set to -N% of fragment, 248 // for the first time, we set to -N% of fragment,
247 // that is, the first piece always smaller. 249 // that is, the first piece always smaller.
@@ -329,9 +331,17 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) @@ -329,9 +331,17 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
329 std::string ts_file = hls_ts_file; 331 std::string ts_file = hls_ts_file;
330 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);
331 if (hls_ts_floor) { 333 if (hls_ts_floor) {
  334 + int64_t floor_ts = (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment));
332 std::stringstream ts_floor; 335 std::stringstream ts_floor;
333 - ts_floor << (int64_t)(srs_get_system_time_ms() / (1000 * hls_fragment)); 336 + ts_floor << floor_ts;
334 ts_file = srs_string_replace(ts_file, "[timestamp]", ts_floor.str()); 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;
335 } 345 }
336 ts_file = srs_path_build_timestamp(ts_file); 346 ts_file = srs_path_build_timestamp(ts_file);
337 if (true) { 347 if (true) {
@@ -180,6 +180,9 @@ private: @@ -180,6 +180,9 @@ private:
180 // the deviation in seconds to adjust the fragment to be more 180 // the deviation in seconds to adjust the fragment to be more
181 // bigger or smaller. 181 // bigger or smaller.
182 double hls_fragment_deviation; 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;
183 private: 186 private:
184 int _sequence_no; 187 int _sequence_no;
185 int target_duration; 188 int target_duration;