胡斌

don't save total duration if hls_total_file is not configured

... ... @@ -73,7 +73,7 @@ const char* _srs_version = "XCORE-"RTMP_SIG_SRS_SERVER;
#define SRS_CONF_DEFAULT_HLS_PATH "./objs/nginx/html"
#define SRS_CONF_DEFAULT_HLS_M3U8_FILE "[app]/[stream].m3u8"
#define SRS_CONF_DEFAULT_HLS_TOTAL_M3U8_FILE ""
#define SRS_CONF_DEFAULT_HLS_TOTAL_FILE "[app]/[stream]_total"
#define SRS_CONF_DEFAULT_HLS_TOTAL_FILE ""
#define SRS_CONF_DEFAULT_HLS_TS_FILE "[app]/[stream]-[seq].ts"
#define SRS_CONF_DEFAULT_HLS_TS_FLOOR false
#define SRS_CONF_DEFAULT_HLS_FRAGMENT 10
... ...
... ... @@ -833,26 +833,30 @@ int SrsHlsMuxer::segment_close(string log_desc)
}
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 (!total_url.empty()) {
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);
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);
}
}
}
... ...