From f676f7af18163b4532b6b982bbe1dc57b32e96dd Mon Sep 17 00:00:00 2001
From: zhangjixing <775834166@qq.com>
Date: 星期四, 24 一月 2019 15:38:22 +0800
Subject: [PATCH] 

---
 QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp |  111 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 67 insertions(+), 44 deletions(-)

diff --git a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
index a46ad7c..3b8498f 100644
--- a/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
+++ b/QiaoJiaSystem/StructureApp/NewRecordVideoElement.cpp
@@ -1,45 +1,59 @@
 #include "NewRecordVideoElement.h"
 #include <basic/util/app/AppPreference.hpp>
-
+#include <QString>
+#include <QDateTime>
 //#todo index int -> string
 NewRecordVideoElement::NewRecordVideoElement(std::string camid) :
-videoEncoderElement(cv::Size(1920, 1080), 5, 0),
-camID(camid)
+//videoEncoderElement(cv::Size(1920, 1080), 5, 0),
+camID(camid),
+m_bSaveWH(false)
 {
 
    // basicPath();
+    //isRecord=false;
     m_cutPath= appPref.getStringData("user.loop.absolute.path");
+
+     recordInit(appPref.getIntData("n_cut_min_duration"),appPref.getIntData("n_cut_max_duration"));
 }
 
 NewRecordVideoElement::~NewRecordVideoElement() {
-    queue<ImgInfo> empty;
+    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);
+    m_filename=srcPath;
+   // DBG("m_filename: " << m_filename);
+    if(!m_bSaveWH)
+    {
+       m_bSaveWH=m_hiredisTool.hashSet(camID,"width",info.img.cols) && m_hiredisTool.hashSet(camID,"height",info.img.rows);
+       DBG("m_bSaveWH="<<m_bSaveWH);
+    }
 
-//    DBG("fisrt fps time"<<info.time);
-    try {
-        videoEncoderElement.threadInitial(srcPath, info.img);
-    }
-    catch (std::exception &e) {
-        ERR(e.what())
-    }
+    m_hiredisTool.pushImageBuf(m_filename,info.img);
+     m_hiredisTool.addFileInfo(m_filename,RECORD_DOING);
     return srcPath;
 }
 
 void NewRecordVideoElement::endRecord() {
-    doRecord();
-    doRecord();
-    doRecord();
-    videoEncoderElement.threadClosing();
+
+    ImgInfo info;
+    getImg(info);
+//    DBG("m_filename: " << m_filename);
+//    DBG("recordDelay:" << recordDelay);
+//    DBG("videoLength:" << videoLength);
+//    DBG("sdkTrigger:" << sdkTrigger);
+    m_hiredisTool.pushImageBuf(m_filename,info.img);
+    m_hiredisTool.addFileInfo(m_filename,RECORD_ENDING);
+
 }
 
 void NewRecordVideoElement::doRecord() {
@@ -49,13 +63,13 @@
      ImgInfo info;
      getImg(info);
 
-//    DBG(" time="<<info.time);
-    videoEncoderElement.doFunc(info.img);
+     m_hiredisTool.pushImageBuf(m_filename,info.img);
+     m_hiredisTool.addFileInfo(m_filename,RECORD_DOING);
 }
 
- std::string NewRecordVideoElement::getFileName(std::string timeStamp)
+ std::string NewRecordVideoElement::getFileName(const std::string& timeStamp)
 {
-    std::string dirPath=makeDir();
+    std::string dirPath=makeDir(timeStamp);
 
     char szDateTime[256] = {0};
     sprintf(szDateTime, "%s%s.mp4", dirPath.c_str(), timeStamp.c_str());
@@ -64,7 +78,7 @@
 }
 
 
-std::string NewRecordVideoElement::makeDir() {
+std::string NewRecordVideoElement::makeDir(const std::string& timeStamp) {
 
     //# ./camIndex/YYYYMM/DD/YYYYMMDDHH/
     std::string t_FilePath = m_cutPath;
@@ -73,15 +87,13 @@
         t_FilePath.push_back('/');
     }
     char buf[24];
+    QDateTime dt = QDateTime::fromString(QString::fromStdString(timeStamp), "yyyy-MM-dd hh:mm:ss:zzz");
 
-     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/
+     std::string t_strTime=dt.toString("yyyyMMddhh").toStdString();
+    // DBG("t_strTime="<<t_strTime);
      t_FilePath.append(camID + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
      //YYYYMMDDHH
-      t_FilePath.append(t_strTime.substr(0,10) + "/");
+      t_FilePath.append(t_strTime.substr(0,10)+ "/");
      std::string t_cmd = "mkdir -p '";
     t_cmd.append(t_FilePath + "'");
     //#get path mkdir path
@@ -91,37 +103,43 @@
 }
 void NewRecordVideoElement::pushImgBuf(const std::string& time,cv::Mat& img)
 {
+//    std::string tmp="camId="+camID+"pushImgBuf";
+//    ClockTimer cl(tmp);
      ImgInfo info;
      img.copyTo(info.img);
 //     info.img=img;
      info.time=time;
      m_imgBufQue.push(info);
+    // if(isRecord)
+    // DBG("camId="<<camID<<"pushtime="<<info.time);
 //     int size=m_imgBufQue.size();
 //     DBG("m_imgBufQue size="<<size);
 }
  void NewRecordVideoElement::getImg(ImgInfo& info)
  {
-        //todo
-        int len=20;
-         info=m_imgBufQue.front();
+//     std::string tmp="camId="+camID+"getImg";
+//     ClockTimer cl(tmp);
+        info=m_imgBufQue.front();
         int size=m_imgBufQue.size();
-//        DBG("m_imgBufQue size="<<size<<" time="<<info.time);
-        if(size>len)
+//        DBG("m_imgBufQue size="<<size<<" camId="<<camID<<" fileMin="<<fileMin/2);
+        if(size>fileMin/2)
         {
              m_imgBufQue.pop();
         }
-
+//        if(isRecord)
+//        DBG("camId="<<camID<<"gettime="<<info.time);
 
 
  }
- void NewRecordVideoElement::threadFunc()
- {
-        Record();
- }
- void NewRecordVideoElement::threadInitial()
- {
-     recordInit(40,100);
- }
+// void NewRecordVideoElement::threadFunc()
+// {
+//       Record();
+// }
+// void NewRecordVideoElement::threadInitial()
+// {
+
+
+// }
 
  void NewRecordVideoElement::Record() {
      switch(recordStatus)
@@ -192,8 +210,11 @@
      }
  }
  void NewRecordVideoElement::setSdkTrigger(bool isTrigger) {
+//     std::string tmp="camId="+camID+"setSdkTrigger";
+//     ClockTimer cl(tmp);
      if(isTrigger)
      {
+//         DBG("setSdkTrigger time=" << AppUtil::getTimeUSecString());
          triggerDelay = 0;
          sdkTrigger = true;
      }
@@ -206,11 +227,13 @@
              sdkTrigger = true;
          }
      }
+     Record();
  }
  void NewRecordVideoElement::recordInit(int videoMin, int videoMax) {
+
      sdkTrigger = false;
-     fileMin = videoMin;
-     fileMax = videoMax;
+     fileMin = videoMin*8;//fps=8
+     fileMax = videoMax*8;
      triggerDelay = fileMin/2;
 
      recordStatus = RECORD_STOP;

--
Gitblit v1.8.0