胡斌

save the total duraion of total.m3u8 to file total

... ... @@ -303,6 +303,7 @@ SrsHlsMuxer::SrsHlsMuxer()
async = new SrsAsyncCallWorker();
context = new SrsTsContext();
save_m3u8_total = false;
total_duraion = 0.0;
}
SrsHlsMuxer::~SrsHlsMuxer()
... ... @@ -831,6 +832,28 @@ int SrsHlsMuxer::segment_close(string log_desc)
return ret;
}
srs_info("write total m3u8 %s success.", m3u8_total_file.c_str());
this->total_duraion += currentSeg->duration;
SrsFileWriter total_writer;
//write total duration to total
std::stringstream ss_total;
std::string total_tmp = total + ".tmp";
ret = total_writer.open(total_tmp);
ss_total.precision(3);
ss_total.setf(std::ios::fixed, std::ios::floatfield);
ss_total << total_duraion;
if ((ret = total_writer.write((char*) ss_total.str().c_str(),
(int) ss_total.str().length(), NULL)) != ERROR_SUCCESS) {
srs_error("write total temp:%s failed. ret=%d",(char*) total_tmp.c_str(), ret);
return ret;
}
if(rename(total_tmp.c_str(), total.c_str()) < 0) {
ret = ERROR_HLS_WRITE_FAILED;
srs_error("rename total file failed. %s => %s, ret=%d", total_tmp.c_str(), total.c_str(), ret);
}
}
} else {
... ...
... ... @@ -210,6 +210,8 @@ private:
std::string total;
std::string total_url;
bool save_m3u8_total;
//total duration for all segments
double total_duraion;
private:
// TODO: FIXME: remove it.
bool should_write_cache;
... ...