winlin

always reset the max target duration for hls.

@@ -280,7 +280,7 @@ SrsHlsMuxer::SrsHlsMuxer() @@ -280,7 +280,7 @@ SrsHlsMuxer::SrsHlsMuxer()
280 previous_floor_ts = 0; 280 previous_floor_ts = 0;
281 accept_floor_ts = 0; 281 accept_floor_ts = 0;
282 hls_ts_floor = false; 282 hls_ts_floor = false;
283 - target_duration = 0; 283 + max_td = 0;
284 _sequence_no = 0; 284 _sequence_no = 0;
285 current = NULL; 285 current = NULL;
286 acodec = SrsCodecAudioReserved1; 286 acodec = SrsCodecAudioReserved1;
@@ -400,10 +400,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, @@ -400,10 +400,8 @@ int SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
400 m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream); 400 m3u8_url = srs_path_build_stream(m3u8_file, req->vhost, req->app, req->stream);
401 m3u8 = path + "/" + m3u8_url; 401 m3u8 = path + "/" + m3u8_url;
402 402
403 - // we always keep the target duration increasing.  
404 - int max_td = srs_max(target_duration, (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost)));  
405 - srs_info("hls update target duration %d=>%d, aof=%.2f", target_duration, max_td, aof_ratio);  
406 - target_duration = max_td; 403 + // when update config, reset the history target duration.
  404 + max_td = (int)(fragment * _srs_config->get_hls_td_ratio(r->vhost));
407 405
408 std::string storage = _srs_config->get_hls_storage(r->vhost); 406 std::string storage = _srs_config->get_hls_storage(r->vhost);
409 if (storage == "ram") { 407 if (storage == "ram") {
@@ -861,6 +859,9 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -861,6 +859,9 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
861 ss << "#EXT-X-MEDIA-SEQUENCE:" << first->sequence_no << SRS_CONSTS_LF; 859 ss << "#EXT-X-MEDIA-SEQUENCE:" << first->sequence_no << SRS_CONSTS_LF;
862 srs_verbose("write m3u8 sequence success."); 860 srs_verbose("write m3u8 sequence success.");
863 861
  862 + // iterator shared for td generation and segemnts wrote.
  863 + std::vector<SrsHlsSegment*>::iterator it;
  864 +
864 // #EXT-X-TARGETDURATION:4294967295\n 865 // #EXT-X-TARGETDURATION:4294967295\n
865 /** 866 /**
866 * @see hls-m3u8-draft-pantos-http-live-streaming-12.pdf, page 25 867 * @see hls-m3u8-draft-pantos-http-live-streaming-12.pdf, page 25
@@ -871,11 +872,13 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file) @@ -871,11 +872,13 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
871 * typical target duration is 10 seconds. 872 * typical target duration is 10 seconds.
872 */ 873 */
873 // @see https://github.com/simple-rtmp-server/srs/issues/304#issuecomment-74000081 874 // @see https://github.com/simple-rtmp-server/srs/issues/304#issuecomment-74000081
874 - std::vector<SrsHlsSegment*>::iterator it; 875 + int target_duration = 0;
875 for (it = segments.begin(); it != segments.end(); ++it) { 876 for (it = segments.begin(); it != segments.end(); ++it) {
876 SrsHlsSegment* segment = *it; 877 SrsHlsSegment* segment = *it;
877 target_duration = srs_max(target_duration, (int)ceil(segment->duration)); 878 target_duration = srs_max(target_duration, (int)ceil(segment->duration));
878 } 879 }
  880 + target_duration = srs_max(target_duration, max_td);
  881 +
879 ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF; 882 ss << "#EXT-X-TARGETDURATION:" << target_duration << SRS_CONSTS_LF;
880 srs_verbose("write m3u8 duration success."); 883 srs_verbose("write m3u8 duration success.");
881 884
@@ -233,7 +233,7 @@ private: @@ -233,7 +233,7 @@ private:
233 int64_t previous_floor_ts; 233 int64_t previous_floor_ts;
234 private: 234 private:
235 int _sequence_no; 235 int _sequence_no;
236 - int target_duration; 236 + int max_td;
237 std::string m3u8; 237 std::string m3u8;
238 std::string m3u8_url; 238 std::string m3u8_url;
239 private: 239 private: