1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

enhance hls in floor mode.

This commit is contained in:
winlin 2015-03-31 17:03:14 +08:00
parent 76c1957260
commit 97442c56b6
3 changed files with 15 additions and 5 deletions

View file

@ -253,7 +253,7 @@ class RESTDvrs(object):
return json.dumps(dvrs) return json.dumps(dvrs)
''' '''
for SRS hook: on_dvr, on_dvr_reap_segment for SRS hook: on_dvr,
on_dvr: on_dvr:
when srs reap a dvr file, call the hook, when srs reap a dvr file, call the hook,
the request in the POST data string is a object encode by json: the request in the POST data string is a object encode by json:
@ -346,7 +346,7 @@ class RESTHls(object):
return json.dumps(hls) return json.dumps(hls)
''' '''
for SRS hook: on_dvr, on_dvr_reap_segment for SRS hook: on, on_dvr_reap_segment
on_dvr: on_dvr:
when srs reap a dvr file, call the hook, when srs reap a dvr file, call the hook,
the request in the POST data string is a object encode by json: the request in the POST data string is a object encode by json:

View file

@ -177,6 +177,7 @@ SrsHlsMuxer::SrsHlsMuxer()
hls_aof_ratio = 1.0; hls_aof_ratio = 1.0;
hls_fragment_deviation = 0; hls_fragment_deviation = 0;
previous_floor_ts = 0; previous_floor_ts = 0;
accept_floor_ts = 0;
hls_ts_floor = false; hls_ts_floor = false;
target_duration = 0; target_duration = 0;
_sequence_no = 0; _sequence_no = 0;
@ -244,6 +245,7 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
hls_aof_ratio = aof_ratio; hls_aof_ratio = aof_ratio;
hls_ts_floor = ts_floor; hls_ts_floor = ts_floor;
previous_floor_ts = 0; previous_floor_ts = 0;
accept_floor_ts = 0;
hls_window = window; hls_window = window;
// for the first time, we set to -N% of fragment, // for the first time, we set to -N% of fragment,
// that is, the first piece always smaller. // 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; std::string ts_file = hls_ts_file;
ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream); ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream);
if (hls_ts_floor) { 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. // we always ensure the piece is increase one by one.
std::stringstream ts_floor; 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()); ts_file = srs_string_replace(ts_file, "[timestamp]", ts_floor.str());
// dup/jmp detect for ts in floor mode. // 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) { 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", 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.c_str(), hls_fragment_deviation);
} }
previous_floor_ts++; previous_floor_ts = floor_ts;
} }
ts_file = srs_path_build_timestamp(ts_file); ts_file = srs_path_build_timestamp(ts_file);
if (true) { if (true) {

View file

@ -182,6 +182,7 @@ private:
double hls_fragment_deviation; double hls_fragment_deviation;
// the previous reap floor timestamp, // the previous reap floor timestamp,
// used to detect the dup or jmp or ts. // used to detect the dup or jmp or ts.
int64_t accept_floor_ts;
int64_t previous_floor_ts; int64_t previous_floor_ts;
private: private:
int _sequence_no; int _sequence_no;