From 239cc54ccdbe0fdd203a7997704d0ef512a60842 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期四, 24 十月 2019 10:32:20 +0800
Subject: [PATCH] add backup rec

---
 csrc/buz/recorder.cpp |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index 2d00c57..17f2306 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -5,6 +5,8 @@
 #include <unistd.h>
 #include <chrono>
 
+#include <sys/stat.h>
+
 extern "C"{
 #include <libavcodec/avcodec.h>
 }
@@ -95,9 +97,12 @@
                 logIt("start record h264 file: %s", file_path_.c_str());                
                 return 0;
             }else{
-                file_path_ = "./" + filename;
-                ret = out_->JustWriter(v, a, file_path_.c_str());
+                std::string backup_dir("./video");
+                mkdir(backup_dir.c_str(), 0777);
+                file_path_ = backup_dir + "/" + filename;
+                
                 logIt("failed in dir %s, try file %s to start record file", dir_.c_str(), file_path_.c_str());                
+                ret = out_->JustWriter(v, a, file_path_.c_str());
                 if (ret){
                     logIt("start record h264 file: %s", file_path_.c_str());                
                     return 0;
@@ -120,7 +125,10 @@
 
             fp_ = fopen(file_path_.c_str(), "wb");
             if (!fp_){
-                file_path_ = "./" + filename;
+                std::string backup_dir("./video");
+                mkdir(backup_dir.c_str(), 0777);
+                file_path_ = backup_dir + "/" + filename;
+
                 logIt("failed in dir %s, try file %s to start record hevc file", dir_.c_str(), file_path_.c_str());                
                 fp_ = fopen(file_path_.c_str(), "wb");
                 if (!fp_){

--
Gitblit v1.8.0