派生自 development/c++

pansen
2018-12-26 a3365259bd9c51db3b5cfcf013ed323f27d1725a
QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
@@ -3,26 +3,27 @@
//#todo index int -> string
NewRecordVideoElement::NewRecordVideoElement(std::string camid) :
videoEncoderElement(cv::Size(1920, 1080), 9, 0),
camID(camid)
{
    videoEncoderElement(cv::Size(1920, 1080), 8, 0), camID(camid) {
   // basicPath();
    m_cutPath= appPref.getStringData("user.loop.absolute.path");
    // basicPath();
    m_cutPath = appPref.getStringData("user.loop.absolute.path");
}
NewRecordVideoElement::~NewRecordVideoElement() {
m_imgBufQue.clear();
    std::queue<ImgInfo> empty;
    empty.swap(m_imgBufQue);
//m_imgBufQue.clear();
}
std::string NewRecordVideoElement::startRecord() {
//    ImgInfo info=m_HiredisTool.getImage(camID);
     ImgInfo info;
     getImg(info);
    std::string srcPath= getFileName(info.time);
    ImgInfo info;
    getImg(info);
    std::string srcPath = getFileName(info.time);
//    DBG("fisrt fps time"<<info.time);
    try {
        videoEncoderElement.threadInitial(srcPath, info.img);
    }
@@ -33,24 +34,24 @@
}
void NewRecordVideoElement::endRecord() {
    ImgInfo info;
    getImg(info);
    doRecord();
    doRecord();
    doRecord();
    videoEncoderElement.threadClosing();
}
void NewRecordVideoElement::doRecord() {
    //  ImgInfo info=m_HiredisTool.getImage(camID);
    ImgInfo info;
    getImg(info);
//    ImgInfo info=m_HiredisTool.getImage(camID);
     ImgInfo info;
     getImg(info);
     DBG(" time="<<info.time);
//    DBG(" time="<<info.time);
    videoEncoderElement.doFunc(info.img);
}
 std::string NewRecordVideoElement::getFileName(std::string timeStamp)
{
    std::string dirPath=makeDir();
std::string NewRecordVideoElement::getFileName(std::string timeStamp) {
    std::string dirPath = makeDir();
    char szDateTime[256] = {0};
    sprintf(szDateTime, "%s%s.mp4", dirPath.c_str(), timeStamp.c_str());
@@ -69,44 +70,135 @@
    }
    char buf[24];
     time_t t=time(nullptr);
     // 20180901113048 2018-09-01 11:30:48
     strftime(buf,24,"%Y%m%d%H",localtime(&t));
      std::string t_strTime(buf);
       //# ./camIndex/YYYYMM/DD/
     t_FilePath.append(camID + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
     //YYYYMMDDHH
      t_FilePath.append(t_strTime.substr(0,10) + "/");
     std::string t_cmd = "mkdir -p '";
    time_t t = time(nullptr);
    // 20180901113048 2018-09-01 11:30:48
    strftime(buf, 24, "%Y%m%d%H", localtime(&t));
    std::string t_strTime(buf);
    //# ./camIndex/YYYYMM/DD/
    t_FilePath.append(camID + "/" + t_strTime.substr(0, 6) + "/" + t_strTime.substr(6, 2) + "/");
    //YYYYMMDDHH
    t_FilePath.append(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;
}
void NewRecordVideoElement::pushImgBuf(const std::string& time,cv::Mat img)
{
     ImgInfo info;
     info.img=img;
     info.time=time;
     m_imgBufQue.push_front(info);
void NewRecordVideoElement::pushImgBuf(const std::string &time, cv::Mat &img) {
    ImgInfo info;
    img.copyTo(info.img);
//     info.img=img;
    info.time = time;
    m_imgBufQue.push(info);
//     int size=m_imgBufQue.size();
//     DBG("m_imgBufQue size="<<size);
}
 void NewRecordVideoElement::getImg(ImgInfo& info)
 {
        //todo
        int len=10;
         info=m_imgBufQue.back();
        int size=m_imgBufQue.size();
        //DBG("m_imgBufQue size="<<size<<" time="<<info.time);
        if(size>len)
        {
             m_imgBufQue.pop_back();
void NewRecordVideoElement::getImg(ImgInfo &info) {
    //todo
    int len = 20;
    info = m_imgBufQue.front();
    int size = m_imgBufQue.size();
//        DBG("m_imgBufQue size="<<size<<" time="<<info.time);
    if (size > len) {
        m_imgBufQue.pop();
    }
}
void NewRecordVideoElement::threadFunc() {
    Record();
}
void NewRecordVideoElement::threadInitial() {
    recordInit(40, 100);
}
void NewRecordVideoElement::Record() {
    switch (recordStatus) {
        case RECORD_STOP:
            //        DBG("recordDelay:" << recordDelay);
            //        DBG("videoLength:" << videoLength);
            //        DBG("sdkTrigger:" << sdkTrigger);
            videoLength = 0;
            recordDelay = 0;
            if (sdkTrigger) {
                recordStatus = RECORD_DOING;
                startRecord();
            } else {
                ImgInfo info;
                getImg(info);
            }
            break;
        case RECORD_DOING:
            videoLength++;
            if (sdkTrigger) {
                if (videoLength < fileMax) {
                    doRecord();
                } else {
                    recordStatus = RECORD_STOP;
                    endRecord();
                }
            } else {
                recordStatus = RECORD_ENDING;
                doRecord();
            }
            break;
        case RECORD_ENDING:
//             DBG("recordDelay:" << recordDelay);
//             DBG("videoLength:" << videoLength);
//             DBG("sdkTrigger:" << sdkTrigger);
            recordDelay++;
            videoLength++;
            if (sdkTrigger) {
                if ((recordDelay < fileMin / 4) &&
                    (videoLength < fileMax)) {
                    doRecord();
                } else {
                    recordStatus = RECORD_STOP;
                    endRecord();
                }
            } else {
                if ((recordDelay < fileMin / 2) &&
                    (videoLength < fileMax)) {
                    doRecord();
                } else {
                    recordStatus = RECORD_STOP;
                    endRecord();
                }
            }
            break;
        default:
            break;
    }
}
void NewRecordVideoElement::setSdkTrigger(bool isTrigger) {
    if (isTrigger) {
        triggerDelay = 0;
        sdkTrigger = true;
    } else {
        if (triggerDelay++ >= fileMin / 2) {
            sdkTrigger = false;
        } else {
            sdkTrigger = true;
        }
    }
}
void NewRecordVideoElement::recordInit(int videoMin, int videoMax) {
    sdkTrigger = false;
    fileMin = videoMin;
    fileMax = videoMax;
    triggerDelay = fileMin / 2;
 }
    recordStatus = RECORD_STOP;
    videoLength = 0;
    recordDelay = 0;
}