胡斌

save the total duraion of total.m3u8 to file total

@@ -303,6 +303,7 @@ SrsHlsMuxer::SrsHlsMuxer() @@ -303,6 +303,7 @@ SrsHlsMuxer::SrsHlsMuxer()
303 async = new SrsAsyncCallWorker(); 303 async = new SrsAsyncCallWorker();
304 context = new SrsTsContext(); 304 context = new SrsTsContext();
305 save_m3u8_total = false; 305 save_m3u8_total = false;
  306 + total_duraion = 0.0;
306 } 307 }
307 308
308 SrsHlsMuxer::~SrsHlsMuxer() 309 SrsHlsMuxer::~SrsHlsMuxer()
@@ -831,6 +832,28 @@ int SrsHlsMuxer::segment_close(string log_desc) @@ -831,6 +832,28 @@ int SrsHlsMuxer::segment_close(string log_desc)
831 return ret; 832 return ret;
832 } 833 }
833 srs_info("write total m3u8 %s success.", m3u8_total_file.c_str()); 834 srs_info("write total m3u8 %s success.", m3u8_total_file.c_str());
  835 +
  836 + this->total_duraion += currentSeg->duration;
  837 + SrsFileWriter total_writer;
  838 + //write total duration to total
  839 + std::stringstream ss_total;
  840 +
  841 + std::string total_tmp = total + ".tmp";
  842 + ret = total_writer.open(total_tmp);
  843 + ss_total.precision(3);
  844 + ss_total.setf(std::ios::fixed, std::ios::floatfield);
  845 + ss_total << total_duraion;
  846 +
  847 + if ((ret = total_writer.write((char*) ss_total.str().c_str(),
  848 + (int) ss_total.str().length(), NULL)) != ERROR_SUCCESS) {
  849 + srs_error("write total temp:%s failed. ret=%d",(char*) total_tmp.c_str(), ret);
  850 + return ret;
  851 + }
  852 +
  853 + if(rename(total_tmp.c_str(), total.c_str()) < 0) {
  854 + ret = ERROR_HLS_WRITE_FAILED;
  855 + srs_error("rename total file failed. %s => %s, ret=%d", total_tmp.c_str(), total.c_str(), ret);
  856 + }
834 } 857 }
835 858
836 } else { 859 } else {
@@ -210,6 +210,8 @@ private: @@ -210,6 +210,8 @@ private:
210 std::string total; 210 std::string total;
211 std::string total_url; 211 std::string total_url;
212 bool save_m3u8_total; 212 bool save_m3u8_total;
  213 + //total duration for all segments
  214 + double total_duraion;
213 private: 215 private:
214 // TODO: FIXME: remove it. 216 // TODO: FIXME: remove it.
215 bool should_write_cache; 217 bool should_write_cache;