1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

add: hls configuration adds [duration] variable (#1083)

This commit is contained in:
xialixin 2018-03-25 17:47:37 +08:00 committed by winlin
parent c20b819a29
commit aaf2905a9d
3 changed files with 17 additions and 3 deletions

View file

@ -1046,6 +1046,7 @@ vhost hls.srs.com {
# [999], replace this const to current millisecond. # [999], replace this const to current millisecond.
# [timestamp],replace this const to current UNIX timestamp in ms. # [timestamp],replace this const to current UNIX timestamp in ms.
# [seq], the sequence number of ts. # [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_DVR#custom-path
# @see https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#hls-config # @see https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS#hls-config
# default: [app]/[stream]-[seq].ts # default: [app]/[stream]-[seq].ts

View file

@ -28,6 +28,7 @@
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <unistd.h> #include <unistd.h>
#include <sstream>
using namespace std; using namespace std;
SrsFragment::SrsFragment() SrsFragment::SrsFragment()
@ -126,11 +127,16 @@ srs_error_t SrsFragment::rename()
string full_path = fullpath(); string full_path = fullpath();
string tmp_file = tmppath(); 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) { 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()); 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; return err;
} }

View file

@ -688,7 +688,14 @@ srs_error_t SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF; ss << "#EXTINF:" << segment->duration() / 1000.0 << ", no desc" << SRS_CONSTS_LF;
// {file name}\n // {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. // write m3u8 to writer.