#include "LoopVideoRecorder.h"
|
#include <functional>
|
#include <algorithm>
|
#include <dirent.h>
|
#include <cstdio>
|
#include <QtCore/QDateTime>
|
#include <basic/util/app/AppPreference.hpp>
|
//#include <sys/stat.h>
|
extern std::vector<std::string> forEachFile(const std::string &dir_name);
|
|
//loop record video
|
void LoopVideoRecorder::loopRecordVideo() {
|
std::cout << "File " << __FILE__ << "FUNC " << __FUNCTION__ << " line " << __LINE__ << std::endl;
|
|
if (m_strRtsp.empty()) {
|
ERR("rtsp为空!");
|
return;
|
}
|
|
//#todo get Path
|
|
// std::string loopAbsPath = appPref.getStringData("user.loop.absolute.path");
|
// std::cout << "File " << __FILE__ << "FUNC " << __FUNCTION__ << " line " << __LINE__ << std::endl;
|
// std::string loopAbsPath = getFullFileName();
|
// if (loopAbsPath.empty()) {
|
// ERR("absolute.path为空");
|
// return ;
|
// }
|
|
// char last = loopAbsPath.back();
|
// if (last != '/') {
|
// loopAbsPath = loopAbsPath + "/";
|
// }
|
|
|
|
// QString CmdMkdir = QString("cd %1 ; mkdir -p %2").arg(QString::fromStdString(loopAbsPath)).arg(QString::fromStdString(m_nIndex));
|
// system(CmdMkdir.toLatin1().data());
|
|
std::string fullPath = getFullFileName();
|
// std::string cmd="mkdir -p "+fullPath;
|
// system(cmd.c_str());
|
//mkdir(fullPath.c_str(),S_IRWXU);
|
if(fullPath.empty())
|
{
|
ERR("LoopVideoRecorder::getFullFileName() is empty");
|
return ;
|
}
|
m_pVideoRcd = new VideoRecorder(fullPath,m_pathId, m_strRtsp, m_nInterval,m_db);
|
|
|
}
|
|
void LoopVideoRecorder::stopTimer() {
|
stop();
|
wait();
|
}
|
|
void LoopVideoRecorder::timerFunc() {
|
// loopRecordVideo();
|
}
|
|
LoopVideoRecorder::LoopVideoRecorder(int interval, std::string index, std::string rtsp,std::string pathId,LDBTool* db_c)
|
: TimerElement(interval), m_nInterval(interval), m_nIndex(index), m_strRtsp(rtsp),m_pathId(pathId),m_db(db_c){
|
// start();
|
// std::cout << "File " << __FILE__ << "FUNC " << __FUNCTION__ << " line " << __LINE__ << std::endl;
|
|
loopRecordVideo();
|
}
|
|
LoopVideoRecorder::~LoopVideoRecorder() {
|
delete m_pVideoRcd;
|
}
|
std::string LoopVideoRecorder::getFullFileName() {
|
|
//# ./camIndex/YYYYMM/DD/camIndex-YYYYMMDDHHMMSS/
|
std::string t_FilePath = appPref.getStringData("user.loop.absolute.path");
|
|
if (t_FilePath.back() != '/') {
|
t_FilePath.push_back('/');
|
}
|
char buf[24];
|
|
time_t t=time(nullptr);
|
// 20180901113048 2018-09-01 11:30:48
|
strftime(buf,24,"%Y%m%d%H%M%S",localtime(&t));
|
std::string t_strTime(buf);
|
//# ./camIndex/YYYYMM/DD/
|
t_FilePath.append(m_nIndex + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
|
//camIndex-YYYYMMDDHH/camIndex-YYYYMMDDHH/
|
t_FilePath.append(m_nIndex + "-" + t_strTime.substr(0,10) + "/");
|
std::string t_cmd = "mkdir -p '";
|
t_cmd.append(t_FilePath + "'");
|
//#get path mkdir path
|
system(t_cmd.c_str());
|
|
return t_FilePath;
|
}
|