From eeb89c114214678a2968c151b91440374ff50572 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期五, 11 十月 2019 09:25:10 +0800
Subject: [PATCH] fix rec no such file
---
csrc/buz/recorder.cpp | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/csrc/buz/recorder.cpp b/csrc/buz/recorder.cpp
index 00611c2..d3d9a98 100644
--- a/csrc/buz/recorder.cpp
+++ b/csrc/buz/recorder.cpp
@@ -78,7 +78,8 @@
out_ = new FormatOut(in_->getFPS(), "mp4");
int pid = getpid();
- file_path_ = dir_ + "/" + sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4";
+ std::string filename(sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4");
+ file_path_ = dir_ + "/" + filename;
auto v = in_->getStream(AVMEDIA_TYPE_VIDEO);
if (!v){
@@ -88,10 +89,18 @@
if (!audio){
a = NULL;
}
- auto ret = out_->JustWriter(v, a, file_path_.c_str());
+ bool ret = out_->JustWriter(v, a, file_path_.c_str());
if (ret){
- logIt("start record file: %s", file_path_.c_str());
+ logIt("start record file: %s", file_path_.c_str());
return 0;
+ }else{
+ file_path_ = "./" + filename;
+ ret = out_->JustWriter(v, a, file_path_.c_str());
+ logIt("failed in dir %s, try file %s to start record file", dir_.c_str(), file_path_.c_str());
+ if (ret){
+ logIt("start record file: %s", file_path_.c_str());
+ return 0;
+ }
}
logIt("failed to start record: %s", file_path_.c_str());
@@ -105,12 +114,18 @@
}
int pid = getpid();
- file_path_ = dir_ + "/" + sole::uuid4().base62() + "-" + std::to_string(pid) + ".hevc";
+ std::string filename(sole::uuid4().base62() + "-" + std::to_string(pid) + ".mp4");
+ file_path_ = dir_ + "/" + filename;
fp_ = fopen(file_path_.c_str(), "wb");
if (!fp_){
- logIt("write hevc open file error: %s", file_path_.c_str());
- return -1;
+ file_path_ = "./" + 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_){
+ logIt("failed start record hevc file: %s", file_path_.c_str());
+ return -1;
+ }
}
logIt("start record file: %s", file_path_.c_str());
--
Gitblit v1.8.0