From 40c264a316e81cb217b4be8a6db1a199ba62226e Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 14 Jul 2015 10:31:42 +0800 Subject: [PATCH] always reset the max target duration for hls. --- trunk/src/app/srs_app_hls.cpp | 15 +++++++++------ trunk/src/app/srs_app_hls.hpp | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 6decfc113..1bf50813e 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -280,7 +280,7 @@ SrsHlsMuxer::SrsHlsMuxer() previous_floor_ts = 0; accept_floor_ts = 0; hls_ts_floor = false; - target_duration = 0; + max_td = 0; _sequence_no = 0; current = NULL; acodec = SrsCodecAudioReserved1; @@ -400,10 +400,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream); m3u8 = path + "/" + m3u8_url; - // we always keep the target duration increasing. - int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost))); - srs_info("hls update target duration %d=>%d, aof=%.2f", target_duration, max_td, aof_ratio); - target_duration = max_td; + // when update config, reset the history target duration. + max_td = (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost)); std::string storage = _srs_config->get_hls_storage(r->vhost); if (storage == "ram") { @@ -861,6 +859,9 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) ss << "#EXT-X-MEDIA-SEQUENCE:" << first->sequence_no << SRS_CONSTS_LF; srs_verbose("write m3u8 sequence success."); + // iterator shared for td generation and segemnts wrote. + std::vector::iterator it; + // #EXT-X-TARGETDURATION:4294967295\n /** * @see hls-m3u8-draft-pantos-http-live-streaming-12.pdf, page 25 @@ -871,11 +872,13 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) * typical target duration is 10 seconds. */ // @see https://github.com/simple-rtmp-server/srs/issues/304#issuecomment-74000081 - std::vector::iterator it; + int target_duration = 0; for (it = segments.begin(); it != segments.end(); ++it) { SrsHlsSegment* segment = *it; target_duration = srs_max(target_duration, (int)ceil(segment->duration)); } + target_duration = srs_max(target_duration, max_td); + ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF; srs_verbose("write m3u8 duration success."); diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 431a0fb3f..27ab1da01 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -233,7 +233,7 @@ private: int64_t previous_floor_ts; private: int _sequence_no; - int target_duration; + int max_td; std::string m3u8; std::string m3u8_url; private: