派生自 development/c++

pansen
2019-03-07 d3b7bbe7102cd089680a828f5d8f6402c8cf6342
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#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;
}