From aaf2905a9dfacbcdc96013a4646ce628ac4ca638 Mon Sep 17 00:00:00 2001 From: xialixin Date: Sun, 25 Mar 2018 17:47:37 +0800 Subject: [PATCH 1/2] add: hls configuration adds [duration] variable (#1083) --- trunk/conf/full.conf | 1 + trunk/src/app/srs_app_fragment.cpp | 10 ++++++++-- trunk/src/app/srs_app_hls.cpp | 9 ++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 5d1925fd8..9d78a8516 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -1046,6 +1046,7 @@ vhost hls.srs.com { # [999], replace this const to current millisecond. # [timestamp],replace this const to current UNIX timestamp in ms. # [seq], the sequence number of ts. + # [duration], replace this const to current ts duration. # @see https://github.com/ossrs/srs/wiki/v2_CN_DVR#custom-path # @see https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#hls-config # default: [app]/[stream]-[seq].ts diff --git a/trunk/src/app/srs_app_fragment.cpp b/trunk/src/app/srs_app_fragment.cpp index 1c73307ab..f158078fd 100644 --- a/trunk/src/app/srs_app_fragment.cpp +++ b/trunk/src/app/srs_app_fragment.cpp @@ -28,6 +28,7 @@ #include #include +#include using namespace std; SrsFragment::SrsFragment() @@ -126,11 +127,16 @@ srs_error_t SrsFragment::rename() string full_path = fullpath(); string tmp_file = tmppath(); - + int tempdur = (int)duration(); + if (true) { + std::stringstream ss; + ss << tempdur; + full_path = srs_string_replace(full_path, "[duration]", ss.str()); + } if (::rename(tmp_file.c_str(), full_path.c_str()) < 0) { return srs_error_new(ERROR_SYSTEM_FRAGMENT_RENAME, "rename %s to %s", tmp_file.c_str(), full_path.c_str()); } - + filepath = full_path; return err; } diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index f6dacc659..b9484705e 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -688,7 +688,14 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file) ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF; // {file name}\n - ss << segment->uri << SRS_CONSTS_LF; + std::string seg_uri = segment->uri; + if (true) { + std::stringstream stemp; + stemp << (int)(segment->duration()); + seg_uri = srs_string_replace(seg_uri, "[duration]", stemp.str()); + } + //ss << segment->uri << SRS_CONSTS_LF; + ss << seg_uri << SRS_CONSTS_LF; } // write m3u8 to writer. From bb4e16ae3c9d39e0de8ea8e7c6195171e1799071 Mon Sep 17 00:00:00 2001 From: xialixin Date: Sun, 25 Mar 2018 17:48:07 +0800 Subject: [PATCH 2/2] fix create dir success result check (#1080) --- trunk/src/kernel/srs_kernel_utility.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 94f6375d3..274bcef8f 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -546,7 +546,7 @@ int srs_do_create_dir_recursively(string dir) { int ret = srs_do_create_dir_recursively(dir); - if (ret == ERROR_SYSTEM_DIR_EXISTS) { + if (ret == ERROR_SYSTEM_DIR_EXISTS || ret == ERROR_SUCCESS) { return srs_success; }