胡斌

1.erase the last "#EXT-X-ENDLIST" int the total.m3u8 if stream is republished

2.erase the title "no desc" in m3u8 to reduce size because the title is optional
... ... @@ -303,6 +303,7 @@ SrsHlsMuxer::SrsHlsMuxer()
async = new SrsAsyncCallWorker();
context = new SrsTsContext();
save_m3u8_total = false;
m3u8_total_endlist_saved = false;
total_duraion = 0.0;
}
... ... @@ -791,7 +792,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
srs_verbose("write m3u8 header success.");
} else {
ret = total_m3u8_writer.open_append(total_m3u8);
ret = total_m3u8_writer.open_write(total_m3u8);
if (ret != ERROR_SUCCESS) {
srs_error(
"open total file %s error:%s reap ts segment, sequence_no=%d, uri=%s, duration=%.2f, start=%"PRId64,
... ... @@ -803,7 +804,12 @@ int SrsHlsMuxer::segment_close(string log_desc)
}
}
bool erase_last_endlist = false;
if (currentSeg->is_sequence_header) {
if( m3u8_total_endlist_saved ){
erase_last_endlist = true;
}
// #EXT-X-DISCONTINUITY\n
ss << "#EXT-X-DISCONTINUITY" << SRS_CONSTS_LF;
srs_verbose("write m3u8 segment discontinuity success.");
... ... @@ -812,7 +818,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
// "#EXTINF:4294967295.208,\n"
ss.precision(3);
ss.setf(std::ios::fixed, std::ios::floatfield);
ss << "#EXTINF:" << currentSeg->duration << ", no desc"
ss << "#EXTINF:" << currentSeg->duration << ","//", no desc" //the #EXTINF:<duration>,<title>,title is optional,so remove it to save the space
<< SRS_CONSTS_LF;
srs_verbose("write m3u8 segment info success.");
... ... @@ -821,7 +827,16 @@ int SrsHlsMuxer::segment_close(string log_desc)
srs_verbose("write m3u8 segment uri success.");
if(log_desc == "unpublish"){
ss << "#EXT-X-ENDLIST" << SRS_CONSTS_LF;
ss << "#EXT-X-ENDLIST" << SRS_CONSTS_LF;
m3u8_total_endlist_saved = true;
}
if(erase_last_endlist){
int64_t cur_pos = total_m3u8_writer.tellg();
cur_pos -= sizeof("#EXT-X-ENDLIST");// sizeof("#EXT-X-ENDLIST") = strlen("#EXT-X-ENDLIST") + 1 = strlen("#EXT-X-ENDLIST") + strlen("\n")
total_m3u8_writer.lseek(cur_pos);
}
// write m3u8 to writer.
... ... @@ -1019,7 +1034,7 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)
// "#EXTINF:4294967295.208,\n"
ss.precision(3);
ss.setf(std::ios::fixed, std::ios::floatfield);
ss << "#EXTINF:" << segment->duration << ", no desc" << SRS_CONSTS_LF;
ss << "#EXTINF:" << segment->duration << ","/*", no desc"*/ << SRS_CONSTS_LF;//#EXTINF:<duration>,<title>,title is optional,so remove it to save the space
srs_verbose("write m3u8 segment info success.");
// {file name}\n
... ...
... ... @@ -210,6 +210,7 @@ private:
std::string total;
std::string total_url;
bool save_m3u8_total;
bool m3u8_total_endlist_saved;
//total duration for all segments
double total_duraion;
private:
... ...
... ... @@ -94,6 +94,32 @@ int SrsFileWriter::open_append(string p)
return ret;
}
int SrsFileWriter::open_write(string p)
{
int ret = ERROR_SUCCESS;
if (fd > 0) {
ret = ERROR_SYSTEM_FILE_ALREADY_OPENED;
srs_error("file %s already opened. ret=%d", path.c_str(), ret);
return ret;
}
int flags = O_CREAT|O_WRONLY;
mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH;
if ((fd = ::open(p.c_str(), flags, mode)) < 0) {
ret = ERROR_SYSTEM_FILE_OPENE;
srs_error("open file %s failed. ret=%d", p.c_str(), ret);
return ret;
}
::lseek(fd, 0l, SEEK_END);
path = p;
return ret;
}
void SrsFileWriter::close()
{
int ret = ERROR_SUCCESS;
... ...
... ... @@ -59,6 +59,11 @@ public:
*/
virtual int open_append(std::string p);
/**
* open file writer, seek to file end.
* @param p a string indicates the path of file to open.
*/
virtual int open_write(std::string p);
/**
* close current writer.
* @remark user can reopen again.
*/
... ...