winlin

dvr use .tmp and rename to .flv when finished.

@@ -454,7 +454,9 @@ int SrsDvrPlan::flv_open(string stream, string path) @@ -454,7 +454,9 @@ int SrsDvrPlan::flv_open(string stream, string path)
454 { 454 {
455 int ret = ERROR_SUCCESS; 455 int ret = ERROR_SUCCESS;
456 456
457 - if ((ret = fs->open(path)) != ERROR_SUCCESS) { 457 + current_flv_path = path;
  458 + std::string tmp_file = path + ".tmp";
  459 + if ((ret = fs->open(tmp_file)) != ERROR_SUCCESS) {
458 srs_error("open file stream for file %s failed. ret=%d", path.c_str(), ret); 460 srs_error("open file stream for file %s failed. ret=%d", path.c_str(), ret);
459 return ret; 461 return ret;
460 } 462 }
@@ -487,7 +489,21 @@ int SrsDvrPlan::on_video_msg(SrsSharedPtrMessage* /*video*/) @@ -487,7 +489,21 @@ int SrsDvrPlan::on_video_msg(SrsSharedPtrMessage* /*video*/)
487 489
488 int SrsDvrPlan::flv_close() 490 int SrsDvrPlan::flv_close()
489 { 491 {
490 - return fs->close(); 492 + int ret = ERROR_SUCCESS;
  493 +
  494 + if ((ret = fs->close()) != ERROR_SUCCESS) {
  495 + return ret;
  496 + }
  497 +
  498 + std::string tmp_file = current_flv_path + ".tmp";
  499 + if (rename(tmp_file.c_str(), current_flv_path.c_str()) < 0) {
  500 + ret = ERROR_SYSTEM_FILE_RENAME;
  501 + srs_error("rename flv file failed, %s => %s. ret=%d",
  502 + tmp_file.c_str(), current_flv_path.c_str(), ret);
  503 + return ret;
  504 + }
  505 +
  506 + return ret;
491 } 507 }
492 508
493 int SrsDvrPlan::on_dvr_keyframe() 509 int SrsDvrPlan::on_dvr_keyframe()
@@ -127,6 +127,10 @@ protected: @@ -127,6 +127,10 @@ protected:
127 SrsSource* _source; 127 SrsSource* _source;
128 SrsRequest* _req; 128 SrsRequest* _req;
129 SrsRtmpJitter* jitter; 129 SrsRtmpJitter* jitter;
  130 + /**
  131 + * current flv file path.
  132 + */
  133 + std::string current_flv_path;
130 public: 134 public:
131 SrsDvrPlan(); 135 SrsDvrPlan();
132 virtual ~SrsDvrPlan(); 136 virtual ~SrsDvrPlan();
@@ -106,6 +106,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -106,6 +106,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
106 #define ERROR_SYSTEM_FILE_READ 426 106 #define ERROR_SYSTEM_FILE_READ 426
107 #define ERROR_SYSTEM_FILE_WRITE 427 107 #define ERROR_SYSTEM_FILE_WRITE 427
108 #define ERROR_SYSTEM_FILE_EOF 428 108 #define ERROR_SYSTEM_FILE_EOF 428
  109 +#define ERROR_SYSTEM_FILE_RENAME 429
109 110
110 // see librtmp. 111 // see librtmp.
111 // failed when open ssl create the dh 112 // failed when open ssl create the dh