diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index af9e27585..10773935d 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -454,7 +454,9 @@ int SrsDvrPlan::flv_open(string stream, string path) { int ret = ERROR_SUCCESS; - if ((ret = fs->open(path)) != ERROR_SUCCESS) { + current_flv_path = path; + std::string tmp_file = path + ".tmp"; + if ((ret = fs->open(tmp_file)) != ERROR_SUCCESS) { srs_error("open file stream for file %s failed. ret=%d", path.c_str(), ret); return ret; } @@ -487,7 +489,21 @@ int SrsDvrPlan::on_video_msg(SrsSharedPtrMessage* /*video*/) int SrsDvrPlan::flv_close() { - return fs->close(); + int ret = ERROR_SUCCESS; + + if ((ret = fs->close()) != ERROR_SUCCESS) { + return ret; + } + + std::string tmp_file = current_flv_path + ".tmp"; + if (rename(tmp_file.c_str(), current_flv_path.c_str()) < 0) { + ret = ERROR_SYSTEM_FILE_RENAME; + srs_error("rename flv file failed, %s => %s. ret=%d", + tmp_file.c_str(), current_flv_path.c_str(), ret); + return ret; + } + + return ret; } int SrsDvrPlan::on_dvr_keyframe() diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp index 562125e06..be665fa8f 100644 --- a/trunk/src/app/srs_app_dvr.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -127,6 +127,10 @@ protected: SrsSource* _source; SrsRequest* _req; SrsRtmpJitter* jitter; + /** + * current flv file path. + */ + std::string current_flv_path; public: SrsDvrPlan(); virtual ~SrsDvrPlan(); diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index b56c48a56..81894bc75 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -106,6 +106,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_SYSTEM_FILE_READ 426 #define ERROR_SYSTEM_FILE_WRITE 427 #define ERROR_SYSTEM_FILE_EOF 428 +#define ERROR_SYSTEM_FILE_RENAME 429 // see librtmp. // failed when open ssl create the dh